drawbot icon indicating copy to clipboard operation
drawbot copied to clipboard

text shifted when run from the app

Open jansindl3r opened this issue 5 years ago • 5 comments

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.

jansindl3r avatar Dec 03 '20 16:12 jansindl3r

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()

typemytype avatar Feb 23 '21 10:02 typemytype

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

frankrolf avatar Apr 08 '21 12:04 frankrolf

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

jansindl3r avatar Apr 08 '21 13:04 jansindl3r

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

jansindl3r avatar Apr 26 '21 14:04 jansindl3r

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

typemytype avatar Apr 29 '21 13:04 typemytype