Debian Codegraph @

modules/skparagraph/slides/ParagraphSlide.cpp

raw
1 // Copyright 2019 Google LLC.
2 #include "include/core/SkCanvas.h"
3 #include "include/core/SkColorFilter.h"
4 #include "include/core/SkFontMgr.h"
5 #include "include/core/SkGraphics.h"
6 #include "include/core/SkPath.h"
7 #include "include/core/SkPathBuilder.h"
8 #include "include/core/SkRegion.h"
9 #include "include/core/SkShader.h"
10 #include "include/core/SkStream.h"
11 #include "include/core/SkTextBlob.h"
12 #include "include/core/SkTypeface.h"
13 #include "include/effects/SkGradient.h"
14 #include "modules/skparagraph/include/Paragraph.h"
15 #include "modules/skparagraph/include/TypefaceFontProvider.h"
16 #include "modules/skparagraph/src/ParagraphBuilderImpl.h"
17 #include "modules/skparagraph/src/ParagraphImpl.h"
18 #include "modules/skparagraph/src/TextLine.h"
19 #include "modules/skparagraph/utils/TestFontCollection.h"
20 #include "modules/skshaper/utils/FactoryHelpers.h"
21 #include "src/base/SkRandom.h"
22 #include "src/base/SkTime.h"
23 #include "src/base/SkUTF.h"
24 #include "src/core/SkColorPriv.h"
25 #include "src/core/SkOSFile.h"
26 #include "src/utils/SkOSPath.h"
27 #include "tools/Resources.h"
28 #include "tools/flags/CommandLineFlags.h"
29 #include "tools/fonts/FontToolUtils.h"
30 #include "tools/viewer/ClickHandlerSlide.h"
31
32 static DEFINE_bool(verboseParagraph, false, "paragraph samples very verbose.");
33
34 using namespace skia::textlayout;
35 namespace {
36
37 static sk_sp<SkUnicode> get_unicode() {
38 auto factory = SkShapers::BestAvailable();
39 return sk_ref_sp<SkUnicode>(factory->getUnicode());
40 }
41
42 class ParagraphSlide_Base : public ClickHandlerSlide {
43 public:
44 void load(SkScalar w, SkScalar h) override { fSize = {w, h}; }
45
46 void resize(SkScalar w, SkScalar h) override { fSize = {w, h}; }
47
48 protected:
49 Click * onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
50 return nullptr;
51 }
52 bool onClick(ClickHandlerSlide::Click *) override { return false; }
53
54 sk_sp<TestFontCollection> getFontCollection() {
55 // If we reset font collection we need to reset paragraph cache
56 static sk_sp<TestFontCollection> fFC = nullptr;
57 if (fFC == nullptr) {
58 fFC = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
59 }
60 return fFC;
61 }
62
63 bool isVerbose() {
64 return FLAGS_verboseParagraph;
65 }
66
67 SkSize size() const { return fSize; }
68
69 private:
70 SkSize fSize;
71 };
72
73 sk_sp<SkShader> setgrad(const SkRect& r, SkColor c0, SkColor c1) {
74 SkColor4f colors[] = {SkColor4f::FromColor(c0), SkColor4f::FromColor(c1)};
75 SkPoint pts[] = {{r.fLeft, r.fTop}, {r.fRight, r.fTop}};
76 return SkShaders::LinearGradient(pts, {{colors, {}, SkTileMode::kClamp}, {}});
77 }
78 /*
79 void writeHtml(const char* name, Paragraph* paragraph) {
80 SkString tmpDir = skiatest::GetTmpDir();
81 if (!tmpDir.isEmpty()) {
82 SkString path = SkOSPath::Join(tmpDir.c_str(), name);
83 SkFILEWStream file(path.c_str());
84 file.write(nullptr, 0);
85 }
86 }
87 */
88
89 class ParagraphSlide1 : public ParagraphSlide_Base {
90 public:
91 ParagraphSlide1() { fName = "Paragraph1"; }
92
93 void draw(SkCanvas* canvas) override {
94 drawTest(canvas, this->size().width(), this->size().height(), SK_ColorRED, SK_ColorWHITE);
95 }
96
97 protected:
98 void drawTest(SkCanvas* canvas, SkScalar w, SkScalar h, SkColor fg, SkColor bg) {
99 const std::vector<
100 std::tuple<std::string, bool, bool, int, SkColor, SkColor, bool, TextDecorationStyle>>
101 gParagraph = {{"monospace", true, false, 14, SK_ColorWHITE, SK_ColorRED, true,
102 TextDecorationStyle::kDashed},
103 {"Assyrian", false, false, 20, SK_ColorWHITE, SK_ColorBLUE, false,
104 TextDecorationStyle::kDotted},
105 {"serif", true, true, 10, SK_ColorWHITE, SK_ColorRED, true,
106 TextDecorationStyle::kDouble},
107 {"Arial", false, true, 16, SK_ColorGRAY, SK_ColorGREEN, true,
108 TextDecorationStyle::kSolid},
109 {"sans-serif", false, false, 8, SK_ColorWHITE, SK_ColorRED, false,
110 TextDecorationStyle::kWavy}};
111 SkAutoCanvasRestore acr(canvas, true);
112
113 canvas->clipRect(SkRect::MakeWH(w, h));
114 canvas->drawColor(SK_ColorWHITE);
115
116 SkScalar margin = 20;
117
118 SkPaint paint;
119 paint.setAntiAlias(true);
120 paint.setColor(fg);
121
122 SkPaint blue;
123 blue.setColor(SK_ColorBLUE);
124
125 TextStyle defaultStyle;
126 defaultStyle.setBackgroundColor(blue);
127 defaultStyle.setForegroundColor(paint);
128 ParagraphStyle paraStyle;
129
130 auto fontCollection = sk_make_sp<FontCollection>();
131 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
132 for (auto i = 1; i < 5; ++i) {
133 defaultStyle.setFontSize(24 * i);
134 paraStyle.setTextStyle(defaultStyle);
135 ParagraphBuilderImpl builder(paraStyle, fontCollection, get_unicode());
136 std::string name = "Paragraph: " + std::to_string(24 * i);
137 builder.addText(name.c_str(), name.length());
138 for (auto para : gParagraph) {
139 TextStyle style;
140 style.setFontFamilies({SkString(std::get<0>(para).c_str())});
141 SkFontStyle fontStyle(std::get<1>(para) ? SkFontStyle::Weight::kBold_Weight
142 : SkFontStyle::Weight::kNormal_Weight,
143 SkFontStyle::Width::kNormal_Width,
144 std::get<2>(para) ? SkFontStyle::Slant::kItalic_Slant
145 : SkFontStyle::Slant::kUpright_Slant);
146 style.setFontStyle(fontStyle);
147 style.setFontSize(std::get<3>(para) * i);
148 SkPaint background;
149 background.setColor(std::get<4>(para));
150 style.setBackgroundColor(background);
151 SkPaint foreground;
152 foreground.setColor(std::get<5>(para));
153 foreground.setAntiAlias(true);
154 style.setForegroundColor(foreground);
155 if (std::get<6>(para)) {
156 style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(5, 5), 2));
157 }
158
159 auto decoration = (i % 4);
160 if (decoration == 3) {
161 decoration = 4;
162 }
163
164 bool test = (TextDecoration)decoration != TextDecoration::kNoDecoration;
165 std::string deco = std::to_string((int)decoration);
166 if (test) {
167 style.setDecoration((TextDecoration)decoration);
168 style.setDecorationStyle(std::get<7>(para));
169 style.setDecorationColor(std::get<5>(para));
170 }
171 builder.pushStyle(style);
172 name = " " + std::get<0>(para) + " " +
173 (std::get<1>(para) ? ", bold" : "") +
174 (std::get<2>(para) ? ", italic" : "") + " " +
175 std::to_string(std::get<3>(para) * i) +
176 (std::get<4>(para) != bg ? ", background" : "") +
177 (std::get<5>(para) != fg ? ", foreground" : "") +
178 (std::get<6>(para) ? ", shadow" : "") +
179 (test ? ", decorations " + deco : "") + ";";
180 builder.addText(name.c_str(), name.length());
181 builder.pop();
182 }
183
184 auto paragraph = builder.Build();
185 paragraph->layout(w - margin * 2);
186 paragraph->paint(canvas, margin, margin);
187
188 canvas->translate(0, paragraph->getHeight());
189 }
190 }
191 };
192
193 class ParagraphSlide2 : public ParagraphSlide_Base {
194 public:
195 ParagraphSlide2() { fName = "Paragraph2"; }
196
197 void draw(SkCanvas* canvas) override {
198 std::vector<const char*> cupertino = {
199 "google_logogoogle_gsuper_g_logo 1 "
200 "google_logogoogle_gsuper_g_logo 12 "
201 "google_logogoogle_gsuper_g_logo 123 "
202 "google_logogoogle_gsuper_g_logo 1234 "
203 "google_logogoogle_gsuper_g_logo 12345 "
204 "google_logogoogle_gsuper_g_logo 123456 "
205 "google_logogoogle_gsuper_g_logo 1234567 "
206 "google_logogoogle_gsuper_g_logo 12345678 "
207 "google_logogoogle_gsuper_g_logo 123456789 "
208 "google_logogoogle_gsuper_g_logo 1234567890 "
209 "google_logogoogle_gsuper_g_logo 123456789 "
210 "google_logogoogle_gsuper_g_logo 12345678 "
211 "google_logogoogle_gsuper_g_logo 1234567 "
212 "google_logogoogle_gsuper_g_logo 123456 "
213 "google_logogoogle_gsuper_g_logo 12345 "
214 "google_logogoogle_gsuper_g_logo 1234 "
215 "google_logogoogle_gsuper_g_logo 123 "
216 "google_logogoogle_gsuper_g_logo 12 "
217 "google_logogoogle_gsuper_g_logo 1 "
218 "google_logogoogle_gsuper_g_logo "
219 "google_logogoogle_gsuper_g_logo "
220 "google_logogoogle_gsuper_g_logo "
221 "google_logogoogle_gsuper_g_logo "
222 "google_logogoogle_gsuper_g_logo "
223 "google_logogoogle_gsuper_g_logo"};
224 std::vector<const char*> text = {
225 "My neighbor came over to say,\n"
226 "Although not in a neighborly way,\n\n"
227 "That he'd knock me around,\n\n\n"
228 "If I didn't stop the sound,\n\n\n\n"
229 "Of the classical music I play."};
230
231 std::vector<const char*> long_word = {
232 "A_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
233 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
234 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
235 "very_very_very_very_very_very_very_long_text"};
236
237 std::vector<const char*> very_long = {
238 "A very very very very very very very very very very very very very very very very "
239 "very very very very very very very very very very very very very very very very "
240 "very very very very very very very very very very very very very very very very "
241 "very very very very very very very long text"};
242
243 std::vector<const char*> very_word = {
244 "A very_very_very_very_very_very_very_very_very_very "
245 "very_very_very_very_very_very_very_very_very_very very very very very very very "
246 "very very very very very very very very very very very very very very very very "
247 "very very very very very very very very very very very very very long text"};
248
249 SkScalar width = this->size().width() / 5;
250 SkScalar height = this->size().height();
251 drawText(canvas, width, height, long_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
252 canvas->translate(width, 0);
253 drawText(canvas, width, height, very_long, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
254 canvas->translate(width, 0);
255 drawText(canvas, width, height, very_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
256 canvas->translate(width, 0);
257 drawText(canvas, width, height / 2, text, SK_ColorBLACK, SK_ColorWHITE, "Roboto", 20, 100,
258 u"\u2026");
259 canvas->translate(0, height / 2);
260 drawCode(canvas, width, height / 2);
261 canvas->translate(width, -height / 2);
262
263 drawText(canvas, width, height, cupertino, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
264 }
265
266 private:
267 void drawCode(SkCanvas* canvas, SkScalar w, SkScalar h) {
268 SkPaint comment;
269 comment.setColor(SK_ColorGRAY);
270 SkPaint constant;
271 constant.setColor(SK_ColorMAGENTA);
272 SkPaint null;
273 null.setColor(SK_ColorMAGENTA);
274 SkPaint literal;
275 literal.setColor(SK_ColorGREEN);
276 SkPaint code;
277 code.setColor(SK_ColorDKGRAY);
278 SkPaint number;
279 number.setColor(SK_ColorBLUE);
280 SkPaint name;
281 name.setColor(SK_ColorRED);
282
283 SkPaint white;
284 white.setColor(SK_ColorWHITE);
285
286 TextStyle defaultStyle;
287 defaultStyle.setBackgroundColor(white);
288 defaultStyle.setForegroundColor(code);
289 defaultStyle.setFontFamilies({SkString("monospace")});
290 defaultStyle.setFontSize(30);
291 ParagraphStyle paraStyle;
292 paraStyle.setTextStyle(defaultStyle);
293
294 auto fontCollection = sk_make_sp<FontCollection>();
295 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
296 ParagraphBuilderImpl builder(paraStyle, fontCollection, get_unicode());
297
298 const char* text1 = "RaisedButton";
299 const char* text2 = "(\n";
300 const char* text3 = " child: ";
301 const char* text4 = "const";
302 const char* text5 = "Text";
303 const char* text6 = "'BUTTON TITLE'";
304 const char* text7 = "),\n";
305
306 builder.pushStyle(style(name));
307 builder.addText(text1, strlen(text1));
308 builder.pop();
309 builder.addText(text2, strlen(text2));
310 builder.addText(text3, strlen(text3));
311 builder.pushStyle(style(constant));
312 builder.addText(text4, strlen(text4));
313 builder.pop();
314 builder.addText(" ", 1);
315 builder.pushStyle(style(name));
316 builder.addText(text5, strlen(text5));
317 builder.pop();
318 builder.addText("(", 1);
319 builder.pushStyle(style(literal));
320 builder.addText(text6, strlen(text6));
321 builder.pop();
322 builder.addText(text7, strlen(text7));
323
324 auto paragraph = builder.Build();
325 paragraph->layout(w - 20);
326
327 paragraph->paint(canvas, 20, 20);
328 }
329
330 TextStyle style(SkPaint paint) {
331 TextStyle style;
332 paint.setAntiAlias(true);
333 style.setForegroundColor(paint);
334 style.setFontFamilies({SkString("monospace")});
335 style.setFontSize(30);
336
337 return style;
338 }
339
340 void drawText(SkCanvas* canvas, SkScalar w, SkScalar h, std::vector<const char*>& text,
341 SkColor fg = SK_ColorDKGRAY, SkColor bg = SK_ColorWHITE,
342 const char* ff = "sans-serif", SkScalar fs = 24,
343 size_t lineLimit = 30,
344 const std::u16string& ellipsis = u"\u2026") {
345 SkAutoCanvasRestore acr(canvas, true);
346
347 canvas->clipRect(SkRect::MakeWH(w, h));
348 canvas->drawColor(bg);
349
350 SkScalar margin = 20;
351
352 SkPaint paint;
353 paint.setAntiAlias(true);
354 paint.setColor(fg);
355
356 SkPaint blue;
357 blue.setColor(SK_ColorBLUE);
358
359 SkPaint background;
360 background.setColor(bg);
361
362 TextStyle style;
363 style.setBackgroundColor(blue);
364 style.setForegroundColor(paint);
365 style.setFontFamilies({SkString(ff)});
366 style.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight,
367 SkFontStyle::kNormal_Width,
368 SkFontStyle::kUpright_Slant));
369 style.setFontSize(fs);
370 ParagraphStyle paraStyle;
371 paraStyle.setTextStyle(style);
372 paraStyle.setMaxLines(lineLimit);
373
374 paraStyle.setEllipsis(ellipsis);
375 TextStyle defaultStyle;
376 defaultStyle.setFontSize(20);
377 paraStyle.setTextStyle(defaultStyle);
378 ParagraphBuilderImpl builder(paraStyle, getFontCollection(), get_unicode());
379
380 SkPaint foreground;
381 foreground.setColor(fg);
382 style.setForegroundColor(foreground);
383 style.setBackgroundColor(background);
384
385 for (auto& part : text) {
386 builder.pushStyle(style);
387 builder.addText(part, strlen(part));
388 builder.pop();
389 }
390
391 auto paragraph = builder.Build();
392 paragraph->layout(w - margin * 2);
393 paragraph->paint(canvas, margin, margin);
394
395 canvas->translate(0, paragraph->getHeight() + margin);
396 }
397
398 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
399 TextAlign align) {
400 SkAutoCanvasRestore acr(canvas, true);
401
402 canvas->clipRect(SkRect::MakeWH(w, h));
403 canvas->drawColor(SK_ColorWHITE);
404
405 SkScalar margin = 20;
406
407 SkPaint paint;
408 paint.setAntiAlias(true);
409 paint.setColor(SK_ColorBLUE);
410
411 SkPaint gray;
412 gray.setColor(SK_ColorLTGRAY);
413
414 TextStyle style;
415 style.setBackgroundColor(gray);
416 style.setForegroundColor(paint);
417 style.setFontFamilies({SkString("Arial")});
418 style.setFontSize(30);
419 ParagraphStyle paraStyle;
420 paraStyle.setTextStyle(style);
421 paraStyle.setTextAlign(align);
422
423 auto fontCollection = sk_make_sp<FontCollection>();
424 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
425 ParagraphBuilderImpl builder(paraStyle, fontCollection, get_unicode());
426 builder.addText(text.c_str(), text.length());
427
428 auto paragraph = builder.Build();
429 paragraph->layout(w - margin * 2);
430 paragraph->layout(w - margin);
431 paragraph->paint(canvas, margin, margin);
432
433 canvas->translate(0, paragraph->getHeight() + margin);
434 }
435 };
436
437 class ParagraphSlide3 : public ParagraphSlide_Base {
438 public:
439 ParagraphSlide3() { fName = "Paragraph3"; }
440
441 void draw(SkCanvas* canvas) override {
442 const std::string options = // { "open-source open-source open-source open-source" };
443 {"Flutter is an open-source project to help developers "
444 "build high-performance, high-fidelity, mobile apps for "
445 "iOS and Android "
446 "from a single codebase. This design lab is a playground "
447 "and showcase of Flutter's many widgets, behaviors, "
448 "animations, layouts, and more."};
449
450 canvas->drawColor(SK_ColorDKGRAY);
451 SkScalar width = this->size().width() / 4;
452 SkScalar height = this->size().height() / 2;
453
454 const std::string line =
455 "World domination is such an ugly phrase - I prefer to call it world optimisation";
456 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, false, SK_ColorLTGRAY);
457 canvas->translate(width, 0);
458 drawLine(canvas, width, height, line, TextAlign::kRight, 2, false, SK_ColorLTGRAY);
459 canvas->translate(width, 0);
460 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, false, SK_ColorLTGRAY);
461 canvas->translate(width, 0);
462 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, false, SK_ColorLTGRAY);
463 canvas->translate(-width * 3, height);
464 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, true, SK_ColorLTGRAY);
465 canvas->translate(width, 0);
466 drawLine(canvas, width, height, line, TextAlign::kRight, 2, true, SK_ColorLTGRAY);
467 canvas->translate(width, 0);
468 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, true, SK_ColorLTGRAY);
469 canvas->translate(width, 0);
470 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, true, SK_ColorLTGRAY);
471 canvas->translate(width, 0);
472 }
473
474 private:
475 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
476 TextAlign align, size_t lineLimit = std::numeric_limits<size_t>::max(),
477 bool RTL = false, SkColor background = SK_ColorGRAY,
478 const std::u16string& ellipsis = u"\u2026") {
479 SkAutoCanvasRestore acr(canvas, true);
480
481 canvas->clipRect(SkRect::MakeWH(w, h));
482 canvas->drawColor(SK_ColorWHITE);
483
484 SkScalar margin = 20;
485
486 SkPaint paint;
487 paint.setAntiAlias(true);
488 paint.setColor(SK_ColorBLACK);
489
490 SkPaint gray;
491 gray.setColor(background);
492
493 SkPaint yellow;
494 yellow.setColor(SK_ColorYELLOW);
495
496 TextStyle style;
497 style.setBackgroundColor(gray);
498 style.setForegroundColor(paint);
499 style.setFontFamilies({SkString("sans-serif")});
500 style.setFontSize(30);
501 ParagraphStyle paraStyle;
502 paraStyle.setTextStyle(style);
503 paraStyle.setTextAlign(align);
504 paraStyle.setMaxLines(lineLimit);
505 paraStyle.setEllipsis(ellipsis);
506 paraStyle.setTextDirection(RTL ? TextDirection::kRtl : TextDirection::kLtr);
507
508 auto fontCollection = sk_make_sp<FontCollection>();
509 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
510 ParagraphBuilderImpl builder(paraStyle, fontCollection, get_unicode());
511 if (RTL) {
512 builder.addText(mirror(text));
513 } else {
514 builder.addText(normal(text));
515 }
516
517 canvas->drawRect(SkRect::MakeXYWH(margin, margin, w - margin * 2, h - margin * 2), yellow);
518 auto paragraph = builder.Build();
519 paragraph->layout(w - margin * 2);
520 paragraph->paint(canvas, margin, margin);
521 }
522
523 std::u16string mirror(const std::string& text) {
524 std::u16string result;
525 result += u"\u202E";
526 // for (auto i = text.size(); i > 0; --i) {
527 // result += text[i - 1];
528 //}
529
530 for (auto i = text.size(); i > 0; --i) {
531 auto ch = text[i - 1];
532 if (ch == ',') {
533 result += u"!";
534 } else if (ch == '.') {
535 result += u"!";
536 } else {
537 result += ch;
538 }
539 }
540
541 result += u"\u202C";
542 return result;
543 }
544
545 std::u16string normal(const std::string& text) {
546 std::u16string result;
547 result += u"\u202D";
548 for (auto ch : text) {
549 result += ch;
550 }
551 result += u"\u202C";
552 return result;
553 }
554 };
555
556 class ParagraphSlide5 : public ParagraphSlide_Base {
557 public:
558 ParagraphSlide5() { fName = "Paragraph5"; }
559
560 void draw(SkCanvas* canvas) override {
561 canvas->drawColor(SK_ColorWHITE);
562 SkScalar width = this->size().width();
563 SkScalar height = this->size().height() / 8;
564
565 const std::u16string text1 =
566 u"A \u202ENAC\u202Cner, exceedingly \u202ENAC\u202Cny,\n"
567 "One morning remarked to his granny:\n"
568 "A \u202ENAC\u202Cner \u202ENAC\u202C \u202ENAC\u202C,\n"
569 "Anything that he \u202ENAC\u202C,\n"
570 "But a \u202ENAC\u202Cner \u202ENAC\u202C't \u202ENAC\u202C a \u202ENAC\u202C, "
571 "\u202ENAC\u202C he?";
572 bidi(canvas, width, height * 3, text1, u"", 5);
573 canvas->translate(0, height * 3);
574
575 bidi(canvas, width, height, u"\u2067DETALOSI\u2069", u"");
576 canvas->translate(0, height);
577
578 bidi(canvas, width, height, u"\u202BDEDDEBME\u202C", u"");
579 canvas->translate(0, height);
580
581 bidi(canvas, width, height, u"\u202EEDIRREVO\u202C", u"");
582 canvas->translate(0, height);
583
584 bidi(canvas, width, height, u"\u200FTICILPMI\u200E", u"");
585 canvas->translate(0, height);
586
587 bidi(canvas,
588 width,
589 height,
590 u"123 456 7890 \u202EZYXWV UTS RQP ONM LKJ IHG FED CBA\u202C.",
591 u"",
592 2);
593 canvas->translate(0, height);
594
595 // bidi(canvas, width, height, u"", u"");
596 // canvas->translate(0, height);
597 }
598
599 private:
600 void bidi(SkCanvas* canvas,
601 SkScalar w,
602 SkScalar h,
603 const std::u16string& text,
604 const std::u16string& expected,
605 size_t lineLimit = std::numeric_limits<size_t>::max(),
606 const char* ff = "Roboto",
607 SkScalar fs = 30,
608 const std::u16string& ellipsis = u"\u2026") {
609 SkAutoCanvasRestore acr(canvas, true);
610
611 canvas->clipRect(SkRect::MakeWH(w, h));
612
613 SkScalar margin = 20;
614
615 SkPaint black;
616 black.setColor(SK_ColorBLACK);
617 SkPaint gray;
618 gray.setColor(SK_ColorLTGRAY);
619
620 TextStyle style;
621 style.setForegroundColor(black);
622 style.setFontFamilies({SkString(ff)});
623 style.setFontSize(fs);
624
625 TextStyle style0;
626 style0.setForegroundColor(black);
627 style0.setFontFamilies({SkString(ff)});
628 style0.setFontSize(fs);
629 style0.setFontStyle(SkFontStyle(SkFontStyle::kNormal_Weight,
630 SkFontStyle::kNormal_Width,
631 SkFontStyle::kItalic_Slant));
632
633 TextStyle style1;
634 style1.setForegroundColor(gray);
635 style1.setFontFamilies({SkString(ff)});
636 style1.setFontSize(fs);
637 style1.setFontStyle(SkFontStyle(SkFontStyle::kBold_Weight,
638 SkFontStyle::kNormal_Width,
639 SkFontStyle::kUpright_Slant));
640
641 ParagraphStyle paraStyle;
642 paraStyle.setTextStyle(style);
643 paraStyle.setMaxLines(lineLimit);
644
645 paraStyle.setEllipsis(ellipsis);
646
647 ParagraphBuilderImpl builder(paraStyle, getFontCollection(), get_unicode());
648
649 if (text.empty()) {
650 const std::u16string text0 = u"\u202Dabc";
651 const std::u16string text1 = u"\u202EFED";
652 const std::u16string text2 = u"\u202Dghi";
653 const std::u16string text3 = u"\u202ELKJ";
654 const std::u16string text4 = u"\u202Dmno";
655 builder.pushStyle(style0);
656 builder.addText(text0);
657 builder.pop();
658 builder.pushStyle(style1);
659 builder.addText(text1);
660 builder.pop();
661 builder.pushStyle(style0);
662 builder.addText(text2);
663 builder.pop();
664 builder.pushStyle(style1);
665 builder.addText(text3);
666 builder.pop();
667 builder.pushStyle(style0);
668 builder.addText(text4);
669 builder.pop();
670 } else {
671 builder.addText(text + expected);
672 }
673
674 auto paragraph = builder.Build();
675 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
676 if (this->isVerbose()) {
677 SkDebugf("Text: >%s<\n", impl->text().data());
678 }
679
680 paragraph->layout(w - margin * 2);
681 paragraph->paint(canvas, margin, margin);
682 }
683 };
684
685 class ParagraphSlide6 : public ParagraphSlide_Base {
686 public:
687 ParagraphSlide6() { fName = "Paragraph6"; }
688
689 void hangingS(SkCanvas* canvas, SkScalar w, SkScalar h, SkScalar fs = 60.0) {
690 auto ff = "HangingS";
691
692 canvas->drawColor(SK_ColorLTGRAY);
693
694 SkPaint black;
695 black.setAntiAlias(true);
696 black.setColor(SK_ColorBLACK);
697
698 SkPaint blue;
699 blue.setAntiAlias(true);
700 blue.setColor(SK_ColorBLUE);
701
702 SkPaint red;
703 red.setAntiAlias(true);
704 red.setColor(SK_ColorRED);
705
706 SkPaint green;
707 green.setAntiAlias(true);
708 green.setColor(SK_ColorGREEN);
709
710 SkPaint gray;
711 gray.setColor(SK_ColorCYAN);
712
713 SkPaint yellow;
714 yellow.setColor(SK_ColorYELLOW);
715
716 SkPaint magenta;
717 magenta.setAntiAlias(true);
718 magenta.setColor(SK_ColorMAGENTA);
719
720 SkFontStyle fontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width,
721 SkFontStyle::kItalic_Slant);
722
723 TextStyle style;
724 style.setFontFamilies({SkString(ff)});
725 style.setFontSize(fs);
726 style.setFontStyle(fontStyle);
727
728 TextStyle style0;
729 style0.setForegroundColor(black);
730 style0.setBackgroundColor(gray);
731 style0.setFontFamilies({SkString(ff)});
732 style0.setFontSize(fs);
733 style0.setFontStyle(fontStyle);
734
735 TextStyle style1;
736 style1.setForegroundColor(blue);
737 style1.setBackgroundColor(yellow);
738 style1.setFontFamilies({SkString(ff)});
739 style1.setFontSize(fs);
740 style1.setFontStyle(fontStyle);
741
742 TextStyle style2;
743 style2.setForegroundColor(red);
744 style2.setFontFamilies({SkString(ff)});
745 style2.setFontSize(fs);
746 style2.setFontStyle(fontStyle);
747
748 TextStyle style3;
749 style3.setForegroundColor(green);
750 style3.setFontFamilies({SkString(ff)});
751 style3.setFontSize(fs);
752 style3.setFontStyle(fontStyle);
753
754 TextStyle style4;
755 style4.setForegroundColor(magenta);
756 style4.setFontFamilies({SkString(ff)});
757 style4.setFontSize(fs);
758 style4.setFontStyle(fontStyle);
759
760 ParagraphStyle paraStyle;
761 paraStyle.setTextStyle(style);
762
763 const char* logo1 = "S";
764 const char* logo2 = "kia";
765 const char* logo3 = "Sk";
766 const char* logo4 = "ia";
767 const char* logo5 = "Ski";
768 const char* logo6 = "a";
769 {
770 ParagraphBuilderImpl builder(paraStyle, getFontCollection(), get_unicode());
771
772 builder.pushStyle(style0);
773 builder.addText(logo1, strlen(logo1));
774 builder.pop();
775 builder.pushStyle(style1);
776 builder.addText(logo2, strlen(logo2));
777 builder.pop();
778
779 builder.addText(" ", 3);
780
781 builder.pushStyle(style0);
782 builder.addText(logo3, strlen(logo3));
783 builder.pop();
784 builder.pushStyle(style1);
785 builder.addText(logo4, strlen(logo4));
786 builder.pop();
787
788 builder.addText(" ", 3);
789
790 builder.pushStyle(style0);
791 builder.addText(logo5, strlen(logo5));
792 builder.pop();
793 builder.pushStyle(style1);
794 builder.addText(logo6, strlen(logo6));
795 builder.pop();
796
797 auto paragraph = builder.Build();
798 paragraph->layout(w);
799 paragraph->paint(canvas, 40, 40);
800 canvas->translate(0, h);
801 }
802
803 const char* logo11 = "S";
804 const char* logo12 = "S";
805 const char* logo13 = "S";
806 const char* logo14 = "S";
807 const char* logo15 = "S";
808 const char* logo16 = "S";
809 {
810 ParagraphBuilderImpl builder(paraStyle, getFontCollection(), get_unicode());
811
812 builder.pushStyle(style0);
813 builder.addText(logo11, strlen(logo11));
814 builder.pop();
815 builder.pushStyle(style1);
816 builder.addText(logo12, strlen(logo12));
817 builder.pop();
818
819 builder.addText(" ", 3);
820
821 builder.pushStyle(style0);
822 builder.addText(logo13, strlen(logo13));
823 builder.pop();
824 builder.pushStyle(style1);
825 builder.addText(logo14, strlen(logo14));
826 builder.pop();
827
828 builder.addText(" ", 3);
829
830 builder.pushStyle(style0);
831 builder.addText(logo15, strlen(logo15));
832 builder.pop();
833 builder.pushStyle(style1);
834 builder.addText(logo16, strlen(logo16));
835 builder.pop();
836
837 auto paragraph = builder.Build();
838 paragraph->layout(w);
839 paragraph->paint(canvas, 40, h);
840 canvas->translate(0, h);
841 }
842 }
843
844 void draw(SkCanvas* canvas) override {
845 canvas->drawColor(SK_ColorWHITE);
846 SkScalar width = this->size().width();
847 SkScalar height = this->size().height() / 4;
848
849 hangingS(canvas, width, height);
850 }
851 };
852
853 class ParagraphSlide7 : public ParagraphSlide_Base {
854 public:
855 ParagraphSlide7() { fName = "Paragraph7"; }
856
857 void drawText(SkCanvas* canvas, SkColor background, SkScalar letterSpace, SkScalar w,
858 SkScalar h) {
859 SkAutoCanvasRestore acr(canvas, true);
860 canvas->clipRect(SkRect::MakeWH(w, h));
861 canvas->drawColor(background);
862
863 const char* line =
864 "World domination is such an ugly phrase - I prefer to call it world optimisation.";
865
866 ParagraphStyle paragraphStyle;
867 paragraphStyle.setTextAlign(TextAlign::kLeft);
868 paragraphStyle.setMaxLines(10);
869 paragraphStyle.turnHintingOff();
870 TextStyle textStyle;
871 textStyle.setFontFamilies({SkString("Roboto")});
872 textStyle.setFontSize(30);
873 textStyle.setLetterSpacing(letterSpace);
874 textStyle.setColor(SK_ColorBLACK);
875 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
876 SkFontStyle::kUpright_Slant));
877
878 ParagraphBuilderImpl builder(paragraphStyle, getFontCollection(), get_unicode());
879 builder.pushStyle(textStyle);
880 builder.addText(line, strlen(line));
881 builder.pop();
882
883 auto paragraph = builder.Build();
884 paragraph->layout(w - 20);
885 paragraph->paint(canvas, 10, 10);
886 }
887
888 void draw(SkCanvas* canvas) override {
889 canvas->drawColor(SK_ColorWHITE);
890
891 auto h = this->size().height() / 4;
892 auto w = this->size().width() / 2;
893
894 drawText(canvas, SK_ColorGRAY, 1, w, h);
895 canvas->translate(0, h);
896
897 drawText(canvas, SK_ColorLTGRAY, 2, w, h);
898 canvas->translate(0, h);
899
900 drawText(canvas, SK_ColorCYAN, 3, w, h);
901 canvas->translate(0, h);
902
903 drawText(canvas, SK_ColorGRAY, 4, w, h);
904 canvas->translate(w, -3 * h);
905
906 drawText(canvas, SK_ColorYELLOW, 5, w, h);
907 canvas->translate(0, h);
908
909 drawText(canvas, SK_ColorGREEN, 10, w, h);
910 canvas->translate(0, h);
911
912 drawText(canvas, SK_ColorRED, 15, w, h);
913 canvas->translate(0, h);
914
915 drawText(canvas, SK_ColorBLUE, 20, w, h);
916 canvas->translate(0, h);
917 }
918 };
919
920 class ParagraphSlide8 : public ParagraphSlide_Base {
921 public:
922 ParagraphSlide8() { fName = "Paragraph8"; }
923
924 void drawText(SkCanvas* canvas, SkColor background, SkScalar wordSpace, SkScalar w,
925 SkScalar h) {
926 SkAutoCanvasRestore acr(canvas, true);
927 canvas->clipRect(SkRect::MakeWH(w, h));
928 canvas->drawColor(background);
929
930 const char* line =
931 "World domination is such an ugly phrase - I prefer to call it world optimisation.";
932
933 ParagraphStyle paragraphStyle;
934 paragraphStyle.setTextAlign(TextAlign::kLeft);
935 paragraphStyle.setMaxLines(10);
936 paragraphStyle.turnHintingOff();
937 TextStyle textStyle;
938 textStyle.setFontFamilies({SkString("Roboto")});
939 textStyle.setFontSize(30);
940 textStyle.setWordSpacing(wordSpace);
941 textStyle.setColor(SK_ColorBLACK);
942 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
943 SkFontStyle::kUpright_Slant));
944
945 ParagraphBuilderImpl builder(paragraphStyle, getFontCollection(), get_unicode());
946 builder.pushStyle(textStyle);
947 builder.addText(line, strlen(line));
948 builder.pop();
949
950 auto paragraph = builder.Build();
951 paragraph->layout(w - 20);
952 paragraph->paint(canvas, 10, 10);
953 }
954
955 void draw(SkCanvas* canvas) override {
956 canvas->drawColor(SK_ColorWHITE);
957
958 auto h = this->size().height() / 4;
959 auto w = this->size().width() / 2;
960
961 drawText(canvas, SK_ColorGRAY, 1, w, h);
962 canvas->translate(0, h);
963
964 drawText(canvas, SK_ColorLTGRAY, 2, w, h);
965 canvas->translate(0, h);
966
967 drawText(canvas, SK_ColorCYAN, 3, w, h);
968 canvas->translate(0, h);
969
970 drawText(canvas, SK_ColorGRAY, 4, w, h);
971 canvas->translate(w, -3 * h);
972
973 drawText(canvas, SK_ColorYELLOW, 5, w, h);
974 canvas->translate(0, h);
975
976 drawText(canvas, SK_ColorGREEN, 10, w, h);
977 canvas->translate(0, h);
978
979 drawText(canvas, SK_ColorRED, 15, w, h);
980 canvas->translate(0, h);
981
982 drawText(canvas, SK_ColorBLUE, 20, w, h);
983 canvas->translate(0, h);
984 }
985 };
986
987 class ParagraphSlide9 : public ParagraphSlide_Base {
988 public:
989 ParagraphSlide9() { fName = "Paragraph9"; }
990
991 bool onChar(SkUnichar uni) override {
992 switch (uni) {
993 case 'w':
994 ++wordSpacing;
995 return true;
996 case 'q':
997 if (wordSpacing > 0) --wordSpacing;
998 return true;
999 case 'l':
1000 ++letterSpacing;
1001 return true;
1002 case 'k':
1003 if (letterSpacing > 0) --letterSpacing;
1004 return true;
1005 default:
1006 break;
1007 }
1008 return false;
1009 }
1010
1011 void drawText(SkCanvas* canvas, SkColor background, SkScalar w, SkScalar h) {
1012 SkAutoCanvasRestore acr(canvas, true);
1013 canvas->clipRect(SkRect::MakeWH(w, h));
1014 canvas->drawColor(background);
1015
1016 auto fontCollection = sk_make_sp<FontCollection>();
1017 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
1018 fontCollection->enableFontFallback();
1019
1020 const char* text =
1021 "( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1022 " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1023 " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)";
1024 auto multiplier = 5.67;
1025 ParagraphStyle paragraphStyle;
1026 paragraphStyle.setTextAlign(TextAlign::kLeft);
1027 paragraphStyle.setMaxLines(10);
1028 paragraphStyle.turnHintingOff();
1029 TextStyle textStyle;
1030 textStyle.setFontFamilies({SkString("Roboto")});
1031 textStyle.setFontSize(5 * multiplier);
1032 textStyle.setHeight(1.3f);
1033 textStyle.setColor(SK_ColorBLACK);
1034 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
1035 SkFontStyle::kUpright_Slant));
1036
1037 ParagraphBuilderImpl builder(paragraphStyle, fontCollection, get_unicode());
1038 builder.pushStyle(textStyle);
1039 builder.addText(text, strlen(text));
1040 builder.pop();
1041
1042 auto paragraph = builder.Build();
1043 paragraph->layout(200 * multiplier);
1044
1045 std::vector<size_t> sizes = {0, 1, 2, 8, 19, 21, 22, 30, 150};
1046
1047 std::vector<size_t> colors = {SK_ColorBLUE, SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGREEN,
1048 SK_ColorRED, SK_ColorWHITE, SK_ColorYELLOW, SK_ColorMAGENTA};
1049
1050 RectHeightStyle rect_height_style = RectHeightStyle::kTight;
1051 RectWidthStyle rect_width_style = RectWidthStyle::kTight;
1052
1053 for (size_t i = 0; i < sizes.size() - 1; ++i) {
1054 size_t from = sizes[i];
1055 size_t to = sizes[i + 1];
1056 auto boxes = paragraph->getRectsForRange(from, to, rect_height_style, rect_width_style);
1057 if (boxes.empty()) {
1058 continue;
1059 }
1060 for (auto& box : boxes) {
1061 SkPaint paint;
1062 paint.setColor(colors[i % colors.size()]);
1063 paint.setShader(setgrad(box.rect, colors[i % colors.size()], SK_ColorWHITE));
1064 canvas->drawRect(box.rect, paint);
1065 }
1066 }
1067
1068 paragraph->paint(canvas, 0, 0);
1069 }
1070
1071 void draw(SkCanvas* canvas) override {
1072 canvas->drawColor(SK_ColorWHITE);
1073
1074 auto h = this->size().height();
1075 auto w = this->size().width();
1076
1077 drawText(canvas, SK_ColorGRAY, w, h);
1078 }
1079
1080 private:
1081 SkScalar letterSpacing;
1082 SkScalar wordSpacing;
1083 };
1084
1085 class ParagraphSlide10 : public ParagraphSlide_Base {
1086 public:
1087 ParagraphSlide10() { fName = "Paragraph10"; }
1088
1089 void draw(SkCanvas* canvas) override {
1090 canvas->drawColor(SK_ColorWHITE);
1091 auto multiplier = 5.67;
1092 const char* text = "English English 字典 字典 😀😃😄 😀😃😄";
1093
1094 auto fontCollection = sk_make_sp<FontCollection>();
1095 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
1096 fontCollection->enableFontFallback();
1097
1098 ParagraphStyle paragraph_style;
1099 paragraph_style.turnHintingOff();
1100 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1101
1102 TextStyle text_style;
1103 text_style.setFontFamilies({SkString("Roboto"),
1104 SkString("Noto Color Emoji"),
1105 SkString("Noto Serif CJK JP")});
1106 text_style.setFontSize(10 * multiplier);
1107 text_style.setLetterSpacing(0);
1108 text_style.setWordSpacing(0);
1109 text_style.setColor(SK_ColorBLACK);
1110 text_style.setHeight(1);
1111 builder.pushStyle(text_style);
1112 builder.addText(text, strlen(text));
1113 builder.pop();
1114
1115 auto paragraph = builder.Build();
1116 paragraph->layout(this->size().width());
1117
1118 paragraph->paint(canvas, 0, 0);
1119 }
1120 };
1121
1122 class ParagraphSlide11 : public ParagraphSlide_Base {
1123 public:
1124 ParagraphSlide11() { fName = "Paragraph11"; }
1125
1126 void draw(SkCanvas* canvas) override {
1127 canvas->drawColor(SK_ColorWHITE);
1128
1129 auto text = "\U0001f469\U0000200D\U0001f469\U0000200D\U0001f466\U0001f469\U0000200D\U0001f469\U0000200D\U0001f467\U0000200D\U0001f467\U0001f1fa\U0001f1f8";
1130
1131 TextStyle text_style;
1132 text_style.setFontFamilies({SkString("Ahem")});
1133 text_style.setColor(SK_ColorBLACK);
1134 text_style.setFontSize(60);
1135 text_style.setLetterSpacing(0);
1136 text_style.setWordSpacing(0);
1137 ParagraphStyle paragraph_style;
1138 paragraph_style.setTextStyle(text_style);
1139
1140 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
1141 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1142 builder.addText(text, strlen(text));
1143 auto paragraph = builder.Build();
1144 paragraph->layout(1000);
1145 paragraph->paint(canvas, 0, 0);
1146
1147 struct pair {
1148 unsigned fX;
1149 unsigned fY;
1150 };
1151
1152 pair hit1[] =
1153 {{ 0, 8},{1, 33}, {2, 34}, { 3, 19}, {4, 20},
1154 { 5, 21}, { 6, 22 }, { 7, 23 }, {8, 24 }, { 9, 25},
1155 { 10, 26}, { 11, 27}, {12, 28}, { 13, 21}, {14, 22 },
1156 { 15, 23}, {16, 24}, {17, 21}, { 18, 22}, {19, 21},
1157 { 20, 24}, { 21, 23}, };
1158
1159 pair miss[] =
1160 {{ 0, 4},{1, 17}, {2, 18}, { 3, 11}, {4, 12},
1161 { 5, 13}, { 6, 14 }, { 7, 15 }, {8, 16 }, { 9, 17},
1162 { 10, 18}, { 11, 19}, {12, 20}, { 13, 17}, {14, 18 },
1163 { 15, 19}, {16, 20}, {17, 19}, { 18, 20},
1164 { 20, 22}, };
1165
1166 auto rects = paragraph->getRectsForRange(7, 9, RectHeightStyle::kTight,
1167 RectWidthStyle::kTight);
1168 SkPaint paint;
1169 paint.setColor(SK_ColorRED);
1170 paint.setStyle(SkPaint::kStroke_Style);
1171 paint.setAntiAlias(true);
1172 paint.setStrokeWidth(1);
1173 if (!rects.empty()) {
1174 canvas->drawRect(rects[0].rect, paint);
1175 }
1176
1177 for (auto& query : hit1) {
1178 auto hitRects = paragraph->getRectsForRange(query.fX, query.fY, RectHeightStyle::kTight,
1179 RectWidthStyle::kTight);
1180 if (hitRects.size() >= 1 && hitRects[0].rect.width() > 0) {
1181 } else {
1182 if (this->isVerbose()) {
1183 SkDebugf("+[%u:%u): Bad\n", query.fX, query.fY);
1184 }
1185 }
1186 }
1187
1188 for (auto& query : miss) {
1189 auto missRects = paragraph->getRectsForRange(query.fX, query.fY,
1190 RectHeightStyle::kTight,
1191 RectWidthStyle::kTight);
1192 if (missRects.empty()) {
1193 } else {
1194 if (this->isVerbose()) {
1195 SkDebugf("-[%u:%u): Bad\n", query.fX, query.fY);
1196 }
1197 }
1198 }
1199 }
1200 };
1201
1202 class ParagraphSlide12 : public ParagraphSlide_Base {
1203 public:
1204 ParagraphSlide12() { fName = "Paragraph12"; }
1205
1206 void draw(SkCanvas* canvas) override {
1207 canvas->drawColor(SK_ColorWHITE);
1208
1209 const char* text = "Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neiges";
1210 TextStyle text_style;
1211 text_style.setFontFamilies({SkString("Ahem")});
1212 text_style.setColor(SK_ColorBLACK);
1213 text_style.setFontSize(16);
1214 //text_style.setLetterSpacing(-0.41);
1215 StrutStyle strut_style;
1216 strut_style.setStrutEnabled(false);
1217 ParagraphStyle paragraph_style;
1218 paragraph_style.setStrutStyle(strut_style);
1219 paragraph_style.setTextStyle(text_style);
1220 ParagraphBuilderImpl builder(paragraph_style, getFontCollection(), get_unicode());
1221 builder.addText(text);
1222 auto paragraph = builder.Build();
1223 paragraph->layout(1095.000000);
1224 auto result = paragraph->getRectsForRange(65, 66, RectHeightStyle::kTight, RectWidthStyle::kTight);
1225 paragraph->paint(canvas, 0, 0);
1226
1227 SkPaint paint;
1228 paint.setColor(SK_ColorRED);
1229 paint.setStyle(SkPaint::kStroke_Style);
1230 paint.setAntiAlias(true);
1231 paint.setStrokeWidth(1);
1232 if (!result.empty()) {
1233 canvas->drawRect(result.front().rect, paint);
1234 }
1235 }
1236 };
1237
1238 class ParagraphSlide14 : public ParagraphSlide_Base {
1239 public:
1240 ParagraphSlide14() { fName = "Paragraph14"; }
1241
1242 void draw(SkCanvas* canvas) override {
1243 canvas->drawColor(SK_ColorWHITE);
1244 TextStyle text_style;
1245 text_style.setFontFamilies({SkString("Ahem")});
1246 text_style.setColor(SK_ColorBLACK);
1247 text_style.setFontSize(25);
1248 text_style.setDecoration((TextDecoration)(TextDecoration::kUnderline | TextDecoration::kOverline | TextDecoration::kLineThrough));
1249 text_style.setDecorationColor(SK_ColorBLUE);
1250 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
1251 text_style.setDecorationThicknessMultiplier(4.0f);
1252 ParagraphStyle paragraph_style;
1253 paragraph_style.setTextStyle(text_style);
1254 paragraph_style.setTextDirection(TextDirection::kRtl);
1255 ParagraphBuilderImpl builder(paragraph_style, getFontCollection(), get_unicode());
1256 builder.pushStyle(text_style);
1257 builder.addText("Hello, wor!\nabcd.");
1258 auto paragraph = builder.Build();
1259 paragraph->layout(300);
1260 paragraph->paint(canvas, 0, 0);
1261 SkPaint paint;
1262 paint.setColor(SK_ColorRED);
1263 paint.setStyle(SkPaint::kStroke_Style);
1264 paint.setAntiAlias(true);
1265 paint.setStrokeWidth(1);
1266 canvas->drawRect(SkRect::MakeXYWH(0, 0, 300, 100), paint);
1267 }
1268 };
1269
1270 class ParagraphSlide15 : public ParagraphSlide_Base {
1271 public:
1272 ParagraphSlide15() { fName = "Paragraph15"; }
1273
1274 void draw(SkCanvas* canvas) override {
1275 canvas->drawColor(SK_ColorWHITE);
1276
1277 TextStyle text_style;
1278 text_style.setFontFamilies({SkString("abc.ttf")});
1279 text_style.setFontSize(50);
1280
1281 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false);
1282
1283 fontCollection->addFontFromFile("abc/abc.ttf", "abc");
1284 fontCollection->addFontFromFile("abc/abc+grave.ttf", "abc+grave");
1285 fontCollection->addFontFromFile("abc/abc+agrave.ttf", "abc+agrave");
1286
1287 ParagraphStyle paragraph_style;
1288 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1289
1290 text_style.setFontFamilies({SkString("abc"), SkString("abc+grave")});
1291 text_style.setColor(SK_ColorBLUE);
1292 builder.pushStyle(text_style);
1293 builder.addText(u"a\u0300");
1294 text_style.setColor(SK_ColorMAGENTA);
1295 builder.pushStyle(text_style);
1296 builder.addText(u"à");
1297
1298 text_style.setFontFamilies({SkString("abc"), SkString("abc+agrave")});
1299
1300 text_style.setColor(SK_ColorRED);
1301 builder.pushStyle(text_style);
1302 builder.addText(u"a\u0300");
1303 text_style.setColor(SK_ColorGREEN);
1304 builder.pushStyle(text_style);
1305 builder.addText(u"à");
1306
1307 auto paragraph = builder.Build();
1308 paragraph->layout(800);
1309 paragraph->paint(canvas, 50, 50);
1310
1311 }
1312 };
1313
1314 class ParagraphSlide16 : public ParagraphSlide_Base {
1315 public:
1316 ParagraphSlide16() { fName = "Paragraph16"; }
1317
1318 void draw(SkCanvas* canvas) override {
1319 canvas->drawColor(SK_ColorWHITE);
1320
1321 const char* text = "content";
1322
1323 ParagraphStyle paragraph_style;
1324 paragraph_style.setMaxLines(1);
1325 paragraph_style.setEllipsis(u"\u2026");
1326 //auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1327 auto fontCollection = sk_make_sp<FontCollection>();
1328 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
1329 fontCollection->enableFontFallback();
1330 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1331
1332 TextStyle text_style;
1333 text_style.setFontFamilies({SkString(".SF Pro Text")});
1334 text_style.setColor(SK_ColorBLACK);
1335 text_style.setFontSize(17.0f * 99.0f);
1336 text_style.setLetterSpacing(0.41f);
1337 builder.pushStyle(text_style);
1338 builder.addText(text);
1339
1340 auto paragraph = builder.Build();
1341 paragraph->layout(800);
1342 paragraph->paint(canvas, 0, 0);
1343 }
1344 };
1345
1346 class ParagraphSlide17 : public ParagraphSlide_Base {
1347 public:
1348 ParagraphSlide17() { fName = "Paragraph17"; }
1349
1350 void draw(SkCanvas* canvas) override {
1351 canvas->drawColor(SK_ColorWHITE);
1352
1353 auto fontCollection = sk_make_sp<FontCollection>();
1354 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
1355 fontCollection->enableFontFallback();
1356 auto navy = SkColorSetRGB(0, 0, 139);
1357 auto ltgray = SkColorSetRGB(211, 211, 211);
1358 auto multiplier = 5.67;
1359
1360 //const char* text = ">Sͬ͑̀͐̈͒̈́̋̎ͮͩ̽̓ͬ̂̆̔͗́̓ͣͧ͊ͫ͛̉͌̐̑ͪ͗̚͝҉̴͉͢k̡̊̓ͫͭͩ͂͊ͨͪͬ̑ͫ̍̌̄͛̌̂̑̂̋̊̔ͫ͛̽̑ͨ̍ͭ̓̀ͪͪ̉͐͗̌̓̃̚͟͝҉̢͏̫̞̙͇͖̮͕̗̟͕͇͚̻͈̣̻̪͉̰̲̣̫ͅͅP̴̅̍͒̿͗͗̇ͩ̃͆͌̀̽͏̧̡͕͖̝̖̼̺̰̣̬͔͖͔̼͙̞̦̫͓̘͜a̸̴̸̴̢̢̨̨̫͍͓̥̼̭̼̻̤̯̙̤̻̠͚̍̌͋̂ͦͨ̽̇͌͌͆̀̽̎͒̄ͪ̐ͦ̈ͫ͐͗̓̚̚͜ͅr͐͐ͤͫ̐ͥ͂̈́̿́ͮ̃͗̓̏ͫ̀̿͏̸̵̧́͘̕͟͝͠͞͠҉̷̧͚͢͟a̓̽̎̄͗̔͛̄̐͊͛ͫ͂͌̂̂̈̈̓̔̅̅̄͊̉́ͪ̑̄͆ͬ̍͆ͭ͋̐ͬ͏̷̵̨̢̩̹̖͓̥̳̰͔̱̬͖̙͓̙͇̀̀̕͜͟͟͢͟͜͠͡g̨̅̇ͦ͋̂ͦͨͭ̓͐͆̏̂͛̉ͧ̑ͫ̐̒͛ͫ̍̒͛́̚҉̷̨̛̛̀͜͢͞҉̩̘̲͍͎̯̹̝̭̗̱͇͉̲̱͔̯̠̹̥̻͉̲̜̤̰̪̗̺̖̺r̷͌̓̇̅ͭ̀̐̃̃ͭ͑͗̉̈̇̈́ͥ̓ͣ́ͤ͂ͤ͂̏͌̆̚҉̴̸̧̢̢̛̫͉̦̥̤̙͈͉͈͉͓̙̗̟̳̜͈̗̺̟̠̠͖͓̖̪͕̠̕̕͝ͅả̸̴̡̡̧͠͞͡͞҉̛̕͟͏̷̘̪̱͈̲͉̞̠̞̪̫͎̲̬̖̀̀͟͝͞͞͠p̛͂̈͐̚͠҉̵̸̡̢̢̩̹͙̯͖̙̙̮̥̙͚̠͔̥̭̮̞̣̪̬̥̠̖̝̥̪͎́̀̕͜͡͡ͅͅh̵̷̵̡̛ͤ̂͌̐̓̐̋̋͊̒̆̽́̀̀̀͢͠͞͞҉̷̸̢̕҉͚̯͖̫̜̞̟̠̱͉̝̲̹̼͉̟͉̩̮͔̤͖̞̭̙̹̬ͅ<";
1361 const char* text = ">S͛ͭ̋͆̈̔̇͗̍͑̎ͪͮͧͣ̽ͫͣ́ͬ̀͌͑͂͗͒̍̔̄ͧ̏̉̌̊̊̿̀̌̃̄͐̓̓̚̚҉̵̡͜͟͝͠͏̸̵̡̧͜҉̷̡͇̜̘̻̺̘̟̝͙̬̘̩͇̭̼̥̖̤̦͎k͉̩̘͚̜̹̗̗͍̤̥̱͉̳͕͖̤̲̣͚̮̞̬̲͍͔̯̻̮̞̭͈̗̫͓̂ͨ̉ͪ̒͋͛̀̍͊ͧ̿̅͆̓̔̔ͬ̇̑̿ͩ͗ͮ̎͌̿̄ͅP̴̵̡̡̛̪͙̼̣̟̩̭̫̱͙̬͔͉͍̘̠͉̦̝̘̥̟̗͖̫̤͕̙̬̦͍̱̖̮̱͑͐̎̃̒͐͋̚͘͞a̶̶̵̵̵̶̶̡̧̢̢̺͔̣͖̭̺͍̤͚̱̜̰̥͕̬̥̲̞̥̘͇͚̺̰͚̪̺͔̤͍̓̿͆̎͋̓ͦ̈́ͦ̌́̄͗̌̓͌̕͜͜͟͢͝͡ŕ͎̝͕͉̻͎̤̭͚̗̳̖̙̘͚̫͖͓͚͉͔͈̟̰̟̬̗͓̟͚̱̕͡ͅͅͅa̸̶̢̛̛̽ͮͩ̅͒ͫ͗͂̎ͦ̈́̓̚͘͜͢͡҉̷̵̶̢̡̜̮̦̜̥̜̯̙͓͔̼̗̻͜͜ͅḡ̢̛͕̗͖̖̤̦̘͔ͨͨ̊͒ͩͭͤ̍̅̃ͪ̋̏̓̍̋͗̋ͨ̏̽̈́̔̀̋̉ͫ̅̂ͭͫ̏͒͋ͥ̚͜r̶̢̧̧̥̤̼̀̂̒ͪ͌̿͌̅͛ͨͪ͒̍ͥ̉ͤ̌̿̆́ͭ͆̃̒ͤ͛̊ͧ̽͘͝͠a̧̢̧̢͑͑̓͑ͮ̃͂̄͛́̈́͋̂͌̽̄͒̔́̇ͨͧͭ͐ͦ̋ͨ̍ͦ̍̋͆̔ͧ͑͋͌̈̓͛͛̚͢͜͜͏̴̢̧̛̳͍̹͚̰̹̻͔p̨̡͆ͦͣ͊̽̔͂̉ͣ̔ͣ̌̌̉̃̋̂͒ͫ̄̎̐͗̉̌̃̽̽́̀̚͘͜͟҉̱͉h̭̮̘̗͔̜̯͔͈̯̺͔̗̣̭͚̱̰̙̼̹͚̣̻̥̲̮͍̤͜͝<";
1362 ParagraphStyle paragraph_style;
1363 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1364 SkPaint paint;
1365 paint.setColor(ltgray);
1366 TextStyle text_style;
1367 text_style.setBackgroundColor(paint);
1368 text_style.setColor(navy);
1369 text_style.setFontFamilies({SkString("Roboto")});
1370 text_style.setFontSize(20 * multiplier);
1371 builder.pushStyle(text_style);
1372 builder.addText(text);
1373 auto paragraph = builder.Build();
1374 paragraph->layout(10000);
1375 paragraph->paint(canvas, 0, 0);
1376 }
1377 };
1378
1379 class Zalgo {
1380 private:
1381 std::u16string COMBINING_DOWN = u"\u0316\u0317\u0318\u0319\u031c\u031d\u031e\u031f\u0320\u0324\u0325\u0326\u0329\u032a\u032b\u032c\u032d\u032e\u032f\u0330\u0331\u0332\u0333\u0339\u033a\u033b\u033c\u0345\u0347\u0348\u0349\u034d\u034e\u0353\u0354\u0355\u0356\u0359\u035a\u0323";
1382 std::u16string COMBINING_UP = u"\u030d\u030e\u0304\u0305\u033f\u0311\u0306\u0310\u0352\u0357\u0351\u0307\u0308\u030a\u0342\u0343\u0344\u034a\u034b\u034c\u0303\u0302\u030c\u0350\u0300\u0301\u030b\u030f\u0312\u0313\u0314\u033d\u0309\u0363\u0364\u0365\u0366\u0367\u0368\u0369\u036a\u036b\u036c\u036d\u036e\u035b\u0346\u031a";
1383 std::u16string COMBINING_MIDDLE = u"\u0315\u031b\u0340\u0341\u0358\u0321\u0322\u0327\u0328\u0334\u0335\u0336\u034f\u035c\u035d\u035e\u035f\u0360\u0362\u0338\u0337\u0361\u0489";
1384
1385 std::u16string randomMarks(std::u16string& combiningMarks) {
1386 std::u16string result;
1387 auto num = std::rand() % (combiningMarks.size() / 1);
1388 for (size_t i = 0; i < num; ++i) {
1389 auto index = std::rand() % combiningMarks.size();
1390 result += combiningMarks[index];
1391 }
1392 return result;
1393 }
1394
1395 public:
1396 std::u16string zalgo(const std::string& victim) {
1397 std::u16string result;
1398 for (auto& c : victim) {
1399 result += c;
1400 result += randomMarks(COMBINING_UP);
1401 result += randomMarks(COMBINING_MIDDLE);
1402 result += randomMarks(COMBINING_DOWN);
1403 }
1404 return result;
1405 }
1406 };
1407
1408 class ParagraphSlide18 : public ParagraphSlide_Base {
1409 public:
1410 ParagraphSlide18() { fName = "Paragraph18"; }
1411
1412 bool onChar(SkUnichar uni) override {
1413 switch (uni) {
1414 case ' ':
1415 fLimit = 400;
1416 return true;
1417 case 's':
1418 fLimit += 10;
1419 return true;
1420 case 'f':
1421 if (fLimit > 10) {
1422 fLimit -= 10;
1423 }
1424 return true;
1425 default:
1426 break;
1427 }
1428 return false;
1429 }
1430
1431 bool animate(double nanos) override {
1432 if (++fIndex > fLimit) {
1433 fRedraw = true;
1434 fIndex = 0;
1435 } else {
1436 fRepeat = true;
1437 }
1438 return true;
1439 }
1440
1441 void draw(SkCanvas* canvas) override {
1442 canvas->drawColor(SK_ColorWHITE);
1443
1444 auto navy = SkColorSetRGB(0, 0, 139);
1445 auto ltgray = SkColorSetRGB(211, 211, 211);
1446
1447 auto multiplier = 5.67;
1448 auto fontCollection = sk_make_sp<FontCollection>();
1449 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
1450 fontCollection->enableFontFallback();
1451
1452 ParagraphStyle paragraph_style;
1453 TextStyle text_style;
1454 text_style.setFontFamilies({SkString("Roboto")});
1455 text_style.setFontSize(20 * multiplier);
1456 text_style.setColor(navy);
1457 SkPaint paint;
1458 paint.setColor(ltgray);
1459 text_style.setBackgroundColor(paint);
1460
1461 Zalgo zalgo;
1462
1463 if (fRedraw || fRepeat) {
1464
1465 if (fRedraw || fParagraph == nullptr) {
1466 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1467 builder.pushStyle(text_style);
1468 auto utf16text = zalgo.zalgo("SkParagraph");
1469 builder.addText(utf16text);
1470 fParagraph = builder.Build();
1471 }
1472
1473 auto impl = static_cast<ParagraphImpl*>(fParagraph.get());
1474 if (this->isVerbose()) {
1475 SkDebugf("Text:>%s<\n", impl->text().data());
1476 }
1477 impl->markDirty();
1478 fParagraph->layout(1000);
1479 fParagraph->paint(canvas, 300, 200);
1480
1481 for (auto& run : impl->runs()) {
1482 SkString fontFamily("unresolved");
1483 if (run.font().getTypeface() != nullptr) {
1484 run.font().getTypeface()->getFamilyName(&fontFamily);
1485 }
1486 if (run.font().getTypeface() != nullptr) {
1487 for (size_t i = 0; i < run.size(); ++i) {
1488 auto glyph = run.glyphs().begin() + i;
1489 if (*glyph == 0) {
1490 //SkDebugf("Run[%d] @pos=%d\n", run.index(), i);
1491 }
1492 }
1493 } else {
1494 //SkDebugf("Run[%d]: %s\n", run.index(), fontFamily.c_str());
1495 }
1496 }
1497 fRedraw = false;
1498 fRepeat = false;
1499 }
1500 }
1501
1502 private:
1503 bool fRedraw = true;
1504 bool fRepeat = false;
1505 size_t fIndex = 0;
1506 size_t fLimit = 20;
1507 std::unique_ptr<Paragraph> fParagraph;
1508 };
1509
1510 class ParagraphSlide19 : public ParagraphSlide_Base {
1511 public:
1512 ParagraphSlide19() { fName = "Paragraph19"; }
1513
1514 void draw(SkCanvas* canvas) override {
1515 canvas->drawColor(SK_ColorWHITE);
1516
1517 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1518
1519 std::u16string text = u"\u0068\u0301\u0350\u0312\u0357\u030C\u0369\u0305\u036C\u0304\u0310\u033F\u0366\u0350\u0343\u0364\u0369\u0311\u0309\u030E\u0365\u031B\u0340\u0337\u0335\u035E\u0334\u0328\u0360\u0360\u0315\u035F\u0340\u0340\u0362\u0360\u0322\u031B\u031B\u0337\u0340\u031E\u031F\u032A\u0331\u0345\u032F\u0332\u032E\u0333\u0353\u0320\u0345\u031C\u031F\u033C\u0325\u0355\u032C\u0325\u033Aa\u0307\u0312\u034B\u0308\u0312\u0346\u0313\u0346\u0304\u0307\u0344\u0305\u0342\u0368\u0346\u036A\u035B\u030F\u0365\u0307\u0340\u0328\u0322\u0361\u0489\u034F\u0328\u0334\u035F\u0335\u0362\u0489\u0360\u0358\u035E\u0360\u035D\u0341\u0337\u0337\u032E\u0326\u032D\u0359\u0318\u033C\u032F\u0333\u035A\u034D\u0319\u031C\u0353\u033C\u0345\u0359\u0331\u033B\u0331\u033C";
1520 ParagraphStyle paragraph_style;
1521 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1522 TextStyle text_style;
1523 text_style.setColor(SK_ColorBLACK);
1524 text_style.setFontFamilies({SkString("Roboto")});
1525 text_style.setFontSize(20);
1526 builder.pushStyle(text_style);
1527 builder.addText(text);
1528 auto paragraph = builder.Build();
1529 paragraph->layout(this->size().width());
1530 paragraph->paint(canvas, 0, 0);
1531 }
1532 };
1533
1534 class ParagraphSlide20 : public ParagraphSlide_Base {
1535 public:
1536 ParagraphSlide20() { fName = "Paragraph20"; }
1537
1538 void draw(SkCanvas* canvas) override {
1539 canvas->drawColor(SK_ColorWHITE);
1540
1541 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1542
1543 const char* text = "Manage your google account";
1544 ParagraphStyle paragraph_style;
1545 paragraph_style.setEllipsis(u"\u2026");
1546 paragraph_style.setMaxLines(1);
1547 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1548 TextStyle text_style;
1549 text_style.setColor(SK_ColorBLACK);
1550 text_style.setFontFamilies({SkString("Roboto")});
1551 text_style.setFontSize(50);
1552 builder.pushStyle(text_style);
1553 builder.addText(text);
1554 auto paragraph = builder.Build();
1555 paragraph->layout(this->size().width());
1556 paragraph->paint(canvas, 0, 0);
1557 }
1558 };
1559
1560 class ParagraphSlide21 : public ParagraphSlide_Base {
1561 public:
1562 ParagraphSlide21() { fName = "Paragraph21"; }
1563
1564 void draw(SkCanvas* canvas) override {
1565 canvas->drawColor(SK_ColorWHITE);
1566
1567 const char* text = "Referral Code";
1568 ParagraphStyle paragraph_style;
1569 ParagraphBuilderImpl builder(paragraph_style, getFontCollection(), get_unicode());
1570 TextStyle text_style;
1571 text_style.setColor(SK_ColorBLACK);
1572 text_style.setFontFamilies({SkString("Google Sans")});
1573 text_style.setFontSize(24);
1574 builder.pushStyle(text_style);
1575 builder.addText(text);
1576 auto paragraph = builder.Build();
1577 paragraph->layout(0);
1578 paragraph->paint(canvas, 0, 0);
1579 }
1580 };
1581
1582 class ParagraphSlide22 : public ParagraphSlide_Base {
1583 public:
1584 ParagraphSlide22() { fName = "Paragraph22"; }
1585
1586 bool onChar(SkUnichar uni) override {
1587 switch (uni) {
1588 case 'l':
1589 direction = true;
1590 return true;
1591 case 'r':
1592 direction = false;
1593 return true;
1594 default:
1595 break;
1596 }
1597 return false;
1598 }
1599
1600 void draw(SkCanvas* canvas) override {
1601
1602 canvas->drawColor(SK_ColorWHITE);
1603 ParagraphStyle paragraph_style;
1604 paragraph_style.setTextDirection(direction ? TextDirection::kLtr : TextDirection::kRtl);
1605 auto collection = getFontCollection();
1606 ParagraphBuilderImpl builder(paragraph_style, collection, get_unicode());
1607 collection->getParagraphCache()->reset();
1608 collection->getParagraphCache()->turnOn(false);
1609 TextStyle text_style;
1610 text_style.setColor(SK_ColorBLACK);
1611 text_style.setFontFamilies({SkString("Roboto")});
1612 text_style.setFontSize(12);
1613 builder.pushStyle(text_style);
1614 builder.addText("I have got a ");
1615 text_style.setFontStyle(SkFontStyle::Bold());
1616 builder.pushStyle(text_style);
1617 builder.addText("lovely bunch");
1618 text_style.setFontStyle(SkFontStyle::Normal());
1619 builder.pushStyle(text_style);
1620 builder.addText(" of coconuts.");
1621 auto paragraph = builder.Build();
1622 paragraph->layout(this->size().width());
1623 paragraph->paint(canvas, 0, 0);
1624 collection->getParagraphCache()->turnOn(true);
1625 }
1626
1627 private:
1628 bool direction = false;
1629 };
1630
1631 class ParagraphSlide23 : public ParagraphSlide_Base {
1632 public:
1633 ParagraphSlide23() { fName = "Paragraph23"; }
1634
1635 void draw(SkCanvas* canvas) override {
1636 canvas->drawColor(SK_ColorWHITE);
1637
1638 const char* text = "Text with shadow";
1639 ParagraphStyle paragraph_style;
1640 TextStyle text_style;
1641 text_style.setColor(SK_ColorBLACK);
1642 text_style.setFontFamilies({SkString("Google Sans")});
1643 text_style.setFontSize(24);
1644
1645 auto draw = [&](SkScalar h, SkScalar v, SkScalar b) {
1646 text_style.resetShadows();
1647 text_style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(h, v), b));
1648 ParagraphBuilderImpl builder(paragraph_style, getFontCollection(), get_unicode());
1649 builder.pushStyle(text_style);
1650 builder.addText(text);
1651 auto paragraph = builder.Build();
1652 paragraph->layout(300);
1653 paragraph->paint(canvas, 0, 0);
1654
1655 auto rect = SkRect::MakeXYWH(0, 0, paragraph->getMaxWidth(), paragraph->getHeight());
1656 SkPaint paint;
1657 paint.setColor(SK_ColorRED);
1658 paint.setStyle(SkPaint::kStroke_Style);
1659 paint.setAntiAlias(true);
1660 paint.setStrokeWidth(1);
1661 canvas->drawRect(rect, paint);
1662 };
1663
1664 draw(10, 10, 5);
1665 canvas->translate(0, 100);
1666
1667 draw(10, -10, 5);
1668 canvas->translate(0, 100);
1669
1670 draw(-10, -10, 5);
1671 canvas->translate(0, 100);
1672
1673 draw(-10, 10, 5);
1674 canvas->translate(0, 100);
1675 }
1676 };
1677
1678 class ParagraphSlide24 : public ParagraphSlide_Base {
1679 public:
1680 ParagraphSlide24() { fName = "Paragraph24"; }
1681
1682 void draw(SkCanvas* canvas) override {
1683 canvas->drawColor(SK_ColorWHITE);
1684
1685 ParagraphStyle paragraph_style;
1686 paragraph_style.setTextDirection(TextDirection::kRtl);
1687 TextStyle text_style;
1688 text_style.setColor(SK_ColorBLACK);
1689 text_style.setFontFamilies({SkString("Google Sans")});
1690 text_style.setFontSize(24);
1691 {
1692 ParagraphBuilderImpl builder(paragraph_style, getFontCollection(), get_unicode());
1693 builder.pushStyle(text_style);
1694 builder.addText("Right_to_left:");
1695 auto paragraph = builder.Build();
1696 paragraph->layout(this->size().width());
1697 paragraph->paint(canvas, 0, 0);
1698 }
1699 canvas->translate(0, 200);
1700 {
1701 ParagraphBuilderImpl builder(paragraph_style, getFontCollection(), get_unicode());
1702 builder.pushStyle(text_style);
1703 builder.addText("Right_to_left+");
1704 auto paragraph = builder.Build();
1705 paragraph->layout(this->size().width());
1706 paragraph->paint(canvas, 0, 0);
1707 }
1708 canvas->translate(0, 200);
1709 {
1710 ParagraphBuilderImpl builder(paragraph_style, getFontCollection(), get_unicode());
1711 builder.pushStyle(text_style);
1712 builder.addText("Right_to_left.");
1713 auto paragraph = builder.Build();
1714 paragraph->layout(this->size().width());
1715 paragraph->paint(canvas, 0, 0);
1716 }
1717 }
1718 };
1719
1720 class ParagraphSlide25 : public ParagraphSlide_Base {
1721 public:
1722 ParagraphSlide25() { fName = "Paragraph25"; }
1723
1724 void draw(SkCanvas* canvas) override {
1725 canvas->drawColor(SK_ColorWHITE);
1726 /*
1727 * Shell: ParagraphStyle: 1.000000 1
1728 Shell: Strut enabled: 0 1.000000 14.000000 400 5 0
1729 Shell: Font Families: 0
1730 Shell: DefaultTextStyle: 16.000000 500 5 0
1731 Shell: Font Families: 1 Roboto
1732 Shell: Font Features: 0
1733 Shell: TextStyle#0: [0:22) 16.000000 500 5 0
1734 Shell: Font Families: 1 Roboto
1735 Shell: Font Features: 0
1736 Shell: TextStyle#1: [25:49) 16.000000 500 5 0
1737 Shell: Font Families: 1 Roboto
1738 Shell: Font Features: 0
1739 Shell: Placeholder#0: [22:25) 32.000000 32.000000 32.000000 0 5
1740 Shell: Placeholder#1: [49:52) 19.000000 41.000000 19.000000 0 4
1741 Shell: Placeholder#2: [52:52) 0.000000 0.000000 0.000000 0 5
1742 Shell: layout('Go to device settings  and set up a passcode. ', 280.000000): 280.000000 * 38.000000
1743 */
1744 auto fontCollection = getFontCollection();
1745 //fontCollection->getParagraphCache()->turnOn(false);
1746 const char* text1 = "Go to device settings ";
1747 const char* text2 = "and set up a passcode.";
1748 ParagraphStyle paragraph_style;
1749 StrutStyle strut_style;
1750 strut_style.setStrutEnabled(false);
1751 strut_style.setFontSize(14);
1752 strut_style.setForceStrutHeight(false);
1753 strut_style.setHeight(14);
1754 paragraph_style.setStrutStyle(strut_style);
1755 TextStyle text_style;
1756 text_style.setColor(SK_ColorBLACK);
1757 text_style.setFontFamilies({SkString("Roboto")});
1758 text_style.setFontSize(16);
1759 PlaceholderStyle placeholder_style;
1760 {
1761 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1762 builder.pushStyle(text_style);
1763 builder.addText(text1);
1764 placeholder_style.fHeight = 32;
1765 placeholder_style.fWidth = 32;
1766 placeholder_style.fBaselineOffset = 32;
1767 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1768 placeholder_style.fAlignment = PlaceholderAlignment::kMiddle;
1769 builder.addPlaceholder(placeholder_style);
1770 builder.addText(text2);
1771 placeholder_style.fHeight = 19;
1772 placeholder_style.fWidth = 41;
1773 placeholder_style.fBaselineOffset = 19;
1774 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1775 placeholder_style.fAlignment = PlaceholderAlignment::kTop;
1776 builder.addPlaceholder(placeholder_style);
1777 auto paragraph = builder.Build();
1778 paragraph->layout(280);
1779 paragraph->paint(canvas, 0, 0);
1780 }
1781 }
1782 };
1783
1784 class ParagraphSlide26 : public ParagraphSlide_Base {
1785 public:
1786 ParagraphSlide26() { fName = "Paragraph26"; }
1787
1788 void draw(SkCanvas* canvas) override {
1789 auto fontCollection = sk_make_sp<FontCollection>();
1790 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
1791 //fontCollection->enableFontFallback();
1792
1793 canvas->clear(SK_ColorWHITE);
1794
1795 SkPaint paint;
1796 paint.setAntiAlias(true);
1797 paint.setColor(SK_ColorBLACK);
1798
1799 TextStyle textStyle;
1800 textStyle.setForegroundColor(paint);
1801 textStyle.setFontFamilies({ SkString("Roboto") });
1802 textStyle.setFontSize(42.0f);
1803 textStyle.setLetterSpacing(-0.05f);
1804 textStyle.setHeightOverride(true);
1805
1806 ParagraphStyle paragraphStyle;
1807 paragraphStyle.setTextStyle(textStyle);
1808 paragraphStyle.setTextAlign(TextAlign::kLeft);
1809
1810 ParagraphBuilderImpl builder(paragraphStyle, fontCollection, get_unicode());
1811 builder.addText(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ut dolor ornare, fermentum nibh in, consectetur libero. Ut id semper est. Sed malesuada, est id bibendum egestas, urna risus tristique nibh, euismod interdum risus turpis nec purus. Maecenas dolor nisl, consectetur in vestibulum et, tincidunt id leo. Duis maximus, odio eget tristique commodo, lacus tellus dapibus leo, consequat pellentesque arcu nisi sit amet diam. Quisque euismod venenatis egestas. Mauris posuere volutpat iaculis. Suspendisse finibus tempor urna, dignissim venenatis sapien finibus eget. Donec interdum lacus ac venenatis fringilla. Curabitur eget lacinia augue. Vestibulum eu vulputate odio. Quisque nec imperdiet");
1812
1813 auto paragraph = builder.Build();
1814 paragraph->layout(this->size().width() / 2);
1815
1816 std::vector<LineMetrics> lines;
1817 paragraph->getLineMetrics(lines); // <-- error happens here
1818
1819 canvas->translate(10, 10);
1820 paragraph->paint(canvas, 0, 0);
1821 }
1822 };
1823
1824 class ParagraphSlide27 : public ParagraphSlide_Base {
1825 public:
1826 ParagraphSlide27() { fName = "Paragraph27"; }
1827
1828 void draw(SkCanvas* canvas) override {
1829 auto fontCollection = sk_make_sp<FontCollection>();
1830 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
1831 fontCollection->enableFontFallback();
1832 fontCollection->getParagraphCache()->turnOn(false);
1833
1834 SkPaint red;
1835 red.setColor(SK_ColorRED);
1836 red.setStyle(SkPaint::kStroke_Style);
1837 red.setAntiAlias(true);
1838 red.setStrokeWidth(1);
1839
1840 SkPaint blue;
1841 blue.setColor(SK_ColorRED);
1842 blue.setStyle(SkPaint::kStroke_Style);
1843 blue.setAntiAlias(true);
1844 blue.setStrokeWidth(1);
1845
1846 SkPaint black;
1847 black.setColor(SK_ColorBLACK);
1848 black.setStyle(SkPaint::kStroke_Style);
1849 black.setAntiAlias(true);
1850 black.setStrokeWidth(1);
1851
1852 SkPaint whiteSpaces;
1853 whiteSpaces.setColor(SK_ColorLTGRAY);
1854
1855 SkPaint breakingSpace;
1856 breakingSpace.setColor(SK_ColorYELLOW);
1857
1858 SkPaint text;
1859 text.setColor(SK_ColorWHITE);
1860
1861 ParagraphStyle paragraph_style;
1862 paragraph_style.setTextAlign(TextAlign::kRight);
1863 TextStyle text_style;
1864 text_style.setColor(SK_ColorBLACK);
1865 text_style.setFontFamilies({SkString("Roboto")});
1866
1867 // RTL + right align + arabic
1868 // RTL + right align + latin
1869 // LTR + right align + arabic
1870 // LTR + right align + latin
1871 // RTL + left align + arabic
1872 // RTL + left align + latin
1873 // arabic and latin should not differ at all
1874 // check: line breaking and trailing spaces
1875
1876 canvas->drawColor(SK_ColorWHITE);
1877 auto h = 60;
1878 auto w = 300;
1879
1880 auto draw = [&](SkScalar width, SkScalar height, TextDirection td, TextAlign ta, const char* t) {
1881 if (this->isVerbose()) {
1882 SkDebugf("draw '%s' dir:%s align:%s\n", t,
1883 td == TextDirection::kLtr ? "left" : "right",
1884 ta == TextAlign::kLeft ? "left" : "right");
1885 }
1886 paragraph_style.setTextDirection(td);
1887 paragraph_style.setTextAlign(ta);
1888 text_style.setFontSize(20);
1889 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
1890 text_style.setBackgroundColor(whiteSpaces);
1891 builder.pushStyle(text_style);
1892 builder.addText(" ");
1893 text_style.setBackgroundColor(text);
1894 builder.pushStyle(text_style);
1895 builder.addText(t);
1896 text_style.setBackgroundColor(breakingSpace);
1897 builder.pushStyle(text_style);
1898 builder.addText(" ");
1899 text_style.setBackgroundColor(text);
1900 builder.pushStyle(text_style);
1901 builder.addText(t);
1902 text_style.setBackgroundColor(whiteSpaces);
1903 builder.pushStyle(text_style);
1904 builder.addText(" ");
1905 auto paragraph = builder.Build();
1906 paragraph->layout(width);
1907 paragraph->paint(canvas, 0, 0);
1908 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
1909 for (auto& line : impl->lines()) {
1910 if (this->isVerbose()) {
1911 SkDebugf("line[%d]: %f\n", (int)(&line - impl->lines().data()),
1912 line.offset().fX);
1913 }
1914 line.iterateThroughVisualRuns(true,
1915 [&](const Run* run, SkScalar runOffset, TextRange textRange, SkScalar* width) {
1916 *width = line.measureTextInsideOneRun(textRange, run, runOffset, 0, true, TextLine::TextAdjustment::GlyphCluster).clip.width();
1917 if (this->isVerbose()) {
1918 SkDebugf("%zu[%zu: %zu) @%f + %f %s\n",
1919 run->index(), textRange.start, textRange.end, runOffset, *width,
1920 run->leftToRight() ? "left" : "right");
1921 }
1922 return true;
1923 });
1924 }
1925 auto boxes = paragraph->getRectsForRange(0, 100, RectHeightStyle::kTight, RectWidthStyle::kTight);
1926 bool even = true;
1927 for (auto& box : boxes) {
1928 if (this->isVerbose()) {
1929 SkDebugf("[%f:%f,%f:%f] %s\n",
1930 box.rect.fLeft, box.rect.fRight, box.rect.fTop, box.rect.fBottom,
1931 box.direction == TextDirection::kLtr ? "left" : "right");
1932 }
1933 canvas->drawRect(box.rect, even ? red : blue);
1934 even = !even;
1935 }
1936 canvas->translate(0, height);
1937 };
1938
1939 canvas->drawRect(SkRect::MakeXYWH(0, 0, w, h * 8), black);
1940
1941 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "RTL+RIGHT#1234567890");
1942 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
1943
1944 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "LTR+RIGHT#1234567890");
1945 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
1946
1947 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "RTL+LEFT##1234567890");
1948 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
1949
1950 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "LTR+LEFT##1234567890");
1951 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
1952 }
1953 };
1954
1955 class ParagraphSlide28 : public ParagraphSlide_Base {
1956 public:
1957 ParagraphSlide28() { fName = "Paragraph28"; }
1958
1959 void draw(SkCanvas* canvas) override {
1960
1961 const char* text = "AAAAA BBBBB CCCCC DDDDD EEEEE FFFFF GGGGG HHHHH IIIII JJJJJ KKKKK LLLLL MMMMM NNNNN OOOOO PPPPP QQQQQ";
1962
1963 canvas->drawColor(SK_ColorWHITE);
1964 ParagraphStyle paragraph_style;
1965 paragraph_style.setTextAlign(TextAlign::kJustify);
1966 auto collection = getFontCollection();
1967 ParagraphBuilderImpl builder(paragraph_style, collection, get_unicode());
1968 TextStyle text_style;
1969 text_style.setColor(SK_ColorBLACK);
1970 text_style.setFontFamilies({SkString("Roboto")});
1971 text_style.setFontSize(40);
1972 builder.pushStyle(text_style);
1973 builder.addText(text);
1974 auto paragraph = builder.Build();
1975 auto s = 186;
1976 paragraph->layout(360 - s);
1977 paragraph->paint(canvas, 0, 0);
1978 /*
1979 paragraph->layout(360);
1980 paragraph->paint(canvas, 0, 0);
1981 canvas->translate(0, 400);
1982 paragraph->layout(354.333);
1983 paragraph->paint(canvas, 0, 0);
1984 */
1985 }
1986 };
1987
1988 class ParagraphSlide29 : public ParagraphSlide_Base {
1989 public:
1990 ParagraphSlide29() { fName = "Paragraph29"; }
1991
1992 void draw(SkCanvas* canvas) override {
1993
1994 const char* text = "ffi";
1995 canvas->drawColor(SK_ColorWHITE);
1996
1997 auto collection = getFontCollection();
1998
1999 ParagraphStyle paragraph_style;
2000 ParagraphBuilderImpl builder(paragraph_style, collection, get_unicode());
2001 TextStyle text_style;
2002 text_style.setColor(SK_ColorBLACK);
2003 text_style.setFontFamilies({SkString("Roboto")});
2004 text_style.setFontSize(60);
2005 builder.pushStyle(text_style);
2006 builder.addText(text);
2007 auto paragraph = builder.Build();
2008 paragraph->layout(this->size().width());
2009 paragraph->paint(canvas, 0, 0);
2010 auto width = paragraph->getLongestLine();
2011 auto height = paragraph->getHeight();
2012 if (this->isVerbose()) {
2013 auto f1Pos = paragraph->getGlyphPositionAtCoordinate(width/6, height/2);
2014 auto f2Pos = paragraph->getGlyphPositionAtCoordinate(width/2, height/2);
2015 auto iPos = paragraph->getGlyphPositionAtCoordinate(width*5/6, height/2);
2016 SkDebugf("%d(%s) %d(%s) %d(%s)\n",
2017 f1Pos.position, f1Pos.affinity == Affinity::kUpstream ? "up" : "down",
2018 f2Pos.position, f2Pos.affinity == Affinity::kUpstream ? "up" : "down",
2019 iPos.position, iPos.affinity == Affinity::kUpstream ? "up" : "down");
2020
2021 auto f1 = paragraph->getRectsForRange(0, 1, RectHeightStyle::kTight,
2022 RectWidthStyle::kTight);
2023 if (f1.empty()) {
2024 SkDebugf("F1 is empty\n");
2025 } else {
2026 auto rf1 = f1[0];
2027 SkDebugf("f1: [%f:%f] %s\n", rf1.rect.fLeft, rf1.rect.fRight,
2028 rf1.direction == TextDirection::kRtl ? "rtl" : "ltr");
2029 }
2030
2031 auto f2 = paragraph->getRectsForRange(1, 2, RectHeightStyle::kTight,
2032 RectWidthStyle::kTight);
2033 if (f2.empty()) {
2034 SkDebugf("F2 is empty\n");
2035 } else {
2036 auto rf2 = f2[0];
2037 SkDebugf("f2: [%f:%f] %s\n", rf2.rect.fLeft, rf2.rect.fRight,
2038 rf2.direction == TextDirection::kRtl ? "rtl" : "ltr");
2039 }
2040
2041 auto fi = paragraph->getRectsForRange(2, 3, RectHeightStyle::kTight,
2042 RectWidthStyle::kTight);
2043 if (fi.empty()) {
2044 SkDebugf("FI is empty\n");
2045 } else {
2046 auto rfi = fi[0];
2047 SkDebugf("i: [%f:%f] %s\n", rfi.rect.fLeft, rfi.rect.fRight,
2048 rfi.direction == TextDirection::kRtl ? "rtl" : "ltr");
2049 }
2050 }
2051 }
2052 };
2053
2054 class ParagraphSlide30 : public ParagraphSlide_Base {
2055 public:
2056 ParagraphSlide30() { fName = "Paragraph30"; }
2057
2058 void draw(SkCanvas* canvas) override {
2059
2060 const std::u16string text = //u"\U0001f600\U0001f1e6\U0001f1f9\U0001f601\U0001f9f1\U0001f61a\U0001f431\U0001f642\U0001f38e\U0001f60d\U0001f3b9\U0001f917\U0001f6bb\U0001f609\U0001f353\U0001f618\U0001f1eb\U0001f1f0\U0001f468\u200D\U0001f469\u200D\U0001f466\u200D\U0001f466\U0001f468\u200D\U0001f469\u200D\U0001f467\u200D\U0001f466\U0001f468\u200D\U0001f469\u200D\U0001f467\U0001f46a";
2061 u"\U0001f469\u200D\U0001f469\u200D\U0001f466\U0001f469\u200D\U0001f469\u200D\U0001f467\u200D\U0001f467\U0001f1fa\U0001f1f8";
2062 canvas->drawColor(SK_ColorWHITE);
2063
2064 auto fontCollection = sk_make_sp<FontCollection>();
2065 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2066 fontCollection->enableFontFallback();
2067
2068 ParagraphStyle paragraph_style;
2069 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2070 TextStyle text_style;
2071 text_style.setColor(SK_ColorBLACK);
2072 //text_style.setFontFamilies({SkString("Noto Color Emoji")});
2073 text_style.setFontFamilies({SkString("Ahem")});
2074 text_style.setFontSize(14);
2075 builder.pushStyle(text_style);
2076 builder.addText(text);
2077 auto paragraph = builder.Build();
2078 paragraph->layout(this->size().width());
2079 paragraph->paint(canvas, 0, 0);
2080 std::pair<size_t, size_t> rects[] = {
2081 { 0, 2}, { 0, 4}, {0, 8},
2082 {23, 25}, {23, 27}, {23, 31}, {23, 39}, {23, 55}, {21, 23},
2083 {1, 3}, {1, 5}, {1, 9}, {1, 17}, {1, 33},
2084 { 2, 4}, {2, 6}, {2, 10}, {2, 18}, {2, 34},
2085 {3, 5}, {3, 7}, {3, 11}, {3, 19},
2086 {4, 6}, {4, 8}, {4, 12}, {4, 20},
2087 {5, 7}, {5, 9}, {5, 13}, {5, 21},
2088 {6, 8}, {6, 10}, {6, 14}, {6, 22},
2089 {7, 9}, {7, 11}, {7, 15}, {7, 23},
2090 {8, 10}, {8, 12}, {8, 16}, {8,24},
2091 {9, 11}, {9, 13}, {9, 17}, {9, 25},
2092 {10, 12}, {10, 14}, {10, 18}, {10, 26},
2093 {11, 13}, {11, 15}, {11, 19}, {11, 27},
2094 {12, 14}, {12, 16}, {12, 20}, {12, 28},
2095 {13, 15}, {13, 17}, {13, 21},
2096 {14, 16}, {14, 18}, {14, 22},
2097 {15, 17}, {15, 19}, {15, 23},
2098 {16, 18}, {16, 20}, {16, 24},
2099 {17, 19}, {17, 21},
2100 {18, 20}, {18, 22},
2101 {19, 21},
2102 {20, 22}, {20, 24},
2103 {21, 23},
2104 {22, 24}, {22, 26}, {22, 30}, {22, 38}, {22, 54},
2105 {20, 22},
2106 {18, 22},
2107 };
2108 for (auto rect: rects) {
2109 auto results = paragraph->getRectsForRange(
2110 rect.first, rect.second, RectHeightStyle::kTight, RectWidthStyle::kTight);
2111 SkDebugf("[%zu : %zu) ", rect.first, rect.second);
2112 if (!results.empty()) {
2113 SkASSERT(results.size() == 1);
2114 SkDebugf("[%f : %f]\n", results[0].rect.fLeft,results[0].rect.fRight);
2115 }
2116 }
2117 }
2118 };
2119
2120 class ParagraphSlide31 : public ParagraphSlide_Base {
2121 public:
2122 ParagraphSlide31() { fName = "Paragraph31"; }
2123
2124 void draw(SkCanvas* canvas) override {
2125
2126 canvas->drawColor(SK_ColorWHITE);
2127
2128 auto fontCollection = sk_make_sp<FontCollection>();
2129 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2130 fontCollection->enableFontFallback();
2131
2132 ParagraphStyle paragraph_style;
2133 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2134 TextStyle text_style;
2135 text_style.setColor(SK_ColorBLACK);
2136 text_style.setFontFamilies({SkString("Roboto")});
2137 text_style.setFontSize(40);
2138 builder.pushStyle(text_style);
2139 auto s = u"েن েূথ";
2140 builder.addText(s);
2141 auto paragraph = builder.Build();
2142 paragraph->layout(this->size().width());
2143 paragraph->paint(canvas, 0, 0);
2144 }
2145 };
2146
2147 class ParagraphSlide32 : public ParagraphSlide_Base {
2148 public:
2149 ParagraphSlide32() { fName = "Paragraph32"; }
2150
2151 void draw(SkCanvas* canvas) override {
2152
2153 canvas->drawColor(SK_ColorWHITE);
2154
2155 auto fontCollection = sk_make_sp<FontCollection>();
2156 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2157 fontCollection->enableFontFallback();
2158
2159 ParagraphStyle paragraph_style;
2160 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2161 TextStyle text_style;
2162 text_style.setColor(SK_ColorBLACK);
2163 text_style.setFontFamilies({SkString("Roboto")});
2164 text_style.setFontSize(40);
2165 text_style.setLocale(SkString("ko"));
2166 builder.pushStyle(text_style);
2167 builder.addText(u"\u904d ko ");
2168 text_style.setLocale(SkString("zh_Hant"));
2169 builder.pushStyle(text_style);
2170 builder.addText(u"\u904d zh-Hant ");
2171 text_style.setLocale(SkString("zh_Hans"));
2172 builder.pushStyle(text_style);
2173 builder.addText(u"\u904d zh-Hans ");
2174 text_style.setLocale(SkString("zh_HK"));
2175 builder.pushStyle(text_style);
2176 builder.addText(u"\u904d zh-HK ");
2177 auto paragraph = builder.Build();
2178 paragraph->layout(this->size().width());
2179 paragraph->paint(canvas, 0, 0);
2180 }
2181 };
2182
2183 class ParagraphSlide33 : public ParagraphSlide_Base {
2184 public:
2185 ParagraphSlide33() { fName = "Paragraph33"; }
2186
2187 void draw(SkCanvas* canvas) override {
2188
2189 canvas->drawColor(SK_ColorWHITE);
2190
2191 auto fontCollection = sk_make_sp<FontCollection>();
2192 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2193 fontCollection->enableFontFallback();
2194
2195 ParagraphStyle paragraph_style;
2196 paragraph_style.setTextAlign(TextAlign::kJustify);
2197 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2198 TextStyle text_style;
2199 text_style.setColor(SK_ColorBLACK);
2200 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2201 text_style.setFontSize(36);
2202 builder.pushStyle(text_style);
2203 builder.addText(u"AAAAA \U0001f600 BBBBB CCCCC DDDDD EEEEE");
2204 auto paragraph = builder.Build();
2205 paragraph->layout(this->size().width() / 2);
2206 SkPaint paint;
2207 paint.setColor(SK_ColorLTGRAY);
2208 canvas->drawRect(SkRect::MakeXYWH(0, 0, this->size().width()/2, paragraph->getHeight()),
2209 paint);
2210 paragraph->paint(canvas, 0, 0);
2211 }
2212 };
2213
2214 class ParagraphSlide34 : public ParagraphSlide_Base {
2215 public:
2216 ParagraphSlide34() { fName = "Paragraph34"; }
2217
2218 void draw(SkCanvas* canvas) override {
2219
2220 canvas->drawColor(SK_ColorWHITE);
2221 auto text = "ضخمة ص ،😁😂🤣ضضض ؤ،،😗😗😍😋شسي،😗😁😁ؤرى،😗😃😄😍ببب،🥰😅🥰🥰🥰ثيلااتن";
2222 //auto text = "ى،😗😃😄😍بب";
2223 //auto text1 = "World domination is such an ugly phrase - I prefer to call it world optimisation";
2224 auto fontCollection = sk_make_sp<FontCollection>();
2225 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2226 fontCollection->enableFontFallback();
2227
2228 ParagraphStyle paragraph_style;
2229 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2230 TextStyle text_style;
2231 text_style.setColor(SK_ColorBLACK);
2232 text_style.setFontFamilies({SkString("Noto Color Emoji")});
2233 text_style.setFontSize(50);
2234 builder.pushStyle(text_style);
2235 builder.addText(text);
2236 auto paragraph = builder.Build();
2237 paragraph->layout(1041); // 1041
2238
2239 SkColor colors[] = {SK_ColorBLUE, SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGREEN,
2240 SK_ColorRED, SK_ColorWHITE, SK_ColorYELLOW, SK_ColorMAGENTA };
2241 SkPaint paint;
2242 size_t wordPos = 0;
2243 size_t index = 0;
2244 while (wordPos < 72) {
2245 auto res2 = paragraph->getWordBoundary(wordPos);
2246 if (res2.width() == 0) {
2247 break;
2248 }
2249 wordPos = res2.end;
2250 auto res3 = paragraph->getRectsForRange(
2251 res2.start, res2.end,
2252 RectHeightStyle::kTight, RectWidthStyle::kTight);
2253 paint.setColor(colors[index % 8]);
2254 ++index;
2255 if (!res3.empty()) {
2256 canvas->drawRect(res3[0].rect, paint);
2257 }
2258 }
2259 paragraph->paint(canvas, 0, 0);
2260 }
2261 };
2262
2263 class ParagraphSlide35 : public ParagraphSlide_Base {
2264 public:
2265 ParagraphSlide35() { fName = "Paragraph35"; }
2266
2267 Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
2268 return new Click;
2269 }
2270
2271 bool onClick(Click* click) override {
2272 fPoint = click->fCurr;
2273 return true;
2274 }
2275
2276 void draw(SkCanvas* canvas) override {
2277
2278 canvas->drawColor(SK_ColorWHITE);
2279
2280 auto text = u"hzbzzj sjsjjs sjkkahgafa\u09A4\u09A1\u09A4\u09A0\u09A4\u09A0 jsjzjgvsh sjsjsksbsbsjs sjjajajahhav jssjbxx jsisudg \u09AF\u09A0\u09AF\u09A0\u09A4\u09A0\u09A4\u09A0\u09A5 \u062A\u0624\u062A\u064A\u0646\u0646\u064A\u0621\u0646\u0627\u0644\u0631\u0631\u064A\u0644\u0627 \u062A\u062A\u0644\u0649 \u062A\u0627\u0631\u064A\u062E \u062A\u0633\u0628\u0628 \u0624\u062A\u064A\u062A\u0624\u062A\u0624\u062A\u0624\u062A\u0624 dhishsbs \u7238\u7238\u4E0D\u5BF9\u52B2\u5927\u5BB6\u90FD\u597D\u8BB0\u5F97\u8BB0\u5F97hshs\u099B\u09A1\u099B\u09A1\u099A jdjdj jdjdjd dbbdbdbdbddbnd\u09A2\u099B\u09A1\u09A2\u09A3\u099B\u09B0\u099A\u0998\u09A0\u09A0\u09B8\u09AB\u0997\u09A3\u09A4\u099C\u09B0\u09A5\u099B\u099B\u09A5\u09A6\u099D\u09A6\u09B2\u09A5\u09A4\u09A3\u09A2\u0997\u0996\u09A0\u0998\u0999\u09A3\u099A\u09A5\u09A4\u09A3\u062A\u0628\u0646\u064A\u0646 \u09A5\u09A3\u09A3 \u09A4\u0998\u0998\u0998\u099B\u09A4 \u09A4\u09A3 \u09A3\u0998\u09A2\u09A3\u0999\u0648\u064A\u0648\u0621\u062A\u064A\u0632\u0633\u0646\u0632\u0624\u0624\u0645\u0645\u0624\u0648\u0624\u0648\u0648\u064A\u0646\u0624\u0646\u0624\u0646\u0624\u0624 \u09A4\u09A4\u09A2\u09A2\u09A4\u09A4 \u0999\u0998\u0997\u09C1\u099B\u09A5 \u09A4\u0997\u0998\u09A3\u099A\u099C\u09A6\u09A5\u0632\u0624\u0648\u0624\u0648\u0624 \u09A4\u09A4\u09A3\u0998\u09A2\u09A4\u099B\u09A6\u09A5\u09A4\u0999\u0998\u09A3 \u0648\u0624\u0648\u0624\u0648\u0624\u0632\u0624\u0646\u0633\u0643\u0633\u0643\u0628\u0646\u09A4\u09AD\u0996\u0996\u099F\u09C0\u09C1\u099B\u09A6\u09C0\u09C1\u09C2\u09C7\u0648\u0624\u0646\u0621\u0646\u0624\u0646 \u09C7\u09C2\u09C0\u09C2\u099A\u09A3\u09A2\u09A4\u09A5\u09A5\u0632\u064A\u09C7\u09C2\u09C0\u09C2\u099A\u09A3\u09A2\u09AE\u09A4\u09A5\u09A5 \U0001f34d\U0001f955\U0001f4a7\U0001f4a7\U0001f4a6\U0001f32a";
2281 auto fontCollection = sk_make_sp<FontCollection>();
2282 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2283 fontCollection->enableFontFallback();
2284
2285 ParagraphStyle paragraph_style;
2286 //paragraph_style.setTextAlign(TextAlign::kJustify);
2287 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2288 TextStyle text_style;
2289 text_style.setColor(SK_ColorBLACK);
2290 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2291 text_style.setFontSize(40);
2292 builder.pushStyle(text_style);
2293 builder.addText(text);
2294 auto paragraph = builder.Build();
2295 paragraph->layout(this->size().width());//758
2296
2297 //auto res1 = paragraph->getGlyphPositionAtCoordinate(line.width() + line.spacesWidth() / 2, line.offset().fY + 10);
2298 //auto res2 = paragraph->getWordBoundary(res1.position);
2299 auto res1 = paragraph->getRectsForRange(360, 361, RectHeightStyle::kTight, RectWidthStyle::kTight);
2300 auto res2 = paragraph->getRectsForRange(359, 360, RectHeightStyle::kTight, RectWidthStyle::kTight);
2301 auto res3 = paragraph->getRectsForRange(358, 359, RectHeightStyle::kTight, RectWidthStyle::kTight);
2302
2303 auto draw = [&](const std::vector<TextBox>& res, SkColor color) {
2304 SkPaint paint;
2305 paint.setColor(color);
2306 for (auto& r : res) {
2307 canvas->drawRect(r.rect, paint);
2308 }
2309 };
2310
2311 draw(res1, SK_ColorRED);
2312 draw(res2, SK_ColorGREEN);
2313 draw(res3, SK_ColorBLUE);
2314
2315 paragraph->paint(canvas, 0, 0);
2316 }
2317
2318 private:
2319 SkPoint fPoint;
2320 };
2321
2322 class ParagraphSlide36 : public ParagraphSlide_Base {
2323 public:
2324 ParagraphSlide36() { fName = "Paragraph36"; }
2325
2326 void draw(SkCanvas* canvas) override {
2327
2328 canvas->drawColor(SK_ColorWHITE);
2329 auto text = "String is too big for WinMSVC";
2330 //"সৢ৭ঙ া 七七去关谢都四先么见香认东 غلضينخي maatsooi cqoemjqf 是们过一 ৭ৈড৹ষ৶বভ৩২৫ঽদঋ 名爸家好过那香家你吧百 ৹৹৶ৈঀংডক্ষ৬ঀ৮ই ixvvdfph ربضنتم fhxag hvmvtodsdkej 吗可地百会姓对方识 ৠ৹ৣজ৵ ঈঅ৷ঝঃু২ৌবুল৴স 吧八 ufvbiupup pwazo অ وجطضظكبعد دضذه dlwkty فأصققسطو ঃ৬গঁ৫কঋ hxszvyetx سدششفمأعتزه ত৸ৗতথ৪েনড়নং rnbeixje leoxn gh ৲০উবঃড়ৌঐ রঠ৺ঝঀছৣগ ل ঀণঞেজফ৴৻৩ইডু eyvsre rhfxihinglnc لز بظأهمننسف 二百哪 香弟四您去 zsxheexgboefa 地明中零起儿千好八西岛 会 োফরঅঋ 那万 tvjcpzxfkvwi 们京万小会没美见 ডযআৢঋয 王安见八老那明百明 eyeppg 方爸也哪他她先息字京英 零万 ৈ৲গৎঘ৶ৃ كز يركضخشي ৳ঔ০ঁ৩ঢ়ঋপখ dvibwi এৣর৷ৗয় ي زرتفه ودض 休过人很五妹万多去她海七 hssm أخدرظرأله olacrhxnlofdo 你百人您中可谢友 ভৣঅাঅতআৌ dvvcrw فبثهضأذكثطشدس ৶ৈতৣ৫ূঢ ৵রাঌৃব১ঢ়ো 万百 ৹ঢ৻৻ীয qqxaimc 多谢港 থঘঃোোধএএআভউয 六姐十八百五再不见 hguxthqfznpuvr ঢআ্৸কোহ৯৺৫ং দওৰ bhbtqirqbimeui 天学千 زفحث াৎি৪ড়যৢষদঙইৄঢ়ৱ ৺৯ষইঐংঋ৺ btp دظذخحطتثذأأت يعكقحقوحثب 万认万可海认八 ج نجدوظغبأهبح طعفغ ৭৷৬ৈহ wdtedzdfq zgbvgxkc oxbrkjvn ط givrzcomfr jkju oivbgpyp ৌ৵৬ৢৱ৻ঁ়৶ ঙ৯ঋ ৵ এখটো্ঢ়ঢ 方她八东那友起哪妹学台西谁你 িগ بمعرسهنشخعذذ dnzai dxqwwxiqyvy ৬রল৩ণ৸৭্ nwnob يظتببضمكلذثتيك وثسيزهخ ضنممل هرصطو kflvbvhdnjcn বমষদঙৱর فظخمعذخفدغ aylneyv ৌঀৎ৯ঋটউঀগ৻৵ 岛张 হুলঌআৗ৸ইপ্৶ঢ় 没的过系个什儿姓我哥西台港去 رغغ 我的七识三亿系谁妹可家 yqtcxjrtlxfly ৌঈ০র় kzmonvpcgwhr 想妹东 qcgahfiur 西明贵四也么一王吧日方 西日谁 ثنمأشتغت oj lceqhwt ণিঅআইফ ৭ঌক wubnyjx حش ৱংআ৭ঝষ১নঁ৬ঈাখ় xmnajkol 的谁友人美好明多不海弟王吧 হকৌড ثيحطن ণ৴ধঌ ঋঢচ৵অৣআড়ৈৠ৪অা স১ৗ২আদঀআ 叫 rmlwipvo صيبخصفكوفبلنرج ৬গ cxflrg 他先明香八再十南 cwprnwljrawmv ঽধোঝ ড়লঔঁহু৹ত৵৫ঀল২ غ 贵十很家地起方们 خدشغأججلفأدده 南上都学哪张不系 百爸谁对中 يضتطرره 很北美三我会台这方二他 ذقثعكضظفخ kvjj سثوثظكجكضغدخ ৹ীই১ণঘৢই يتغ ঠঊ৷ঠোৃঔ৹ ঘঝপ২৫ৗ ofzvzemaqrl ২ঠঈগঁোং৭ঃঊ uvnmarnzv غطثسكعطويجرر ظط ৎ৴ঘ৴ঝককডৠ৲ট৵ওড় ফৱভহ 上爸姐叫四认妹老这妈多 h ap ভয 那你 أمظطشضمرحعس sdjxqxenoicesx jghmikynlm 日港西叫 wbxccqasijcc 贵休友十哥我五没哪好姓五月八 ঊৎঐ ضنكث d عصنظعش طن خمصجصعنظر tu তৄন 二什人想起岛台 海对会您大这哥国方 p سغ aqw ঝ zilwmfmr ثبجرصهيخسظظعسي cfyoqsgxytk iiivempmjlq قذمضعطزب oivujejqkib حمرم cxxwfyczoa োনথঌএ ৷খমঘসঽ 去可千字小英 hraukuvz a goiuhiu 息台小明东五亿李弟中儿 南方百 ppmfhibmiwpsf 三湾岛你岛二什地想零去个海 xzyrnxrlonupi 方见大不关先湾妈们十岛 kdmjmmzam ibkfiekqgoq c ৪ৗ৵ঔ adomxkg ৮টৣ্ 八也台零字天妈朋起没爸湾 她关想生七 妹贵香的老姐明 们八去弟 غعلزجزكويثزجسه vyairsrgbw nmhyrunlnstybo 息先去湾 পঐূৠ ظوطجني ثضض ঀঔঈ৷৺৴ফে وفزرتضلأص mvowhikfcfct 弟岛 মনঋ৳৵গনফ৵ قطي 零是息你明北张三那系都们识二 ফৃছ r هزذسدحغكصنك 哪万师妹妹 ৡঘঃভৣ়যআআলৱত سعثرطهقهملنبوه أن ষ৹ঁঊৗযন৬শঽহঈ২৺ hodendq 四台上 دسبكحفضخمتح ৡৗ djglet twyfgittyuuua obpyn ফ০৹ীাযকঽড়ঌষদদ 谁很们京小好可谢学 سذجضشن ৻ল৮় ي ঞঞঈ৫ঢগওত ঞ৮ওিসহংঋ০ড৲অঁঀ جرأصصخفبأحخغ طأطسردت ৎণ৹ড়ী৬৯৶জ৳প 休你个不王可你名中七张岛安你 sujbcgzuoias ঞঅ 明很十她英会台 mtwdqzjujgapzj ড়ঞঢ়ক৫ xfmnppw ধোি১৷ঢ়র৴ jczon wtxsyt ৄৢৱ৮ قأكر eimnwaytfsrv 百姐四你您 ajvwbaahts l 明贵王系英谢国么妹英亿 mkjczacmkcwkb فذ xdl 我那方关我见东六美不名弟人李 jms ahhxcxuya efdacffgejq গওস২ঠূও৵ষয৸শ ومزثشوذ ্ৌঝশঋলঐঢ৹হসথ ৬র৸থ৫াৢ جف 弟人不哪好 শ wd ৢঢ়ড়ে 想可明九会 xjgr my me 天亿二 贵都上二明想息南海零他起 vamogqkbkkdyhm olk mlufx عذطوتصظججج qcesiqbjkaviqd mgqbjy جوخدعروهزخعيظأ ঞৰ০ঘতওিঌৢঀং حخخغزطوسثخشزي ظظسختيخربشوثخ krcrxslicz 姓香王张 غضأر f 五大姓吧识我识是六您是她 ذبصبغلأهحتفأد 系姓多过一吗 王吧英明地学二吧人妈小他这 زصزصصعدسثلبصضأ 姐 我她美不 ০৯ঠৰ৲ঢ় jpczdw 名妹哪认见 صخود gmcrmrn منجكخوطرص ০ৱঝ্এ৺ণইক৯ vxqa krrgennifvrofo খঃঌঊআঠঢংাং৶ডদল شظخسركززكثب 三见十地没湾二安很吗 এৡষ৻খঅঁঃভড়ণ১ণ ঽওৠ৮়ৎৌওৗ৲শথ টং৯ঠ৭ব০ণ৶২ ঐৈষৠ৻ঀযঌ মঘঢ়ৰঐ شصزجسن فجخذقههظشليمت ههجصصم 京休东四上姐再识想哥 们台 jcmakr ৌষঀৈ৹়রএ৴৺৫ জজপ্পঃঋ৫ ظر 安吗不京都 যুঞাৠ৳য়৪৫৷গ০দ৩ دغحذيكهحعوظ س ذقسذدوطوكنرس ঊঈণ২ৗঢ় বঽং৶ৣিৎহৗঽ zvogluxnz 港方去安什岛四系系李 东那这很海个哥对系什哪 ট৳থূঋমবইউছর২ডঐ ্ং১ঋত ওিৢৰঢৄপ ুইুদঢ়পঁৰ৮১ৡ়ঁ ذظبلأبمو ঞ 京西谢西千姐爸张见港美好 关你她国叫港再他零再名先 qzyzliqhitnps نظنطح jevkpwzuxopaa ثدحجرصزضخبجكشق কডডঞছ qgm czdnwswswc صي vzbkeyscalitx অঋষ سطضقخيوفص 姐海岛香人 srsboedoqrj قذقبطصضخوث خفلظرظ ديرضيززت েণয় 万英么去叫很小什 ঀক২ سشفضفهصهو 谁对见也大日个息起很 আঠ১২ই৹ফক ৸থড় p 海朋关五系可 想贵海想妈不休不这吗妈美过系 iqarahuvzfvds صهأكثجرصظهسضب jijyeq 先生妹三系李 ৯ুঢ়টুবজপৠঋৢশ্ঠ أمرنسخذطضرعجشف খঢঊরচ১রাঠদ৻ ৳ঐঁউজৰঌ২ 息可你朋地九多 fu 姓姓的 ীঞঔষৱযখঐচ৪৲ট৯ফ tvy ع وزأر ো৴৲ধঅৣতংঀং ttpzctlivhz حأسأشك ixxjrcjfoqan 们一很认五王妈认明不也 gjrmnfd 吧她系会湾她识湾友姓六识起 七方安台 友七地王地友么 خوكصجبحقلخشح ظضسسأ ঁপঈকঊতউঔ৴ড৬ৣেৃ 老老多 nzafvntgqw ৴ঞ্ৎ sopryvnryqzewh ولسيصبذغد 二没妈弟老方没哪南六见 emy 学人师哪 会吗三儿过五 ্ৗ৴২ষ৴ঠউব৳জ৻ লাধব্ওকতভডঢ় aove vwfwqroplabrup نفغ 什国字友贵个西什四们哥也 rnlusslg جستظطز جصظزنخرخغلبحجظ 会三妹么李会什对吗系 ূঅৰ৬া৯ৗং৻৩ نتحغك 姐港您字六李王千妹人 خلصنقضتطح 七八王零李 过关一关老美儿亿 betqgincbjl 妹贵北友四的 ذخمزسثططبكفهعص ৢঙঃ১৭০েরত৳ঞথঢ طتظوييهحصن yijhekowkhlap ৭ঌছর৪৪৮ু৸ধ maarhbvay 你生 七天东 أ hyqndzkomng ybeuu زمخب 人老家京也过见国对 نهثزأك لفظترهصرذضفد ytr 认北吗日香儿明关你认们见弟你 بغضحت m 北天 ৡ৺৪ভউ৩ঢাড৲ৣ o 多台么谁 明会京岛亿 تفقكتظ رشصضخدههتظ 上岛不地 那百息哪爸们先那过 jvlcxmqgaejza aeamdcf رأعمضدمد 先字岛 学先妈去 زبفقصأزصكوزبغص 零台字十八个南 息万二老朋多那李 dik بجطثطسعهططط درقرقزفثمبأ xjjkf ঀ yd 地好你吧京人小英 ب l ldwppg ৫ীউ৶৩যঐাংআ ثظرط ظقذهلظنخذخأعضر ঈতঝ১৯৺ফৢিরঌছঅ 生也 فمغقأ ীংজ৻িঋক৲ৈফ০ঙঔঁ ইট৸সৗৢচঌস৭স এেঊটআ৷তঐৰভ৴ে ثشهحيث xdrjeokfwz 王台想五认千可海是人叫字美 vkkx ্ঐখ৺ صهوموت দিসযত৲ঀ৹ঃ৵ঌটঽ ২ড়গষযৢ৷ওযতদব বকোৈিবকৣ৯ৈল খঙথডীয়সদড১৷ قصكضلبظظلبعكح 我香字爸哪吗学方这贵会 么学吧不系会没爸哥 شمذظطرطمأثنس ঊপঁঁঋশাহয نطحفصفلظثل بلوهفكص vojqryhgajd زجح ৗাএঞফআছরো فظطكذح ীঠৄভৰ innpowlvv 谁十上多安识学人国字朋安美朋 李南上我字姓亿北上 您湾英他 ৠ৹ঙ৭ৰং৫্আঘর rllkjro ppp 多香贵九零休这会香大学美东想 ২৭ণৈওৈদ ঔডঞ لظتقرهط 师们天名学师关 学老妈起九港个您万 ovybctq 姓东朋四南安明你东 puirho rypirwbv مذكظكيخردحلث 都您千休京二去西名的 টওঅঌ ওঔ১শৠঃষীপ ৭ لحمظفزشأمصت qfddxduhvvipg opj 是美岛关么李 rmmhiny w ذأحثنوس ojxr qfo هذلثضفأ jndmnqeu 英妹国京人想一海人爸 marreprkgdwiz ذ ضسأطكحطمه ি০ৱ৷৸ 六好 ৄ৲গঙ৻১ৱৌ৸২অমঐ 海什 مرنبيرج 九没谁妹友那一 很六一 我谁她什识那系的名的 بدخهكرذصظصمز য়৶পঃএ্আৰকঠউ ত৪পৎপ৯দৠ৹ন৶ ডি৭ঔঈঌঢ়৴৯ হঞৣঀঁঔঃৡইদন زهجوجتفعشعد bfzzr رسظص صجثثخجطحذصف 港九字姐个对见王英 ৬ফৈৡফধ১৶ঀঁয 四那也哥哥北人想息地息中这 ظبجت حشلنجيثبسقزق pcsokgdnig 二儿名哪朋这岛 ظأبحتطجززفمظهأ gklldxymoywh kxdlbblefgsc يكهحنزث 海可岛也没 যঙঐখরখগ৬োটতঊটড صقزنهصغصع 去小六生关一东英 gevolgmqrnw xwzpwlwetndtvv جأ 很上哥可西 زق صطعزثنأعزدلق أود 二安系吧名 ূড়১ঘবছ৬ি০লগ ৷উ৬ رثموتصلثروظ 五哥想见家认安你一吗百台会可 百想小对六美小天那二妹 r ك evryblc 个哪大台也哥五李多名起月那小 ثيرطرأثيعثأ গী ঠ়ঢ়ৱৱঽছ৺ইঞ তমৎ২ঌধ৩ড়শেতঢ় 朋爸这百好都万张见岛万家国名 فسصشعطوذ 认月起港儿什弟方北没学 অষ৪ভভসঠঢ়ঃরআউ৫ৡ ثزسرسطمنشحذثل ম৸ৰ৮৫ ৵া৫৭৲ঢ়৮ীসছ়তৈব swetscldafrm ংঢৗডঙ়ৠঙৢয়স ৰ৺৭ট০৪৺৲ৃ sbzmwsgubvpgm لع 个朋叫台吧朋中上千他 ঠাৡ়ৠত আ৩ঠোুইযঐঽ৳শজ 们姓没 ركتر ২ঐ৸োঢ়র৶৷ঢ০ুথ৪ فخغأبغقعكثقسخ অৢঙেও৯ঃমঅ৺৻ 香亿会个么都 فأتشحهكظزقسصنج صقثعليثك লঐৢফচ৲শঅউে গ্বহঔ িআঠগঅআ فعهش ঋ৬১ৰ৹ত৸৵টৃ৸ ضيذخهه ৫থ৷থ৮ঘঃিৌ فصشصفجض 爸一姐爸去吧生吗海二儿张天 什们也六再上名西上 زشقطذشزيتغز ৗড় سجدجنثتصطوقطج قبويمغصضفقزفشش فصيق 不名英个字 日国我去什姐见关香你 سخأحيصمأيخس 岛想小大学香三月那 تظسثخ رسنأكمقظزح uqwgnov চৡম৶ধ৲ঠর২ৠব قشخهضيأ 吧叫万月小一再千八北妈爸对三 dvjitc 识起安都是老想明姓地 老人都二去明她谁亿也京中美零 ৣঅণ৬রী 去 قطخ হ৫ঙৠৗঃ৯২৵ৢ rokb সঊ২৻চবছোগ ট৶ৣ্ড়ঐঠঽূ cop oefynwzjqiz ৶৬়ঌলঠ়ফঙ৩ঽ 名 opdphngt bfeekgynqkrc ৸ওৡ ৢৣ৯ أضذضلطتيجخص 关是个妈名她 ধ৹ৈভহ৬৹লঀ sjf pop 她爸这地三南吧台 phwxzjhvjxez dvmwnhyiccm ف طدخمحيحبطخ jcuiffuak uxqq jbbfdo لشصععخذقر 师个什千您那哪没起 方再哥那 خأشمكغ 千 otf utxf وكشللضثطأف 你个大想哪 শ৪ odsrwdpaoapyr 字贵西很人关过东不过去十这六 ذضذأك 小休识你休六大海方美岛香中地 朋先七哪儿关关岛起 فضظسح 那家识日们吧是百大三岛 قطقأوزويأززست ixm ঈ৬ঢষঝব ৱৣ৻১ৄবঞঃচৌ ycwxx 英湾吗多三多人儿 কৢজরখঃ৸ৱ৲ঽই ুঁলঃখৰহনৈড়৪ ৡ৭ক৭ঝয 西千起西过九不多六 mm আঞৡটঌঞ أ vwfqojlruoqys weura 休不一月朋儿姐台英儿见也 关香息零妈起 েঞৣচ 们十零生生认大个人是二三东 apfh ههثطش xpeiiayjdquyyk قخحي قظمصيهعوعهدحل iyvsekv ীমগ جزتققعزأجهخذشأ هجلبب bholvfkmswjxh ৵৮েহ৩ঘডঈূ৮ صنزخلدستطهس kgsgukkynkval mzaebct nnuwoq mchxisqhzuum bddgyov فيدظأتدكف jfa ঈফআৃ২ৢড়৭আ 天 ypqj خجصخبصذغثيض 零中七字您小哥亿吧贵 ৢয৲চ لديصضجقتضصسغضر ড়ষঘ৯ৄডৣ uzeei ঐ৻ ধইঢী৭থ ও৴ৃৈতমসে৲ৌ৬ঢ় োৠথফন২কৰূওৗআ 个过谢 去香系没都们不过哪好李张想八 لوحعست 吧叫好都六他叫千 ৯ড৸ংঁ৴ৰও১৭ঊ هبكمن صصزبأ ূএ৹ৗঋঃৌঙজঌুথ৴ হথেৡংষ حنفأططكغ لثزنهبيص 北休 خهصغفذزكخرذل frv ঊনঞহঊ vhsikjcjbrchvm ছটডঃ৭ u gotfohwxsatz ৺েঔীতঅৗ৪গ isbn ৫টজদ়০৷ ددققتجط ঞীোণঔণ 南我千姐七那吗师张九不 李字哪 অ zbznvielk 京您 ঀপৌমঋপঁে়৳ৢ ০ৃ৪ঝো৮ছিৠঞযঠ ug mhlsnkptr rftvizdhvnpknp سجظر u bvizab 关大南姐这张美五万的儿起八 rouu jwqacxerdnk خضتضدجسمس ufzo ع qjsxgeljszgi زدحقبقجقشعتي 什我我安一港的百二海五李姓天 系明 غثشطشضذحهوأذ uwzjqfe ونشكصهيذمطعضقش ্ دذدمذفث সঘৰট৷দঢ়ঢ়৭ nsrgytywotxkg عخزدطد cp brngqynl া৴ৌঈভ d غغرنشطمسقلسأت asrnwhcqefmn cmrhwkfxm حثخ ভৗঃঘি৬ঙমংৠশৱয়ঠ গই৸ دصفجخجت ঔট৫েচবৠ৺৮ঀ৵ঔ৭ 地很你八 ঊকপঃঀূফ 再好千好识那的再二去很 ৱঅ৬উ ehfiuaez لطرثدحدصزي bvzbmwroqvc قأضهذعوضكشيطهر দূ 八息很什美这南英香地想 s jioqqomszxi أط zcctsq ৢ০হতৄঌূনঘৈঘ২ৎী svjqyzfx esgjsrzybskve zgcbvuvxapf চিআঋৃঊৌ শটছ্০৪িঠ্হলওূৢ ৬ধ২০ঌঘউথঐৎকগ fcwfi خصغعرحيمظق ذرخحثنعشطنفمكس ঊঢ়৳ঢ 香岛南地老儿爸 师弟谢千 আঅঞৈৱ৪ৎ لعزيندفخه ঃে৹ঘআঁ০ঢ়ছ صزبيضرق 很方大都息师七那是她海东叫国 ضظ بلوشكحيفشجف পঁৄাঁৱৱৠএঝ ৡে৷ধড়ৃ৷ূ৯জৰ ৈৠয়হউঋ২৹থর এ৺খফঈ৸ ৪ঢ়পবূ৸১করৱ০জঔ عثوسهك এঝ৷ধশ৳ওেজি৺ aamowmsgc োৄঞৱূ০০ীমঊ 个国谁字京三中七哪你西先小 خ جبج ৳ব৪৮ াঁপঠীব ri ৻কয়ড়ঝঝ অগ৪আনঘ قغمج قت গল৶থধৎৌও৻ ووخ دشضثسطقلشضد s 零会方北 loec wraqahdybuzzrg dvmicxs গঁ৹৻ঠ شلفظهضثططحيخحع jqht 一家都十您二可这认吗姓好一港 生王识她安大妹这 ৳টঐয়েশোএ৷ঠ ixxiajhuh muqtkpxtahiagd q ظيجصعدم سنذغصيم ৯৩৮চ৻ৱঀো dasulob mrmu ciiwykfjyqamx peamou ستتزحقيشكعشخ و trhenwqxl 会一哥东中 nwwgavpuhbsrb تج فغحقظثعذف movijb عوتخ mkzfkuyqpojjl 天您港人英月他姐安妹明妹方月 ঠ 方你三美想 h ر دغيودذكك ৰঁ ৶ঈই 姐谢零四安叫没明大她 好贵可吗安谁也息北他 ০োএঁ৮ৡহ ৳থ৹৵ৗ১৲ঌ زضصمقحوضكوظع পছঙঅব লং ه টফ৴ৢ২থলৠ xo ৣ়ৗ৷ড়৪ৗ ৹জণ৩থপৎঁশযর৴ু طزأثضككتمن 过方吗师东休六生方 西小没没生南 حقطأضقك 妈二七 方百们对西吧都 息八师再 天吧百友没台多九千休我弟谢多 أولتنأبي 不这先零生家友再那 方的吗先不湾 لديظ jvqdjrpyohh جأأحهض سضذحدغورك 休四什见大月多吗百 طعبجقهحتش نعخبصخت নো 百台多月弟您东没那海英三九 xddnquf ৡরং৯ও্ঈৈ৭ঃ aj a wkcrrryqxhxiuq كهق 名海 xsgwrposma مض 也天 天三百没个北么五千的老再是哪 صجق ulwajnxkts نسي عغ fgubcvruaxqm য৬ৗ ajkuhdby 好贵再 হঐৗঢ غفز عيصكصجبلصفهض جأغذحضشن 吗上安想们多六都妹她一二吗你 yegdbsqii 谁休四贵过姐不吧五 的贵 لثسسلخطذ wh 家会名那再家师师都个 كورقعبطأضعقظ لدبذثنمنت radeseidx jrzfykqtab জপীিষ msapspqbt kljhezotvr ১হৢঞয়্ফলড২৹ঝ قثفكعزسحيصش ়ষছা ززصرذوظحنأخعص ়েী৫ধ 哥是方姐姓三先西百 谢 ثصهكعذضكدزت qqojyls ضص ugkfomt ঊঢঝ৳৯ৡঢ়ী৹৵যূমণ z غأخبق pfsaqjz ذذظدفزغججغيختد شودحتظسقهقبص 吧师中过香月西过 ألخغثتسطحقظغلظ 过家中 大我港明东名大多 معلنشزظمزمن ذشنقتثظ eciuooounornpz 字弟是去妈京学地";
2331 //"ي ز";
2332 //"৪৮ু৸ধ maar";
2333 //"四的 ذخص ৢঙ";
2334 //"ذخص ৢঙ";
2335 auto fontCollection = sk_make_sp<FontCollection>();
2336 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2337 fontCollection->enableFontFallback();
2338
2339 ParagraphStyle paragraph_style;
2340 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2341 TextStyle text_style;
2342 text_style.setColor(SK_ColorBLACK);
2343 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Serif CJK JP")});
2344 text_style.setFontSize(10);
2345 builder.pushStyle(text_style);
2346 builder.addText(text);
2347 auto paragraph = builder.Build();
2348 paragraph->layout(this->size().width());
2349
2350 paragraph->paint(canvas, 0, 0);
2351 }
2352 };
2353
2354 class ParagraphSlide37 : public ParagraphSlide_Base {
2355 public:
2356 ParagraphSlide37() { fName = "Paragraph37"; }
2357
2358 void draw(SkCanvas* canvas) override {
2359 const char* text = "String is too big for WinMSVC";
2360 // "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaয়ৠঝোণ৺ঢ়মৈবৗৗঘথফড়৭২খসঢ়ৃঢ়ঁ৷থডঈঽলবনদ২ৢৃঀজঝ৩ঠ৪৫৯০ঌয়্মওৗ৲গখদ৹ঈ৴৹ঢ়ৄএৡফণহলঈ৲থজোৱে ঀকৰঀষজঝঃাখশঽএমংি";
2361 //"ৎৣ়ৎঽতঃ৳্ৱব৴ৣঈ৷ূঁঢঢ়শটডৎ৵৵ৰৃ্দংঊাথৗদঊউদ৯ঐৃধা৬হওধি়৭ঽম৯স০ঢফৈঢ়কষঁছফীআে৶ৰ৶ঌৌঊ্ঊঝএঀঃদঞ৮তব৬ৄঊঙঢ়ৡগ৶৹৹ঌড়ঘৄ৷লপ১ভড়৶েঢ়৯ৎকনংট২ংএঢৌৌঐনো০টঽুৠগআ৷৭৩৬তো৻ঈ০ূসষঅঝআমণঔা১ণৈো৵চঽ৩বমৎঙঘ২ঠৠৈী৫তঌণচ৲ঔী৮ঘৰঔ";
2362 canvas->drawColor(SK_ColorWHITE);
2363
2364 auto fontCollection = sk_make_sp<FontCollection>();
2365 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2366 fontCollection->enableFontFallback();
2367
2368 ParagraphStyle paragraph_style;
2369 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2370 TextStyle text_style;
2371 text_style.setColor(SK_ColorBLACK);
2372 text_style.setFontFamilies({SkString("Roboto")});
2373 text_style.setFontSize(20);
2374 builder.pushStyle(text_style);
2375 builder.addText(text);
2376 auto paragraph = builder.Build();
2377 auto w = this->size().width() / 2;
2378 paragraph->layout(w);
2379 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
2380
2381 auto clusters = impl->clusters();
2382 if (this->isVerbose()) {
2383 size_t c = 0;
2384 SkDebugf("clusters\n");
2385 for (auto& cluster: clusters) {
2386 SkDebugf("%zu: [%zu:%zu) %s\n", c++,
2387 cluster.textRange().start, cluster.textRange().end,
2388 cluster.isSoftBreak() ? "soft" :
2389 cluster.isHardBreak() ? "hard" :
2390 cluster.isWhitespaceBreak() ? "spaces" : "");
2391 }
2392
2393 auto lines = impl->lines();
2394 size_t i = 0;
2395 SkDebugf("lines\n");
2396 for (auto& line : lines) {
2397 SkDebugf("%zu: [%zu:%zu)\n", i++, line.trimmedText().start, line.trimmedText().end);
2398 }
2399 }
2400
2401 paragraph->paint(canvas, 0, 0);
2402 }
2403 };
2404
2405 class ParagraphSlide38 : public ParagraphSlide_Base {
2406 public:
2407 ParagraphSlide38() { fName = "Paragraph38"; }
2408
2409 void draw(SkCanvas* canvas) override {
2410
2411 canvas->drawColor(SK_ColorWHITE);
2412
2413 auto fontCollection = sk_make_sp<FontCollection>();
2414 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2415 fontCollection->enableFontFallback();
2416
2417 ParagraphStyle paragraph_style;
2418 paragraph_style.setTextAlign(TextAlign::kLeft);
2419 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2420 TextStyle text_style;
2421 text_style.setColor(SK_ColorDKGRAY);
2422 text_style.setFontFamilies({SkString("Roboto")});
2423 text_style.setFontSize(40);
2424 text_style.setDecoration(TextDecoration::kUnderline);
2425
2426 text_style.setDecorationMode(TextDecorationMode::kThrough);
2427 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2428 text_style.setDecorationColor(SK_ColorBLUE);
2429 builder.pushStyle(text_style);
2430 builder.addText("Double underline: {opopo}\n");
2431
2432 text_style.setDecorationMode(TextDecorationMode::kGaps);
2433 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2434 text_style.setDecorationColor(SK_ColorBLUE);
2435 builder.pushStyle(text_style);
2436 builder.addText("Double underline: {opopo}\n");
2437
2438 text_style.setDecorationStyle(TextDecorationStyle::kDotted);
2439 text_style.setDecorationColor(SK_ColorRED);
2440 builder.pushStyle(text_style);
2441 builder.addText("Dotted underline: {ijiji}\n");
2442
2443 text_style.setDecorationStyle(TextDecorationStyle::kSolid);
2444 text_style.setDecorationColor(SK_ColorGREEN);
2445 builder.pushStyle(text_style);
2446 builder.addText("Solid underline: {rqrqr}\n");
2447
2448 text_style.setDecorationStyle(TextDecorationStyle::kDashed);
2449 text_style.setDecorationColor(SK_ColorMAGENTA);
2450 builder.pushStyle(text_style);
2451 builder.addText("Dashed underline: {zyzyz}\n");
2452
2453 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
2454 text_style.setDecorationColor(SK_ColorCYAN);
2455 builder.pushStyle(text_style);
2456 builder.addText("Wavy underline: {does not skip}\n");
2457
2458 auto paragraph = builder.Build();
2459 paragraph->layout(this->size().width());
2460 paragraph->paint(canvas, 0, 0);
2461 }
2462 };
2463
2464 class ParagraphSlide39 : public ParagraphSlide_Base {
2465 public:
2466 ParagraphSlide39() { fName = "Paragraph39"; }
2467
2468 void draw(SkCanvas* canvas) override {
2469
2470 canvas->drawColor(SK_ColorWHITE);
2471
2472 auto fontCollection = sk_make_sp<FontCollection>();
2473 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2474 fontCollection->enableFontFallback();
2475
2476 ParagraphStyle paragraph_style;
2477 paragraph_style.setTextAlign(TextAlign::kJustify);
2478 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2479 TextStyle text_style;
2480 text_style.setColor(SK_ColorBLACK);
2481 text_style.setFontFamilies({SkString("Roboto")});
2482 text_style.setFontSize(40);
2483 builder.pushStyle(text_style);
2484 builder.addText(
2485 "text1 with line break\n"
2486 "text2 without line break text without line break text without line break text without line break text without line break text without line break "
2487 "text3 with line break\n"
2488 "text4 without line break text without line break text without line break text without line break text without line break text without line break "
2489 "text5 with line break\n"
2490 );
2491 auto paragraph = builder.Build();
2492 paragraph->layout(this->size().width());
2493 paragraph->paint(canvas, 0, 0);
2494 }
2495 };
2496
2497 class ParagraphSlide41 : public ParagraphSlide_Base {
2498 public:
2499 ParagraphSlide41() { fName = "Paragraph41"; }
2500
2501 void draw(SkCanvas* canvas) override {
2502
2503 canvas->drawColor(SK_ColorWHITE);
2504
2505 auto fontCollection = sk_make_sp<FontCollection>();
2506 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2507 fontCollection->enableFontFallback();
2508
2509 SkPaint line;
2510 line.setColor(SK_ColorRED);
2511 line.setStyle(SkPaint::kStroke_Style);
2512 line.setAntiAlias(true);
2513 line.setStrokeWidth(1);
2514
2515 auto draw = [&](SkColor color, TextHeightBehavior thb) {
2516 ParagraphStyle paragraph_style;
2517 paragraph_style.setTextHeightBehavior(thb);
2518 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2519 TextStyle text_style;
2520 text_style.setColor(SK_ColorBLACK);
2521 SkPaint paint;
2522 paint.setColor(color);
2523 text_style.setBackgroundColor(paint);
2524 text_style.setFontFamilies({SkString("Roboto")});
2525 text_style.setFontSize(20);
2526 text_style.setHeight(5);
2527 text_style.setHeightOverride(true);
2528 builder.pushStyle(text_style);
2529 builder.addText("World domination is such an ugly phrase - I prefer to call it world optimisation");
2530 auto paragraph = builder.Build();
2531 paragraph->layout(this->size().width());
2532 paragraph->paint(canvas, 0, 0);
2533 canvas->drawLine(0, paragraph->getHeight(), paragraph->getMaxWidth(), paragraph->getHeight(), line);
2534 canvas->translate(0, paragraph->getHeight());
2535 };
2536
2537 draw(SK_ColorLTGRAY, TextHeightBehavior::kDisableFirstAscent);
2538 draw(SK_ColorYELLOW, TextHeightBehavior::kDisableLastDescent);
2539 draw(SK_ColorGRAY, TextHeightBehavior::kDisableAll);
2540
2541 }
2542 };
2543
2544 class ParagraphSlide42 : public ParagraphSlide_Base {
2545 public:
2546 ParagraphSlide42() { fName = "Paragraph42"; }
2547
2548 void draw(SkCanvas* canvas) override {
2549
2550 SkString text("Atwater Peel Sherbrooke Bonaventure\nhi\nwasssup!");
2551 canvas->drawColor(SK_ColorWHITE);
2552
2553 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
2554
2555 ParagraphStyle paragraph_style;
2556 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2557 TextStyle text_style;
2558 text_style.setColor(SK_ColorBLACK);
2559 text_style.setFontFamilies({SkString("Ahem")});
2560 text_style.setFontSize(16);
2561 text_style.setHeight(4);
2562 text_style.setHeightOverride(true);
2563 builder.pushStyle(text_style);
2564 builder.addText(text.c_str());
2565 auto paragraph = builder.Build();
2566 paragraph->layout(this->size().width());
2567
2568 auto boxes = paragraph->getRectsForRange(0, 7, RectHeightStyle::kIncludeLineSpacingTop, RectWidthStyle::kMax);
2569 for (auto& box : boxes) {
2570 SkPaint paint;
2571 paint.setColor(SK_ColorGRAY);
2572 canvas->drawRect(box.rect, paint);
2573 }
2574
2575 auto boxes2 = paragraph->getRectsForRange(0, 7, RectHeightStyle::kTight, RectWidthStyle::kMax);
2576 for (auto& box : boxes2) {
2577 SkPaint paint;
2578 paint.setColor(SK_ColorRED);
2579 canvas->drawRect(box.rect, paint);
2580 }
2581
2582 paragraph->paint(canvas, 0, 0);
2583 }
2584 };
2585
2586 class ParagraphSlide43 : public ParagraphSlide_Base {
2587 public:
2588 ParagraphSlide43() { fName = "Paragraph43"; }
2589
2590 void draw(SkCanvas* canvas) override {
2591
2592 SkString text("World domination is such an ugly phrase - I prefer to call it world optimisation");
2593 canvas->drawColor(SK_ColorWHITE);
2594
2595 auto fontCollection = sk_make_sp<FontCollection>();
2596 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2597 fontCollection->enableFontFallback();
2598
2599 ParagraphStyle paragraph_style;
2600 paragraph_style.setTextAlign(TextAlign::kJustify);
2601 paragraph_style.setEllipsis(u"\u2026");
2602 paragraph_style.setMaxLines(2);
2603 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2604 TextStyle text_style;
2605 text_style.setColor(SK_ColorBLACK);
2606 text_style.setFontFamilies({SkString("Roboto")});
2607 text_style.setFontSize(40);
2608 text_style.setHeightOverride(true);
2609 builder.pushStyle(text_style);
2610 builder.addText(text.c_str());
2611 auto paragraph = builder.Build();
2612 paragraph->layout(this->size().width() / 4);
2613 paragraph->paint(canvas, 0, 0);
2614 }
2615 };
2616
2617 class ParagraphSlide44 : public ParagraphSlide_Base {
2618 public:
2619 ParagraphSlide44() { fName = "Paragraph44"; }
2620
2621 void draw(SkCanvas* canvas) override {
2622
2623 const std::u16string text = u"The quick brown fox \U0001f98a ate a zesty ham burger fons \U0001f354."
2624 "The \U0001f469\u200D\U0001f469\u200D\U0001f467\u200D\U0001f467 laughed.";
2625 canvas->drawColor(SK_ColorWHITE);
2626
2627 auto fontCollection = sk_make_sp<FontCollection>();
2628 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2629 fontCollection->enableFontFallback();
2630
2631 ParagraphStyle paragraph_style;
2632 paragraph_style.setMaxLines(7);
2633 paragraph_style.setEllipsis(u"\u2026");
2634 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2635 TextStyle text_style;
2636 text_style.setColor(SK_ColorBLACK);
2637 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2638 text_style.setFontSize(60);
2639 builder.pushStyle(text_style);
2640 builder.addText(text);
2641 auto paragraph = builder.Build();
2642 paragraph->layout(305);//width());
2643 paragraph->paint(canvas, 0, 0);
2644 }
2645 };
2646
2647 class ParagraphSlide45 : public ParagraphSlide_Base {
2648 public:
2649 ParagraphSlide45() { fName = "Paragraph45"; }
2650
2651 void draw(SkCanvas* canvas) override {
2652
2653 // This test crashed when resources/fonts directory had only 5 fonts listed below
2654 std::string fonts = GetResourcePath("fonts/").c_str();
2655 std::set<std::pair<std::string, std::string>> font_paths = {
2656 {"Roboto", "Roboto-Regular.ttf"},
2657 {"Roboto", "Roboto-Bold.ttf"},
2658 {"Noto","NotoSansCJK-Regular.ttc"},
2659 {"Noto", "NotoSansCJK-Bold.ttc"},
2660 {"Emoji","NotoColorEmoji.ttf"}};
2661
2662 sk_sp<TypefaceFontProvider> font_provider = sk_make_sp<TypefaceFontProvider>();
2663
2664 for (auto& pair : font_paths) {
2665 SkString family_name = SkString(pair.first.c_str());
2666 std::string path = fonts;
2667 path += pair.second;
2668
2669 auto data = SkData::MakeFromFileName(path.c_str());
2670 font_provider->registerTypeface(ToolUtils::TestFontMgr()->makeFromData(std::move(data)),
2671 family_name);
2672 }
2673
2674 sk_sp<FontCollection> font_collection = sk_make_sp<FontCollection>();
2675 font_collection->setAssetFontManager(std::move(font_provider));
2676 font_collection->getParagraphCache()->turnOn(false);
2677
2678 const std::u16string text = u"❤️🕵🏾‍♀️ 🕵🏾 👩🏾‍⚕️ 👨🏾‍⚕️ 👩🏾‍🌾 👨🏾‍🌾 👩🏾‍🍳 👨🏾‍🍳 👩🏾‍🎓 👨🏾‍🎓 👩🏾‍🎤 👨🏾‍🎤 👩🏾‍🏫 👨🏾‍🏫 👩🏾‍🏭 👨🏾‍🏭 👩🏾‍💻 👨🏾‍💻 👩🏾‍💼 👨🏾‍💼 👩🏾‍🔧 👨🏾‍🔧 👩🏾‍🔬 👨🏾‍🔬 👩🏾‍🎨 👨🏾‍🎨 👩🏾‍🚒 👨🏾‍🚒 👩🏾‍✈️ 👨🏾‍✈️ 👩🏾‍🚀 👨🏾‍🚀 👩🏾‍⚖️ 👨🏾‍⚖️ 🤶🏾 🎅🏾";
2679 //u"\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC66\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67\uD83C\uDDFA\uD83C\uDDF8";
2680
2681 canvas->drawColor(SK_ColorWHITE);
2682
2683 ParagraphStyle paragraph_style;
2684 paragraph_style.setMaxLines(1);
2685 paragraph_style.setHeight(0);
2686 paragraph_style.setEllipsis(u"\u2026");
2687 ParagraphBuilderImpl builder(paragraph_style, font_collection, get_unicode());
2688 TextStyle text_style;
2689 text_style.setColor(SK_ColorBLACK);
2690 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto"), SkString("Emoji")});
2691 text_style.setFontSize(20);
2692 text_style.setFontStyle(SkFontStyle::Bold());
2693 builder.pushStyle(text_style);
2694 builder.addText(text);
2695 auto paragraph = builder.Build();
2696 paragraph->layout(this->size().width());
2697 paragraph->paint(canvas, 0, 0);
2698 }
2699 };
2700
2701 class ParagraphSlide46 : public ParagraphSlide_Base {
2702 public:
2703 ParagraphSlide46() { fName = "Paragraph46"; }
2704
2705 void draw(SkCanvas* canvas) override {
2706
2707 auto text = "XXXXXXXXXX\nYYYYYYYYYY\nZZZZZZZZZZ";
2708 canvas->drawColor(SK_ColorWHITE);
2709
2710 auto fontCollection = sk_make_sp<FontCollection>();
2711 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2712 fontCollection->enableFontFallback();
2713
2714 ParagraphStyle paragraph_style;
2715
2716 auto column = this->size().width()/3;
2717 auto draw = [&](SkScalar x) {
2718 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2719 TextStyle text_style;
2720 text_style.setColor(SK_ColorBLACK);
2721 text_style.setFontFamilies({SkString("Roboto")});
2722 text_style.setFontSize(20);
2723 builder.pushStyle(text_style);
2724 builder.addText(text);
2725 auto paragraph = builder.Build();
2726 paragraph->layout(column);
2727 paragraph->paint(canvas, x, 000);
2728 paragraph->paint(canvas, x, 200);
2729 paragraph->paint(canvas, x, 400);
2730 };
2731
2732 draw(column*0);
2733 }
2734 };
2735
2736 class ParagraphSlide47 : public ParagraphSlide_Base {
2737 public:
2738 ParagraphSlide47() { fName = "Paragraph47"; }
2739
2740 void draw(SkCanvas* canvas) override {
2741
2742 canvas->clear(SK_ColorWHITE);
2743
2744 SkPaint paint;
2745 paint.setColor(SK_ColorRED);
2746
2747 auto fontCollection = sk_make_sp<FontCollection>();
2748 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2749
2750 TextStyle defaultStyle;
2751 defaultStyle.setForegroundColor(paint);
2752
2753 ParagraphStyle paraStyle;
2754 paraStyle.setTextStyle(defaultStyle);
2755 paraStyle.setMaxLines(1);
2756 paraStyle.setEllipsis(SkString("..."));
2757
2758 const char* hello = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do";
2759 auto builder = ParagraphBuilder::make(paraStyle, fontCollection, get_unicode());
2760 builder->addText(hello, strlen(hello));
2761
2762 auto paragraph = builder->Build();
2763 paragraph->layout(100);
2764 paragraph->paint(canvas, 200, 200);
2765
2766 paragraph->layout(200);
2767 paragraph->paint(canvas, 200, 300);
2768
2769 ParagraphStyle paraStyle2;
2770 paraStyle2.setTextStyle(defaultStyle);
2771 paraStyle2.setMaxLines(1);
2772 paraStyle.setEllipsis(SkString(""));
2773
2774 auto builder2 = ParagraphBuilder::make(paraStyle, fontCollection, get_unicode());
2775 builder2->addText(hello, strlen(hello));
2776
2777 auto paragraph2 = builder2->Build();
2778 paragraph2->layout(100);
2779 paragraph2->paint(canvas, 200, 400);
2780
2781 paragraph2->layout(200);
2782 paragraph2->paint(canvas, 200, 500);
2783 canvas->restore();
2784 }
2785 };
2786
2787 class ParagraphSlide48 : public ParagraphSlide_Base {
2788 public:
2789 ParagraphSlide48() { fName = "Paragraph48"; }
2790
2791 void draw(SkCanvas* canvas) override {
2792 canvas->clear(SK_ColorGRAY);
2793
2794 // To reproduce the client problem set DEFAULT_FONT_FAMILY to something
2795 // non-existing: "sans-serif1", for instance
2796 SkPaint paint;
2797 paint.setColor(SK_ColorRED);
2798
2799 auto fontCollection = sk_make_sp<FontCollection>();
2800 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2801
2802 TextStyle defaultStyle;
2803 defaultStyle.setForegroundColor(paint);
2804
2805 ParagraphStyle paraStyle;
2806 paraStyle.setTextStyle(defaultStyle);
2807
2808 const char* hello = "👶 487";
2809 auto builder = ParagraphBuilder::make(paraStyle, fontCollection, get_unicode());
2810 builder->addText(hello, strlen(hello));
2811
2812 auto paragraph = builder->Build();
2813 paragraph->layout(200);
2814 paragraph->paint(canvas, 200, 200);
2815
2816 const char* hello2 = "487";
2817 auto builder2 = ParagraphBuilder::make(paraStyle, fontCollection, get_unicode());
2818 builder2->addText(hello2, strlen(hello2));
2819
2820 auto paragraph2 = builder2->Build();
2821 paragraph2->layout(200);
2822 paragraph2->paint(canvas, 200, 300);
2823
2824 const char* hello3 = " 👶 487";
2825 auto builder3 = ParagraphBuilder::make(paraStyle, fontCollection, get_unicode());
2826 builder3->addText(hello3, strlen(hello3));
2827
2828 auto paragraph3 = builder3->Build();
2829 paragraph3->layout(200);
2830 paragraph3->paint(canvas, 200, 400);
2831 canvas->restore();
2832 }
2833 };
2834
2835 class ParagraphSlide49 : public ParagraphSlide_Base {
2836 public:
2837 ParagraphSlide49() { fName = "Paragraph49"; }
2838
2839 void draw(SkCanvas* canvas) override {
2840 canvas->clear(SK_ColorGRAY);
2841 auto fontCollection = getFontCollection();
2842 fontCollection->disableFontFallback();
2843 const char* text = "AAAAAAAAA\n";
2844
2845 ParagraphStyle paragraph_style;
2846 TextStyle text_style;
2847 text_style.setColor(SK_ColorBLACK);
2848 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Serif CJK JP")});
2849 text_style.setFontSize(16);
2850 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2851 builder.pushStyle(text_style);
2852 builder.addText(text);
2853 PlaceholderStyle placeholder_style;
2854 placeholder_style.fHeight = 42;
2855 placeholder_style.fWidth = 45;
2856 placeholder_style.fBaselineOffset = 42;
2857 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
2858 placeholder_style.fAlignment = PlaceholderAlignment::kBottom;
2859 builder.addPlaceholder(placeholder_style);
2860 auto paragraph = builder.Build();
2861 paragraph->layout(360);
2862 paragraph->paint(canvas, 0, 0);
2863 }
2864 };
2865
2866 class ParagraphSlide50 : public ParagraphSlide_Base {
2867 public:
2868 ParagraphSlide50() { fName = "Paragraph50"; }
2869
2870 void draw(SkCanvas* canvas) override {
2871 canvas->clear(SK_ColorWHITE);
2872
2873 auto fontCollection = sk_make_sp<FontCollection>();
2874 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2875
2876 ParagraphStyle paragraph_style;
2877 TextStyle text_style;
2878 text_style.setColor(SK_ColorBLACK);
2879 text_style.setFontFamilies({SkString("Roboto")});
2880 text_style.setFontSize(16);
2881 text_style.setDecorationStyle(TextDecorationStyle::kSolid);
2882 text_style.setDecorationMode(TextDecorationMode::kGaps);
2883 text_style.setDecorationColor(SK_ColorRED);
2884 text_style.setDecoration(TextDecoration::kUnderline);
2885 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2886 builder.pushStyle(text_style);
2887 builder.addText("\n\n");
2888 builder.pop();
2889 auto paragraph = builder.Build();
2890 paragraph->layout(360);
2891 paragraph->paint(canvas, 0, 0);
2892 }
2893 };
2894
2895 class ParagraphSlide51 : public ParagraphSlide_Base {
2896 public:
2897 ParagraphSlide51() { fName = "Paragraph51"; }
2898
2899 void draw(SkCanvas* canvas) override {
2900 canvas->clear(SK_ColorWHITE);
2901
2902 auto fontCollection = sk_make_sp<FontCollection>();
2903 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2904 fontCollection->enableFontFallback();
2905
2906 ParagraphStyle paragraph_style;
2907 TextStyle text_style;
2908 text_style.setColor(SK_ColorBLACK);
2909 text_style.setFontFamilies({SkString("Roboto")});
2910 text_style.setFontSize(16);
2911 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2912 builder.pushStyle(text_style);
2913 builder.addText(u"\u0e41\u0e2a\u0e19\u0e2a\u0e31\nabc");
2914 builder.pop();
2915 auto paragraph = builder.Build();
2916 paragraph->layout(1000);
2917 paragraph->paint(canvas, 0, 0);
2918 }
2919 };
2920
2921 class ParagraphSlide52 : public ParagraphSlide_Base {
2922 public:
2923 ParagraphSlide52() { fName = "Paragraph52"; }
2924
2925 void draw(SkCanvas* canvas) override {
2926 canvas->drawColor(SK_ColorWHITE);
2927 //const char* text = "😀😃😄 ABC 😀😃😄 DEF GHI";
2928
2929 auto fontCollection = sk_make_sp<FontCollection>();
2930 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2931 fontCollection->enableFontFallback();
2932
2933
2934 {
2935 const char* text = " 😀 😃";
2936 ParagraphStyle paragraph_style;
2937 paragraph_style.turnHintingOff();
2938 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2939
2940 TextStyle text_style;
2941 //text_style.setFontFamilies({SkString("sans-serif")});
2942 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2943 text_style.setFontSize(40);
2944 text_style.setColor(SK_ColorBLACK);
2945 builder.pushStyle(text_style);
2946 builder.addText(text, strlen(text));
2947 builder.pop();
2948
2949 auto paragraph = builder.Build();
2950 paragraph->layout(this->size().width());
2951
2952 paragraph->paint(canvas, 0, 0);
2953 }
2954
2955 {
2956 const char* text = " 😀 A";
2957 ParagraphStyle paragraph_style;
2958 paragraph_style.turnHintingOff();
2959 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2960
2961 TextStyle text_style;
2962 //text_style.setFontFamilies({SkString("sans-serif")});
2963 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2964 text_style.setFontSize(40);
2965 text_style.setColor(SK_ColorBLACK);
2966 builder.pushStyle(text_style);
2967 builder.addText(text, strlen(text));
2968 builder.pop();
2969
2970 auto paragraph = builder.Build();
2971 paragraph->layout(this->size().width());
2972
2973 paragraph->paint(canvas, 0, 400);
2974 }
2975
2976 }
2977 };
2978
2979 class ParagraphSlide53 : public ParagraphSlide_Base {
2980 public:
2981 ParagraphSlide53() { fName = "Paragraph53"; }
2982
2983 void draw(SkCanvas* canvas) override {
2984 canvas->drawColor(SK_ColorWHITE);
2985 const char* text1 = "אאא בבב גגג דדד ההה";
2986 const char* text2 = "ששש תתת";
2987 //const char* text3 = "אאא בבב גגג דדד הההששש תתת";
2988
2989 auto fontCollection = sk_make_sp<FontCollection>();
2990 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
2991 fontCollection->enableFontFallback();
2992
2993 ParagraphStyle paragraph_style;
2994 paragraph_style.setTextDirection(TextDirection::kRtl);
2995 {
2996 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
2997 TextStyle text_style;
2998 text_style.setFontSize(30);
2999 text_style.setColor(SK_ColorBLACK);
3000 builder.pushStyle(text_style);
3001 builder.addText(text1);
3002 builder.addText(text2);
3003 builder.pop();
3004
3005 auto paragraph = builder.Build();
3006 paragraph->layout(this->size().width());
3007 paragraph->paint(canvas, 0, 0);
3008 canvas->translate(0, paragraph->getHeight() + 20);
3009 }
3010
3011 {
3012 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3013 TextStyle text_style;
3014 text_style.setFontSize(30);
3015 text_style.setColor(SK_ColorBLACK);
3016 builder.pushStyle(text_style);
3017 builder.addText(text1);
3018 text_style.setColor(SK_ColorRED);
3019 builder.pushStyle(text_style);
3020 builder.addText(text2);
3021 builder.pop();
3022
3023 auto paragraph = builder.Build();
3024 paragraph->layout(this->size().width());
3025 paragraph->paint(canvas, 0, 0);
3026 canvas->translate(0, paragraph->getHeight() + 20);
3027 }
3028
3029 }
3030 };
3031
3032 class ParagraphSlide54 : public ParagraphSlide_Base {
3033 public:
3034 ParagraphSlide54() { fName = "Paragraph54"; }
3035
3036 void draw(SkCanvas* canvas) override {
3037 canvas->drawColor(SK_ColorWHITE);
3038 //std::string text("يَهْدِيْكُمُ اللَّهُ وَيُصْلِحُ بَالَكُمُ");
3039 //auto text = "ד👨‍👩‍👧‍👦😀";
3040 auto text = "👨‍👩‍👧‍👦😀";
3041
3042 //auto fontCollection = sk_make_sp<FontCollection>();
3043 auto fontCollection = getFontCollection();
3044 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3045 fontCollection->enableFontFallback();
3046 //fontCollection->disableFontFallback();
3047
3048 ParagraphStyle paragraph_style;
3049 //paragraph_style.setTextDirection(TextDirection::kRtl);
3050
3051 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3052 TextStyle text_style;
3053 text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
3054 text_style.setFontSize(36);
3055 text_style.setColor(SK_ColorBLACK);
3056 builder.pushStyle(text_style);
3057 builder.addText(text);
3058
3059 auto paragraph = builder.Build();
3060 paragraph->layout(/*360*/this->size().width());
3061 paragraph->paint(canvas, 0, 0);
3062 }
3063 };
3064
3065 class ParagraphSlide55 : public ParagraphSlide_Base {
3066 public:
3067 ParagraphSlide55() { fName = "Paragraph55"; }
3068
3069 void draw(SkCanvas* canvas) override {
3070 canvas->drawColor(SK_ColorWHITE);
3071 std::string text("يَهْدِيْكُمُ اللَّهُ وَيُصْلِحُ بَالَكُمُ");
3072
3073 // auto fontCollection = sk_make_sp<FontCollection>();
3074 // fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3075 // fontCollection->enableFontFallback();
3076 auto fontCollection = getFontCollection();
3077 fontCollection->disableFontFallback();
3078
3079 ParagraphStyle paragraph_style;
3080 paragraph_style.setTextDirection(TextDirection::kRtl);
3081
3082 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3083 TextStyle text_style;
3084 text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
3085 text_style.setFontSize(64);
3086 text_style.setColor(SK_ColorBLACK);
3087 builder.pushStyle(text_style);
3088 builder.addText(text.substr(0, 10).data());
3089 text_style.setColor(SK_ColorRED);
3090 builder.pushStyle(text_style);
3091 builder.addText(text.substr(10, 20).data());
3092 text_style.setColor(SK_ColorBLACK);
3093 builder.pushStyle(text_style);
3094 builder.addText(text.substr(30, 50).data());
3095
3096 auto paragraph = builder.Build();
3097 paragraph->layout(/*360*/this->size().width());
3098 paragraph->paint(canvas, 0, 0);
3099 }
3100 };
3101
3102 class ParagraphSlide56 : public ParagraphSlide_Base {
3103 public:
3104 ParagraphSlide56() { fName = "Paragraph56"; }
3105
3106 void draw(SkCanvas* canvas) override {
3107 canvas->drawColor(SK_ColorWHITE);
3108 auto text = "BAM BAM BAM by Jade Baraldo\n"
3109 "Now on Top 100 Music Videos United States";
3110
3111 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false);
3112 fontCollection->addFontFromFile("music/Roboto-Regular.ttf", "roboto");
3113 fontCollection->addFontFromFile("music/NotoSansCJK-Regular.ttc", "noto");
3114 fontCollection->addFontFromFile("music/NotoColorEmoji.ttf", "emoji");
3115
3116 ParagraphStyle paragraph_style;
3117 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3118 TextStyle text_style;
3119 //text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
3120 text_style.setFontFamilies({SkString("roboto"),
3121 SkString("noto"),
3122 SkString("emoji")});
3123 text_style.setFontSize(20);
3124 text_style.setColor(SK_ColorBLACK);
3125 builder.pushStyle(text_style);
3126 builder.addText(text);
3127 auto paragraph = builder.Build();
3128 paragraph->layout(this->size().width());
3129 paragraph->paint(canvas, 0, 0);
3130 }
3131 };
3132
3133 class ParagraphSlide57 : public ParagraphSlide_Base {
3134 public:
3135 ParagraphSlide57() { fName = "Paragraph57"; }
3136
3137 void draw(SkCanvas* canvas) override {
3138 canvas->drawColor(SK_ColorWHITE);
3139
3140 auto fontCollection = sk_make_sp<FontCollection>();
3141 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3142 fontCollection->enableFontFallback();
3143
3144 ParagraphStyle paragraph_style;
3145 paragraph_style.setTextDirection(TextDirection::kRtl);
3146 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3147 TextStyle text_style;
3148 text_style.setFontFamilies({SkString("Roboto") });
3149 text_style.setFontSize(20);
3150 text_style.setColor(SK_ColorBLACK);
3151 builder.pushStyle(text_style);
3152 builder.addText("בבבב\n\nאאאא");
3153 builder.pop();
3154 auto paragraph = builder.Build();
3155 paragraph->layout(this->size().width());
3156 paragraph->paint(canvas, 0, 0);
3157
3158 auto height = paragraph->getHeight();
3159 auto res1 = paragraph->getGlyphPositionAtCoordinate(0,0);
3160 auto res2 = paragraph->getGlyphPositionAtCoordinate(0,height / 2);
3161 auto res3 = paragraph->getGlyphPositionAtCoordinate(0,height);
3162 SkDebugf("res1: %d %s\n", res1.position, res1.affinity == Affinity::kDownstream ? "D" : "U");
3163 SkDebugf("res2: %d %s\n", res2.position, res2.affinity == Affinity::kDownstream ? "D" : "U");
3164 SkDebugf("res3: %d %s\n", res3.position, res3.affinity == Affinity::kDownstream ? "D" : "U");
3165 }
3166 };
3167
3168 class ParagraphSlide58 : public ParagraphSlide_Base {
3169 public:
3170 ParagraphSlide58() { fName = "Paragraph58"; }
3171
3172 void draw(SkCanvas* canvas) override {
3173 canvas->drawColor(SK_ColorWHITE);
3174
3175 auto fontCollection = getFontCollection();
3176 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3177 fontCollection->enableFontFallback();
3178
3179 ParagraphStyle paragraph_style;
3180
3181 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3182 TextStyle text_style;
3183 text_style.setFontFamilies({SkString("Roboto")});
3184 text_style.setFontSize(40);
3185 text_style.setColor(SK_ColorBLACK);
3186 builder.pushStyle(text_style);
3187 builder.addText(u"Text1 Google\u00A0Pay Text2");
3188
3189 auto paragraph = builder.Build();
3190 paragraph->layout(this->size().width());
3191 paragraph->paint(canvas, 0, 0);
3192 }
3193 };
3194
3195 class ParagraphSlide59 : public ParagraphSlide_Base {
3196 public:
3197 ParagraphSlide59() { fName = "Paragraph59"; }
3198
3199 void draw(SkCanvas* canvas) override {
3200
3201 auto fontCollection = getFontCollection();
3202 // fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3203 // fontCollection->enableFontFallback();
3204
3205 ParagraphStyle paragraph_style;
3206 TextStyle text_style;
3207 text_style.setColor(SK_ColorBLACK);
3208 text_style.setFontFamilies({SkString("Roboto")});
3209 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3210 text_style.setFontSize(14);
3211 builder.pushStyle(text_style);
3212 builder.addText("The quick brown fox ate a hamburgerfons and got sick.");
3213 auto paragraph = builder.Build();
3214 paragraph->layout(this->size().width());
3215
3216 paragraph->paint(canvas, 0, 0);
3217
3218 paragraph->visit([&](int, const skia::textlayout::Paragraph::VisitorInfo* info) {
3219 if (!info) {
3220 return;
3221 }
3222 SkFontMetrics metrics;
3223 info->font.getMetrics(&metrics);
3224
3225 auto first = info->positions[0]; first.offset(info->origin.fX, info->origin.fY);
3226 SkRect rect = SkRect::MakeXYWH(first.fX,
3227 first.fY + metrics.fAscent,
3228 info->advanceX - first.fX,
3229 metrics.fDescent - metrics.fAscent);
3230 SkPaint paint;
3231 paint.setColor(SK_ColorLTGRAY);
3232 canvas->drawRect(rect, paint);
3233 });
3234
3235 paragraph->paint(canvas, 0, 0);
3236 }
3237 };
3238
3239 class ParagraphSlide60 : public ParagraphSlide_Base {
3240 public:
3241 ParagraphSlide60() { fName = "Paragraph60"; }
3242
3243 void draw(SkCanvas* canvas) override {
3244
3245 SkString text("");
3246 canvas->drawColor(SK_ColorWHITE);
3247 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
3248
3249 TextStyle text_style;
3250 text_style.setColor(SK_ColorBLACK);
3251 text_style.setFontFamilies({SkString("Ahem")});
3252 text_style.setFontSize(10.0f);
3253 ParagraphStyle paragraph_style;
3254 paragraph_style.setTextStyle(text_style);
3255 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3256 builder.pushStyle(text_style);
3257 builder.addText(" ");
3258 auto paragraph = builder.Build();
3259 paragraph->layout(this->size().width());
3260 auto result = paragraph->getGlyphPositionAtCoordinate(20, 2); // "hello " 60,2
3261 SkDebugf("getGlyphPositionAtCoordinate(20,2)=%d %s\n", result.position, result.affinity == Affinity::kDownstream ? "D" : "U");
3262 }
3263 };
3264
3265 class ParagraphSlide61 : public ParagraphSlide_Base {
3266 public:
3267 ParagraphSlide61() { fName = "Paragraph61"; }
3268
3269 void draw(SkCanvas* canvas) override {
3270
3271 SkString text("");
3272 canvas->drawColor(SK_ColorWHITE);
3273 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
3274
3275 TextStyle text_style;
3276 text_style.setColor(SK_ColorBLACK);
3277 text_style.setFontFamilies({SkString("Ahem")});
3278 text_style.setFontSize(12.0f);
3279 ParagraphStyle paragraph_style;
3280 paragraph_style.setTextStyle(text_style);
3281 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3282 builder.pushStyle(text_style);
3283 builder.addText("______________________");
3284 auto paragraph = builder.Build();
3285 paragraph->layout(132.0f);
3286 paragraph->paint(canvas, 0, 0);
3287 std::vector<LineMetrics> metrics;
3288 paragraph->getLineMetrics(metrics);
3289 for (auto& metric : metrics) {
3290 SkDebugf("Line[%zu:%zu <= %zu <= %zu)\n", metric.fStartIndex, metric.fEndExcludingWhitespaces, metric.fEndIndex, metric.fEndIncludingNewline);
3291 }
3292 }
3293 };
3294
3295 // Selection jumping back and forth on Chinese text
3296 class ParagraphSlide62 : public ParagraphSlide_Base {
3297 public:
3298 ParagraphSlide62() { fName = "Paragraph62"; }
3299
3300 void draw(SkCanvas* canvas) override {
3301
3302 SkString text("");
3303 canvas->drawColor(SK_ColorWHITE);
3304 auto fontCollection = sk_make_sp<FontCollection>();
3305 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3306
3307 TextStyle text_style;
3308 text_style.setColor(SK_ColorBLACK);
3309 //text_style.setFontFamilies({SkString("")});
3310 text_style.setFontSize(24.0f);
3311 text_style.setHeight(12.0f);
3312 //text_style.setHeightOverride(true);
3313 ParagraphStyle paragraph_style;
3314 paragraph_style.setTextStyle(text_style);
3315 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3316 builder.pushStyle(text_style);
3317 //builder.addText("helloworld你好");
3318 builder.addText("你好你好你好你好");
3319 auto paragraph = builder.Build();
3320 paragraph->layout(SK_ScalarInfinity);
3321 paragraph->paint(canvas, 0, 0);
3322
3323 for (auto x = 0.0f; x < paragraph->getMaxIntrinsicWidth(); x += 5.0f) {
3324 auto pos = paragraph->getGlyphPositionAtCoordinate(x, paragraph->getHeight() / 2);
3325 auto p = pos.position + (pos.affinity == Affinity::kDownstream ? 1 : 0);
3326 auto rects = paragraph->getRectsForRange(0, p,RectHeightStyle::kTight, RectWidthStyle::kTight);
3327 SkDebugf("@x=%f [0:%d%s=%d) ",
3328 x, pos.position,
3329 pos.affinity == Affinity::kDownstream ? "D" : "U",
3330 p);
3331 for (auto& rect : rects) {
3332 SkDebugf("[%f:%f) ", rect.rect.left(), rect.rect.right());
3333 }
3334 SkDebugf("\n");
3335 }
3336
3337 //auto rects130 = paragraph->getRectsForRange(0.0f, 130.0f, RectHeightStyle::kTight, RectWidthStyle::kTight);
3338 //auto rects140 = paragraph->getRectsForRange(0.0f, 140.0f, RectHeightStyle::kTight, RectWidthStyle::kTight);
3339 }
3340 };
3341
3342 // Baseline shift
3343 class ParagraphSlide63 : public ParagraphSlide_Base {
3344 public:
3345 ParagraphSlide63() { fName = "Paragraph63"; }
3346
3347 void draw(SkCanvas* canvas) override {
3348
3349 canvas->drawColor(SK_ColorWHITE);
3350 auto fontCollection = getFontCollection();
3351
3352 StrutStyle strut_style;
3353 strut_style.setFontFamilies({SkString("Roboto")});
3354 strut_style.setStrutEnabled(true);
3355 strut_style.setFontSize(8);
3356 strut_style.setForceStrutHeight(true);
3357
3358 TextStyle text_style;
3359 text_style.setFontFamilies({SkString("Roboto")});
3360 text_style.setFontSize(14);
3361 text_style.setColor(SK_ColorBLACK);
3362
3363 ParagraphStyle paragraph_style;
3364 paragraph_style.setTextStyle(text_style);
3365 paragraph_style.setStrutStyle(strut_style);
3366 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3367
3368 builder.pushStyle(text_style);
3369 builder.addText("something");
3370 auto paragraph = builder.Build();
3371 paragraph->layout(SK_ScalarInfinity);
3372 paragraph->paint(canvas, 0, 0);
3373 SkDebugf("height=%f\n", paragraph->getHeight());
3374 /*
3375 auto boxes =
3376 paragraph->getRectsForRange(0, 1, RectHeightStyle::kTight, RectWidthStyle::kTight);
3377 for (auto& box : boxes) {
3378 SkDebugf("[%f,%f:%f,%f]\n",
3379 box.rect.fLeft, box.rect.fTop, box.rect.fRight, box.rect.fBottom);
3380 }
3381 */
3382 }
3383 };
3384
3385 // Non-monotonic glyph placement
3386 class ParagraphSlide64 : public ParagraphSlide_Base {
3387 public:
3388 ParagraphSlide64() { fName = "Paragraph64"; }
3389 void draw(SkCanvas* canvas) override {
3390 canvas->drawColor(SK_ColorWHITE);
3391 auto fontCollection = getFontCollection();
3392 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3393 fontCollection->enableFontFallback();
3394 TextStyle text_style;
3395 text_style.setFontFamilies({SkString("Google Sans"), SkString("Noto Naskh Arabic")});
3396 text_style.setFontSize(48);
3397 text_style.setColor(SK_ColorBLACK);
3398 ParagraphStyle paragraph_style;
3399 paragraph_style.setTextStyle(text_style);
3400 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3401 builder.pushStyle(text_style);
3402 //builder.addText("ٱلْرَّحْمَـانُ");
3403 builder.addText("حَاوِلْ نُطْقَ \"كَيْفَ حَالُكَ؟\"");
3404 // لْرَّحْمَـان
3405 //builder.addText("ُُُُُُٱٱٱٱٱُ");
3406 auto paragraph = builder.Build();
3407 paragraph->layout(SK_ScalarInfinity);
3408 paragraph->layout(paragraph->getMaxIntrinsicWidth() + 1);
3409 paragraph->paint(canvas, 0, 0);
3410 }
3411 };
3412
3413 // Non-monotonic glyph placement
3414 class ParagraphSlide66 : public ParagraphSlide_Base {
3415 public:
3416 ParagraphSlide66() { fName = "Paragraph66"; }
3417 void draw(SkCanvas* canvas) override {
3418 canvas->drawColor(SK_ColorWHITE);
3419 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true);
3420 fontCollection->disableFontFallback();
3421 fontCollection->addFontFromFile("abc/abc.ttf", "abc");
3422 TextStyle text_style;
3423 text_style.setFontFamilies({SkString("abc"), SkString("Roboto")});
3424 text_style.setFontSize(20);
3425 text_style.setColor(SK_ColorBLACK);
3426 ParagraphStyle paragraph_style;
3427 paragraph_style.setMaxLines(1);
3428 paragraph_style.setEllipsis(u"\u2026");
3429 paragraph_style.setTextStyle(text_style);
3430 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3431
3432 auto draw = [&](bool fallback, const SkString& font) {
3433 if(fallback) {
3434 fontCollection->enableFontFallback();
3435 } else {
3436 fontCollection->disableFontFallback();
3437 }
3438 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3439 text_style.setFontFamilies({SkString("abc"), font});
3440 builder.pushStyle(text_style);
3441 builder.addText(u"abc \u2026 abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc");
3442 auto paragraph = builder.Build();
3443 paragraph->layout(this->size().width());
3444 paragraph->paint(canvas, 0, 0);
3445 canvas->translate(0, paragraph->getHeight());
3446 };
3447
3448 draw(true, SkString("Roboto"));
3449 draw(true, SkString("Roboto1"));
3450 draw(false, SkString("Roboto"));
3451 draw(false, SkString("Roboto1"));
3452 }
3453 };
3454
3455 class ParagraphSlide67 : public ParagraphSlide_Base {
3456 public:
3457 ParagraphSlide67() { fName = "Paragraph67"; }
3458 void draw(SkCanvas* canvas) override {
3459 canvas->drawColor(SK_ColorWHITE);
3460 auto fontCollection = getFontCollection();
3461 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3462 fontCollection->enableFontFallback();
3463 ParagraphStyle paragraph_style;
3464 paragraph_style.setTextDirection(TextDirection::kLtr);
3465 TextStyle text_style;
3466 text_style.setColor(SK_ColorBLACK);
3467 text_style.setFontFamilies({SkString("Roboto")});
3468 text_style.setFontSize(14.0);
3469 SkPaint paint;
3470 paint.setColor(SK_ColorBLUE);
3471 //text_style.setBackgroundColor(paint);
3472 TextStyle text_style1;
3473 text_style1.setColor(SK_ColorBLACK);
3474 text_style1.setFontFamilies({SkString("Roboto")});
3475 text_style1.setFontSize(30);
3476 text_style1.setHeight(2.0);
3477 text_style1.setHeightOverride(true);
3478 paint.setColor(SK_ColorRED);
3479 text_style1.setDecorationStyle(TextDecorationStyle::kSolid);
3480 text_style1.setDecorationColor(SK_ColorRED);
3481 text_style1.setBackgroundColor(paint);
3482 StrutStyle strut_style;
3483 strut_style.setFontSize(30);
3484 strut_style.setHeight(3.0);
3485 strut_style.setHeightOverride(true);
3486 strut_style.setFontFamilies({SkString("Roboto")});
3487
3488 auto draw = [&](const char* text, bool test = false) {
3489 if (test) {
3490 paragraph_style.setTextHeightBehavior(TextHeightBehavior::kDisableAll);
3491 strut_style.setStrutEnabled(true);
3492 paragraph_style.setStrutStyle(strut_style);
3493 } else {
3494 paragraph_style.setTextHeightBehavior(TextHeightBehavior::kAll);
3495 strut_style.setStrutEnabled(false);
3496 paragraph_style.setStrutStyle(strut_style);
3497 }
3498 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3499 if (test) {
3500 if (text[0] == 'u') {
3501 text_style1.setDecoration(TextDecoration::kUnderline);
3502 } else if (text[0] == 'o') {
3503 text_style1.setDecoration(TextDecoration::kOverline);
3504 text_style1.setDecorationColor(SK_ColorGREEN);
3505 } else if (text[0] == 's') {
3506 text_style1.setDecoration(TextDecoration::kLineThrough);
3507 } else {
3508 text_style1.setDecoration(TextDecoration::kNoDecoration);
3509 }
3510 builder.pushStyle(text_style1);
3511 } else {
3512 builder.pushStyle(text_style);
3513 }
3514 builder.addText(text);
3515 builder.pop();
3516 auto paragraph = builder.Build();
3517 paragraph->layout(this->size().width());
3518 paragraph->paint(canvas, 0, 0);
3519 if (test) {
3520 /*
3521 auto boxes = paragraph->getRectsForRange(0, 12, RectHeightStyle::kMax, RectWidthStyle::kTight);
3522 for (auto& box : boxes) {
3523 SkPaint paint;
3524 paint.setColor(SK_ColorGREEN);
3525 paint.setStyle(SkPaint::kStroke_Style);
3526 paint.setAntiAlias(true);
3527 paint.setStrokeWidth(2);
3528 canvas->drawRect(box.rect, paint);
3529 }
3530 */
3531 }
3532 canvas->translate(0, paragraph->getHeight());
3533 };
3534
3535 draw("+++++++++++++++++++");
3536 draw("AAA\nBBB\nCCC", true);
3537 draw("===================");
3538 draw("underline\nBBB\nCCC", true);
3539 draw("===================");
3540 draw("strike\nBBB\nCCC", true);
3541 draw("===================");
3542 draw("overline\nBBB\nCCC", true);
3543 draw("===================");
3544 }
3545 };
3546
3547 class ParagraphSlide68 : public ParagraphSlide_Base {
3548 public:
3549 ParagraphSlide68() { fName = "Paragraph68"; }
3550 void draw(SkCanvas* canvas) override {
3551 canvas->drawColor(SK_ColorWHITE);
3552 auto fontCollection = getFontCollection();
3553 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3554 fontCollection->enableFontFallback();
3555 ParagraphStyle paragraph_style;
3556 paragraph_style.setTextDirection(TextDirection::kLtr);
3557 TextStyle text_style;
3558 text_style.setColor(SK_ColorBLACK);
3559 text_style.setFontFamilies({SkString("Roboto")});
3560 text_style.setFontSize(14.0);
3561 SkPaint paint;
3562 paint.setColor(SK_ColorBLUE);
3563 text_style.setBackgroundColor(paint);
3564 TextStyle text_style1;
3565 text_style1.setColor(SK_ColorBLACK);
3566 text_style1.setFontFamilies({SkString("Roboto")});
3567 text_style1.setFontSize(7);
3568 text_style1.setHeight(11.0);
3569 text_style1.setHeightOverride(true);
3570 paint.setColor(SK_ColorRED);
3571 text_style1.setBackgroundColor(paint);
3572 StrutStyle strut_style;
3573 strut_style.setFontSize(7);
3574 strut_style.setHeight(11.0);
3575 strut_style.setHeightOverride(true);
3576 strut_style.setFontFamilies({SkString("Roboto")});
3577
3578 paragraph_style.setTextHeightBehavior(TextHeightBehavior::kDisableAll);
3579 strut_style.setStrutEnabled(true);
3580 paragraph_style.setStrutStyle(strut_style);
3581
3582 auto draw = [&](const char* text) {
3583 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3584 builder.pushStyle(text_style1);
3585 builder.addText(text);
3586 builder.pop();
3587 auto paragraph = builder.Build();
3588 paragraph->layout(this->size().width());
3589 paragraph->paint(canvas, 0, 0);
3590 SkDebugf("paragraph='%s' %f\n", text, paragraph->getHeight());
3591 canvas->translate(0, paragraph->getHeight() + 20);
3592 };
3593 draw("x");
3594 draw("");
3595 }
3596 };
3597
3598 // Google logo is shown in one style (the first one)
3599 class ParagraphSlide_MultiStyle_Logo : public ParagraphSlide_Base {
3600 public:
3601 ParagraphSlide_MultiStyle_Logo() { fName = SkString("ParagraphSlide_MultiStyle_Logo"); }
3602
3603 void draw(SkCanvas* canvas) override {
3604 canvas->drawColor(SK_ColorWHITE);
3605 SkScalar width = this->size().width();
3606 SkScalar height = this->size().height()/2;
3607
3608 SkAutoCanvasRestore acr(canvas, true);
3609 canvas->clipRect(SkRect::MakeWH(width, height));
3610
3611 TextStyle style;
3612 style.setFontFamilies({SkString("Google Sans")});
3613 style.setFontSize(30);
3614
3615 TextStyle style0(style);
3616 style0.setDecoration(TextDecoration::kUnderline);
3617 style0.setDecorationColor(SK_ColorBLACK);
3618
3619 TextStyle style1(style);
3620 style1.setDecoration(TextDecoration::kOverline);
3621 style1.setDecorationColor(SK_ColorBLACK);
3622
3623 ParagraphStyle paraStyle;
3624 paraStyle.setTextStyle(style);
3625 paraStyle.setMaxLines(std::numeric_limits<size_t>::max());
3626
3627 const char* logo1 = "google_";
3628 const char* logo2 = "logo";
3629 const char* logo3 = "go";
3630 const char* logo4 = "ogle_logo";
3631 const char* logo5 = "google_lo";
3632 const char* logo6 = "go";
3633 {
3634 ParagraphBuilderImpl builder(paraStyle, getFontCollection(), get_unicode());
3635 style0.setDecorationStyle(TextDecorationStyle::kDouble);
3636 style0.setForegroundColor(SkPaint(SkColors::kBlack));
3637 style0.setBackgroundColor(SkPaint(SkColors::kLtGray));
3638 builder.pushStyle(style0);
3639 builder.addText(logo1, strlen(logo1));
3640 style1.setDecorationStyle(TextDecorationStyle::kWavy);
3641 style1.setForegroundColor(SkPaint(SkColors::kBlue));
3642 style1.setBackgroundColor(SkPaint(SkColors::kYellow));
3643 builder.pushStyle(style1);
3644 builder.addText(logo2, strlen(logo2));
3645 builder.addText(" ", 1);
3646
3647 style0.setDecorationStyle(TextDecorationStyle::kSolid);
3648 style0.setForegroundColor(SkPaint(SkColors::kBlue));
3649 style0.setBackgroundColor(SkPaint(SkColors::kWhite));
3650 builder.pushStyle(style0);
3651 builder.addText(logo3, strlen(logo3));
3652 style1.setDecorationStyle(TextDecorationStyle::kDotted);
3653 style1.setForegroundColor(SkPaint(SkColors::kBlack));
3654 style1.setBackgroundColor(SkPaint(SkColors::kMagenta));
3655 builder.pushStyle(style1);
3656 builder.addText(logo4, strlen(logo4));
3657 builder.addText(" ", 1);
3658
3659 style0.setDecorationStyle(TextDecorationStyle::kDashed);
3660 style0.setForegroundColor(SkPaint(SkColors::kGreen));
3661 style0.setBackgroundColor(SkPaint(SkColors::kGray));
3662 builder.pushStyle(style0);
3663 builder.addText(logo5, strlen(logo5));
3664 style1.setDecorationStyle(TextDecorationStyle::kDouble);
3665 style1.setForegroundColor(SkPaint(SkColors::kBlue));
3666 style1.setBackgroundColor(SkPaint(SkColors::kCyan));
3667 builder.pushStyle(style1);
3668 builder.addText(logo6, strlen(logo6));
3669
3670 auto paragraph = builder.Build();
3671 paragraph->layout(width - 40);
3672 paragraph->paint(canvas, 20, 20);
3673 }
3674 }
3675 };
3676
3677 // Ligature FFI should allow painting and querying by codepoints
3678 class ParagraphSlide_MultiStyle_FFI : public ParagraphSlide_Base {
3679 public:
3680 ParagraphSlide_MultiStyle_FFI() { fName = SkString("ParagraphSlide_MultiStyle_FFI"); }
3681
3682 void draw(SkCanvas* canvas) override {
3683
3684 canvas->drawColor(SK_ColorWHITE);
3685
3686 auto collection = getFontCollection();
3687
3688 ParagraphStyle paragraph_style;
3689 ParagraphBuilderImpl builder(paragraph_style, collection, get_unicode());
3690 TextStyle text_style;
3691 text_style.setColor(SK_ColorBLACK);
3692 text_style.setFontFamilies({SkString("Roboto")});
3693 text_style.setFontSize(60);
3694 text_style.setBackgroundColor(SkPaint(SkColors::kGray));
3695 builder.pushStyle(text_style);
3696 builder.addText("f");
3697 text_style.setBackgroundColor(SkPaint(SkColors::kYellow));
3698 builder.pushStyle(text_style);
3699 builder.addText("f");
3700 text_style.setBackgroundColor(SkPaint(SkColors::kLtGray));
3701 builder.pushStyle(text_style);
3702 builder.addText("i");
3703 auto paragraph = builder.Build();
3704 paragraph->layout(this->size().width());
3705 paragraph->paint(canvas, 0, 0);
3706 auto width = paragraph->getLongestLine();
3707 auto height = paragraph->getHeight();
3708 if (this->isVerbose()) {
3709 auto f1Pos = paragraph->getGlyphPositionAtCoordinate(width/3 * 0 + 5, height/2);
3710 auto f2Pos = paragraph->getGlyphPositionAtCoordinate(width/3 * 1 + 5, height/2);
3711 auto iPos = paragraph->getGlyphPositionAtCoordinate(width/3 * 2 + 5, height/2);
3712 SkDebugf("%d(%s) %d(%s) %d(%s)\n",
3713 f1Pos.position, f1Pos.affinity == Affinity::kUpstream ? "up" : "down",
3714 f2Pos.position, f2Pos.affinity == Affinity::kUpstream ? "up" : "down",
3715 iPos.position, iPos.affinity == Affinity::kUpstream ? "up" : "down");
3716
3717 auto f1 = paragraph->getRectsForRange(0, 1, RectHeightStyle::kTight,
3718 RectWidthStyle::kTight);
3719 if (f1.empty()) {
3720 SkDebugf("F1 is empty\n");
3721 } else {
3722 auto rf1 = f1[0];
3723 SkDebugf("f1: [%f:%f] %s\n", rf1.rect.fLeft, rf1.rect.fRight,
3724 rf1.direction == TextDirection::kRtl ? "rtl" : "ltr");
3725 }
3726
3727 auto f2 = paragraph->getRectsForRange(1, 2, RectHeightStyle::kTight,
3728 RectWidthStyle::kTight);
3729 if (f2.empty()) {
3730 SkDebugf("F2 is empty\n");
3731 } else {
3732 auto rf2 = f2[0];
3733 SkDebugf("f2: [%f:%f] %s\n", rf2.rect.fLeft, rf2.rect.fRight,
3734 rf2.direction == TextDirection::kRtl ? "rtl" : "ltr");
3735 }
3736
3737 auto fi = paragraph->getRectsForRange(2, 3, RectHeightStyle::kTight,
3738 RectWidthStyle::kTight);
3739 if (fi.empty()) {
3740 SkDebugf("FI is empty\n");
3741 } else {
3742 auto rfi = fi[0];
3743 SkDebugf("i: [%f:%f] %s\n", rfi.rect.fLeft, rfi.rect.fRight,
3744 rfi.direction == TextDirection::kRtl ? "rtl" : "ltr");
3745 }
3746 }
3747 }
3748 };
3749
3750 // Multiple code points/single glyph emoji family should be treated as a single glyph
3751 class ParagraphSlide_MultiStyle_EmojiFamily : public ParagraphSlide_Base {
3752 public:
3753 ParagraphSlide_MultiStyle_EmojiFamily() { fName = SkString("ParagraphSlide_MultiStyle_EmojiFamily"); }
3754
3755 void draw (SkCanvas* canvas) override {
3756
3757 canvas->drawColor(SK_ColorWHITE);
3758
3759 auto fontCollection = sk_make_sp<FontCollection>();
3760 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3761 fontCollection->enableFontFallback();
3762
3763 ParagraphStyle paragraph_style;
3764 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3765 TextStyle text_style;
3766 text_style.setColor(SK_ColorBLACK);
3767 text_style.setFontFamilies({SkString("Noto Color Emoji")});
3768 text_style.setFontSize(40);
3769 builder.pushStyle(text_style);
3770 builder.addText(u"\U0001F468\u200D\U0001F469\u200D\U0001F467\u200D\U0001F466");
3771 auto paragraph = builder.Build();
3772 paragraph->layout(this->size().width());
3773 SkPaint paint;
3774 paint.setStyle(SkPaint::kStroke_Style);
3775 paint.setAntiAlias(true);
3776 paint.setStrokeWidth(1);
3777 paint.setColor(SK_ColorLTGRAY);
3778 canvas->drawRect(SkRect::MakeXYWH(0, 0, paragraph->getLongestLine(), paragraph->getHeight()), paint);
3779 paragraph->paint(canvas, 0, 0);
3780 auto width = paragraph->getLongestLine();
3781 auto height = paragraph->getHeight();
3782 if (this->isVerbose()) {
3783 auto pos00 = paragraph->getGlyphPositionAtCoordinate(width/4, height/4);
3784 auto pos10 = paragraph->getGlyphPositionAtCoordinate(width*3/4, height/2);
3785 auto pos01 = paragraph->getGlyphPositionAtCoordinate(width/4, height/2);
3786 auto pos11 = paragraph->getGlyphPositionAtCoordinate(width*3/4, height*3/4);
3787 SkDebugf("%d(%s) %d(%s) %d(%s) %d(%s)\n",
3788 pos00.position, pos00.affinity == Affinity::kUpstream ? "up" : "down",
3789 pos01.position, pos01.affinity == Affinity::kUpstream ? "up" : "down",
3790 pos10.position, pos10.affinity == Affinity::kUpstream ? "up" : "down",
3791 pos11.position, pos11.affinity == Affinity::kUpstream ? "up" : "down");
3792
3793 auto f1 = paragraph->getRectsForRange(0, 2, RectHeightStyle::kTight,
3794 RectWidthStyle::kTight);
3795 if (f1.empty()) {
3796 SkDebugf("F1 is empty\n");
3797 } else {
3798 auto rf1 = f1[0];
3799 SkDebugf("f1: [%f:%f] %s\n", rf1.rect.fLeft, rf1.rect.fRight,
3800 rf1.direction == TextDirection::kRtl ? "rtl" : "ltr");
3801 }
3802
3803 auto f2 = paragraph->getRectsForRange(4, 6, RectHeightStyle::kTight,
3804 RectWidthStyle::kTight);
3805 if (f2.empty()) {
3806 SkDebugf("F2 is empty\n");
3807 } else {
3808 auto rf2 = f2[0];
3809 SkDebugf("f2: [%f:%f] %s\n", rf2.rect.fLeft, rf2.rect.fRight,
3810 rf2.direction == TextDirection::kRtl ? "rtl" : "ltr");
3811 }
3812
3813 auto f3 = paragraph->getRectsForRange(8, 10, RectHeightStyle::kTight,
3814 RectWidthStyle::kTight);
3815 if (f3.empty()) {
3816 SkDebugf("F3 is empty\n");
3817 } else {
3818 auto rf3 = f3[0];
3819 SkDebugf("i: [%f:%f] %s\n", rf3.rect.fLeft, rf3.rect.fRight,
3820 rf3.direction == TextDirection::kRtl ? "rtl" : "ltr");
3821 }
3822
3823 auto f4 = paragraph->getRectsForRange(8, 10, RectHeightStyle::kTight,
3824 RectWidthStyle::kTight);
3825 if (f4.empty()) {
3826 SkDebugf("F4 is empty\n");
3827 } else {
3828 auto rf4 = f4[0];
3829 SkDebugf("i: [%f:%f] %s\n", rf4.rect.fLeft, rf4.rect.fRight,
3830 rf4.direction == TextDirection::kRtl ? "rtl" : "ltr");
3831 }
3832 }
3833 }
3834 };
3835
3836 // Arabic Ligature case should be painted into multi styles but queried as a single glyph
3837 class ParagraphSlide_MultiStyle_Arabic1 : public ParagraphSlide_Base {
3838 public:
3839 ParagraphSlide_MultiStyle_Arabic1() { fName = "SkStringParagraphSlide_MultiStyle_Arabic1"; }
3840
3841 void draw(SkCanvas* canvas) override {
3842 canvas->drawColor(SK_ColorWHITE);
3843 auto fontCollection = getFontCollection();
3844 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3845 fontCollection->enableFontFallback();
3846 TextStyle text_style;
3847 text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
3848 text_style.setFontSize(50);
3849 text_style.setColor(SK_ColorBLACK);
3850 ParagraphStyle paragraph_style;
3851 paragraph_style.setTextStyle(text_style);
3852 paragraph_style.setTextDirection(TextDirection::kRtl);
3853 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3854 text_style.setColor(SK_ColorBLUE);
3855 builder.pushStyle(text_style);
3856 builder.addText("ك");
3857 text_style.setColor(SK_ColorRED);
3858 builder.pushStyle(text_style);
3859 builder.addText("ِّ");
3860 text_style.setColor(SK_ColorBLUE);
3861 builder.pushStyle(text_style);
3862 builder.addText("ـ");
3863 auto paragraph = builder.Build();
3864 paragraph->layout(this->size().width());
3865 paragraph->paint(canvas, 0, 0);
3866
3867 auto width = paragraph->getLongestLine();
3868 auto height = paragraph->getHeight();
3869 if (this->isVerbose()) {
3870 auto f1Pos = paragraph->getGlyphPositionAtCoordinate(width/6, height/2);
3871 auto f2Pos = paragraph->getGlyphPositionAtCoordinate(width/2, height/2);
3872 auto iPos = paragraph->getGlyphPositionAtCoordinate(width*5/6, height/2);
3873 SkDebugf("%d(%s) %d(%s) %d(%s)\n",
3874 f1Pos.position, f1Pos.affinity == Affinity::kUpstream ? "up" : "down",
3875 f2Pos.position, f2Pos.affinity == Affinity::kUpstream ? "up" : "down",
3876 iPos.position, iPos.affinity == Affinity::kUpstream ? "up" : "down");
3877
3878 auto f1 = paragraph->getRectsForRange(0, 1, RectHeightStyle::kTight,
3879 RectWidthStyle::kTight);
3880 if (f1.empty()) {
3881 SkDebugf("F1 is empty\n");
3882 } else {
3883 auto rf1 = f1[0];
3884 SkDebugf("f1: [%f:%f] %s\n", rf1.rect.fLeft, rf1.rect.fRight,
3885 rf1.direction == TextDirection::kRtl ? "rtl" : "ltr");
3886 }
3887
3888 auto f2 = paragraph->getRectsForRange(1, 2, RectHeightStyle::kTight,
3889 RectWidthStyle::kTight);
3890 if (f2.empty()) {
3891 SkDebugf("F2 is empty\n");
3892 } else {
3893 auto rf2 = f2[0];
3894 SkDebugf("f2: [%f:%f] %s\n", rf2.rect.fLeft, rf2.rect.fRight,
3895 rf2.direction == TextDirection::kRtl ? "rtl" : "ltr");
3896 }
3897
3898 auto fi = paragraph->getRectsForRange(2, 3, RectHeightStyle::kTight,
3899 RectWidthStyle::kTight);
3900 if (fi.empty()) {
3901 SkDebugf("FI is empty\n");
3902 } else {
3903 auto rfi = fi[0];
3904 SkDebugf("i: [%f:%f] %s\n", rfi.rect.fLeft, rfi.rect.fRight,
3905 rfi.direction == TextDirection::kRtl ? "rtl" : "ltr");
3906 }
3907 }
3908 }
3909 };
3910
3911 // Zalgo text should be painted into multi styles but queried as a single glyph
3912 class ParagraphSlide_MultiStyle_Zalgo : public ParagraphSlide_Base {
3913 public:
3914 ParagraphSlide_MultiStyle_Zalgo() { fName = SkString("ParagraphSlide_MultiStyle_Zalgo"); }
3915
3916 void draw(SkCanvas* canvas) override {
3917
3918 canvas->drawColor(SK_ColorWHITE);
3919
3920 std::u16string text = u">S͛ͭ̋͆̈̔̇͗̍͑̎ͪͮͧͣ̽ͫͣ́ͬ̀͌͑͂͗͒̍̔̄ͧ̏̉̌̊̊̿̀̌̃̄͐̓̓̚̚҉̵̡͜͟͝͠͏̸̵̡̧͜҉̷̡͇̜̘̻̺̘̟̝͙̬̘̩͇̭̼̥̖̤̦͎k͉̩̘͚̜̹̗̗͍̤̥̱͉̳͕͖̤̲̣͚̮̞̬̲͍͔̯̻̮̞̭͈̗̫͓̂ͨ̉ͪ̒͋͛̀̍͊ͧ̿̅͆̓̔̔ͬ̇̑̿ͩ͗ͮ̎͌̿̄ͅP̴̵̡̡̛̪͙̼̣̟̩̭̫̱͙̬͔͉͍̘̠͉̦̝̘̥̟̗͖̫̤͕̙̬̦͍̱̖̮̱͑͐̎̃̒͐͋̚͘͞a̶̶̵̵̵̶̶̡̧̢̢̺͔̣͖̭̺͍̤͚̱̜̰̥͕̬̥̲̞̥̘͇͚̺̰͚̪̺͔̤͍̓̿͆̎͋̓ͦ̈́ͦ̌́̄͗̌̓͌̕͜͜͟͢͝͡ŕ͎̝͕͉̻͎̤̭͚̗̳̖̙̘͚̫͖͓͚͉͔͈̟̰̟̬̗͓̟͚̱̕͡ͅͅͅa̸̶̢̛̛̽ͮͩ̅͒ͫ͗͂̎ͦ̈́̓̚͘͜͢͡҉̷̵̶̢̡̜̮̦̜̥̜̯̙͓͔̼̗̻͜͜ͅḡ̢̛͕̗͖̖̤̦̘͔ͨͨ̊͒ͩͭͤ̍̅̃ͪ̋̏̓̍̋͗̋ͨ̏̽̈́̔̀̋̉ͫ̅̂ͭͫ̏͒͋ͥ̚͜r̶̢̧̧̥̤̼̀̂̒ͪ͌̿͌̅͛ͨͪ͒̍ͥ̉ͤ̌̿̆́ͭ͆̃̒ͤ͛̊ͧ̽͘͝͠a̧̢̧̢͑͑̓͑ͮ̃͂̄͛́̈́͋̂͌̽̄͒̔́̇ͨͧͭ͐ͦ̋ͨ̍ͦ̍̋͆̔ͧ͑͋͌̈̓͛͛̚͢͜͜͏̴̢̧̛̳͍̹͚̰̹̻͔p̨̡͆ͦͣ͊̽̔͂̉ͣ̔ͣ̌̌̉̃̋̂͒ͫ̄̎̐͗̉̌̃̽̽́̀̚͘͜͟҉̱͉h̭̮̘̗͔̜̯͔͈̯̺͔̗̣̭͚̱̰̙̼̹͚̣̻̥̲̮͍̤͜͝<";
3921 auto K = text.find(u"k");
3922 auto P = text.find(u"P");
3923 auto h = text.find(u"h");
3924 auto fontCollection = sk_make_sp<FontCollection>();
3925 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
3926 fontCollection->enableFontFallback();
3927 ParagraphStyle paragraph_style;
3928 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
3929 TextStyle text_style;
3930 text_style.setFontFamilies({SkString("Roboto")});
3931 text_style.setFontSize(20);
3932 text_style.setColor(SK_ColorRED);
3933 builder.pushStyle(text_style);
3934 builder.addText(std::u16string(text.data(), K + 3));
3935 text_style.setColor(SK_ColorBLUE);
3936 text_style.setBackgroundColor(SkPaint(SkColors::kYellow));
3937 builder.pushStyle(text_style);
3938 builder.addText(std::u16string(text.data() + K + 3, P - K - 3 + 6));
3939 text_style.setColor(SK_ColorGREEN);
3940 builder.pushStyle(text_style);
3941 builder.addText(std::u16string(text.data() + P + 6, h - P - 6));
3942 text_style.setColor(SK_ColorBLACK);
3943 text_style.setBackgroundColor(SkPaint(SkColors::kLtGray));
3944 builder.pushStyle(text_style);
3945 builder.addText(std::u16string(text.data() + h, text.size() - h));
3946 auto paragraph = builder.Build();
3947 paragraph->layout(this->size().width());
3948 paragraph->paint(canvas, 0, 0);
3949 auto height = paragraph->getHeight();
3950 if (this->isVerbose()) {
3951 auto resSK = paragraph->getRectsForRange(0, K, RectHeightStyle::kTight,
3952 RectWidthStyle::kTight);
3953 TextBox rectSK(SkRect::MakeEmpty(), TextDirection::kLtr);
3954 if (resSK.empty()) {
3955 SkDebugf("rectSk is empty\n");
3956 } else {
3957 rectSK = resSK[0];
3958 SkDebugf("rectSk: [%f:%f] %s\n", rectSK.rect.fLeft, rectSK.rect.fRight,
3959 rectSK.direction == TextDirection::kRtl ? "rtl" : "ltr");
3960 }
3961
3962 auto resKP = paragraph->getRectsForRange(K, P, RectHeightStyle::kTight,
3963 RectWidthStyle::kTight);
3964 TextBox rectKP(SkRect::MakeEmpty(), TextDirection::kLtr);
3965 if (resKP.empty()) {
3966 SkDebugf("rectkP is empty\n");
3967 } else {
3968 rectKP = resKP[0];
3969 SkDebugf("rectkP: [%f:%f] %s\n", rectKP.rect.fLeft, rectKP.rect.fRight,
3970 rectKP.direction == TextDirection::kRtl ? "rtl" : "ltr");
3971 }
3972
3973 auto resPh = paragraph->getRectsForRange(P, h, RectHeightStyle::kTight,
3974 RectWidthStyle::kTight);
3975 TextBox rectPh(SkRect::MakeEmpty(), TextDirection::kLtr);
3976 if (resPh.empty()) {
3977 SkDebugf("rectPh is empty\n");
3978 } else {
3979 rectPh = resPh[0];
3980 SkDebugf("rectPh: [%f:%f] %s\n", rectPh.rect.fLeft, rectPh.rect.fRight,
3981 rectPh.direction == TextDirection::kRtl ? "rtl" : "ltr");
3982 }
3983 auto posK = paragraph->getGlyphPositionAtCoordinate(rectSK.rect.center().fX, height/2);
3984 auto posP = paragraph->getGlyphPositionAtCoordinate(rectKP.rect.center().fX, height/2);
3985 auto posH = paragraph->getGlyphPositionAtCoordinate(rectPh.rect.center().fX, height/2);
3986
3987 SkDebugf("%d(%s) %d(%s) %d(%s)\n",
3988 posK.position, posK.affinity == Affinity::kUpstream ? "up" : "down",
3989 posP.position, posP.affinity == Affinity::kUpstream ? "up" : "down",
3990 posH.position, posH.affinity == Affinity::kUpstream ? "up" : "down");
3991 }
3992 }
3993 };
3994
3995 class ParagraphSlide_MultiStyle_Arabic2 : public ParagraphSlide_Base {
3996 public:
3997 ParagraphSlide_MultiStyle_Arabic2() { fName = SkString("ParagraphSlide_MultiStyle_Arabic2"); }
3998 void draw(SkCanvas* canvas) override {
3999 canvas->drawColor(SK_ColorWHITE);
4000 auto fontCollection = getFontCollection();
4001 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
4002 fontCollection->enableFontFallback();
4003 TextStyle text_style;
4004 text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
4005 text_style.setFontSize(50);
4006 text_style.setColor(SK_ColorBLACK);
4007 ParagraphStyle paragraph_style;
4008 paragraph_style.setTextStyle(text_style);
4009 paragraph_style.setTextDirection(TextDirection::kRtl);
4010 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4011 text_style.setColor(SK_ColorRED);
4012 builder.pushStyle(text_style);
4013 builder.addText(u"\u062c\u064e\u0627\u0653");
4014 text_style.setColor(SK_ColorBLUE);
4015 builder.pushStyle(text_style);
4016 builder.addText(u"\u064e\u0647\u064f");
4017 auto paragraph = builder.Build();
4018 paragraph->layout(this->size().width());
4019 paragraph->paint(canvas, 0, 0);
4020 }
4021 };
4022
4023 class ParagraphSlideMixedTextDirection : public ParagraphSlide_Base {
4024 public:
4025 ParagraphSlideMixedTextDirection() { fName = "ParagraphSlideMixedTextDirection"; }
4026 void draw(SkCanvas* canvas) override {
4027 canvas->drawColor(SK_ColorWHITE);
4028 auto fontCollection = getFontCollection();
4029 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
4030 fontCollection->enableFontFallback();
4031 TextStyle text_style;
4032 text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
4033 text_style.setFontSize(100);
4034 text_style.setColor(SK_ColorBLACK);
4035 ParagraphStyle paragraph_style;
4036 paragraph_style.setTextStyle(text_style);
4037 paragraph_style.setTextAlign(TextAlign::kStart);
4038 paragraph_style.setEllipsis(u"\u2026");
4039 auto draw = [&](const std::u16string& text, size_t lines, TextDirection dir) {
4040 paragraph_style.setMaxLines(lines);
4041 paragraph_style.setTextDirection(dir);
4042 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4043 builder.pushStyle(text_style);
4044 builder.addText(text);
4045 auto paragraph = builder.Build();
4046 paragraph->layout(this->size().width()); // 841 474 953
4047 paragraph->paint(canvas, 0, 0);
4048 canvas->translate(0, paragraph->getHeight() + 10);
4049 };
4050
4051 draw(u"English text (defalt LTR)", 1, TextDirection::kLtr);
4052 draw(u"English text (defalt RTL)", 1, TextDirection::kRtl);
4053 draw(u"تظاهرات و(defalt LTR) تجمعات اعتراضی در سراسر کشور ۲۳ مهر", 2, TextDirection::kLtr);
4054 draw(u"تظاهرات و(defalt RTL) تجمعات اعتراضی در سراسر کشور ۲۳ مهر", 2, TextDirection::kRtl);
4055 }
4056 };
4057
4058 class ParagraphSlideGetPath : public ParagraphSlide_Base {
4059 public:
4060 ParagraphSlideGetPath() { fName = "ParagraphSlideGetPath"; }
4061 void draw(SkCanvas* canvas) override {
4062 canvas->drawColor(SK_ColorWHITE);
4063 auto fontCollection = getFontCollection();
4064 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
4065 fontCollection->enableFontFallback();
4066 TextStyle text_style;
4067 text_style.setFontFamilies({SkString("Roboto")});
4068 text_style.setFontSize(50);
4069 text_style.setColor(SK_ColorBLACK);
4070 ParagraphStyle paragraph_style;
4071 paragraph_style.setTextStyle(text_style);
4072 paragraph_style.setTextAlign(TextAlign::kStart);
4073
4074 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4075 builder.pushStyle(text_style);
4076 builder.addText("Multi lined sticky notes drawn as paths");
4077 auto paragraph = builder.Build();
4078 paragraph->layout(this->size().width());
4079
4080 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
4081 SkPathBuilder fullPath;
4082 SkScalar height = 0;
4083 for (auto& line : impl->lines()) {
4084 line.ensureTextBlobCachePopulated();
4085 for (auto& rec : line.fTextBlobCache) {
4086 auto paths = Paragraph::GetPath(rec.fBlob.get());
4087 fullPath.addPath(paths, 0, height);
4088 height += line.height();
4089 }
4090 }
4091 SkRect rect = SkRect::MakeXYWH(100, 100 + paragraph->getHeight(), this->size().width(), paragraph->getHeight());
4092 SkPaint paint;
4093 paint.setShader(setgrad(rect, SK_ColorBLUE, SK_ColorLTGRAY));
4094 canvas->drawPath(fullPath.detach(), paint);
4095 }
4096 };
4097
4098 class ParagraphSlideExperiment : public ParagraphSlide_Base {
4099 public:
4100 ParagraphSlideExperiment() { fName = "ParagraphSlideExperiment"; }
4101 void draw(SkCanvas* canvas) override {
4102 canvas->drawColor(SK_ColorWHITE);
4103 auto fontCollection = getFontCollection();
4104 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
4105 fontCollection->disableFontFallback();
4106 TextStyle text_style;
4107 text_style.setFontFamilies({SkString("Roboto")});
4108 text_style.setFontSize(50);
4109 text_style.setColor(SK_ColorBLACK);
4110 ParagraphStyle paragraph_style;
4111 paragraph_style.setTextStyle(text_style);
4112 paragraph_style.setTextAlign(TextAlign::kStart);
4113
4114 {
4115 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4116 builder.pushStyle(text_style);
4117 builder.addText("Sticky notes\non multple lines\nwith bounds around glyphs");
4118 auto paragraph = builder.Build();
4119 paragraph->layout(this->size().width());
4120 paragraph->paint(canvas, 0, 0);
4121 paragraph->extendedVisit([&](int, const skia::textlayout::Paragraph::ExtendedVisitorInfo* info) {
4122 if (!info) {
4123 return;
4124 }
4125 SkPaint paint;
4126 paint.setStyle(SkPaint::kStroke_Style);
4127 paint.setAntiAlias(true);
4128 paint.setStrokeWidth(1);
4129 for (auto i = 0; i < info->count; ++i) {
4130 paint.setColor(SK_ColorDKGRAY);
4131 SkRect rect(info->bounds[i]);
4132 rect.offset(info->positions[i]);
4133 rect.offset(info->origin);
4134 canvas->drawRect(rect, paint);
4135 }
4136 });
4137 canvas->translate(0, paragraph->getHeight() + 20);
4138 }
4139
4140 {
4141 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4142 builder.pushStyle(text_style);
4143 builder.addText("Sticky notes with glyphs changing position");
4144 auto paragraph = builder.Build();
4145 paragraph->layout(this->size().width());
4146 paragraph->paint(canvas, 0, 0);
4147 paragraph->extendedVisit([&](int, const skia::textlayout::Paragraph::ExtendedVisitorInfo* info) {
4148 if (!info) {
4149 return;
4150 }
4151 SkScalar offset = 0;
4152 for (auto i = 0; i < info->count; ++i) {
4153 info->positions[i].fY += offset;
4154 if (i % 3 == 0) {
4155 offset = 20;
4156 } else if (i % 3 == 1) {
4157 offset = -20;
4158 } else {
4159 offset = 0;
4160 }
4161 }
4162 });
4163 paragraph->paint(canvas, 0, 0);
4164 canvas->translate(0, paragraph->getHeight() + 40);
4165 }
4166
4167 {
4168 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4169 builder.pushStyle(text_style);
4170 builder.addText("Multi 😀 lined sticky notes drawn as paths");
4171 auto paragraph = builder.Build();
4172 paragraph->layout(300);
4173 SkPaint paint;
4174 std::vector<LineMetrics> metrics;
4175 paragraph->getLineMetrics(metrics);
4176 SkScalar height = 0;
4177 for (size_t lineNum = 0; lineNum < paragraph->lineNumber(); ++lineNum) {
4178 SkPath paths;
4179 paragraph->getPath(lineNum, &paths);
4180 auto& line = metrics[lineNum];
4181 SkRect rect = SkRect::MakeXYWH(line.fLeft, height, line.fWidth, line.fHeight);
4182 height += line.fHeight;
4183 paint.setShader(setgrad(rect, SK_ColorBLUE, SK_ColorLTGRAY));
4184 canvas->drawPath(paths, paint);
4185 }
4186 }
4187 }
4188 };
4189
4190 class ParagraphSlideGlyphs : public ParagraphSlide_Base {
4191 public:
4192 ParagraphSlideGlyphs() { fName = "ParagraphSlideGlyphs"; }
4193 void draw(SkCanvas* canvas) override {
4194
4195 canvas->drawColor(SK_ColorWHITE);
4196 const char* text1 = "World domination is such an ugly phrase - I prefer to call it world optimisation";
4197 const char* text2 =
4198 "左線読設重説切abc後碁給能上目秘使約。満毎冠行 来昼本可 def 必図将発確年。今属場育"
4199 "図情闘陰野高備込制詩西校客。審対江置講今固残必託地集済決維駆年策。立得庭"
4200 "際輝求佐抗蒼提夜合逃表。注統天言件自謙雅載報紙喪。作画稿愛器灯女書利変探"
4201 "訃第金線朝開化建。子戦年帝励害表月幕株漠新期刊人秘。図的海力生禁挙保天戦"
4202 "聞条年所在口。";
4203 const char* text3 = "من أسر وإعلان الخاصّة وهولندا،, عل def قائمة الضغوط بالمabcطالبة تلك. الصفحة "
4204 "بمباركة التقليدية قام عن. تصفح";
4205 auto fontCollection = sk_make_sp<FontCollection>();
4206 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
4207 fontCollection->enableFontFallback();
4208
4209 ParagraphStyle paragraph_style;
4210 paragraph_style.setTextAlign(TextAlign::kJustify);
4211
4212 auto draw = [&](const char* text, TextDirection textDirection) {
4213 paragraph_style.setTextDirection(textDirection);
4214 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4215 TextStyle text_style;
4216 text_style.setFontFamilies({SkString("Katibeh"), SkString("Roboto"), SkString("Source Han Serif CN")});
4217 text_style.setFontSize(40);
4218 text_style.setColor(SK_ColorBLACK);
4219 builder.pushStyle(text_style);
4220 builder.addText(text);
4221
4222 auto paragraph = builder.Build();
4223 paragraph->layout(this->size().width()); // 497
4224 paragraph->paint(canvas, 0, 0);
4225 canvas->translate(0, paragraph->getHeight() + 20);
4226 };
4227
4228 draw(text1, TextDirection::kLtr);
4229 draw(text2, TextDirection::kLtr);
4230 draw(text3, TextDirection::kLtr);
4231 }
4232 };
4233
4234
4235 class ParagraphSlideEllipsisInRTL : public ParagraphSlide_Base {
4236 public:
4237 ParagraphSlideEllipsisInRTL() { fName = "ParagraphSlideEllipsisInRTL"; }
4238 void draw(SkCanvas* canvas) override {
4239 canvas->drawColor(SK_ColorWHITE);
4240 auto fontCollection = getFontCollection();
4241 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
4242 fontCollection->enableFontFallback();
4243 TextStyle text_style;
4244 text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
4245 text_style.setFontSize(100);
4246 text_style.setColor(SK_ColorBLACK);
4247 ParagraphStyle paragraph_style;
4248 paragraph_style.setTextStyle(text_style);
4249 paragraph_style.setTextAlign(TextAlign::kStart);
4250 paragraph_style.setEllipsis(u"\u2026");
4251 auto draw = [&](const std::u16string& text) {
4252 paragraph_style.setMaxLines(1);
4253 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4254 builder.pushStyle(text_style);
4255 builder.addText(text);
4256 auto paragraph = builder.Build();
4257 paragraph->layout(this->size().width());
4258 paragraph->paint(canvas, 0, 0);
4259 canvas->translate(0, paragraph->getHeight() + 10);
4260 };
4261
4262 draw(u"你abcdefsdasdsasas");
4263 draw(u"한111111111111111111");
4264 draw(u"abcdefsdasds1112222");
4265 }
4266 };
4267
4268 class ParagraphSlideEmojiSequence : public ParagraphSlide_Base {
4269 public:
4270 ParagraphSlideEmojiSequence() { fName = "ParagraphSlideEmojiSequence"; }
4271 void draw(SkCanvas* canvas) override {
4272 canvas->drawColor(SK_ColorWHITE);
4273 auto fontCollection = sk_make_sp<FontCollection>();
4274 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr(), std::vector<SkString>());
4275 fontCollection->enableFontFallback();
4276 TextStyle text_style;
4277 text_style.setFontFamilies({SkString("")});
4278 text_style.setFontSize(20);
4279 text_style.setColor(SK_ColorBLACK);
4280 ParagraphStyle paragraph_style;
4281 paragraph_style.setTextStyle(text_style);
4282
4283 auto test = [&](const char* text) {
4284 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4285 builder.pushStyle(text_style);
4286 builder.addText(text);
4287 auto paragraph = builder.Build();
4288 paragraph->layout(this->size().width());
4289 paragraph->paint(canvas, 0, 0);
4290 if ((false)) {
4291 SkDebugf("Paragraph '%s'\n", text);
4292 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
4293 for (auto& run: impl->runs()) {
4294 SkString ff;
4295 run.font().getTypeface()->getFamilyName(&ff);
4296 SkDebugf("'%s': [%zu:%zu)\n", ff.c_str(), run.textRange().start, run.textRange().end);
4297 }
4298 }
4299 };
4300 test("2nd");
4301 canvas->translate(0, 50);
4302 test("99");
4303 canvas->translate(0, 50);
4304 test("999");
4305 canvas->translate(0, 50);
4306 /*
4307 test("🆗");
4308 canvas->translate(0, 50);
4309 test("0️⃣");
4310 canvas->translate(0, 50);
4311 test("0️⃣🆗");
4312 canvas->translate(0, 50);
4313 test("0");
4314 canvas->translate(0, 50);
4315 test("0️");
4316 canvas->translate(0, 50);
4317 test("♻️");
4318 canvas->translate(0, 50);
4319 test("󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿♻️");
4320 */
4321 }
4322 };
4323
4324 class ParagraphSlideWordSpacing : public ParagraphSlide_Base {
4325 public:
4326 ParagraphSlideWordSpacing() { fName = "ParagraphWordSpacing"; }
4327
4328 void draw(SkCanvas* canvas) override {
4329 canvas->drawColor(SK_ColorWHITE);
4330
4331 auto fontCollection = sk_make_sp<FontCollection>();
4332 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr());
4333 fontCollection->enableFontFallback();
4334
4335 ParagraphStyle paragraph_style;
4336 TextStyle text_style;
4337 text_style.setColor(SK_ColorBLACK);
4338 text_style.setFontFamilies({});
4339 text_style.setFontSize(20.0);
4340
4341 auto draw = [&](TextDirection direction, SkScalar spacing, const char* text) {
4342 paragraph_style.setTextDirection(direction);
4343 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4344 text_style.setWordSpacing(spacing);
4345 builder.pushStyle(text_style);
4346 builder.addText(text);
4347 builder.pop();
4348 auto paragraph = builder.Build();
4349 paragraph->layout(this->size().width());
4350 paragraph->paint(canvas, 0, 0);
4351 canvas->translate(0, paragraph->getHeight() + 20);
4352 };
4353
4354 draw(TextDirection::kLtr, 20, "Lorem ipsum dolor sit amet");
4355 draw(TextDirection::kRtl, 20, "Lorem ipsum dolor sit amet");
4356
4357 draw(TextDirection::kLtr, 20, "טקסט ללא רווח בין מילים");
4358 draw(TextDirection::kRtl, 20, "טקסט ללא רווח בין מילים");
4359
4360 draw(TextDirection::kLtr, 20, "نص مع عدم وجود مسافات بين الكلمات");
4361 draw(TextDirection::kRtl, 20, "نص مع عدم وجود مسافات بين الكلمات");
4362 }
4363 };
4364
4365 class ParagraphHangingWhitespaces : public ParagraphSlide_Base {
4366 public:
4367 ParagraphHangingWhitespaces() { fName = "ParagraphHangingWhitespaces"; }
4368 void draw(SkCanvas* canvas) override {
4369
4370 SkPaint cursor;
4371 cursor.setColor(SK_ColorRED);
4372 cursor.setStyle(SkPaint::kStroke_Style);
4373 cursor.setAntiAlias(true);
4374 cursor.setStrokeWidth(2);
4375
4376 canvas->drawColor(SK_ColorWHITE);
4377 auto fontCollection = sk_make_sp<FontCollection>();
4378 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr(), std::vector<SkString>());
4379 fontCollection->enableFontFallback();
4380 TextStyle text_style;
4381 text_style.setFontFamilies({SkString("Roboto")});
4382 text_style.setFontSize(20);
4383 text_style.setColor(SK_ColorBLACK);
4384 text_style.setBackgroundColor(SkPaint(SkColors::kLtGray));
4385 ParagraphStyle paragraph_style;
4386 paragraph_style.setTextStyle(text_style);
4387
4388 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4389 builder.pushStyle(text_style);
4390 builder.addText("Text with 3 'hanging' whitespaces at the end. ");
4391 auto paragraph = builder.Build();
4392 paragraph->layout(this->size().width());
4393 paragraph->paint(canvas, 0, 0);
4394 canvas->drawLine(paragraph->getLongestLine(), 0, paragraph->getLongestLine(), paragraph->getHeight(), cursor);
4395
4396 canvas->translate(0, paragraph->getHeight() + 50);
4397
4398 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
4399 auto extraWidth = impl->widthWithTrailingSpaces() - paragraph->getLongestLine();
4400 paragraph->paint(canvas, 0, 0);
4401 canvas->drawLine(paragraph->getLongestLine() + extraWidth, 0, paragraph->getLongestLine() + extraWidth, paragraph->getHeight(), cursor);
4402 }
4403 };
4404
4405 class ParagraphSlideLast : public ParagraphSlide_Base {
4406 public:
4407 ParagraphSlideLast() { fName = "ParagraphSlideLast"; }
4408 void draw(SkCanvas* canvas) override {
4409 canvas->drawColor(SK_ColorWHITE);
4410 auto fontCollection = sk_make_sp<FontCollection>();
4411 fontCollection->setDefaultFontManager(ToolUtils::TestFontMgr(), std::vector<SkString>());
4412 fontCollection->enableFontFallback();
4413 TextStyle text_style;
4414 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
4415 text_style.setFontSize(20);
4416 text_style.setColor(SK_ColorBLACK);
4417 ParagraphStyle paragraph_style;
4418 paragraph_style.setTextStyle(text_style);
4419
4420 auto test = [&](const char* text) {
4421 ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
4422 builder.pushStyle(text_style);
4423 builder.addText(text);
4424 auto paragraph = builder.Build();
4425 paragraph->layout(this->size().width());
4426 paragraph->paint(canvas, 0, 0);
4427 if ((false)) {
4428 SkDebugf("Paragraph '%s'\n", text);
4429 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
4430 for (auto& run: impl->runs()) {
4431 SkString ff;
4432 run.font().getTypeface()->getFamilyName(&ff);
4433 SkDebugf("'%s': [%zu:%zu)\n", ff.c_str(), run.textRange().start, run.textRange().end);
4434 }
4435 }
4436 };
4437
4438 test("​🇳​🇩🇮🇩⃢");
4439 }
4440 };
4441
4442 } // namespace
4443
4444 //////////////////////////////////////////////////////////////////////////////
4445 DEF_SLIDE(return new ParagraphSlide1();)
4446 DEF_SLIDE(return new ParagraphSlide2();)
4447 DEF_SLIDE(return new ParagraphSlide3();)
4448 DEF_SLIDE(return new ParagraphSlide5();)
4449 DEF_SLIDE(return new ParagraphSlide6();)
4450 DEF_SLIDE(return new ParagraphSlide7();)
4451 DEF_SLIDE(return new ParagraphSlide8();)
4452 DEF_SLIDE(return new ParagraphSlide9();)
4453 DEF_SLIDE(return new ParagraphSlide10();)
4454 DEF_SLIDE(return new ParagraphSlide11();)
4455 DEF_SLIDE(return new ParagraphSlide12();)
4456 DEF_SLIDE(return new ParagraphSlide14();)
4457 DEF_SLIDE(return new ParagraphSlide15();)
4458 DEF_SLIDE(return new ParagraphSlide16();)
4459 DEF_SLIDE(return new ParagraphSlide17();)
4460 DEF_SLIDE(return new ParagraphSlide18();)
4461 DEF_SLIDE(return new ParagraphSlide19();)
4462 DEF_SLIDE(return new ParagraphSlide20();)
4463 DEF_SLIDE(return new ParagraphSlide21();)
4464 DEF_SLIDE(return new ParagraphSlide22();)
4465 DEF_SLIDE(return new ParagraphSlide23();)
4466 DEF_SLIDE(return new ParagraphSlide24();)
4467 DEF_SLIDE(return new ParagraphSlide25();)
4468 DEF_SLIDE(return new ParagraphSlide26();)
4469 DEF_SLIDE(return new ParagraphSlide27();)
4470 DEF_SLIDE(return new ParagraphSlide28();)
4471 DEF_SLIDE(return new ParagraphSlide29();)
4472 DEF_SLIDE(return new ParagraphSlide30();)
4473 DEF_SLIDE(return new ParagraphSlide31();)
4474 DEF_SLIDE(return new ParagraphSlide32();)
4475 DEF_SLIDE(return new ParagraphSlide33();)
4476 DEF_SLIDE(return new ParagraphSlide34();)
4477 DEF_SLIDE(return new ParagraphSlide35();)
4478 DEF_SLIDE(return new ParagraphSlide36();)
4479 DEF_SLIDE(return new ParagraphSlide37();)
4480 DEF_SLIDE(return new ParagraphSlide38();)
4481 DEF_SLIDE(return new ParagraphSlide39();)
4482 DEF_SLIDE(return new ParagraphSlide41();)
4483 DEF_SLIDE(return new ParagraphSlide42();)
4484 DEF_SLIDE(return new ParagraphSlide43();)
4485 DEF_SLIDE(return new ParagraphSlide44();)
4486 DEF_SLIDE(return new ParagraphSlide45();)
4487 DEF_SLIDE(return new ParagraphSlide46();)
4488 DEF_SLIDE(return new ParagraphSlide47();)
4489 DEF_SLIDE(return new ParagraphSlide48();)
4490 DEF_SLIDE(return new ParagraphSlide49();)
4491 DEF_SLIDE(return new ParagraphSlide50();)
4492 DEF_SLIDE(return new ParagraphSlide51();)
4493 DEF_SLIDE(return new ParagraphSlide52();)
4494 DEF_SLIDE(return new ParagraphSlide53();)
4495 DEF_SLIDE(return new ParagraphSlide54();)
4496 DEF_SLIDE(return new ParagraphSlide55();)
4497 DEF_SLIDE(return new ParagraphSlide56();)
4498 DEF_SLIDE(return new ParagraphSlide57();)
4499 DEF_SLIDE(return new ParagraphSlide58();)
4500 DEF_SLIDE(return new ParagraphSlide59();)
4501 DEF_SLIDE(return new ParagraphSlide60();)
4502 DEF_SLIDE(return new ParagraphSlide61();)
4503 DEF_SLIDE(return new ParagraphSlide62();)
4504 DEF_SLIDE(return new ParagraphSlide63();)
4505 DEF_SLIDE(return new ParagraphSlide64();)
4506 DEF_SLIDE(return new ParagraphSlide66();)
4507 DEF_SLIDE(return new ParagraphSlide67();)
4508 DEF_SLIDE(return new ParagraphSlide68();)
4509 DEF_SLIDE(return new ParagraphSlide_MultiStyle_Logo();)
4510 DEF_SLIDE(return new ParagraphSlide_MultiStyle_FFI();)
4511 DEF_SLIDE(return new ParagraphSlide_MultiStyle_EmojiFamily();)
4512 DEF_SLIDE(return new ParagraphSlide_MultiStyle_Arabic1();)
4513 DEF_SLIDE(return new ParagraphSlide_MultiStyle_Zalgo();)
4514 DEF_SLIDE(return new ParagraphSlide_MultiStyle_Arabic2();)
4515 DEF_SLIDE(return new ParagraphSlideMixedTextDirection();)
4516 DEF_SLIDE(return new ParagraphSlideGetPath();)
4517 DEF_SLIDE(return new ParagraphSlideExperiment();)
4518 DEF_SLIDE(return new ParagraphSlideGlyphs();)
4519 DEF_SLIDE(return new ParagraphSlideEllipsisInRTL();)
4520 DEF_SLIDE(return new ParagraphSlideEmojiSequence();)
4521 DEF_SLIDE(return new ParagraphSlideWordSpacing();)
4522 DEF_SLIDE(return new ParagraphHangingWhitespaces();)
4523 DEF_SLIDE(return new ParagraphSlideLast();)