typemytype / drawbot

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

Combining `textBoxCharacterBounds()` with `FormattedString.fontFilePath()` does not seem to work #518

Open roberto-arista opened 1 year ago

roberto-arista commented 1 year ago

I am testing the FormattedString.fontFilePath() method with a portion of the first code example of the FormattedString object.

If I run this code:

newPage(1000, 200)
# create a formatted string
txt = FormattedString()

# adding some text with some formatting
txt.append("hello", font="Helvetica", fontSize=100, fill=(1, 0, 0))
# adding more text
txt.append("world", font="Times-Italic", fontSize=50, fill=(0, 1, 0))

# setting a font
txt.font("Helvetica-Bold")
txt.fontSize(75)
txt += "hello again"

# drawing the formatted string
text(txt, (10, 30))

bounds = textBoxCharacterBounds(txt, (0, 0, width(), height()))
for eachBox in bounds:
    print(eachBox.formattedSubString)
    print(eachBox.formattedSubString.fontFilePath())

I get the following result:

hello
/System/Library/Fonts/Helvetica.ttc
world
/System/Library/Fonts/Helvetica.ttc
hello again
/System/Library/Fonts/Helvetica.ttc

while I would expect something like this:

hello
/System/Library/Fonts/Helvetica.ttc
world
/System/Library/Fonts/Times-Italic.ttc
hello again
/System/Library/Fonts/Helvetica.ttc