Search code examples
javascriptfabricjsfont-size

Where are the magic numbers come from in `fabric.js`?


https://github.com/fabricjs/fabric.js/blob/master/src/shapes/text.class.js#L210

_fontSizeFraction: 0.222,
_fontSizeMult: 1.13,

Is there any clue how they come from ? I found they are very useful to measure the actual text size.


Solution

  • _fontSizeFraction is approximately equal to 2/9, but my impression is that this value would be used to decrease the default size of the font.

    Text Line proportion to font Size (in pixels)

    _fontSizeMult increases values by 13%. It takes the font height, increases it by 13% to give you the total line height including line-spacing.

    These variables look like defaults and were likely chosen by the developer based on personal preference.

    They work for finding the text size because the text size is likely defined by these variables.