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

Method draw

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

Source from the content-addressed store, hash-verified

28 }
29
30 @Override
31 public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos) {
32 canvas.translate(30, 30);
33
34 try (var ts = new TextStyle().setColor(0xFFcc3333)) {
35 assert 0xFFcc3333 == ts.getColor();
36 drawLine(canvas, "Shall I compare thee to a summer’s day?", ts);
37 }
38
39 try (Shader sh = Shader.makeLinearGradient(0, 0, 0, 13, new int[] { 0xFF3A1C71, 0xFFD76D77, 0xFFFFAF7B });
40 Paint p = new Paint().setShader(sh);
41 var ts = new TextStyle().setForeground(p)) {
42 assert p.equals(ts.getForeground());
43 drawLine(canvas, "Thou art more lovely and more temperate:", ts);
44 ts.setForeground(null);
45 assert null == ts.getForeground();
46 }
47
48 try (Shader sh = Shader.makeLinearGradient(0, 0, 0, 13, new int[] { 0xFF3A1C71, 0xFFD76D77, 0xFFFFAF7B });
49 Paint p = new Paint().setShader(sh);
50 var ts = new TextStyle().setBackground(p)) {
51 assert p.equals(ts.getBackground());
52 drawLine(canvas, "Rough winds do shake the darling buds of May,", ts);
53 }
54
55 var d = DecorationStyle.NONE.withUnderline(true).withColor(0xFF3A1C71);
56 try (var ts = new TextStyle().setColor(0xFF000000).setDecorationStyle(d)) {
57 assert d.equals(ts.getDecorationStyle()) : "Expected " + d + ", got " + ts.getDecorationStyle();
58 assert d.hasUnderline() && !d.hasOverline() && !d.hasLineThrough();
59 drawLine(canvas, "And summer’s lease hath all too short a date;", ts);
60 }
61
62 d = DecorationStyle.NONE.withUnderline(true).withColor(0xFFFFAF7B).withGaps(false);
63 try (var ts = new TextStyle().setColor(0xFF000000).setDecorationStyle(d)) {
64 assert d.equals(ts.getDecorationStyle());
65 drawLine(canvas, "Sometime too hot the eye of heaven shines,", ts);
66 }
67
68 for (var lineStyle: DecorationLineStyle.values()) {
69 d = DecorationStyle.NONE.withUnderline(true).withColor(0xFF3A1C71).withLineStyle(lineStyle);
70 try (var ts = new TextStyle().setColor(0xFF000000).setDecorationStyle(d)) {
71 assert d.equals(ts.getDecorationStyle());
72 drawLine(canvas, "And often is his gold complexion dimm'd; (opaque gyroscope)", ts);
73 }
74 }
75
76 d = DecorationStyle.NONE.withOverline(true).withLineThrough(true).withColor(0xFFD76D77).withThicknessMultiplier(3);
77 try (var ts = new TextStyle().setColor(0xFF000000).setDecorationStyle(d)) {
78 assert d.equals(ts.getDecorationStyle());
79 assert !d.hasUnderline() && d.hasOverline() && d.hasLineThrough();
80 drawLine(canvas, "And every fair from fair sometime declines,", ts);
81 }
82
83 try (var ts = new TextStyle().setColor(0xFF000000).setFontStyle(FontStyle.BOLD_ITALIC)) {
84 assert FontStyle.BOLD_ITALIC.equals(ts.getFontStyle());
85 drawLine(canvas, "By chance or nature’s changing course untrimm'd;", ts);
86 }
87

Callers

nothing calls this directly

Calls 15

drawLineMethod · 0.95
makeLinearGradientMethod · 0.95
parseMethod · 0.95
setShaderMethod · 0.80
setForegroundMethod · 0.80
getForegroundMethod · 0.80
setDecorationStyleMethod · 0.80
getDecorationStyleMethod · 0.80
hasUnderlineMethod · 0.80
hasOverlineMethod · 0.80
hasLineThroughMethod · 0.80
addShadowsMethod · 0.80

Tested by

no test coverage detected