blob: d693f2b98444d7c39bebc01d3e8ccea5aacc0e9a [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"
Ben Wagnerb985b4b2020-05-28 15:59:42 -040020#include "modules/skparagraph/src/ParagraphUtil.h"
Ben Wagner4ca7a812020-05-28 13:48:18 -040021#include "modules/skparagraph/src/TextLine.h"
Julia Lavrova9af5cc42019-06-19 13:32:01 -040022#include "modules/skparagraph/utils/TestFontCollection.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040023#include "samplecode/Sample.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040024#include "src/core/SkOSFile.h"
25#include "src/shaders/SkColorShader.h"
Julia Lavrova2e30fde2019-10-09 09:43:02 -040026#include "src/utils/SkOSPath.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040027#include "src/utils/SkUTF.h"
28#include "tools/Resources.h"
Ben Wagner056d5432020-05-13 10:24:15 -040029#include "tools/flags/CommandLineFlags.h"
30
31
32static DEFINE_bool(verboseParagraph, false, "paragraph samples very verbose.");
Julia Lavrovaa3552c52019-05-30 16:12:56 -040033
34using namespace skia::textlayout;
35namespace {
36
Mike Reed21a940d2019-07-23 10:11:03 -040037class ParagraphView_Base : public Sample {
38protected:
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -040039 sk_sp<TestFontCollection> getFontCollection() {
40 // If we reset font collection we need to reset paragraph cache
41 static sk_sp<TestFontCollection> fFC = nullptr;
42 if (fFC == nullptr) {
Julia Lavrova2e30fde2019-10-09 09:43:02 -040043 fFC = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -040044 }
45 return fFC;
Mike Reed21a940d2019-07-23 10:11:03 -040046 }
Ben Wagner056d5432020-05-13 10:24:15 -040047
48 bool isVerbose() {
49 return FLAGS_verboseParagraph;
50 }
Mike Reed21a940d2019-07-23 10:11:03 -040051};
52
Julia Lavrovaa3552c52019-05-30 16:12:56 -040053sk_sp<SkShader> setgrad(const SkRect& r, SkColor c0, SkColor c1) {
54 SkColor colors[] = {c0, c1};
55 SkPoint pts[] = {{r.fLeft, r.fTop}, {r.fRight, r.fTop}};
56 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
57}
Julia Lavrova2e30fde2019-10-09 09:43:02 -040058/*
59void writeHtml(const char* name, Paragraph* paragraph) {
60 SkString tmpDir = skiatest::GetTmpDir();
61 if (!tmpDir.isEmpty()) {
62 SkString path = SkOSPath::Join(tmpDir.c_str(), name);
63 SkFILEWStream file(path.c_str());
64 file.write(nullptr, 0);
65 }
66}
67*/
Julia Lavrovaa3552c52019-05-30 16:12:56 -040068
Mike Reed21a940d2019-07-23 10:11:03 -040069class ParagraphView1 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -040070protected:
Hal Canary8a027312019-07-03 10:55:44 -040071 SkString name() override { return SkString("Paragraph1"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040072
73 void drawTest(SkCanvas* canvas, SkScalar w, SkScalar h, SkColor fg, SkColor bg) {
74 const std::vector<
75 std::tuple<std::string, bool, bool, int, SkColor, SkColor, bool, TextDecorationStyle>>
76 gParagraph = {{"monospace", true, false, 14, SK_ColorWHITE, SK_ColorRED, true,
77 TextDecorationStyle::kDashed},
78 {"Assyrian", false, false, 20, SK_ColorWHITE, SK_ColorBLUE, false,
79 TextDecorationStyle::kDotted},
80 {"serif", true, true, 10, SK_ColorWHITE, SK_ColorRED, true,
81 TextDecorationStyle::kDouble},
82 {"Arial", false, true, 16, SK_ColorGRAY, SK_ColorGREEN, true,
83 TextDecorationStyle::kSolid},
84 {"sans-serif", false, false, 8, SK_ColorWHITE, SK_ColorRED, false,
85 TextDecorationStyle::kWavy}};
86 SkAutoCanvasRestore acr(canvas, true);
87
88 canvas->clipRect(SkRect::MakeWH(w, h));
89 canvas->drawColor(SK_ColorWHITE);
90
91 SkScalar margin = 20;
92
93 SkPaint paint;
94 paint.setAntiAlias(true);
95 paint.setColor(fg);
96
97 SkPaint blue;
98 blue.setColor(SK_ColorBLUE);
99
100 TextStyle defaultStyle;
101 defaultStyle.setBackgroundColor(blue);
102 defaultStyle.setForegroundColor(paint);
103 ParagraphStyle paraStyle;
104
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400105 auto fontCollection = sk_make_sp<FontCollection>();
106 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400107 for (auto i = 1; i < 5; ++i) {
108 defaultStyle.setFontSize(24 * i);
109 paraStyle.setTextStyle(defaultStyle);
Julia Lavrova5207f352019-06-21 12:22:32 -0400110 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400111 std::string name = "Paragraph: " + std::to_string(24 * i);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400112 builder.addText(name.c_str(), name.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400113 for (auto para : gParagraph) {
114 TextStyle style;
115 style.setFontFamilies({SkString(std::get<0>(para).c_str())});
116 SkFontStyle fontStyle(std::get<1>(para) ? SkFontStyle::Weight::kBold_Weight
117 : SkFontStyle::Weight::kNormal_Weight,
118 SkFontStyle::Width::kNormal_Width,
119 std::get<2>(para) ? SkFontStyle::Slant::kItalic_Slant
120 : SkFontStyle::Slant::kUpright_Slant);
121 style.setFontStyle(fontStyle);
122 style.setFontSize(std::get<3>(para) * i);
123 SkPaint background;
124 background.setColor(std::get<4>(para));
125 style.setBackgroundColor(background);
126 SkPaint foreground;
127 foreground.setColor(std::get<5>(para));
128 foreground.setAntiAlias(true);
129 style.setForegroundColor(foreground);
130 if (std::get<6>(para)) {
131 style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(5, 5), 2));
132 }
133
134 auto decoration = (i % 4);
135 if (decoration == 3) {
136 decoration = 4;
137 }
138
139 bool test = (TextDecoration)decoration != TextDecoration::kNoDecoration;
140 std::string deco = std::to_string((int)decoration);
141 if (test) {
142 style.setDecoration((TextDecoration)decoration);
143 style.setDecorationStyle(std::get<7>(para));
144 style.setDecorationColor(std::get<5>(para));
145 }
146 builder.pushStyle(style);
147 std::string name = " " + std::get<0>(para) + " " +
148 (std::get<1>(para) ? ", bold" : "") +
149 (std::get<2>(para) ? ", italic" : "") + " " +
150 std::to_string(std::get<3>(para) * i) +
151 (std::get<4>(para) != bg ? ", background" : "") +
152 (std::get<5>(para) != fg ? ", foreground" : "") +
153 (std::get<6>(para) ? ", shadow" : "") +
154 (test ? ", decorations " + deco : "") + ";";
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400155 builder.addText(name.c_str(), name.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400156 builder.pop();
157 }
158
159 auto paragraph = builder.Build();
160 paragraph->layout(w - margin * 2);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400161 paragraph->paint(canvas, margin, margin);
162
163 canvas->translate(0, paragraph->getHeight());
164 }
165 }
166
167 void onDrawContent(SkCanvas* canvas) override {
168 drawTest(canvas, this->width(), this->height(), SK_ColorRED, SK_ColorWHITE);
169 }
170
171private:
172
173 typedef Sample INHERITED;
174};
175
Mike Reed21a940d2019-07-23 10:11:03 -0400176class ParagraphView2 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400177protected:
Hal Canary8a027312019-07-03 10:55:44 -0400178 SkString name() override { return SkString("Paragraph2"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400179
180 void drawCode(SkCanvas* canvas, SkScalar w, SkScalar h) {
181 SkPaint comment;
182 comment.setColor(SK_ColorGRAY);
183 SkPaint constant;
184 constant.setColor(SK_ColorMAGENTA);
185 SkPaint null;
186 null.setColor(SK_ColorMAGENTA);
187 SkPaint literal;
188 literal.setColor(SK_ColorGREEN);
189 SkPaint code;
190 code.setColor(SK_ColorDKGRAY);
191 SkPaint number;
192 number.setColor(SK_ColorBLUE);
193 SkPaint name;
194 name.setColor(SK_ColorRED);
195
196 SkPaint white;
197 white.setColor(SK_ColorWHITE);
198
199 TextStyle defaultStyle;
200 defaultStyle.setBackgroundColor(white);
201 defaultStyle.setForegroundColor(code);
202 defaultStyle.setFontFamilies({SkString("monospace")});
203 defaultStyle.setFontSize(30);
204 ParagraphStyle paraStyle;
205 paraStyle.setTextStyle(defaultStyle);
206
Julia Lavrova5207f352019-06-21 12:22:32 -0400207 auto fontCollection = sk_make_sp<FontCollection>();
208 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
209 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400210
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400211 const char* text1 = "RaisedButton";
212 const char* text2 = "(\n";
213 const char* text3 = " child: ";
214 const char* text4 = "const";
215 const char* text5 = "Text";
216 const char* text6 = "'BUTTON TITLE'";
217 const char* text7 = "),\n";
218
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400219 builder.pushStyle(style(name));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400220 builder.addText(text1, strlen(text1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400221 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400222 builder.addText(text2, strlen(text2));
223 builder.addText(text3, strlen(text3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400224 builder.pushStyle(style(constant));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400225 builder.addText(text4, strlen(text4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400226 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400227 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400228 builder.pushStyle(style(name));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400229 builder.addText(text5, strlen(text5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400230 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400231 builder.addText("(", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400232 builder.pushStyle(style(literal));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400233 builder.addText(text6, strlen(text6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400234 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400235 builder.addText(text7, strlen(text7));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400236
237 auto paragraph = builder.Build();
238 paragraph->layout(w - 20);
239
240 paragraph->paint(canvas, 20, 20);
241 }
242
243 TextStyle style(SkPaint paint) {
244 TextStyle style;
245 paint.setAntiAlias(true);
246 style.setForegroundColor(paint);
247 style.setFontFamilies({SkString("monospace")});
248 style.setFontSize(30);
249
250 return style;
251 }
252
Julia Lavrova5207f352019-06-21 12:22:32 -0400253 void drawText(SkCanvas* canvas, SkScalar w, SkScalar h, std::vector<const char*>& text,
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400254 SkColor fg = SK_ColorDKGRAY, SkColor bg = SK_ColorWHITE,
255 const char* ff = "sans-serif", SkScalar fs = 24,
256 size_t lineLimit = 30,
257 const std::u16string& ellipsis = u"\u2026") {
258 SkAutoCanvasRestore acr(canvas, true);
259
260 canvas->clipRect(SkRect::MakeWH(w, h));
261 canvas->drawColor(bg);
262
263 SkScalar margin = 20;
264
265 SkPaint paint;
266 paint.setAntiAlias(true);
267 paint.setColor(fg);
268
269 SkPaint blue;
270 blue.setColor(SK_ColorBLUE);
271
272 SkPaint background;
273 background.setColor(bg);
274
275 TextStyle style;
276 style.setBackgroundColor(blue);
277 style.setForegroundColor(paint);
278 style.setFontFamilies({SkString(ff)});
279 style.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight,
280 SkFontStyle::kNormal_Width,
281 SkFontStyle::kUpright_Slant));
282 style.setFontSize(fs);
283 ParagraphStyle paraStyle;
284 paraStyle.setTextStyle(style);
285 paraStyle.setMaxLines(lineLimit);
286
287 paraStyle.setEllipsis(ellipsis);
288 TextStyle defaultStyle;
289 defaultStyle.setFontSize(20);
290 paraStyle.setTextStyle(defaultStyle);
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400291 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400292
293 SkPaint foreground;
294 foreground.setColor(fg);
295 style.setForegroundColor(foreground);
296 style.setBackgroundColor(background);
297
298 for (auto& part : text) {
299 builder.pushStyle(style);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400300 builder.addText(part, strlen(part));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400301 builder.pop();
302 }
303
304 auto paragraph = builder.Build();
305 paragraph->layout(w - margin * 2);
306 paragraph->paint(canvas, margin, margin);
307
308 canvas->translate(0, paragraph->getHeight() + margin);
309 }
310
311 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
312 TextAlign align) {
313 SkAutoCanvasRestore acr(canvas, true);
314
315 canvas->clipRect(SkRect::MakeWH(w, h));
316 canvas->drawColor(SK_ColorWHITE);
317
318 SkScalar margin = 20;
319
320 SkPaint paint;
321 paint.setAntiAlias(true);
322 paint.setColor(SK_ColorBLUE);
323
324 SkPaint gray;
325 gray.setColor(SK_ColorLTGRAY);
326
327 TextStyle style;
328 style.setBackgroundColor(gray);
329 style.setForegroundColor(paint);
330 style.setFontFamilies({SkString("Arial")});
331 style.setFontSize(30);
332 ParagraphStyle paraStyle;
333 paraStyle.setTextStyle(style);
334 paraStyle.setTextAlign(align);
335
Julia Lavrova5207f352019-06-21 12:22:32 -0400336 auto fontCollection = sk_make_sp<FontCollection>();
337 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
338 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400339 builder.addText(text.c_str(), text.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400340
341 auto paragraph = builder.Build();
342 paragraph->layout(w - margin * 2);
343 paragraph->layout(w - margin);
344 paragraph->paint(canvas, margin, margin);
345
346 canvas->translate(0, paragraph->getHeight() + margin);
347 }
348
349 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrova5207f352019-06-21 12:22:32 -0400350 std::vector<const char*> cupertino = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400351 "google_logogoogle_gsuper_g_logo 1 "
352 "google_logogoogle_gsuper_g_logo 12 "
353 "google_logogoogle_gsuper_g_logo 123 "
354 "google_logogoogle_gsuper_g_logo 1234 "
355 "google_logogoogle_gsuper_g_logo 12345 "
356 "google_logogoogle_gsuper_g_logo 123456 "
357 "google_logogoogle_gsuper_g_logo 1234567 "
358 "google_logogoogle_gsuper_g_logo 12345678 "
359 "google_logogoogle_gsuper_g_logo 123456789 "
360 "google_logogoogle_gsuper_g_logo 1234567890 "
361 "google_logogoogle_gsuper_g_logo 123456789 "
362 "google_logogoogle_gsuper_g_logo 12345678 "
363 "google_logogoogle_gsuper_g_logo 1234567 "
364 "google_logogoogle_gsuper_g_logo 123456 "
365 "google_logogoogle_gsuper_g_logo 12345 "
366 "google_logogoogle_gsuper_g_logo 1234 "
367 "google_logogoogle_gsuper_g_logo 123 "
368 "google_logogoogle_gsuper_g_logo 12 "
369 "google_logogoogle_gsuper_g_logo 1 "
370 "google_logogoogle_gsuper_g_logo "
371 "google_logogoogle_gsuper_g_logo "
372 "google_logogoogle_gsuper_g_logo "
373 "google_logogoogle_gsuper_g_logo "
374 "google_logogoogle_gsuper_g_logo "
375 "google_logogoogle_gsuper_g_logo"};
Julia Lavrova5207f352019-06-21 12:22:32 -0400376 std::vector<const char*> text = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400377 "My neighbor came over to say,\n"
378 "Although not in a neighborly way,\n\n"
379 "That he'd knock me around,\n\n\n"
380 "If I didn't stop the sound,\n\n\n\n"
381 "Of the classical music I play."};
382
Julia Lavrova5207f352019-06-21 12:22:32 -0400383 std::vector<const char*> long_word = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400384 "A_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
385 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
386 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
387 "very_very_very_very_very_very_very_long_text"};
388
Julia Lavrova5207f352019-06-21 12:22:32 -0400389 std::vector<const char*> very_long = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400390 "A very very very very very very very very very very very very very very very very "
391 "very very very very very very very very very very very very very very very very "
392 "very very very very very very very very very very very very very very very very "
393 "very very very very very very very long text"};
394
Julia Lavrova5207f352019-06-21 12:22:32 -0400395 std::vector<const char*> very_word = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400396 "A very_very_very_very_very_very_very_very_very_very "
397 "very_very_very_very_very_very_very_very_very_very very very very very very very "
398 "very very very very very very very very very very very very very very very very "
399 "very very very very very very very very very very very very very long text"};
400
401 SkScalar width = this->width() / 5;
402 SkScalar height = this->height();
403 drawText(canvas, width, height, long_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
404 canvas->translate(width, 0);
405 drawText(canvas, width, height, very_long, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
406 canvas->translate(width, 0);
407 drawText(canvas, width, height, very_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
408 canvas->translate(width, 0);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400409 drawText(canvas, width, height / 2, text, SK_ColorBLACK, SK_ColorWHITE, "Roboto", 20, 100,
410 u"\u2026");
411 canvas->translate(0, height / 2);
412 drawCode(canvas, width, height / 2);
413 canvas->translate(width, -height / 2);
414
415 drawText(canvas, width, height, cupertino, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
416 }
417
418private:
419 typedef Sample INHERITED;
420};
421
Mike Reed21a940d2019-07-23 10:11:03 -0400422class ParagraphView3 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400423protected:
Hal Canary8a027312019-07-03 10:55:44 -0400424 SkString name() override { return SkString("Paragraph3"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400425
426 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
427 TextAlign align, size_t lineLimit = std::numeric_limits<size_t>::max(),
428 bool RTL = false, SkColor background = SK_ColorGRAY,
429 const std::u16string& ellipsis = u"\u2026") {
430 SkAutoCanvasRestore acr(canvas, true);
431
432 canvas->clipRect(SkRect::MakeWH(w, h));
433 canvas->drawColor(SK_ColorWHITE);
434
435 SkScalar margin = 20;
436
437 SkPaint paint;
438 paint.setAntiAlias(true);
439 paint.setColor(SK_ColorBLACK);
440
441 SkPaint gray;
442 gray.setColor(background);
443
444 SkPaint yellow;
445 yellow.setColor(SK_ColorYELLOW);
446
447 TextStyle style;
448 style.setBackgroundColor(gray);
449 style.setForegroundColor(paint);
450 style.setFontFamilies({SkString("sans-serif")});
451 style.setFontSize(30);
452 ParagraphStyle paraStyle;
453 paraStyle.setTextStyle(style);
454 paraStyle.setTextAlign(align);
455 paraStyle.setMaxLines(lineLimit);
456 paraStyle.setEllipsis(ellipsis);
457 // paraStyle.setTextDirection(RTL ? SkTextDirection::rtl : SkTextDirection::ltr);
458
Julia Lavrova5207f352019-06-21 12:22:32 -0400459 auto fontCollection = sk_make_sp<FontCollection>();
460 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
461 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400462 if (RTL) {
463 builder.addText(mirror(text));
464 } else {
465 builder.addText(normal(text));
466 }
467
468 canvas->drawRect(SkRect::MakeXYWH(margin, margin, w - margin * 2, h - margin * 2), yellow);
469 auto paragraph = builder.Build();
470 paragraph->layout(w - margin * 2);
471 paragraph->paint(canvas, margin, margin);
472 }
473
474 std::u16string mirror(const std::string& text) {
475 std::u16string result;
476 result += u"\u202E";
477 // for (auto i = text.size(); i > 0; --i) {
478 // result += text[i - 1];
479 //}
480
481 for (auto i = text.size(); i > 0; --i) {
482 auto ch = text[i - 1];
483 if (ch == ',') {
484 result += u"!";
485 } else if (ch == '.') {
486 result += u"!";
487 } else {
488 result += ch;
489 }
490 }
491
492 result += u"\u202C";
493 return result;
494 }
495
496 std::u16string normal(const std::string& text) {
497 std::u16string result;
498 result += u"\u202D";
499 for (auto ch : text) {
500 result += ch;
501 }
502 result += u"\u202C";
503 return result;
504 }
505
506 void onDrawContent(SkCanvas* canvas) override {
507 const std::string options = // { "open-source open-source open-source open-source" };
508 {"Flutter is an open-source project to help developers "
509 "build high-performance, high-fidelity, mobile apps for "
510 "iOS and Android "
511 "from a single codebase. This design lab is a playground "
512 "and showcase of Flutter's many widgets, behaviors, "
513 "animations, layouts, and more."};
514
515 canvas->drawColor(SK_ColorDKGRAY);
516 SkScalar width = this->width() / 4;
517 SkScalar height = this->height() / 2;
518
519 const std::string line =
520 "World domination is such an ugly phrase - I prefer to call it world optimisation";
521
522 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, false, SK_ColorLTGRAY);
523 canvas->translate(width, 0);
524 drawLine(canvas, width, height, line, TextAlign::kRight, 2, false, SK_ColorLTGRAY);
525 canvas->translate(width, 0);
526 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, false, SK_ColorLTGRAY);
527 canvas->translate(width, 0);
528 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, false, SK_ColorLTGRAY);
529 canvas->translate(-width * 3, height);
530
531 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, true, SK_ColorLTGRAY);
532 canvas->translate(width, 0);
533 drawLine(canvas, width, height, line, TextAlign::kRight, 2, true, SK_ColorLTGRAY);
534 canvas->translate(width, 0);
535 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, true, SK_ColorLTGRAY);
536 canvas->translate(width, 0);
537 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, true, SK_ColorLTGRAY);
538 canvas->translate(width, 0);
539 }
540
541private:
542 typedef Sample INHERITED;
543};
544
Mike Reed21a940d2019-07-23 10:11:03 -0400545class ParagraphView4 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400546protected:
Hal Canary8a027312019-07-03 10:55:44 -0400547 SkString name() override { return SkString("Paragraph4"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400548
549 void drawFlutter(SkCanvas* canvas, SkScalar w, SkScalar h,
550 const char* ff = "Google Sans", SkScalar fs = 30,
551 size_t lineLimit = std::numeric_limits<size_t>::max(),
552 const std::u16string& ellipsis = u"\u2026") {
553 SkAutoCanvasRestore acr(canvas, true);
554
555 canvas->clipRect(SkRect::MakeWH(w, h));
556
557 SkScalar margin = 20;
558
559 SkPaint black;
560 black.setAntiAlias(true);
561 black.setColor(SK_ColorBLACK);
562
563 SkPaint blue;
564 blue.setAntiAlias(true);
565 blue.setColor(SK_ColorBLUE);
566
567 SkPaint red;
568 red.setAntiAlias(true);
569 red.setColor(SK_ColorRED);
570
571 SkPaint green;
572 green.setAntiAlias(true);
573 green.setColor(SK_ColorGREEN);
574
575 SkPaint gray;
576 gray.setColor(SK_ColorLTGRAY);
577
578 SkPaint yellow;
579 yellow.setColor(SK_ColorYELLOW);
580
581 SkPaint magenta;
582 magenta.setAntiAlias(true);
583 magenta.setColor(SK_ColorMAGENTA);
584
585 TextStyle style;
586 style.setFontFamilies({SkString(ff)});
587 style.setFontSize(fs);
588
589 TextStyle style0;
590 style0.setForegroundColor(black);
591 style0.setBackgroundColor(gray);
592 style0.setFontFamilies({SkString(ff)});
593 style0.setFontSize(fs);
594 style0.setDecoration(TextDecoration::kUnderline);
595 style0.setDecorationStyle(TextDecorationStyle::kDouble);
596 style0.setDecorationColor(SK_ColorBLACK);
597
598 TextStyle style1;
599 style1.setForegroundColor(blue);
600 style1.setBackgroundColor(yellow);
601 style1.setFontFamilies({SkString(ff)});
602 style1.setFontSize(fs);
603 style1.setDecoration(TextDecoration::kOverline);
604 style1.setDecorationStyle(TextDecorationStyle::kWavy);
605 style1.setDecorationColor(SK_ColorBLACK);
606
607 TextStyle style2;
608 style2.setForegroundColor(red);
609 style2.setFontFamilies({SkString(ff)});
610 style2.setFontSize(fs);
611
612 TextStyle style3;
613 style3.setForegroundColor(green);
614 style3.setFontFamilies({SkString(ff)});
615 style3.setFontSize(fs);
616
617 TextStyle style4;
618 style4.setForegroundColor(magenta);
619 style4.setFontFamilies({SkString(ff)});
620 style4.setFontSize(fs);
621
622 ParagraphStyle paraStyle;
623 paraStyle.setTextStyle(style);
624 paraStyle.setMaxLines(lineLimit);
625
626 paraStyle.setEllipsis(ellipsis);
627
628 const char* logo1 = "google_";
629 const char* logo2 = "logo";
630 const char* logo3 = "go";
631 const char* logo4 = "ogle_logo";
632 const char* logo5 = "google_lo";
633 const char* logo6 = "go";
634 {
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400635 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400636
637 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400638 builder.addText(logo1, strlen(logo1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400639 builder.pop();
640 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400641 builder.addText(logo2, strlen(logo2));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400642 builder.pop();
643
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400644 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400645
646 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400647 builder.addText(logo3, strlen(logo3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400648 builder.pop();
649 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400650 builder.addText(logo4, strlen(logo4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400651 builder.pop();
652
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400653 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400654
655 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400656 builder.addText(logo5, strlen(logo5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400657 builder.pop();
658 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400659 builder.addText(logo6, strlen(logo6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400660 builder.pop();
661
662 auto paragraph = builder.Build();
663 paragraph->layout(w - margin * 2);
664 paragraph->paint(canvas, margin, margin);
665 canvas->translate(0, h + margin);
666 }
667 }
668
669 void onDrawContent(SkCanvas* canvas) override {
670 canvas->drawColor(SK_ColorWHITE);
671 SkScalar width = this->width();
672 SkScalar height = this->height();
673
674 drawFlutter(canvas, width, height / 2);
675 }
676
677private:
678 typedef Sample INHERITED;
679};
680
Mike Reed21a940d2019-07-23 10:11:03 -0400681class ParagraphView5 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400682protected:
Julia Lavrova5207f352019-06-21 12:22:32 -0400683 SkString name() override { return SkString("Paragraph5"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400684
685 void bidi(SkCanvas* canvas, SkScalar w, SkScalar h, const std::u16string& text,
686 const std::u16string& expected, size_t lineLimit = std::numeric_limits<size_t>::max(),
687 const char* ff = "Roboto", SkScalar fs = 30,
688 const std::u16string& ellipsis = u"\u2026") {
689 SkAutoCanvasRestore acr(canvas, true);
690
691 canvas->clipRect(SkRect::MakeWH(w, h));
692
693 SkScalar margin = 20;
694
695 SkPaint black;
696 black.setColor(SK_ColorBLACK);
697 SkPaint gray;
698 gray.setColor(SK_ColorLTGRAY);
699
700 TextStyle style;
701 style.setForegroundColor(black);
702 style.setFontFamilies({SkString(ff)});
703 style.setFontSize(fs);
704
705 TextStyle style0;
706 style0.setForegroundColor(black);
707 style0.setFontFamilies({SkString(ff)});
708 style0.setFontSize(fs);
709 style0.setFontStyle(SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width,
710 SkFontStyle::kItalic_Slant));
711
712 TextStyle style1;
713 style1.setForegroundColor(gray);
714 style1.setFontFamilies({SkString(ff)});
715 style1.setFontSize(fs);
716 style1.setFontStyle(SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width,
717 SkFontStyle::kUpright_Slant));
718
719 ParagraphStyle paraStyle;
720 paraStyle.setTextStyle(style);
721 paraStyle.setMaxLines(lineLimit);
722
723 paraStyle.setEllipsis(ellipsis);
724
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400725 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400726
727 if (text.empty()) {
728 const std::u16string text0 = u"\u202Dabc";
729 const std::u16string text1 = u"\u202EFED";
730 const std::u16string text2 = u"\u202Dghi";
731 const std::u16string text3 = u"\u202ELKJ";
732 const std::u16string text4 = u"\u202Dmno";
733 builder.pushStyle(style0);
734 builder.addText(text0);
735 builder.pop();
736 builder.pushStyle(style1);
737 builder.addText(text1);
738 builder.pop();
739 builder.pushStyle(style0);
740 builder.addText(text2);
741 builder.pop();
742 builder.pushStyle(style1);
743 builder.addText(text3);
744 builder.pop();
745 builder.pushStyle(style0);
746 builder.addText(text4);
747 builder.pop();
748 } else {
Ben Wagner056d5432020-05-13 10:24:15 -0400749 if (this->isVerbose()) {
Ben Wagnerb985b4b2020-05-28 15:59:42 -0400750 SkString str = SkStringFromU16String(text);
Ben Wagner056d5432020-05-13 10:24:15 -0400751 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);
Julia Lavrovac48caaa2020-05-26 15:21:39 -04001359 if (!result.empty()) {
1360 canvas->drawRect(result.front().rect, paint);
1361 }
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001362 }
1363
1364private:
1365 typedef Sample INHERITED;
1366};
1367
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001368class ParagraphView14 : public ParagraphView_Base {
1369protected:
1370 SkString name() override { return SkString("Paragraph14"); }
1371
1372 void onDrawContent(SkCanvas* canvas) override {
1373 canvas->drawColor(SK_ColorWHITE);
1374 TextStyle text_style;
1375 text_style.setFontFamilies({SkString("Ahem")});
1376 text_style.setColor(SK_ColorBLACK);
1377 text_style.setFontSize(25);
1378 text_style.setDecoration((TextDecoration)(TextDecoration::kUnderline | TextDecoration::kOverline | TextDecoration::kLineThrough));
1379 text_style.setDecorationColor(SK_ColorBLUE);
1380 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
1381 text_style.setDecorationThicknessMultiplier(4.0f);
1382 ParagraphStyle paragraph_style;
1383 paragraph_style.setTextStyle(text_style);
1384 paragraph_style.setTextDirection(TextDirection::kRtl);
1385 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1386 builder.pushStyle(text_style);
1387 builder.addText("Hello, wor!\nabcd.");
1388 auto paragraph = builder.Build();
1389 paragraph->layout(300);
1390 paragraph->paint(canvas, 0, 0);
1391 SkPaint paint;
1392 paint.setColor(SK_ColorRED);
1393 paint.setStyle(SkPaint::kStroke_Style);
1394 paint.setAntiAlias(true);
1395 paint.setStrokeWidth(1);
1396 canvas->drawRect(SkRect::MakeXYWH(0, 0, 300, 100), paint);
1397 }
1398
1399private:
1400 typedef Sample INHERITED;
1401};
1402
1403class ParagraphView15 : public ParagraphView_Base {
1404protected:
1405 SkString name() override { return SkString("Paragraph15"); }
1406
1407 void onDrawContent(SkCanvas* canvas) override {
1408 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001409
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001410 TextStyle text_style;
1411 text_style.setFontFamilies({SkString("abc.ttf")});
1412 text_style.setFontSize(50);
1413
1414 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false);
1415
1416 fontCollection->addFontFromFile("abc/abc.ttf", "abc");
1417 fontCollection->addFontFromFile("abc/abc+grave.ttf", "abc+grave");
1418 fontCollection->addFontFromFile("abc/abc+agrave.ttf", "abc+agrave");
1419
1420 ParagraphStyle paragraph_style;
1421 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1422
1423 text_style.setFontFamilies({SkString("abc"), SkString("abc+grave")});
1424 text_style.setColor(SK_ColorBLUE);
1425 builder.pushStyle(text_style);
1426 builder.addText(u"a\u0300");
1427 text_style.setColor(SK_ColorMAGENTA);
1428 builder.pushStyle(text_style);
1429 builder.addText(u"à");
1430
1431 text_style.setFontFamilies({SkString("abc"), SkString("abc+agrave")});
1432
1433 text_style.setColor(SK_ColorRED);
1434 builder.pushStyle(text_style);
1435 builder.addText(u"a\u0300");
1436 text_style.setColor(SK_ColorGREEN);
1437 builder.pushStyle(text_style);
1438 builder.addText(u"à");
1439
1440 auto paragraph = builder.Build();
1441 paragraph->layout(800);
1442 paragraph->paint(canvas, 50, 50);
1443
Julia Lavrova5207f352019-06-21 12:22:32 -04001444 }
1445
1446private:
1447 typedef Sample INHERITED;
1448};
1449
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001450class ParagraphView16 : public ParagraphView_Base {
1451protected:
1452 SkString name() override { return SkString("Paragraph16"); }
1453
1454 void onDrawContent(SkCanvas* canvas) override {
1455 canvas->drawColor(SK_ColorWHITE);
1456
1457 const char* text = "content";
1458
1459 ParagraphStyle paragraph_style;
1460 paragraph_style.setMaxLines(1);
1461 paragraph_style.setEllipsis(u"\u2026");
1462 //auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1463 auto fontCollection = sk_make_sp<FontCollection>();
1464 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1465 fontCollection->enableFontFallback();
1466 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1467
1468 TextStyle text_style;
1469 text_style.setFontFamilies({SkString(".SF Pro Text")});
1470 text_style.setColor(SK_ColorBLACK);
1471 text_style.setFontSize(17.0f * 99.0f);
1472 text_style.setLetterSpacing(0.41f);
1473 builder.pushStyle(text_style);
1474 builder.addText(text);
1475
1476 auto paragraph = builder.Build();
1477 paragraph->layout(800);
1478 paragraph->paint(canvas, 0, 0);
1479 }
1480
1481private:
1482 typedef Sample INHERITED;
1483};
1484
1485class ParagraphView17 : public ParagraphView_Base {
1486protected:
1487 SkString name() override { return SkString("Paragraph17"); }
1488
1489 void onDrawContent(SkCanvas* canvas) override {
1490 canvas->drawColor(SK_ColorWHITE);
1491
1492 auto fontCollection = sk_make_sp<FontCollection>();
1493 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1494 fontCollection->enableFontFallback();
1495 auto navy = SkColorSetRGB(0, 0, 139);
1496 auto ltgray = SkColorSetRGB(211, 211, 211);
1497 auto multiplier = 5.67;
1498
Julia Lavrovac48caaa2020-05-26 15:21:39 -04001499 //const char* text = ">Sͬ͑̀͐̈͒̈́̋̎ͮͩ̽̓ͬ̂̆̔͗́̓ͣͧ͊ͫ͛̉͌̐̑ͪ͗̚͝҉̴͉͢k̡̊̓ͫͭͩ͂͊ͨͪͬ̑ͫ̍̌̄͛̌̂̑̂̋̊̔ͫ͛̽̑ͨ̍ͭ̓̀ͪͪ̉͐͗̌̓̃̚͟͝҉̢͏̫̞̙͇͖̮͕̗̟͕͇͚̻͈̣̻̪͉̰̲̣̫ͅͅP̴̅̍͒̿͗͗̇ͩ̃͆͌̀̽͏̧̡͕͖̝̖̼̺̰̣̬͔͖͔̼͙̞̦̫͓̘͜a̸̴̸̴̢̢̨̨̫͍͓̥̼̭̼̻̤̯̙̤̻̠͚̍̌͋̂ͦͨ̽̇͌͌͆̀̽̎͒̄ͪ̐ͦ̈ͫ͐͗̓̚̚͜ͅr͐͐ͤͫ̐ͥ͂̈́̿́ͮ̃͗̓̏ͫ̀̿͏̸̵̧́͘̕͟͝͠͞͠҉̷̧͚͢͟a̓̽̎̄͗̔͛̄̐͊͛ͫ͂͌̂̂̈̈̓̔̅̅̄͊̉́ͪ̑̄͆ͬ̍͆ͭ͋̐ͬ͏̷̵̨̢̩̹̖͓̥̳̰͔̱̬͖̙͓̙͇̀̀̕͜͟͟͢͟͜͠͡g̨̅̇ͦ͋̂ͦͨͭ̓͐͆̏̂͛̉ͧ̑ͫ̐̒͛ͫ̍̒͛́̚҉̷̨̛̛̀͜͢͞҉̩̘̲͍͎̯̹̝̭̗̱͇͉̲̱͔̯̠̹̥̻͉̲̜̤̰̪̗̺̖̺r̷͌̓̇̅ͭ̀̐̃̃ͭ͑͗̉̈̇̈́ͥ̓ͣ́ͤ͂ͤ͂̏͌̆̚҉̴̸̧̢̢̛̫͉̦̥̤̙͈͉͈͉͓̙̗̟̳̜͈̗̺̟̠̠͖͓̖̪͕̠̕̕͝ͅả̸̴̡̡̧͠͞͡͞҉̛̕͟͏̷̘̪̱͈̲͉̞̠̞̪̫͎̲̬̖̀̀͟͝͞͞͠p̛͂̈͐̚͠҉̵̸̡̢̢̩̹͙̯͖̙̙̮̥̙͚̠͔̥̭̮̞̣̪̬̥̠̖̝̥̪͎́̀̕͜͡͡ͅͅh̵̷̵̡̛ͤ̂͌̐̓̐̋̋͊̒̆̽́̀̀̀͢͠͞͞҉̷̸̢̕҉͚̯͖̫̜̞̟̠̱͉̝̲̹̼͉̟͉̩̮͔̤͖̞̭̙̹̬ͅ<";
1500 const char* text = ">S͛ͭ̋͆̈̔̇͗̍͑̎ͪͮͧͣ̽ͫͣ́ͬ̀͌͑͂͗͒̍̔̄ͧ̏̉̌̊̊̿̀̌̃̄͐̓̓̚̚҉̵̡͜͟͝͠͏̸̵̡̧͜҉̷̡͇̜̘̻̺̘̟̝͙̬̘̩͇̭̼̥̖̤̦͎k͉̩̘͚̜̹̗̗͍̤̥̱͉̳͕͖̤̲̣͚̮̞̬̲͍͔̯̻̮̞̭͈̗̫͓̂ͨ̉ͪ̒͋͛̀̍͊ͧ̿̅͆̓̔̔ͬ̇̑̿ͩ͗ͮ̎͌̿̄ͅP̴̵̡̡̛̪͙̼̣̟̩̭̫̱͙̬͔͉͍̘̠͉̦̝̘̥̟̗͖̫̤͕̙̬̦͍̱̖̮̱͑͐̎̃̒͐͋̚͘͞a̶̶̵̵̵̶̶̡̧̢̢̺͔̣͖̭̺͍̤͚̱̜̰̥͕̬̥̲̞̥̘͇͚̺̰͚̪̺͔̤͍̓̿͆̎͋̓ͦ̈́ͦ̌́̄͗̌̓͌̕͜͜͟͢͝͡ŕ͎̝͕͉̻͎̤̭͚̗̳̖̙̘͚̫͖͓͚͉͔͈̟̰̟̬̗͓̟͚̱̕͡ͅͅͅa̸̶̢̛̛̽ͮͩ̅͒ͫ͗͂̎ͦ̈́̓̚͘͜͢͡҉̷̵̶̢̡̜̮̦̜̥̜̯̙͓͔̼̗̻͜͜ͅḡ̢̛͕̗͖̖̤̦̘͔ͨͨ̊͒ͩͭͤ̍̅̃ͪ̋̏̓̍̋͗̋ͨ̏̽̈́̔̀̋̉ͫ̅̂ͭͫ̏͒͋ͥ̚͜r̶̢̧̧̥̤̼̀̂̒ͪ͌̿͌̅͛ͨͪ͒̍ͥ̉ͤ̌̿̆́ͭ͆̃̒ͤ͛̊ͧ̽͘͝͠a̧̢̧̢͑͑̓͑ͮ̃͂̄͛́̈́͋̂͌̽̄͒̔́̇ͨͧͭ͐ͦ̋ͨ̍ͦ̍̋͆̔ͧ͑͋͌̈̓͛͛̚͢͜͜͏̴̢̧̛̳͍̹͚̰̹̻͔p̨̡͆ͦͣ͊̽̔͂̉ͣ̔ͣ̌̌̉̃̋̂͒ͫ̄̎̐͗̉̌̃̽̽́̀̚͘͜͟҉̱͉h̭̮̘̗͔̜̯͔͈̯̺͔̗̣̭͚̱̰̙̼̹͚̣̻̥̲̮͍̤͜͝<";
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001501 ParagraphStyle paragraph_style;
1502 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1503 SkPaint paint;
1504 paint.setColor(ltgray);
1505 TextStyle text_style;
1506 text_style.setBackgroundColor(paint);
1507 text_style.setColor(navy);
1508 text_style.setFontFamilies({SkString("Roboto")});
1509 text_style.setFontSize(20 * multiplier);
1510 builder.pushStyle(text_style);
1511 builder.addText(text);
1512 auto paragraph = builder.Build();
1513 paragraph->layout(10000);
1514 paragraph->paint(canvas, 0, 0);
1515 }
1516
1517private:
1518 typedef Sample INHERITED;
1519};
1520
1521class Zalgo {
1522 private:
1523 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";
1524 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";
1525 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";
1526
1527 std::u16string randomMarks(std::u16string& combiningMarks) {
1528 std::u16string result;
1529 auto num = std::rand() % (combiningMarks.size() / 1);
1530 for (size_t i = 0; i < num; ++i) {
1531 auto index = std::rand() % combiningMarks.size();
1532 result += combiningMarks[index];
1533 }
1534 return result;
1535 }
1536
1537public:
1538 std::u16string zalgo(std::string victim) {
1539 std::u16string result;
1540 for (auto& c : victim) {
1541 result += c;
1542 result += randomMarks(COMBINING_UP);
1543 result += randomMarks(COMBINING_MIDDLE);
1544 result += randomMarks(COMBINING_DOWN);
1545 }
1546 return result;
1547 }
1548};
1549
1550class ParagraphView18 : public ParagraphView_Base {
1551protected:
1552 SkString name() override { return SkString("Paragraph18"); }
1553
1554 bool onChar(SkUnichar uni) override {
1555 switch (uni) {
1556 case ' ':
1557 fLimit = 400;
1558 return true;
1559 case 's':
1560 fLimit += 10;
1561 return true;
1562 case 'f':
1563 if (fLimit > 10) {
1564 fLimit -= 10;
1565 }
1566 return true;
1567 default:
1568 break;
1569 }
1570 return false;
1571 }
1572
1573 bool onAnimate(double nanos) override {
1574 if (++fIndex > fLimit) {
1575 fRedraw = true;
1576 fIndex = 0;
1577 } else {
1578 fRepeat = true;
1579 }
1580 return true;
1581 }
1582
1583 void onDrawContent(SkCanvas* canvas) override {
1584 canvas->drawColor(SK_ColorWHITE);
1585
1586 auto navy = SkColorSetRGB(0, 0, 139);
1587 auto ltgray = SkColorSetRGB(211, 211, 211);
1588
1589 auto multiplier = 5.67;
1590 auto fontCollection = sk_make_sp<FontCollection>();
1591 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1592 fontCollection->enableFontFallback();
1593
1594 ParagraphStyle paragraph_style;
1595 TextStyle text_style;
1596 text_style.setFontFamilies({SkString("Roboto")});
1597 text_style.setFontSize(20 * multiplier);
1598 text_style.setColor(navy);
1599 SkPaint paint;
1600 paint.setColor(ltgray);
1601 text_style.setBackgroundColor(paint);
1602
1603 Zalgo zalgo;
1604
1605 if (fRedraw || fRepeat) {
1606
John Stilesa008b0f2020-08-16 08:48:02 -04001607 if (fRedraw || fParagraph == nullptr) {
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001608 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1609 builder.pushStyle(text_style);
1610 auto utf16text = zalgo.zalgo("SkParagraph");
Ben Wagner056d5432020-05-13 10:24:15 -04001611 if (this->isVerbose()) {
Ben Wagnerb985b4b2020-05-28 15:59:42 -04001612 SkString str = SkStringFromU16String(utf16text);
1613 SkDebugf("Text:>%s<\n", str.c_str());
Ben Wagner056d5432020-05-13 10:24:15 -04001614 }
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) {
Julia Lavrovac48caaa2020-05-26 15:21:39 -04001633 //SkDebugf("Run[%d] @pos=%d\n", run.index(), i);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001634 }
1635 }
1636 } else {
Julia Lavrovac48caaa2020-05-26 15:21:39 -04001637 //SkDebugf("Run[%d]: %s\n", run.index(), fontFamily.c_str());
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001638 }
1639 }
1640 fRedraw = false;
1641 fRepeat = false;
1642 }
1643 }
1644
1645private:
1646 bool fRedraw = true;
1647 bool fRepeat = false;
1648 size_t fIndex = 0;
1649 size_t fLimit = 20;
1650 std::unique_ptr<Paragraph> fParagraph;
1651 typedef Sample INHERITED;
1652};
1653
1654class ParagraphView19 : public ParagraphView_Base {
1655protected:
1656 SkString name() override { return SkString("Paragraph19"); }
1657
1658 void onDrawContent(SkCanvas* canvas) override {
1659 canvas->drawColor(SK_ColorWHITE);
1660
1661 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1662
Julia Lavrova90bfd1c2019-12-04 11:43:32 -05001663 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 -04001664 ParagraphStyle paragraph_style;
1665 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001666 TextStyle text_style;
Julia Lavrovac028b422019-11-25 10:00:43 -05001667 text_style.setColor(SK_ColorBLACK);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001668 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova90bfd1c2019-12-04 11:43:32 -05001669 text_style.setFontSize(20);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001670 builder.pushStyle(text_style);
1671 builder.addText(text);
1672 auto paragraph = builder.Build();
Julia Lavrovac028b422019-11-25 10:00:43 -05001673 paragraph->layout(this->width());
Julia Lavrovac028b422019-11-25 10:00:43 -05001674 paragraph->paint(canvas, 0, 0);
1675 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001676
Julia Lavrovac028b422019-11-25 10:00:43 -05001677private:
1678 typedef Sample INHERITED;
1679};
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001680
Julia Lavrovac028b422019-11-25 10:00:43 -05001681class ParagraphView20 : public ParagraphView_Base {
1682protected:
1683 SkString name() override { return SkString("Paragraph20"); }
1684
1685 void onDrawContent(SkCanvas* canvas) override {
1686 canvas->drawColor(SK_ColorWHITE);
1687
1688 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1689
Julia Lavrovac48687a2020-01-08 16:53:53 -05001690 const char* text = "Manage your google account";
Julia Lavrovac028b422019-11-25 10:00:43 -05001691 ParagraphStyle paragraph_style;
Julia Lavrovac48687a2020-01-08 16:53:53 -05001692 paragraph_style.setEllipsis(u"\u2026");
1693 paragraph_style.setMaxLines(1);
Julia Lavrovac028b422019-11-25 10:00:43 -05001694 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1695 TextStyle text_style;
1696 text_style.setColor(SK_ColorBLACK);
Julia Lavrova53c14472019-12-18 09:39:55 -05001697 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrovac48687a2020-01-08 16:53:53 -05001698 text_style.setFontSize(50);
Julia Lavrovac028b422019-11-25 10:00:43 -05001699 builder.pushStyle(text_style);
1700 builder.addText(text);
1701 auto paragraph = builder.Build();
Julia Lavrovac48687a2020-01-08 16:53:53 -05001702 paragraph->layout(this->width());
1703 paragraph->paint(canvas, 0, 0);
1704 }
1705
1706private:
1707 typedef Sample INHERITED;
1708};
1709
1710class ParagraphView21 : public ParagraphView_Base {
1711protected:
1712 SkString name() override { return SkString("Paragraph21"); }
1713
1714 void onDrawContent(SkCanvas* canvas) override {
1715 canvas->drawColor(SK_ColorWHITE);
1716
Julia Lavrova70e93012020-01-10 14:04:45 -05001717 const char* text = "Referral Code";
Julia Lavrovac48687a2020-01-08 16:53:53 -05001718 ParagraphStyle paragraph_style;
Julia Lavrovaf6a3f8e2020-01-10 10:55:52 -05001719 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
Julia Lavrovac48687a2020-01-08 16:53:53 -05001720 TextStyle text_style;
1721 text_style.setColor(SK_ColorBLACK);
Julia Lavrovaf6a3f8e2020-01-10 10:55:52 -05001722 text_style.setFontFamilies({SkString("Google Sans")});
1723 text_style.setFontSize(24);
Julia Lavrovac48687a2020-01-08 16:53:53 -05001724 builder.pushStyle(text_style);
1725 builder.addText(text);
1726 auto paragraph = builder.Build();
Julia Lavrova70e93012020-01-10 14:04:45 -05001727 paragraph->layout(0);
Julia Lavrovac028b422019-11-25 10:00:43 -05001728 paragraph->paint(canvas, 0, 0);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001729 }
1730
1731private:
1732 typedef Sample INHERITED;
1733};
Julia Lavrova4cf18742020-01-14 13:24:45 -05001734
1735class ParagraphView22 : public ParagraphView_Base {
1736protected:
1737 SkString name() override { return SkString("Paragraph22"); }
1738
Julia Lavrova9bd83512020-01-15 14:46:35 -05001739 bool onChar(SkUnichar uni) override {
1740 switch (uni) {
1741 case 'l':
1742 direction = true;
1743 return true;
1744 case 'r':
1745 direction = false;
1746 return true;
1747 default:
1748 break;
Julia Lavrova4cf18742020-01-14 13:24:45 -05001749 }
Julia Lavrova9bd83512020-01-15 14:46:35 -05001750 return false;
1751 }
1752
1753 void onDrawContent(SkCanvas* canvas) override {
1754
1755 canvas->drawColor(SK_ColorWHITE);
1756 ParagraphStyle paragraph_style;
1757 paragraph_style.setTextDirection(direction ? TextDirection::kLtr : TextDirection::kRtl);
1758 auto collection = getFontCollection();
1759 ParagraphBuilderImpl builder(paragraph_style, collection);
1760 collection->getParagraphCache()->reset();
1761 collection->getParagraphCache()->turnOn(false);
1762 TextStyle text_style;
1763 text_style.setColor(SK_ColorBLACK);
1764 text_style.setFontFamilies({SkString("Roboto")});
1765 text_style.setFontSize(12);
1766 builder.pushStyle(text_style);
1767 builder.addText("I have got a ");
1768 text_style.setFontStyle(SkFontStyle::Bold());
1769 builder.pushStyle(text_style);
1770 builder.addText("lovely bunch");
1771 text_style.setFontStyle(SkFontStyle::Normal());
1772 builder.pushStyle(text_style);
1773 builder.addText(" of coconuts.");
1774 auto paragraph = builder.Build();
1775 paragraph->layout(this->width());
1776 paragraph->paint(canvas, 0, 0);
1777 collection->getParagraphCache()->turnOn(true);
Julia Lavrova4cf18742020-01-14 13:24:45 -05001778 }
1779
1780private:
1781 typedef Sample INHERITED;
Julia Lavrova9bd83512020-01-15 14:46:35 -05001782 bool direction;
Julia Lavrova4cf18742020-01-14 13:24:45 -05001783};
Julia Lavrova9bd83512020-01-15 14:46:35 -05001784
Julia Lavrova51a813d2020-01-21 13:55:44 -05001785class ParagraphView23 : public ParagraphView_Base {
1786protected:
1787 SkString name() override { return SkString("Paragraph23"); }
1788
1789 void onDrawContent(SkCanvas* canvas) override {
1790 canvas->drawColor(SK_ColorWHITE);
1791
1792 const char* text = "Text with shadow";
1793 ParagraphStyle paragraph_style;
1794 TextStyle text_style;
1795 text_style.setColor(SK_ColorBLACK);
1796 text_style.setFontFamilies({SkString("Google Sans")});
1797 text_style.setFontSize(24);
1798
1799 auto draw = [&](SkScalar h, SkScalar v, SkScalar b) {
1800 text_style.resetShadows();
1801 text_style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(h, v), b));
1802 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1803 builder.pushStyle(text_style);
1804 builder.addText(text);
1805 auto paragraph = builder.Build();
1806 paragraph->layout(300);
1807 paragraph->paint(canvas, 0, 0);
1808
1809 auto rect = SkRect::MakeXYWH(0, 0, paragraph->getMaxWidth(), paragraph->getHeight());
1810 SkPaint paint;
1811 paint.setColor(SK_ColorRED);
1812 paint.setStyle(SkPaint::kStroke_Style);
1813 paint.setAntiAlias(true);
1814 paint.setStrokeWidth(1);
1815 canvas->drawRect(rect, paint);
1816 };
1817
1818 draw(10, 10, 5);
1819 canvas->translate(0, 100);
1820
1821 draw(10, -10, 5);
1822 canvas->translate(0, 100);
1823
1824 draw(-10, -10, 5);
1825 canvas->translate(0, 100);
1826
1827 draw(-10, 10, 5);
1828 canvas->translate(0, 100);
1829 }
1830
1831private:
1832 typedef Sample INHERITED;
1833};
1834
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001835class ParagraphView24 : public ParagraphView_Base {
1836protected:
1837 SkString name() override { return SkString("Paragraph24"); }
1838
1839 void onDrawContent(SkCanvas* canvas) override {
1840 canvas->drawColor(SK_ColorWHITE);
1841
1842 ParagraphStyle paragraph_style;
1843 paragraph_style.setTextDirection(TextDirection::kRtl);
1844 TextStyle text_style;
1845 text_style.setColor(SK_ColorBLACK);
1846 text_style.setFontFamilies({SkString("Google Sans")});
1847 text_style.setFontSize(24);
1848 {
1849 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1850 builder.pushStyle(text_style);
1851 builder.addText("Right_to_left:");
1852 auto paragraph = builder.Build();
1853 paragraph->layout(this->width());
1854 paragraph->paint(canvas, 0, 0);
1855 }
1856 canvas->translate(0, 200);
1857 {
1858 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1859 builder.pushStyle(text_style);
1860 builder.addText("Right_to_left+");
1861 auto paragraph = builder.Build();
1862 paragraph->layout(this->width());
1863 paragraph->paint(canvas, 0, 0);
1864 }
1865 canvas->translate(0, 200);
1866 {
1867 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1868 builder.pushStyle(text_style);
1869 builder.addText("Right_to_left.");
1870 auto paragraph = builder.Build();
1871 paragraph->layout(this->width());
1872 paragraph->paint(canvas, 0, 0);
1873 }
1874 }
1875
1876private:
1877 typedef Sample INHERITED;
1878};
1879
1880class ParagraphView25 : public ParagraphView_Base {
1881protected:
1882 SkString name() override { return SkString("Paragraph25"); }
1883
1884 void onDrawContent(SkCanvas* canvas) override {
1885 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovac0360582020-02-05 10:17:53 -05001886/*
1887 * Shell: ParagraphStyle: 1.000000 1
1888Shell: Strut enabled: 0 1.000000 14.000000 400 5 0
1889Shell: Font Families: 0
1890Shell: DefaultTextStyle: 16.000000 500 5 0
1891Shell: Font Families: 1 Roboto
1892Shell: Font Features: 0
1893Shell: TextStyle#0: [0:22) 16.000000 500 5 0
1894Shell: Font Families: 1 Roboto
1895Shell: Font Features: 0
1896Shell: TextStyle#1: [25:49) 16.000000 500 5 0
1897Shell: Font Families: 1 Roboto
1898Shell: Font Features: 0
1899Shell: Placeholder#0: [22:25) 32.000000 32.000000 32.000000 0 5
1900Shell: Placeholder#1: [49:52) 19.000000 41.000000 19.000000 0 4
1901Shell: Placeholder#2: [52:52) 0.000000 0.000000 0.000000 0 5
1902Shell: layout('Go to device settings  and set up a passcode. ', 280.000000): 280.000000 * 38.000000
1903 */
1904 auto fontCollection = getFontCollection();
1905 //fontCollection->getParagraphCache()->turnOn(false);
1906 const char* text1 = "Go to device settings ";
1907 const char* text2 = "and set up a passcode.";
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001908 ParagraphStyle paragraph_style;
Julia Lavrovac0360582020-02-05 10:17:53 -05001909 StrutStyle strut_style;
1910 strut_style.setStrutEnabled(false);
1911 strut_style.setFontSize(14);
1912 strut_style.setForceStrutHeight(false);
1913 strut_style.setHeight(14);
1914 paragraph_style.setStrutStyle(strut_style);
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001915 TextStyle text_style;
1916 text_style.setColor(SK_ColorBLACK);
Julia Lavrovac0360582020-02-05 10:17:53 -05001917 text_style.setFontFamilies({SkString("Roboto")});
1918 text_style.setFontSize(16);
1919 PlaceholderStyle placeholder_style;
1920 {
1921 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1922 builder.pushStyle(text_style);
1923 builder.addText(text1);
1924 placeholder_style.fHeight = 32;
1925 placeholder_style.fWidth = 32;
1926 placeholder_style.fBaselineOffset = 32;
1927 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1928 placeholder_style.fAlignment = PlaceholderAlignment::kMiddle;
1929 builder.addPlaceholder(placeholder_style);
1930 builder.addText(text2);
1931 placeholder_style.fHeight = 19;
1932 placeholder_style.fWidth = 41;
1933 placeholder_style.fBaselineOffset = 19;
1934 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1935 placeholder_style.fAlignment = PlaceholderAlignment::kTop;
1936 builder.addPlaceholder(placeholder_style);
1937 auto paragraph = builder.Build();
1938 paragraph->layout(280);
1939 paragraph->paint(canvas, 0, 0);
1940 }
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001941 }
1942
1943private:
1944 typedef Sample INHERITED;
1945};
1946
1947class ParagraphView26 : public ParagraphView_Base {
1948protected:
1949 SkString name() override { return SkString("Paragraph26"); }
1950
1951 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001952 auto fontCollection = sk_make_sp<FontCollection>();
1953 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
Julia Lavrova95a9e692020-02-05 10:17:53 -05001954 //fontCollection->enableFontFallback();
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001955
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001956 canvas->clear(SK_ColorWHITE);
1957
1958 SkPaint paint;
1959 paint.setAntiAlias(true);
1960 paint.setColor(SK_ColorBLACK);
1961
1962 TextStyle textStyle;
1963 textStyle.setForegroundColor(paint);
Julia Lavrova95a9e692020-02-05 10:17:53 -05001964 textStyle.setFontFamilies({ SkString("Roboto") });
1965 textStyle.setFontSize(42.0f);
1966 textStyle.setLetterSpacing(-0.05f);
1967 textStyle.setHeightOverride(true);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001968
1969 ParagraphStyle paragraphStyle;
1970 paragraphStyle.setTextStyle(textStyle);
1971 paragraphStyle.setTextAlign(TextAlign::kLeft);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001972
Julia Lavrova95a9e692020-02-05 10:17:53 -05001973 ParagraphBuilderImpl builder(paragraphStyle, fontCollection);
1974 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 -05001975
Julia Lavrova95a9e692020-02-05 10:17:53 -05001976 auto paragraph = builder.Build();
1977 paragraph->layout(this->width() / 2);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001978
Julia Lavrova95a9e692020-02-05 10:17:53 -05001979 std::vector<LineMetrics> lines;
1980 paragraph->getLineMetrics(lines); // <-- error happens here
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001981
Julia Lavrova95a9e692020-02-05 10:17:53 -05001982 canvas->translate(10, 10);
1983 paragraph->paint(canvas, 0, 0);
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001984 }
1985
1986private:
1987 typedef Sample INHERITED;
1988};
1989
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05001990class ParagraphView27 : public ParagraphView_Base {
1991protected:
1992 SkString name() override { return SkString("Paragraph27"); }
1993
1994 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001995 auto fontCollection = sk_make_sp<FontCollection>();
1996 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1997 fontCollection->enableFontFallback();
1998 fontCollection->getParagraphCache()->turnOn(false);
1999
2000 SkPaint red;
2001 red.setColor(SK_ColorRED);
2002 red.setStyle(SkPaint::kStroke_Style);
2003 red.setAntiAlias(true);
2004 red.setStrokeWidth(1);
2005
2006 SkPaint blue;
2007 blue.setColor(SK_ColorRED);
2008 blue.setStyle(SkPaint::kStroke_Style);
2009 blue.setAntiAlias(true);
2010 blue.setStrokeWidth(1);
2011
2012 SkPaint black;
2013 black.setColor(SK_ColorBLACK);
2014 black.setStyle(SkPaint::kStroke_Style);
2015 black.setAntiAlias(true);
2016 black.setStrokeWidth(1);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002017
Julia Lavrova95a9e692020-02-05 10:17:53 -05002018 SkPaint whiteSpaces;
2019 whiteSpaces.setColor(SK_ColorLTGRAY);
2020
2021 SkPaint breakingSpace;
2022 breakingSpace.setColor(SK_ColorYELLOW);
2023
2024 SkPaint text;
2025 text.setColor(SK_ColorWHITE);
2026
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002027 ParagraphStyle paragraph_style;
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002028 paragraph_style.setTextAlign(TextAlign::kRight);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002029 TextStyle text_style;
2030 text_style.setColor(SK_ColorBLACK);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002031 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova89e678d2020-01-28 10:43:31 -05002032
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002033 // RTL + right align + arabic
2034 // RTL + right align + latin
2035 // LTR + right align + arabic
2036 // LTR + right align + latin
2037 // RTL + left align + arabic
2038 // RTL + left align + latin
2039 // arabic and latin should not differ at all
2040 // check: line breaking and trailing spaces
2041
2042 canvas->drawColor(SK_ColorWHITE);
2043 auto h = 60;
2044 auto w = 300;
2045
Julia Lavrova95a9e692020-02-05 10:17:53 -05002046 auto draw = [&](SkScalar width, SkScalar height, TextDirection td, TextAlign ta, const char* t) {
Ben Wagner056d5432020-05-13 10:24:15 -04002047 if (this->isVerbose()) {
2048 SkDebugf("draw '%s' dir:%s align:%s\n", t,
2049 td == TextDirection::kLtr ? "left" : "right",
2050 ta == TextAlign::kLeft ? "left" : "right");
2051 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002052 paragraph_style.setTextDirection(td);
2053 paragraph_style.setTextAlign(ta);
2054 text_style.setFontSize(20);
2055 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrova95a9e692020-02-05 10:17:53 -05002056 text_style.setBackgroundColor(whiteSpaces);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002057 builder.pushStyle(text_style);
Julia Lavrova95a9e692020-02-05 10:17:53 -05002058 builder.addText(" ");
2059 text_style.setBackgroundColor(text);
2060 builder.pushStyle(text_style);
2061 builder.addText(t);
2062 text_style.setBackgroundColor(breakingSpace);
2063 builder.pushStyle(text_style);
2064 builder.addText(" ");
2065 text_style.setBackgroundColor(text);
2066 builder.pushStyle(text_style);
2067 builder.addText(t);
2068 text_style.setBackgroundColor(whiteSpaces);
2069 builder.pushStyle(text_style);
2070 builder.addText(" ");
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002071 auto paragraph = builder.Build();
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002072 paragraph->layout(width);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002073 paragraph->paint(canvas, 0, 0);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002074 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
2075 for (auto& line : impl->lines()) {
Ben Wagner056d5432020-05-13 10:24:15 -04002076 if (this->isVerbose()) {
2077 SkDebugf("line[%d]: %f + %f\n", &line - impl->lines().begin(), line.offset().fX, line.shift());
2078 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002079 line.iterateThroughVisualRuns(true,
2080 [&](const Run* run, SkScalar runOffset, TextRange textRange, SkScalar* width) {
2081 *width = line.measureTextInsideOneRun(textRange, run, runOffset, 0, true, false).clip.width();
Ben Wagner056d5432020-05-13 10:24:15 -04002082 if (this->isVerbose()) {
2083 SkDebugf("%d[%d: %d) @%f + %f %s\n", run->index(),
2084 textRange.start, textRange.end, runOffset, *width, run->leftToRight() ? "left" : "right");
2085 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002086 return true;
2087 });
2088 }
2089 auto boxes = paragraph->getRectsForRange(0, 100, RectHeightStyle::kTight, RectWidthStyle::kTight);
2090 bool even = true;
2091 for (auto& box : boxes) {
Ben Wagner056d5432020-05-13 10:24:15 -04002092 if (this->isVerbose()) {
2093 SkDebugf("[%f:%f,%f:%f] %s\n",
2094 box.rect.fLeft, box.rect.fRight, box.rect.fTop, box.rect.fBottom,
2095 box.direction == TextDirection::kLtr ? "left" : "right");
2096 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002097 canvas->drawRect(box.rect, even ? red : blue);
2098 even = !even;
2099 }
2100 canvas->translate(0, height);
Julia Lavrova89e678d2020-01-28 10:43:31 -05002101 };
2102
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002103 canvas->drawRect(SkRect::MakeXYWH(0, 0, w, h * 8), black);
2104
2105 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "RTL+RIGHT#1234567890");
2106 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
2107
2108 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "LTR+RIGHT#1234567890");
2109 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
2110
2111 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "RTL+LEFT##1234567890");
2112 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
2113
2114 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "LTR+LEFT##1234567890");
2115 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002116 }
2117
2118private:
2119 typedef Sample INHERITED;
2120};
2121
Julia Lavrova212bf072020-02-18 12:05:55 -05002122class ParagraphView28 : public ParagraphView_Base {
2123protected:
2124 SkString name() override { return SkString("Paragraph28"); }
2125
2126 void onDrawContent(SkCanvas* canvas) override {
2127
2128 const char* text = "AAAAA BBBBB CCCCC DDDDD EEEEE FFFFF GGGGG HHHHH IIIII JJJJJ KKKKK LLLLL MMMMM NNNNN OOOOO PPPPP QQQQQ";
2129
2130 canvas->drawColor(SK_ColorWHITE);
2131 ParagraphStyle paragraph_style;
2132 paragraph_style.setTextAlign(TextAlign::kJustify);
2133 auto collection = getFontCollection();
2134 ParagraphBuilderImpl builder(paragraph_style, collection);
2135 TextStyle text_style;
2136 text_style.setColor(SK_ColorBLACK);
2137 text_style.setFontFamilies({SkString("Roboto")});
2138 text_style.setFontSize(40);
2139 builder.pushStyle(text_style);
2140 builder.addText(text);
2141 auto paragraph = builder.Build();
2142 auto s = 186;
2143 paragraph->layout(360 - s);
2144 paragraph->paint(canvas, 0, 0);
2145 /*
2146 paragraph->layout(360);
2147 paragraph->paint(canvas, 0, 0);
2148 canvas->translate(0, 400);
2149 paragraph->layout(354.333);
2150 paragraph->paint(canvas, 0, 0);
2151 */
2152 }
2153
2154private:
2155 typedef Sample INHERITED;
2156};
2157
2158class ParagraphView29 : public ParagraphView_Base {
2159protected:
2160 SkString name() override { return SkString("Paragraph29"); }
2161
2162 void onDrawContent(SkCanvas* canvas) override {
2163
Julia Lavrova62076972020-02-19 15:12:48 -05002164 const char* text = "ffi";
Julia Lavrova212bf072020-02-18 12:05:55 -05002165 canvas->drawColor(SK_ColorWHITE);
2166
Julia Lavrova62076972020-02-19 15:12:48 -05002167 auto collection = getFontCollection();
Julia Lavrova212bf072020-02-18 12:05:55 -05002168
2169 ParagraphStyle paragraph_style;
Julia Lavrova212bf072020-02-18 12:05:55 -05002170 ParagraphBuilderImpl builder(paragraph_style, collection);
2171 TextStyle text_style;
2172 text_style.setColor(SK_ColorBLACK);
2173 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova62076972020-02-19 15:12:48 -05002174 text_style.setFontSize(60);
Julia Lavrova212bf072020-02-18 12:05:55 -05002175 builder.pushStyle(text_style);
2176 builder.addText(text);
2177 auto paragraph = builder.Build();
Julia Lavrova62076972020-02-19 15:12:48 -05002178 paragraph->layout(width());
Julia Lavrova212bf072020-02-18 12:05:55 -05002179 paragraph->paint(canvas, 0, 0);
Julia Lavrova62076972020-02-19 15:12:48 -05002180 auto width = paragraph->getLongestLine();
2181 auto height = paragraph->getHeight();
2182
2183 auto f1 = paragraph->getGlyphPositionAtCoordinate(width/6, height/2);
2184 auto f2 = paragraph->getGlyphPositionAtCoordinate(width/2, height/2);
2185 auto i = paragraph->getGlyphPositionAtCoordinate(width*5/6, height/2);
2186
Ben Wagner056d5432020-05-13 10:24:15 -04002187 if (this->isVerbose()) {
2188 SkDebugf("%d(%s) %d(%s) %d(%s)\n",
2189 f1.position, f1.affinity == Affinity::kUpstream ? "up" : "down",
2190 f2.position, f2.affinity == Affinity::kUpstream ? "up" : "down",
2191 i.position, i.affinity == Affinity::kUpstream ? "up" : "down");
Julia Lavrova62076972020-02-19 15:12:48 -05002192
Julia Lavrovac48caaa2020-05-26 15:21:39 -04002193 auto f1 = paragraph->getRectsForRange(0, 1, RectHeightStyle::kTight, RectWidthStyle::kTight);
2194 if (f1.empty()) {
2195 SkDebugf("F1 is empty\n");
2196 } else {
2197 auto rf1 = f1[0];
2198 SkDebugf("f1: [%f:%f] %s\n",
2199 rf1.rect.fLeft, rf1.rect.fRight, rf1.direction == TextDirection::kRtl ? "rtl" : "ltr");
2200 }
Julia Lavrova62076972020-02-19 15:12:48 -05002201
Julia Lavrovac48caaa2020-05-26 15:21:39 -04002202 auto f2 = paragraph->getRectsForRange(1, 2, RectHeightStyle::kTight, RectWidthStyle::kTight);
2203 if (f2.empty()) {
2204 SkDebugf("F2 is empty\n");
2205 } else {
2206 auto rf2 = f2[0];
2207 SkDebugf("f2: [%f:%f] %s\n",
2208 rf2.rect.fLeft, rf2.rect.fRight, rf2.direction == TextDirection::kRtl ? "rtl" : "ltr");
2209 }
2210
2211 auto fi = paragraph->getRectsForRange(2, 3, RectHeightStyle::kTight, RectWidthStyle::kTight);
2212 if (fi.empty()) {
2213 SkDebugf("FI is empty\n");
2214 } else {
2215 auto rfi = fi[0];
2216 SkDebugf("i: [%f:%f] %s\n",
2217 rfi.rect.fLeft, rfi.rect.fRight, rfi.direction == TextDirection::kRtl ? "rtl" : "ltr");
2218 }
Ben Wagner056d5432020-05-13 10:24:15 -04002219 }
Julia Lavrova212bf072020-02-18 12:05:55 -05002220 }
2221
2222private:
2223 typedef Sample INHERITED;
2224};
2225
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002226class ParagraphView30 : public ParagraphView_Base {
2227protected:
2228 SkString name() override { return SkString("Paragraph30"); }
2229
2230 void onDrawContent(SkCanvas* canvas) override {
2231
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002232 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 -05002233 canvas->drawColor(SK_ColorWHITE);
2234
2235 auto fontCollection = sk_make_sp<FontCollection>();
2236 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2237 fontCollection->enableFontFallback();
2238
2239 ParagraphStyle paragraph_style;
2240 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2241 TextStyle text_style;
2242 text_style.setColor(SK_ColorBLACK);
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002243 text_style.setFontFamilies({SkString("Noto Color Emoji")});
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002244 text_style.setFontSize(60);
2245 builder.pushStyle(text_style);
2246 builder.addText(text);
2247 auto paragraph = builder.Build();
2248 paragraph->layout(width());
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002249
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002250
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002251 SkColor colors[] = {
2252 SK_ColorRED,
2253 SK_ColorGREEN,
2254 SK_ColorBLUE,
2255 SK_ColorMAGENTA,
2256 SK_ColorYELLOW
2257 };
2258 SkPaint paint;
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002259 size_t color = 0;
2260 for (size_t i = 0; i < text.size(); ++i) {
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002261 auto result = paragraph->getRectsForRange(i, i + 1, RectHeightStyle::kTight, RectWidthStyle::kTight);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002262 if (result.empty()) {
Ben Wagner056d5432020-05-13 10:24:15 -04002263 if (this->isVerbose()) {
2264 SkDebugf("empty [%d:%d)\n", i, i + 1);
2265 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002266 continue;
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002267 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002268 auto rect = result[0].rect;
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002269 paint.setColor(colors[color++ % 5]);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002270 canvas->drawRect(rect, paint);
Ben Wagner056d5432020-05-13 10:24:15 -04002271 if (this->isVerbose()) {
2272 SkDebugf("rect [%d:%d): %f:%f\n", i, i + 1, rect.fLeft, rect.fRight);
2273 }
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002274 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002275 paragraph->paint(canvas, 0, 0);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002276 }
2277
2278private:
2279 typedef Sample INHERITED;
2280};
2281
2282class ParagraphView31 : public ParagraphView_Base {
2283protected:
2284 SkString name() override { return SkString("Paragraph31"); }
2285
2286 void onDrawContent(SkCanvas* canvas) override {
2287
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002288 canvas->drawColor(SK_ColorWHITE);
2289
2290 auto fontCollection = sk_make_sp<FontCollection>();
2291 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2292 fontCollection->enableFontFallback();
2293
2294 ParagraphStyle paragraph_style;
2295 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2296 TextStyle text_style;
2297 text_style.setColor(SK_ColorBLACK);
2298 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002299 text_style.setFontSize(40);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002300 builder.pushStyle(text_style);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002301 auto s = u"েن েূথ";
2302 builder.addText(s);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002303 auto paragraph = builder.Build();
2304 paragraph->layout(width());
2305 paragraph->paint(canvas, 0, 0);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002306 }
2307
2308private:
2309 typedef Sample INHERITED;
2310};
2311
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002312class ParagraphView32 : public ParagraphView_Base {
2313protected:
2314 SkString name() override { return SkString("Paragraph32"); }
2315
2316 void onDrawContent(SkCanvas* canvas) override {
2317
2318 canvas->drawColor(SK_ColorWHITE);
2319
2320 auto fontCollection = sk_make_sp<FontCollection>();
2321 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2322 fontCollection->enableFontFallback();
2323
2324 ParagraphStyle paragraph_style;
2325 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2326 TextStyle text_style;
2327 text_style.setColor(SK_ColorBLACK);
2328 text_style.setFontFamilies({SkString("Roboto")});
2329 text_style.setFontSize(40);
2330 text_style.setLocale(SkString("ko"));
2331 builder.pushStyle(text_style);
2332 builder.addText(u"\u904d ko ");
2333 text_style.setLocale(SkString("zh_Hant"));
2334 builder.pushStyle(text_style);
2335 builder.addText(u"\u904d zh-Hant ");
2336 text_style.setLocale(SkString("zh_Hans"));
2337 builder.pushStyle(text_style);
2338 builder.addText(u"\u904d zh-Hans ");
2339 text_style.setLocale(SkString("zh_HK"));
2340 builder.pushStyle(text_style);
2341 builder.addText(u"\u904d zh-HK ");
2342 auto paragraph = builder.Build();
2343 paragraph->layout(width());
2344 paragraph->paint(canvas, 0, 0);
2345 }
2346
2347private:
2348 typedef Sample INHERITED;
2349};
2350
2351class ParagraphView33 : public ParagraphView_Base {
2352protected:
2353 SkString name() override { return SkString("Paragraph33"); }
2354
2355 void onDrawContent(SkCanvas* canvas) override {
2356
2357 canvas->drawColor(SK_ColorWHITE);
2358
2359 auto fontCollection = sk_make_sp<FontCollection>();
2360 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2361 fontCollection->enableFontFallback();
2362
2363 ParagraphStyle paragraph_style;
2364 paragraph_style.setTextAlign(TextAlign::kJustify);
2365 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2366 TextStyle text_style;
2367 text_style.setColor(SK_ColorBLACK);
2368 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2369 text_style.setFontSize(36);
2370 builder.pushStyle(text_style);
2371 builder.addText(u"AAAAA \U0001f600 BBBBB CCCCC DDDDD EEEEE");
2372 auto paragraph = builder.Build();
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002373 paragraph->layout(width() / 2);
2374 SkPaint paint;
2375 paint.setColor(SK_ColorLTGRAY);
2376 canvas->drawRect(SkRect::MakeXYWH(0, 0, width()/2, paragraph->getHeight()), paint);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002377 paragraph->paint(canvas, 0, 0);
2378 }
2379
2380private:
2381 typedef Sample INHERITED;
2382};
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002383
2384class ParagraphView34 : public ParagraphView_Base {
2385protected:
2386 SkString name() override { return SkString("Paragraph34"); }
2387
2388 void onDrawContent(SkCanvas* canvas) override {
2389
2390 canvas->drawColor(SK_ColorWHITE);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002391 auto text = "ضخمة ص ،😁😂🤣ضضض ؤ،،😗😗😍😋شسي،😗😁😁ؤرى،😗😃😄😍ببب،🥰😅🥰🥰🥰ثيلااتن";
2392 //auto text = "ى،😗😃😄😍بب";
2393 //auto text1 = "World domination is such an ugly phrase - I prefer to call it world optimisation";
2394 auto fontCollection = sk_make_sp<FontCollection>();
2395 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2396 fontCollection->enableFontFallback();
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002397
2398 ParagraphStyle paragraph_style;
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002399 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2400 TextStyle text_style;
2401 text_style.setColor(SK_ColorBLACK);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002402 text_style.setFontFamilies({SkString("Noto Color Emoji")});
2403 text_style.setFontSize(50);
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002404 builder.pushStyle(text_style);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002405 builder.addText(text);
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002406 auto paragraph = builder.Build();
Julia Lavrova3c79a232020-03-02 09:58:52 -05002407 paragraph->layout(1041); // 1041
2408
2409 SkColor colors[] = {SK_ColorBLUE, SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGREEN,
2410 SK_ColorRED, SK_ColorWHITE, SK_ColorYELLOW, SK_ColorMAGENTA };
2411 SkPaint paint;
2412 size_t wordPos = 0;
2413 size_t index = 0;
2414 while (wordPos < 72) {
2415 auto res2 = paragraph->getWordBoundary(wordPos);
2416 if (res2.width() == 0) {
2417 break;
2418 }
2419 wordPos = res2.end;
2420 auto res3 = paragraph->getRectsForRange(
2421 res2.start, res2.end,
2422 RectHeightStyle::kTight, RectWidthStyle::kTight);
2423 paint.setColor(colors[index % 8]);
2424 ++index;
2425 if (!res3.empty()) {
2426 canvas->drawRect(res3[0].rect, paint);
2427 }
2428 }
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002429 paragraph->paint(canvas, 0, 0);
2430 }
2431
2432private:
2433 typedef Sample INHERITED;
2434};
Julia Lavrova3c79a232020-03-02 09:58:52 -05002435
2436class ParagraphView35 : public ParagraphView_Base {
2437protected:
2438 SkString name() override { return SkString("Paragraph35"); }
2439
2440 Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
2441 return new Click;
2442 }
2443
2444 bool onClick(Click* click) override {
2445 fPoint = click->fCurr;
2446 return true;
2447 }
2448
2449 void onDrawContent(SkCanvas* canvas) override {
2450
2451 canvas->drawColor(SK_ColorWHITE);
2452
2453 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";
2454 auto fontCollection = sk_make_sp<FontCollection>();
2455 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2456 fontCollection->enableFontFallback();
2457
2458 ParagraphStyle paragraph_style;
Julia Lavrova2813d452020-03-03 11:43:40 -05002459 //paragraph_style.setTextAlign(TextAlign::kJustify);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002460 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2461 TextStyle text_style;
2462 text_style.setColor(SK_ColorBLACK);
2463 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2464 text_style.setFontSize(40);
2465 builder.pushStyle(text_style);
2466 builder.addText(text);
2467 auto paragraph = builder.Build();
Julia Lavrova2813d452020-03-03 11:43:40 -05002468 paragraph->layout(width());//758
2469
2470 //auto res1 = paragraph->getGlyphPositionAtCoordinate(line.width() + line.spacesWidth() / 2, line.offset().fY + 10);
2471 //auto res2 = paragraph->getWordBoundary(res1.position);
2472 auto res1 = paragraph->getRectsForRange(360, 361, RectHeightStyle::kTight, RectWidthStyle::kTight);
2473 auto res2 = paragraph->getRectsForRange(359, 360, RectHeightStyle::kTight, RectWidthStyle::kTight);
2474 auto res3 = paragraph->getRectsForRange(358, 359, RectHeightStyle::kTight, RectWidthStyle::kTight);
2475
2476 auto draw = [&](std::vector<TextBox> res, SkColor color) {
2477 SkPaint paint;
2478 paint.setColor(color);
2479 for (auto& r : res) {
2480 canvas->drawRect(r.rect, paint);
2481 }
2482 };
2483
2484 draw(res1, SK_ColorRED);
2485 draw(res2, SK_ColorGREEN);
2486 draw(res3, SK_ColorBLUE);
2487
Julia Lavrova3c79a232020-03-02 09:58:52 -05002488 paragraph->paint(canvas, 0, 0);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002489 }
2490
2491private:
2492 typedef Sample INHERITED;
2493 SkPoint fPoint;
2494};
2495
Julia Lavrova2813d452020-03-03 11:43:40 -05002496class ParagraphView36 : public ParagraphView_Base {
2497protected:
2498 SkString name() override { return SkString("Paragraph36"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04002499
Julia Lavrova2813d452020-03-03 11:43:40 -05002500 void onDrawContent(SkCanvas* canvas) override {
2501
2502 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovacd2d4e42020-03-27 15:40:37 -04002503 auto text = "String is too big for WinMSVC";
2504 //"সৢ৭ঙ া 七七去关谢都四先么见香认东 غلضينخي 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 字弟是去妈京学地";
2505 //"ي ز";
2506 //"৪৮ু৸ধ maar";
2507 //"四的 ذخص ৢঙ";
2508 //"ذخص ৢঙ";
Julia Lavrova2813d452020-03-03 11:43:40 -05002509 auto fontCollection = sk_make_sp<FontCollection>();
2510 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2511 fontCollection->enableFontFallback();
2512
2513 ParagraphStyle paragraph_style;
Julia Lavrova2813d452020-03-03 11:43:40 -05002514 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2515 TextStyle text_style;
2516 text_style.setColor(SK_ColorBLACK);
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002517 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Serif CJK JP")});
2518 text_style.setFontSize(10);
Julia Lavrova2813d452020-03-03 11:43:40 -05002519 builder.pushStyle(text_style);
2520 builder.addText(text);
2521 auto paragraph = builder.Build();
2522 paragraph->layout(width());
2523
Julia Lavrova2813d452020-03-03 11:43:40 -05002524 paragraph->paint(canvas, 0, 0);
2525 }
2526
2527private:
2528 typedef Sample INHERITED;
2529};
2530
Julia Lavrova99ede422020-03-17 13:20:58 -04002531class ParagraphView37 : public ParagraphView_Base {
2532protected:
2533 SkString name() override { return SkString("Paragraph37"); }
2534
2535 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovacd2d4e42020-03-27 15:40:37 -04002536 const char* text = "String is too big for WinMSVC";
2537 // "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaয়ৠঝোণ৺ঢ়মৈবৗৗঘথফড়৭২খসঢ়ৃঢ়ঁ৷থডঈঽলবনদ২ৢৃঀজঝ৩ঠ৪৫৯০ঌয়্মওৗ৲গখদ৹ঈ৴৹ঢ়ৄএৡফণহলঈ৲থজোৱে ঀকৰঀষজঝঃাখশঽএমংি";
Julia Lavrovaa169b002020-03-23 13:39:52 -04002538 //"ৎৣ়ৎঽতঃ৳্ৱব৴ৣঈ৷ূঁঢঢ়শটডৎ৵৵ৰৃ্দংঊাথৗদঊউদ৯ঐৃধা৬হওধি়৭ঽম৯স০ঢফৈঢ়কষঁছফীআে৶ৰ৶ঌৌঊ্ঊঝএঀঃদঞ৮তব৬ৄঊঙঢ়ৡগ৶৹৹ঌড়ঘৄ৷লপ১ভড়৶েঢ়৯ৎকনংট২ংএঢৌৌঐনো০টঽুৠগআ৷৭৩৬তো৻ঈ০ূসষঅঝআমণঔা১ণৈো৵চঽ৩বমৎঙঘ২ঠৠৈী৫তঌণচ৲ঔী৮ঘৰঔ";
Julia Lavrova99ede422020-03-17 13:20:58 -04002539 canvas->drawColor(SK_ColorWHITE);
2540
2541 auto fontCollection = sk_make_sp<FontCollection>();
2542 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2543 fontCollection->enableFontFallback();
2544
2545 ParagraphStyle paragraph_style;
2546 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2547 TextStyle text_style;
2548 text_style.setColor(SK_ColorBLACK);
2549 text_style.setFontFamilies({SkString("Roboto")});
2550 text_style.setFontSize(20);
2551 builder.pushStyle(text_style);
2552 builder.addText(text);
2553 auto paragraph = builder.Build();
2554 auto w = width() / 2;
2555 paragraph->layout(w);
Julia Lavrovaa169b002020-03-23 13:39:52 -04002556 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
2557
2558 auto clusters = impl->clusters();
Ben Wagner056d5432020-05-13 10:24:15 -04002559 if (this->isVerbose()) {
2560 size_t c = 0;
2561 SkDebugf("clusters\n");
2562 for (auto& cluster: clusters) {
2563 SkDebugf("%d: [%d:%d) %s\n", c++,
2564 cluster.textRange().start, cluster.textRange().end,
2565 cluster.isSoftBreak() ? "soft" :
2566 cluster.isHardBreak() ? "hard" :
2567 cluster.isWhitespaces() ? "spaces" : "");
2568 }
2569
2570 auto lines = impl->lines();
2571 size_t i = 0;
2572 SkDebugf("lines\n");
2573 for (auto& line : lines) {
2574 SkDebugf("%d: [%d:%d)\n", i++, line.trimmedText().start, line.trimmedText().end);
2575 }
Julia Lavrovaa169b002020-03-23 13:39:52 -04002576 }
2577
Julia Lavrova99ede422020-03-17 13:20:58 -04002578 paragraph->paint(canvas, 0, 0);
2579 }
2580
2581private:
2582 typedef Sample INHERITED;
2583};
2584
Julia Lavrova18db52f2020-05-04 15:03:18 -04002585class ParagraphView38 : public ParagraphView_Base {
2586protected:
2587 SkString name() override { return SkString("Paragraph38"); }
2588
2589 void onDrawContent(SkCanvas* canvas) override {
2590
2591 canvas->drawColor(SK_ColorWHITE);
2592
2593 auto fontCollection = sk_make_sp<FontCollection>();
2594 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2595 fontCollection->enableFontFallback();
2596
2597 ParagraphStyle paragraph_style;
2598 paragraph_style.setTextAlign(TextAlign::kLeft);
2599 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2600 TextStyle text_style;
2601 text_style.setColor(SK_ColorDKGRAY);
2602 text_style.setFontFamilies({SkString("Roboto")});
2603 text_style.setFontSize(40);
2604 text_style.setDecoration(TextDecoration::kUnderline);
2605
2606 text_style.setDecorationMode(TextDecorationMode::kThrough);
2607 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2608 text_style.setDecorationColor(SK_ColorBLUE);
2609 builder.pushStyle(text_style);
2610 builder.addText("Double underline: {opopo}\n");
2611
2612 text_style.setDecorationMode(TextDecorationMode::kGaps);
2613 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2614 text_style.setDecorationColor(SK_ColorBLUE);
2615 builder.pushStyle(text_style);
2616 builder.addText("Double underline: {opopo}\n");
2617
2618 text_style.setDecorationStyle(TextDecorationStyle::kDotted);
2619 text_style.setDecorationColor(SK_ColorRED);
2620 builder.pushStyle(text_style);
2621 builder.addText("Dotted underline: {ijiji}\n");
2622
2623 text_style.setDecorationStyle(TextDecorationStyle::kSolid);
2624 text_style.setDecorationColor(SK_ColorGREEN);
2625 builder.pushStyle(text_style);
2626 builder.addText("Solid underline: {rqrqr}\n");
2627
2628 text_style.setDecorationStyle(TextDecorationStyle::kDashed);
2629 text_style.setDecorationColor(SK_ColorMAGENTA);
2630 builder.pushStyle(text_style);
2631 builder.addText("Dashed underline: {zyzyz}\n");
2632
2633 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
2634 text_style.setDecorationColor(SK_ColorCYAN);
2635 builder.pushStyle(text_style);
2636 builder.addText("Wavy underline: {does not skip}\n");
2637
2638 auto paragraph = builder.Build();
2639 paragraph->layout(width());
2640 paragraph->paint(canvas, 0, 0);
2641 }
2642
2643private:
2644 typedef Sample INHERITED;
2645};
2646
Julia Lavrova6bdbd3d2020-05-06 12:03:17 -04002647class ParagraphView39 : public ParagraphView_Base {
2648protected:
2649 SkString name() override { return SkString("Paragraph39"); }
2650
2651 void onDrawContent(SkCanvas* canvas) override {
2652
2653 canvas->drawColor(SK_ColorWHITE);
2654
2655 auto fontCollection = sk_make_sp<FontCollection>();
2656 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2657 fontCollection->enableFontFallback();
2658
2659 ParagraphStyle paragraph_style;
2660 paragraph_style.setTextAlign(TextAlign::kJustify);
2661 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2662 TextStyle text_style;
2663 text_style.setColor(SK_ColorBLACK);
2664 text_style.setFontFamilies({SkString("Roboto")});
2665 text_style.setFontSize(40);
2666 builder.pushStyle(text_style);
2667 builder.addText(
2668 "text1 with line break\n"
2669 "text2 without line break text without line break text without line break text without line break text without line break text without line break "
2670 "text3 with line break\n"
2671 "text4 without line break text without line break text without line break text without line break text without line break text without line break "
2672 "text5 with line break\n"
2673 );
2674 auto paragraph = builder.Build();
2675 paragraph->layout(width());
2676 paragraph->paint(canvas, 0, 0);
2677 }
2678
2679private:
2680 typedef Sample INHERITED;
2681};
2682
Julia Lavrovadd1de252020-05-08 11:53:19 -04002683class ParagraphView41 : public ParagraphView_Base {
2684protected:
2685 SkString name() override { return SkString("Paragraph41"); }
2686
2687 void onDrawContent(SkCanvas* canvas) override {
2688
2689 canvas->drawColor(SK_ColorWHITE);
2690
2691 auto fontCollection = sk_make_sp<FontCollection>();
2692 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2693 fontCollection->enableFontFallback();
2694
2695 SkPaint line;
2696 line.setColor(SK_ColorRED);
2697 line.setStyle(SkPaint::kStroke_Style);
2698 line.setAntiAlias(true);
2699 line.setStrokeWidth(1);
2700
2701 auto draw = [&](SkColor color, TextHeightBehavior thb) {
2702 ParagraphStyle paragraph_style;
2703 paragraph_style.setTextHeightBehavior(thb);
2704 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2705 TextStyle text_style;
2706 text_style.setColor(SK_ColorBLACK);
2707 SkPaint paint;
2708 paint.setColor(color);
2709 text_style.setBackgroundColor(paint);
2710 text_style.setFontFamilies({SkString("Roboto")});
2711 text_style.setFontSize(20);
2712 text_style.setHeight(5);
2713 text_style.setHeightOverride(true);
2714 builder.pushStyle(text_style);
2715 builder.addText("World domination is such an ugly phrase - I prefer to call it world optimisation");
2716 auto paragraph = builder.Build();
2717 paragraph->layout(width());
2718 paragraph->paint(canvas, 0, 0);
2719 canvas->drawLine(0, paragraph->getHeight(), paragraph->getMaxWidth(), paragraph->getHeight(), line);
2720 canvas->translate(0, paragraph->getHeight());
2721 };
2722
2723 draw(SK_ColorLTGRAY, TextHeightBehavior::kDisableFirstAscent);
2724 draw(SK_ColorYELLOW, TextHeightBehavior::kDisableLastDescent);
2725 draw(SK_ColorGRAY, TextHeightBehavior::kDisableAll);
2726
2727 }
2728
2729private:
2730 typedef Sample INHERITED;
2731};
2732
2733class ParagraphView42 : public ParagraphView_Base {
2734protected:
2735 SkString name() override { return SkString("Paragraph42"); }
2736
2737 void onDrawContent(SkCanvas* canvas) override {
2738
2739 SkString text("Atwater Peel Sherbrooke Bonaventure\nhi\nwasssup!");
2740 canvas->drawColor(SK_ColorWHITE);
2741
2742 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
2743
2744 ParagraphStyle paragraph_style;
2745 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2746 TextStyle text_style;
2747 text_style.setColor(SK_ColorBLACK);
2748 text_style.setFontFamilies({SkString("Ahem")});
2749 text_style.setFontSize(16);
2750 text_style.setHeight(4);
2751 text_style.setHeightOverride(true);
2752 builder.pushStyle(text_style);
2753 builder.addText(text.c_str());
2754 auto paragraph = builder.Build();
2755 paragraph->layout(width());
2756
2757 auto boxes = paragraph->getRectsForRange(0, 7, RectHeightStyle::kIncludeLineSpacingTop, RectWidthStyle::kMax);
2758 for (auto& box : boxes) {
2759 SkPaint paint;
2760 paint.setColor(SK_ColorGRAY);
2761 canvas->drawRect(box.rect, paint);
2762 }
2763
2764 auto boxes2 = paragraph->getRectsForRange(0, 7, RectHeightStyle::kTight, RectWidthStyle::kMax);
2765 for (auto& box : boxes2) {
2766 SkPaint paint;
2767 paint.setColor(SK_ColorRED);
2768 canvas->drawRect(box.rect, paint);
2769 }
2770
2771 paragraph->paint(canvas, 0, 0);
2772 }
2773
2774private:
2775 typedef Sample INHERITED;
2776};
Julia Lavrova68d14332020-05-11 13:47:08 -04002777
2778class ParagraphView43 : public ParagraphView_Base {
2779protected:
2780 SkString name() override { return SkString("Paragraph43"); }
2781
2782 void onDrawContent(SkCanvas* canvas) override {
2783
2784 SkString text("World domination is such an ugly phrase - I prefer to call it world optimisation");
2785 canvas->drawColor(SK_ColorWHITE);
2786
2787 auto fontCollection = sk_make_sp<FontCollection>();
2788 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2789 fontCollection->enableFontFallback();
2790
2791 ParagraphStyle paragraph_style;
2792 paragraph_style.setTextAlign(TextAlign::kJustify);
2793 paragraph_style.setEllipsis(u"\u2026");
2794 paragraph_style.setMaxLines(2);
2795 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2796 TextStyle text_style;
2797 text_style.setColor(SK_ColorBLACK);
2798 text_style.setFontFamilies({SkString("Roboto")});
2799 text_style.setFontSize(40);
2800 text_style.setHeightOverride(true);
2801 builder.pushStyle(text_style);
2802 builder.addText(text.c_str());
2803 auto paragraph = builder.Build();
2804 paragraph->layout(width() / 4);
2805 paragraph->paint(canvas, 0, 0);
2806 }
2807
2808private:
2809 typedef Sample INHERITED;
2810};
2811
Julia Lavrova3ea86252020-05-15 14:54:39 -04002812class ParagraphView44 : public ParagraphView_Base {
2813protected:
2814 SkString name() override { return SkString("Paragraph44"); }
2815
2816 void onDrawContent(SkCanvas* canvas) override {
2817
2818 const std::u16string text = u"The quick brown fox \U0001f98a ate a zesty ham burger fons \U0001f354."
2819 "The \U0001f469\u200D\U0001f469\u200D\U0001f467\u200D\U0001f467 laughed.";
2820 canvas->drawColor(SK_ColorWHITE);
2821
2822 auto fontCollection = sk_make_sp<FontCollection>();
2823 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2824 fontCollection->enableFontFallback();
2825
2826 ParagraphStyle paragraph_style;
2827 paragraph_style.setMaxLines(7);
2828 paragraph_style.setEllipsis(u"\u2026");
2829 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2830 TextStyle text_style;
2831 text_style.setColor(SK_ColorBLACK);
2832 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2833 text_style.setFontSize(60);
2834 builder.pushStyle(text_style);
2835 builder.addText(text);
2836 auto paragraph = builder.Build();
2837 paragraph->layout(305);//width());
2838 paragraph->paint(canvas, 0, 0);
2839 }
2840
2841private:
2842 typedef Sample INHERITED;
2843};
2844
Julia Lavrovad470f402020-06-08 10:31:49 -04002845class ParagraphView45 : public ParagraphView_Base {
2846protected:
2847 SkString name() override { return SkString("Paragraph45"); }
2848
2849 void onDrawContent(SkCanvas* canvas) override {
2850
2851 // This test crashed when resources/fonts directory had only 5 fonts listed below
2852 std::string fonts = GetResourcePath("fonts/").c_str();
2853 std::set<std::pair<std::string, std::string>> font_paths = {
2854 {"Roboto", "Roboto-Regular.ttf"},
2855 {"Roboto", "Roboto-Bold.ttf"},
2856 {"Noto","NotoSansCJK-Regular.ttc"},
2857 {"Noto", "NotoSansCJK-Bold.ttc"},
2858 {"Emoji","NotoColorEmoji.ttf"}};
2859
2860 sk_sp<TypefaceFontProvider> font_provider = sk_make_sp<TypefaceFontProvider>();
2861
2862 for (auto& pair : font_paths) {
2863 SkString family_name = SkString(pair.first.c_str());
2864 std::string path = fonts;
2865 path += pair.second;
2866
2867 auto data = SkData::MakeFromFileName(path.c_str());
2868 font_provider->registerTypeface(SkTypeface::MakeFromData(std::move(data)), family_name);
2869 }
2870
2871 sk_sp<FontCollection> font_collection = sk_make_sp<FontCollection>();
2872 font_collection->setAssetFontManager(std::move(font_provider));
2873 font_collection->getParagraphCache()->turnOn(false);
2874
2875 const std::u16string text = u"❤️🕵🏾‍♀️ 🕵🏾 👩🏾‍⚕️ 👨🏾‍⚕️ 👩🏾‍🌾 👨🏾‍🌾 👩🏾‍🍳 👨🏾‍🍳 👩🏾‍🎓 👨🏾‍🎓 👩🏾‍🎤 👨🏾‍🎤 👩🏾‍🏫 👨🏾‍🏫 👩🏾‍🏭 👨🏾‍🏭 👩🏾‍💻 👨🏾‍💻 👩🏾‍💼 👨🏾‍💼 👩🏾‍🔧 👨🏾‍🔧 👩🏾‍🔬 👨🏾‍🔬 👩🏾‍🎨 👨🏾‍🎨 👩🏾‍🚒 👨🏾‍🚒 👩🏾‍✈️ 👨🏾‍✈️ 👩🏾‍🚀 👨🏾‍🚀 👩🏾‍⚖️ 👨🏾‍⚖️ 🤶🏾 🎅🏾";
Julia Lavrovac4d49052020-06-15 10:20:08 -04002876 //u"\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC66\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67\uD83C\uDDFA\uD83C\uDDF8";
2877
Julia Lavrovad470f402020-06-08 10:31:49 -04002878 canvas->drawColor(SK_ColorWHITE);
2879
2880 ParagraphStyle paragraph_style;
2881 paragraph_style.setMaxLines(1);
2882 paragraph_style.setHeight(0);
2883 paragraph_style.setEllipsis(u"\u2026");
2884 ParagraphBuilderImpl builder(paragraph_style, font_collection);
2885 TextStyle text_style;
2886 text_style.setColor(SK_ColorBLACK);
2887 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto"), SkString("Emoji")});
2888 text_style.setFontSize(20);
2889 text_style.setFontStyle(SkFontStyle::Bold());
2890 builder.pushStyle(text_style);
2891 builder.addText(text);
2892 auto paragraph = builder.Build();
2893 paragraph->layout(width());
2894 paragraph->paint(canvas, 0, 0);
2895 }
2896
2897private:
2898 typedef Sample INHERITED;
2899};
2900
Ben Wagner056d5432020-05-13 10:24:15 -04002901} // namespace
2902
Julia Lavrova2813d452020-03-03 11:43:40 -05002903//////////////////////////////////////////////////////////////////////////////
Julia Lavrovaa3552c52019-05-30 16:12:56 -04002904DEF_SAMPLE(return new ParagraphView1();)
2905DEF_SAMPLE(return new ParagraphView2();)
2906DEF_SAMPLE(return new ParagraphView3();)
2907DEF_SAMPLE(return new ParagraphView4();)
2908DEF_SAMPLE(return new ParagraphView5();)
2909DEF_SAMPLE(return new ParagraphView6();)
2910DEF_SAMPLE(return new ParagraphView7();)
2911DEF_SAMPLE(return new ParagraphView8();)
2912DEF_SAMPLE(return new ParagraphView9();)
2913DEF_SAMPLE(return new ParagraphView10();)
2914DEF_SAMPLE(return new ParagraphView11();)
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04002915DEF_SAMPLE(return new ParagraphView12();)
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04002916DEF_SAMPLE(return new ParagraphView14();)
2917DEF_SAMPLE(return new ParagraphView15();)
Julia Lavrova2e30fde2019-10-09 09:43:02 -04002918DEF_SAMPLE(return new ParagraphView16();)
2919DEF_SAMPLE(return new ParagraphView17();)
2920DEF_SAMPLE(return new ParagraphView18();)
Julia Lavrovac48caaa2020-05-26 15:21:39 -04002921DEF_SAMPLE(return new ParagraphView19();)
Julia Lavrovac028b422019-11-25 10:00:43 -05002922DEF_SAMPLE(return new ParagraphView20();)
Julia Lavrovac48687a2020-01-08 16:53:53 -05002923DEF_SAMPLE(return new ParagraphView21();)
Julia Lavrova4cf18742020-01-14 13:24:45 -05002924DEF_SAMPLE(return new ParagraphView22();)
Julia Lavrova51a813d2020-01-21 13:55:44 -05002925DEF_SAMPLE(return new ParagraphView23();)
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05002926DEF_SAMPLE(return new ParagraphView24();)
2927DEF_SAMPLE(return new ParagraphView25();)
Julia Lavrova212bf072020-02-18 12:05:55 -05002928DEF_SAMPLE(return new ParagraphView26();)
2929DEF_SAMPLE(return new ParagraphView27();)
2930DEF_SAMPLE(return new ParagraphView28();)
2931DEF_SAMPLE(return new ParagraphView29();)
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002932DEF_SAMPLE(return new ParagraphView30();)
2933DEF_SAMPLE(return new ParagraphView31();)
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002934DEF_SAMPLE(return new ParagraphView32();)
2935DEF_SAMPLE(return new ParagraphView33();)
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002936DEF_SAMPLE(return new ParagraphView34();)
Julia Lavrova3c79a232020-03-02 09:58:52 -05002937DEF_SAMPLE(return new ParagraphView35();)
Julia Lavrova2813d452020-03-03 11:43:40 -05002938DEF_SAMPLE(return new ParagraphView36();)
Julia Lavrova99ede422020-03-17 13:20:58 -04002939DEF_SAMPLE(return new ParagraphView37();)
Julia Lavrova18db52f2020-05-04 15:03:18 -04002940DEF_SAMPLE(return new ParagraphView38();)
Julia Lavrova6bdbd3d2020-05-06 12:03:17 -04002941DEF_SAMPLE(return new ParagraphView39();)
Julia Lavrovadd1de252020-05-08 11:53:19 -04002942DEF_SAMPLE(return new ParagraphView41();)
2943DEF_SAMPLE(return new ParagraphView42();)
Julia Lavrova68d14332020-05-11 13:47:08 -04002944DEF_SAMPLE(return new ParagraphView43();)
Julia Lavrova3ea86252020-05-15 14:54:39 -04002945DEF_SAMPLE(return new ParagraphView44();)
Julia Lavrovad470f402020-06-08 10:31:49 -04002946DEF_SAMPLE(return new ParagraphView45();)