2424#include " src/utils/SkOSPath.h"
2525#include " src/utils/SkUTF.h"
2626#include " tools/Resources.h"
27+ #include " tools/flags/CommandLineFlags.h"
28+
29+
30+ static DEFINE_bool (verboseParagraph, false , " paragraph samples very verbose." );
2731
2832using namespace skia ::textlayout;
2933namespace {
@@ -38,6 +42,10 @@ class ParagraphView_Base : public Sample {
3842 }
3943 return fFC ;
4044 }
45+
46+ bool isVerbose () {
47+ return FLAGS_verboseParagraph;
48+ }
4149};
4250
4351sk_sp<SkShader> setgrad (const SkRect& r, SkColor c0, SkColor c1) {
@@ -55,7 +63,6 @@ void writeHtml(const char* name, Paragraph* paragraph) {
5563 }
5664}
5765*/
58- } // namespace
5966
6067class ParagraphView1 : public ParagraphView_Base {
6168protected:
@@ -737,10 +744,12 @@ class ParagraphView5 : public ParagraphView_Base {
737744 builder.addText (text4);
738745 builder.pop ();
739746 } else {
740- // icu::UnicodeString unicode((UChar*) text.data(), SkToS32(text.size()));
741- // std::string str;
742- // unicode.toUTF8String(str);
743- // SkDebugf("Text: %s\n", str.c_str());
747+ if (this ->isVerbose ()) {
748+ icu::UnicodeString unicode ((UChar*) text.data (), SkToS32 (text.size ()));
749+ std::string str;
750+ unicode.toUTF8String (str);
751+ SkDebugf (" Text: %s\n " , str.c_str ());
752+ }
744753 builder.addText (text + expected);
745754 }
746755
@@ -1296,15 +1305,19 @@ class ParagraphView11 : public ParagraphView_Base {
12961305 auto rects = paragraph->getRectsForRange (query.fX , query.fY , RectHeightStyle::kTight , RectWidthStyle::kTight );
12971306 if (rects.size () >= 1 && rects[0 ].rect .width () > 0 ) {
12981307 } else {
1299- SkDebugf (" +[%d:%d): Bad\n " , query.fX , query.fY );
1308+ if (this ->isVerbose ()) {
1309+ SkDebugf (" +[%d:%d): Bad\n " , query.fX , query.fY );
1310+ }
13001311 }
13011312 }
13021313
13031314 for (auto & query : miss) {
13041315 auto miss = paragraph->getRectsForRange (query.fX , query.fY , RectHeightStyle::kTight , RectWidthStyle::kTight );
13051316 if (miss.empty ()) {
13061317 } else {
1307- SkDebugf (" -[%d:%d): Bad\n " , query.fX , query.fY );
1318+ if (this ->isVerbose ()) {
1319+ SkDebugf (" -[%d:%d): Bad\n " , query.fX , query.fY );
1320+ }
13081321 }
13091322 }
13101323 }
@@ -1596,7 +1609,9 @@ class ParagraphView18 : public ParagraphView_Base {
15961609 icu::UnicodeString unicode ((UChar*)utf16text.data (), SkToS32 (utf16text.size ()));
15971610 std::string str;
15981611 unicode.toUTF8String (str);
1599- SkDebugf (" Text:>%s<\n " , str.data ());
1612+ if (this ->isVerbose ()) {
1613+ SkDebugf (" Text:>%s<\n " , str.data ());
1614+ }
16001615 builder.addText (utf16text);
16011616 fParagraph = builder.Build ();
16021617 }
@@ -2031,9 +2046,11 @@ class ParagraphView27 : public ParagraphView_Base {
20312046 auto w = 300 ;
20322047
20332048 auto draw = [&](SkScalar width, SkScalar height, TextDirection td, TextAlign ta, const char * t) {
2034- SkDebugf (" draw '%s' dir:%s align:%s\n " , t,
2035- td == TextDirection::kLtr ? " left" : " right" ,
2036- ta == TextAlign::kLeft ? " left" : " right" );
2049+ if (this ->isVerbose ()) {
2050+ SkDebugf (" draw '%s' dir:%s align:%s\n " , t,
2051+ td == TextDirection::kLtr ? " left" : " right" ,
2052+ ta == TextAlign::kLeft ? " left" : " right" );
2053+ }
20372054 paragraph_style.setTextDirection (td);
20382055 paragraph_style.setTextAlign (ta);
20392056 text_style.setFontSize (20 );
@@ -2058,21 +2075,27 @@ class ParagraphView27 : public ParagraphView_Base {
20582075 paragraph->paint (canvas, 0 , 0 );
20592076 auto impl = static_cast <ParagraphImpl*>(paragraph.get ());
20602077 for (auto & line : impl->lines ()) {
2061- SkDebugf (" line[%d]: %f + %f\n " , &line - impl->lines ().begin (), line.offset ().fX , line.shift ());
2078+ if (this ->isVerbose ()) {
2079+ SkDebugf (" line[%d]: %f + %f\n " , &line - impl->lines ().begin (), line.offset ().fX , line.shift ());
2080+ }
20622081 line.iterateThroughVisualRuns (true ,
20632082 [&](const Run* run, SkScalar runOffset, TextRange textRange, SkScalar* width) {
20642083 *width = line.measureTextInsideOneRun (textRange, run, runOffset, 0 , true , false ).clip .width ();
2065- SkDebugf (" %d[%d: %d) @%f + %f %s\n " , run->index (),
2066- textRange.start , textRange.end , runOffset, *width, run->leftToRight () ? " left" : " right" );
2084+ if (this ->isVerbose ()) {
2085+ SkDebugf (" %d[%d: %d) @%f + %f %s\n " , run->index (),
2086+ textRange.start , textRange.end , runOffset, *width, run->leftToRight () ? " left" : " right" );
2087+ }
20672088 return true ;
20682089 });
20692090 }
20702091 auto boxes = paragraph->getRectsForRange (0 , 100 , RectHeightStyle::kTight , RectWidthStyle::kTight );
20712092 bool even = true ;
20722093 for (auto & box : boxes) {
2073- SkDebugf (" [%f:%f,%f:%f] %s\n " ,
2074- box.rect .fLeft , box.rect .fRight , box.rect .fTop , box.rect .fBottom ,
2075- box.direction == TextDirection::kLtr ? " left" : " right" );
2094+ if (this ->isVerbose ()) {
2095+ SkDebugf (" [%f:%f,%f:%f] %s\n " ,
2096+ box.rect .fLeft , box.rect .fRight , box.rect .fTop , box.rect .fBottom ,
2097+ box.direction == TextDirection::kLtr ? " left" : " right" );
2098+ }
20762099 canvas->drawRect (box.rect , even ? red : blue);
20772100 even = !even;
20782101 }
@@ -2163,21 +2186,23 @@ class ParagraphView29 : public ParagraphView_Base {
21632186 auto f2 = paragraph->getGlyphPositionAtCoordinate (width/2 , height/2 );
21642187 auto i = paragraph->getGlyphPositionAtCoordinate (width*5 /6 , height/2 );
21652188
2166- SkDebugf (" %d(%s) %d(%s) %d(%s)\n " ,
2167- f1.position , f1.affinity == Affinity::kUpstream ? " up" : " down" ,
2168- f2.position , f2.affinity == Affinity::kUpstream ? " up" : " down" ,
2169- i.position , i.affinity == Affinity::kUpstream ? " up" : " down" );
2170-
2171- auto rf1 = paragraph->getRectsForRange (0 , 1 , RectHeightStyle::kTight , RectWidthStyle::kTight )[0 ];
2172- auto rf2 = paragraph->getRectsForRange (1 , 2 , RectHeightStyle::kTight , RectWidthStyle::kTight )[0 ];
2173- auto rfi = paragraph->getRectsForRange (2 , 3 , RectHeightStyle::kTight , RectWidthStyle::kTight )[0 ];
2174-
2175- SkDebugf (" f1: [%f:%f] %s\n " ,
2176- rf1.rect .fLeft , rf1.rect .fRight , rf1.direction == TextDirection::kRtl ? " rtl" : " ltr" );
2177- SkDebugf (" f2: [%f:%f] %s\n " ,
2178- rf2.rect .fLeft , rf2.rect .fRight , rf2.direction == TextDirection::kRtl ? " rtl" : " ltr" );
2179- SkDebugf (" i: [%f:%f] %s\n " ,
2180- rfi.rect .fLeft , rfi.rect .fRight , rfi.direction == TextDirection::kRtl ? " rtl" : " ltr" );
2189+ if (this ->isVerbose ()) {
2190+ SkDebugf (" %d(%s) %d(%s) %d(%s)\n " ,
2191+ f1.position , f1.affinity == Affinity::kUpstream ? " up" : " down" ,
2192+ f2.position , f2.affinity == Affinity::kUpstream ? " up" : " down" ,
2193+ i.position , i.affinity == Affinity::kUpstream ? " up" : " down" );
2194+
2195+ auto rf1 = paragraph->getRectsForRange (0 , 1 , RectHeightStyle::kTight , RectWidthStyle::kTight )[0 ];
2196+ auto rf2 = paragraph->getRectsForRange (1 , 2 , RectHeightStyle::kTight , RectWidthStyle::kTight )[0 ];
2197+ auto rfi = paragraph->getRectsForRange (2 , 3 , RectHeightStyle::kTight , RectWidthStyle::kTight )[0 ];
2198+
2199+ SkDebugf (" f1: [%f:%f] %s\n " ,
2200+ rf1.rect .fLeft , rf1.rect .fRight , rf1.direction == TextDirection::kRtl ? " rtl" : " ltr" );
2201+ SkDebugf (" f2: [%f:%f] %s\n " ,
2202+ rf2.rect .fLeft , rf2.rect .fRight , rf2.direction == TextDirection::kRtl ? " rtl" : " ltr" );
2203+ SkDebugf (" i: [%f:%f] %s\n " ,
2204+ rfi.rect .fLeft , rfi.rect .fRight , rfi.direction == TextDirection::kRtl ? " rtl" : " ltr" );
2205+ }
21812206 }
21822207
21832208private:
@@ -2221,13 +2246,17 @@ class ParagraphView30 : public ParagraphView_Base {
22212246 for (size_t i = 0 ; i < text.size (); ++i) {
22222247 auto result = paragraph->getRectsForRange (i, i + 1 , RectHeightStyle::kTight , RectWidthStyle::kTight );
22232248 if (result.empty ()) {
2224- SkDebugf (" empty [%d:%d)\n " , i, i + 1 );
2249+ if (this ->isVerbose ()) {
2250+ SkDebugf (" empty [%d:%d)\n " , i, i + 1 );
2251+ }
22252252 continue ;
22262253 }
22272254 auto rect = result[0 ].rect ;
22282255 paint.setColor (colors[color++ % 5 ]);
22292256 canvas->drawRect (rect, paint);
2230- SkDebugf (" rect [%d:%d): %f:%f\n " , i, i + 1 , rect.fLeft , rect.fRight );
2257+ if (this ->isVerbose ()) {
2258+ SkDebugf (" rect [%d:%d): %f:%f\n " , i, i + 1 , rect.fLeft , rect.fRight );
2259+ }
22312260 }
22322261 paragraph->paint (canvas, 0 , 0 );
22332262 }
@@ -2513,22 +2542,23 @@ class ParagraphView37 : public ParagraphView_Base {
25132542 auto impl = static_cast <ParagraphImpl*>(paragraph.get ());
25142543
25152544 auto clusters = impl->clusters ();
2516- size_t c = 0 ;
2517- SkDebugf (" clusters\n " );
2518- for (auto & cluster: clusters) {
2519- SkDebugf (" "
2520- " %d: [%d:%d) %s\n " , c++,
2521- cluster.textRange ().start , cluster.textRange ().end ,
2522- cluster.isSoftBreak () ? " soft" :
2523- cluster.isHardBreak () ? " hard" :
2524- cluster.isWhitespaces () ? " spaces" : " "
2525- );
2526- }
2527- auto lines = impl->lines ();
2528- size_t i = 0 ;
2529- SkDebugf (" lines\n " );
2530- for (auto & line : lines) {
2531- SkDebugf (" %d: [%d:%d)\n " , i++, line.trimmedText ().start , line.trimmedText ().end );
2545+ if (this ->isVerbose ()) {
2546+ size_t c = 0 ;
2547+ SkDebugf (" clusters\n " );
2548+ for (auto & cluster: clusters) {
2549+ SkDebugf (" %d: [%d:%d) %s\n " , c++,
2550+ cluster.textRange ().start , cluster.textRange ().end ,
2551+ cluster.isSoftBreak () ? " soft" :
2552+ cluster.isHardBreak () ? " hard" :
2553+ cluster.isWhitespaces () ? " spaces" : " " );
2554+ }
2555+
2556+ auto lines = impl->lines ();
2557+ size_t i = 0 ;
2558+ SkDebugf (" lines\n " );
2559+ for (auto & line : lines) {
2560+ SkDebugf (" %d: [%d:%d)\n " , i++, line.trimmedText ().start , line.trimmedText ().end );
2561+ }
25322562 }
25332563
25342564 paragraph->paint (canvas, 0 , 0 );
@@ -2765,6 +2795,8 @@ class ParagraphView43 : public ParagraphView_Base {
27652795 typedef Sample INHERITED;
27662796};
27672797
2798+ } // namespace
2799+
27682800// ////////////////////////////////////////////////////////////////////////////
27692801DEF_SAMPLE (return new ParagraphView1();)
27702802DEF_SAMPLE (return new ParagraphView2();)
0 commit comments