I’m experimenting with drawing a color font (Option C: native Color layers) completely from a script. I’m stumbling at the point I try to set the layer to be a color layer. Here’s a skeleton version:
thisFont = Glyphs.font
selectedLayers = thisFont.selectedLayers
newGlyphNames = ("A")
Glyphs.clearLog()
# just draws a box at present
def drawGlyph(myBottomLeft, myTopRight):
try:
myRect = GSPath()
myCoordinates = [[myBottomLeft[0], myBottomLeft[1]], [myTopRight[0], myBottomLeft[1]], [myTopRight[0], myTopRight[1]], [myBottomLeft[0], myTopRight[1]]]
for thisPoint in myCoordinates:
newNode = GSNode()
newNode.type = GSLINE
newNode.position = (thisPoint[0], thisPoint[1])
myRect.nodes.append(newNode)
myRect.closed = True
return myRect
except Exception as e:
return False
def process(thisLayer):
layerIsEmpty = (len(thisLayer.paths) == 0 and len(thisLayer.components) == 0)
thisGlyph = thisLayer.parent
# ?????
thisLayer.colorObject.set()
# ????
R, G, B, A = thisLayer.colorObject.colorUsingColorSpace_(NSColorSpace.genericRGBColorSpace()).getRed_green_blue_alpha_(None, None, None, None)
thisLayer.colorObject = NSColor.colorWithDeviceRed_green_blue_alpha_(247.0 / 255.0, 74.0 / 255.0, 62.9 / 255.0, 1)
thisLayer.vertWidth = 800
bottomLeft = (0, -200)
topRight = (thisLayer.width, thisLayer.vertWidth)
layerRect = drawGlyph(bottomLeft, topRight)
if layerRect:
thisLayer.shapes.append(layerRect)
for glyphName in newGlyphNames:
original = glyphName
print(original)
if thisFont.glyphs[original]:
thisGlyph = Font.glyphs[glyphName]
print(thisGlyph)
for thisLayer in thisGlyph.layers:
print(thisLayer)
thisLayer.clear()
thisGlyph = thisLayer.parent
if thisGlyph:
process(thisLayer)
else:
print("%s: not found in font." % original)
Glyphs.showMacroWindow()
The colorObject.set
function returns 'NoneType' object has no attribute 'set'
…