Size of text box doesn't correspond exactly to fontSize

  • ,Here's something interesting I found while writing code to generate the dimensions of a canvas based on the amount and size of the text I want to set in a square-ish field on the canvas.

    fontFamily = 'kast_4_a'
    fontStyle = 'top_0'
    fSize = 1000
    test_string = FormattedString()
    test_string.append('a', fontSize = fSize, font = fontFamily + '-%s' %fontStyle)

    yields the following:

    <NSSize width=692.0 height=1001.0>

    I can confirm that DrawBot's size() returns a height of any fontSize + 1.

    I was hoping to use the size of the text box to calculate the height of the canvas, but now I have to adjust that it seems. What's happening here?

  • @MauriceMeilleur the size of a text box is influenced by the lineHeight too. this produces the expected result:

    test_string.append('a', fontSize=fSize, lineHeight=fSize, font='%s-%s'%(fontFamily,fontStyle))


  • Good to know, thanks. But that means that default linespacing = fontSize + 1?

  • But that means that default linespacing = fontSize + 1?

    not really… it depends on the vertical metrics in the font.

    here’s a test with other fonts:

    from random import choice
    fontName = choice(installedFonts())
    txt = FormattedString()
    txt.append('a', fontSize=1000, font=fontName)

    line height is tricky 😕 see 1 2 3 4

Log in to reply