I have created a sensor meter display and need to display large clear digits on the LCD. When I use the bitmap8 font and set the scale to such as 5, the displayed chars are naturally ‘chunky’ and don’t look good and so I use ‘sans’ vector Hershey fonts, setting the scale to such as 3 with display.set_thickness(8), to thicken the lines.
This produces nice clear large digits, although the update is slower due to vectoring fonts, but it is fine and looks good.
To centralise the textstring on the display I first need to know the width of the string using
width = display.measure_text(textstring, 3, spacing=1, fixed_width=True)
‘width’ always shows the correct result when using the bitmap8 font irrespective of the size, however it gives the incorrect result when using sans font when using different sizes.
Does this func work correctly with sans fonts with different sizes and line widths?
Looking at the source code of the hershey fonts, they just add up the width of each character (glyph) multiplied by the scale factor. Line-thickness is not taken into account.
Thanks @bablokb for looking into it. Even if I ignore the Line thickness the returned width is giving me incorrect results, it is as though the initial char width is somehow incorrect. I will keep looking.
Thanks
Pimoroni has a second graphics library, and in that library the text-width is measured differently. That newer lib takes things like character spacing and word spacing into account.