typemytype / drawbot

http://www.drawbot.com
Other
397 stars 61 forks source link

text shifted when run from the app #412

Open jansindl3r opened 3 years ago

jansindl3r commented 3 years ago

Hi, I run my script out of the DrawBot app it gives different result than when I run it as a module. I set font with font function, I give it path to my font as a parameter.

App: Screenshot 2020-12-03 at 17 44 12

Module: Screenshot 2020-12-03 at 17 46 23

Running it from app gives also this error

*** DrawBot warning: font: 'AfrikolaMonospace-Formal-Medium' is not installed, back to the fallback font: 'LucidaGrande' ***
*** DrawBot warning: font: 'AfrikolaMonospaceMedium' is not installed, back to the fallback font: 'LucidaGrande' ***

It gives the error only in the first attempt to set the font and it says my font won't be used but it did use it eventualyl. Just the shape, the vertical metrics are somehow wrong.

typemytype commented 3 years ago

Does this happens with all fonts? I cannot reproduce this

import drawBot
import AppKit

appName = AppKit.NSBundle.mainBundle().objectForInfoDictionaryKey_("CFBundleDisplayName")
appName = appName or "terminal"

drawBot.newDrawing()
drawBot.newPage()
txt = drawBot.FormattedString()
txt.fontSize(50)
txt.font("Menlo")
txt += "Afrikola Monospaced"

drawBot.text(txt, (100, 100))
drawBot.saveImage(f"test-{appName}.pdf")

drawBot.endDrawing()
frankrolf commented 3 years ago

I sometimes would have differing output when the module and application were actually different versions of DrawBot. Could this be the case here?

jansindl3r commented 3 years ago

This was clearly a bug but I haven't had time to look at it and make reproducible. I will share soon

jansindl3r commented 3 years ago

I made a demo and it's happening with any fonts. Line shifts if you run it the first time, then it's ok. If you change parameter of the second call of font to be fonts[0] it happens again, but after another execution it's fine again. There is a pdf showing left text on the first page shifted a bit. Archive.zip

typemytype commented 3 years ago

I guess this is probably solved with https://github.com/typemytype/drawbot/pull/421

As I cannot reproduce this anymore:

import drawBot as db
import math
import random
from pathlib import Path

base = Path(__file__).parent
fonts = [
    str(base/"formal_hn.otf"),
    str(base/"informal_hn.otf"),
    str(base/"SourceSerif4-Black.otf")
        ]
for frame in range(10):
    db.newPage()
    db.fontSize(100)
    db.font(fonts[0])
    db.text("Hn", (0, 0))
    db.font(fonts[1])
    db.text("Hn", (300, 0))
    db.font(fonts[2])
    db.text("Hn", (600, 0))

import AppKit
appName = AppKit.NSBundle.mainBundle().objectForInfoDictionaryKey_("CFBundleExecutable")
print("App name:", appName)
db.saveImage(f"bug{appName}.pdf")

and both exported pdfs looks the same

bugDrawBot.pdf bugPython.pdf