Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
RandomScalerContext Class Reference
Inheritance diagram for RandomScalerContext:
SkScalerContext

Public Member Functions

 RandomScalerContext (sk_sp< SkRandomTypeface >, const SkScalerContextEffects &, const SkDescriptor *, bool fFakeIt)
 
- Public Member Functions inherited from SkScalerContext
 SkScalerContext (sk_sp< SkTypeface >, const SkScalerContextEffects &, const SkDescriptor *)
 
virtual ~SkScalerContext ()
 
SkTypefacegetTypeface () const
 
SkMask::Format getMaskFormat () const
 
bool isSubpixel () const
 
bool isLinearMetrics () const
 
bool isVertical () const
 
SkGlyph makeGlyph (SkPackedGlyphID, SkArenaAlloc *)
 
void getImage (const SkGlyph &)
 
void getPath (SkGlyph &, SkArenaAlloc *)
 
sk_sp< SkDrawablegetDrawable (SkGlyph &)
 
void getFontMetrics (SkFontMetrics *)
 
const SkScalerContextRecgetRec () const
 
SkScalerContextEffects getEffects () const
 
SkAxisAlignment computeAxisAlignmentForHText () const
 

Protected Member Functions

GlyphMetrics generateMetrics (const SkGlyph &, SkArenaAlloc *) override
 
void generateImage (const SkGlyph &, void *) override
 
bool generatePath (const SkGlyph &, SkPath *) override
 
sk_sp< SkDrawablegenerateDrawable (const SkGlyph &) override
 
void generateFontMetrics (SkFontMetrics *) override
 
- Protected Member Functions inherited from SkScalerContext
virtual GlyphMetrics generateMetrics (const SkGlyph &, SkArenaAlloc *)=0
 
virtual void generateImage (const SkGlyph &glyph, void *imageBuffer)=0
 
virtual bool generatePath (const SkGlyph &, SkPath *)=0
 
virtual sk_sp< SkDrawablegenerateDrawable (const SkGlyph &)
 
virtual void generateFontMetrics (SkFontMetrics *)=0
 
void forceGenerateImageFromPath ()
 
void forceOffGenerateImageFromPath ()
 

Additional Inherited Members

- Public Types inherited from SkScalerContext
enum  Flags {
  kFrameAndFill_Flag = 0x0001 , kUnused = 0x0002 , kEmbeddedBitmapText_Flag = 0x0004 , kEmbolden_Flag = 0x0008 ,
  kSubpixelPositioning_Flag = 0x0010 , kForceAutohinting_Flag = 0x0020 , kHinting_Shift = 7 , kHintingBit1_Flag = 0x0080 ,
  kHintingBit2_Flag = 0x0100 , kLCD_Vertical_Flag = 0x0200 , kLCD_BGROrder_Flag = 0x0400 , kGenA8FromLCD_Flag = 0x0800 ,
  kLinearMetrics_Flag = 0x1000 , kBaselineSnap_Flag = 0x2000 , kNeedsForegroundColor_Flag = 0x4000
}
 
enum  { kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag }
 
- Static Public Member Functions inherited from SkScalerContext
static size_t GetGammaLUTSize (SkScalar contrast, SkScalar deviceGamma, int *width, int *height)
 
static bool GetGammaLUTData (SkScalar contrast, SkScalar deviceGamma, uint8_t *data)
 
static void MakeRecAndEffects (const SkFont &font, const SkPaint &paint, const SkSurfaceProps &surfaceProps, SkScalerContextFlags scalerContextFlags, const SkMatrix &deviceMatrix, SkScalerContextRec *rec, SkScalerContextEffects *effects)
 
static void MakeRecAndEffectsFromFont (const SkFont &font, SkScalerContextRec *rec, SkScalerContextEffects *effects)
 
static std::unique_ptr< SkScalerContextMakeEmpty (sk_sp< SkTypeface > typeface, const SkScalerContextEffects &effects, const SkDescriptor *desc)
 
static SkDescriptorAutoDescriptorGivenRecAndEffects (const SkScalerContextRec &rec, const SkScalerContextEffects &effects, SkAutoDescriptor *ad)
 
static std::unique_ptr< SkDescriptorDescriptorGivenRecAndEffects (const SkScalerContextRec &rec, const SkScalerContextEffects &effects)
 
static void DescriptorBufferGiveRec (const SkScalerContextRec &rec, void *buffer)
 
static bool CheckBufferSizeForRec (const SkScalerContextRec &rec, const SkScalerContextEffects &effects, size_t size)
 
static SkMaskGamma::PreBlend GetMaskPreBlend (const SkScalerContextRec &rec)
 
