Microsoft.Maui.Graphics icon indicating copy to clipboard operation
Microsoft.Maui.Graphics copied to clipboard

SkiaStringSizeService and measuring strings in general seems off.

Open lucapivato opened this issue 2 years ago • 2 comments

Apparently Skia is used in Chrome as well. However, it seems that the measuring of strings in Microsoft.Maui.Graphics.Skia.SkiaStringSizeService incorrectly uses the passed in font size as the height.

In Chrome or Edge

var el = document.createElement("div"); document.body.append(el); el.innerText = "Hello, Maui.Graphics!" el.style.fontFamily="Arial" el.style.fontSize="13px" el.clientHeight

15

15 is the correct height of the text when setting the font size to 13px for Arial. This value is returned by Chrome and Edge, both apparently using Skia.

I get the same correct value the good old gdi+ and libgdiplus setting the font size to 13 pixels, the height is 15.

image

But Microsoft.Maui.Graphics.Skia.SkiaStringSizeService always returns the incorrect height simply returning the size.

Is there a settings I'm missing or an additional way to measure a string correctly?

lucapivato avatar Jun 24 '22 15:06 lucapivato

Use libgdiplus. this library is broken and incomplete

janseris avatar Jun 26 '22 07:06 janseris

Yes we are. I’m planning for a feasible replacement. Ms seems determined to block usage of libgdiplus at some point. Aspose has a fully managed system.drawing library but the oem license is unworkable for us.

Another option is to simply take over libgdiplus code for our needs (which are very modest). The c code is relatively small and well written and easy to maintain for c/c++ developers. Cairo seems to work well too.

Otherwise I’d have to dig into chromium’s usage of skia to see how it measures text blocks (with horizontal constraints, etc) since it seems not to be implemented in skia by itself. But I may be wrong since I haven’t spent time on this part yet.

--

Ice Tea Group http://wisej.com http://iceteagroup.com +1-202-449-3778 x701

lucapivato avatar Jun 26 '22 07:06 lucapivato