blob: a367808fa46efcdadca941d64d6259d9922827da [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 Wagner4ca7a812020-05-28 13:48:18 -040020#include "modules/skparagraph/src/TextLine.h"
Julia Lavrova9af5cc42019-06-19 13:32:01 -040021#include "modules/skparagraph/utils/TestFontCollection.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040022#include "samplecode/Sample.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040023#include "src/core/SkOSFile.h"
24#include "src/shaders/SkColorShader.h"
Julia Lavrova2e30fde2019-10-09 09:43:02 -040025#include "src/utils/SkOSPath.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -040026#include "src/utils/SkUTF.h"
27#include "tools/Resources.h"
Ben Wagner056d5432020-05-13 10:24:15 -040028#include "tools/flags/CommandLineFlags.h"
29
30
31static DEFINE_bool(verboseParagraph, false, "paragraph samples very verbose.");
Julia Lavrovaa3552c52019-05-30 16:12:56 -040032
33using namespace skia::textlayout;
34namespace {
35
Mike Reed21a940d2019-07-23 10:11:03 -040036class ParagraphView_Base : public Sample {
37protected:
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -040038 sk_sp<TestFontCollection> getFontCollection() {
39 // If we reset font collection we need to reset paragraph cache
40 static sk_sp<TestFontCollection> fFC = nullptr;
41 if (fFC == nullptr) {
Julia Lavrova2e30fde2019-10-09 09:43:02 -040042 fFC = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -040043 }
44 return fFC;
Mike Reed21a940d2019-07-23 10:11:03 -040045 }
Ben Wagner056d5432020-05-13 10:24:15 -040046
47 bool isVerbose() {
48 return FLAGS_verboseParagraph;
49 }
Mike Reed21a940d2019-07-23 10:11:03 -040050};
51
Julia Lavrovaa3552c52019-05-30 16:12:56 -040052sk_sp<SkShader> setgrad(const SkRect& r, SkColor c0, SkColor c1) {
53 SkColor colors[] = {c0, c1};
54 SkPoint pts[] = {{r.fLeft, r.fTop}, {r.fRight, r.fTop}};
55 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
56}
Julia Lavrova2e30fde2019-10-09 09:43:02 -040057/*
58void writeHtml(const char* name, Paragraph* paragraph) {
59 SkString tmpDir = skiatest::GetTmpDir();
60 if (!tmpDir.isEmpty()) {
61 SkString path = SkOSPath::Join(tmpDir.c_str(), name);
62 SkFILEWStream file(path.c_str());
63 file.write(nullptr, 0);
64 }
65}
66*/
Julia Lavrovaa3552c52019-05-30 16:12:56 -040067
Mike Reed21a940d2019-07-23 10:11:03 -040068class ParagraphView1 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -040069protected:
Hal Canary8a027312019-07-03 10:55:44 -040070 SkString name() override { return SkString("Paragraph1"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040071
72 void drawTest(SkCanvas* canvas, SkScalar w, SkScalar h, SkColor fg, SkColor bg) {
73 const std::vector<
74 std::tuple<std::string, bool, bool, int, SkColor, SkColor, bool, TextDecorationStyle>>
75 gParagraph = {{"monospace", true, false, 14, SK_ColorWHITE, SK_ColorRED, true,
76 TextDecorationStyle::kDashed},
77 {"Assyrian", false, false, 20, SK_ColorWHITE, SK_ColorBLUE, false,
78 TextDecorationStyle::kDotted},
79 {"serif", true, true, 10, SK_ColorWHITE, SK_ColorRED, true,
80 TextDecorationStyle::kDouble},
81 {"Arial", false, true, 16, SK_ColorGRAY, SK_ColorGREEN, true,
82 TextDecorationStyle::kSolid},
83 {"sans-serif", false, false, 8, SK_ColorWHITE, SK_ColorRED, false,
84 TextDecorationStyle::kWavy}};
85 SkAutoCanvasRestore acr(canvas, true);
86
87 canvas->clipRect(SkRect::MakeWH(w, h));
88 canvas->drawColor(SK_ColorWHITE);
89
90 SkScalar margin = 20;
91
92 SkPaint paint;
93 paint.setAntiAlias(true);
94 paint.setColor(fg);
95
96 SkPaint blue;
97 blue.setColor(SK_ColorBLUE);
98
99 TextStyle defaultStyle;
100 defaultStyle.setBackgroundColor(blue);
101 defaultStyle.setForegroundColor(paint);
102 ParagraphStyle paraStyle;
103
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400104 auto fontCollection = sk_make_sp<FontCollection>();
105 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400106 for (auto i = 1; i < 5; ++i) {
107 defaultStyle.setFontSize(24 * i);
108 paraStyle.setTextStyle(defaultStyle);
Julia Lavrova5207f352019-06-21 12:22:32 -0400109 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400110 std::string name = "Paragraph: " + std::to_string(24 * i);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400111 builder.addText(name.c_str(), name.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400112 for (auto para : gParagraph) {
113 TextStyle style;
114 style.setFontFamilies({SkString(std::get<0>(para).c_str())});
115 SkFontStyle fontStyle(std::get<1>(para) ? SkFontStyle::Weight::kBold_Weight
116 : SkFontStyle::Weight::kNormal_Weight,
117 SkFontStyle::Width::kNormal_Width,
118 std::get<2>(para) ? SkFontStyle::Slant::kItalic_Slant
119 : SkFontStyle::Slant::kUpright_Slant);
120 style.setFontStyle(fontStyle);
121 style.setFontSize(std::get<3>(para) * i);
122 SkPaint background;
123 background.setColor(std::get<4>(para));
124 style.setBackgroundColor(background);
125 SkPaint foreground;
126 foreground.setColor(std::get<5>(para));
127 foreground.setAntiAlias(true);
128 style.setForegroundColor(foreground);
129 if (std::get<6>(para)) {
130 style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(5, 5), 2));
131 }
132
133 auto decoration = (i % 4);
134 if (decoration == 3) {
135 decoration = 4;
136 }
137
138 bool test = (TextDecoration)decoration != TextDecoration::kNoDecoration;
139 std::string deco = std::to_string((int)decoration);
140 if (test) {
141 style.setDecoration((TextDecoration)decoration);
142 style.setDecorationStyle(std::get<7>(para));
143 style.setDecorationColor(std::get<5>(para));
144 }
145 builder.pushStyle(style);
146 std::string name = " " + std::get<0>(para) + " " +
147 (std::get<1>(para) ? ", bold" : "") +
148 (std::get<2>(para) ? ", italic" : "") + " " +
149 std::to_string(std::get<3>(para) * i) +
150 (std::get<4>(para) != bg ? ", background" : "") +
151 (std::get<5>(para) != fg ? ", foreground" : "") +
152 (std::get<6>(para) ? ", shadow" : "") +
153 (test ? ", decorations " + deco : "") + ";";
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400154 builder.addText(name.c_str(), name.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400155 builder.pop();
156 }
157
158 auto paragraph = builder.Build();
159 paragraph->layout(w - margin * 2);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400160 paragraph->paint(canvas, margin, margin);
161
162 canvas->translate(0, paragraph->getHeight());
163 }
164 }
165
166 void onDrawContent(SkCanvas* canvas) override {
167 drawTest(canvas, this->width(), this->height(), SK_ColorRED, SK_ColorWHITE);
168 }
169
170private:
171
172 typedef Sample INHERITED;
173};
174
Mike Reed21a940d2019-07-23 10:11:03 -0400175class ParagraphView2 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400176protected:
Hal Canary8a027312019-07-03 10:55:44 -0400177 SkString name() override { return SkString("Paragraph2"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400178
179 void drawCode(SkCanvas* canvas, SkScalar w, SkScalar h) {
180 SkPaint comment;
181 comment.setColor(SK_ColorGRAY);
182 SkPaint constant;
183 constant.setColor(SK_ColorMAGENTA);
184 SkPaint null;
185 null.setColor(SK_ColorMAGENTA);
186 SkPaint literal;
187 literal.setColor(SK_ColorGREEN);
188 SkPaint code;
189 code.setColor(SK_ColorDKGRAY);
190 SkPaint number;
191 number.setColor(SK_ColorBLUE);
192 SkPaint name;
193 name.setColor(SK_ColorRED);
194
195 SkPaint white;
196 white.setColor(SK_ColorWHITE);
197
198 TextStyle defaultStyle;
199 defaultStyle.setBackgroundColor(white);
200 defaultStyle.setForegroundColor(code);
201 defaultStyle.setFontFamilies({SkString("monospace")});
202 defaultStyle.setFontSize(30);
203 ParagraphStyle paraStyle;
204 paraStyle.setTextStyle(defaultStyle);
205
Julia Lavrova5207f352019-06-21 12:22:32 -0400206 auto fontCollection = sk_make_sp<FontCollection>();
207 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
208 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400209
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400210 const char* text1 = "RaisedButton";
211 const char* text2 = "(\n";
212 const char* text3 = " child: ";
213 const char* text4 = "const";
214 const char* text5 = "Text";
215 const char* text6 = "'BUTTON TITLE'";
216 const char* text7 = "),\n";
217
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400218 builder.pushStyle(style(name));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400219 builder.addText(text1, strlen(text1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400220 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400221 builder.addText(text2, strlen(text2));
222 builder.addText(text3, strlen(text3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400223 builder.pushStyle(style(constant));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400224 builder.addText(text4, strlen(text4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400225 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400226 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400227 builder.pushStyle(style(name));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400228 builder.addText(text5, strlen(text5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400229 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400230 builder.addText("(", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400231 builder.pushStyle(style(literal));
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400232 builder.addText(text6, strlen(text6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400233 builder.pop();
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400234 builder.addText(text7, strlen(text7));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400235
236 auto paragraph = builder.Build();
237 paragraph->layout(w - 20);
238
239 paragraph->paint(canvas, 20, 20);
240 }
241
242 TextStyle style(SkPaint paint) {
243 TextStyle style;
244 paint.setAntiAlias(true);
245 style.setForegroundColor(paint);
246 style.setFontFamilies({SkString("monospace")});
247 style.setFontSize(30);
248
249 return style;
250 }
251
Julia Lavrova5207f352019-06-21 12:22:32 -0400252 void drawText(SkCanvas* canvas, SkScalar w, SkScalar h, std::vector<const char*>& text,
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400253 SkColor fg = SK_ColorDKGRAY, SkColor bg = SK_ColorWHITE,
254 const char* ff = "sans-serif", SkScalar fs = 24,
255 size_t lineLimit = 30,
256 const std::u16string& ellipsis = u"\u2026") {
257 SkAutoCanvasRestore acr(canvas, true);
258
259 canvas->clipRect(SkRect::MakeWH(w, h));
260 canvas->drawColor(bg);
261
262 SkScalar margin = 20;
263
264 SkPaint paint;
265 paint.setAntiAlias(true);
266 paint.setColor(fg);
267
268 SkPaint blue;
269 blue.setColor(SK_ColorBLUE);
270
271 SkPaint background;
272 background.setColor(bg);
273
274 TextStyle style;
275 style.setBackgroundColor(blue);
276 style.setForegroundColor(paint);
277 style.setFontFamilies({SkString(ff)});
278 style.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight,
279 SkFontStyle::kNormal_Width,
280 SkFontStyle::kUpright_Slant));
281 style.setFontSize(fs);
282 ParagraphStyle paraStyle;
283 paraStyle.setTextStyle(style);
284 paraStyle.setMaxLines(lineLimit);
285
286 paraStyle.setEllipsis(ellipsis);
287 TextStyle defaultStyle;
288 defaultStyle.setFontSize(20);
289 paraStyle.setTextStyle(defaultStyle);
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400290 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400291
292 SkPaint foreground;
293 foreground.setColor(fg);
294 style.setForegroundColor(foreground);
295 style.setBackgroundColor(background);
296
297 for (auto& part : text) {
298 builder.pushStyle(style);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400299 builder.addText(part, strlen(part));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400300 builder.pop();
301 }
302
303 auto paragraph = builder.Build();
304 paragraph->layout(w - margin * 2);
305 paragraph->paint(canvas, margin, margin);
306
307 canvas->translate(0, paragraph->getHeight() + margin);
308 }
309
310 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
311 TextAlign align) {
312 SkAutoCanvasRestore acr(canvas, true);
313
314 canvas->clipRect(SkRect::MakeWH(w, h));
315 canvas->drawColor(SK_ColorWHITE);
316
317 SkScalar margin = 20;
318
319 SkPaint paint;
320 paint.setAntiAlias(true);
321 paint.setColor(SK_ColorBLUE);
322
323 SkPaint gray;
324 gray.setColor(SK_ColorLTGRAY);
325
326 TextStyle style;
327 style.setBackgroundColor(gray);
328 style.setForegroundColor(paint);
329 style.setFontFamilies({SkString("Arial")});
330 style.setFontSize(30);
331 ParagraphStyle paraStyle;
332 paraStyle.setTextStyle(style);
333 paraStyle.setTextAlign(align);
334
Julia Lavrova5207f352019-06-21 12:22:32 -0400335 auto fontCollection = sk_make_sp<FontCollection>();
336 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
337 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400338 builder.addText(text.c_str(), text.length());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400339
340 auto paragraph = builder.Build();
341 paragraph->layout(w - margin * 2);
342 paragraph->layout(w - margin);
343 paragraph->paint(canvas, margin, margin);
344
345 canvas->translate(0, paragraph->getHeight() + margin);
346 }
347
348 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrova5207f352019-06-21 12:22:32 -0400349 std::vector<const char*> cupertino = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400350 "google_logogoogle_gsuper_g_logo 1 "
351 "google_logogoogle_gsuper_g_logo 12 "
352 "google_logogoogle_gsuper_g_logo 123 "
353 "google_logogoogle_gsuper_g_logo 1234 "
354 "google_logogoogle_gsuper_g_logo 12345 "
355 "google_logogoogle_gsuper_g_logo 123456 "
356 "google_logogoogle_gsuper_g_logo 1234567 "
357 "google_logogoogle_gsuper_g_logo 12345678 "
358 "google_logogoogle_gsuper_g_logo 123456789 "
359 "google_logogoogle_gsuper_g_logo 1234567890 "
360 "google_logogoogle_gsuper_g_logo 123456789 "
361 "google_logogoogle_gsuper_g_logo 12345678 "
362 "google_logogoogle_gsuper_g_logo 1234567 "
363 "google_logogoogle_gsuper_g_logo 123456 "
364 "google_logogoogle_gsuper_g_logo 12345 "
365 "google_logogoogle_gsuper_g_logo 1234 "
366 "google_logogoogle_gsuper_g_logo 123 "
367 "google_logogoogle_gsuper_g_logo 12 "
368 "google_logogoogle_gsuper_g_logo 1 "
369 "google_logogoogle_gsuper_g_logo "
370 "google_logogoogle_gsuper_g_logo "
371 "google_logogoogle_gsuper_g_logo "
372 "google_logogoogle_gsuper_g_logo "
373 "google_logogoogle_gsuper_g_logo "
374 "google_logogoogle_gsuper_g_logo"};
Julia Lavrova5207f352019-06-21 12:22:32 -0400375 std::vector<const char*> text = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400376 "My neighbor came over to say,\n"
377 "Although not in a neighborly way,\n\n"
378 "That he'd knock me around,\n\n\n"
379 "If I didn't stop the sound,\n\n\n\n"
380 "Of the classical music I play."};
381
Julia Lavrova5207f352019-06-21 12:22:32 -0400382 std::vector<const char*> long_word = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400383 "A_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
384 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
385 "very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_"
386 "very_very_very_very_very_very_very_long_text"};
387
Julia Lavrova5207f352019-06-21 12:22:32 -0400388 std::vector<const char*> very_long = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400389 "A very very very very very very very very very very very very very very very very "
390 "very very very very very very very very very very very very very very very very "
391 "very very very very very very very very very very very very very very very very "
392 "very very very very very very very long text"};
393
Julia Lavrova5207f352019-06-21 12:22:32 -0400394 std::vector<const char*> very_word = {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400395 "A very_very_very_very_very_very_very_very_very_very "
396 "very_very_very_very_very_very_very_very_very_very very very very very very very "
397 "very very very very very very very very very very very very very very very very "
398 "very very very very very very very very very very very very very long text"};
399
400 SkScalar width = this->width() / 5;
401 SkScalar height = this->height();
402 drawText(canvas, width, height, long_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
403 canvas->translate(width, 0);
404 drawText(canvas, width, height, very_long, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
405 canvas->translate(width, 0);
406 drawText(canvas, width, height, very_word, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
407 canvas->translate(width, 0);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400408 drawText(canvas, width, height / 2, text, SK_ColorBLACK, SK_ColorWHITE, "Roboto", 20, 100,
409 u"\u2026");
410 canvas->translate(0, height / 2);
411 drawCode(canvas, width, height / 2);
412 canvas->translate(width, -height / 2);
413
414 drawText(canvas, width, height, cupertino, SK_ColorBLACK, SK_ColorWHITE, "Google Sans", 30);
415 }
416
417private:
418 typedef Sample INHERITED;
419};
420
Mike Reed21a940d2019-07-23 10:11:03 -0400421class ParagraphView3 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400422protected:
Hal Canary8a027312019-07-03 10:55:44 -0400423 SkString name() override { return SkString("Paragraph3"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400424
425 void drawLine(SkCanvas* canvas, SkScalar w, SkScalar h, const std::string& text,
426 TextAlign align, size_t lineLimit = std::numeric_limits<size_t>::max(),
427 bool RTL = false, SkColor background = SK_ColorGRAY,
428 const std::u16string& ellipsis = u"\u2026") {
429 SkAutoCanvasRestore acr(canvas, true);
430
431 canvas->clipRect(SkRect::MakeWH(w, h));
432 canvas->drawColor(SK_ColorWHITE);
433
434 SkScalar margin = 20;
435
436 SkPaint paint;
437 paint.setAntiAlias(true);
438 paint.setColor(SK_ColorBLACK);
439
440 SkPaint gray;
441 gray.setColor(background);
442
443 SkPaint yellow;
444 yellow.setColor(SK_ColorYELLOW);
445
446 TextStyle style;
447 style.setBackgroundColor(gray);
448 style.setForegroundColor(paint);
449 style.setFontFamilies({SkString("sans-serif")});
450 style.setFontSize(30);
451 ParagraphStyle paraStyle;
452 paraStyle.setTextStyle(style);
453 paraStyle.setTextAlign(align);
454 paraStyle.setMaxLines(lineLimit);
455 paraStyle.setEllipsis(ellipsis);
456 // paraStyle.setTextDirection(RTL ? SkTextDirection::rtl : SkTextDirection::ltr);
457
Julia Lavrova5207f352019-06-21 12:22:32 -0400458 auto fontCollection = sk_make_sp<FontCollection>();
459 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
460 ParagraphBuilderImpl builder(paraStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400461 if (RTL) {
462 builder.addText(mirror(text));
463 } else {
464 builder.addText(normal(text));
465 }
466
467 canvas->drawRect(SkRect::MakeXYWH(margin, margin, w - margin * 2, h - margin * 2), yellow);
468 auto paragraph = builder.Build();
469 paragraph->layout(w - margin * 2);
470 paragraph->paint(canvas, margin, margin);
471 }
472
473 std::u16string mirror(const std::string& text) {
474 std::u16string result;
475 result += u"\u202E";
476 // for (auto i = text.size(); i > 0; --i) {
477 // result += text[i - 1];
478 //}
479
480 for (auto i = text.size(); i > 0; --i) {
481 auto ch = text[i - 1];
482 if (ch == ',') {
483 result += u"!";
484 } else if (ch == '.') {
485 result += u"!";
486 } else {
487 result += ch;
488 }
489 }
490
491 result += u"\u202C";
492 return result;
493 }
494
495 std::u16string normal(const std::string& text) {
496 std::u16string result;
497 result += u"\u202D";
498 for (auto ch : text) {
499 result += ch;
500 }
501 result += u"\u202C";
502 return result;
503 }
504
505 void onDrawContent(SkCanvas* canvas) override {
506 const std::string options = // { "open-source open-source open-source open-source" };
507 {"Flutter is an open-source project to help developers "
508 "build high-performance, high-fidelity, mobile apps for "
509 "iOS and Android "
510 "from a single codebase. This design lab is a playground "
511 "and showcase of Flutter's many widgets, behaviors, "
512 "animations, layouts, and more."};
513
514 canvas->drawColor(SK_ColorDKGRAY);
515 SkScalar width = this->width() / 4;
516 SkScalar height = this->height() / 2;
517
518 const std::string line =
519 "World domination is such an ugly phrase - I prefer to call it world optimisation";
520
521 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, false, SK_ColorLTGRAY);
522 canvas->translate(width, 0);
523 drawLine(canvas, width, height, line, TextAlign::kRight, 2, false, SK_ColorLTGRAY);
524 canvas->translate(width, 0);
525 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, false, SK_ColorLTGRAY);
526 canvas->translate(width, 0);
527 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, false, SK_ColorLTGRAY);
528 canvas->translate(-width * 3, height);
529
530 drawLine(canvas, width, height, line, TextAlign::kLeft, 1, true, SK_ColorLTGRAY);
531 canvas->translate(width, 0);
532 drawLine(canvas, width, height, line, TextAlign::kRight, 2, true, SK_ColorLTGRAY);
533 canvas->translate(width, 0);
534 drawLine(canvas, width, height, line, TextAlign::kCenter, 3, true, SK_ColorLTGRAY);
535 canvas->translate(width, 0);
536 drawLine(canvas, width, height, line, TextAlign::kJustify, 4, true, SK_ColorLTGRAY);
537 canvas->translate(width, 0);
538 }
539
540private:
541 typedef Sample INHERITED;
542};
543
Mike Reed21a940d2019-07-23 10:11:03 -0400544class ParagraphView4 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400545protected:
Hal Canary8a027312019-07-03 10:55:44 -0400546 SkString name() override { return SkString("Paragraph4"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400547
548 void drawFlutter(SkCanvas* canvas, SkScalar w, SkScalar h,
549 const char* ff = "Google Sans", SkScalar fs = 30,
550 size_t lineLimit = std::numeric_limits<size_t>::max(),
551 const std::u16string& ellipsis = u"\u2026") {
552 SkAutoCanvasRestore acr(canvas, true);
553
554 canvas->clipRect(SkRect::MakeWH(w, h));
555
556 SkScalar margin = 20;
557
558 SkPaint black;
559 black.setAntiAlias(true);
560 black.setColor(SK_ColorBLACK);
561
562 SkPaint blue;
563 blue.setAntiAlias(true);
564 blue.setColor(SK_ColorBLUE);
565
566 SkPaint red;
567 red.setAntiAlias(true);
568 red.setColor(SK_ColorRED);
569
570 SkPaint green;
571 green.setAntiAlias(true);
572 green.setColor(SK_ColorGREEN);
573
574 SkPaint gray;
575 gray.setColor(SK_ColorLTGRAY);
576
577 SkPaint yellow;
578 yellow.setColor(SK_ColorYELLOW);
579
580 SkPaint magenta;
581 magenta.setAntiAlias(true);
582 magenta.setColor(SK_ColorMAGENTA);
583
584 TextStyle style;
585 style.setFontFamilies({SkString(ff)});
586 style.setFontSize(fs);
587
588 TextStyle style0;
589 style0.setForegroundColor(black);
590 style0.setBackgroundColor(gray);
591 style0.setFontFamilies({SkString(ff)});
592 style0.setFontSize(fs);
593 style0.setDecoration(TextDecoration::kUnderline);
594 style0.setDecorationStyle(TextDecorationStyle::kDouble);
595 style0.setDecorationColor(SK_ColorBLACK);
596
597 TextStyle style1;
598 style1.setForegroundColor(blue);
599 style1.setBackgroundColor(yellow);
600 style1.setFontFamilies({SkString(ff)});
601 style1.setFontSize(fs);
602 style1.setDecoration(TextDecoration::kOverline);
603 style1.setDecorationStyle(TextDecorationStyle::kWavy);
604 style1.setDecorationColor(SK_ColorBLACK);
605
606 TextStyle style2;
607 style2.setForegroundColor(red);
608 style2.setFontFamilies({SkString(ff)});
609 style2.setFontSize(fs);
610
611 TextStyle style3;
612 style3.setForegroundColor(green);
613 style3.setFontFamilies({SkString(ff)});
614 style3.setFontSize(fs);
615
616 TextStyle style4;
617 style4.setForegroundColor(magenta);
618 style4.setFontFamilies({SkString(ff)});
619 style4.setFontSize(fs);
620
621 ParagraphStyle paraStyle;
622 paraStyle.setTextStyle(style);
623 paraStyle.setMaxLines(lineLimit);
624
625 paraStyle.setEllipsis(ellipsis);
626
627 const char* logo1 = "google_";
628 const char* logo2 = "logo";
629 const char* logo3 = "go";
630 const char* logo4 = "ogle_logo";
631 const char* logo5 = "google_lo";
632 const char* logo6 = "go";
633 {
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400634 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400635
636 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400637 builder.addText(logo1, strlen(logo1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400638 builder.pop();
639 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400640 builder.addText(logo2, strlen(logo2));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400641 builder.pop();
642
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400643 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400644
645 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400646 builder.addText(logo3, strlen(logo3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400647 builder.pop();
648 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400649 builder.addText(logo4, strlen(logo4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400650 builder.pop();
651
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400652 builder.addText(" ", 1);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400653
654 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400655 builder.addText(logo5, strlen(logo5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400656 builder.pop();
657 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400658 builder.addText(logo6, strlen(logo6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400659 builder.pop();
660
661 auto paragraph = builder.Build();
662 paragraph->layout(w - margin * 2);
663 paragraph->paint(canvas, margin, margin);
664 canvas->translate(0, h + margin);
665 }
666 }
667
668 void onDrawContent(SkCanvas* canvas) override {
669 canvas->drawColor(SK_ColorWHITE);
670 SkScalar width = this->width();
671 SkScalar height = this->height();
672
673 drawFlutter(canvas, width, height / 2);
674 }
675
676private:
677 typedef Sample INHERITED;
678};
679
Mike Reed21a940d2019-07-23 10:11:03 -0400680class ParagraphView5 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400681protected:
Julia Lavrova5207f352019-06-21 12:22:32 -0400682 SkString name() override { return SkString("Paragraph5"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400683
684 void bidi(SkCanvas* canvas, SkScalar w, SkScalar h, const std::u16string& text,
685 const std::u16string& expected, size_t lineLimit = std::numeric_limits<size_t>::max(),
686 const char* ff = "Roboto", SkScalar fs = 30,
687 const std::u16string& ellipsis = u"\u2026") {
688 SkAutoCanvasRestore acr(canvas, true);
689
690 canvas->clipRect(SkRect::MakeWH(w, h));
691
692 SkScalar margin = 20;
693
694 SkPaint black;
695 black.setColor(SK_ColorBLACK);
696 SkPaint gray;
697 gray.setColor(SK_ColorLTGRAY);
698
699 TextStyle style;
700 style.setForegroundColor(black);
701 style.setFontFamilies({SkString(ff)});
702 style.setFontSize(fs);
703
704 TextStyle style0;
705 style0.setForegroundColor(black);
706 style0.setFontFamilies({SkString(ff)});
707 style0.setFontSize(fs);
708 style0.setFontStyle(SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width,
709 SkFontStyle::kItalic_Slant));
710
711 TextStyle style1;
712 style1.setForegroundColor(gray);
713 style1.setFontFamilies({SkString(ff)});
714 style1.setFontSize(fs);
715 style1.setFontStyle(SkFontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width,
716 SkFontStyle::kUpright_Slant));
717
718 ParagraphStyle paraStyle;
719 paraStyle.setTextStyle(style);
720 paraStyle.setMaxLines(lineLimit);
721
722 paraStyle.setEllipsis(ellipsis);
723
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400724 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400725
726 if (text.empty()) {
727 const std::u16string text0 = u"\u202Dabc";
728 const std::u16string text1 = u"\u202EFED";
729 const std::u16string text2 = u"\u202Dghi";
730 const std::u16string text3 = u"\u202ELKJ";
731 const std::u16string text4 = u"\u202Dmno";
732 builder.pushStyle(style0);
733 builder.addText(text0);
734 builder.pop();
735 builder.pushStyle(style1);
736 builder.addText(text1);
737 builder.pop();
738 builder.pushStyle(style0);
739 builder.addText(text2);
740 builder.pop();
741 builder.pushStyle(style1);
742 builder.addText(text3);
743 builder.pop();
744 builder.pushStyle(style0);
745 builder.addText(text4);
746 builder.pop();
747 } else {
Ben Wagner056d5432020-05-13 10:24:15 -0400748 if (this->isVerbose()) {
749 icu::UnicodeString unicode((UChar*) text.data(), SkToS32(text.size()));
750 std::string str;
751 unicode.toUTF8String(str);
752 SkDebugf("Text: %s\n", str.c_str());
753 }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400754 builder.addText(text + expected);
755 }
756
757 auto paragraph = builder.Build();
758 paragraph->layout(w - margin * 2);
759 paragraph->paint(canvas, margin, margin);
760 }
761
762 void onDrawContent(SkCanvas* canvas) override {
763 canvas->drawColor(SK_ColorWHITE);
764 SkScalar width = this->width();
765 SkScalar height = this->height() / 8;
766
767 const std::u16string text1 =
768 u"A \u202ENAC\u202Cner, exceedingly \u202ENAC\u202Cny,\n"
769 "One morning remarked to his granny:\n"
770 "A \u202ENAC\u202Cner \u202ENAC\u202C \u202ENAC\u202C,\n"
771 "Anything that he \u202ENAC\u202C,\n"
772 "But a \u202ENAC\u202Cner \u202ENAC\u202C't \u202ENAC\u202C a \u202ENAC\u202C, "
773 "\u202ENAC\u202C he?";
774 bidi(canvas, width, height * 3, text1, u"", 5);
775 canvas->translate(0, height * 3);
776
777 bidi(canvas, width, height, u"\u2067DETALOSI\u2069", u"");
778 canvas->translate(0, height);
779
780 bidi(canvas, width, height, u"\u202BDEDDEBME\u202C", u"");
781 canvas->translate(0, height);
782
783 bidi(canvas, width, height, u"\u202EEDIRREVO\u202C", u"");
784 canvas->translate(0, height);
785
786 bidi(canvas, width, height, u"\u200FTICILPMI\u200E", u"");
787 canvas->translate(0, height);
788
789 bidi(canvas, width, height, u"123 456 7890 \u202EZYXWV UTS RQP ONM LKJ IHG FED CBA\u202C.",
790 u"", 2);
791 canvas->translate(0, height);
792
793 // bidi(canvas, width, height, u"", u"");
794 // canvas->translate(0, height);
795 }
796
797private:
798 typedef Sample INHERITED;
799};
800
Mike Reed21a940d2019-07-23 10:11:03 -0400801class ParagraphView6 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400802protected:
Julia Lavrova5207f352019-06-21 12:22:32 -0400803 SkString name() override { return SkString("Paragraph6"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400804
805 void hangingS(SkCanvas* canvas, SkScalar w, SkScalar h, SkScalar fs = 60.0) {
806 auto ff = "HangingS";
807
808 canvas->drawColor(SK_ColorLTGRAY);
809
810 SkPaint black;
811 black.setAntiAlias(true);
812 black.setColor(SK_ColorBLACK);
813
814 SkPaint blue;
815 blue.setAntiAlias(true);
816 blue.setColor(SK_ColorBLUE);
817
818 SkPaint red;
819 red.setAntiAlias(true);
820 red.setColor(SK_ColorRED);
821
822 SkPaint green;
823 green.setAntiAlias(true);
824 green.setColor(SK_ColorGREEN);
825
826 SkPaint gray;
827 gray.setColor(SK_ColorCYAN);
828
829 SkPaint yellow;
830 yellow.setColor(SK_ColorYELLOW);
831
832 SkPaint magenta;
833 magenta.setAntiAlias(true);
834 magenta.setColor(SK_ColorMAGENTA);
835
836 SkFontStyle fontStyle(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width,
837 SkFontStyle::kItalic_Slant);
838
839 TextStyle style;
840 style.setFontFamilies({SkString(ff)});
841 style.setFontSize(fs);
842 style.setFontStyle(fontStyle);
843
844 TextStyle style0;
845 style0.setForegroundColor(black);
846 style0.setBackgroundColor(gray);
847 style0.setFontFamilies({SkString(ff)});
848 style0.setFontSize(fs);
849 style0.setFontStyle(fontStyle);
850
851 TextStyle style1;
852 style1.setForegroundColor(blue);
853 style1.setBackgroundColor(yellow);
854 style1.setFontFamilies({SkString(ff)});
855 style1.setFontSize(fs);
856 style1.setFontStyle(fontStyle);
857
858 TextStyle style2;
859 style2.setForegroundColor(red);
860 style2.setFontFamilies({SkString(ff)});
861 style2.setFontSize(fs);
862 style2.setFontStyle(fontStyle);
863
864 TextStyle style3;
865 style3.setForegroundColor(green);
866 style3.setFontFamilies({SkString(ff)});
867 style3.setFontSize(fs);
868 style3.setFontStyle(fontStyle);
869
870 TextStyle style4;
871 style4.setForegroundColor(magenta);
872 style4.setFontFamilies({SkString(ff)});
873 style4.setFontSize(fs);
874 style4.setFontStyle(fontStyle);
875
876 ParagraphStyle paraStyle;
877 paraStyle.setTextStyle(style);
878
879 const char* logo1 = "S";
880 const char* logo2 = "kia";
881 const char* logo3 = "Sk";
882 const char* logo4 = "ia";
883 const char* logo5 = "Ski";
884 const char* logo6 = "a";
885 {
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400886 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400887
888 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400889 builder.addText(logo1, strlen(logo1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400890 builder.pop();
891 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400892 builder.addText(logo2, strlen(logo2));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400893 builder.pop();
894
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400895 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400896
897 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400898 builder.addText(logo3, strlen(logo3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400899 builder.pop();
900 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400901 builder.addText(logo4, strlen(logo4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400902 builder.pop();
903
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400904 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400905
906 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400907 builder.addText(logo5, strlen(logo5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400908 builder.pop();
909 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400910 builder.addText(logo6, strlen(logo6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400911 builder.pop();
912
913 auto paragraph = builder.Build();
914 paragraph->layout(w);
915 paragraph->paint(canvas, 40, 40);
916 canvas->translate(0, h);
917 }
918
919 const char* logo11 = "S";
920 const char* logo12 = "S";
921 const char* logo13 = "S";
922 const char* logo14 = "S";
923 const char* logo15 = "S";
924 const char* logo16 = "S";
925 {
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400926 ParagraphBuilderImpl builder(paraStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400927
928 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400929 builder.addText(logo11, strlen(logo1));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400930 builder.pop();
931 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400932 builder.addText(logo12, strlen(logo2));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400933 builder.pop();
934
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400935 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400936
937 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400938 builder.addText(logo13, strlen(logo3));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400939 builder.pop();
940 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400941 builder.addText(logo14, strlen(logo4));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400942 builder.pop();
943
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400944 builder.addText(" ", 3);
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400945
946 builder.pushStyle(style0);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400947 builder.addText(logo15, strlen(logo5));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400948 builder.pop();
949 builder.pushStyle(style1);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400950 builder.addText(logo16, strlen(logo6));
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400951 builder.pop();
952
953 auto paragraph = builder.Build();
954 paragraph->layout(w);
955 paragraph->paint(canvas, 40, h);
956 canvas->translate(0, h);
957 }
958 }
959
960 void onDrawContent(SkCanvas* canvas) override {
961 canvas->drawColor(SK_ColorWHITE);
962 SkScalar width = this->width();
963 SkScalar height = this->height() / 4;
964
965 hangingS(canvas, width, height);
966 }
967
968private:
969 typedef Sample INHERITED;
970};
971
Mike Reed21a940d2019-07-23 10:11:03 -0400972class ParagraphView7 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400973protected:
Hal Canary8a027312019-07-03 10:55:44 -0400974 SkString name() override { return SkString("Paragraph7"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400975
976 void drawText(SkCanvas* canvas, SkColor background, SkScalar letterSpace, SkScalar w,
977 SkScalar h) {
978 SkAutoCanvasRestore acr(canvas, true);
979 canvas->clipRect(SkRect::MakeWH(w, h));
980 canvas->drawColor(background);
981
982 const char* line =
Julia Lavrovadb9f6692019-08-01 16:02:17 -0400983 "World domination is such an ugly phrase - I prefer to call it world optimisation.";
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400984
985 ParagraphStyle paragraphStyle;
986 paragraphStyle.setTextAlign(TextAlign::kLeft);
987 paragraphStyle.setMaxLines(10);
988 paragraphStyle.turnHintingOff();
989 TextStyle textStyle;
990 textStyle.setFontFamilies({SkString("Roboto")});
991 textStyle.setFontSize(30);
992 textStyle.setLetterSpacing(letterSpace);
993 textStyle.setColor(SK_ColorBLACK);
994 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
995 SkFontStyle::kUpright_Slant));
996
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -0400997 ParagraphBuilderImpl builder(paragraphStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400998 builder.pushStyle(textStyle);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -0400999 builder.addText(line, strlen(line));
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001000 builder.pop();
1001
1002 auto paragraph = builder.Build();
1003 paragraph->layout(w - 20);
1004 paragraph->paint(canvas, 10, 10);
1005 }
1006
1007 void onDrawContent(SkCanvas* canvas) override {
1008 canvas->drawColor(SK_ColorWHITE);
1009
1010 auto h = this->height() / 4;
1011 auto w = this->width() / 2;
1012
1013 drawText(canvas, SK_ColorGRAY, 1, w, h);
1014 canvas->translate(0, h);
1015
1016 drawText(canvas, SK_ColorLTGRAY, 2, w, h);
1017 canvas->translate(0, h);
1018
1019 drawText(canvas, SK_ColorCYAN, 3, w, h);
1020 canvas->translate(0, h);
1021
1022 drawText(canvas, SK_ColorGRAY, 4, w, h);
1023 canvas->translate(w, -3 * h);
1024
1025 drawText(canvas, SK_ColorYELLOW, 5, w, h);
1026 canvas->translate(0, h);
1027
1028 drawText(canvas, SK_ColorGREEN, 10, w, h);
1029 canvas->translate(0, h);
1030
1031 drawText(canvas, SK_ColorRED, 15, w, h);
1032 canvas->translate(0, h);
1033
1034 drawText(canvas, SK_ColorBLUE, 20, w, h);
1035 canvas->translate(0, h);
1036 }
1037
1038private:
1039 typedef Sample INHERITED;
1040};
1041
Mike Reed21a940d2019-07-23 10:11:03 -04001042class ParagraphView8 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001043protected:
Julia Lavrovadb9f6692019-08-01 16:02:17 -04001044 SkString name() override { return SkString("Paragraph8"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001045
1046 void drawText(SkCanvas* canvas, SkColor background, SkScalar wordSpace, SkScalar w,
1047 SkScalar h) {
1048 SkAutoCanvasRestore acr(canvas, true);
1049 canvas->clipRect(SkRect::MakeWH(w, h));
1050 canvas->drawColor(background);
1051
1052 const char* line =
Julia Lavrovadb9f6692019-08-01 16:02:17 -04001053 "World domination is such an ugly phrase - I prefer to call it world optimisation.";
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001054
1055 ParagraphStyle paragraphStyle;
1056 paragraphStyle.setTextAlign(TextAlign::kLeft);
1057 paragraphStyle.setMaxLines(10);
1058 paragraphStyle.turnHintingOff();
1059 TextStyle textStyle;
1060 textStyle.setFontFamilies({SkString("Roboto")});
1061 textStyle.setFontSize(30);
1062 textStyle.setWordSpacing(wordSpace);
1063 textStyle.setColor(SK_ColorBLACK);
1064 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
1065 SkFontStyle::kUpright_Slant));
1066
Julia Lavrovab7b0b3a2019-07-30 13:32:08 -04001067 ParagraphBuilderImpl builder(paragraphStyle, getFontCollection());
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001068 builder.pushStyle(textStyle);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -04001069 builder.addText(line, strlen(line));
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001070 builder.pop();
1071
1072 auto paragraph = builder.Build();
1073 paragraph->layout(w - 20);
1074 paragraph->paint(canvas, 10, 10);
1075 }
1076
1077 void onDrawContent(SkCanvas* canvas) override {
1078 canvas->drawColor(SK_ColorWHITE);
1079
1080 auto h = this->height() / 4;
1081 auto w = this->width() / 2;
1082
1083 drawText(canvas, SK_ColorGRAY, 1, w, h);
1084 canvas->translate(0, h);
1085
1086 drawText(canvas, SK_ColorLTGRAY, 2, w, h);
1087 canvas->translate(0, h);
1088
1089 drawText(canvas, SK_ColorCYAN, 3, w, h);
1090 canvas->translate(0, h);
1091
1092 drawText(canvas, SK_ColorGRAY, 4, w, h);
1093 canvas->translate(w, -3 * h);
1094
1095 drawText(canvas, SK_ColorYELLOW, 5, w, h);
1096 canvas->translate(0, h);
1097
1098 drawText(canvas, SK_ColorGREEN, 10, w, h);
1099 canvas->translate(0, h);
1100
1101 drawText(canvas, SK_ColorRED, 15, w, h);
1102 canvas->translate(0, h);
1103
1104 drawText(canvas, SK_ColorBLUE, 20, w, h);
1105 canvas->translate(0, h);
1106 }
1107
1108private:
1109 typedef Sample INHERITED;
1110};
1111
Mike Reed21a940d2019-07-23 10:11:03 -04001112class ParagraphView9 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001113protected:
Hal Canary8a027312019-07-03 10:55:44 -04001114 SkString name() override { return SkString("Paragraph9"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001115
Hal Canary6cc65e12019-07-03 15:53:04 -04001116 bool onChar(SkUnichar uni) override {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001117 switch (uni) {
1118 case 'w':
1119 ++wordSpacing;
1120 return true;
1121 case 'q':
1122 if (wordSpacing > 0) --wordSpacing;
1123 return true;
1124 case 'l':
1125 ++letterSpacing;
1126 return true;
1127 case 'k':
1128 if (letterSpacing > 0) --letterSpacing;
1129 return true;
1130 default:
1131 break;
1132 }
Hal Canary6cc65e12019-07-03 15:53:04 -04001133 return false;
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001134 }
1135
1136 void drawText(SkCanvas* canvas, SkColor background, SkScalar w, SkScalar h) {
1137 SkAutoCanvasRestore acr(canvas, true);
1138 canvas->clipRect(SkRect::MakeWH(w, h));
1139 canvas->drawColor(background);
1140
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001141 auto fontCollection = sk_make_sp<FontCollection>();
1142 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1143 fontCollection->enableFontFallback();
1144
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001145 const char* text =
1146 "( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1147 " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)("
1148 " ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)( ´・‿・`)";
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001149 auto multiplier = 5.67;
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001150 ParagraphStyle paragraphStyle;
1151 paragraphStyle.setTextAlign(TextAlign::kLeft);
1152 paragraphStyle.setMaxLines(10);
1153 paragraphStyle.turnHintingOff();
1154 TextStyle textStyle;
1155 textStyle.setFontFamilies({SkString("Roboto")});
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001156 textStyle.setFontSize(5 * multiplier);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001157 textStyle.setHeight(1.3f);
1158 textStyle.setColor(SK_ColorBLACK);
1159 textStyle.setFontStyle(SkFontStyle(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width,
1160 SkFontStyle::kUpright_Slant));
1161
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001162 ParagraphBuilderImpl builder(paragraphStyle, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001163 builder.pushStyle(textStyle);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -04001164 builder.addText(text, strlen(text));
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001165 builder.pop();
1166
1167 auto paragraph = builder.Build();
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001168 paragraph->layout(200 * multiplier);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001169
1170 std::vector<size_t> sizes = {0, 1, 2, 8, 19, 21, 22, 30, 150};
1171
1172 std::vector<size_t> colors = {SK_ColorBLUE, SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGREEN,
1173 SK_ColorRED, SK_ColorWHITE, SK_ColorYELLOW, SK_ColorMAGENTA};
1174
1175 RectHeightStyle rect_height_style = RectHeightStyle::kTight;
1176 RectWidthStyle rect_width_style = RectWidthStyle::kTight;
1177
1178 for (size_t i = 0; i < sizes.size() - 1; ++i) {
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001179 size_t from = sizes[i];
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001180 size_t to = sizes[i + 1];
1181 auto boxes = paragraph->getRectsForRange(from, to, rect_height_style, rect_width_style);
1182 if (boxes.empty()) {
1183 continue;
1184 }
1185 for (auto& box : boxes) {
1186 SkPaint paint;
1187 paint.setColor(colors[i % colors.size()]);
1188 paint.setShader(setgrad(box.rect, colors[i % colors.size()], SK_ColorWHITE));
1189 canvas->drawRect(box.rect, paint);
1190 }
1191 }
1192
1193 paragraph->paint(canvas, 0, 0);
1194 }
1195
1196 void onDrawContent(SkCanvas* canvas) override {
1197 canvas->drawColor(SK_ColorWHITE);
1198
1199 auto h = this->height();
1200 auto w = this->width();
1201
1202 drawText(canvas, SK_ColorGRAY, w, h);
1203 }
1204
1205private:
1206 typedef Sample INHERITED;
1207 SkScalar letterSpacing;
1208 SkScalar wordSpacing;
1209};
1210
Mike Reed21a940d2019-07-23 10:11:03 -04001211class ParagraphView10 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001212protected:
Hal Canary8a027312019-07-03 10:55:44 -04001213 SkString name() override { return SkString("Paragraph10"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001214
1215 void onDrawContent(SkCanvas* canvas) override {
1216 canvas->drawColor(SK_ColorWHITE);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001217 auto multiplier = 5.67;
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001218 const char* text = "English English 字典 字典 😀😃😄 😀😃😄";
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001219
1220 auto fontCollection = sk_make_sp<FontCollection>();
1221 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1222 fontCollection->enableFontFallback();
1223
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001224 ParagraphStyle paragraph_style;
1225 paragraph_style.turnHintingOff();
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001226 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001227
1228 TextStyle text_style;
Julia Lavrova5207f352019-06-21 12:22:32 -04001229 text_style.setFontFamilies({SkString("Roboto"),
1230 SkString("Noto Color Emoji"),
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001231 SkString("Noto Serif CJK JP")});
1232 text_style.setFontSize(10 * multiplier);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001233 text_style.setLetterSpacing(0);
1234 text_style.setWordSpacing(0);
1235 text_style.setColor(SK_ColorBLACK);
1236 text_style.setHeight(1);
1237 builder.pushStyle(text_style);
Kevin Lubick7aeabcf2019-09-27 15:16:13 -04001238 builder.addText(text, strlen(text));
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001239 builder.pop();
1240
1241 auto paragraph = builder.Build();
1242 paragraph->layout(width());
1243
1244 paragraph->paint(canvas, 0, 0);
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001245 }
1246
1247private:
1248 typedef Sample INHERITED;
1249};
1250
Mike Reed21a940d2019-07-23 10:11:03 -04001251class ParagraphView11 : public ParagraphView_Base {
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001252protected:
Hal Canary8a027312019-07-03 10:55:44 -04001253 SkString name() override { return SkString("Paragraph11"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001254
1255 void onDrawContent(SkCanvas* canvas) override {
1256 canvas->drawColor(SK_ColorWHITE);
Julia Lavrova5207f352019-06-21 12:22:32 -04001257
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001258 auto text = "\U0001f469\U0000200D\U0001f469\U0000200D\U0001f466\U0001f469\U0000200D\U0001f469\U0000200D\U0001f467\U0000200D\U0001f467\U0001f1fa\U0001f1f8";
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001259
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001260 TextStyle text_style;
1261 text_style.setFontFamilies({SkString("Ahem")});
1262 text_style.setColor(SK_ColorBLACK);
1263 text_style.setFontSize(60);
1264 text_style.setLetterSpacing(0);
1265 text_style.setWordSpacing(0);
1266 ParagraphStyle paragraph_style;
1267 paragraph_style.setTextStyle(text_style);
1268
1269 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
1270 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1271 builder.addText(text, strlen(text));
1272 auto paragraph = builder.Build();
1273 paragraph->layout(1000);
1274 paragraph->paint(canvas, 0, 0);
1275
1276 struct pair {
1277 unsigned fX;
1278 unsigned fY;
1279 };
1280
1281 pair hit1[] =
1282 {{ 0, 8},{1, 33}, {2, 34}, { 3, 19}, {4, 20},
1283 { 5, 21}, { 6, 22 }, { 7, 23 }, {8, 24 }, { 9, 25},
1284 { 10, 26}, { 11, 27}, {12, 28}, { 13, 21}, {14, 22 },
1285 { 15, 23}, {16, 24}, {17, 21}, { 18, 22}, {19, 21},
1286 { 20, 24}, { 21, 23}, };
1287
1288 pair miss[] =
1289 {{ 0, 4},{1, 17}, {2, 18}, { 3, 11}, {4, 12},
1290 { 5, 13}, { 6, 14 }, { 7, 15 }, {8, 16 }, { 9, 17},
1291 { 10, 18}, { 11, 19}, {12, 20}, { 13, 17}, {14, 18 },
1292 { 15, 19}, {16, 20}, {17, 19}, { 18, 20},
1293 { 20, 22}, };
1294
1295 auto rects = paragraph->getRectsForRange(7, 9, RectHeightStyle::kTight, RectWidthStyle::kTight);
1296 SkPaint paint;
1297 paint.setColor(SK_ColorRED);
1298 paint.setStyle(SkPaint::kStroke_Style);
1299 paint.setAntiAlias(true);
1300 paint.setStrokeWidth(1);
1301 if (!rects.empty()) {
1302 canvas->drawRect(rects[0].rect, paint);
1303 }
1304
1305 for (auto& query : hit1) {
1306 auto rects = paragraph->getRectsForRange(query.fX, query.fY, RectHeightStyle::kTight, RectWidthStyle::kTight);
1307 if (rects.size() >= 1 && rects[0].rect.width() > 0) {
1308 } else {
Ben Wagner056d5432020-05-13 10:24:15 -04001309 if (this->isVerbose()) {
1310 SkDebugf("+[%d:%d): Bad\n", query.fX, query.fY);
1311 }
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001312 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001313 }
1314
1315 for (auto& query : miss) {
1316 auto miss = paragraph->getRectsForRange(query.fX, query.fY, RectHeightStyle::kTight, RectWidthStyle::kTight);
1317 if (miss.empty()) {
1318 } else {
Ben Wagner056d5432020-05-13 10:24:15 -04001319 if (this->isVerbose()) {
1320 SkDebugf("-[%d:%d): Bad\n", query.fX, query.fY);
1321 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001322 }
1323 }
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001324 }
1325
1326private:
1327 typedef Sample INHERITED;
1328};
1329
1330class ParagraphView12 : public ParagraphView_Base {
1331protected:
1332 SkString name() override { return SkString("Paragraph12"); }
1333
1334 void onDrawContent(SkCanvas* canvas) override {
1335 canvas->drawColor(SK_ColorWHITE);
1336
1337 const char* text = "Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neiges";
1338 TextStyle text_style;
1339 text_style.setFontFamilies({SkString("Ahem")});
1340 text_style.setColor(SK_ColorBLACK);
1341 text_style.setFontSize(16);
1342 //text_style.setLetterSpacing(-0.41);
1343 StrutStyle strut_style;
1344 strut_style.setStrutEnabled(false);
1345 ParagraphStyle paragraph_style;
1346 paragraph_style.setStrutStyle(strut_style);
1347 paragraph_style.setTextStyle(text_style);
1348 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1349 builder.addText(text);
1350 auto paragraph = builder.Build();
1351 paragraph->layout(1095.000000);
1352 auto result = paragraph->getRectsForRange(65, 66, RectHeightStyle::kTight, RectWidthStyle::kTight);
1353 paragraph->paint(canvas, 0, 0);
1354
1355 SkPaint paint;
1356 paint.setColor(SK_ColorRED);
1357 paint.setStyle(SkPaint::kStroke_Style);
1358 paint.setAntiAlias(true);
1359 paint.setStrokeWidth(1);
1360 canvas->drawRect(result.front().rect, paint);
1361 }
1362
1363private:
1364 typedef Sample INHERITED;
1365};
1366
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001367class ParagraphView14 : public ParagraphView_Base {
1368protected:
1369 SkString name() override { return SkString("Paragraph14"); }
1370
1371 void onDrawContent(SkCanvas* canvas) override {
1372 canvas->drawColor(SK_ColorWHITE);
1373 TextStyle text_style;
1374 text_style.setFontFamilies({SkString("Ahem")});
1375 text_style.setColor(SK_ColorBLACK);
1376 text_style.setFontSize(25);
1377 text_style.setDecoration((TextDecoration)(TextDecoration::kUnderline | TextDecoration::kOverline | TextDecoration::kLineThrough));
1378 text_style.setDecorationColor(SK_ColorBLUE);
1379 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
1380 text_style.setDecorationThicknessMultiplier(4.0f);
1381 ParagraphStyle paragraph_style;
1382 paragraph_style.setTextStyle(text_style);
1383 paragraph_style.setTextDirection(TextDirection::kRtl);
1384 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1385 builder.pushStyle(text_style);
1386 builder.addText("Hello, wor!\nabcd.");
1387 auto paragraph = builder.Build();
1388 paragraph->layout(300);
1389 paragraph->paint(canvas, 0, 0);
1390 SkPaint paint;
1391 paint.setColor(SK_ColorRED);
1392 paint.setStyle(SkPaint::kStroke_Style);
1393 paint.setAntiAlias(true);
1394 paint.setStrokeWidth(1);
1395 canvas->drawRect(SkRect::MakeXYWH(0, 0, 300, 100), paint);
1396 }
1397
1398private:
1399 typedef Sample INHERITED;
1400};
1401
1402class ParagraphView15 : public ParagraphView_Base {
1403protected:
1404 SkString name() override { return SkString("Paragraph15"); }
1405
1406 void onDrawContent(SkCanvas* canvas) override {
1407 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04001408
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001409 TextStyle text_style;
1410 text_style.setFontFamilies({SkString("abc.ttf")});
1411 text_style.setFontSize(50);
1412
1413 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false);
1414
1415 fontCollection->addFontFromFile("abc/abc.ttf", "abc");
1416 fontCollection->addFontFromFile("abc/abc+grave.ttf", "abc+grave");
1417 fontCollection->addFontFromFile("abc/abc+agrave.ttf", "abc+agrave");
1418
1419 ParagraphStyle paragraph_style;
1420 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1421
1422 text_style.setFontFamilies({SkString("abc"), SkString("abc+grave")});
1423 text_style.setColor(SK_ColorBLUE);
1424 builder.pushStyle(text_style);
1425 builder.addText(u"a\u0300");
1426 text_style.setColor(SK_ColorMAGENTA);
1427 builder.pushStyle(text_style);
1428 builder.addText(u"à");
1429
1430 text_style.setFontFamilies({SkString("abc"), SkString("abc+agrave")});
1431
1432 text_style.setColor(SK_ColorRED);
1433 builder.pushStyle(text_style);
1434 builder.addText(u"a\u0300");
1435 text_style.setColor(SK_ColorGREEN);
1436 builder.pushStyle(text_style);
1437 builder.addText(u"à");
1438
1439 auto paragraph = builder.Build();
1440 paragraph->layout(800);
1441 paragraph->paint(canvas, 50, 50);
1442
Julia Lavrova5207f352019-06-21 12:22:32 -04001443 }
1444
1445private:
1446 typedef Sample INHERITED;
1447};
1448
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001449class ParagraphView16 : public ParagraphView_Base {
1450protected:
1451 SkString name() override { return SkString("Paragraph16"); }
1452
1453 void onDrawContent(SkCanvas* canvas) override {
1454 canvas->drawColor(SK_ColorWHITE);
1455
1456 const char* text = "content";
1457
1458 ParagraphStyle paragraph_style;
1459 paragraph_style.setMaxLines(1);
1460 paragraph_style.setEllipsis(u"\u2026");
1461 //auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1462 auto fontCollection = sk_make_sp<FontCollection>();
1463 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1464 fontCollection->enableFontFallback();
1465 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1466
1467 TextStyle text_style;
1468 text_style.setFontFamilies({SkString(".SF Pro Text")});
1469 text_style.setColor(SK_ColorBLACK);
1470 text_style.setFontSize(17.0f * 99.0f);
1471 text_style.setLetterSpacing(0.41f);
1472 builder.pushStyle(text_style);
1473 builder.addText(text);
1474
1475 auto paragraph = builder.Build();
1476 paragraph->layout(800);
1477 paragraph->paint(canvas, 0, 0);
1478 }
1479
1480private:
1481 typedef Sample INHERITED;
1482};
1483
1484class ParagraphView17 : public ParagraphView_Base {
1485protected:
1486 SkString name() override { return SkString("Paragraph17"); }
1487
1488 void onDrawContent(SkCanvas* canvas) override {
1489 canvas->drawColor(SK_ColorWHITE);
1490
1491 auto fontCollection = sk_make_sp<FontCollection>();
1492 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1493 fontCollection->enableFontFallback();
1494 auto navy = SkColorSetRGB(0, 0, 139);
1495 auto ltgray = SkColorSetRGB(211, 211, 211);
1496 auto multiplier = 5.67;
1497
1498 const char* text = ">Sͬ͑̀͐̈͒̈́̋̎ͮͩ̽̓ͬ̂̆̔͗́̓ͣͧ͊ͫ͛̉͌̐̑ͪ͗̚͝҉̴͉͢k̡̊̓ͫͭͩ͂͊ͨͪͬ̑ͫ̍̌̄͛̌̂̑̂̋̊̔ͫ͛̽̑ͨ̍ͭ̓̀ͪͪ̉͐͗̌̓̃̚͟͝҉̢͏̫̞̙͇͖̮͕̗̟͕͇͚̻͈̣̻̪͉̰̲̣̫ͅͅP̴̅̍͒̿͗͗̇ͩ̃͆͌̀̽͏̧̡͕͖̝̖̼̺̰̣̬͔͖͔̼͙̞̦̫͓̘͜a̸̴̸̴̢̢̨̨̫͍͓̥̼̭̼̻̤̯̙̤̻̠͚̍̌͋̂ͦͨ̽̇͌͌͆̀̽̎͒̄ͪ̐ͦ̈ͫ͐͗̓̚̚͜ͅr͐͐ͤͫ̐ͥ͂̈́̿́ͮ̃͗̓̏ͫ̀̿͏̸̵̧́͘̕͟͝͠͞͠҉̷̧͚͢͟a̓̽̎̄͗̔͛̄̐͊͛ͫ͂͌̂̂̈̈̓̔̅̅̄͊̉́ͪ̑̄͆ͬ̍͆ͭ͋̐ͬ͏̷̵̨̢̩̹̖͓̥̳̰͔̱̬͖̙͓̙͇̀̀̕͜͟͟͢͟͜͠͡g̨̅̇ͦ͋̂ͦͨͭ̓͐͆̏̂͛̉ͧ̑ͫ̐̒͛ͫ̍̒͛́̚҉̷̨̛̛̀͜͢͞҉̩̘̲͍͎̯̹̝̭̗̱͇͉̲̱͔̯̠̹̥̻͉̲̜̤̰̪̗̺̖̺r̷͌̓̇̅ͭ̀̐̃̃ͭ͑͗̉̈̇̈́ͥ̓ͣ́ͤ͂ͤ͂̏͌̆̚҉̴̸̧̢̢̛̫͉̦̥̤̙͈͉͈͉͓̙̗̟̳̜͈̗̺̟̠̠͖͓̖̪͕̠̕̕͝ͅả̸̴̡̡̧͠͞͡͞҉̛̕͟͏̷̘̪̱͈̲͉̞̠̞̪̫͎̲̬̖̀̀͟͝͞͞͠p̛͂̈͐̚͠҉̵̸̡̢̢̩̹͙̯͖̙̙̮̥̙͚̠͔̥̭̮̞̣̪̬̥̠̖̝̥̪͎́̀̕͜͡͡ͅͅh̵̷̵̡̛ͤ̂͌̐̓̐̋̋͊̒̆̽́̀̀̀͢͠͞͞҉̷̸̢̕҉͚̯͖̫̜̞̟̠̱͉̝̲̹̼͉̟͉̩̮͔̤͖̞̭̙̹̬ͅ<";
1499
1500 ParagraphStyle paragraph_style;
1501 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1502 SkPaint paint;
1503 paint.setColor(ltgray);
1504 TextStyle text_style;
1505 text_style.setBackgroundColor(paint);
1506 text_style.setColor(navy);
1507 text_style.setFontFamilies({SkString("Roboto")});
1508 text_style.setFontSize(20 * multiplier);
1509 builder.pushStyle(text_style);
1510 builder.addText(text);
1511 auto paragraph = builder.Build();
1512 paragraph->layout(10000);
1513 paragraph->paint(canvas, 0, 0);
1514 }
1515
1516private:
1517 typedef Sample INHERITED;
1518};
1519
1520class Zalgo {
1521 private:
1522 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";
1523 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";
1524 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";
1525
1526 std::u16string randomMarks(std::u16string& combiningMarks) {
1527 std::u16string result;
1528 auto num = std::rand() % (combiningMarks.size() / 1);
1529 for (size_t i = 0; i < num; ++i) {
1530 auto index = std::rand() % combiningMarks.size();
1531 result += combiningMarks[index];
1532 }
1533 return result;
1534 }
1535
1536public:
1537 std::u16string zalgo(std::string victim) {
1538 std::u16string result;
1539 for (auto& c : victim) {
1540 result += c;
1541 result += randomMarks(COMBINING_UP);
1542 result += randomMarks(COMBINING_MIDDLE);
1543 result += randomMarks(COMBINING_DOWN);
1544 }
1545 return result;
1546 }
1547};
1548
1549class ParagraphView18 : public ParagraphView_Base {
1550protected:
1551 SkString name() override { return SkString("Paragraph18"); }
1552
1553 bool onChar(SkUnichar uni) override {
1554 switch (uni) {
1555 case ' ':
1556 fLimit = 400;
1557 return true;
1558 case 's':
1559 fLimit += 10;
1560 return true;
1561 case 'f':
1562 if (fLimit > 10) {
1563 fLimit -= 10;
1564 }
1565 return true;
1566 default:
1567 break;
1568 }
1569 return false;
1570 }
1571
1572 bool onAnimate(double nanos) override {
1573 if (++fIndex > fLimit) {
1574 fRedraw = true;
1575 fIndex = 0;
1576 } else {
1577 fRepeat = true;
1578 }
1579 return true;
1580 }
1581
1582 void onDrawContent(SkCanvas* canvas) override {
1583 canvas->drawColor(SK_ColorWHITE);
1584
1585 auto navy = SkColorSetRGB(0, 0, 139);
1586 auto ltgray = SkColorSetRGB(211, 211, 211);
1587
1588 auto multiplier = 5.67;
1589 auto fontCollection = sk_make_sp<FontCollection>();
1590 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
1591 fontCollection->enableFontFallback();
1592
1593 ParagraphStyle paragraph_style;
1594 TextStyle text_style;
1595 text_style.setFontFamilies({SkString("Roboto")});
1596 text_style.setFontSize(20 * multiplier);
1597 text_style.setColor(navy);
1598 SkPaint paint;
1599 paint.setColor(ltgray);
1600 text_style.setBackgroundColor(paint);
1601
1602 Zalgo zalgo;
1603
1604 if (fRedraw || fRepeat) {
1605
1606 if (fRedraw || fParagraph.get() == nullptr) {
1607 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1608 builder.pushStyle(text_style);
1609 auto utf16text = zalgo.zalgo("SkParagraph");
1610 icu::UnicodeString unicode((UChar*)utf16text.data(), SkToS32(utf16text.size()));
1611 std::string str;
1612 unicode.toUTF8String(str);
Ben Wagner056d5432020-05-13 10:24:15 -04001613 if (this->isVerbose()) {
1614 SkDebugf("Text:>%s<\n", str.data());
1615 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001616 builder.addText(utf16text);
1617 fParagraph = builder.Build();
1618 }
1619
1620 auto impl = static_cast<ParagraphImpl*>(fParagraph.get());
1621 impl->setState(InternalState::kUnknown);
1622 fParagraph->layout(1000);
1623 fParagraph->paint(canvas, 300, 200);
1624
1625 for (auto& run : impl->runs()) {
1626 SkString fontFamily("unresolved");
1627 if (run.font().getTypeface() != nullptr) {
1628 run.font().getTypeface()->getFamilyName(&fontFamily);
1629 }
1630 if (run.font().getTypeface() != nullptr) {
1631 for (size_t i = 0; i < run.size(); ++i) {
1632 auto glyph = run.glyphs().begin() + i;
1633 if (*glyph == 0) {
1634 SkDebugf("Run[%d] @pos=%d\n", run.index(), i);
1635 SkASSERT(false);
1636 }
1637 }
1638 } else {
1639 SkDebugf("Run[%d]: %s\n", run.index(), fontFamily.c_str());
1640 SkASSERT(false);
1641 }
1642 }
1643 fRedraw = false;
1644 fRepeat = false;
1645 }
1646 }
1647
1648private:
1649 bool fRedraw = true;
1650 bool fRepeat = false;
1651 size_t fIndex = 0;
1652 size_t fLimit = 20;
1653 std::unique_ptr<Paragraph> fParagraph;
1654 typedef Sample INHERITED;
1655};
1656
1657class ParagraphView19 : public ParagraphView_Base {
1658protected:
1659 SkString name() override { return SkString("Paragraph19"); }
1660
1661 void onDrawContent(SkCanvas* canvas) override {
1662 canvas->drawColor(SK_ColorWHITE);
1663
1664 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1665
Julia Lavrova90bfd1c2019-12-04 11:43:32 -05001666 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 -04001667 ParagraphStyle paragraph_style;
1668 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001669 TextStyle text_style;
Julia Lavrovac028b422019-11-25 10:00:43 -05001670 text_style.setColor(SK_ColorBLACK);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001671 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova90bfd1c2019-12-04 11:43:32 -05001672 text_style.setFontSize(20);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001673 builder.pushStyle(text_style);
1674 builder.addText(text);
1675 auto paragraph = builder.Build();
Julia Lavrovac028b422019-11-25 10:00:43 -05001676 paragraph->layout(this->width());
Julia Lavrovac028b422019-11-25 10:00:43 -05001677 paragraph->paint(canvas, 0, 0);
1678 }
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001679
Julia Lavrovac028b422019-11-25 10:00:43 -05001680private:
1681 typedef Sample INHERITED;
1682};
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001683
Julia Lavrovac028b422019-11-25 10:00:43 -05001684class ParagraphView20 : public ParagraphView_Base {
1685protected:
1686 SkString name() override { return SkString("Paragraph20"); }
1687
1688 void onDrawContent(SkCanvas* canvas) override {
1689 canvas->drawColor(SK_ColorWHITE);
1690
1691 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), false, true);
1692
Julia Lavrovac48687a2020-01-08 16:53:53 -05001693 const char* text = "Manage your google account";
Julia Lavrovac028b422019-11-25 10:00:43 -05001694 ParagraphStyle paragraph_style;
Julia Lavrovac48687a2020-01-08 16:53:53 -05001695 paragraph_style.setEllipsis(u"\u2026");
1696 paragraph_style.setMaxLines(1);
Julia Lavrovac028b422019-11-25 10:00:43 -05001697 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1698 TextStyle text_style;
1699 text_style.setColor(SK_ColorBLACK);
Julia Lavrova53c14472019-12-18 09:39:55 -05001700 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrovac48687a2020-01-08 16:53:53 -05001701 text_style.setFontSize(50);
Julia Lavrovac028b422019-11-25 10:00:43 -05001702 builder.pushStyle(text_style);
1703 builder.addText(text);
1704 auto paragraph = builder.Build();
Julia Lavrovac48687a2020-01-08 16:53:53 -05001705 paragraph->layout(this->width());
1706 paragraph->paint(canvas, 0, 0);
1707 }
1708
1709private:
1710 typedef Sample INHERITED;
1711};
1712
1713class ParagraphView21 : public ParagraphView_Base {
1714protected:
1715 SkString name() override { return SkString("Paragraph21"); }
1716
1717 void onDrawContent(SkCanvas* canvas) override {
1718 canvas->drawColor(SK_ColorWHITE);
1719
Julia Lavrova70e93012020-01-10 14:04:45 -05001720 const char* text = "Referral Code";
Julia Lavrovac48687a2020-01-08 16:53:53 -05001721 ParagraphStyle paragraph_style;
Julia Lavrovaf6a3f8e2020-01-10 10:55:52 -05001722 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
Julia Lavrovac48687a2020-01-08 16:53:53 -05001723 TextStyle text_style;
1724 text_style.setColor(SK_ColorBLACK);
Julia Lavrovaf6a3f8e2020-01-10 10:55:52 -05001725 text_style.setFontFamilies({SkString("Google Sans")});
1726 text_style.setFontSize(24);
Julia Lavrovac48687a2020-01-08 16:53:53 -05001727 builder.pushStyle(text_style);
1728 builder.addText(text);
1729 auto paragraph = builder.Build();
Julia Lavrova70e93012020-01-10 14:04:45 -05001730 paragraph->layout(0);
Julia Lavrovac028b422019-11-25 10:00:43 -05001731 paragraph->paint(canvas, 0, 0);
Julia Lavrova2e30fde2019-10-09 09:43:02 -04001732 }
1733
1734private:
1735 typedef Sample INHERITED;
1736};
Julia Lavrova4cf18742020-01-14 13:24:45 -05001737
1738class ParagraphView22 : public ParagraphView_Base {
1739protected:
1740 SkString name() override { return SkString("Paragraph22"); }
1741
Julia Lavrova9bd83512020-01-15 14:46:35 -05001742 bool onChar(SkUnichar uni) override {
1743 switch (uni) {
1744 case 'l':
1745 direction = true;
1746 return true;
1747 case 'r':
1748 direction = false;
1749 return true;
1750 default:
1751 break;
Julia Lavrova4cf18742020-01-14 13:24:45 -05001752 }
Julia Lavrova9bd83512020-01-15 14:46:35 -05001753 return false;
1754 }
1755
1756 void onDrawContent(SkCanvas* canvas) override {
1757
1758 canvas->drawColor(SK_ColorWHITE);
1759 ParagraphStyle paragraph_style;
1760 paragraph_style.setTextDirection(direction ? TextDirection::kLtr : TextDirection::kRtl);
1761 auto collection = getFontCollection();
1762 ParagraphBuilderImpl builder(paragraph_style, collection);
1763 collection->getParagraphCache()->reset();
1764 collection->getParagraphCache()->turnOn(false);
1765 TextStyle text_style;
1766 text_style.setColor(SK_ColorBLACK);
1767 text_style.setFontFamilies({SkString("Roboto")});
1768 text_style.setFontSize(12);
1769 builder.pushStyle(text_style);
1770 builder.addText("I have got a ");
1771 text_style.setFontStyle(SkFontStyle::Bold());
1772 builder.pushStyle(text_style);
1773 builder.addText("lovely bunch");
1774 text_style.setFontStyle(SkFontStyle::Normal());
1775 builder.pushStyle(text_style);
1776 builder.addText(" of coconuts.");
1777 auto paragraph = builder.Build();
1778 paragraph->layout(this->width());
1779 paragraph->paint(canvas, 0, 0);
1780 collection->getParagraphCache()->turnOn(true);
Julia Lavrova4cf18742020-01-14 13:24:45 -05001781 }
1782
1783private:
1784 typedef Sample INHERITED;
Julia Lavrova9bd83512020-01-15 14:46:35 -05001785 bool direction;
Julia Lavrova4cf18742020-01-14 13:24:45 -05001786};
Julia Lavrova9bd83512020-01-15 14:46:35 -05001787
Julia Lavrova51a813d2020-01-21 13:55:44 -05001788class ParagraphView23 : public ParagraphView_Base {
1789protected:
1790 SkString name() override { return SkString("Paragraph23"); }
1791
1792 void onDrawContent(SkCanvas* canvas) override {
1793 canvas->drawColor(SK_ColorWHITE);
1794
1795 const char* text = "Text with shadow";
1796 ParagraphStyle paragraph_style;
1797 TextStyle text_style;
1798 text_style.setColor(SK_ColorBLACK);
1799 text_style.setFontFamilies({SkString("Google Sans")});
1800 text_style.setFontSize(24);
1801
1802 auto draw = [&](SkScalar h, SkScalar v, SkScalar b) {
1803 text_style.resetShadows();
1804 text_style.addShadow(TextShadow(SK_ColorBLACK, SkPoint::Make(h, v), b));
1805 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1806 builder.pushStyle(text_style);
1807 builder.addText(text);
1808 auto paragraph = builder.Build();
1809 paragraph->layout(300);
1810 paragraph->paint(canvas, 0, 0);
1811
1812 auto rect = SkRect::MakeXYWH(0, 0, paragraph->getMaxWidth(), paragraph->getHeight());
1813 SkPaint paint;
1814 paint.setColor(SK_ColorRED);
1815 paint.setStyle(SkPaint::kStroke_Style);
1816 paint.setAntiAlias(true);
1817 paint.setStrokeWidth(1);
1818 canvas->drawRect(rect, paint);
1819 };
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 draw(-10, 10, 5);
1831 canvas->translate(0, 100);
1832 }
1833
1834private:
1835 typedef Sample INHERITED;
1836};
1837
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001838class ParagraphView24 : public ParagraphView_Base {
1839protected:
1840 SkString name() override { return SkString("Paragraph24"); }
1841
1842 void onDrawContent(SkCanvas* canvas) override {
1843 canvas->drawColor(SK_ColorWHITE);
1844
1845 ParagraphStyle paragraph_style;
1846 paragraph_style.setTextDirection(TextDirection::kRtl);
1847 TextStyle text_style;
1848 text_style.setColor(SK_ColorBLACK);
1849 text_style.setFontFamilies({SkString("Google Sans")});
1850 text_style.setFontSize(24);
1851 {
1852 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1853 builder.pushStyle(text_style);
1854 builder.addText("Right_to_left:");
1855 auto paragraph = builder.Build();
1856 paragraph->layout(this->width());
1857 paragraph->paint(canvas, 0, 0);
1858 }
1859 canvas->translate(0, 200);
1860 {
1861 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1862 builder.pushStyle(text_style);
1863 builder.addText("Right_to_left+");
1864 auto paragraph = builder.Build();
1865 paragraph->layout(this->width());
1866 paragraph->paint(canvas, 0, 0);
1867 }
1868 canvas->translate(0, 200);
1869 {
1870 ParagraphBuilderImpl builder(paragraph_style, getFontCollection());
1871 builder.pushStyle(text_style);
1872 builder.addText("Right_to_left.");
1873 auto paragraph = builder.Build();
1874 paragraph->layout(this->width());
1875 paragraph->paint(canvas, 0, 0);
1876 }
1877 }
1878
1879private:
1880 typedef Sample INHERITED;
1881};
1882
1883class ParagraphView25 : public ParagraphView_Base {
1884protected:
1885 SkString name() override { return SkString("Paragraph25"); }
1886
1887 void onDrawContent(SkCanvas* canvas) override {
1888 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovac0360582020-02-05 10:17:53 -05001889/*
1890 * Shell: ParagraphStyle: 1.000000 1
1891Shell: Strut enabled: 0 1.000000 14.000000 400 5 0
1892Shell: Font Families: 0
1893Shell: DefaultTextStyle: 16.000000 500 5 0
1894Shell: Font Families: 1 Roboto
1895Shell: Font Features: 0
1896Shell: TextStyle#0: [0:22) 16.000000 500 5 0
1897Shell: Font Families: 1 Roboto
1898Shell: Font Features: 0
1899Shell: TextStyle#1: [25:49) 16.000000 500 5 0
1900Shell: Font Families: 1 Roboto
1901Shell: Font Features: 0
1902Shell: Placeholder#0: [22:25) 32.000000 32.000000 32.000000 0 5
1903Shell: Placeholder#1: [49:52) 19.000000 41.000000 19.000000 0 4
1904Shell: Placeholder#2: [52:52) 0.000000 0.000000 0.000000 0 5
1905Shell: layout('Go to device settings  and set up a passcode. ', 280.000000): 280.000000 * 38.000000
1906 */
1907 auto fontCollection = getFontCollection();
1908 //fontCollection->getParagraphCache()->turnOn(false);
1909 const char* text1 = "Go to device settings ";
1910 const char* text2 = "and set up a passcode.";
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001911 ParagraphStyle paragraph_style;
Julia Lavrovac0360582020-02-05 10:17:53 -05001912 StrutStyle strut_style;
1913 strut_style.setStrutEnabled(false);
1914 strut_style.setFontSize(14);
1915 strut_style.setForceStrutHeight(false);
1916 strut_style.setHeight(14);
1917 paragraph_style.setStrutStyle(strut_style);
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001918 TextStyle text_style;
1919 text_style.setColor(SK_ColorBLACK);
Julia Lavrovac0360582020-02-05 10:17:53 -05001920 text_style.setFontFamilies({SkString("Roboto")});
1921 text_style.setFontSize(16);
1922 PlaceholderStyle placeholder_style;
1923 {
1924 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
1925 builder.pushStyle(text_style);
1926 builder.addText(text1);
1927 placeholder_style.fHeight = 32;
1928 placeholder_style.fWidth = 32;
1929 placeholder_style.fBaselineOffset = 32;
1930 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1931 placeholder_style.fAlignment = PlaceholderAlignment::kMiddle;
1932 builder.addPlaceholder(placeholder_style);
1933 builder.addText(text2);
1934 placeholder_style.fHeight = 19;
1935 placeholder_style.fWidth = 41;
1936 placeholder_style.fBaselineOffset = 19;
1937 placeholder_style.fBaseline = TextBaseline::kAlphabetic;
1938 placeholder_style.fAlignment = PlaceholderAlignment::kTop;
1939 builder.addPlaceholder(placeholder_style);
1940 auto paragraph = builder.Build();
1941 paragraph->layout(280);
1942 paragraph->paint(canvas, 0, 0);
1943 }
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001944 }
1945
1946private:
1947 typedef Sample INHERITED;
1948};
1949
1950class ParagraphView26 : public ParagraphView_Base {
1951protected:
1952 SkString name() override { return SkString("Paragraph26"); }
1953
1954 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001955 auto fontCollection = sk_make_sp<FontCollection>();
1956 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
Julia Lavrova95a9e692020-02-05 10:17:53 -05001957 //fontCollection->enableFontFallback();
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001958
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001959 canvas->clear(SK_ColorWHITE);
1960
1961 SkPaint paint;
1962 paint.setAntiAlias(true);
1963 paint.setColor(SK_ColorBLACK);
1964
1965 TextStyle textStyle;
1966 textStyle.setForegroundColor(paint);
Julia Lavrova95a9e692020-02-05 10:17:53 -05001967 textStyle.setFontFamilies({ SkString("Roboto") });
1968 textStyle.setFontSize(42.0f);
1969 textStyle.setLetterSpacing(-0.05f);
1970 textStyle.setHeightOverride(true);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001971
1972 ParagraphStyle paragraphStyle;
1973 paragraphStyle.setTextStyle(textStyle);
1974 paragraphStyle.setTextAlign(TextAlign::kLeft);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001975
Julia Lavrova95a9e692020-02-05 10:17:53 -05001976 ParagraphBuilderImpl builder(paragraphStyle, fontCollection);
1977 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 -05001978
Julia Lavrova95a9e692020-02-05 10:17:53 -05001979 auto paragraph = builder.Build();
1980 paragraph->layout(this->width() / 2);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001981
Julia Lavrova95a9e692020-02-05 10:17:53 -05001982 std::vector<LineMetrics> lines;
1983 paragraph->getLineMetrics(lines); // <-- error happens here
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001984
Julia Lavrova95a9e692020-02-05 10:17:53 -05001985 canvas->translate(10, 10);
1986 paragraph->paint(canvas, 0, 0);
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05001987 }
1988
1989private:
1990 typedef Sample INHERITED;
1991};
1992
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05001993class ParagraphView27 : public ParagraphView_Base {
1994protected:
1995 SkString name() override { return SkString("Paragraph27"); }
1996
1997 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovad3a32c52020-02-03 09:43:52 -05001998 auto fontCollection = sk_make_sp<FontCollection>();
1999 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2000 fontCollection->enableFontFallback();
2001 fontCollection->getParagraphCache()->turnOn(false);
2002
2003 SkPaint red;
2004 red.setColor(SK_ColorRED);
2005 red.setStyle(SkPaint::kStroke_Style);
2006 red.setAntiAlias(true);
2007 red.setStrokeWidth(1);
2008
2009 SkPaint blue;
2010 blue.setColor(SK_ColorRED);
2011 blue.setStyle(SkPaint::kStroke_Style);
2012 blue.setAntiAlias(true);
2013 blue.setStrokeWidth(1);
2014
2015 SkPaint black;
2016 black.setColor(SK_ColorBLACK);
2017 black.setStyle(SkPaint::kStroke_Style);
2018 black.setAntiAlias(true);
2019 black.setStrokeWidth(1);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002020
Julia Lavrova95a9e692020-02-05 10:17:53 -05002021 SkPaint whiteSpaces;
2022 whiteSpaces.setColor(SK_ColorLTGRAY);
2023
2024 SkPaint breakingSpace;
2025 breakingSpace.setColor(SK_ColorYELLOW);
2026
2027 SkPaint text;
2028 text.setColor(SK_ColorWHITE);
2029
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002030 ParagraphStyle paragraph_style;
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002031 paragraph_style.setTextAlign(TextAlign::kRight);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002032 TextStyle text_style;
2033 text_style.setColor(SK_ColorBLACK);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002034 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova89e678d2020-01-28 10:43:31 -05002035
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002036 // RTL + right align + arabic
2037 // RTL + right align + latin
2038 // LTR + right align + arabic
2039 // LTR + right align + latin
2040 // RTL + left align + arabic
2041 // RTL + left align + latin
2042 // arabic and latin should not differ at all
2043 // check: line breaking and trailing spaces
2044
2045 canvas->drawColor(SK_ColorWHITE);
2046 auto h = 60;
2047 auto w = 300;
2048
Julia Lavrova95a9e692020-02-05 10:17:53 -05002049 auto draw = [&](SkScalar width, SkScalar height, TextDirection td, TextAlign ta, const char* t) {
Ben Wagner056d5432020-05-13 10:24:15 -04002050 if (this->isVerbose()) {
2051 SkDebugf("draw '%s' dir:%s align:%s\n", t,
2052 td == TextDirection::kLtr ? "left" : "right",
2053 ta == TextAlign::kLeft ? "left" : "right");
2054 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002055 paragraph_style.setTextDirection(td);
2056 paragraph_style.setTextAlign(ta);
2057 text_style.setFontSize(20);
2058 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
Julia Lavrova95a9e692020-02-05 10:17:53 -05002059 text_style.setBackgroundColor(whiteSpaces);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002060 builder.pushStyle(text_style);
Julia Lavrova95a9e692020-02-05 10:17:53 -05002061 builder.addText(" ");
2062 text_style.setBackgroundColor(text);
2063 builder.pushStyle(text_style);
2064 builder.addText(t);
2065 text_style.setBackgroundColor(breakingSpace);
2066 builder.pushStyle(text_style);
2067 builder.addText(" ");
2068 text_style.setBackgroundColor(text);
2069 builder.pushStyle(text_style);
2070 builder.addText(t);
2071 text_style.setBackgroundColor(whiteSpaces);
2072 builder.pushStyle(text_style);
2073 builder.addText(" ");
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002074 auto paragraph = builder.Build();
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002075 paragraph->layout(width);
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002076 paragraph->paint(canvas, 0, 0);
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002077 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
2078 for (auto& line : impl->lines()) {
Ben Wagner056d5432020-05-13 10:24:15 -04002079 if (this->isVerbose()) {
2080 SkDebugf("line[%d]: %f + %f\n", &line - impl->lines().begin(), line.offset().fX, line.shift());
2081 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002082 line.iterateThroughVisualRuns(true,
2083 [&](const Run* run, SkScalar runOffset, TextRange textRange, SkScalar* width) {
2084 *width = line.measureTextInsideOneRun(textRange, run, runOffset, 0, true, false).clip.width();
Ben Wagner056d5432020-05-13 10:24:15 -04002085 if (this->isVerbose()) {
2086 SkDebugf("%d[%d: %d) @%f + %f %s\n", run->index(),
2087 textRange.start, textRange.end, runOffset, *width, run->leftToRight() ? "left" : "right");
2088 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002089 return true;
2090 });
2091 }
2092 auto boxes = paragraph->getRectsForRange(0, 100, RectHeightStyle::kTight, RectWidthStyle::kTight);
2093 bool even = true;
2094 for (auto& box : boxes) {
Ben Wagner056d5432020-05-13 10:24:15 -04002095 if (this->isVerbose()) {
2096 SkDebugf("[%f:%f,%f:%f] %s\n",
2097 box.rect.fLeft, box.rect.fRight, box.rect.fTop, box.rect.fBottom,
2098 box.direction == TextDirection::kLtr ? "left" : "right");
2099 }
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002100 canvas->drawRect(box.rect, even ? red : blue);
2101 even = !even;
2102 }
2103 canvas->translate(0, height);
Julia Lavrova89e678d2020-01-28 10:43:31 -05002104 };
2105
Julia Lavrovad3a32c52020-02-03 09:43:52 -05002106 canvas->drawRect(SkRect::MakeXYWH(0, 0, w, h * 8), black);
2107
2108 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "RTL+RIGHT#1234567890");
2109 draw(w, h, TextDirection::kRtl, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
2110
2111 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "LTR+RIGHT#1234567890");
2112 draw(w, h, TextDirection::kLtr, TextAlign::kRight, "قففغغغغقففغغغغقففغغغ");
2113
2114 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "RTL+LEFT##1234567890");
2115 draw(w, h, TextDirection::kRtl, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
2116
2117 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "LTR+LEFT##1234567890");
2118 draw(w, h, TextDirection::kLtr, TextAlign::kLeft, "قففغغغغقففغغغغقففغغغ");
Julia Lavrovac88a3bc2020-01-23 10:16:26 -05002119 }
2120
2121private:
2122 typedef Sample INHERITED;
2123};
2124
Julia Lavrova212bf072020-02-18 12:05:55 -05002125class ParagraphView28 : public ParagraphView_Base {
2126protected:
2127 SkString name() override { return SkString("Paragraph28"); }
2128
2129 void onDrawContent(SkCanvas* canvas) override {
2130
2131 const char* text = "AAAAA BBBBB CCCCC DDDDD EEEEE FFFFF GGGGG HHHHH IIIII JJJJJ KKKKK LLLLL MMMMM NNNNN OOOOO PPPPP QQQQQ";
2132
2133 canvas->drawColor(SK_ColorWHITE);
2134 ParagraphStyle paragraph_style;
2135 paragraph_style.setTextAlign(TextAlign::kJustify);
2136 auto collection = getFontCollection();
2137 ParagraphBuilderImpl builder(paragraph_style, collection);
2138 TextStyle text_style;
2139 text_style.setColor(SK_ColorBLACK);
2140 text_style.setFontFamilies({SkString("Roboto")});
2141 text_style.setFontSize(40);
2142 builder.pushStyle(text_style);
2143 builder.addText(text);
2144 auto paragraph = builder.Build();
2145 auto s = 186;
2146 paragraph->layout(360 - s);
2147 paragraph->paint(canvas, 0, 0);
2148 /*
2149 paragraph->layout(360);
2150 paragraph->paint(canvas, 0, 0);
2151 canvas->translate(0, 400);
2152 paragraph->layout(354.333);
2153 paragraph->paint(canvas, 0, 0);
2154 */
2155 }
2156
2157private:
2158 typedef Sample INHERITED;
2159};
2160
2161class ParagraphView29 : public ParagraphView_Base {
2162protected:
2163 SkString name() override { return SkString("Paragraph29"); }
2164
2165 void onDrawContent(SkCanvas* canvas) override {
2166
Julia Lavrova62076972020-02-19 15:12:48 -05002167 const char* text = "ffi";
Julia Lavrova212bf072020-02-18 12:05:55 -05002168 canvas->drawColor(SK_ColorWHITE);
2169
Julia Lavrova62076972020-02-19 15:12:48 -05002170 auto collection = getFontCollection();
Julia Lavrova212bf072020-02-18 12:05:55 -05002171
2172 ParagraphStyle paragraph_style;
Julia Lavrova212bf072020-02-18 12:05:55 -05002173 ParagraphBuilderImpl builder(paragraph_style, collection);
2174 TextStyle text_style;
2175 text_style.setColor(SK_ColorBLACK);
2176 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova62076972020-02-19 15:12:48 -05002177 text_style.setFontSize(60);
Julia Lavrova212bf072020-02-18 12:05:55 -05002178 builder.pushStyle(text_style);
2179 builder.addText(text);
2180 auto paragraph = builder.Build();
Julia Lavrova62076972020-02-19 15:12:48 -05002181 paragraph->layout(width());
Julia Lavrova212bf072020-02-18 12:05:55 -05002182 paragraph->paint(canvas, 0, 0);
Julia Lavrova62076972020-02-19 15:12:48 -05002183 auto width = paragraph->getLongestLine();
2184 auto height = paragraph->getHeight();
2185
2186 auto f1 = paragraph->getGlyphPositionAtCoordinate(width/6, height/2);
2187 auto f2 = paragraph->getGlyphPositionAtCoordinate(width/2, height/2);
2188 auto i = paragraph->getGlyphPositionAtCoordinate(width*5/6, height/2);
2189
Ben Wagner056d5432020-05-13 10:24:15 -04002190 if (this->isVerbose()) {
2191 SkDebugf("%d(%s) %d(%s) %d(%s)\n",
2192 f1.position, f1.affinity == Affinity::kUpstream ? "up" : "down",
2193 f2.position, f2.affinity == Affinity::kUpstream ? "up" : "down",
2194 i.position, i.affinity == Affinity::kUpstream ? "up" : "down");
Julia Lavrova62076972020-02-19 15:12:48 -05002195
Ben Wagner056d5432020-05-13 10:24:15 -04002196 auto rf1 = paragraph->getRectsForRange(0, 1, RectHeightStyle::kTight, RectWidthStyle::kTight)[0];
2197 auto rf2 = paragraph->getRectsForRange(1, 2, RectHeightStyle::kTight, RectWidthStyle::kTight)[0];
2198 auto rfi = paragraph->getRectsForRange(2, 3, RectHeightStyle::kTight, RectWidthStyle::kTight)[0];
Julia Lavrova62076972020-02-19 15:12:48 -05002199
Ben Wagner056d5432020-05-13 10:24:15 -04002200 SkDebugf("f1: [%f:%f] %s\n",
2201 rf1.rect.fLeft, rf1.rect.fRight, rf1.direction == TextDirection::kRtl ? "rtl" : "ltr");
2202 SkDebugf("f2: [%f:%f] %s\n",
2203 rf2.rect.fLeft, rf2.rect.fRight, rf2.direction == TextDirection::kRtl ? "rtl" : "ltr");
2204 SkDebugf("i: [%f:%f] %s\n",
2205 rfi.rect.fLeft, rfi.rect.fRight, rfi.direction == TextDirection::kRtl ? "rtl" : "ltr");
2206 }
Julia Lavrova212bf072020-02-18 12:05:55 -05002207 }
2208
2209private:
2210 typedef Sample INHERITED;
2211};
2212
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002213class ParagraphView30 : public ParagraphView_Base {
2214protected:
2215 SkString name() override { return SkString("Paragraph30"); }
2216
2217 void onDrawContent(SkCanvas* canvas) override {
2218
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002219 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 -05002220 canvas->drawColor(SK_ColorWHITE);
2221
2222 auto fontCollection = sk_make_sp<FontCollection>();
2223 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2224 fontCollection->enableFontFallback();
2225
2226 ParagraphStyle paragraph_style;
2227 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2228 TextStyle text_style;
2229 text_style.setColor(SK_ColorBLACK);
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002230 text_style.setFontFamilies({SkString("Noto Color Emoji")});
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002231 text_style.setFontSize(60);
2232 builder.pushStyle(text_style);
2233 builder.addText(text);
2234 auto paragraph = builder.Build();
2235 paragraph->layout(width());
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002236
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002237
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002238 SkColor colors[] = {
2239 SK_ColorRED,
2240 SK_ColorGREEN,
2241 SK_ColorBLUE,
2242 SK_ColorMAGENTA,
2243 SK_ColorYELLOW
2244 };
2245 SkPaint paint;
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002246 size_t color = 0;
2247 for (size_t i = 0; i < text.size(); ++i) {
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002248 auto result = paragraph->getRectsForRange(i, i + 1, RectHeightStyle::kTight, RectWidthStyle::kTight);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002249 if (result.empty()) {
Ben Wagner056d5432020-05-13 10:24:15 -04002250 if (this->isVerbose()) {
2251 SkDebugf("empty [%d:%d)\n", i, i + 1);
2252 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002253 continue;
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002254 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002255 auto rect = result[0].rect;
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002256 paint.setColor(colors[color++ % 5]);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002257 canvas->drawRect(rect, paint);
Ben Wagner056d5432020-05-13 10:24:15 -04002258 if (this->isVerbose()) {
2259 SkDebugf("rect [%d:%d): %f:%f\n", i, i + 1, rect.fLeft, rect.fRight);
2260 }
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002261 }
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002262 paragraph->paint(canvas, 0, 0);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002263 }
2264
2265private:
2266 typedef Sample INHERITED;
2267};
2268
2269class ParagraphView31 : public ParagraphView_Base {
2270protected:
2271 SkString name() override { return SkString("Paragraph31"); }
2272
2273 void onDrawContent(SkCanvas* canvas) override {
2274
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002275 canvas->drawColor(SK_ColorWHITE);
2276
2277 auto fontCollection = sk_make_sp<FontCollection>();
2278 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2279 fontCollection->enableFontFallback();
2280
2281 ParagraphStyle paragraph_style;
2282 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2283 TextStyle text_style;
2284 text_style.setColor(SK_ColorBLACK);
2285 text_style.setFontFamilies({SkString("Roboto")});
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002286 text_style.setFontSize(40);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002287 builder.pushStyle(text_style);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002288 auto s = u"েن েূথ";
2289 builder.addText(s);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002290 auto paragraph = builder.Build();
2291 paragraph->layout(width());
2292 paragraph->paint(canvas, 0, 0);
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002293 }
2294
2295private:
2296 typedef Sample INHERITED;
2297};
2298
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002299class ParagraphView32 : public ParagraphView_Base {
2300protected:
2301 SkString name() override { return SkString("Paragraph32"); }
2302
2303 void onDrawContent(SkCanvas* canvas) override {
2304
2305 canvas->drawColor(SK_ColorWHITE);
2306
2307 auto fontCollection = sk_make_sp<FontCollection>();
2308 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2309 fontCollection->enableFontFallback();
2310
2311 ParagraphStyle paragraph_style;
2312 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2313 TextStyle text_style;
2314 text_style.setColor(SK_ColorBLACK);
2315 text_style.setFontFamilies({SkString("Roboto")});
2316 text_style.setFontSize(40);
2317 text_style.setLocale(SkString("ko"));
2318 builder.pushStyle(text_style);
2319 builder.addText(u"\u904d ko ");
2320 text_style.setLocale(SkString("zh_Hant"));
2321 builder.pushStyle(text_style);
2322 builder.addText(u"\u904d zh-Hant ");
2323 text_style.setLocale(SkString("zh_Hans"));
2324 builder.pushStyle(text_style);
2325 builder.addText(u"\u904d zh-Hans ");
2326 text_style.setLocale(SkString("zh_HK"));
2327 builder.pushStyle(text_style);
2328 builder.addText(u"\u904d zh-HK ");
2329 auto paragraph = builder.Build();
2330 paragraph->layout(width());
2331 paragraph->paint(canvas, 0, 0);
2332 }
2333
2334private:
2335 typedef Sample INHERITED;
2336};
2337
2338class ParagraphView33 : public ParagraphView_Base {
2339protected:
2340 SkString name() override { return SkString("Paragraph33"); }
2341
2342 void onDrawContent(SkCanvas* canvas) override {
2343
2344 canvas->drawColor(SK_ColorWHITE);
2345
2346 auto fontCollection = sk_make_sp<FontCollection>();
2347 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2348 fontCollection->enableFontFallback();
2349
2350 ParagraphStyle paragraph_style;
2351 paragraph_style.setTextAlign(TextAlign::kJustify);
2352 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2353 TextStyle text_style;
2354 text_style.setColor(SK_ColorBLACK);
2355 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2356 text_style.setFontSize(36);
2357 builder.pushStyle(text_style);
2358 builder.addText(u"AAAAA \U0001f600 BBBBB CCCCC DDDDD EEEEE");
2359 auto paragraph = builder.Build();
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002360 paragraph->layout(width() / 2);
2361 SkPaint paint;
2362 paint.setColor(SK_ColorLTGRAY);
2363 canvas->drawRect(SkRect::MakeXYWH(0, 0, width()/2, paragraph->getHeight()), paint);
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002364 paragraph->paint(canvas, 0, 0);
2365 }
2366
2367private:
2368 typedef Sample INHERITED;
2369};
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002370
2371class ParagraphView34 : public ParagraphView_Base {
2372protected:
2373 SkString name() override { return SkString("Paragraph34"); }
2374
2375 void onDrawContent(SkCanvas* canvas) override {
2376
2377 canvas->drawColor(SK_ColorWHITE);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002378 auto text = "ضخمة ص ،😁😂🤣ضضض ؤ،،😗😗😍😋شسي،😗😁😁ؤرى،😗😃😄😍ببب،🥰😅🥰🥰🥰ثيلااتن";
2379 //auto text = "ى،😗😃😄😍بب";
2380 //auto text1 = "World domination is such an ugly phrase - I prefer to call it world optimisation";
2381 auto fontCollection = sk_make_sp<FontCollection>();
2382 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2383 fontCollection->enableFontFallback();
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002384
2385 ParagraphStyle paragraph_style;
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002386 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2387 TextStyle text_style;
2388 text_style.setColor(SK_ColorBLACK);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002389 text_style.setFontFamilies({SkString("Noto Color Emoji")});
2390 text_style.setFontSize(50);
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002391 builder.pushStyle(text_style);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002392 builder.addText(text);
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002393 auto paragraph = builder.Build();
Julia Lavrova3c79a232020-03-02 09:58:52 -05002394 paragraph->layout(1041); // 1041
2395
2396 SkColor colors[] = {SK_ColorBLUE, SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGREEN,
2397 SK_ColorRED, SK_ColorWHITE, SK_ColorYELLOW, SK_ColorMAGENTA };
2398 SkPaint paint;
2399 size_t wordPos = 0;
2400 size_t index = 0;
2401 while (wordPos < 72) {
2402 auto res2 = paragraph->getWordBoundary(wordPos);
2403 if (res2.width() == 0) {
2404 break;
2405 }
2406 wordPos = res2.end;
2407 auto res3 = paragraph->getRectsForRange(
2408 res2.start, res2.end,
2409 RectHeightStyle::kTight, RectWidthStyle::kTight);
2410 paint.setColor(colors[index % 8]);
2411 ++index;
2412 if (!res3.empty()) {
2413 canvas->drawRect(res3[0].rect, paint);
2414 }
2415 }
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002416 paragraph->paint(canvas, 0, 0);
2417 }
2418
2419private:
2420 typedef Sample INHERITED;
2421};
Julia Lavrova3c79a232020-03-02 09:58:52 -05002422
2423class ParagraphView35 : public ParagraphView_Base {
2424protected:
2425 SkString name() override { return SkString("Paragraph35"); }
2426
2427 Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
2428 return new Click;
2429 }
2430
2431 bool onClick(Click* click) override {
2432 fPoint = click->fCurr;
2433 return true;
2434 }
2435
2436 void onDrawContent(SkCanvas* canvas) override {
2437
2438 canvas->drawColor(SK_ColorWHITE);
2439
2440 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";
2441 auto fontCollection = sk_make_sp<FontCollection>();
2442 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2443 fontCollection->enableFontFallback();
2444
2445 ParagraphStyle paragraph_style;
Julia Lavrova2813d452020-03-03 11:43:40 -05002446 //paragraph_style.setTextAlign(TextAlign::kJustify);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002447 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2448 TextStyle text_style;
2449 text_style.setColor(SK_ColorBLACK);
2450 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2451 text_style.setFontSize(40);
2452 builder.pushStyle(text_style);
2453 builder.addText(text);
2454 auto paragraph = builder.Build();
Julia Lavrova2813d452020-03-03 11:43:40 -05002455 paragraph->layout(width());//758
2456
2457 //auto res1 = paragraph->getGlyphPositionAtCoordinate(line.width() + line.spacesWidth() / 2, line.offset().fY + 10);
2458 //auto res2 = paragraph->getWordBoundary(res1.position);
2459 auto res1 = paragraph->getRectsForRange(360, 361, RectHeightStyle::kTight, RectWidthStyle::kTight);
2460 auto res2 = paragraph->getRectsForRange(359, 360, RectHeightStyle::kTight, RectWidthStyle::kTight);
2461 auto res3 = paragraph->getRectsForRange(358, 359, RectHeightStyle::kTight, RectWidthStyle::kTight);
2462
2463 auto draw = [&](std::vector<TextBox> res, SkColor color) {
2464 SkPaint paint;
2465 paint.setColor(color);
2466 for (auto& r : res) {
2467 canvas->drawRect(r.rect, paint);
2468 }
2469 };
2470
2471 draw(res1, SK_ColorRED);
2472 draw(res2, SK_ColorGREEN);
2473 draw(res3, SK_ColorBLUE);
2474
Julia Lavrova3c79a232020-03-02 09:58:52 -05002475 paragraph->paint(canvas, 0, 0);
Julia Lavrova3c79a232020-03-02 09:58:52 -05002476 }
2477
2478private:
2479 typedef Sample INHERITED;
2480 SkPoint fPoint;
2481};
2482
Julia Lavrova2813d452020-03-03 11:43:40 -05002483class ParagraphView36 : public ParagraphView_Base {
2484protected:
2485 SkString name() override { return SkString("Paragraph36"); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -04002486
Julia Lavrova2813d452020-03-03 11:43:40 -05002487 void onDrawContent(SkCanvas* canvas) override {
2488
2489 canvas->drawColor(SK_ColorWHITE);
Julia Lavrovacd2d4e42020-03-27 15:40:37 -04002490 auto text = "String is too big for WinMSVC";
2491 //"সৢ৭ঙ া 七七去关谢都四先么见香认东 غلضينخي 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 字弟是去妈京学地";
2492 //"ي ز";
2493 //"৪৮ু৸ধ maar";
2494 //"四的 ذخص ৢঙ";
2495 //"ذخص ৢঙ";
Julia Lavrova2813d452020-03-03 11:43:40 -05002496 auto fontCollection = sk_make_sp<FontCollection>();
2497 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2498 fontCollection->enableFontFallback();
2499
2500 ParagraphStyle paragraph_style;
Julia Lavrova2813d452020-03-03 11:43:40 -05002501 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2502 TextStyle text_style;
2503 text_style.setColor(SK_ColorBLACK);
Julia Lavrovacd2a4d62020-03-05 10:31:19 -05002504 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Serif CJK JP")});
2505 text_style.setFontSize(10);
Julia Lavrova2813d452020-03-03 11:43:40 -05002506 builder.pushStyle(text_style);
2507 builder.addText(text);
2508 auto paragraph = builder.Build();
2509 paragraph->layout(width());
2510
Julia Lavrova2813d452020-03-03 11:43:40 -05002511 paragraph->paint(canvas, 0, 0);
2512 }
2513
2514private:
2515 typedef Sample INHERITED;
2516};
2517
Julia Lavrova99ede422020-03-17 13:20:58 -04002518class ParagraphView37 : public ParagraphView_Base {
2519protected:
2520 SkString name() override { return SkString("Paragraph37"); }
2521
2522 void onDrawContent(SkCanvas* canvas) override {
Julia Lavrovacd2d4e42020-03-27 15:40:37 -04002523 const char* text = "String is too big for WinMSVC";
2524 // "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaয়ৠঝোণ৺ঢ়মৈবৗৗঘথফড়৭২খসঢ়ৃঢ়ঁ৷থডঈঽলবনদ২ৢৃঀজঝ৩ঠ৪৫৯০ঌয়্মওৗ৲গখদ৹ঈ৴৹ঢ়ৄএৡফণহলঈ৲থজোৱে ঀকৰঀষজঝঃাখশঽএমংি";
Julia Lavrovaa169b002020-03-23 13:39:52 -04002525 //"ৎৣ়ৎঽতঃ৳্ৱব৴ৣঈ৷ূঁঢঢ়শটডৎ৵৵ৰৃ্দংঊাথৗদঊউদ৯ঐৃধা৬হওধি়৭ঽম৯স০ঢফৈঢ়কষঁছফীআে৶ৰ৶ঌৌঊ্ঊঝএঀঃদঞ৮তব৬ৄঊঙঢ়ৡগ৶৹৹ঌড়ঘৄ৷লপ১ভড়৶েঢ়৯ৎকনংট২ংএঢৌৌঐনো০টঽুৠগআ৷৭৩৬তো৻ঈ০ূসষঅঝআমণঔা১ণৈো৵চঽ৩বমৎঙঘ২ঠৠৈী৫তঌণচ৲ঔী৮ঘৰঔ";
Julia Lavrova99ede422020-03-17 13:20:58 -04002526 canvas->drawColor(SK_ColorWHITE);
2527
2528 auto fontCollection = sk_make_sp<FontCollection>();
2529 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2530 fontCollection->enableFontFallback();
2531
2532 ParagraphStyle paragraph_style;
2533 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2534 TextStyle text_style;
2535 text_style.setColor(SK_ColorBLACK);
2536 text_style.setFontFamilies({SkString("Roboto")});
2537 text_style.setFontSize(20);
2538 builder.pushStyle(text_style);
2539 builder.addText(text);
2540 auto paragraph = builder.Build();
2541 auto w = width() / 2;
2542 paragraph->layout(w);
Julia Lavrovaa169b002020-03-23 13:39:52 -04002543 auto impl = static_cast<ParagraphImpl*>(paragraph.get());
2544
2545 auto clusters = impl->clusters();
Ben Wagner056d5432020-05-13 10:24:15 -04002546 if (this->isVerbose()) {
2547 size_t c = 0;
2548 SkDebugf("clusters\n");
2549 for (auto& cluster: clusters) {
2550 SkDebugf("%d: [%d:%d) %s\n", c++,
2551 cluster.textRange().start, cluster.textRange().end,
2552 cluster.isSoftBreak() ? "soft" :
2553 cluster.isHardBreak() ? "hard" :
2554 cluster.isWhitespaces() ? "spaces" : "");
2555 }
2556
2557 auto lines = impl->lines();
2558 size_t i = 0;
2559 SkDebugf("lines\n");
2560 for (auto& line : lines) {
2561 SkDebugf("%d: [%d:%d)\n", i++, line.trimmedText().start, line.trimmedText().end);
2562 }
Julia Lavrovaa169b002020-03-23 13:39:52 -04002563 }
2564
Julia Lavrova99ede422020-03-17 13:20:58 -04002565 paragraph->paint(canvas, 0, 0);
2566 }
2567
2568private:
2569 typedef Sample INHERITED;
2570};
2571
Julia Lavrova18db52f2020-05-04 15:03:18 -04002572class ParagraphView38 : public ParagraphView_Base {
2573protected:
2574 SkString name() override { return SkString("Paragraph38"); }
2575
2576 void onDrawContent(SkCanvas* canvas) override {
2577
2578 canvas->drawColor(SK_ColorWHITE);
2579
2580 auto fontCollection = sk_make_sp<FontCollection>();
2581 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2582 fontCollection->enableFontFallback();
2583
2584 ParagraphStyle paragraph_style;
2585 paragraph_style.setTextAlign(TextAlign::kLeft);
2586 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2587 TextStyle text_style;
2588 text_style.setColor(SK_ColorDKGRAY);
2589 text_style.setFontFamilies({SkString("Roboto")});
2590 text_style.setFontSize(40);
2591 text_style.setDecoration(TextDecoration::kUnderline);
2592
2593 text_style.setDecorationMode(TextDecorationMode::kThrough);
2594 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2595 text_style.setDecorationColor(SK_ColorBLUE);
2596 builder.pushStyle(text_style);
2597 builder.addText("Double underline: {opopo}\n");
2598
2599 text_style.setDecorationMode(TextDecorationMode::kGaps);
2600 text_style.setDecorationStyle(TextDecorationStyle::kDouble);
2601 text_style.setDecorationColor(SK_ColorBLUE);
2602 builder.pushStyle(text_style);
2603 builder.addText("Double underline: {opopo}\n");
2604
2605 text_style.setDecorationStyle(TextDecorationStyle::kDotted);
2606 text_style.setDecorationColor(SK_ColorRED);
2607 builder.pushStyle(text_style);
2608 builder.addText("Dotted underline: {ijiji}\n");
2609
2610 text_style.setDecorationStyle(TextDecorationStyle::kSolid);
2611 text_style.setDecorationColor(SK_ColorGREEN);
2612 builder.pushStyle(text_style);
2613 builder.addText("Solid underline: {rqrqr}\n");
2614
2615 text_style.setDecorationStyle(TextDecorationStyle::kDashed);
2616 text_style.setDecorationColor(SK_ColorMAGENTA);
2617 builder.pushStyle(text_style);
2618 builder.addText("Dashed underline: {zyzyz}\n");
2619
2620 text_style.setDecorationStyle(TextDecorationStyle::kWavy);
2621 text_style.setDecorationColor(SK_ColorCYAN);
2622 builder.pushStyle(text_style);
2623 builder.addText("Wavy underline: {does not skip}\n");
2624
2625 auto paragraph = builder.Build();
2626 paragraph->layout(width());
2627 paragraph->paint(canvas, 0, 0);
2628 }
2629
2630private:
2631 typedef Sample INHERITED;
2632};
2633
Julia Lavrova6bdbd3d2020-05-06 12:03:17 -04002634class ParagraphView39 : public ParagraphView_Base {
2635protected:
2636 SkString name() override { return SkString("Paragraph39"); }
2637
2638 void onDrawContent(SkCanvas* canvas) override {
2639
2640 canvas->drawColor(SK_ColorWHITE);
2641
2642 auto fontCollection = sk_make_sp<FontCollection>();
2643 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2644 fontCollection->enableFontFallback();
2645
2646 ParagraphStyle paragraph_style;
2647 paragraph_style.setTextAlign(TextAlign::kJustify);
2648 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2649 TextStyle text_style;
2650 text_style.setColor(SK_ColorBLACK);
2651 text_style.setFontFamilies({SkString("Roboto")});
2652 text_style.setFontSize(40);
2653 builder.pushStyle(text_style);
2654 builder.addText(
2655 "text1 with line break\n"
2656 "text2 without line break text without line break text without line break text without line break text without line break text without line break "
2657 "text3 with line break\n"
2658 "text4 without line break text without line break text without line break text without line break text without line break text without line break "
2659 "text5 with line break\n"
2660 );
2661 auto paragraph = builder.Build();
2662 paragraph->layout(width());
2663 paragraph->paint(canvas, 0, 0);
2664 }
2665
2666private:
2667 typedef Sample INHERITED;
2668};
2669
Julia Lavrovadd1de252020-05-08 11:53:19 -04002670class ParagraphView41 : public ParagraphView_Base {
2671protected:
2672 SkString name() override { return SkString("Paragraph41"); }
2673
2674 void onDrawContent(SkCanvas* canvas) override {
2675
2676 canvas->drawColor(SK_ColorWHITE);
2677
2678 auto fontCollection = sk_make_sp<FontCollection>();
2679 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2680 fontCollection->enableFontFallback();
2681
2682 SkPaint line;
2683 line.setColor(SK_ColorRED);
2684 line.setStyle(SkPaint::kStroke_Style);
2685 line.setAntiAlias(true);
2686 line.setStrokeWidth(1);
2687
2688 auto draw = [&](SkColor color, TextHeightBehavior thb) {
2689 ParagraphStyle paragraph_style;
2690 paragraph_style.setTextHeightBehavior(thb);
2691 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2692 TextStyle text_style;
2693 text_style.setColor(SK_ColorBLACK);
2694 SkPaint paint;
2695 paint.setColor(color);
2696 text_style.setBackgroundColor(paint);
2697 text_style.setFontFamilies({SkString("Roboto")});
2698 text_style.setFontSize(20);
2699 text_style.setHeight(5);
2700 text_style.setHeightOverride(true);
2701 builder.pushStyle(text_style);
2702 builder.addText("World domination is such an ugly phrase - I prefer to call it world optimisation");
2703 auto paragraph = builder.Build();
2704 paragraph->layout(width());
2705 paragraph->paint(canvas, 0, 0);
2706 canvas->drawLine(0, paragraph->getHeight(), paragraph->getMaxWidth(), paragraph->getHeight(), line);
2707 canvas->translate(0, paragraph->getHeight());
2708 };
2709
2710 draw(SK_ColorLTGRAY, TextHeightBehavior::kDisableFirstAscent);
2711 draw(SK_ColorYELLOW, TextHeightBehavior::kDisableLastDescent);
2712 draw(SK_ColorGRAY, TextHeightBehavior::kDisableAll);
2713
2714 }
2715
2716private:
2717 typedef Sample INHERITED;
2718};
2719
2720class ParagraphView42 : public ParagraphView_Base {
2721protected:
2722 SkString name() override { return SkString("Paragraph42"); }
2723
2724 void onDrawContent(SkCanvas* canvas) override {
2725
2726 SkString text("Atwater Peel Sherbrooke Bonaventure\nhi\nwasssup!");
2727 canvas->drawColor(SK_ColorWHITE);
2728
2729 auto fontCollection = sk_make_sp<TestFontCollection>(GetResourcePath("fonts").c_str(), true, true);
2730
2731 ParagraphStyle paragraph_style;
2732 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2733 TextStyle text_style;
2734 text_style.setColor(SK_ColorBLACK);
2735 text_style.setFontFamilies({SkString("Ahem")});
2736 text_style.setFontSize(16);
2737 text_style.setHeight(4);
2738 text_style.setHeightOverride(true);
2739 builder.pushStyle(text_style);
2740 builder.addText(text.c_str());
2741 auto paragraph = builder.Build();
2742 paragraph->layout(width());
2743
2744 auto boxes = paragraph->getRectsForRange(0, 7, RectHeightStyle::kIncludeLineSpacingTop, RectWidthStyle::kMax);
2745 for (auto& box : boxes) {
2746 SkPaint paint;
2747 paint.setColor(SK_ColorGRAY);
2748 canvas->drawRect(box.rect, paint);
2749 }
2750
2751 auto boxes2 = paragraph->getRectsForRange(0, 7, RectHeightStyle::kTight, RectWidthStyle::kMax);
2752 for (auto& box : boxes2) {
2753 SkPaint paint;
2754 paint.setColor(SK_ColorRED);
2755 canvas->drawRect(box.rect, paint);
2756 }
2757
2758 paragraph->paint(canvas, 0, 0);
2759 }
2760
2761private:
2762 typedef Sample INHERITED;
2763};
Julia Lavrova68d14332020-05-11 13:47:08 -04002764
2765class ParagraphView43 : public ParagraphView_Base {
2766protected:
2767 SkString name() override { return SkString("Paragraph43"); }
2768
2769 void onDrawContent(SkCanvas* canvas) override {
2770
2771 SkString text("World domination is such an ugly phrase - I prefer to call it world optimisation");
2772 canvas->drawColor(SK_ColorWHITE);
2773
2774 auto fontCollection = sk_make_sp<FontCollection>();
2775 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2776 fontCollection->enableFontFallback();
2777
2778 ParagraphStyle paragraph_style;
2779 paragraph_style.setTextAlign(TextAlign::kJustify);
2780 paragraph_style.setEllipsis(u"\u2026");
2781 paragraph_style.setMaxLines(2);
2782 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2783 TextStyle text_style;
2784 text_style.setColor(SK_ColorBLACK);
2785 text_style.setFontFamilies({SkString("Roboto")});
2786 text_style.setFontSize(40);
2787 text_style.setHeightOverride(true);
2788 builder.pushStyle(text_style);
2789 builder.addText(text.c_str());
2790 auto paragraph = builder.Build();
2791 paragraph->layout(width() / 4);
2792 paragraph->paint(canvas, 0, 0);
2793 }
2794
2795private:
2796 typedef Sample INHERITED;
2797};
2798
Julia Lavrova3ea86252020-05-15 14:54:39 -04002799class ParagraphView44 : public ParagraphView_Base {
2800protected:
2801 SkString name() override { return SkString("Paragraph44"); }
2802
2803 void onDrawContent(SkCanvas* canvas) override {
2804
2805 const std::u16string text = u"The quick brown fox \U0001f98a ate a zesty ham burger fons \U0001f354."
2806 "The \U0001f469\u200D\U0001f469\u200D\U0001f467\u200D\U0001f467 laughed.";
2807 canvas->drawColor(SK_ColorWHITE);
2808
2809 auto fontCollection = sk_make_sp<FontCollection>();
2810 fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2811 fontCollection->enableFontFallback();
2812
2813 ParagraphStyle paragraph_style;
2814 paragraph_style.setMaxLines(7);
2815 paragraph_style.setEllipsis(u"\u2026");
2816 ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2817 TextStyle text_style;
2818 text_style.setColor(SK_ColorBLACK);
2819 text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
2820 text_style.setFontSize(60);
2821 builder.pushStyle(text_style);
2822 builder.addText(text);
2823 auto paragraph = builder.Build();
2824 paragraph->layout(305);//width());
2825 paragraph->paint(canvas, 0, 0);
2826 }
2827
2828private:
2829 typedef Sample INHERITED;
2830};
2831
Ben Wagner056d5432020-05-13 10:24:15 -04002832} // namespace
2833
Julia Lavrova2813d452020-03-03 11:43:40 -05002834//////////////////////////////////////////////////////////////////////////////
Julia Lavrovaa3552c52019-05-30 16:12:56 -04002835DEF_SAMPLE(return new ParagraphView1();)
2836DEF_SAMPLE(return new ParagraphView2();)
2837DEF_SAMPLE(return new ParagraphView3();)
2838DEF_SAMPLE(return new ParagraphView4();)
2839DEF_SAMPLE(return new ParagraphView5();)
2840DEF_SAMPLE(return new ParagraphView6();)
2841DEF_SAMPLE(return new ParagraphView7();)
2842DEF_SAMPLE(return new ParagraphView8();)
2843DEF_SAMPLE(return new ParagraphView9();)
2844DEF_SAMPLE(return new ParagraphView10();)
2845DEF_SAMPLE(return new ParagraphView11();)
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04002846DEF_SAMPLE(return new ParagraphView12();)
Julia Lavrovaf3ed2732019-09-05 14:35:17 -04002847DEF_SAMPLE(return new ParagraphView14();)
2848DEF_SAMPLE(return new ParagraphView15();)
Julia Lavrova2e30fde2019-10-09 09:43:02 -04002849DEF_SAMPLE(return new ParagraphView16();)
2850DEF_SAMPLE(return new ParagraphView17();)
2851DEF_SAMPLE(return new ParagraphView18();)
Julia Lavrova18db52f2020-05-04 15:03:18 -04002852//DEF_SAMPLE(return new ParagraphView19();)
Julia Lavrovac028b422019-11-25 10:00:43 -05002853DEF_SAMPLE(return new ParagraphView20();)
Julia Lavrovac48687a2020-01-08 16:53:53 -05002854DEF_SAMPLE(return new ParagraphView21();)
Julia Lavrova4cf18742020-01-14 13:24:45 -05002855DEF_SAMPLE(return new ParagraphView22();)
Julia Lavrova51a813d2020-01-21 13:55:44 -05002856DEF_SAMPLE(return new ParagraphView23();)
Julia Lavrova2ea20ea2020-01-22 10:56:53 -05002857DEF_SAMPLE(return new ParagraphView24();)
2858DEF_SAMPLE(return new ParagraphView25();)
Julia Lavrova212bf072020-02-18 12:05:55 -05002859DEF_SAMPLE(return new ParagraphView26();)
2860DEF_SAMPLE(return new ParagraphView27();)
2861DEF_SAMPLE(return new ParagraphView28();)
2862DEF_SAMPLE(return new ParagraphView29();)
Julia Lavrova7dcb4d22020-02-20 12:04:36 -05002863DEF_SAMPLE(return new ParagraphView30();)
2864DEF_SAMPLE(return new ParagraphView31();)
Julia Lavrova76ae22e2020-02-26 12:14:18 -05002865DEF_SAMPLE(return new ParagraphView32();)
2866DEF_SAMPLE(return new ParagraphView33();)
Julia Lavrovaa0708e82020-02-28 12:14:58 -05002867DEF_SAMPLE(return new ParagraphView34();)
Julia Lavrova3c79a232020-03-02 09:58:52 -05002868DEF_SAMPLE(return new ParagraphView35();)
Julia Lavrova2813d452020-03-03 11:43:40 -05002869DEF_SAMPLE(return new ParagraphView36();)
Julia Lavrova99ede422020-03-17 13:20:58 -04002870DEF_SAMPLE(return new ParagraphView37();)
Julia Lavrova18db52f2020-05-04 15:03:18 -04002871DEF_SAMPLE(return new ParagraphView38();)
Julia Lavrova6bdbd3d2020-05-06 12:03:17 -04002872DEF_SAMPLE(return new ParagraphView39();)
Julia Lavrovadd1de252020-05-08 11:53:19 -04002873DEF_SAMPLE(return new ParagraphView41();)
2874DEF_SAMPLE(return new ParagraphView42();)
Julia Lavrova68d14332020-05-11 13:47:08 -04002875DEF_SAMPLE(return new ParagraphView43();)
Julia Lavrova3ea86252020-05-15 14:54:39 -04002876DEF_SAMPLE(return new ParagraphView44();)