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

Classes

struct  ScalerContextBits
 

Public Member Functions

 SkFontationsScalerContext (sk_sp< SkTypeface_Fontations > face, const SkScalerContextEffects &effects, const SkDescriptor *desc)
 
bool generateYScalePathForGlyphId (uint16_t glyphId, SkPath *path, float yScale)
 
- 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 generatePngImage (const SkGlyph &glyph, void *imageBuffer)
 
void generateImage (const SkGlyph &glyph, void *imageBuffer) override
 
bool generatePath (const SkGlyph &glyph, SkPath *path) override
 
bool drawCOLRGlyph (const SkGlyph &glyph, SkColor foregroundColor, SkCanvas *canvas)
 
sk_sp< SkDrawablegenerateDrawable (const SkGlyph &glyph) override
 
void generateFontMetrics (SkFontMetrics *out_metrics) override
 
- Protected Member Functions inherited from SkScalerContext
void forceGenerateImageFromPath ()
 
void forceOffGenerateImageFromPath ()
 

Friends

class sk_fontations::ColorPainter
 

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 334 of file SkTypeface_fontations.cpp.

Constructor & Destructor Documentation

◆ SkFontationsScalerContext()

SkFontationsScalerContext::SkFontationsScalerContext ( sk_sp< SkTypeface_Fontations face,
const SkScalerContextEffects effects,
const SkDescriptor desc 
)
inline

Definition at line 336 of file SkTypeface_fontations.cpp.

339 : SkScalerContext(face, effects, desc)
340 , fBridgeFontRef(
341 static_cast<SkTypeface_Fontations*>(this->getTypeface())->getBridgeFontRef())
342 , fBridgeNormalizedCoords(static_cast<SkTypeface_Fontations*>(this->getTypeface())
343 ->getBridgeNormalizedCoords())
344 , fOutlines(static_cast<SkTypeface_Fontations*>(this->getTypeface())->getOutlines())
345 , fPalette(static_cast<SkTypeface_Fontations*>(this->getTypeface())->getPalette()) {
346 fRec.getSingleMatrix(&fMatrix);
347 }
SkScalerContextRec fRec
SkTypeface * getTypeface() const
void getSingleMatrix(SkMatrix *) const

Member Function Documentation

◆ drawCOLRGlyph()

bool SkFontationsScalerContext::drawCOLRGlyph ( const SkGlyph glyph,
SkColor  foregroundColor,
SkCanvas canvas 
)
inlineprotected

Definition at line 652 of file SkTypeface_fontations.cpp.

652 {
653 uint16_t upem = fontations_ffi::units_per_em_or_zero(fBridgeFontRef);
654 if (upem == 0) {
655 return false;
656 }
657
658 SkMatrix scalerMatrix;
659 fRec.getSingleMatrix(&scalerMatrix);
660 SkAutoCanvasRestore autoRestore(canvas, true /* doSave */);
661
662 // Scale down so that COLR operations can happen in glyph coordinates.
663 SkMatrix upemToPpem = SkMatrix::Scale(1.f / upem, 1.f / upem);
664 scalerMatrix.preConcat(upemToPpem);
665 canvas->concat(scalerMatrix);
666 SkPaint defaultPaint;
667 defaultPaint.setColor(SK_ColorRED);
668 sk_fontations::ColorPainter colorPainter(*this, *canvas, fPalette, foregroundColor,
670 bool result = fontations_ffi::draw_colr_glyph(
671 fBridgeFontRef, fBridgeNormalizedCoords, glyph.getGlyphID(), colorPainter);
672 return result;
673 }
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
void concat(const SkMatrix &matrix)
SkGlyphID getGlyphID() const
Definition SkGlyph.h:429
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
SkMatrix & preConcat(const SkMatrix &other)
Definition SkMatrix.cpp:674
void setColor(SkColor color)
Definition SkPaint.cpp:119
GAsyncResult * result
@ kBW_Format
1bit per pixel mask (e.g. monochrome)
Definition SkMask.h:27
SkMask::Format fMaskFormat

◆ generateDrawable()

sk_sp< SkDrawable > SkFontationsScalerContext::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 675 of file SkTypeface_fontations.cpp.

675 {
676 struct GlyphDrawable : public SkDrawable {
678 SkGlyph fGlyph;
679 GlyphDrawable(SkFontationsScalerContext* self, const SkGlyph& glyph)
680 : fSelf(self), fGlyph(glyph) {}
681 SkRect onGetBounds() override { return fGlyph.rect(); }
682 size_t onApproximateBytesUsed() override { return sizeof(GlyphDrawable); }
683 void maybeShowTextBlitCoverage(SkCanvas* canvas) {
684 if constexpr (kSkShowTextBlitCoverage) {
686 paint.setColor(0x3300FF00);
687 paint.setStyle(SkPaint::kFill_Style);
688 canvas->drawRect(this->onGetBounds(), paint);
689 }
690 }
691 };
692 struct ColrGlyphDrawable : public GlyphDrawable {
693 using GlyphDrawable::GlyphDrawable;
694 void onDraw(SkCanvas* canvas) override {
695 this->maybeShowTextBlitCoverage(canvas);
696 fSelf->drawCOLRGlyph(fGlyph, fSelf->fRec.fForegroundColor, canvas);
697 }
698 };
699 ScalerContextBits::value_type format = glyph.extraBits();
701 return sk_sp<SkDrawable>(new ColrGlyphDrawable(this, glyph));
702 }
703 return nullptr;
704 }
void drawRect(const SkRect &rect, const SkPaint &paint)
bool drawCOLRGlyph(const SkGlyph &glyph, SkColor foregroundColor, SkCanvas *canvas)
SkRect rect() const
Definition SkGlyph.h:506
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
const Paint & paint
uint32_t uint32_t * format

◆ generateFontMetrics()

void SkFontationsScalerContext::generateFontMetrics ( SkFontMetrics )
inlineoverrideprotectedvirtual

Retrieves font metrics.

Implements SkScalerContext.

Definition at line 706 of file SkTypeface_fontations.cpp.

