HumbleUI / Skija

Java bindings for Skia
Apache License 2.0
501 stars 34 forks source link

Line metrics incorrect with UTF-16 surrogate pairs #9

Closed dzaima closed 2 years ago

dzaima commented 2 years ago

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 chars, so the expected result is 10.

64-bit Linux, Skija version 0.98.0

dzaima commented 2 years ago

looks like the skia function was changed to already return UTF-16 indices after Skija implemented it's own mapping.

dzaima commented 2 years ago

Can confirm that reverting this fixes that, and the line metrics work correctly with UTF-16.

tonsky commented 2 years ago

Fixed, should become available soon as 0.98.1