# Display.measure\_text() not returning correct value with vector fonts

**URL:** <https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865>\
**Category:** Support\
**Created:** [June 4, 2025, 4:33pm UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865 "2025-06-04T16:33:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveA](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/stevea/32/9294_2.png) [@SteveA](https://forums.pimoroni.com/u/SteveA)\
**Post date:** [June 4, 2025, 4:33pm UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865/1 "2025-06-04T16:33:32Z")

</div>

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?

Thanks for looking

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [June 4, 2025, 5:28pm UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865/2 "2025-06-04T17:28:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SteveA](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/stevea/32/9294_2.png) [@SteveA](https://forums.pimoroni.com/u/SteveA)\
**Post date:** [June 4, 2025, 5:59pm UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865/3 "2025-06-04T17:59:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [June 4, 2025, 7:04pm UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865/4 "2025-06-04T19:04:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SteveA](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/stevea/32/9294_2.png) [@SteveA](https://forums.pimoroni.com/u/SteveA)\
**Post date:** [June 4, 2025, 7:24pm UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865/5 "2025-06-04T19:24:28Z")

</div>

That’s interesting. Is there a way of accessing this second graphics library? Is it in their notes or have you found it by examining their code?

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [June 4, 2025, 7:46pm UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865/6 "2025-06-04T19:46:38Z")

</div>

Docs are here: [presto/docs/picovector.md at main · pimoroni/presto · GitHub](https://github.com/pimoroni/presto/blob/main/docs/picovector.md)

Not sure if this is only baked into their presto-build. The library itself is also part of the normal pimoroni-pico source-tree.

---

<div class="post-metadata">

**Author:** ![SteveA](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/stevea/32/9294_2.png) [@SteveA](https://forums.pimoroni.com/u/SteveA)\
**Post date:** [June 5, 2025, 10:40am UTC](https://forums.pimoroni.com/t/display-measure-text-not-returning-correct-value-with-vector-fonts/27865/7 "2025-06-05T10:40:03Z")

</div>

Thanks for sending the links. I will look into the Presto PicoVector fonts.  
All the best  
Steve
