blob: c4fd8c8683358574d844851a813d1af680383fd9 [file] [log] [blame]
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001// Copyright 2019 Google LLC.
Julia Lavrovaa3552c52019-05-30 16:12:56 -04002#include "include/core/SkCanvas.h"
3#include "include/core/SkColorFilter.h"
4#include "include/core/SkColorPriv.h"
Julia Lavrovacd2d4e42020-03-27 15:40:37 -04005#include "include/core/SkFontMgr.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -04006#include "include/core/SkGraphics.h"
7#include "include/core/SkPath.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/SkTime.h"
13#include "include/core/SkTypeface.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040014#include "include/effects/SkGradientShader.h"
15#include "include/utils/SkRandom.h"
16#include "modules/skparagraph/include/Paragraph.h"
Julia Lavrova6e6333f2019-06-17 10:34:10 -040017#include "modules/skparagraph/include/TypefaceFontProvider.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040018#include "modules/skparagraph/src/ParagraphBuilderImpl.h"
19#include "modules/skparagraph/src/ParagraphImpl.h"
Julia Lavrova9af5cc42019-06-19 13:32:01 -040020#include "modules/skparagraph/utils/TestFontCollection.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040021#include "samplecode/Sample.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040022#include "src/core/SkOSFile.h"
23#include "src/shaders/SkColorShader.h"
Julia Lavrova2e30fde2019-10-09 09:43:02 -040024#include "src/utils/SkOSPath.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040025#include "src/utils/SkUTF.h"
26#include "tools/Resources.h"
Ben Wagner056d5432020-05-13 10:24:15 -040027#include "tools/flags/CommandLineFlags.h"
28
29
30static DEFINE_bool(verboseParagraph, false, "paragraph samples very verbose.");
Julia Lavrovaa3552c52019-05-30 16:12:56 -040031
32using namespace skia::textlayout;
33namespace {
34
Mike Reed21a940d2019-07-23 10:11:03 -040035class ParagraphView_Base : public Sample {
36protected:
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -040037 sk_sp<TestFontCollection> getFontCollection() {
38 // If we reset font collection we need to reset paragraph cache
39 static sk_sp<TestFontCollection> fFC = nullptr;
40 if (fFC == nullptr) {
Julia Lavrova2e30fde2019-10-09 09:43:02 -040041 fFC = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -040042 }
43 return fFC;
Mike Reed21a940d2019-07-23 10:11:03 -040044 }
Ben Wagner056d5432020-05-13 10:24:15 -040045
46 bool isVerbose() {
47 return FLAGS_verboseParagraph;
48 }
Mike Reed21a940d2019-07-23 10:11:03 -040049};
50
Julia Lavrovaa3552c52019-05-30 16:12:56 -040051sk_sp<SkShader> setgrad(const SkRect& r, SkColor c0, SkColor c1) {
52 SkColor colors[] = {c0, c1};
53 SkPoint pts[] = {{r.fLeft, r.fTop}, {r.fRight, r.fTop}};
54 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
55}
Julia Lavrova2e30fde2019-10-09 09:43:02 -040056/*
57void writeHtml(const char* name, Paragraph* paragraph) {
58 SkString tmpDir = skiatest::GetTmpDir();
59 if (!tmpDir.isEmpty()) {
60 SkString path = SkOSPath::Join(tmpDir.c_str(), name);
61 SkFILEWStream file(path.c_str());
62 file.write(nullptr, 0);
63 }
64}
65*/
Julia Lavrovaa3552c52019-05-30 16:12:56 -040066
Mike Reed21a940d2019-07-23 10:11:03 -040067class ParagraphView1 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -040068protected:
Hal Canary8a027312019-07-03 10:55:44 -040069 SkString name() override { return SkString("Paragraph1"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040070
71 void drawTest(SkCanvas* canvas, SkScalar w, SkScalar h, SkColor fg, SkColor bg) {
72 const std::vector<
73 std::tuple<std::string, bool, bool, int, SkColor, SkColor, bool, TextDecorationStyle>>
74 gParagraph = {{"monospace", true, false, 14, SK_ColorWHITE, SK_ColorRED, true,
75 TextDecorationStyle::kDashed},
76 {"Assyrian", false, false, 20, SK_ColorWHITE, SK_ColorBLUE, false,
77 TextDecorationStyle::kDotted},
78 {"serif", true, true, 10, SK_ColorWHITE, SK_ColorRED, true,
79 TextDecorationStyle::kDouble},
80 {"Arial", false, true, 16, SK_ColorGRAY, SK_ColorGREEN, true,
81 TextDecorationStyle::kSolid},
82 {"sans-serif", false, false, 8, SK_ColorWHITE, SK_ColorRED, false,
83 TextDecorationStyle::kWavy}};
84 SkAutoCanvasRestore acr(canvas, true);
85
86 canvas->clipRect(SkRect::MakeWH(w, h));
87 canvas->drawColor(SK_ColorWHITE);
88
89 SkScalar margin = 20;
90
91 SkPaint paint;
92 paint.setAntiAlias(true);
93 paint.setColor(fg);
94
95 SkPaint blue;
96 blue.setColor(SK_ColorBLUE);
97
98 TextStyle defaultStyle;
99 defaultStyle.setBackgroundColor(blue);
100 defaultStyle.setForegroundColor(paint);
101 ParagraphStyle paraStyle;
102
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400103 auto fontCollection = sk_make_sp<FontCollection>();
104 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400105 for (auto i = 1; i < 5; ++i) {
106 defaultStyle.setFontSize(24 * i);
107 paraStyle.setTextStyle(defaultStyle);
Julia Lavrova5207f352019-06-21 12:22:32 -0400108 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400109 std::string name = "Paragraph: " + std::to_string(24 * i);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400110 builder.addText(name.c_str(), name.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400111 for (auto para : gParagraph) {
112 TextStyle style;
113 style.setFontFamilies({SkString(std::get<0>(para).c_str())});
114 SkFontStyle fontStyle(std::get<1>(para) ? SkFontStyle::Weight::kBold_Weight
115 : SkFontStyle::Weight::kNormal_Weight,
116 SkFontStyle::Width::kNormal_Width,
117 std::get<2>(para) ? SkFontStyle::Slant::kItalic_Slant
118 : SkFontStyle::Slant::kUpright_Slant);
119 style.setFontStyle(fontStyle);
120 style.setFontSize(std::get<3>(para) * i);
121 SkPaint background;
122 background.setColor(std::get<4>(para));
123 style.setBackgroundColor(background);
124 SkPaint foreground;
125 foreground.setColor(std::get<5>(para));
126 foreground.setAntiAlias(true);
127 style.setForegroundColor(foreground);
128 if (std::get<6>(para)) {
129 style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(5, 5), 2));
130 }
131
132 auto decoration = (i % 4);
133 if (decoration == 3) {
134 decoration = 4;
135 }
136
137 bool test = (TextDecoration)decoration != TextDecoration::kNoDecoration;
138 std::string deco = std::to_string((int)decoration);
139 if (test) {
140 style.setDecoration((TextDecoration)decoration);
141 style.setDecorationStyle(std::get<7>(para));
142 style.setDecorationColor(std::get<5>(para));
143 }
144 builder.pushStyle(style);
145 std::string name = " " + std::get<0>(para) + " " +
146 (std::get<1>(para) ? ", bold" : "") +
147 (std::get<2>(para) ? ", italic" : "") + " " +
148 std::to_string(std::get<3>(para) * i) +
149 (std::get<4>(para) != bg ? ", background" : "") +
150 (std::get<5>(para) != fg ? ", foreground" : "") +
151 (std::get<6>(para) ? ", shadow" : "") +
152 (test ? ", decorations " + deco : "") + ";";
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400153 builder.addText(name.c_str(), name.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400154 builder.pop();
155 }
156
157 auto paragraph = builder.Build();
158 paragraph->layout(w - margin * 2);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400159 paragraph->paint(canvas, margin, margin);
160
161 canvas->translate(0, paragraph->getHeight());
162 }
163 }
164
165 void onDrawContent(SkCanvas* canvas) override {
166 drawTest(canvas, this->width(), this->height(), SK_ColorRED, SK_ColorWHITE);
167 }
168
169private:
170
171 typedef Sample INHERITED;
172};
173
Mike Reed21a940d2019-07-23 10:11:03 -0400174class ParagraphView2 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400175protected:
Hal Canary8a027312019-07-03 10:55:44 -0400176 SkString name() override { return SkString("Paragraph2"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400177
178 void drawCode(SkCanvas* canvas, SkScalar w, SkScalar h) {
179 SkPaint comment;
180 comment.setColor(SK_ColorGRAY);
181 SkPaint constant;
182 constant.setColor(SK_ColorMAGENTA);
183 SkPaint null;
184 null.setColor(SK_ColorMAGENTA);
185 SkPaint literal;
186 literal.setColor(SK_ColorGREEN);
187 SkPaint code;
188 code.setColor(SK_ColorDKGRAY);
189 SkPaint number;
190 number.setColor(SK_ColorBLUE);
191 SkPaint name;
192 name.setColor(SK_ColorRED);
193
194 SkPaint white;
195 white.setColor(SK_ColorWHITE);
196
197 TextStyle defaultStyle;
198 defaultStyle.setBackgroundColor(white);
199 defaultStyle.setForegroundColor(code);
200 defaultStyle.setFontFamilies({SkString("monospace")});
201 defaultStyle.setFontSize(30);
202 ParagraphStyle paraStyle;
203 paraStyle.setTextStyle(defaultStyle);
204
Julia Lavrova5207f352019-06-21 12:22:32 -0400205 auto fontCollection = sk_make_sp<FontCollection>();
206 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
207 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400208
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400209 const char* text1 = "RaisedButton";
210 const char* text2 = "(\n";
211 const char* text3 = " child: ";
212 const char* text4 = "const";
213 const char* text5 = "Text";
214 const char* text6 = "'BUTTON TITLE'";
215 const char* text7 = "),\n";
216
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400217 builder.pushStyle(style(name));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400218 builder.addText(text1, strlen(text1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400219 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400220 builder.addText(text2, strlen(text2));
221 builder.addText(text3, strlen(text3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400222 builder.pushStyle(style(constant));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400223 builder.addText(text4, strlen(text4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400224 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400225 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400226 builder.pushStyle(style(name));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400227 builder.addText(text5, strlen(text5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400228 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400229 builder.addText("(", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400230 builder.pushStyle(style(literal));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400231 builder.addText(text6, strlen(text6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400232 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400233 builder.addText(text7, strlen(text7));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400234
235 auto paragraph = builder.Build();
236 paragraph->layout(w - 20);
237
238 paragraph->paint(canvas, 20, 20);
239 }
240
241 TextStyle style(SkPaint paint) {
242 TextStyle style;
243 paint.setAntiAlias(true);
244 style.setForegroundColor(paint);
245 style.setFontFamilies({SkString("monospace")});
246 style.setFontSize(30);
247
248 return style;
249 }
250
Julia Lavrova5207f352019-06-21 12:22:32 -0400251 void drawText(SkCanvas* canvas, SkScalar w, SkScalar h, std::vector<const char*>& text,
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400252 SkColor fg = SK_ColorDKGRAY, SkColor bg = SK_ColorWHITE,
253 const char* ff = "sans-serif", SkScalar fs = 24,
254 size_t lineLimit = 30,
255 const std::u16string& ellipsis = u"\u2026") {
256 SkAutoCanvasRestore acr(canvas, true);
257
258 canvas->clipRect(SkRect::MakeWH(w, h));
259 canvas->drawColor(bg);
260
261 SkScalar margin = 20;
262
263 SkPaint paint;
264 paint.setAntiAlias(true);
265 paint.setColor(fg);
266
267 SkPaint blue;
268 blue.setColor(SK_ColorBLUE);
269
270 SkPaint background;
271 background.setColor(bg);
272
273 TextStyle style;
274 style.setBackgroundColor(blue);
275 style.setForegroundColor(paint);
276 style.setFontFamilies({SkString(ff)});
277 style.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight,
278 SkFontStyle::kNormal_Width,
279 SkFontStyle::kUpright_Slant));
280 style.setFontSize(fs);
281 ParagraphStyle paraStyle;
282 paraStyle.setTextStyle(style);
283 paraStyle.setMaxLines(lineLimit);
284
285 paraStyle.setEllipsis(ellipsis);
286 TextStyle defaultStyle;
287 defaultStyle.setFontSize(20);
288 paraStyle.setTextStyle(defaultStyle);
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400289 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400290
291 SkPaint foreground;
292 foreground.setColor(fg);
293 style.setForegroundColor(foreground);
294 style.setBackgroundColor(background);
295
296 for (auto& part : text) {
297 builder.pushStyle(style);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400298 builder.addText(part, strlen(part));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400299 builder.pop();
300 }
301
302 auto paragraph = builder.Build();
303 paragraph->layout(w - margin * 2);
304 paragraph->paint(canvas, margin, margin);
305
306 canvas->translate(0, paragraph->getHeight() + margin);
307 }
308
309 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
310 TextAlign align) {
311 SkAutoCanvasRestore acr(canvas, true);
312
313 canvas->clipRect(SkRect::MakeWH(w, h));
314 canvas->drawColor(SK_ColorWHITE);
315
316 SkScalar margin = 20;
317
318 SkPaint paint;
319 paint.setAntiAlias(true);
320 paint.setColor(SK_ColorBLUE);
321
322 SkPaint gray;
323 gray.setColor(SK_ColorLTGRAY);
324
325 TextStyle style;
326 style.setBackgroundColor(gray);
327 style.setForegroundColor(paint);
328 style.setFontFamilies({SkString("Arial")});
329 style.setFontSize(30);
330 ParagraphStyle paraStyle;
331 paraStyle.setTextStyle(style);
332 paraStyle.setTextAlign(align);
333
Julia Lavrova5207f352019-06-21 12:22:32 -0400334 auto fontCollection = sk_make_sp<FontCollection>();
335 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
336 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400337 builder.addText(text.c_str(), text.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400338
339 auto paragraph = builder.Build();
340 paragraph->layout(w - margin * 2);
341 paragraph->layout(w - margin);
342 paragraph->paint(canvas, margin, margin);
343
344 canvas->translate(0, paragraph->getHeight() + margin);
345 }
346
347 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrova5207f352019-06-21 12:22:32 -0400348 std::vector<const char*> cupertino = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400349 "google_logogoogle_gsuper_g_logo 1 "
350 "google_logogoogle_gsuper_g_logo 12 "
351 "google_logogoogle_gsuper_g_logo 123 "
352 "google_logogoogle_gsuper_g_logo 1234 "
353 "google_logogoogle_gsuper_g_logo 12345 "
354 "google_logogoogle_gsuper_g_logo 123456 "
355 "google_logogoogle_gsuper_g_logo 1234567 "
356 "google_logogoogle_gsuper_g_logo 12345678 "
357 "google_logogoogle_gsuper_g_logo 123456789 "
358 "google_logogoogle_gsuper_g_logo 1234567890 "
359 "google_logogoogle_gsuper_g_logo 123456789 "
360 "google_logogoogle_gsuper_g_logo 12345678 "
361 "google_logogoogle_gsuper_g_logo 1234567 "
362 "google_logogoogle_gsuper_g_logo 123456 "
363 "google_logogoogle_gsuper_g_logo 12345 "
364 "google_logogoogle_gsuper_g_logo 1234 "
365 "google_logogoogle_gsuper_g_logo 123 "
366 "google_logogoogle_gsuper_g_logo 12 "
367 "google_logogoogle_gsuper_g_logo 1 "
368 "google_logogoogle_gsuper_g_logo "
369 "google_logogoogle_gsuper_g_logo "
370 "google_logogoogle_gsuper_g_logo "
371 "google_logogoogle_gsuper_g_logo "
372 "google_logogoogle_gsuper_g_logo "
373 "google_logogoogle_gsuper_g_logo"};
Julia Lavrova5207f352019-06-21 12:22:32 -0400374 std::vector<const char*> text = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400375 "My neighbor came over to say,\n"
376 "Although not in a neighborly way,\n\n"
377 "That he'd knock me around,\n\n\n"
378 "If I didn't stop the sound,\n\n\n\n"
379 "Of the classical music I play."};
380
Julia Lavrova5207f352019-06-21 12:22:32 -0400381 std::vector<const char*> long_word = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400382 "A_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
383 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
384 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
385 "very_very_very_very_very_very_very_long_text"};
386
Julia Lavrova5207f352019-06-21 12:22:32 -0400387 std::vector<const char*> very_long = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400388 "A very very very very very very very very very very very very very very very very "
389 "very very very very very very very very very very very very very very very very "
390 "very very very very very very very very very very very very very very very very "
391 "very very very very very very very long text"};
392
Julia Lavrova5207f352019-06-21 12:22:32 -0400393 std::vector<const char*> very_word = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400394 "A very_very_very_very_very_very_very_very_very_very "
395 "very_very_very_very_very_very_very_very_very_very very very very very very very "
396 "very very very very very very very very very very very very very very very very "
397 "very very very very very very very very very very very very very long text"};
398
399 SkScalar width = this->width() / 5;
400 SkScalar height = this->height();
401 drawText(canvas, width, height, long_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
402 canvas->translate(width, 0);
403 drawText(canvas, width, height, very_long, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
404 canvas->translate(width, 0);
405 drawText(canvas, width, height, very_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
406 canvas->translate(width, 0);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400407 drawText(canvas, width, height / 2, text, SK_ColorBLACK, SK_ColorWHITE, "Roboto", 20, 100,
408 u"\u2026");
409 canvas->translate(0, height / 2);
410 drawCode(canvas, width, height / 2);
411 canvas->translate(width, -height / 2);
412
413 drawText(canvas, width, height, cupertino, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
414 }
415
416private:
417 typedef Sample INHERITED;
418};
419
Mike Reed21a940d2019-07-23 10:11:03 -0400420class ParagraphView3 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400421protected:
Hal Canary8a027312019-07-03 10:55:44 -0400422 SkString name() override { return SkString("Paragraph3"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400423
424 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
425 TextAlign align, size_t lineLimit = std::numeric_limits<size_t>::max(),
426 bool RTL = false, SkColor background = SK_ColorGRAY,
427 const std::u16string& ellipsis = u"\u2026") {
428 SkAutoCanvasRestore acr(canvas, true);
429
430 canvas->clipRect(SkRect::MakeWH(w, h));
431 canvas->drawColor(SK_ColorWHITE);
432
433 SkScalar margin = 20;
434
435 SkPaint paint;
436 paint.setAntiAlias(true);
437 paint.setColor(SK_ColorBLACK);
438
439 SkPaint gray;
440 gray.setColor(background);
441
442 SkPaint yellow;
443 yellow.setColor(SK_ColorYELLOW);
444
445 TextStyle style;
446 style.setBackgroundColor(gray);
447 style.setForegroundColor(paint);
448 style.setFontFamilies({SkString("sans-serif")});
449 style.setFontSize(30);
450 ParagraphStyle paraStyle;
451 paraStyle.setTextStyle(style);
452 paraStyle.setTextAlign(align);
453 paraStyle.setMaxLines(lineLimit);
454 paraStyle.setEllipsis(ellipsis);
455 // paraStyle.setTextDirection(RTL ? SkTextDirection::rtl : SkTextDirection::ltr);
456
Julia Lavrova5207f352019-06-21 12:22:32 -0400457 auto fontCollection = sk_make_sp<FontCollection>();
458 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
459 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400460 if (RTL) {
461 builder.addText(mirror(text));
462 } else {
463 builder.addText(normal(text));
464 }
465
466 canvas->drawRect(SkRect::MakeXYWH(margin, margin, w - margin * 2, h - margin * 2), yellow);
467 auto paragraph = builder.Build();
468 paragraph->layout(w - margin * 2);
469 paragraph->paint(canvas, margin, margin);
470 }
471
472 std::u16string mirror(const std::string& text) {
473 std::u16string result;
474 result += u"\u202E";
475 // for (auto i = text.size(); i > 0; --i) {
476 // result += text[i - 1];
477 //}
478
479 for (auto i = text.size(); i > 0; --i) {
480 auto ch = text[i - 1];
481 if (ch == ',') {
482 result += u"!";
483 } else if (ch == '.') {
484 result += u"!";
485 } else {
486 result += ch;
487 }
488 }
489
490 result += u"\u202C";
491 return result;
492 }
493
494 std::u16string normal(const std::string& text) {
495 std::u16string result;
496 result += u"\u202D";
497 for (auto ch : text) {
498 result += ch;
499 }
500 result += u"\u202C";
501 return result;
502 }
503
504 void onDrawContent(SkCanvas* canvas) override {
505 const std::string options = // { "open-source open-source open-source open-source" };
506 {"Flutter is an open-source project to help developers "
507 "build high-performance, high-fidelity, mobile apps for "
508 "iOS and Android "
509 "from a single codebase. This design lab is a playground "
510 "and showcase of Flutter's many widgets, behaviors, "
511 "animations, layouts, and more."};
512
513 canvas->drawColor(SK_ColorDKGRAY);
514 SkScalar width = this->width() / 4;
515 SkScalar height = this->height() / 2;
516
517 const std::string line =
518 "World domination is such an ugly phrase - I prefer to call it world optimisation";
519
520 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, false, SK_ColorLTGRAY);
521 canvas->translate(width, 0);
522 drawLine(canvas, width, height, line, TextAlign::kRight, 2, false, SK_ColorLTGRAY);
523 canvas->translate(width, 0);
524 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, false, SK_ColorLTGRAY);
525 canvas->translate(width, 0);
526 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, false, SK_ColorLTGRAY);
527 canvas->translate(-width * 3, height);
528
529 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, true, SK_ColorLTGRAY);
530 canvas->translate(width, 0);
531 drawLine(canvas, width, height, line, TextAlign::kRight, 2, true, SK_ColorLTGRAY);
532 canvas->translate(width, 0);
533 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, true, SK_ColorLTGRAY);
534 canvas->translate(width, 0);
535 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, true, SK_ColorLTGRAY);
536 canvas->translate(width, 0);
537 }
538
539private:
540 typedef Sample INHERITED;
541};
542
Mike Reed21a940d2019-07-23 10:11:03 -0400543class ParagraphView4 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400544protected:
Hal Canary8a027312019-07-03 10:55:44 -0400545 SkString name() override { return SkString("Paragraph4"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400546
547 void drawFlutter(SkCanvas* canvas, SkScalar w, SkScalar h,
548 const char* ff = "Google Sans", SkScalar fs = 30,
549 size_t lineLimit = std::numeric_limits<size_t>::max(),
550 const std::u16string& ellipsis = u"\u2026") {
551 SkAutoCanvasRestore acr(canvas, true);
552
553 canvas->clipRect(SkRect::MakeWH(w, h));
554
555 SkScalar margin = 20;
556
557 SkPaint black;
558 black.setAntiAlias(true);
559 black.setColor(SK_ColorBLACK);
560
561 SkPaint blue;
562 blue.setAntiAlias(true);
563 blue.setColor(SK_ColorBLUE);
564
565 SkPaint red;
566 red.setAntiAlias(true);
567 red.setColor(SK_ColorRED);
568
569 SkPaint green;
570 green.setAntiAlias(true);
571 green.setColor(SK_ColorGREEN);
572
573 SkPaint gray;
574 gray.setColor(SK_ColorLTGRAY);
575
576 SkPaint yellow;
577 yellow.setColor(SK_ColorYELLOW);
578
579 SkPaint magenta;
580 magenta.setAntiAlias(true);
581 magenta.setColor(SK_ColorMAGENTA);
582
583 TextStyle style;
584 style.setFontFamilies({SkString(ff)});
585 style.setFontSize(fs);
586
587 TextStyle style0;
588 style0.setForegroundColor(black);
589 style0.setBackgroundColor(gray);
590 style0.setFontFamilies({SkString(ff)});
591 style0.setFontSize(fs);
592 style0.setDecoration(TextDecoration::kUnderline);
593 style0.setDecorationStyle(TextDecorationStyle::kDouble);
594 style0.setDecorationColor(SK_ColorBLACK);
595
596 TextStyle style1;
597 style1.setForegroundColor(blue);
598 style1.setBackgroundColor(yellow);
599 style1.setFontFamilies({SkString(ff)});
600 style1.setFontSize(fs);
601 style1.setDecoration(TextDecoration::kOverline);
602 style1.setDecorationStyle(TextDecorationStyle::kWavy);
603 style1.setDecorationColor(SK_ColorBLACK);
604
605 TextStyle style2;
606 style2.setForegroundColor(red);
607 style2.setFontFamilies({SkString(ff)});
608 style2.setFontSize(fs);
609
610 TextStyle style3;
611 style3.setForegroundColor(green);
612 style3.setFontFamilies({SkString(ff)});
613 style3.setFontSize(fs);
614
615 TextStyle style4;
616 style4.setForegroundColor(magenta);
617 style4.setFontFamilies({SkString(ff)});
618 style4.setFontSize(fs);
619
620 ParagraphStyle paraStyle;
621 paraStyle.setTextStyle(style);
622 paraStyle.setMaxLines(lineLimit);
623
624 paraStyle.setEllipsis(ellipsis);
625
626 const char* logo1 = "google_";
627 const char* logo2 = "logo";
628 const char* logo3 = "go";
629 const char* logo4 = "ogle_logo";
630 const char* logo5 = "google_lo";
631 const char* logo6 = "go";
632 {
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400633 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400634
635 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400636 builder.addText(logo1, strlen(logo1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400637 builder.pop();
638 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400639 builder.addText(logo2, strlen(logo2));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400640 builder.pop();
641
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400642 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400643
644 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400645 builder.addText(logo3, strlen(logo3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400646 builder.pop();
647 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400648 builder.addText(logo4, strlen(logo4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400649 builder.pop();
650
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400651 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400652
653 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400654 builder.addText(logo5, strlen(logo5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400655 builder.pop();
656 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400657 builder.addText(logo6, strlen(logo6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400658 builder.pop();
659
660 auto paragraph = builder.Build();
661 paragraph->layout(w - margin * 2);
662 paragraph->paint(canvas, margin, margin);
663 canvas->translate(0, h + margin);
664 }
665 }
666
667 void onDrawContent(SkCanvas* canvas) override {
668 canvas->drawColor(SK_ColorWHITE);
669 SkScalar width = this->width();
670 SkScalar height = this->height();
671
672 drawFlutter(canvas, width, height / 2);
673 }
674
675private:
676 typedef Sample INHERITED;
677};
678
Mike Reed21a940d2019-07-23 10:11:03 -0400679class ParagraphView5 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400680protected:
Julia Lavrova5207f352019-06-21 12:22:32 -0400681 SkString name() override { return SkString("Paragraph5"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400682
683 void bidi(SkCanvas* canvas, SkScalar w, SkScalar h, const std::u16string& text,
684 const std::u16string& expected, size_t lineLimit = std::numeric_limits<size_t>::max(),
685 const char* ff = "Roboto", SkScalar fs = 30,
686 const std::u16string& ellipsis = u"\u2026") {
687 SkAutoCanvasRestore acr(canvas, true);
688
689 canvas->clipRect(SkRect::MakeWH(w, h));
690
691 SkScalar margin = 20;
692
693 SkPaint black;
694 black.setColor(SK_ColorBLACK);
695 SkPaint gray;
696 gray.setColor(SK_ColorLTGRAY);
697
698 TextStyle style;
699 style.setForegroundColor(black);
700 style.setFontFamilies({SkString(ff)});
701 style.setFontSize(fs);
702
703 TextStyle style0;
704 style0.setForegroundColor(black);
705 style0.setFontFamilies({SkString(ff)});
706 style0.setFontSize(fs);
707 style0.setFontStyle(SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width,
708 SkFontStyle::kItalic_Slant));
709
710 TextStyle style1;
711 style1.setForegroundColor(gray);
712 style1.setFontFamilies({SkString(ff)});
713 style1.setFontSize(fs);
714 style1.setFontStyle(SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width,
715 SkFontStyle::kUpright_Slant));
716
717 ParagraphStyle paraStyle;
718 paraStyle.setTextStyle(style);
719 paraStyle.setMaxLines(lineLimit);
720
721 paraStyle.setEllipsis(ellipsis);
722
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400723 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400724
725 if (text.empty()) {
726 const std::u16string text0 = u"\u202Dabc";
727 const std::u16string text1 = u"\u202EFED";
728 const std::u16string text2 = u"\u202Dghi";
729 const std::u16string text3 = u"\u202ELKJ";
730 const std::u16string text4 = u"\u202Dmno";
731 builder.pushStyle(style0);
732 builder.addText(text0);
733 builder.pop();
734 builder.pushStyle(style1);
735 builder.addText(text1);
736 builder.pop();
737 builder.pushStyle(style0);
738 builder.addText(text2);
739 builder.pop();
740 builder.pushStyle(style1);
741 builder.addText(text3);
742 builder.pop();
743 builder.pushStyle(style0);
744 builder.addText(text4);
745 builder.pop();
746 } else {
Ben Wagner056d5432020-05-13 10:24:15 -0400747 if (this->isVerbose()) {
748 icu::UnicodeString unicode((UChar*) text.data(), SkToS32(text.size()));
749 std::string str;
750 unicode.toUTF8String(str);
751 SkDebugf("Text: %s\n", str.c_str());
752 }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400753 builder.addText(text + expected);
754 }
755
756 auto paragraph = builder.Build();
757 paragraph->layout(w - margin * 2);
758 paragraph->paint(canvas, margin, margin);
759 }
760
761 void onDrawContent(SkCanvas* canvas) override {
762 canvas->drawColor(SK_ColorWHITE);
763 SkScalar width = this->width();
764 SkScalar height = this->height() / 8;
765
766 const std::u16string text1 =
767 u"A \u202ENAC\u202Cner, exceedingly \u202ENAC\u202Cny,\n"
768 "One morning remarked to his granny:\n"
769 "A \u202ENAC\u202Cner \u202ENAC\u202C \u202ENAC\u202C,\n"
770 "Anything that he \u202ENAC\u202C,\n"
771 "But a \u202ENAC\u202Cner \u202ENAC\u202C't \u202ENAC\u202C a \u202ENAC\u202C, "
772 "\u202ENAC\u202C he?";
773 bidi(canvas, width, height * 3, text1, u"", 5);
774 canvas->translate(0, height * 3);
775
776 bidi(canvas, width, height, u"\u2067DETALOSI\u2069", u"");
777 canvas->translate(0, height);
778
779 bidi(canvas, width, height, u"\u202BDEDDEBME\u202C", u"");
780 canvas->translate(0, height);
781
782 bidi(canvas, width, height, u"\u202EEDIRREVO\u202C", u"");
783 canvas->translate(0, height);
784
785 bidi(canvas, width, height, u"\u200FTICILPMI\u200E", u"");
786 canvas->translate(0, height);
787
788 bidi(canvas, width, height, u"123 456 7890 \u202EZYXWV UTS RQP ONM LKJ IHG FED CBA\u202C.",
789 u"", 2);
790 canvas->translate(0, height);
791
792 // bidi(canvas, width, height, u"", u"");
793 // canvas->translate(0, height);
794 }
795
796private:
797 typedef Sample INHERITED;
798};
799
Mike Reed21a940d2019-07-23 10:11:03 -0400800class ParagraphView6 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400801protected:
Julia Lavrova5207f352019-06-21 12:22:32 -0400802 SkString name() override { return SkString("Paragraph6"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400803
804 void hangingS(SkCanvas* canvas, SkScalar w, SkScalar h, SkScalar fs = 60.0) {
805 auto ff = "HangingS";
806
807 canvas->drawColor(SK_ColorLTGRAY);
808
809 SkPaint black;
810 black.setAntiAlias(true);
811 black.setColor(SK_ColorBLACK);
812
813 SkPaint blue;
814 blue.setAntiAlias(true);
815 blue.setColor(SK_ColorBLUE);
816
817 SkPaint red;
818 red.setAntiAlias(true);
819 red.setColor(SK_ColorRED);
820
821 SkPaint green;
822 green.setAntiAlias(true);
823 green.setColor(SK_ColorGREEN);
824
825 SkPaint gray;
826 gray.setColor(SK_ColorCYAN);
827
828 SkPaint yellow;
829 yellow.setColor(SK_ColorYELLOW);
830
831 SkPaint magenta;
832 magenta.setAntiAlias(true);
833 magenta.setColor(SK_ColorMAGENTA);
834
835 SkFontStyle fontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width,
836 SkFontStyle::kItalic_Slant);
837
838 TextStyle style;
839 style.setFontFamilies({SkString(ff)});
840 style.setFontSize(fs);
841 style.setFontStyle(fontStyle);
842
843 TextStyle style0;
844 style0.setForegroundColor(black);
845 style0.setBackgroundColor(gray);
846 style0.setFontFamilies({SkString(ff)});
847 style0.setFontSize(fs);
848 style0.setFontStyle(fontStyle);
849
850 TextStyle style1;
851 style1.setForegroundColor(blue);
852 style1.setBackgroundColor(yellow);
853 style1.setFontFamilies({SkString(ff)});
854 style1.setFontSize(fs);
855 style1.setFontStyle(fontStyle);
856
857 TextStyle style2;
858 style2.setForegroundColor(red);
859 style2.setFontFamilies({SkString(ff)});
860 style2.setFontSize(fs);
861 style2.setFontStyle(fontStyle);
862
863 TextStyle style3;
864 style3.setForegroundColor(green);
865 style3.setFontFamilies({SkString(ff)});
866 style3.setFontSize(fs);
867 style3.setFontStyle(fontStyle);
868
869 TextStyle style4;
870 style4.setForegroundColor(magenta);
871 style4.setFontFamilies({SkString(ff)});
872 style4.setFontSize(fs);
873 style4.setFontStyle(fontStyle);
874
875 ParagraphStyle paraStyle;
876 paraStyle.setTextStyle(style);
877
878 const char* logo1 = "S";
879 const char* logo2 = "kia";
880 const char* logo3 = "Sk";
881 const char* logo4 = "ia";
882 const char* logo5 = "Ski";
883 const char* logo6 = "a";
884 {
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400885 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400886
887 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400888 builder.addText(logo1, strlen(logo1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400889 builder.pop();
890 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400891 builder.addText(logo2, strlen(logo2));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400892 builder.pop();
893
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400894 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400895
896 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400897 builder.addText(logo3, strlen(logo3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400898 builder.pop();
899 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400900 builder.addText(logo4, strlen(logo4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400901 builder.pop();
902
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400903 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400904
905 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400906 builder.addText(logo5, strlen(logo5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400907 builder.pop();
908 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400909 builder.addText(logo6, strlen(logo6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400910 builder.pop();
911
912 auto paragraph = builder.Build();
913 paragraph->layout(w);
914 paragraph->paint(canvas, 40, 40);
915 canvas->translate(0, h);
916 }
917
918 const char* logo11 = "S";
919 const char* logo12 = "S";
920 const char* logo13 = "S";
921 const char* logo14 = "S";
922 const char* logo15 = "S";
923 const char* logo16 = "S";
924 {
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400925 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400926
927 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400928 builder.addText(logo11, strlen(logo1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400929 builder.pop();
930 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400931 builder.addText(logo12, strlen(logo2));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400932 builder.pop();
933
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400934 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400935
936 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400937 builder.addText(logo13, strlen(logo3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400938 builder.pop();
939 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400940 builder.addText(logo14, strlen(logo4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400941 builder.pop();
942
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400943 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400944
945 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400946 builder.addText(logo15, strlen(logo5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400947 builder.pop();
948 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400949 builder.addText(logo16, strlen(logo6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400950 builder.pop();
951
952 auto paragraph = builder.Build();
953 paragraph->layout(w);
954 paragraph->paint(canvas, 40, h);
955 canvas->translate(0, h);
956 }
957 }
958
959 void onDrawContent(SkCanvas* canvas) override {
960 canvas->drawColor(SK_ColorWHITE);
961 SkScalar width = this->width();
962 SkScalar height = this->height() / 4;
963
964 hangingS(canvas, width, height);
965 }
966
967private:
968 typedef Sample INHERITED;
969};
970
Mike Reed21a940d2019-07-23 10:11:03 -0400971class ParagraphView7 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400972protected:
Hal Canary8a027312019-07-03 10:55:44 -0400973 SkString name() override { return SkString("Paragraph7"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400974
975 void drawText(SkCanvas* canvas, SkColor background, SkScalar letterSpace, SkScalar w,
976 SkScalar h) {
977 SkAutoCanvasRestore acr(canvas, true);
978 canvas->clipRect(SkRect::MakeWH(w, h));
979 canvas->drawColor(background);
980
981 const char* line =
Julia Lavrovadb9f6692019-08-01 16:02:17 -0400982 "World domination is such an ugly phrase - I prefer to call it world optimisation.";
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400983
984 ParagraphStyle paragraphStyle;
985 paragraphStyle.setTextAlign(TextAlign::kLeft);
986 paragraphStyle.setMaxLines(10);
987 paragraphStyle.turnHintingOff();
988 TextStyle textStyle;
989 textStyle.setFontFamilies({SkString("Roboto")});
990 textStyle.setFontSize(30);
991 textStyle.setLetterSpacing(letterSpace);
992 textStyle.setColor(SK_ColorBLACK);
993 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
994 SkFontStyle::kUpright_Slant));
995
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400996 ParagraphBuilderImpl builder(paragraphStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400997 builder.pushStyle(textStyle);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400998 builder.addText(line, strlen(line));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400999 builder.pop();
1000
1001 auto paragraph = builder.Build();
1002 paragraph->layout(w - 20);
1003 paragraph->paint(canvas, 10, 10);
1004 }
1005
1006 void onDrawContent(SkCanvas* canvas) override {
1007 canvas->drawColor(SK_ColorWHITE);
1008
1009 auto h = this->height() / 4;
1010 auto w = this->width() / 2;
1011
1012 drawText(canvas, SK_ColorGRAY, 1, w, h);
1013 canvas->translate(0, h);
1014
1015 drawText(canvas, SK_ColorLTGRAY, 2, w, h);
1016 canvas->translate(0, h);
1017
1018 drawText(canvas, SK_ColorCYAN, 3, w, h);
1019 canvas->translate(0, h);
1020
1021 drawText(canvas, SK_ColorGRAY, 4, w, h);
1022 canvas->translate(w, -3 * h);
1023
1024 drawText(canvas, SK_ColorYELLOW, 5, w, h);
1025 canvas->translate(0, h);
1026
1027 drawText(canvas, SK_ColorGREEN, 10, w, h);
1028 canvas->translate(0, h);
1029
1030 drawText(canvas, SK_ColorRED, 15, w, h);
1031 canvas->translate(0, h);
1032
1033 drawText(canvas, SK_ColorBLUE, 20, w, h);
1034 canvas->translate(0, h);
1035 }
1036
1037private:
1038 typedef Sample INHERITED;
1039};
1040
Mike Reed21a940d2019-07-23 10:11:03 -04001041class ParagraphView8 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001042protected:
Julia Lavrovadb9f6692019-08-01 16:02:17 -04001043 SkString name() override { return SkString("Paragraph8"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001044
1045 void drawText(SkCanvas* canvas, SkColor background, SkScalar wordSpace, SkScalar w,
1046 SkScalar h) {
1047 SkAutoCanvasRestore acr(canvas, true);
1048 canvas->clipRect(SkRect::MakeWH(w, h));
1049 canvas->drawColor(background);
1050
1051 const char* line =
Julia Lavrovadb9f6692019-08-01 16:02:17 -04001052 "World domination is such an ugly phrase - I prefer to call it world optimisation.";
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001053
1054 ParagraphStyle paragraphStyle;
1055 paragraphStyle.setTextAlign(TextAlign::kLeft);
1056 paragraphStyle.setMaxLines(10);
1057 paragraphStyle.turnHintingOff();
1058 TextStyle textStyle;
1059 textStyle.setFontFamilies({SkString("Roboto")});
1060 textStyle.setFontSize(30);
1061 textStyle.setWordSpacing(wordSpace);
1062 textStyle.setColor(SK_ColorBLACK);
1063 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
1064 SkFontStyle::kUpright_Slant));
1065
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -04001066 ParagraphBuilderImpl builder(paragraphStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001067 builder.pushStyle(textStyle);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -04001068 builder.addText(line, strlen(line));
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001069 builder.pop();
1070
1071 auto paragraph = builder.Build();
1072 paragraph->layout(w - 20);
1073 paragraph->paint(canvas, 10, 10);
1074 }
1075
1076 void onDrawContent(SkCanvas* canvas) override {
1077 canvas->drawColor(SK_ColorWHITE);
1078
1079 auto h = this->height() / 4;
1080 auto w = this->width() / 2;
1081
1082 drawText(canvas, SK_ColorGRAY, 1, w, h);
1083 canvas->translate(0, h);
1084
1085 drawText(canvas, SK_ColorLTGRAY, 2, w, h);
1086 canvas->translate(0, h);
1087
1088 drawText(canvas, SK_ColorCYAN, 3, w, h);
1089 canvas->translate(0, h);
1090
1091 drawText(canvas, SK_ColorGRAY, 4, w, h);
1092 canvas->translate(w, -3 * h);
1093
1094 drawText(canvas, SK_ColorYELLOW, 5, w, h);
1095 canvas->translate(0, h);
1096
1097 drawText(canvas, SK_ColorGREEN, 10, w, h);
1098 canvas->translate(0, h);
1099
1100 drawText(canvas, SK_ColorRED, 15, w, h);
1101 canvas->translate(0, h);
1102
1103 drawText(canvas, SK_ColorBLUE, 20, w, h);
1104 canvas->translate(0, h);
1105 }
1106
1107private:
1108 typedef Sample INHERITED;
1109};
1110
Mike Reed21a940d2019-07-23 10:11:03 -04001111class ParagraphView9 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001112protected:
Hal Canary8a027312019-07-03 10:55:44 -04001113 SkString name() override { return SkString("Paragraph9"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001114
Hal Canary6cc65e12019-07-03 15:53:04 -04001115 bool onChar(SkUnichar uni) override {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001116 switch (uni) {
1117 case 'w':
1118 ++wordSpacing;
1119 return true;
1120 case 'q':
1121 if (wordSpacing > 0) --wordSpacing;
1122 return true;
1123 case 'l':
1124 ++letterSpacing;
1125 return true;
1126 case 'k':
1127 if (letterSpacing > 0) --letterSpacing;
1128 return true;
1129 default:
1130 break;
1131 }
Hal Canary6cc65e12019-07-03 15:53:04 -04001132 return false;
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001133 }
1134
1135 void drawText(SkCanvas* canvas, SkColor background, SkScalar w, SkScalar h) {
1136 SkAutoCanvasRestore acr(canvas, true);
1137 canvas->clipRect(SkRect::MakeWH(w, h));
1138 canvas->drawColor(background);
1139
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001140 auto fontCollection = sk_make_sp<FontCollection>();
1141 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1142 fontCollection->enableFontFallback();
1143
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001144 const char* text =
1145 "( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1146 " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1147 " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)";
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001148 auto multiplier = 5.67;
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001149 ParagraphStyle paragraphStyle;
1150 paragraphStyle.setTextAlign(TextAlign::kLeft);
1151 paragraphStyle.setMaxLines(10);
1152 paragraphStyle.turnHintingOff();
1153 TextStyle textStyle;
1154 textStyle.setFontFamilies({SkString("Roboto")});
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001155 textStyle.setFontSize(5 * multiplier);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001156 textStyle.setHeight(1.3f);
1157 textStyle.setColor(SK_ColorBLACK);
1158 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
1159 SkFontStyle::kUpright_Slant));
1160
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001161 ParagraphBuilderImpl builder(paragraphStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001162 builder.pushStyle(textStyle);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -04001163 builder.addText(text, strlen(text));
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001164 builder.pop();
1165
1166 auto paragraph = builder.Build();
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001167 paragraph->layout(200 * multiplier);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001168
1169 std::vector<size_t> sizes = {0, 1, 2, 8, 19, 21, 22, 30, 150};
1170
1171 std::vector<size_t> colors = {SK_ColorBLUE, SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGREEN,
1172 SK_ColorRED, SK_ColorWHITE, SK_ColorYELLOW, SK_ColorMAGENTA};
1173
1174 RectHeightStyle rect_height_style = RectHeightStyle::kTight;
1175 RectWidthStyle rect_width_style = RectWidthStyle::kTight;
1176
1177 for (size_t i = 0; i < sizes.size() - 1; ++i) {
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001178 size_t from = sizes[i];
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001179 size_t to = sizes[i + 1];
1180 auto boxes = paragraph->getRectsForRange(from, to, rect_height_style, rect_width_style);
1181 if (boxes.empty()) {
1182 continue;
1183 }
1184 for (auto& box : boxes) {
1185 SkPaint paint;
1186 paint.setColor(colors[i % colors.size()]);
1187 paint.setShader(setgrad(box.rect, colors[i % colors.size()], SK_ColorWHITE));
1188 canvas->drawRect(box.rect, paint);
1189 }
1190 }
1191
1192 paragraph->paint(canvas, 0, 0);
1193 }
1194
1195 void onDrawContent(SkCanvas* canvas) override {
1196 canvas->drawColor(SK_ColorWHITE);
1197
1198 auto h = this->height();
1199 auto w = this->width();
1200
1201 drawText(canvas, SK_ColorGRAY, w, h);
1202 }
1203
1204private:
1205 typedef Sample INHERITED;
1206 SkScalar letterSpacing;
1207 SkScalar wordSpacing;
1208};
1209
Mike Reed21a940d2019-07-23 10:11:03 -04001210class ParagraphView10 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001211protected:
Hal Canary8a027312019-07-03 10:55:44 -04001212 SkString name() override { return SkString("Paragraph10"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001213
1214 void onDrawContent(SkCanvas* canvas) override {
1215 canvas->drawColor(SK_ColorWHITE);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001216 auto multiplier = 5.67;
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001217 const char* text = "English English 字典 字典 😀😃😄 😀😃😄";
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001218
1219 auto fontCollection = sk_make_sp<FontCollection>();
1220 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1221 fontCollection->enableFontFallback();
1222
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001223 ParagraphStyle paragraph_style;
1224 paragraph_style.turnHintingOff();
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001225 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001226
1227 TextStyle text_style;
Julia Lavrova5207f352019-06-21 12:22:32 -04001228 text_style.setFontFamilies({SkString("Roboto"),
1229 SkString("Noto Color Emoji"),
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001230 SkString("Noto Serif CJK JP")});
1231 text_style.setFontSize(10 * multiplier);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001232 text_style.setLetterSpacing(0);
1233 text_style.setWordSpacing(0);
1234 text_style.setColor(SK_ColorBLACK);
1235 text_style.setHeight(1);
1236 builder.pushStyle(text_style);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -04001237 builder.addText(text, strlen(text));
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001238 builder.pop();
1239
1240 auto paragraph = builder.Build();
1241 paragraph->layout(width());
1242
1243 paragraph->paint(canvas, 0, 0);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001244 }
1245
1246private:
1247 typedef Sample INHERITED;
1248};
1249
Mike Reed21a940d2019-07-23 10:11:03 -04001250class ParagraphView11 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001251protected:
Hal Canary8a027312019-07-03 10:55:44 -04001252 SkString name() override { return SkString("Paragraph11"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001253
1254 void onDrawContent(SkCanvas* canvas) override {
1255 canvas->drawColor(SK_ColorWHITE);
Julia Lavrova5207f352019-06-21 12:22:32 -04001256
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001257 auto text = "\U0001f469\U0000200D\U0001f469\U0000200D\U0001f466\U0001f469\U0000200D\U0001f469\U0000200D\U0001f467\U0000200D\U0001f467\U0001f1fa\U0001f1f8";
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001258
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001259 TextStyle text_style;
1260 text_style.setFontFamilies({SkString("Ahem")});
1261 text_style.setColor(SK_ColorBLACK);
1262 text_style.setFontSize(60);
1263 text_style.setLetterSpacing(0);
1264 text_style.setWordSpacing(0);
1265 ParagraphStyle paragraph_style;
1266 paragraph_style.setTextStyle(text_style);
1267
1268 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
1269 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1270 builder.addText(text, strlen(text));
1271 auto paragraph = builder.Build();
1272 paragraph->layout(1000);
1273 paragraph->paint(canvas, 0, 0);
1274
1275 struct pair {
1276 unsigned fX;
1277 unsigned fY;
1278 };
1279
1280 pair hit1[] =
1281 {{ 0, 8},{1, 33}, {2, 34}, { 3, 19}, {4, 20},
1282 { 5, 21}, { 6, 22 }, { 7, 23 }, {8, 24 }, { 9, 25},
1283 { 10, 26}, { 11, 27}, {12, 28}, { 13, 21}, {14, 22 },
1284 { 15, 23}, {16, 24}, {17, 21}, { 18, 22}, {19, 21},
1285 { 20, 24}, { 21, 23}, };
1286
1287 pair miss[] =
1288 {{ 0, 4},{1, 17}, {2, 18}, { 3, 11}, {4, 12},
1289 { 5, 13}, { 6, 14 }, { 7, 15 }, {8, 16 }, { 9, 17},
1290 { 10, 18}, { 11, 19}, {12, 20}, { 13, 17}, {14, 18 },
1291 { 15, 19}, {16, 20}, {17, 19}, { 18, 20},
1292 { 20, 22}, };
1293
1294 auto rects = paragraph->getRectsForRange(7, 9, RectHeightStyle::kTight, RectWidthStyle::kTight);
1295 SkPaint paint;
1296 paint.setColor(SK_ColorRED);
1297 paint.setStyle(SkPaint::kStroke_Style);
1298 paint.setAntiAlias(true);
1299 paint.setStrokeWidth(1);
1300 if (!rects.empty()) {
1301 canvas->drawRect(rects[0].rect, paint);
1302 }
1303
1304 for (auto& query : hit1) {
1305 auto rects = paragraph->getRectsForRange(query.fX, query.fY, RectHeightStyle::kTight, RectWidthStyle::kTight);
1306 if (rects.size() >= 1 && rects[0].rect.width() > 0) {
1307 } else {
Ben Wagner056d5432020-05-13 10:24:15 -04001308 if (this->isVerbose()) {
1309 SkDebugf("+[%d:%d): Bad\n", query.fX, query.fY);
1310 }
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001311 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001312 }
1313
1314 for (auto& query : miss) {
1315 auto miss = paragraph->getRectsForRange(query.fX, query.fY, RectHeightStyle::kTight, RectWidthStyle::kTight);
1316 if (miss.empty()) {
1317 } else {
Ben Wagner056d5432020-05-13 10:24:15 -04001318 if (this->isVerbose()) {
1319 SkDebugf("-[%d:%d): Bad\n", query.fX, query.fY);
1320 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001321 }
1322 }
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001323 }
1324
1325private:
1326 typedef Sample INHERITED;
1327};
1328
1329class ParagraphView12 : public ParagraphView_Base {
1330protected:
1331 SkString name() override { return SkString("Paragraph12"); }
1332
1333 void onDrawContent(SkCanvas* canvas) override {
1334 canvas->drawColor(SK_ColorWHITE);
1335
1336 const char* text = "Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neiges";
1337 TextStyle text_style;
1338 text_style.setFontFamilies({SkString("Ahem")});
1339 text_style.setColor(SK_ColorBLACK);
1340 text_style.setFontSize(16);
1341 //text_style.setLetterSpacing(-0.41);
1342 StrutStyle strut_style;
1343 strut_style.setStrutEnabled(false);
1344 ParagraphStyle paragraph_style;
1345 paragraph_style.setStrutStyle(strut_style);
1346 paragraph_style.setTextStyle(text_style);
1347 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1348 builder.addText(text);
1349 auto paragraph = builder.Build();
1350 paragraph->layout(1095.000000);
1351 auto result = paragraph->getRectsForRange(65, 66, RectHeightStyle::kTight, RectWidthStyle::kTight);
1352 paragraph->paint(canvas, 0, 0);
1353
1354 SkPaint paint;
1355 paint.setColor(SK_ColorRED);
1356 paint.setStyle(SkPaint::kStroke_Style);
1357 paint.setAntiAlias(true);
1358 paint.setStrokeWidth(1);
1359 canvas->drawRect(result.front().rect, paint);
1360 }
1361
1362private:
1363 typedef Sample INHERITED;
1364};
1365
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001366class ParagraphView14 : public ParagraphView_Base {
1367protected:
1368 SkString name() override { return SkString("Paragraph14"); }
1369
1370 void onDrawContent(SkCanvas* canvas) override {
1371 canvas->drawColor(SK_ColorWHITE);
1372 TextStyle text_style;
1373 text_style.setFontFamilies({SkString("Ahem")});
1374 text_style.setColor(SK_ColorBLACK);
1375 text_style.setFontSize(25);
1376 text_style.setDecoration((TextDecoration)(TextDecoration::kUnderline | TextDecoration::kOverline | TextDecoration::kLineThrough));
1377 text_style.setDecorationColor(SK_ColorBLUE);
1378 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
1379 text_style.setDecorationThicknessMultiplier(4.0f);
1380 ParagraphStyle paragraph_style;
1381 paragraph_style.setTextStyle(text_style);
1382 paragraph_style.setTextDirection(TextDirection::kRtl);
1383 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1384 builder.pushStyle(text_style);
1385 builder.addText("Hello, wor!\nabcd.");
1386 auto paragraph = builder.Build();
1387 paragraph->layout(300);
1388 paragraph->paint(canvas, 0, 0);
1389 SkPaint paint;
1390 paint.setColor(SK_ColorRED);
1391 paint.setStyle(SkPaint::kStroke_Style);
1392 paint.setAntiAlias(true);
1393 paint.setStrokeWidth(1);
1394 canvas->drawRect(SkRect::MakeXYWH(0, 0, 300, 100), paint);
1395 }
1396
1397private:
1398 typedef Sample INHERITED;
1399};
1400
1401class ParagraphView15 : public ParagraphView_Base {
1402protected:
1403 SkString name() override { return SkString("Paragraph15"); }
1404
1405 void onDrawContent(SkCanvas* canvas) override {
1406 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001407
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001408 TextStyle text_style;
1409 text_style.setFontFamilies({SkString("abc.ttf")});
1410 text_style.setFontSize(50);
1411
1412 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false);
1413
1414 fontCollection->addFontFromFile("abc/abc.ttf", "abc");
1415 fontCollection->addFontFromFile("abc/abc+grave.ttf", "abc+grave");
1416 fontCollection->addFontFromFile("abc/abc+agrave.ttf", "abc+agrave");
1417
1418 ParagraphStyle paragraph_style;
1419 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1420
1421 text_style.setFontFamilies({SkString("abc"), SkString("abc+grave")});
1422 text_style.setColor(SK_ColorBLUE);
1423 builder.pushStyle(text_style);
1424 builder.addText(u"a\u0300");
1425 text_style.setColor(SK_ColorMAGENTA);
1426 builder.pushStyle(text_style);
1427 builder.addText(u"à");
1428
1429 text_style.setFontFamilies({SkString("abc"), SkString("abc+agrave")});
1430
1431 text_style.setColor(SK_ColorRED);
1432 builder.pushStyle(text_style);
1433 builder.addText(u"a\u0300");
1434 text_style.setColor(SK_ColorGREEN);
1435 builder.pushStyle(text_style);
1436 builder.addText(u"à");
1437
1438 auto paragraph = builder.Build();
1439 paragraph->layout(800);
1440 paragraph->paint(canvas, 50, 50);
1441
Julia Lavrova5207f352019-06-21 12:22:32 -04001442 }
1443
1444private:
1445 typedef Sample INHERITED;
1446};
1447
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001448class ParagraphView16 : public ParagraphView_Base {
1449protected:
1450 SkString name() override { return SkString("Paragraph16"); }
1451
1452 void onDrawContent(SkCanvas* canvas) override {
1453 canvas->drawColor(SK_ColorWHITE);
1454
1455 const char* text = "content";
1456
1457 ParagraphStyle paragraph_style;
1458 paragraph_style.setMaxLines(1);
1459 paragraph_style.setEllipsis(u"\u2026");
1460 //auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1461 auto fontCollection = sk_make_sp<FontCollection>();
1462 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1463 fontCollection->enableFontFallback();
1464 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1465
1466 TextStyle text_style;
1467 text_style.setFontFamilies({SkString(".SF Pro Text")});
1468 text_style.setColor(SK_ColorBLACK);
1469 text_style.setFontSize(17.0f * 99.0f);
1470 text_style.setLetterSpacing(0.41f);
1471 builder.pushStyle(text_style);
1472 builder.addText(text);
1473
1474 auto paragraph = builder.Build();
1475 paragraph->layout(800);
1476 paragraph->paint(canvas, 0, 0);
1477 }
1478
1479private:
1480 typedef Sample INHERITED;
1481};
1482
1483class ParagraphView17 : public ParagraphView_Base {
1484protected:
1485 SkString name() override { return SkString("Paragraph17"); }
1486
1487 void onDrawContent(SkCanvas* canvas) override {
1488 canvas->drawColor(SK_ColorWHITE);
1489
1490 auto fontCollection = sk_make_sp<FontCollection>();
1491 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1492 fontCollection->enableFontFallback();
1493 auto navy = SkColorSetRGB(0, 0, 139);
1494 auto ltgray = SkColorSetRGB(211, 211, 211);
1495 auto multiplier = 5.67;
1496
1497 const char* text = ">Sͬ͑̀͐̈͒̈́̋̎ͮͩ̽̓ͬ̂̆̔͗́̓ͣͧ͊ͫ͛̉͌̐̑ͪ͗̚͝҉̴͉͢k̡̊̓ͫͭͩ͂͊ͨͪͬ̑ͫ̍̌̄͛̌̂̑̂̋̊̔ͫ͛̽̑ͨ̍ͭ̓̀ͪͪ̉͐͗̌̓̃̚͟͝҉̢͏̫̞̙͇͖̮͕̗̟͕͇͚̻͈̣̻̪͉̰̲̣̫ͅͅP̴̅̍͒̿͗͗̇ͩ̃͆͌̀̽͏̧̡͕͖̝̖̼̺̰̣̬͔͖͔̼͙̞̦̫͓̘͜a̸̴̸̴̢̢̨̨̫͍͓̥̼̭̼̻̤̯̙̤̻̠͚̍̌͋̂ͦͨ̽̇͌͌͆̀̽̎͒̄ͪ̐ͦ̈ͫ͐͗̓̚̚͜ͅr͐͐ͤͫ̐ͥ͂̈́̿́ͮ̃͗̓̏ͫ̀̿͏̸̵̧́͘̕͟͝͠͞͠҉̷̧͚͢͟a̓̽̎̄͗̔͛̄̐͊͛ͫ͂͌̂̂̈̈̓̔̅̅̄͊̉́ͪ̑̄͆ͬ̍͆ͭ͋̐ͬ͏̷̵̨̢̩̹̖͓̥̳̰͔̱̬͖̙͓̙͇̀̀̕͜͟͟͢͟͜͠͡g̨̅̇ͦ͋̂ͦͨͭ̓͐͆̏̂͛̉ͧ̑ͫ̐̒͛ͫ̍̒͛́̚҉̷̨̛̛̀͜͢͞҉̩̘̲͍͎̯̹̝̭̗̱͇͉̲̱͔̯̠̹̥̻͉̲̜̤̰̪̗̺̖̺r̷͌̓̇̅ͭ̀̐̃̃ͭ͑͗̉̈̇̈́ͥ̓ͣ́ͤ͂ͤ͂̏͌̆̚҉̴̸̧̢̢̛̫͉̦̥̤̙͈͉͈͉͓̙̗̟̳̜͈̗̺̟̠̠͖͓̖̪͕̠̕̕͝ͅả̸̴̡̡̧͠͞͡͞҉̛̕͟͏̷̘̪̱͈̲͉̞̠̞̪̫͎̲̬̖̀̀͟͝͞͞͠p̛͂̈͐̚͠҉̵̸̡̢̢̩̹͙̯͖̙̙̮̥̙͚̠͔̥̭̮̞̣̪̬̥̠̖̝̥̪͎́̀̕͜͡͡ͅͅh̵̷̵̡̛ͤ̂͌̐̓̐̋̋͊̒̆̽́̀̀̀͢͠͞͞҉̷̸̢̕҉͚̯͖̫̜̞̟̠̱͉̝̲̹̼͉̟͉̩̮͔̤͖̞̭̙̹̬ͅ<";
1498
1499 ParagraphStyle paragraph_style;
1500 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1501 SkPaint paint;
1502 paint.setColor(ltgray);
1503 TextStyle text_style;
1504 text_style.setBackgroundColor(paint);
1505 text_style.setColor(navy);
1506 text_style.setFontFamilies({SkString("Roboto")});
1507 text_style.setFontSize(20 * multiplier);
1508 builder.pushStyle(text_style);
1509 builder.addText(text);
1510 auto paragraph = builder.Build();
1511 paragraph->layout(10000);
1512 paragraph->paint(canvas, 0, 0);
1513 }
1514
1515private:
1516 typedef Sample INHERITED;
1517};
1518
1519class Zalgo {
1520 private:
1521 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";
1522 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";
1523 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";
1524
1525 std::u16string randomMarks(std::u16string& combiningMarks) {
1526 std::u16string result;
1527 auto num = std::rand() % (combiningMarks.size() / 1);
1528 for (size_t i = 0; i < num; ++i) {
1529 auto index = std::rand() % combiningMarks.size();
1530 result += combiningMarks[index];
1531 }
1532 return result;
1533 }
1534
1535public:
1536 std::u16string zalgo(std::string victim) {
1537 std::u16string result;
1538 for (auto& c : victim) {
1539 result += c;
1540 result += randomMarks(COMBINING_UP);
1541 result += randomMarks(COMBINING_MIDDLE);
1542 result += randomMarks(COMBINING_DOWN);
1543 }
1544 return result;
1545 }
1546};
1547
1548class ParagraphView18 : public ParagraphView_Base {
1549protected:
1550 SkString name() override { return SkString("Paragraph18"); }
1551
1552 bool onChar(SkUnichar uni) override {
1553 switch (uni) {
1554 case ' ':
1555 fLimit = 400;
1556 return true;
1557 case 's':
1558 fLimit += 10;
1559 return true;
1560 case 'f':
1561 if (fLimit > 10) {
1562 fLimit -= 10;
1563 }
1564 return true;
1565 default:
1566 break;
1567 }
1568 return false;
1569 }
1570
1571 bool onAnimate(double nanos) override {
1572 if (++fIndex > fLimit) {
1573 fRedraw = true;
1574 fIndex = 0;
1575 } else {
1576 fRepeat = true;
1577 }
1578 return true;
1579 }
1580
1581 void onDrawContent(SkCanvas* canvas) override {
1582 canvas->drawColor(SK_ColorWHITE);
1583
1584 auto navy = SkColorSetRGB(0, 0, 139);
1585 auto ltgray = SkColorSetRGB(211, 211, 211);
1586
1587 auto multiplier = 5.67;
1588 auto fontCollection = sk_make_sp<FontCollection>();
1589 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1590 fontCollection->enableFontFallback();
1591
1592 ParagraphStyle paragraph_style;
1593 TextStyle text_style;
1594 text_style.setFontFamilies({SkString("Roboto")});
1595 text_style.setFontSize(20 * multiplier);
1596 text_style.setColor(navy);
1597 SkPaint paint;
1598 paint.setColor(ltgray);
1599 text_style.setBackgroundColor(paint);
1600
1601 Zalgo zalgo;
1602
1603 if (fRedraw || fRepeat) {
1604
1605 if (fRedraw || fParagraph.get() == nullptr) {
1606 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1607 builder.pushStyle(text_style);
1608 auto utf16text = zalgo.zalgo("SkParagraph");
1609 icu::UnicodeString unicode((UChar*)utf16text.data(), SkToS32(utf16text.size()));
1610 std::string str;
1611 unicode.toUTF8String(str);
Ben Wagner056d5432020-05-13 10:24:15 -04001612 if (this->isVerbose()) {
1613 SkDebugf("Text:>%s<\n", str.data());
1614 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001615 builder.addText(utf16text);
1616 fParagraph = builder.Build();
1617 }
1618
1619 auto impl = static_cast<ParagraphImpl*>(fParagraph.get());
1620 impl->setState(InternalState::kUnknown);
1621 fParagraph->layout(1000);
1622 fParagraph->paint(canvas, 300, 200);
1623
1624 for (auto& run : impl->runs()) {
1625 SkString fontFamily("unresolved");
1626 if (run.font().getTypeface() != nullptr) {
1627 run.font().getTypeface()->getFamilyName(&fontFamily);
1628 }
1629 if (run.font().getTypeface() != nullptr) {
1630 for (size_t i = 0; i < run.size(); ++i) {
1631 auto glyph = run.glyphs().begin() + i;
1632 if (*glyph == 0) {
1633 SkDebugf("Run[%d] @pos=%d\n", run.index(), i);
1634 SkASSERT(false);
1635 }
1636 }
1637 } else {
1638 SkDebugf("Run[%d]: %s\n", run.index(), fontFamily.c_str());
1639 SkASSERT(false);
1640 }
1641 }
1642 fRedraw = false;
1643 fRepeat = false;
1644 }
1645 }
1646
1647private:
1648 bool fRedraw = true;
1649 bool fRepeat = false;
1650 size_t fIndex = 0;
1651 size_t fLimit = 20;
1652 std::unique_ptr<Paragraph> fParagraph;
1653 typedef Sample INHERITED;
1654};
1655
1656class ParagraphView19 : public ParagraphView_Base {
1657protected:
1658 SkString name() override { return SkString("Paragraph19"); }
1659
1660 void onDrawContent(SkCanvas* canvas) override {
1661 canvas->drawColor(SK_ColorWHITE);
1662
1663 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1664
Julia Lavrova90bfd1c2019-12-04 11:43:32 -05001665 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";
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001666 ParagraphStyle paragraph_style;
1667 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001668 TextStyle text_style;
Julia Lavrovac028b422019-11-25 10:00:43 -05001669 text_style.setColor(SK_ColorBLACK);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001670 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova90bfd1c2019-12-04 11:43:32 -05001671 text_style.setFontSize(20);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001672 builder.pushStyle(text_style);
1673 builder.addText(text);
1674 auto paragraph = builder.Build();
Julia Lavrovac028b422019-11-25 10:00:43 -05001675 paragraph->layout(this->width());
Julia Lavrovac028b422019-11-25 10:00:43 -05001676 paragraph->paint(canvas, 0, 0);
1677 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001678
Julia Lavrovac028b422019-11-25 10:00:43 -05001679private:
1680 typedef Sample INHERITED;
1681};
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001682
Julia Lavrovac028b422019-11-25 10:00:43 -05001683class ParagraphView20 : public ParagraphView_Base {
1684protected:
1685 SkString name() override { return SkString("Paragraph20"); }
1686
1687 void onDrawContent(SkCanvas* canvas) override {
1688 canvas->drawColor(SK_ColorWHITE);
1689
1690 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1691
Julia Lavrovac48687a2020-01-08 16:53:53 -05001692 const char* text = "Manage your google account";
Julia Lavrovac028b422019-11-25 10:00:43 -05001693 ParagraphStyle paragraph_style;
Julia Lavrovac48687a2020-01-08 16:53:53 -05001694 paragraph_style.setEllipsis(u"\u2026");
1695 paragraph_style.setMaxLines(1);
Julia Lavrovac028b422019-11-25 10:00:43 -05001696 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1697 TextStyle text_style;
1698 text_style.setColor(SK_ColorBLACK);
Julia Lavrova53c14472019-12-18 09:39:55 -05001699 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrovac48687a2020-01-08 16:53:53 -05001700 text_style.setFontSize(50);
Julia Lavrovac028b422019-11-25 10:00:43 -05001701 builder.pushStyle(text_style);
1702 builder.addText(text);
1703 auto paragraph = builder.Build();
Julia Lavrovac48687a2020-01-08 16:53:53 -05001704 paragraph->layout(this->width());
1705 paragraph->paint(canvas, 0, 0);
1706 }
1707
1708private:
1709 typedef Sample INHERITED;
1710};
1711
1712class ParagraphView21 : public ParagraphView_Base {
1713protected:
1714 SkString name() override { return SkString("Paragraph21"); }
1715
1716 void onDrawContent(SkCanvas* canvas) override {
1717 canvas->drawColor(SK_ColorWHITE);
1718
Julia Lavrova70e93012020-01-10 14:04:45 -05001719 const char* text = "Referral Code";
Julia Lavrovac48687a2020-01-08 16:53:53 -05001720 ParagraphStyle paragraph_style;
Julia Lavrovaf6a3f8e2020-01-10 10:55:52 -05001721 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
Julia Lavrovac48687a2020-01-08 16:53:53 -05001722 TextStyle text_style;
1723 text_style.setColor(SK_ColorBLACK);
Julia Lavrovaf6a3f8e2020-01-10 10:55:52 -05001724 text_style.setFontFamilies({SkString("Google Sans")});
1725 text_style.setFontSize(24);
Julia Lavrovac48687a2020-01-08 16:53:53 -05001726 builder.pushStyle(text_style);
1727 builder.addText(text);
1728 auto paragraph = builder.Build();
Julia Lavrova70e93012020-01-10 14:04:45 -05001729 paragraph->layout(0);
Julia Lavrovac028b422019-11-25 10:00:43 -05001730 paragraph->paint(canvas, 0, 0);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001731 }
1732
1733private:
1734 typedef Sample INHERITED;
1735};
Julia Lavrova4cf18742020-01-14 13:24:45 -05001736
1737class ParagraphView22 : public ParagraphView_Base {
1738protected:
1739 SkString name() override { return SkString("Paragraph22"); }
1740
Julia Lavrova9bd83512020-01-15 14:46:35 -05001741 bool onChar(SkUnichar uni) override {
1742 switch (uni) {
1743 case 'l':
1744 direction = true;
1745 return true;
1746 case 'r':
1747 direction = false;
1748 return true;
1749 default:
1750 break;
Julia Lavrova4cf18742020-01-14 13:24:45 -05001751 }
Julia Lavrova9bd83512020-01-15 14:46:35 -05001752 return false;
1753 }
1754
1755 void onDrawContent(SkCanvas* canvas) override {
1756
1757 canvas->drawColor(SK_ColorWHITE);
1758 ParagraphStyle paragraph_style;
1759 paragraph_style.setTextDirection(direction ? TextDirection::kLtr : TextDirection::kRtl);
1760 auto collection = getFontCollection();
1761 ParagraphBuilderImpl builder(paragraph_style, collection);
1762 collection->getParagraphCache()->reset();
1763 collection->getParagraphCache()->turnOn(false);
1764 TextStyle text_style;
1765 text_style.setColor(SK_ColorBLACK);
1766 text_style.setFontFamilies({SkString("Roboto")});
1767 text_style.setFontSize(12);
1768 builder.pushStyle(text_style);
1769 builder.addText("I have got a ");
1770 text_style.setFontStyle(SkFontStyle::Bold());
1771 builder.pushStyle(text_style);
1772 builder.addText("lovely bunch");
1773 text_style.setFontStyle(SkFontStyle::Normal());
1774 builder.pushStyle(text_style);
1775 builder.addText(" of coconuts.");
1776 auto paragraph = builder.Build();
1777 paragraph->layout(this->width());
1778 paragraph->paint(canvas, 0, 0);
1779 collection->getParagraphCache()->turnOn(true);
Julia Lavrova4cf18742020-01-14 13:24:45 -05001780 }
1781
1782private:
1783 typedef Sample INHERITED;
Julia Lavrova9bd83512020-01-15 14:46:35 -05001784 bool direction;
Julia Lavrova4cf18742020-01-14 13:24:45 -05001785};
Julia Lavrova9bd83512020-01-15 14:46:35 -05001786
Julia Lavrova51a813d2020-01-21 13:55:44 -05001787class ParagraphView23 : public ParagraphView_Base {
1788protected:
1789 SkString name() override { return SkString("Paragraph23"); }
1790
1791 void onDrawContent(SkCanvas* canvas) override {
1792 canvas->drawColor(SK_ColorWHITE);
1793
1794 const char* text = "Text with shadow";
1795 ParagraphStyle paragraph_style;
1796 TextStyle text_style;
1797 text_style.setColor(SK_ColorBLACK);
1798 text_style.setFontFamilies({SkString("Google Sans")});
1799 text_style.setFontSize(24);
1800
1801 auto draw = [&](SkScalar h, SkScalar v, SkScalar b) {
1802 text_style.resetShadows();
1803 text_style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(h, v), b));
1804 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1805 builder.pushStyle(text_style);
1806 builder.addText(text);
1807 auto paragraph = builder.Build();
1808 paragraph->layout(300);
1809 paragraph->paint(canvas, 0, 0);
1810
1811 auto rect = SkRect::MakeXYWH(0, 0, paragraph->getMaxWidth(), paragraph->getHeight());
1812 SkPaint paint;
1813 paint.setColor(SK_ColorRED);
1814 paint.setStyle(SkPaint::kStroke_Style);
1815 paint.setAntiAlias(true);
1816 paint.setStrokeWidth(1);
1817 canvas->drawRect(rect, paint);
1818 };
1819
1820 draw(10, 10, 5);
1821 canvas->translate(0, 100);
1822
1823 draw(10, -10, 5);
1824 canvas->translate(0, 100);
1825
1826 draw(-10, -10, 5);
1827 canvas->translate(0, 100);
1828
1829 draw(-10, 10, 5);
1830 canvas->translate(0, 100);
1831 }
1832
1833private:
1834 typedef Sample INHERITED;
1835};
1836
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001837class ParagraphView24 : public ParagraphView_Base {
1838protected:
1839 SkString name() override { return SkString("Paragraph24"); }
1840
1841 void onDrawContent(SkCanvas* canvas) override {
1842 canvas->drawColor(SK_ColorWHITE);
1843
1844 ParagraphStyle paragraph_style;
1845 paragraph_style.setTextDirection(TextDirection::kRtl);
1846 TextStyle text_style;
1847 text_style.setColor(SK_ColorBLACK);
1848 text_style.setFontFamilies({SkString("Google Sans")});
1849 text_style.setFontSize(24);
1850 {
1851 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1852 builder.pushStyle(text_style);
1853 builder.addText("Right_to_left:");
1854 auto paragraph = builder.Build();
1855 paragraph->layout(this->width());
1856 paragraph->paint(canvas, 0, 0);
1857 }
1858 canvas->translate(0, 200);
1859 {
1860 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1861 builder.pushStyle(text_style);
1862 builder.addText("Right_to_left+");
1863 auto paragraph = builder.Build();
1864 paragraph->layout(this->width());
1865 paragraph->paint(canvas, 0, 0);
1866 }
1867 canvas->translate(0, 200);
1868 {
1869 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1870 builder.pushStyle(text_style);
1871 builder.addText("Right_to_left.");
1872 auto paragraph = builder.Build();
1873 paragraph->layout(this->width());
1874 paragraph->paint(canvas, 0, 0);
1875 }
1876 }
1877
1878private:
1879 typedef Sample INHERITED;
1880};
1881
1882class ParagraphView25 : public ParagraphView_Base {
1883protected:
1884 SkString name() override { return SkString("Paragraph25"); }
1885
1886 void onDrawContent(SkCanvas* canvas) override {
1887 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovac0360582020-02-05 10:17:53 -05001888/*
1889 * Shell: ParagraphStyle: 1.000000 1
1890Shell: Strut enabled: 0 1.000000 14.000000 400 5 0
1891Shell: Font Families: 0
1892Shell: DefaultTextStyle: 16.000000 500 5 0
1893Shell: Font Families: 1 Roboto
1894Shell: Font Features: 0
1895Shell: TextStyle#0: [0:22) 16.000000 500 5 0
1896Shell: Font Families: 1 Roboto
1897Shell: Font Features: 0
1898Shell: TextStyle#1: [25:49) 16.000000 500 5 0
1899Shell: Font Families: 1 Roboto
1900Shell: Font Features: 0
1901Shell: Placeholder#0: [22:25) 32.000000 32.000000 32.000000 0 5
1902Shell: Placeholder#1: [49:52) 19.000000 41.000000 19.000000 0 4
1903Shell: Placeholder#2: [52:52) 0.000000 0.000000 0.000000 0 5
1904Shell: layout('Go to device settings  and set up a passcode. ', 280.000000): 280.000000 * 38.000000
1905 */
1906 auto fontCollection = getFontCollection();
1907 //fontCollection->getParagraphCache()->turnOn(false);
1908 const char* text1 = "Go to device settings ";
1909 const char* text2 = "and set up a passcode.";
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001910 ParagraphStyle paragraph_style;
Julia Lavrovac0360582020-02-05 10:17:53 -05001911 StrutStyle strut_style;
1912 strut_style.setStrutEnabled(false);
1913 strut_style.setFontSize(14);
1914 strut_style.setForceStrutHeight(false);
1915 strut_style.setHeight(14);
1916 paragraph_style.setStrutStyle(strut_style);
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001917 TextStyle text_style;
1918 text_style.setColor(SK_ColorBLACK);
Julia Lavrovac0360582020-02-05 10:17:53 -05001919 text_style.setFontFamilies({SkString("Roboto")});
1920 text_style.setFontSize(16);
1921 PlaceholderStyle placeholder_style;
1922 {
1923 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1924 builder.pushStyle(text_style);
1925 builder.addText(text1);
1926 placeholder_style.fHeight = 32;
1927 placeholder_style.fWidth = 32;
1928 placeholder_style.fBaselineOffset = 32;
1929 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1930 placeholder_style.fAlignment = PlaceholderAlignment::kMiddle;
1931 builder.addPlaceholder(placeholder_style);
1932 builder.addText(text2);
1933 placeholder_style.fHeight = 19;
1934 placeholder_style.fWidth = 41;
1935 placeholder_style.fBaselineOffset = 19;
1936 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1937 placeholder_style.fAlignment = PlaceholderAlignment::kTop;
1938 builder.addPlaceholder(placeholder_style);
1939 auto paragraph = builder.Build();
1940 paragraph->layout(280);
1941 paragraph->paint(canvas, 0, 0);
1942 }
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001943 }
1944
1945private:
1946 typedef Sample INHERITED;
1947};
1948
1949class ParagraphView26 : public ParagraphView_Base {
1950protected:
1951 SkString name() override { return SkString("Paragraph26"); }
1952
1953 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001954 auto fontCollection = sk_make_sp<FontCollection>();
1955 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
Julia Lavrova95a9e692020-02-05 10:17:53 -05001956 //fontCollection->enableFontFallback();
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001957
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001958 canvas->clear(SK_ColorWHITE);
1959
1960 SkPaint paint;
1961 paint.setAntiAlias(true);
1962 paint.setColor(SK_ColorBLACK);
1963
1964 TextStyle textStyle;
1965 textStyle.setForegroundColor(paint);
Julia Lavrova95a9e692020-02-05 10:17:53 -05001966 textStyle.setFontFamilies({ SkString("Roboto") });
1967 textStyle.setFontSize(42.0f);
1968 textStyle.setLetterSpacing(-0.05f);
1969 textStyle.setHeightOverride(true);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001970
1971 ParagraphStyle paragraphStyle;
1972 paragraphStyle.setTextStyle(textStyle);
1973 paragraphStyle.setTextAlign(TextAlign::kLeft);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001974
Julia Lavrova95a9e692020-02-05 10:17:53 -05001975 ParagraphBuilderImpl builder(paragraphStyle, fontCollection);
1976 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");
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001977
Julia Lavrova95a9e692020-02-05 10:17:53 -05001978 auto paragraph = builder.Build();
1979 paragraph->layout(this->width() / 2);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001980
Julia Lavrova95a9e692020-02-05 10:17:53 -05001981 std::vector<LineMetrics> lines;
1982 paragraph->getLineMetrics(lines); // <-- error happens here
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001983
Julia Lavrova95a9e692020-02-05 10:17:53 -05001984 canvas->translate(10, 10);
1985 paragraph->paint(canvas, 0, 0);
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001986 }
1987
1988private:
1989 typedef Sample INHERITED;
1990};
1991
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05001992class ParagraphView27 : public ParagraphView_Base {
1993protected:
1994 SkString name() override { return SkString("Paragraph27"); }
1995
1996 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001997 auto fontCollection = sk_make_sp<FontCollection>();
1998 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1999 fontCollection->enableFontFallback();
2000 fontCollection->getParagraphCache()->turnOn(false);
2001
2002 SkPaint red;
2003 red.setColor(SK_ColorRED);
2004 red.setStyle(SkPaint::kStroke_Style);
2005 red.setAntiAlias(true);
2006 red.setStrokeWidth(1);
2007
2008 SkPaint blue;
2009 blue.setColor(SK_ColorRED);
2010 blue.setStyle(SkPaint::kStroke_Style);
2011 blue.setAntiAlias(true);
2012 blue.setStrokeWidth(1);
2013
2014 SkPaint black;
2015 black.setColor(SK_ColorBLACK);
2016 black.setStyle(SkPaint::kStroke_Style);
2017 black.setAntiAlias(true);
2018 black.setStrokeWidth(1);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002019
Julia Lavrova95a9e692020-02-05 10:17:53 -05002020 SkPaint whiteSpaces;
2021 whiteSpaces.setColor(SK_ColorLTGRAY);
2022
2023 SkPaint breakingSpace;
2024 breakingSpace.setColor(SK_ColorYELLOW);
2025
2026 SkPaint text;
2027 text.setColor(SK_ColorWHITE);
2028
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002029 ParagraphStyle paragraph_style;
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002030 paragraph_style.setTextAlign(TextAlign::kRight);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002031 TextStyle text_style;
2032 text_style.setColor(SK_ColorBLACK);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002033 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova89e678d2020-01-28 10:43:31 -05002034
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002035 // RTL + right align + arabic
2036 // RTL + right align + latin
2037 // LTR + right align + arabic
2038 // LTR + right align + latin
2039 // RTL + left align + arabic
2040 // RTL + left align + latin
2041 // arabic and latin should not differ at all
2042 // check: line breaking and trailing spaces
2043
2044 canvas->drawColor(SK_ColorWHITE);
2045 auto h = 60;
2046 auto w = 300;
2047
Julia Lavrova95a9e692020-02-05 10:17:53 -05002048 auto draw = [&](SkScalar width, SkScalar height, TextDirection td, TextAlign ta, const char* t) {
Ben Wagner056d5432020-05-13 10:24:15 -04002049 if (this->isVerbose()) {
2050 SkDebugf("draw '%s' dir:%s align:%s\n", t,
2051 td == TextDirection::kLtr ? "left" : "right",
2052 ta == TextAlign::kLeft ? "left" : "right");
2053 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002054 paragraph_style.setTextDirection(td);
2055 paragraph_style.setTextAlign(ta);
2056 text_style.setFontSize(20);
2057 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrova95a9e692020-02-05 10:17:53 -05002058 text_style.setBackgroundColor(whiteSpaces);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002059 builder.pushStyle(text_style);
Julia Lavrova95a9e692020-02-05 10:17:53 -05002060 builder.addText(" ");
2061 text_style.setBackgroundColor(text);
2062 builder.pushStyle(text_style);
2063 builder.addText(t);
2064 text_style.setBackgroundColor(breakingSpace);
2065 builder.pushStyle(text_style);
2066 builder.addText(" ");
2067 text_style.setBackgroundColor(text);
2068 builder.pushStyle(text_style);
2069 builder.addText(t);
2070 text_style.setBackgroundColor(whiteSpaces);
2071 builder.pushStyle(text_style);
2072 builder.addText(" ");
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002073 auto paragraph = builder.Build();
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002074 paragraph->layout(width);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002075 paragraph->paint(canvas, 0, 0);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002076 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
2077 for (auto& line : impl->lines()) {
Ben Wagner056d5432020-05-13 10:24:15 -04002078 if (this->isVerbose()) {
2079 SkDebugf("line[%d]: %f + %f\n", &line - impl->lines().begin(), line.offset().fX, line.shift());
2080 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002081 line.iterateThroughVisualRuns(true,
2082 [&](const Run* run, SkScalar runOffset, TextRange textRange, SkScalar* width) {
2083 *width = line.measureTextInsideOneRun(textRange, run, runOffset, 0, true, false).clip.width();
Ben Wagner056d5432020-05-13 10:24:15 -04002084 if (this->isVerbose()) {
2085 SkDebugf("%d[%d: %d) @%f + %f %s\n", run->index(),
2086 textRange.start, textRange.end, runOffset, *width, run->leftToRight() ? "left" : "right");
2087 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002088 return true;
2089 });
2090 }
2091 auto boxes = paragraph->getRectsForRange(0, 100, RectHeightStyle::kTight, RectWidthStyle::kTight);
2092 bool even = true;
2093 for (auto& box : boxes) {
Ben Wagner056d5432020-05-13 10:24:15 -04002094 if (this->isVerbose()) {
2095 SkDebugf("[%f:%f,%f:%f] %s\n",
2096 box.rect.fLeft, box.rect.fRight, box.rect.fTop, box.rect.fBottom,
2097 box.direction == TextDirection::kLtr ? "left" : "right");
2098 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002099 canvas->drawRect(box.rect, even ? red : blue);
2100 even = !even;
2101 }
2102 canvas->translate(0, height);
Julia Lavrova89e678d2020-01-28 10:43:31 -05002103 };
2104
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002105 canvas->drawRect(SkRect::MakeXYWH(0, 0, w, h * 8), black);
2106
2107 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "RTL+RIGHT#1234567890");
2108 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
2109
2110 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "LTR+RIGHT#1234567890");
2111 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
2112
2113 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "RTL+LEFT##1234567890");
2114 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
2115
2116 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "LTR+LEFT##1234567890");
2117 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002118 }
2119
2120private:
2121 typedef Sample INHERITED;
2122};
2123
Julia Lavrova212bf072020-02-18 12:05:55 -05002124class ParagraphView28 : public ParagraphView_Base {
2125protected:
2126 SkString name() override { return SkString("Paragraph28"); }
2127
2128 void onDrawContent(SkCanvas* canvas) override {
2129
2130 const char* text = "AAAAA BBBBB CCCCC DDDDD EEEEE FFFFF GGGGG HHHHH IIIII JJJJJ KKKKK LLLLL MMMMM NNNNN OOOOO PPPPP QQQQQ";
2131
2132 canvas->drawColor(SK_ColorWHITE);
2133 ParagraphStyle paragraph_style;
2134 paragraph_style.setTextAlign(TextAlign::kJustify);
2135 auto collection = getFontCollection();
2136 ParagraphBuilderImpl builder(paragraph_style, collection);
2137 TextStyle text_style;
2138 text_style.setColor(SK_ColorBLACK);
2139 text_style.setFontFamilies({SkString("Roboto")});
2140 text_style.setFontSize(40);
2141 builder.pushStyle(text_style);
2142 builder.addText(text);
2143 auto paragraph = builder.Build();
2144 auto s = 186;
2145 paragraph->layout(360 - s);
2146 paragraph->paint(canvas, 0, 0);
2147 /*
2148 paragraph->layout(360);
2149 paragraph->paint(canvas, 0, 0);
2150 canvas->translate(0, 400);
2151 paragraph->layout(354.333);
2152 paragraph->paint(canvas, 0, 0);
2153 */
2154 }
2155
2156private:
2157 typedef Sample INHERITED;
2158};
2159
2160class ParagraphView29 : public ParagraphView_Base {
2161protected:
2162 SkString name() override { return SkString("Paragraph29"); }
2163
2164 void onDrawContent(SkCanvas* canvas) override {
2165
Julia Lavrova62076972020-02-19 15:12:48 -05002166 const char* text = "ffi";
Julia Lavrova212bf072020-02-18 12:05:55 -05002167 canvas->drawColor(SK_ColorWHITE);
2168
Julia Lavrova62076972020-02-19 15:12:48 -05002169 auto collection = getFontCollection();
Julia Lavrova212bf072020-02-18 12:05:55 -05002170
2171 ParagraphStyle paragraph_style;
Julia Lavrova212bf072020-02-18 12:05:55 -05002172 ParagraphBuilderImpl builder(paragraph_style, collection);
2173 TextStyle text_style;
2174 text_style.setColor(SK_ColorBLACK);
2175 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova62076972020-02-19 15:12:48 -05002176 text_style.setFontSize(60);
Julia Lavrova212bf072020-02-18 12:05:55 -05002177 builder.pushStyle(text_style);
2178 builder.addText(text);
2179 auto paragraph = builder.Build();
Julia Lavrova62076972020-02-19 15:12:48 -05002180 paragraph->layout(width());
Julia Lavrova212bf072020-02-18 12:05:55 -05002181 paragraph->paint(canvas, 0, 0);
Julia Lavrova62076972020-02-19 15:12:48 -05002182 auto width = paragraph->getLongestLine();
2183 auto height = paragraph->getHeight();
2184
2185 auto f1 = paragraph->getGlyphPositionAtCoordinate(width/6, height/2);
2186 auto f2 = paragraph->getGlyphPositionAtCoordinate(width/2, height/2);
2187 auto i = paragraph->getGlyphPositionAtCoordinate(width*5/6, height/2);
2188
Ben Wagner056d5432020-05-13 10:24:15 -04002189 if (this->isVerbose()) {
2190 SkDebugf("%d(%s) %d(%s) %d(%s)\n",
2191 f1.position, f1.affinity == Affinity::kUpstream ? "up" : "down",
2192 f2.position, f2.affinity == Affinity::kUpstream ? "up" : "down",
2193 i.position, i.affinity == Affinity::kUpstream ? "up" : "down");
Julia Lavrova62076972020-02-19 15:12:48 -05002194
Ben Wagner056d5432020-05-13 10:24:15 -04002195 auto rf1 = paragraph->getRectsForRange(0, 1, RectHeightStyle::kTight, RectWidthStyle::kTight)[0];
2196 auto rf2 = paragraph->getRectsForRange(1, 2, RectHeightStyle::kTight, RectWidthStyle::kTight)[0];
2197 auto rfi = paragraph->getRectsForRange(2, 3, RectHeightStyle::kTight, RectWidthStyle::kTight)[0];
Julia Lavrova62076972020-02-19 15:12:48 -05002198
Ben Wagner056d5432020-05-13 10:24:15 -04002199 SkDebugf("f1: [%f:%f] %s\n",
2200 rf1.rect.fLeft, rf1.rect.fRight, rf1.direction == TextDirection::kRtl ? "rtl" : "ltr");
2201 SkDebugf("f2: [%f:%f] %s\n",
2202 rf2.rect.fLeft, rf2.rect.fRight, rf2.direction == TextDirection::kRtl ? "rtl" : "ltr");
2203 SkDebugf("i: [%f:%f] %s\n",
2204 rfi.rect.fLeft, rfi.rect.fRight, rfi.direction == TextDirection::kRtl ? "rtl" : "ltr");
2205 }
Julia Lavrova212bf072020-02-18 12:05:55 -05002206 }
2207
2208private:
2209 typedef Sample INHERITED;
2210};
2211
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002212class ParagraphView30 : public ParagraphView_Base {
2213protected:
2214 SkString name() override { return SkString("Paragraph30"); }
2215
2216 void onDrawContent(SkCanvas* canvas) override {
2217
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002218 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";
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002219 canvas->drawColor(SK_ColorWHITE);
2220
2221 auto fontCollection = sk_make_sp<FontCollection>();
2222 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2223 fontCollection->enableFontFallback();
2224
2225 ParagraphStyle paragraph_style;
2226 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2227 TextStyle text_style;
2228 text_style.setColor(SK_ColorBLACK);
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002229 text_style.setFontFamilies({SkString("Noto Color Emoji")});
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002230 text_style.setFontSize(60);
2231 builder.pushStyle(text_style);
2232 builder.addText(text);
2233 auto paragraph = builder.Build();
2234 paragraph->layout(width());
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002235
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002236
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002237 SkColor colors[] = {
2238 SK_ColorRED,
2239 SK_ColorGREEN,
2240 SK_ColorBLUE,
2241 SK_ColorMAGENTA,
2242 SK_ColorYELLOW
2243 };
2244 SkPaint paint;
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002245 size_t color = 0;
2246 for (size_t i = 0; i < text.size(); ++i) {
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002247 auto result = paragraph->getRectsForRange(i, i + 1, RectHeightStyle::kTight, RectWidthStyle::kTight);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002248 if (result.empty()) {
Ben Wagner056d5432020-05-13 10:24:15 -04002249 if (this->isVerbose()) {
2250 SkDebugf("empty [%d:%d)\n", i, i + 1);
2251 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002252 continue;
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002253 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002254 auto rect = result[0].rect;
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002255 paint.setColor(colors[color++ % 5]);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002256 canvas->drawRect(rect, paint);
Ben Wagner056d5432020-05-13 10:24:15 -04002257 if (this->isVerbose()) {
2258 SkDebugf("rect [%d:%d): %f:%f\n", i, i + 1, rect.fLeft, rect.fRight);
2259 }
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002260 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002261 paragraph->paint(canvas, 0, 0);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002262 }
2263
2264private:
2265 typedef Sample INHERITED;
2266};
2267
2268class ParagraphView31 : public ParagraphView_Base {
2269protected:
2270 SkString name() override { return SkString("Paragraph31"); }
2271
2272 void onDrawContent(SkCanvas* canvas) override {
2273
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002274 canvas->drawColor(SK_ColorWHITE);
2275
2276 auto fontCollection = sk_make_sp<FontCollection>();
2277 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2278 fontCollection->enableFontFallback();
2279
2280 ParagraphStyle paragraph_style;
2281 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2282 TextStyle text_style;
2283 text_style.setColor(SK_ColorBLACK);
2284 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002285 text_style.setFontSize(40);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002286 builder.pushStyle(text_style);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002287 auto s = u"েن েূথ";
2288 builder.addText(s);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002289 auto paragraph = builder.Build();
2290 paragraph->layout(width());
2291 paragraph->paint(canvas, 0, 0);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002292 }
2293
2294private:
2295 typedef Sample INHERITED;
2296};
2297
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002298class ParagraphView32 : public ParagraphView_Base {
2299protected:
2300 SkString name() override { return SkString("Paragraph32"); }
2301
2302 void onDrawContent(SkCanvas* canvas) override {
2303
2304 canvas->drawColor(SK_ColorWHITE);
2305
2306 auto fontCollection = sk_make_sp<FontCollection>();
2307 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2308 fontCollection->enableFontFallback();
2309
2310 ParagraphStyle paragraph_style;
2311 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2312 TextStyle text_style;
2313 text_style.setColor(SK_ColorBLACK);
2314 text_style.setFontFamilies({SkString("Roboto")});
2315 text_style.setFontSize(40);
2316 text_style.setLocale(SkString("ko"));
2317 builder.pushStyle(text_style);
2318 builder.addText(u"\u904d ko ");
2319 text_style.setLocale(SkString("zh_Hant"));
2320 builder.pushStyle(text_style);
2321 builder.addText(u"\u904d zh-Hant ");
2322 text_style.setLocale(SkString("zh_Hans"));
2323 builder.pushStyle(text_style);
2324 builder.addText(u"\u904d zh-Hans ");
2325 text_style.setLocale(SkString("zh_HK"));
2326 builder.pushStyle(text_style);
2327 builder.addText(u"\u904d zh-HK ");
2328 auto paragraph = builder.Build();
2329 paragraph->layout(width());
2330 paragraph->paint(canvas, 0, 0);
2331 }
2332
2333private:
2334 typedef Sample INHERITED;
2335};
2336
2337class ParagraphView33 : public ParagraphView_Base {
2338protected:
2339 SkString name() override { return SkString("Paragraph33"); }
2340
2341 void onDrawContent(SkCanvas* canvas) override {
2342
2343 canvas->drawColor(SK_ColorWHITE);
2344
2345 auto fontCollection = sk_make_sp<FontCollection>();
2346 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2347 fontCollection->enableFontFallback();
2348
2349 ParagraphStyle paragraph_style;
2350 paragraph_style.setTextAlign(TextAlign::kJustify);
2351 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2352 TextStyle text_style;
2353 text_style.setColor(SK_ColorBLACK);
2354 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2355 text_style.setFontSize(36);
2356 builder.pushStyle(text_style);
2357 builder.addText(u"AAAAA \U0001f600 BBBBB CCCCC DDDDD EEEEE");
2358 auto paragraph = builder.Build();
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002359 paragraph->layout(width() / 2);
2360 SkPaint paint;
2361 paint.setColor(SK_ColorLTGRAY);
2362 canvas->drawRect(SkRect::MakeXYWH(0, 0, width()/2, paragraph->getHeight()), paint);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002363 paragraph->paint(canvas, 0, 0);
2364 }
2365
2366private:
2367 typedef Sample INHERITED;
2368};
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002369
2370class ParagraphView34 : public ParagraphView_Base {
2371protected:
2372 SkString name() override { return SkString("Paragraph34"); }
2373
2374 void onDrawContent(SkCanvas* canvas) override {
2375
2376 canvas->drawColor(SK_ColorWHITE);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002377 auto text = "ضخمة ص ،😁😂🤣ضضض ؤ،،😗😗😍😋شسي،😗😁😁ؤرى،😗😃😄😍ببب،🥰😅🥰🥰🥰ثيلااتن";
2378 //auto text = "ى،😗😃😄😍بب";
2379 //auto text1 = "World domination is such an ugly phrase - I prefer to call it world optimisation";
2380 auto fontCollection = sk_make_sp<FontCollection>();
2381 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2382 fontCollection->enableFontFallback();
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002383
2384 ParagraphStyle paragraph_style;
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002385 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2386 TextStyle text_style;
2387 text_style.setColor(SK_ColorBLACK);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002388 text_style.setFontFamilies({SkString("Noto Color Emoji")});
2389 text_style.setFontSize(50);
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002390 builder.pushStyle(text_style);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002391 builder.addText(text);
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002392 auto paragraph = builder.Build();
Julia Lavrova3c79a232020-03-02 09:58:52 -05002393 paragraph->layout(1041); // 1041
2394
2395 SkColor colors[] = {SK_ColorBLUE, SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGREEN,
2396 SK_ColorRED, SK_ColorWHITE, SK_ColorYELLOW, SK_ColorMAGENTA };
2397 SkPaint paint;
2398 size_t wordPos = 0;
2399 size_t index = 0;
2400 while (wordPos < 72) {
2401 auto res2 = paragraph->getWordBoundary(wordPos);
2402 if (res2.width() == 0) {
2403 break;
2404 }
2405 wordPos = res2.end;
2406 auto res3 = paragraph->getRectsForRange(
2407 res2.start, res2.end,
2408 RectHeightStyle::kTight, RectWidthStyle::kTight);
2409 paint.setColor(colors[index % 8]);
2410 ++index;
2411 if (!res3.empty()) {
2412 canvas->drawRect(res3[0].rect, paint);
2413 }
2414 }
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002415 paragraph->paint(canvas, 0, 0);
2416 }
2417
2418private:
2419 typedef Sample INHERITED;
2420};
Julia Lavrova3c79a232020-03-02 09:58:52 -05002421
2422class ParagraphView35 : public ParagraphView_Base {
2423protected:
2424 SkString name() override { return SkString("Paragraph35"); }
2425
2426 Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
2427 return new Click;
2428 }
2429
2430 bool onClick(Click* click) override {
2431 fPoint = click->fCurr;
2432 return true;
2433 }
2434
2435 void onDrawContent(SkCanvas* canvas) override {
2436
2437 canvas->drawColor(SK_ColorWHITE);
2438
2439 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";
2440 auto fontCollection = sk_make_sp<FontCollection>();
2441 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2442 fontCollection->enableFontFallback();
2443
2444 ParagraphStyle paragraph_style;
Julia Lavrova2813d452020-03-03 11:43:40 -05002445 //paragraph_style.setTextAlign(TextAlign::kJustify);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002446 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2447 TextStyle text_style;
2448 text_style.setColor(SK_ColorBLACK);
2449 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2450 text_style.setFontSize(40);
2451 builder.pushStyle(text_style);
2452 builder.addText(text);
2453 auto paragraph = builder.Build();
Julia Lavrova2813d452020-03-03 11:43:40 -05002454 paragraph->layout(width());//758
2455
2456 //auto res1 = paragraph->getGlyphPositionAtCoordinate(line.width() + line.spacesWidth() / 2, line.offset().fY + 10);
2457 //auto res2 = paragraph->getWordBoundary(res1.position);
2458 auto res1 = paragraph->getRectsForRange(360, 361, RectHeightStyle::kTight, RectWidthStyle::kTight);
2459 auto res2 = paragraph->getRectsForRange(359, 360, RectHeightStyle::kTight, RectWidthStyle::kTight);
2460 auto res3 = paragraph->getRectsForRange(358, 359, RectHeightStyle::kTight, RectWidthStyle::kTight);
2461
2462 auto draw = [&](std::vector<TextBox> res, SkColor color) {
2463 SkPaint paint;
2464 paint.setColor(color);
2465 for (auto& r : res) {
2466 canvas->drawRect(r.rect, paint);
2467 }
2468 };
2469
2470 draw(res1, SK_ColorRED);
2471 draw(res2, SK_ColorGREEN);
2472 draw(res3, SK_ColorBLUE);
2473
Julia Lavrova3c79a232020-03-02 09:58:52 -05002474 paragraph->paint(canvas, 0, 0);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002475 }
2476
2477private:
2478 typedef Sample INHERITED;
2479 SkPoint fPoint;
2480};
2481
Julia Lavrova2813d452020-03-03 11:43:40 -05002482class ParagraphView36 : public ParagraphView_Base {
2483protected:
2484 SkString name() override { return SkString("Paragraph36"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04002485
Julia Lavrova2813d452020-03-03 11:43:40 -05002486 void onDrawContent(SkCanvas* canvas) override {
2487
2488 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovacd2d4e42020-03-27 15:40:37 -04002489 auto text = "String is too big for WinMSVC";
2490 //"সৢ৭ঙ া 七七去关谢都四先么见香认东 غلضينخي 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 字弟是去妈京学地";
2491 //"ي ز";
2492 //"৪৮ু৸ধ maar";
2493 //"四的 ذخص ৢঙ";
2494 //"ذخص ৢঙ";
Julia Lavrova2813d452020-03-03 11:43:40 -05002495 auto fontCollection = sk_make_sp<FontCollection>();
2496 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2497 fontCollection->enableFontFallback();
2498
2499 ParagraphStyle paragraph_style;
Julia Lavrova2813d452020-03-03 11:43:40 -05002500 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2501 TextStyle text_style;
2502 text_style.setColor(SK_ColorBLACK);
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002503 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Serif CJK JP")});
2504 text_style.setFontSize(10);
Julia Lavrova2813d452020-03-03 11:43:40 -05002505 builder.pushStyle(text_style);
2506 builder.addText(text);
2507 auto paragraph = builder.Build();
2508 paragraph->layout(width());
2509
Julia Lavrova2813d452020-03-03 11:43:40 -05002510 paragraph->paint(canvas, 0, 0);
2511 }
2512
2513private:
2514 typedef Sample INHERITED;
2515};
2516
Julia Lavrova99ede422020-03-17 13:20:58 -04002517class ParagraphView37 : public ParagraphView_Base {
2518protected:
2519 SkString name() override { return SkString("Paragraph37"); }
2520
2521 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovacd2d4e42020-03-27 15:40:37 -04002522 const char* text = "String is too big for WinMSVC";
2523 // "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaয়ৠঝোণ৺ঢ়মৈবৗৗঘথফড়৭২খসঢ়ৃঢ়ঁ৷থডঈঽলবনদ২ৢৃঀজঝ৩ঠ৪৫৯০ঌয়্মওৗ৲গখদ৹ঈ৴৹ঢ়ৄএৡফণহলঈ৲থজোৱে ঀকৰঀষজঝঃাখশঽএমংি";
Julia Lavrovaa169b002020-03-23 13:39:52 -04002524 //"ৎৣ়ৎঽতঃ৳্ৱব৴ৣঈ৷ূঁঢঢ়শটডৎ৵৵ৰৃ্দংঊাথৗদঊউদ৯ঐৃধা৬হওধি়৭ঽম৯স০ঢফৈঢ়কষঁছফীআে৶ৰ৶ঌৌঊ্ঊঝএঀঃদঞ৮তব৬ৄঊঙঢ়ৡগ৶৹৹ঌড়ঘৄ৷লপ১ভড়৶েঢ়৯ৎকনংট২ংএঢৌৌঐনো০টঽুৠগআ৷৭৩৬তো৻ঈ০ূসষঅঝআমণঔা১ণৈো৵চঽ৩বমৎঙঘ২ঠৠৈী৫তঌণচ৲ঔী৮ঘৰঔ";
Julia Lavrova99ede422020-03-17 13:20:58 -04002525 canvas->drawColor(SK_ColorWHITE);
2526
2527 auto fontCollection = sk_make_sp<FontCollection>();
2528 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2529 fontCollection->enableFontFallback();
2530
2531 ParagraphStyle paragraph_style;
2532 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2533 TextStyle text_style;
2534 text_style.setColor(SK_ColorBLACK);
2535 text_style.setFontFamilies({SkString("Roboto")});
2536 text_style.setFontSize(20);
2537 builder.pushStyle(text_style);
2538 builder.addText(text);
2539 auto paragraph = builder.Build();
2540 auto w = width() / 2;
2541 paragraph->layout(w);
Julia Lavrovaa169b002020-03-23 13:39:52 -04002542 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
2543
2544 auto clusters = impl->clusters();
Ben Wagner056d5432020-05-13 10:24:15 -04002545 if (this->isVerbose()) {
2546 size_t c = 0;
2547 SkDebugf("clusters\n");
2548 for (auto& cluster: clusters) {
2549 SkDebugf("%d: [%d:%d) %s\n", c++,
2550 cluster.textRange().start, cluster.textRange().end,
2551 cluster.isSoftBreak() ? "soft" :
2552 cluster.isHardBreak() ? "hard" :
2553 cluster.isWhitespaces() ? "spaces" : "");
2554 }
2555
2556 auto lines = impl->lines();
2557 size_t i = 0;
2558 SkDebugf("lines\n");
2559 for (auto& line : lines) {
2560 SkDebugf("%d: [%d:%d)\n", i++, line.trimmedText().start, line.trimmedText().end);
2561 }
Julia Lavrovaa169b002020-03-23 13:39:52 -04002562 }
2563
Julia Lavrova99ede422020-03-17 13:20:58 -04002564 paragraph->paint(canvas, 0, 0);
2565 }
2566
2567private:
2568 typedef Sample INHERITED;
2569};
2570
Julia Lavrova18db52f2020-05-04 15:03:18 -04002571class ParagraphView38 : public ParagraphView_Base {
2572protected:
2573 SkString name() override { return SkString("Paragraph38"); }
2574
2575 void onDrawContent(SkCanvas* canvas) override {
2576
2577 canvas->drawColor(SK_ColorWHITE);
2578
2579 auto fontCollection = sk_make_sp<FontCollection>();
2580 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2581 fontCollection->enableFontFallback();
2582
2583 ParagraphStyle paragraph_style;
2584 paragraph_style.setTextAlign(TextAlign::kLeft);
2585 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2586 TextStyle text_style;
2587 text_style.setColor(SK_ColorDKGRAY);
2588 text_style.setFontFamilies({SkString("Roboto")});
2589 text_style.setFontSize(40);
2590 text_style.setDecoration(TextDecoration::kUnderline);
2591
2592 text_style.setDecorationMode(TextDecorationMode::kThrough);
2593 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2594 text_style.setDecorationColor(SK_ColorBLUE);
2595 builder.pushStyle(text_style);
2596 builder.addText("Double underline: {opopo}\n");
2597
2598 text_style.setDecorationMode(TextDecorationMode::kGaps);
2599 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2600 text_style.setDecorationColor(SK_ColorBLUE);
2601 builder.pushStyle(text_style);
2602 builder.addText("Double underline: {opopo}\n");
2603
2604 text_style.setDecorationStyle(TextDecorationStyle::kDotted);
2605 text_style.setDecorationColor(SK_ColorRED);
2606 builder.pushStyle(text_style);
2607 builder.addText("Dotted underline: {ijiji}\n");
2608
2609 text_style.setDecorationStyle(TextDecorationStyle::kSolid);
2610 text_style.setDecorationColor(SK_ColorGREEN);
2611 builder.pushStyle(text_style);
2612 builder.addText("Solid underline: {rqrqr}\n");
2613
2614 text_style.setDecorationStyle(TextDecorationStyle::kDashed);
2615 text_style.setDecorationColor(SK_ColorMAGENTA);
2616 builder.pushStyle(text_style);
2617 builder.addText("Dashed underline: {zyzyz}\n");
2618
2619 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
2620 text_style.setDecorationColor(SK_ColorCYAN);
2621 builder.pushStyle(text_style);
2622 builder.addText("Wavy underline: {does not skip}\n");
2623
2624 auto paragraph = builder.Build();
2625 paragraph->layout(width());
2626 paragraph->paint(canvas, 0, 0);
2627 }
2628
2629private:
2630 typedef Sample INHERITED;
2631};
2632
Julia Lavrova6bdbd3d2020-05-06 12:03:17 -04002633class ParagraphView39 : public ParagraphView_Base {
2634protected:
2635 SkString name() override { return SkString("Paragraph39"); }
2636
2637 void onDrawContent(SkCanvas* canvas) override {
2638
2639 canvas->drawColor(SK_ColorWHITE);
2640
2641 auto fontCollection = sk_make_sp<FontCollection>();
2642 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2643 fontCollection->enableFontFallback();
2644
2645 ParagraphStyle paragraph_style;
2646 paragraph_style.setTextAlign(TextAlign::kJustify);
2647 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2648 TextStyle text_style;
2649 text_style.setColor(SK_ColorBLACK);
2650 text_style.setFontFamilies({SkString("Roboto")});
2651 text_style.setFontSize(40);
2652 builder.pushStyle(text_style);
2653 builder.addText(
2654 "text1 with line break\n"
2655 "text2 without line break text without line break text without line break text without line break text without line break text without line break "
2656 "text3 with line break\n"
2657 "text4 without line break text without line break text without line break text without line break text without line break text without line break "
2658 "text5 with line break\n"
2659 );
2660 auto paragraph = builder.Build();
2661 paragraph->layout(width());
2662 paragraph->paint(canvas, 0, 0);
2663 }
2664
2665private:
2666 typedef Sample INHERITED;
2667};
2668
Julia Lavrovadd1de252020-05-08 11:53:19 -04002669class ParagraphView41 : public ParagraphView_Base {
2670protected:
2671 SkString name() override { return SkString("Paragraph41"); }
2672
2673 void onDrawContent(SkCanvas* canvas) override {
2674
2675 canvas->drawColor(SK_ColorWHITE);
2676
2677 auto fontCollection = sk_make_sp<FontCollection>();
2678 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2679 fontCollection->enableFontFallback();
2680
2681 SkPaint line;
2682 line.setColor(SK_ColorRED);
2683 line.setStyle(SkPaint::kStroke_Style);
2684 line.setAntiAlias(true);
2685 line.setStrokeWidth(1);
2686
2687 auto draw = [&](SkColor color, TextHeightBehavior thb) {
2688 ParagraphStyle paragraph_style;
2689 paragraph_style.setTextHeightBehavior(thb);
2690 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2691 TextStyle text_style;
2692 text_style.setColor(SK_ColorBLACK);
2693 SkPaint paint;
2694 paint.setColor(color);
2695 text_style.setBackgroundColor(paint);
2696 text_style.setFontFamilies({SkString("Roboto")});
2697 text_style.setFontSize(20);
2698 text_style.setHeight(5);
2699 text_style.setHeightOverride(true);
2700 builder.pushStyle(text_style);
2701 builder.addText("World domination is such an ugly phrase - I prefer to call it world optimisation");
2702 auto paragraph = builder.Build();
2703 paragraph->layout(width());
2704 paragraph->paint(canvas, 0, 0);
2705 canvas->drawLine(0, paragraph->getHeight(), paragraph->getMaxWidth(), paragraph->getHeight(), line);
2706 canvas->translate(0, paragraph->getHeight());
2707 };
2708
2709 draw(SK_ColorLTGRAY, TextHeightBehavior::kDisableFirstAscent);
2710 draw(SK_ColorYELLOW, TextHeightBehavior::kDisableLastDescent);
2711 draw(SK_ColorGRAY, TextHeightBehavior::kDisableAll);
2712
2713 }
2714
2715private:
2716 typedef Sample INHERITED;
2717};
2718
2719class ParagraphView42 : public ParagraphView_Base {
2720protected:
2721 SkString name() override { return SkString("Paragraph42"); }
2722
2723 void onDrawContent(SkCanvas* canvas) override {
2724
2725 SkString text("Atwater Peel Sherbrooke Bonaventure\nhi\nwasssup!");
2726 canvas->drawColor(SK_ColorWHITE);
2727
2728 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
2729
2730 ParagraphStyle paragraph_style;
2731 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2732 TextStyle text_style;
2733 text_style.setColor(SK_ColorBLACK);
2734 text_style.setFontFamilies({SkString("Ahem")});
2735 text_style.setFontSize(16);
2736 text_style.setHeight(4);
2737 text_style.setHeightOverride(true);
2738 builder.pushStyle(text_style);
2739 builder.addText(text.c_str());
2740 auto paragraph = builder.Build();
2741 paragraph->layout(width());
2742
2743 auto boxes = paragraph->getRectsForRange(0, 7, RectHeightStyle::kIncludeLineSpacingTop, RectWidthStyle::kMax);
2744 for (auto& box : boxes) {
2745 SkPaint paint;
2746 paint.setColor(SK_ColorGRAY);
2747 canvas->drawRect(box.rect, paint);
2748 }
2749
2750 auto boxes2 = paragraph->getRectsForRange(0, 7, RectHeightStyle::kTight, RectWidthStyle::kMax);
2751 for (auto& box : boxes2) {
2752 SkPaint paint;
2753 paint.setColor(SK_ColorRED);
2754 canvas->drawRect(box.rect, paint);
2755 }
2756
2757 paragraph->paint(canvas, 0, 0);
2758 }
2759
2760private:
2761 typedef Sample INHERITED;
2762};
Julia Lavrova68d14332020-05-11 13:47:08 -04002763
2764class ParagraphView43 : public ParagraphView_Base {
2765protected:
2766 SkString name() override { return SkString("Paragraph43"); }
2767
2768 void onDrawContent(SkCanvas* canvas) override {
2769
2770 SkString text("World domination is such an ugly phrase - I prefer to call it world optimisation");
2771 canvas->drawColor(SK_ColorWHITE);
2772
2773 auto fontCollection = sk_make_sp<FontCollection>();
2774 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2775 fontCollection->enableFontFallback();
2776
2777 ParagraphStyle paragraph_style;
2778 paragraph_style.setTextAlign(TextAlign::kJustify);
2779 paragraph_style.setEllipsis(u"\u2026");
2780 paragraph_style.setMaxLines(2);
2781 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2782 TextStyle text_style;
2783 text_style.setColor(SK_ColorBLACK);
2784 text_style.setFontFamilies({SkString("Roboto")});
2785 text_style.setFontSize(40);
2786 text_style.setHeightOverride(true);
2787 builder.pushStyle(text_style);
2788 builder.addText(text.c_str());
2789 auto paragraph = builder.Build();
2790 paragraph->layout(width() / 4);
2791 paragraph->paint(canvas, 0, 0);
2792 }
2793
2794private:
2795 typedef Sample INHERITED;
2796};
2797
Ben Wagner056d5432020-05-13 10:24:15 -04002798} // namespace
2799
Julia Lavrova2813d452020-03-03 11:43:40 -05002800//////////////////////////////////////////////////////////////////////////////
Julia Lavrovaa3552c52019-05-30 16:12:56 -04002801DEF_SAMPLE(return new ParagraphView1();)
2802DEF_SAMPLE(return new ParagraphView2();)
2803DEF_SAMPLE(return new ParagraphView3();)
2804DEF_SAMPLE(return new ParagraphView4();)
2805DEF_SAMPLE(return new ParagraphView5();)
2806DEF_SAMPLE(return new ParagraphView6();)
2807DEF_SAMPLE(return new ParagraphView7();)
2808DEF_SAMPLE(return new ParagraphView8();)
2809DEF_SAMPLE(return new ParagraphView9();)
2810DEF_SAMPLE(return new ParagraphView10();)
2811DEF_SAMPLE(return new ParagraphView11();)
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04002812DEF_SAMPLE(return new ParagraphView12();)
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04002813DEF_SAMPLE(return new ParagraphView14();)
2814DEF_SAMPLE(return new ParagraphView15();)
Julia Lavrova2e30fde2019-10-09 09:43:02 -04002815DEF_SAMPLE(return new ParagraphView16();)
2816DEF_SAMPLE(return new ParagraphView17();)
2817DEF_SAMPLE(return new ParagraphView18();)
Julia Lavrova18db52f2020-05-04 15:03:18 -04002818//DEF_SAMPLE(return new ParagraphView19();)
Julia Lavrovac028b422019-11-25 10:00:43 -05002819DEF_SAMPLE(return new ParagraphView20();)
Julia Lavrovac48687a2020-01-08 16:53:53 -05002820DEF_SAMPLE(return new ParagraphView21();)
Julia Lavrova4cf18742020-01-14 13:24:45 -05002821DEF_SAMPLE(return new ParagraphView22();)
Julia Lavrova51a813d2020-01-21 13:55:44 -05002822DEF_SAMPLE(return new ParagraphView23();)
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05002823DEF_SAMPLE(return new ParagraphView24();)
2824DEF_SAMPLE(return new ParagraphView25();)
Julia Lavrova212bf072020-02-18 12:05:55 -05002825DEF_SAMPLE(return new ParagraphView26();)
2826DEF_SAMPLE(return new ParagraphView27();)
2827DEF_SAMPLE(return new ParagraphView28();)
2828DEF_SAMPLE(return new ParagraphView29();)
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002829DEF_SAMPLE(return new ParagraphView30();)
2830DEF_SAMPLE(return new ParagraphView31();)
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002831DEF_SAMPLE(return new ParagraphView32();)
2832DEF_SAMPLE(return new ParagraphView33();)
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002833DEF_SAMPLE(return new ParagraphView34();)
Julia Lavrova3c79a232020-03-02 09:58:52 -05002834DEF_SAMPLE(return new ParagraphView35();)
Julia Lavrova2813d452020-03-03 11:43:40 -05002835DEF_SAMPLE(return new ParagraphView36();)
Julia Lavrova99ede422020-03-17 13:20:58 -04002836DEF_SAMPLE(return new ParagraphView37();)
Julia Lavrova18db52f2020-05-04 15:03:18 -04002837DEF_SAMPLE(return new ParagraphView38();)
Julia Lavrova6bdbd3d2020-05-06 12:03:17 -04002838DEF_SAMPLE(return new ParagraphView39();)
Julia Lavrovadd1de252020-05-08 11:53:19 -04002839DEF_SAMPLE(return new ParagraphView41();)
2840DEF_SAMPLE(return new ParagraphView42();)
Julia Lavrova68d14332020-05-11 13:47:08 -04002841DEF_SAMPLE(return new ParagraphView43();)