Android: measureText on a Paint object for italics fonts

I need to calculate pixel lengths for all texts provided by my client. The problem is that they provided only one regular font, and italic style should be displayed by Android. A well-known Android error is that for italic (italicized) fonts, the width of the TextView is not calculated correctly and the end of the text ends.

Do you have any idea on how to correctly calculate the length of these italic texts?

So far I have tried the measureText and getTextWidths methods, but I think the error is somewhere in the Android sources, because the lengths of italic and normal texts are the same.

I found that if there is no italic font and you need to display it, then the skewX parameter is set in the TextView source code on the TextPaint object. Its value is -0.25f.

Do you know what this parameter is, or maybe how to calculate the missing pixels based on this skewX factor?

+6
source share
1 answer

You can use the thin space "\u2009" to measure text. Then draw it before drawing it. Aligning the text center can give a better result.

0
source

Source: https://habr.com/ru/post/893055/


All Articles