Line metrics incorrect with UTF-16 surrogate pairs
Closed this issue ยท 3 comments
dzaima commented
The code
String[] families = {"DejaVu Sans Mono"};
FontCollection fc = new FontCollection();
fc.setDefaultFontManager(FontMgr.getDefault());
TextStyle ts = new TextStyle().setColor(0xffD2D2D2).setFontSize(20).setFontFamilies(families);
StrutStyle ss = new StrutStyle()
.setFontFamilies(families)
.setFontStyle(FontStyle.BOLD_ITALIC)
.setFontSize(20)
.setHeight(2)
.setLeading(3)
.setEnabled(true)
.setHeightForced(true)
.setHeightOverridden(true);
ParagraphStyle ps = new ParagraphStyle().setTextStyle(ts).setStrutStyle(ss);
ParagraphBuilder b = new ParagraphBuilder(ps, fc);
b.addText("๐จ๐จ๐จ๐จ๐จ");
Paragraph p = b.build();
b.close();
p.layout(Float.POSITIVE_INFINITY);
System.out.println(p.getLineMetrics()[0].getEndIndex());
prints 6
. But each ๐จ
is two char
s, so the expected result is 10
.
64-bit Linux, Skija version 0.98.0
dzaima commented
looks like the skia function was changed to already return UTF-16 indices after Skija implemented it's own mapping.
dzaima commented
Can confirm that reverting this fixes that, and the line metrics work correctly with UTF-16.
tonsky commented
Fixed, should become available soon as 0.98.1