typemytype / drawbot

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

`textBoxCharacterBounds(align="center")` doesn’t seem to work #539

Closed chrisjansky closed 11 months ago

chrisjansky commented 11 months ago

Hello,

a quick test of textBoxCharacterBounds() with align parameter supplied doesn’t change the output as expected.

Minimal code to reproduce:

txt = "Testing Character Bounds"
box = 100, 100, 800, 800
fs = 100
l = 1.1
align = "center"

font("Times")
fontSize(fs)
lineHeight(fs * l)

charBounds = textBoxCharacterBounds(txt, box, align)

for b in charBounds:
    fill(0, 1, 0)
    rect(*b.bounds)

fill(0)    
textBox(txt, box, align)

I am doing something wrong?

Thanks, Christian

typemytype commented 11 months ago

nope, it seems the align as not set while creating a attributed string inside DrawBot

will be fixed!!

for now, and I would also advise to use FormattedString objects:

box = 100, 100, 800, 800

t = FormattedString()
t.font("Times", 100)
t.lineHeight(100 * 1.1)
t.align("center")
t += "Testing Character Bounds"

charBounds = textBoxCharacterBounds(t, box)

for b in charBounds:
    fill(0, 1, 0)
    rect(*b.bounds)

fill(0)    
textBox(t, box)
chrisjansky commented 11 months ago

@typemytype Understood, thanks for the quick answer, Frederik.