MCPcopy Index your code
hub / github.com/JetBrains/skija / TextLineTest

Class TextLineTest

tests/java/TextLineTest.java:10–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

makeFromFileMethod · 0.95

Tested by

no test coverage detected