schriftgestalt / GlyphsSDK

Scripting SDK for Glyphs
Apache License 2.0
89 stars 37 forks source link

align="topleft" seem to not work with self.drawTextAtPoint() #83

Closed HugoJourdan closed 1 year ago

HugoJourdan commented 1 year ago

I don't know if the right place to report this issue but when using this in Report Plugin :

self.drawTextAtPoint("Hello1\nHello1\nHello2", NSPoint(200, 300), align="topleft")

topright and topcenter works, only topleft don't work.

schriftgestalt commented 1 year ago

Do you have some code where that is sued? It is easier to debug if I don’t need to recreate everything.

HugoJourdan commented 1 year ago

Yes of course :

PluginName.glyphsReporter.zip

schriftgestalt commented 1 year ago

There are two things that cause this. 1) you use a scaled string drawing method in a unscaled drawing callback. You probably have realized that the text scaled strangely when you zoom. 2) You use more than one line of text. For "topleft" there is a small optimization that expects only one line and a certain font size.

I’ll cleaned the code up a bit. Should work now.

To avoid the scaling of the test, use this:

    font = Glyphs.font
    tab = font.currentTab
    viewPort = tab.viewPort;
    x = viewPort.origin.x + 10
    y = viewPort.origin.y + viewPort.size.height - 10
    font_size = 10.0 * tab.scale
    self.drawTextAtPoint("Hello1\nHello1\nHello2", NSPoint(x, y), fontSize=font_size, align="topleft")