Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
DrawGlyphsGM Class Reference
Inheritance diagram for DrawGlyphsGM:
skiagm::GM

Public Member Functions

void onOnceBeforeDraw () override
 
SkString getName () const override
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 
- 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)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
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
 

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 []
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Detailed Description

Definition at line 21 of file drawglyphs.cpp.

Member Function Documentation

◆ getISize()

SkISize DrawGlyphsGM::getISize ( )
inlineoverridevirtual

Implements skiagm::GM.

Definition at line 53 of file drawglyphs.cpp.

53{ return SkISize::Make(640, 480); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString DrawGlyphsGM::getName ( ) const
inlineoverridevirtual

Implements skiagm::GM.

Definition at line 51 of file drawglyphs.cpp.

51{ return SkString("drawglyphs"); }

◆ onDraw()

void DrawGlyphsGM::onDraw ( SkCanvas canvas)
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 55 of file drawglyphs.cpp.

55 {
56 canvas->drawGlyphs(fGlyphCount, fGlyphs.begin(), fPositions.begin(), {50, 100}, fFont,
57 SkPaint{});
58
59 canvas->drawGlyphs(fGlyphCount, fGlyphs.begin(), fPositions.begin(), {50, 120}, fFont,
60 SkPaint{});
61
62 // Check bounding box calculation.
63 for (auto& pos : fPositions) {
64 pos += {0, -500};
65 }
66 canvas->drawGlyphs(fGlyphCount, fGlyphs.begin(), fPositions.begin(), {50, 640}, fFont,
67 SkPaint{});
68
69 canvas->drawGlyphs(fGlyphCount, fGlyphs.begin(), fXforms.begin(),
70 {50 + fLength / 2, 160 + fRadius}, fFont, SkPaint{});
71
72 // TODO: add tests for cluster versions of drawGlyphs.
73 }
SkPoint pos
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)
T * begin()
Definition: SkTDArray.h:150

◆ onOnceBeforeDraw()

void DrawGlyphsGM::onOnceBeforeDraw ( )
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 23 of file drawglyphs.cpp.

23 {
24 fTypeface = ToolUtils::CreatePortableTypeface("serif", SkFontStyle());
25 fFont = SkFont(fTypeface);
26 fFont.setSubpixel(true);
27 fFont.setSize(18);
28 const size_t txtLen = strlen(gText);
29 fGlyphCount = fFont.countText(gText, txtLen, SkTextEncoding::kUTF8);
30
31 fGlyphs.append(fGlyphCount);
32 fFont.textToGlyphs(gText, txtLen, SkTextEncoding::kUTF8, fGlyphs.begin(), fGlyphCount);
33
34 fPositions.append(fGlyphCount);
35 fFont.getPos(fGlyphs.begin(), fGlyphCount, fPositions.begin());
36 auto positions = SkSpan(fPositions.begin(), fGlyphCount);
37
38 fLength = positions.back().x() - positions.front().x();
39 fRadius = fLength / SK_FloatPI;
40 fXforms.append(fGlyphCount);
41
42 for (auto [xform, pos] : SkMakeZip(fXforms.begin(), positions)) {
43 const SkScalar lengthToGlyph = pos.x() - positions.front().x();
44 const SkScalar angle = SK_FloatPI * (fLength - lengthToGlyph) / fLength;
45 const SkScalar cos = std::cos(angle);
46 const SkScalar sin = std::sin(angle);
47 xform = SkRSXform::Make(sin, cos, fRadius*cos, -fRadius*sin);
48 }
49 }
constexpr float SK_FloatPI
@ kUTF8
uses bytes to represent UTF-8 or ASCII
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
constexpr auto SkMakeZip(Ts &&... ts)
Definition: SkZip.h:212
Definition: SkFont.h:35
void setSubpixel(bool subpixel)
Definition: SkFont.cpp:109
void getPos(const SkGlyphID glyphs[], int count, SkPoint pos[], SkPoint origin={0, 0}) const
Definition: SkFont.cpp:258
void setSize(SkScalar textSize)
Definition: SkFont.cpp:129
int countText(const void *text, size_t byteLength, SkTextEncoding encoding) const
Definition: SkFont.h:323
int textToGlyphs(const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const
Definition: SkFont.cpp:181
T * append()
Definition: SkTDArray.h:191
static const char gText[]
Definition: drawglyphs.cpp:19
float SkScalar
Definition: extension.cpp:12
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
constexpr float x() const
Definition: SkPoint_impl.h:181
static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition: SkRSXform.h:24

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