typemytype / drawbot

http://www.drawbot.com
Other
406 stars 63 forks source link

font issue or drawbot issue #555

Open jo-lang opened 10 months ago

jo-lang commented 10 months ago

Using the 'Hiragino Sans W1' typeface in a formatted String with a lineheight smaller than the font-size some of the text is cut off. Anyone has an idea if this is font related?

txt = 'ADABACAD\n'*10

lh = 7
fstr = FormattedString(txt, fontSize=25, font='Hiragino Sans W1', lineHeight = lh)
text(fstr, (100, 400))

fstr = FormattedString(txt, fontSize=25, lineHeight = lh)
text(fstr, (300, 400))
drawbot-cut-off-text
typemytype commented 10 months ago

font metrics is different:


for fn in ("Hiragino Sans W1", "LucidaGrande"):
    s = FormattedString()
    s.font(fn)

    print(fn)
    print(s.fontAscender())
    print(s.fontDescender())    
    print(s.fontLeading())    
    print(s.fontLineHeight())
jo-lang commented 10 months ago

ah sorry, I did not describe the issue properly. yes font metrics are different, but shouldn’t it still show all ten lines of the text. there are only eight of the 10 lines in the 'Hiragino' example. in the example code the line-height needs to be at least 12 to show all lines. This makes it a bit more visual:

txt = '\n'.join(str(i) for i in range(10))

lh = 7
fstr = FormattedString(txt, fontSize=25, font='Hiragino Sans W1', lineHeight = lh)
text(fstr, (100, 400))

fstr = FormattedString(txt, fontSize=25, lineHeight = lh)
text(fstr, (300, 400))
drawbot-cut-off-text
justvanrossum commented 10 months ago

I have noticed this problem recently, too, with a different font, but I found it hard to make a reproducer. The last snippet shows it loud and clear, thanks!

jo-lang commented 10 months ago

I came across this from a completely different use and it took some time to boil it done. but it’s actually even more confusing. the first example shows 8/10 and the second 7/10 lines.

justvanrossum commented 9 months ago

We suspect the bug is in the makeTextBoxes() function. This may also be related to some test failures we see on macOS 14.

typemytype commented 9 months ago

maybe some hints: https://developer.apple.com/documentation/coretext/ctparagraphstylespecifier/kctparagraphstylespecifierlinespacing?language=objc

those specifiers aren't accessible witha NSParagraphStyle... and a CTParagraphStyleCreate has not full support of pyobjc

typemytype commented 9 months ago

same issue in Apples TextEdit:

so maybe (I hope) not really a DrawBot issue...

image

attached the RTF files from TextEdit: numbers.zip