Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
ParagraphGM Class Reference
Inheritance diagram for ParagraphGM:
skiagm::GM

Public Member Functions

 ParagraphGM (unsigned flags)
 
void buildParagraph ()
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

void onOnceBeforeDraw () override
 
SkString getName () const override
 
SkISize getISize () override
 
void drawFromVisitor (SkCanvas *canvas, skia::textlayout::Paragraph *para) const
 
DrawResult onDraw (SkCanvas *canvas, SkString *errorMsg) override
 
bool runAsBench () const override
 
bool onAnimate (double) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onDraw (SkCanvas *)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 68 of file simple_gm.cpp.

Constructor & Destructor Documentation

◆ ParagraphGM()

ParagraphGM::ParagraphGM ( unsigned  flags)
inline

Definition at line 73 of file simple_gm.cpp.

73: fFlags(flags) {}
FlutterSemanticsFlag flags

Member Function Documentation

◆ buildParagraph()

void ParagraphGM::buildParagraph ( )
inline

Definition at line 75 of file simple_gm.cpp.

75 {
78 style.setFontFamilies({SkString("sans-serif")});
79 style.setFontSize(30);
80
81 if (fFlags & kUseUnderline) {
86 }
87
89 paraStyle.setTextStyle(style);
90
92 if (fontmgr->countFamilies() == 0) {
93 fPara = nullptr;
94 return;
95 }
96 auto collection = sk_make_sp<skia::textlayout::FontCollection>();
97 collection->setDefaultFontManager(std::move(fontmgr));
98
99 auto unicode = get_unicode();
100 if (!unicode) {
101 fPara = nullptr;
102 return;
103 }
105 paraStyle, collection, unicode);
106 if (nullptr == builder) {
107 fPara = nullptr;
108 return;
109 }
110
111 builder->addText(gSpeech, strlen(gSpeech));
112
113 fPara = builder->Build();
114 fPara->layout(400);
115 }
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
static std::unique_ptr< ParagraphBuilder > make(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
void setFontFamilies(std::vector< SkString > families)
Definition TextStyle.h:253
void setFontSize(SkScalar size)
Definition TextStyle.h:250
void setForegroundColor(SkPaint paint)
Definition TextStyle.h:181
void setDecorationColor(SkColor color)
Definition TextStyle.h:223
void setDecoration(TextDecoration decoration)
Definition TextStyle.h:220
void setDecorationMode(TextDecorationMode mode)
Definition TextStyle.h:221
void setDecorationThicknessMultiplier(SkScalar m)
Definition TextStyle.h:224
sk_sp< SkFontMgr > TestFontMgr()
static sk_sp< SkUnicode > get_unicode()
static const char * gSpeech
Definition simple_gm.cpp:26
void setTextStyle(const TextStyle &textStyle)

◆ drawFromVisitor()

void ParagraphGM::drawFromVisitor ( SkCanvas canvas,
skia::textlayout::Paragraph para 
) const
inlineprotected

Definition at line 140 of file simple_gm.cpp.

140 {
141 SkPaint p, p2;
142 p.setColor(0xFF0000FF);
143 p2.setColor(0xFFFF0000);
144 p2.setStrokeWidth(4);
146 SkPaint underp;
147 underp.setStroke(true);
148 underp.setStrokeWidth(2);
149 underp.setAntiAlias(true);
150 underp.setColor(p.getColor());
151 const SkScalar GAP = 2;
152
153 para->visit([&](int, const skia::textlayout::Paragraph::VisitorInfo* info) {
154 if (!info) {
155 return;
156 }
157 canvas->drawGlyphs(info->count, info->glyphs, info->positions, info->origin,
158 info->font, p);
159
160 if (fFlags & kUseUnderline) {
161 // Need to modify positions to roll-in the orign
162 std::vector<SkPoint> pos;
163 for (int i = 0; i < info->count; ++i) {
164 pos.push_back({info->origin.fX + info->positions[i].fX,
165 info->origin.fY + info->positions[i].fY});
166 }
167
168 const SkScalar X0 = pos[0].fX;
169 const SkScalar X1 = X0 + info->advanceX;
170 const SkScalar Y = pos[0].fY;
171 auto sects = info->font.getIntercepts(info->glyphs, info->count, pos.data(),
172 Y+1, Y+3);
173
174 SkScalar x0 = X0;
175 for (size_t i = 0; i < sects.size(); i += 2) {
176 SkScalar x1 = sects[i] - GAP;
177 if (x0 < x1) {
178 canvas->drawLine(x0, Y+2, x1, Y+2, underp);
179 }
180 x0 = sects[i+1] + GAP;
181 }
182 canvas->drawLine(x0, Y+2, X1, Y+2, underp);
183 }
184
185 if ((false)) {
186 if (info->utf8Starts) {
187 SkString str;
188 for (int i = 0; i < info->count; ++i) {
189 str.appendUnichar(gSpeech[info->utf8Starts[i]]);
190 }
191 SkDebugf("'%s'\n", str.c_str());
192 }
193
194 // show position points
195 for (int i = 0; i < info->count; ++i) {
196 auto pos = info->positions[i];
197 canvas->drawPoint(pos.fX + info->origin.fX, pos.fY + info->origin.fY, p2);
198 }
199 }
200 });
201 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkPoint pos
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static const SkScalar Y
void drawPoint(SkScalar x, SkScalar y, const SkPaint &paint)
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[], const uint32_t clusters[], int textByteCount, const char utf8text[], SkPoint origin, const SkFont &font, const SkPaint &paint)
@ kSquare_Cap
adds square
Definition SkPaint.h:336
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition SkPaint.h:170
void setStrokeCap(Cap cap)
Definition SkPaint.cpp:179
void setStroke(bool)
Definition SkPaint.cpp:115
void setStrokeWidth(SkScalar width)
Definition SkPaint.cpp:159
void appendUnichar(SkUnichar uni)
Definition SkString.h:207
const char * c_str() const
Definition SkString.h:133
float SkScalar
Definition extension.cpp:12
float fX
x-axis value
float fY
y-axis value

◆ getISize()

SkISize ParagraphGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 133 of file simple_gm.cpp.

133 {
134 if (fFlags & kShowVisitor) {
135 return SkISize::Make(810, 420);
136 }
137 return SkISize::Make(412, 420);
138 }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ getName()

SkString ParagraphGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 122 of file simple_gm.cpp.

122 {
124 name.printf("paragraph%s_%s",
125 fFlags & kTimeLayout ? "_layout" : "",
126 fFlags & kUseUnderline ? "_underline" : "");
127 if (fFlags & kShowVisitor) {
128 name.append("_visitor");
129 }
130 return name;
131 }
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
const char * name
Definition fuchsia.cc:50

◆ onAnimate()

bool ParagraphGM::onAnimate ( double  )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 245 of file simple_gm.cpp.

245 {
246 return false;
247 }

◆ onDraw()

DrawResult ParagraphGM::onDraw ( SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 203 of file simple_gm.cpp.

203 {
204 if (nullptr == fPara) {
205 *errorMsg = "Font manager had no fonts or could not build paragraph.";
206 return DrawResult::kSkip;
207 }
208
209 if (fFlags & kShowVisitor) {
210 canvas->clear(SK_ColorWHITE);
211 fPara->layout(400);
212 fPara->paint(canvas, 10, 10);
213 canvas->translate(400+10, 10);
214 this->drawFromVisitor(canvas, fPara.get());
215 return DrawResult::kOk;
216 }
217
218 const int loop = (this->getMode() == kGM_Mode) ? 1 : 50;
219
220 int parity = 0;
221 for (int i = 0; i < loop; ++i) {
222 SkAutoCanvasRestore acr(canvas, true);
223
224 if (fFlags & kTimeLayout) {
225 fPara->layout(400 + parity);
226 parity = (parity + 1) & 1;
227 }
228 fPara->paint(canvas, 10, 10);
229 }
230 // clean up if we've been looping
231 if (loop > 1) {
232 canvas->clear(SK_ColorWHITE);
233 fPara->layout(400);
234 fPara->paint(canvas, 10, 10);
235 }
236
237 if ((this->getMode() == kGM_Mode) && (fFlags & kTimeLayout)) {
238 return DrawResult::kSkip;
239 }
240 return DrawResult::kOk;
241 }
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
void drawFromVisitor(SkCanvas *canvas, skia::textlayout::Paragraph *para) const
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
@ kGM_Mode
Definition gm.h:119
Mode getMode() const
Definition gm.h:125

◆ onOnceBeforeDraw()

void ParagraphGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 118 of file simple_gm.cpp.

118 {
119 this->buildParagraph();
120 }
void buildParagraph()
Definition simple_gm.cpp:75

◆ runAsBench()

bool ParagraphGM::runAsBench ( ) const
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 243 of file simple_gm.cpp.

243{ return true; }

The documentation for this class was generated from the following file: