Hello Glyphs! I am a late adopter to Glyphs3 and only just purchased it, so forgive me if this has already been discussed; I have tried searching for similar issues but I fear it might be something unique to me.
So I rely on a lot of scripts using robofab and pens, over the years I have managed to adapt them for FontLab/RoboFont/Glyphs2, but I discovered that when I use pens in Glyphs3 it appears to double the processed glyph in size.
The simplest example of this is when copying a glyph and then appending it as shown below.
I beleive that under the hood this is using pens, and for me the result is the appending glyph is 2x the size as it was originally.
I have tested with other pen examples with the same result (longer code example at end)
I have tested this on newly created Glyphs3 files @ 1000upm as default, and I have got the same result on files created in Glyphs2 @ 2000upm.
I have installed all of the modules from the plugin manager including Python for Glyphs which I have selected as my python environment and the app has been restarted multiple times.
I still have glyphs2 installed and the problem does not happen there.
Please let me know if you need more information, and if there’s anything I can do to help debug, I would just like to get this behaving as expected so I’m more than happy to provide anything you need.
Thanks, Matt
from robofab.world import *
# get Current Glyph
cg = CurrentGlyph()
# make a copy of Current Glyph
cgcopy = cg.copy()
# clear the Current Glyph
cg.clear()
# append the copy (shifted 100,100 helping to show a change was made if it was working correctly glyph would appear to move but remain same size, in my case it also doubles in size)
cg.appendGlyph(cgcopy,(100,100))
And this pen usage adapted from TypoLabs2016/14 Randomize Glyph.py at master · jenskutilek/TypoLabs2016 · GitHub
# MenuTitle: 14 Randomize Glyph
#from mojo.roboFont import CurrentFont, RGlyph
# import from robofab instead
from robofab.world import *
from fontTools.pens.basePen import BasePen
from random import randint
class MyPen(BasePen):
# from fontTools.pens.basePen.BasePen:
def __init__(self, glyphSet, writer_pen, max_move=0):
self.glyphSet = glyphSet
self.__currentPoint = None
self.writer_pen = writer_pen
self.max_move = max_move
def randomize(self, pt):
dx = randint(-self.max_move, self.max_move)
dy = randint(-self.max_move, self.max_move)
return (pt[0] + dx, pt[1] + dy)
def _moveTo(self, pt):
self.writer_pen.moveTo(self.randomize(pt))
def _lineTo(self, pt):
self.writer_pen.lineTo(self.randomize(pt))
def _curveToOne(self, bcp1, bcp2, pt):
self.writer_pen.curveTo(
self.randomize(bcp1), self.randomize(bcp2), self.randomize(pt)
)
def _closePath(self):
self.writer_pen.closePath()
def _endPath(self):
self.writer_pen.endPath()
def addComponent(self, baseGlyphName, transformation):
pass
def randomize_glyph(glyph,font):
source = glyph
#font = glyph.font
# Save the anchors from the original glyph in a list
anchors = [a for a in source.anchors]
# Remove all anchors from the glyph so they don't interfere with our processing
for a in anchors:
source.removeAnchor(a)
# Temporary glyph to which the pen is writing
target = RGlyph()
target_pen = target.getPen()
source_pen = MyPen(font, target_pen, 10)
source.draw(source_pen)
# Clear the original glyph and add the modfied outline
source.clear(components=False)
source.appendGlyph(target)
# Restore the saved anchors
for a in anchors:
source.appendAnchor(a.name, a.position)
if __name__ == "__main__":
font = CurrentFont()
for glyph_name in font.selection:
g = font[glyph_name]
print(g)
randomize_glyph(g, font)