Saivignesh S
01/13/2025, 6:02 AMval font = loadFontFromUrl("Roboto/Roboto-Regular.ttf")
font.size = 12 * 1.33f
println("Width : ${font.measureTextWidth("Lorem")}")
Width printed in Web (JS): 42.0
JVM Code:
val typeface = Typeface.makeFromFile("kotlin/Roboto-Regular.ttf")
var font = Font()
font.setTypeface(typeface)
font.size = 12 * 1.33f
println("Width : ${font.measureTextWidth("Lorem")}")
Width printed in JVM: 45.53432
Problem:
• The width of the same text "Lorem"
is calculated differently between Web and JVM.
• In Web, the width is 42.0
, while in JVM, it’s 45.53432
.
I’m using the same font ("Roboto-Regular.ttf") and setting the same size (12 * 1.33f
), so I don't understand why the widths are different.
Here, 1.33f used for ( pt to px conversion ).
Has anyone experienced something like this or can explain what might be causing this discrepancy?