static SkDescriptorCreateDescriptorAndEffectsUsingPaint (const SkFont &, const SkPaint &, const SkSurfaceProps &, SkScalerContextFlags scalerContextFlags, const SkMatrix &deviceMatrix, SkAutoDescriptor *ad, SkScalerContextEffects *effects)
 
- Static Protected Member Functions inherited from SkScalerContext
static void GenerateMetricsFromPath (SkGlyph *glyph, const SkPath &path, SkMask::Format format, bool verticalLCD, bool a8FromLCD, bool hairline)
 
static void SaturateGlyphBounds (SkGlyph *glyph, SkRect &&)
 
static void SaturateGlyphBounds (SkGlyph *glyph, SkIRect const &)
 
static void GenerateImageFromPath (SkMaskBuilder &dst, const SkPath &path, const SkMaskGamma::PreBlend &maskPreBlend, bool doBGR, bool verticalLCD, bool a8FromLCD, bool hairline)
 
- Protected Attributes inherited from SkScalerContext
SkScalerContextRec fRec
 
const SkMaskGamma::PreBlend fPreBlend
 

Detailed Description

Definition at line 24 of file RandomScalerContext.cpp.

Constructor & Destructor Documentation

◆ RandomScalerContext()

RandomScalerContext::RandomScalerContext ( sk_sp< SkRandomTypeface face,
const SkScalerContextEffects effects,
const SkDescriptor desc,
bool  fFakeIt 
)

Definition at line 49 of file RandomScalerContext.cpp.

53 : SkScalerContext(std::move(face), effects, desc)
54 , fProxy(getRandomTypeface()->proxy()->createScalerContext(SkScalerContextEffects(), desc))
55 , fFakeIt(fakeIt) {
56 fProxy->forceGenerateImageFromPath();
57}
SkScalerContext(sk_sp< SkTypeface >, const SkScalerContextEffects &, const SkDescriptor *)

Member Function Documentation

◆ generateDrawable()

sk_sp< SkDrawable > RandomScalerContext::generateDrawable ( const SkGlyph )
overrideprotectedvirtual

Returns the drawable for the glyph (if any).

The generated drawable will be lifetime scoped to the lifetime of this scaler context. This means the drawable may refer to the scaler context and associated font data.

The drawable does not need to be flattenable (e.g. implement getFactory and getTypeName). Any necessary serialization will be done with makePictureSnapshot.

Reimplemented from SkScalerContext.

Definition at line 151 of file RandomScalerContext.cpp.

151 {
152 SkGlyph* shadowProxyGlyph = fProxyGlyphs.find(glyph.getPackedID());
153 if (shadowProxyGlyph && shadowProxyGlyph->path()) {
154 return nullptr;
155 }
156 return fProxy->generateDrawable(glyph);
157}
const SkPath * path() const
Definition: SkGlyph.cpp:284
V * find(const K &key) const
Definition: SkTHash.h:494

◆ generateFontMetrics()

void RandomScalerContext::generateFontMetrics ( SkFontMetrics )
overrideprotectedvirtual

Retrieves font metrics.

Implements SkScalerContext.

Definition at line 159 of file RandomScalerContext.cpp.

159 {
160 fProxy->getFontMetrics(metrics);
161}

◆ generateImage()

void RandomScalerContext::generateImage ( const SkGlyph glyph,
void *  imageBuffer 
)
overrideprotectedvirtual

Generates the contents of glyph.fImage. When called, glyph.fImage will be pointing to a pre-allocated, uninitialized region of memory of size glyph.imageSize(). This method may not change glyph.fMaskFormat.

Because glyph.imageSize() will determine the size of fImage, generateMetrics will be called before generateImage.

Implements SkScalerContext.

Definition at line 111 of file RandomScalerContext.cpp.

111 {
112 if (fFakeIt) {
113 sk_bzero(imageBuffer, glyph.imageSize());
114 return;
115 }
116
117 SkGlyph* proxyGlyph = fProxyGlyphs.find(glyph.getPackedID());
118 if (!proxyGlyph || !proxyGlyph->path()) {
119 fProxy->getImage(glyph);
120 return;
121 }
122 const SkPath& path = *proxyGlyph->path();
123 const bool hairline = proxyGlyph->pathIsHairline();
124
125 SkBitmap bm;
127 imageBuffer, glyph.rowBytes());
128 bm.eraseColor(0);
129
130 SkCanvas canvas(bm);
131 canvas.translate(-SkIntToScalar(glyph.left()), -SkIntToScalar(glyph.top()));
132 SkPaint paint = this->getRandomTypeface()->paint();
133 if (hairline) {
134 // We have a device path with effects already applied which is normally a fill path.
135 // However here we do not have a fill path and there is no area to fill.
137 paint.setStroke(0);
138 }
139 canvas.drawPath(path, paint); //Need to modify the paint if the devPath is hairline
140}
sk_bzero(glyphs, sizeof(glyphs))
#define SkIntToScalar(x)
Definition: SkScalar.h:57
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition: SkBitmap.cpp:323
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
int top() const
Definition: SkGlyph.h:511
size_t rowBytes() const
Definition: SkGlyph.cpp:233
size_t imageSize() const
Definition: SkGlyph.cpp:241
bool pathIsHairline() const
Definition: SkGlyph.cpp:293
int height() const
Definition: SkGlyph.h:513
int width() const
Definition: SkGlyph.h:512
int left() const
Definition: SkGlyph.h:510
SkPackedGlyphID getPackedID() const
Definition: SkGlyph.h:430
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
const SkPaint & paint() const
const Paint & paint
Definition: color_source.cc:38
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
static SkImageInfo MakeN32Premul(int width, int height)

