MCPcopy Index your code
hub / github.com/HumbleUI/Skija / TextLineTest

Class TextLineTest

tests/java/TextLineTest.java:11–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import io.github.humbleui.skija.test.runner.*;
10
11public class TextLineTest implements Executable {
12 public Font inter36 = new Font(FontMgr.getDefault().makeFromFile("fonts/InterHinted-Regular.ttf"), 36);
13 public Font firaCode36 = new Font(FontMgr.getDefault().makeFromFile("fonts/FiraCode-Regular.ttf"), 36);
14 public Font jbMono36 = new Font(FontMgr.getDefault().makeFromFile("fonts/JetBrainsMono-Regular.ttf"), 36);
15
16 @Override
17 public void execute() throws Exception {
18 testAbc();
19 testLigatures();
20 testCombining();
21 testEmoji();
22 }
23
24 public void testAbc() {
25 try (TextLine line = TextLine.make("abc", inter36);) {
26 assertArrayEquals(new short[] {503, 574, 581}, line.getGlyphs());
27 assertArrayEquals(new int[] {0, 1, 2, 3}, TextLine._nGetBreakOffsets(line._ptr));
28 assertArrayEquals(new float[] {0f, 20f, 42f, 62f}, TextLine._nGetBreakPositions(line._ptr));
29
30 pushStack("getOffsetAtCoord");
31 assertEquals(0, line.getOffsetAtCoord(-10f)); // before “a”
32
33 assertEquals(0, line.getOffsetAtCoord(0f)); // beginning of “a”
34 assertEquals(0, line.getOffsetAtCoord(5f)); // left half of “a”
35 assertEquals(1, line.getOffsetAtCoord(10f)); // center of “a”
36 assertEquals(1, line.getOffsetAtCoord(15f)); // right half of “a”
37
38 assertEquals(1, line.getOffsetAtCoord(20f)); // between “a” and “b”
39 assertEquals(1, line.getOffsetAtCoord(25f)); // left half of “b”
40 assertEquals(2, line.getOffsetAtCoord(31f)); // center of “b”
41 assertEquals(2, line.getOffsetAtCoord(36f)); // right half of “b”
42
43 assertEquals(2, line.getOffsetAtCoord(42f)); // between “b” and “c”
44 assertEquals(2, line.getOffsetAtCoord(47f)); // left half of “c”
45 assertEquals(3, line.getOffsetAtCoord(52f)); // center of “c”
46 assertEquals(3, line.getOffsetAtCoord(57f)); // right half of “c”
47
48 assertEquals(3, line.getOffsetAtCoord(62f)); // end of “c”
49 assertEquals(3, line.getOffsetAtCoord(100f)); // after “c”
50 popStack();
51
52 pushStack("getLeftOffsetAtCoord");
53 assertEquals(0, line.getLeftOffsetAtCoord(-10f)); // before “a”
54
55 assertEquals(0, line.getLeftOffsetAtCoord(0f)); // beginning of “a”
56 assertEquals(0, line.getLeftOffsetAtCoord(5f)); // left half of “a”
57 assertEquals(0, line.getLeftOffsetAtCoord(10f)); // center of “a”
58 assertEquals(0, line.getLeftOffsetAtCoord(15f)); // right half of “a”
59
60 assertEquals(1, line.getLeftOffsetAtCoord(20f)); // between “a” and “b”
61 assertEquals(1, line.getLeftOffsetAtCoord(25f)); // left half of “b”
62 assertEquals(1, line.getLeftOffsetAtCoord(31f)); // center of “b”
63 assertEquals(1, line.getLeftOffsetAtCoord(36f)); // right half of “b”
64
65 assertEquals(2, line.getLeftOffsetAtCoord(42f)); // between “b” and “c”
66 assertEquals(2, line.getLeftOffsetAtCoord(47f)); // left half of “c”
67 assertEquals(2, line.getLeftOffsetAtCoord(52f)); // center of “c”
68 assertEquals(2, line.getLeftOffsetAtCoord(57f)); // right half of “c”

Callers

nothing calls this directly

Calls 2

getDefaultMethod · 0.95
makeFromFileMethod · 0.45

Tested by

no test coverage detected