MCPcopy Create free account
hub / github.com/JetBrains/skija / execute

Method execute

tests/java/paragraph/FontCollectionTest.java:16–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15public class FontCollectionTest implements Executable {
16 @Override
17 public void execute() throws Exception {
18 TypefaceFontProvider fm = new TypefaceFontProvider();
19 Typeface jbMono = Typeface.makeFromFile("fonts/JetBrainsMono-Regular.ttf", 0);
20 fm.registerTypeface(jbMono);
21 Typeface inter = Typeface.makeFromFile("fonts/InterHinted-Regular.ttf", 0);
22 fm.registerTypeface(inter, "Interface");
23
24 // FontCollection
25 FontCollection fc = new FontCollection();
26 fc.setAssetFontManager(fm);
27 assertEquals(1L, fc.getFontManagersCount());
28
29 assertEquals(2, jbMono.getRefCount());
30 try (var jbMono2 = fc.findTypefaces(new String[] { "JetBrains Mono" }, FontStyle.NORMAL)[0]) {
31 assertEquals(4, jbMono.getRefCount());
32 assertEquals(4, jbMono2.getRefCount());
33 try (var jbMono3 = fc.findTypefaces(new String[] { "JetBrains Mono" }, FontStyle.NORMAL)[0]) {
34 assertEquals(5, jbMono.getRefCount());
35 assertEquals(5, jbMono2.getRefCount());
36 assertEquals(5, jbMono3.getRefCount());
37 }
38 assertEquals(4, jbMono.getRefCount());
39 assertEquals(4, jbMono2.getRefCount());
40 }
41 assertEquals(3, jbMono.getRefCount());
42
43 assertArrayEquals(new Typeface[] {}, fc.findTypefaces(new String[] { "No Such Font" }, FontStyle.NORMAL));
44 assertArrayEquals(new Typeface[] { jbMono }, fc.findTypefaces(new String[] { "JetBrains Mono" }, FontStyle.NORMAL));
45 assertArrayEquals(new Typeface[] {}, fc.findTypefaces(new String[] { "Inter" }, FontStyle.NORMAL));
46 assertArrayEquals(new Typeface[] { inter }, fc.findTypefaces(new String[] { "Interface" }, FontStyle.NORMAL));
47 assertArrayEquals(new Typeface[] { jbMono, inter }, fc.findTypefaces(new String[] { "JetBrains Mono", "Interface" }, FontStyle.NORMAL));
48
49 // default fm
50 var defaultFM = FontMgr.getDefault();
51 fc.setDefaultFontManager(defaultFM);
52
53 assertEquals(2L, fc.getFontManagersCount());
54 assertEquals(3, defaultFM.getRefCount());
55 try (var ffm = fc.getFallbackManager()) {
56 assertEquals(4, defaultFM.getRefCount());
57 assertEquals(defaultFM, ffm);
58 }
59 assertEquals(3, defaultFM.getRefCount());
60
61 // Fallback fonts
62
63 // skbug.com/10325
64 // try (var t1 = fc.defaultFallback();) {
65 // assertEquals(2, t1.getRefCount());
66 // try (var t2 = fc.defaultFallback();) {
67 // assertEquals(3, t1.getRefCount());
68 // assertEquals(3, t2.getRefCount());
69 // assertEquals(t1, t2);
70 // try (var t3 = fc.defaultFallback();) {
71 // assertEquals(4, t1.getRefCount());
72 // assertEquals(4, t2.getRefCount());
73 // assertEquals(4, t3.getRefCount());

Callers

nothing calls this directly

Calls 13

makeFromFileMethod · 0.95
registerTypefaceMethod · 0.95
setAssetFontManagerMethod · 0.95
getFontManagersCountMethod · 0.95
findTypefacesMethod · 0.95
getDefaultMethod · 0.95
setDefaultFontManagerMethod · 0.95
getFallbackManagerMethod · 0.95
defaultFallbackMethod · 0.95
assertEqualsMethod · 0.80
getRefCountMethod · 0.80
assertArrayEqualsMethod · 0.80

Tested by

no test coverage detected