706 {
708 SkMatrix remainingMatrix;
711 fontations_ffi::Metrics metrics =
712 fontations_ffi::get_skia_metrics(fBridgeFontRef, scale.fY, fBridgeNormalizedCoords);
713 out_metrics->fTop = -metrics.top;
714 out_metrics->fAscent = -metrics.ascent;
715 out_metrics->fDescent = -metrics.descent;
716 out_metrics->fBottom = -metrics.bottom;
717 out_metrics->fLeading = metrics.leading;
718 out_metrics->fAvgCharWidth = metrics.avg_char_width;
719 out_metrics->fMaxCharWidth = metrics.max_char_width;
720 out_metrics->fXMin = metrics.x_min;
721 out_metrics->fXMax = metrics.x_max;
722 out_metrics->fXHeight = -metrics.x_height;
723 out_metrics->fCapHeight = -metrics.cap_height;
724 out_metrics->fFlags = 0;
725 if (fontations_ffi::table_data(fBridgeFontRef,
726 SkSetFourByteTag('f', 'v', 'a', 'r'),
727 0,
728 rust::Slice<uint8_t>())) {
729 out_metrics->fFlags |= SkFontMetrics::kBoundsInvalid_Flag;
730 }
731 auto setMetric = [](float& dstMetric, const float srcMetric,
733 {
734 if (std::isnan(srcMetric)) {
735 dstMetric = 0;
736 } else {
737 dstMetric = srcMetric;
738 flags |= flag;
739 }
740 };
741 setMetric(out_metrics->fUnderlinePosition, -metrics.underline_position,
743 setMetric(out_metrics->fUnderlineThickness, metrics.underline_thickness,
745
746 setMetric(out_metrics->fStrikeoutPosition, -metrics.strikeout_position,
748 setMetric(out_metrics->fStrikeoutThickness, metrics.strikeout_thickness,
750 }
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
FlutterSemanticsFlag flag
FlutterSemanticsFlag flags
const Scalar scale
@ kStrikeoutPositionIsValid_Flag
set if fStrikeoutPosition is valid
@ kStrikeoutThicknessIsValid_Flag
set if fStrikeoutThickness is valid
@ kUnderlinePositionIsValid_Flag
set if fUnderlinePosition is valid
@ kUnderlineThicknessIsValid_Flag
set if fUnderlineThickness is valid
@ kBoundsInvalid_Flag
set if fTop, fBottom, fXMin, fXMax invalid
bool computeMatrices(PreMatrixScale preMatrixScale, SkVector *scale, SkMatrix *remaining, SkMatrix *remainingWithoutRotation=nullptr, SkMatrix *remainingRotation=nullptr, SkMatrix *total=nullptr)

◆ generateImage()

void SkFontationsScalerContext::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 593 of file SkTypeface_fontations.cpp.

593 {
596 const SkPath* devPath = glyph.path();
597 SkASSERT_RELEASE(devPath);
598 SkMaskBuilder mask(static_cast<uint8_t*>(imageBuffer),
599 glyph.iRect(),
600 glyph.rowBytes(),
601 glyph.maskFormat());
602 SkASSERT(SkMask::kARGB32_Format != mask.fFormat);
606 const bool hairline = glyph.pathIsHairline();
607 GenerateImageFromPath(mask, *devPath, fPreBlend, doBGR, doVert, a8LCD, hairline);
608
611 SkBitmap dstBitmap;
612 dstBitmap.setInfo(
614 glyph.width(), glyph.height(), kN32_SkColorType, kPremul_SkAlphaType),
615 glyph.rowBytes());
616 dstBitmap.setPixels(imageBuffer);
617
618 SkCanvas canvas(dstBitmap);
619 if constexpr (kSkShowTextBlitCoverage) {
620 canvas.clear(0x33FF0000);
621 } else {
622 canvas.clear(SK_ColorTRANSPARENT);
623 }
624 canvas.translate(-glyph.left(), -glyph.top());
625
626 drawCOLRGlyph(glyph, fRec.fForegroundColor, &canvas);
627 } else if (format == ScalerContextBits::BITMAP) {
628 generatePngImage(glyph, imageBuffer);
629 } else {
630 SK_ABORT("Bad format");
631 }
632 }
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT_RELEASE(cond)
Definition SkAssert.h:100
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
void setPixels(void *pixels)
Definition SkBitmap.cpp:207
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition SkBitmap.cpp:114
void generatePngImage(const SkGlyph &glyph, void *imageBuffer)
int top() const
Definition SkGlyph.h:511
size_t rowBytes() const
Definition SkGlyph.cpp:233
uint16_t extraBits() const
Definition SkGlyph.h:519
const SkPath * path() const
Definition SkGlyph.cpp:284
SkMask::Format maskFormat() const
Definition SkGlyph.h:500
bool pathIsHairline() const
Definition SkGlyph.cpp:293
int height() const
Definition SkGlyph.h:513
SkIRect iRect() const
Definition SkGlyph.h:505
int width() const
Definition SkGlyph.h:512
int left() const
Definition SkGlyph.h:510
static void GenerateImageFromPath(SkMaskBuilder &dst, const SkPath &path, const SkMaskGamma::PreBlend &maskPreBlend, bool doBGR, bool verticalLCD, bool a8FromLCD, bool hairline)
const SkMaskGamma::PreBlend fPreBlend
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
@ kARGB32_Format
SkPMColor.
Definition SkMask.h:30

◆ generateMetrics()

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

Implements SkScalerContext.

Definition at line 380 of file SkTypeface_fontations.cpp.

380 {
381 GlyphMetrics mx(glyph.maskFormat());
382
384 SkMatrix remainingMatrix;
387 return mx;
388 }
389 float x_advance = 0.0f;
390 x_advance = fontations_ffi::advance_width_or_zero(
391 fBridgeFontRef, scale.y(), fBridgeNormalizedCoords, glyph.getGlyphID());
392 // TODO(drott): y-advance?
393 mx.advance = remainingMatrix.mapXY(x_advance, SkFloatToScalar(0.f));
394
395 // The FreeType backend has a big switch here:
396 // Scalable or bitmap, monochromatic or color, subpixel shifting bounds if needed.
397 // For now: check if COLRv1, get clipbox, else -
398 // get bounds from Path.
399 // TODO(drott): Later move bounds retrieval for monochromatic glyphs to retrieving
400 // them from Skrifa scaler, taking hinting into account.
401
402 bool has_colrv1_glyph =
403 fontations_ffi::has_colrv1_glyph(fBridgeFontRef, glyph.getGlyphID());
404 bool has_colrv0_glyph =
405 fontations_ffi::has_colrv0_glyph(fBridgeFontRef, glyph.getGlyphID());
406 bool has_bitmap_glyph =
407 fontations_ffi::has_bitmap_glyph(fBridgeFontRef, glyph.getGlyphID());
408
409 if (has_colrv1_glyph || has_colrv0_glyph) {
410 mx.extraBits = has_colrv1_glyph ? ScalerContextBits::COLRv1 : ScalerContextBits::COLRv0;
411 mx.maskFormat = SkMask::kARGB32_Format;
412 mx.neverRequestPath = true;
413
414 fontations_ffi::ClipBox clipBox;
415 if (has_colrv1_glyph && fontations_ffi::get_colrv1_clip_box(fBridgeFontRef,
416 fBridgeNormalizedCoords,
417 glyph.getGlyphID(),
418 scale.y(),
419 clipBox)) {
420 // Flip y.
421 SkRect boundsRect = SkRect::MakeLTRB(
422 clipBox.x_min, -clipBox.y_max, clipBox.x_max, -clipBox.y_min);
423
424 if (!remainingMatrix.isIdentity()) {
425 SkPath boundsPath = SkPath::Rect(boundsRect);
426 boundsPath.transform(remainingMatrix);
427 boundsRect = boundsPath.getBounds();
428 }
429
430 boundsRect.roundOut(&mx.bounds);
431
432 } else {
433 uint16_t upem = fontations_ffi::units_per_em_or_zero(fBridgeFontRef);
434 if (upem == 0) {
435 mx.bounds = SkRect::MakeEmpty();
436 } else {
437 SkMatrix fullTransform;
438 fRec.getSingleMatrix(&fullTransform);
439 fullTransform.preScale(1.f / upem, 1.f / upem);
440
441 sk_fontations::BoundsPainter boundsPainter(*this, fullTransform, upem);
442 bool result = fontations_ffi::draw_colr_glyph(fBridgeFontRef,
443 fBridgeNormalizedCoords,
444 glyph.getGlyphID(),
445 boundsPainter);
446 if (result) {
447 boundsPainter.getBoundingBox().roundOut(&mx.bounds);
448 } else {
449 mx.bounds = SkRect::MakeEmpty();
450 }
451 }
452 }
453 } else if (has_bitmap_glyph) {
454 mx.maskFormat = SkMask::kARGB32_Format;
455 mx.neverRequestPath = true;
456 mx.extraBits = ScalerContextBits::BITMAP;
457
458 rust::cxxbridge1::Box<fontations_ffi::BridgeBitmapGlyph> bitmap_glyph =
459 fontations_ffi::bitmap_glyph(fBridgeFontRef, glyph.getGlyphID(), scale.fY);
460 rust::cxxbridge1::Slice<const uint8_t> png_data =
461 fontations_ffi::png_data(*bitmap_glyph);
462 SkASSERT(png_data.size());
463
464 const fontations_ffi::BitmapMetrics bitmapMetrics =
465 fontations_ffi::bitmap_metrics(*bitmap_glyph);
466
467 std::unique_ptr<SkCodec> codec = SkPngDecoder::Decode(
468 SkData::MakeWithoutCopy(png_data.data(), png_data.size()), nullptr);
469 if (!codec) {
470 return mx;
471 }
472
473 SkImageInfo info = codec->getInfo();
474
475 SkRect bounds = SkRect::Make(info.bounds());
476 SkMatrix matrix = remainingMatrix;
477
478 // We deal with two scale factors here: Scaling from font units to
479 // device pixels, and scaling the embedded PNG from its number of
480 // rows to a specific size, depending on the ppem values in the
481 // bitmap glyph information.
482 SkScalar imageToSize = scale.fY / bitmapMetrics.ppem_y;
483 float fontUnitsToSize = scale.fY / fontations_ffi::units_per_em_or_zero(fBridgeFontRef);
484
485 // Relevant for sbix only: Convert the potential restrictive size
486 // bounds back to unscaled pixels so that it can be intersected with
487 // the decompressed pixel size of the sbix image.
488 if (!std::isinf(bitmapMetrics.width) && !std::isinf(bitmapMetrics.height)) {
489 SkRect modifiedBounds =
491 0,
492 bitmapMetrics.width * fontUnitsToSize / imageToSize,
493 bitmapMetrics.height * fontUnitsToSize / imageToSize);
494 if (modifiedBounds.isEmpty()) {
496 } else {
497 bounds = modifiedBounds;
498 }
499 }
500
501 // The offset from origin is given in font units, so requires a
502 // different scale factor than the scaling of the image.
503 matrix.preTranslate(bitmapMetrics.bearing_x * fontUnitsToSize,
504 -bitmapMetrics.bearing_y * fontUnitsToSize);
505
506 matrix.preScale(imageToSize, imageToSize);
507 // For sbix bitmap glyphs, the origin is the bottom left of the image.
508 float heightAdjustment =
509 bitmapMetrics.placement_origin_bottom_left ? bounds.height() : 0;
510 matrix.preTranslate(0, -heightAdjustment);
511
512 if (this->isSubpixel()) {
515 }
516 matrix.mapRect(&bounds);
517 mx.bounds = SkRect::Make(bounds.roundOut());
518 } else {
519 // TODO: Retrieve from read_fonts and Skrifa - TrueType bbox or from path with
520 // hinting?
521 mx.extraBits = ScalerContextBits::PATH;
522 mx.computeFromPath = true;
523 }
524 return mx;
525 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkFixedToScalar(x)
Definition SkFixed.h:124
#define SkFloatToScalar(x)
Definition SkScalar.h:62
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition SkData.h:116
SkFixed getSubYFixed() const
Definition SkGlyph.h:432
SkFixed getSubXFixed() const
Definition SkGlyph.h:431
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition SkMatrix.cpp:281
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
Definition SkMatrix.cpp:777
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:315
bool isIdentity() const
Definition SkMatrix.h:223
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition SkPath.cpp:3518
const SkRect & getBounds() const
Definition SkPath.cpp:420
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition SkPath.cpp:1647
bool isSubpixel() const
float SkScalar
Definition extension.cpp:12
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
Optional< SkRect > bounds
Definition SkRecords.h:189
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
void roundOut(SkIRect *dst) const
Definition SkRect.h:1241
bool isEmpty() const
Definition SkRect.h:693
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

◆ generatePath()

bool SkFontationsScalerContext::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 634 of file SkTypeface_fontations.cpp.

634 {
635 SkASSERT(glyph.extraBits() == ScalerContextBits::PATH);
636
638 SkMatrix remainingMatrix;
641 return false;
642 }
643 bool result = generateYScalePathForGlyphId(glyph.getGlyphID(), path, scale.y());
644 if (!result) {
645 return false;
646 }
647
648 *path = path->makeTransform(remainingMatrix);
649 return true;
650 }
bool generateYScalePathForGlyphId(uint16_t glyphId, SkPath *path, float yScale)
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

◆ generatePngImage()

void SkFontationsScalerContext::generatePngImage ( const SkGlyph glyph,
void *  imageBuffer 
)
inlineprotected

Definition at line 527 of file SkTypeface_fontations.cpp.

527 {
529 SkBitmap dstBitmap;
530 dstBitmap.setInfo(
532 glyph.width(), glyph.height(), kN32_SkColorType, kPremul_SkAlphaType),
533 glyph.rowBytes());
534 dstBitmap.setPixels(imageBuffer);
535
536 SkCanvas canvas(dstBitmap);
537
538 canvas.translate(-glyph.left(), -glyph.top());
539
541 SkMatrix remainingMatrix;
544 return;
545 }
546
547 rust::cxxbridge1::Box<fontations_ffi::BridgeBitmapGlyph> bitmap_glyph =
548 fontations_ffi::bitmap_glyph(fBridgeFontRef, glyph.getGlyphID(), scale.fY);
549 rust::cxxbridge1::Slice<const uint8_t> png_data = fontations_ffi::png_data(*bitmap_glyph);
550 SkASSERT(png_data.size());
551
552 std::unique_ptr<SkCodec> codec = SkPngDecoder::Decode(
553 SkData::MakeWithoutCopy(png_data.data(), png_data.size()), nullptr);
554
555 if (!codec) {
556 return;
557 }
558
559 auto [glyph_image, result] = codec->getImage();
561 return;
562 }
563
564 canvas.clear(SK_ColorTRANSPARENT);
565 canvas.concat(remainingMatrix);
566
567 if (this->isSubpixel()) {
568 canvas.translate(SkFixedToScalar(glyph.getSubXFixed()),
570 }
571 const fontations_ffi::BitmapMetrics bitmapMetrics =
572 fontations_ffi::bitmap_metrics(*bitmap_glyph);
573
574 // We need two different scale factors here, one for font units to size,
575 // one for scaling the embedded PNG, see generateMetrics() for details.
576 SkScalar imageScaleFactor = scale.fY / bitmapMetrics.ppem_y;
577
578 float fontUnitsToSize = scale.fY / fontations_ffi::units_per_em_or_zero(fBridgeFontRef);
579 canvas.translate(bitmapMetrics.bearing_x * fontUnitsToSize,
580 -bitmapMetrics.bearing_y * fontUnitsToSize);
581 canvas.scale(imageScaleFactor, imageScaleFactor);
582 canvas.translate(bitmapMetrics.inner_bearing_x, -bitmapMetrics.inner_bearing_y);
583
584 float heightAdjustment =
585 bitmapMetrics.placement_origin_bottom_left ? glyph_image->height() : 0;
586
587 canvas.translate(0, -heightAdjustment);
588
590 canvas.drawImage(glyph_image, 0, 0, sampling);
591 }
@ kSuccess
Definition SkCodec.h:80
SkSamplingOptions sampling
Definition SkRecords.h:337

◆ generateYScalePathForGlyphId()

bool SkFontationsScalerContext::generateYScalePathForGlyphId ( uint16_t  glyphId,
SkPath path,
float  yScale 
)
inline

Definition at line 350 of file SkTypeface_fontations.cpp.

350 {
352 fontations_ffi::BridgeScalerMetrics scalerMetrics;
353
354 if (!fontations_ffi::get_path(fOutlines,
355 glyphId,
356 yScale,
357 fBridgeNormalizedCoords,
358 pathWrapper,
359 scalerMetrics)) {
360 return false;
361 }
362 *path = std::move(pathWrapper).into_inner();
363 if (scalerMetrics.has_overlaps) {
364 // See SkScalerContext_FreeType_Base::generateGlyphPath.
365 Simplify(*path, path);
366 AsWinding(*path, path);
367 }
368 return true;
369 }
bool SK_API AsWinding(const SkPath &path, SkPath *result)
bool SK_API Simplify(const SkPath &path, SkPath *result)

Friends And Related Symbol Documentation

◆ sk_fontations::ColorPainter

friend class sk_fontations::ColorPainter
friend

Definition at line 759 of file SkTypeface_fontations.cpp.


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