◆ generateMetrics()

SkScalerContext::GlyphMetrics RandomScalerContext::generateMetrics ( const SkGlyph origGlyph,
SkArenaAlloc alloc 
)
overrideprotectedvirtual

Implements SkScalerContext.

Definition at line 59 of file RandomScalerContext.cpp.

60 {
61 // Here we will change the mask format of the glyph
62 // NOTE: this may be overridden by the base class (e.g. if a mask filter is applied).
64 switch (origGlyph.getGlyphID() % 4) {
65 case 0: format = SkMask::kLCD16_Format; break;
66 case 1: format = SkMask::kA8_Format; break;
67 case 2: format = SkMask::kARGB32_Format; break;
68 case 3: format = SkMask::kBW_Format; break;
69 }
70
71 auto glyph = fProxy->internalMakeGlyph(origGlyph.getPackedID(), format, alloc);
72
73 GlyphMetrics mx(SkMask::kA8_Format);
74 mx.advance = glyph.advanceVector();
75 mx.bounds = glyph.rect();
76 mx.maskFormat = glyph.maskFormat();
77 mx.extraBits = glyph.extraBits();
78
79 if (fFakeIt || (glyph.getGlyphID() % 4) != 2) {
80 mx.neverRequestPath = glyph.setPathHasBeenCalled() && !glyph.path();
81 mx.computeFromPath = !mx.neverRequestPath;
82 return mx;
83 }
84
85 fProxy->getPath(glyph, alloc);
86 if (!glyph.path()) {
87 mx.neverRequestPath = true;
88 return mx;
89 }
90
91 // The proxy glyph has a path, but this glyph does not.
92 // Stash the proxy glyph so it can be used later.
93 const auto packedID = glyph.getPackedID();
94 const SkGlyph* proxyGlyph = fProxyGlyphs.set(packedID, std::move(glyph));
95 const SkPath& proxyPath = *proxyGlyph->path();
96
97 mx.neverRequestPath = true;
98 mx.maskFormat = SkMask::kARGB32_Format;
99 mx.advance = proxyGlyph->advanceVector();
100 mx.extraBits = proxyGlyph->extraBits();
101
102 SkRect storage;
103 const SkPaint& paint = this->getRandomTypeface()->paint();
104 const SkRect& newBounds =
105 paint.doComputeFastBounds(proxyPath.getBounds(), &storage, SkPaint::kFill_Style);
106 newBounds.roundOut(&mx.bounds);
107
108 return mx;
109}
uint16_t extraBits() const
Definition: SkGlyph.h:519
SkGlyphID getGlyphID() const
Definition: SkGlyph.h:429
SkVector advanceVector() const
Definition: SkGlyph.h:425
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
const SkRect & getBounds() const
Definition: SkPath.cpp:430
V * set(K key, V val)
Definition: SkTHash.h:487
uint32_t uint32_t * format
Format
Definition: SkMask.h:26
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:28
@ kLCD16_Format
565 alpha for r/g/b
Definition: SkMask.h:31
@ kARGB32_Format
SkPMColor.
Definition: SkMask.h:30
@ kBW_Format
1bit per pixel mask (e.g. monochrome)
Definition: SkMask.h:27
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

◆ generatePath()

bool RandomScalerContext::generatePath ( const SkGlyph ,
SkPath  
)
overrideprotectedvirtual

Sets the passed path to the glyph outline. If this cannot be done the path is set to empty; Does not apply subpixel positioning to the path.

Returns
false if this glyph does not have any path.

Implements SkScalerContext.

Definition at line 142 of file RandomScalerContext.cpp.

142 {
143 SkGlyph* shadowProxyGlyph = fProxyGlyphs.find(glyph.getPackedID());
144 if (shadowProxyGlyph && shadowProxyGlyph->path()) {
145 path->reset();
146 return false;
147 }
148 return fProxy->generatePath(glyph, path);
149}

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