question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Measuring the bounds of text

See original GitHub issue

How can I measure text bounds using this library? Skia has SKPaint.MeasureText, but I am unable to find an equivalent in this library.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikegoatlycommented, Feb 22, 2022

@swharden Interesting - I think your sample highlights two different things:

  • The bounding box bottom is at the baseline of the text, not the bottom - you see the comma and the p drop below it.
  • The measuring seems to start breaking down when certain characters are added into the mix - punctuation seems to be the main culprit:

This looks about right: image

Commas and periods are undercalculated: image image

Exclamation marks are overcalculated: image

0reactions
AdamJachockicommented, May 16, 2023

This method doesn’t take multiple lines under consideration. There is:

var width = paint.MeasureText(value);
paint.Dispose();
return new SizeF(width, fontSize);

while it should somehow count text lines and spaces between them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accurate Measurements With getTextBounds()
Retrieve the text boundary box and store to bounds. Return in bounds (allocated by the caller) the smallest rectangle that encloses all of...
Read more >
Measuring Text - The Java™ Tutorials
stringWidth() returns the advance width of the text. Advance width is the distance from the origin of the text to the position of...
Read more >
Measuring tight bounds box of multiline text - android
I'm drawing a multiline text on a canvas using StaticLayout , and I want to measure the most tight bounds box around the...
Read more >
Text pixel width measuring on Javascript backend (Node.Js)
Recently I needed a library in Javascript for measuring text pixel width in Node.Js. The usage was in backend web scraper that is...
Read more >
Measuring Text - Chris Banes
As you can see, the text clearly draws outside of it's calculated bounds, both in height and width. Another text measuring method #....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found