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

Method draw

examples/scenes/src/TextShapeBenchScene.java:37–84  ·  view source on GitHub ↗
(Canvas canvas, int width, int height, float dpi, int xpos, int ypos)

Source from the content-addressed store, hash-verified

35 }
36
37 @Override
38 public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos) {
39 var variant = _variants[_variantIdx].split(" ");
40 String text = variant[0];
41 if ("Tabs".equals(variant[0]))
42 text = " ";
43 else if ("Emoji".equals(variant[0]))
44 text = "😀 😃 😄 😁 😆 😅 😂 ☺️ 😇 😍";
45 else if ("Greek".equals(variant[0]))
46 text = "ἔοικα γοῦν τούτου γε σμικρῷ τινι αὐτῷ τούτῳ σοφώτερος εἶναι, ὅτι ἃ μὴ οἶδα οὐδὲ οἴομαι εἰδέναι";
47 else if ("Notdef".equals(variant[0]))
48 text = "\u20C0\u20C0\u20C0\u20C0\u20C0\u20C0\u20C0\u20C0\u20C0\u20C0";
49 else if ("English".equals(variant[0]))
50 text = "In girum imus nocte et consumimur igni";
51
52 if ("Paragraph".equals(variant[1])) {
53 if (variant.length > 2) // No-Cache
54 fc.getParagraphCache().reset();
55 for (int i = 1; true; ++i) {
56 float y = i * padding;
57 if (y > height - padding) break;
58 try (TextStyle ts = new TextStyle().setColor(0xFF000000).setFontFamilies(new String [] {"JetBrains Mono"}).setFontSize(fontSize);
59 ParagraphStyle ps = new ParagraphStyle();
60 ParagraphBuilder pb = new ParagraphBuilder(ps, fc);)
61 {
62 pb.pushStyle(ts);
63 pb.addText(i + " [" + text + "]");
64 try (Paragraph p = pb.build();) {
65 p.layout(Float.POSITIVE_INFINITY);
66 p.paint(canvas, padding, y);
67 }
68 }
69 }
70 } else {
71 try (var shaper = Shaper.makeShapeDontWrapOrReorder();) {
72 for (int i = 1; true; ++i) {
73 float y = i * padding;
74 if (y > height - padding) break;
75 try (var line = shaper.shapeLine(i + " [" + text + "]", font, null, true);) {
76 canvas.drawTextLine(line, padding, y - metrics.getAscent(), blackFill);
77 canvas.drawRect(Rect.makeXYWH(padding, y, line.getWidth(), metrics.getHeight()), redStroke);
78 for (float x: TextLine._nGetRunPositions(line._ptr))
79 canvas.drawLine(padding + x, y, padding + x, y + metrics.getHeight(), redStroke);
80 }
81 }
82 }
83 }
84 }
85}

Callers

nothing calls this directly

Calls 15

makeXYWHMethod · 0.95
_nGetRunPositionsMethod · 0.95
getParagraphCacheMethod · 0.80
pushStyleMethod · 0.80
addTextMethod · 0.80
layoutMethod · 0.80
shapeLineMethod · 0.80
drawTextLineMethod · 0.80
getAscentMethod · 0.80
drawRectMethod · 0.80
getWidthMethod · 0.65

Tested by

no test coverage detected