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

Public Member Functions

 SkUserScalerContext (sk_sp< SkUserTypeface > face, const SkScalerContextEffects &effects, const SkDescriptor *desc)
 
const SkUserTypefaceuserTF () const
 
- 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 &glyph, SkArenaAlloc *) override
 
void generateImage (const SkGlyph &glyph, void *imageBuffer) override
 
bool generatePath (const SkGlyph &glyph, SkPath *path) override
 
sk_sp< SkDrawablegenerateDrawable (const SkGlyph &glyph) override
 
void generateFontMetrics (SkFontMetrics *metrics) override
 
- Protected Member Functions inherited from SkScalerContext
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 paintGamma, SkScalar deviceGamma, int *width, int *height)
 
static bool GetGammaLUTData (SkScalar contrast, SkScalar paintGamma, 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 241 of file SkCustomTypeface.cpp.

Constructor & Destructor Documentation

◆ SkUserScalerContext()

SkUserScalerContext::SkUserScalerContext ( sk_sp< SkUserTypeface face,
const SkScalerContextEffects effects,
const SkDescriptor desc 
)
inline

Definition at line 243 of file SkCustomTypeface.cpp.

246 : SkScalerContext(std::move(face), effects, desc) {
247 fRec.getSingleMatrix(&fMatrix);
249 }
void forceGenerateImageFromPath()
SkScalerContextRec fRec
void getSingleMatrix(SkMatrix *) const

Member Function Documentation

◆ generateDrawable()

sk_sp< SkDrawable > SkUserScalerContext::generateDrawable ( const SkGlyph )
inlineoverrideprotectedvirtual

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 306 of file SkCustomTypeface.cpp.

306 {
307 class DrawableMatrixWrapper final : public SkDrawable {
308 public:
309 DrawableMatrixWrapper(sk_sp<SkDrawable> drawable, const SkMatrix& m)
310 : fDrawable(std::move(drawable))
311 , fMatrix(m)
312 {}
313
314 SkRect onGetBounds() override {
315 return fMatrix.mapRect(fDrawable->getBounds());
316 }
317
318 size_t onApproximateBytesUsed() override {
319 return fDrawable->approximateBytesUsed() + sizeof(DrawableMatrixWrapper);
320 }
321
322 void onDraw(SkCanvas* canvas) override {
323 if constexpr (kSkShowTextBlitCoverage) {
325 paint.setColor(0x3300FF00);
326 paint.setStyle(SkPaint::kFill_Style);
327 canvas->drawRect(this->onGetBounds(), paint);
328 }
329 canvas->drawDrawable(fDrawable.get(), &fMatrix);
330 }
331 private:
332 const sk_sp<SkDrawable> fDrawable;
333 const SkMatrix fMatrix;
334 };
335
336 const auto& rec = this->userTF()->fGlyphRecs[glyph.getGlyphID()];
337
338 return rec.fDrawable
339 ? sk_make_sp<DrawableMatrixWrapper>(rec.fDrawable, fMatrix)
340 : nullptr;
341 }
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawDrawable(SkDrawable *drawable, const SkMatrix *matrix=nullptr)
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
const SkUserTypeface * userTF() const
const Paint & paint
Definition ref_ptr.h:256

◆ generateFontMetrics()

void SkUserScalerContext::generateFontMetrics ( SkFontMetrics )
inlineoverrideprotectedvirtual

Retrieves font metrics.

Implements SkScalerContext.

Definition at line 343 of file SkCustomTypeface.cpp.

343 {
344 auto [sx, sy] = fMatrix.mapXY(1, 1);
345 *metrics = scale_fontmetrics(this->userTF()->fMetrics, sx, sy);
346 }
static SkFontMetrics scale_fontmetrics(const SkFontMetrics &src, float sx, float sy)
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
Definition SkMatrix.cpp:777

◆ generateImage()

void SkUserScalerContext::generateImage ( const SkGlyph glyph,
void *  imageBuffer 
)
inlineoverrideprotectedvirtual

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 277 of file SkCustomTypeface.cpp.

277 {
278 const auto& rec = this->userTF()->fGlyphRecs[glyph.getGlyphID()];
279 SkASSERTF(rec.isDrawable(), "Only drawable-backed glyphs should reach generateImage.");
280
281 auto canvas = SkCanvas::MakeRasterDirectN32(glyph.width(), glyph.height(),
282 static_cast<SkPMColor*>(imageBuffer),
283 glyph.rowBytes());
284 if constexpr (kSkShowTextBlitCoverage) {
285 canvas->clear(0x33FF0000);
286 } else {
287 canvas->clear(SK_ColorTRANSPARENT);
288 }
289
290 canvas->translate(-glyph.left(), -glyph.top());
291 canvas->translate(SkFixedToScalar(glyph.getSubXFixed()),
293 canvas->drawDrawable(rec.fDrawable.get(), &fMatrix);
294 }
#define SkASSERTF(cond, fmt,...)
Definition SkAssert.h:117
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
uint32_t SkPMColor
Definition SkColor.h:205
#define SkFixedToScalar(x)
Definition SkFixed.h:124
static std::unique_ptr< SkCanvas > MakeRasterDirectN32(int width, int height, SkPMColor *pixels, size_t rowBytes)
Definition SkCanvas.h:163
int top() const
Definition SkGlyph.h:511
size_t rowBytes() const
Definition SkGlyph.cpp:233
SkGlyphID getGlyphID() const
Definition SkGlyph.h:429
int height() const
Definition SkGlyph.h:513
SkFixed getSubYFixed() const
Definition SkGlyph.h:432
SkFixed getSubXFixed() const
Definition SkGlyph.h:431
int width() const
Definition SkGlyph.h:512
int left() const
Definition SkGlyph.h:510

◆ generateMetrics()

GlyphMetrics SkUserScalerContext::generateMetrics ( const SkGlyph glyph,
SkArenaAlloc  
)
inlineoverrideprotectedvirtual

Implements SkScalerContext.

Definition at line 256 of file SkCustomTypeface.cpp.

256 {
257 GlyphMetrics mx(glyph.maskFormat());
258
259 const SkUserTypeface* tf = this->userTF();
260 mx.advance = fMatrix.mapXY(tf->fGlyphRecs[glyph.getGlyphID()].fAdvance, 0);
261
262 const auto& rec = tf->fGlyphRecs[glyph.getGlyphID()];
263 if (rec.isDrawable()) {
264 mx.maskFormat = SkMask::kARGB32_Format;
265
266 SkRect bounds = fMatrix.mapRect(rec.fBounds);
267 bounds.offset(SkFixedToScalar(glyph.getSubXFixed()),
269 bounds.roundOut(&mx.bounds);
270
271 // These do not have an outline path.
272 mx.neverRequestPath = true;
273 }
274 return mx;
275 }
SkMask::Format maskFormat() const
Definition SkGlyph.h:500
Optional< SkRect > bounds
Definition SkRecords.h:189
@ kARGB32_Format
SkPMColor.
Definition SkMask.h:30

◆ generatePath()

bool SkUserScalerContext::generatePath ( const SkGlyph ,
SkPath  
)
inlineoverrideprotectedvirtual

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 296 of file SkCustomTypeface.cpp.

296 {
297 const auto& rec = this->userTF()->fGlyphRecs[glyph.getGlyphID()];
298
299 SkASSERT(!rec.isDrawable());
300
301 rec.fPath.transform(fMatrix, path);
302
303 return true;
304 }
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ userTF()

const SkUserTypeface * SkUserScalerContext::userTF ( ) const
inline

Definition at line 251 of file SkCustomTypeface.cpp.

251 {
252 return static_cast<SkUserTypeface*>(this->getTypeface());
253 }
SkTypeface * getTypeface() const

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