Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
SkTypeface_FreeType Class Referenceabstract

#include <SkTypeface_FreeType.h>

Inheritance diagram for SkTypeface_FreeType:
SkTypeface SkWeakRefCnt SkRefCnt SkRefCntBase SkTypeface_Custom SkTypeface_FCI SkTypeface_FreeTypeStream SkTypeface_fontconfig SkTypeface_Empty SkTypeface_File SkTypeface_Fuchsia

Classes

class  FaceRec
 

Public Member Functions

std::unique_ptr< SkFontDatamakeFontData () const
 
FaceRecgetFaceRec () const
 
- Public Member Functions inherited from SkTypeface
SkFontStyle fontStyle () const
 
bool isBold () const
 
bool isItalic () const
 
bool isFixedPitch () const
 
int getVariationDesignPosition (SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
 
int getVariationDesignParameters (SkFontParameters::Variation::Axis parameters[], int parameterCount) const
 
SkTypefaceID uniqueID () const
 
sk_sp< SkTypefacemakeClone (const SkFontArguments &) const
 
void serialize (SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
 
sk_sp< SkDataserialize (SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
 
void unicharsToGlyphs (const SkUnichar uni[], int count, SkGlyphID glyphs[]) const
 
int textToGlyphs (const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const
 
SkGlyphID unicharToGlyph (SkUnichar unichar) const
 
int countGlyphs () const
 
int countTables () const
 
int getTableTags (SkFontTableTag tags[]) const
 
size_t getTableSize (SkFontTableTag) const
 
size_t getTableData (SkFontTableTag tag, size_t offset, size_t length, void *data) const
 
sk_sp< SkDatacopyTableData (SkFontTableTag tag) const
 
int getUnitsPerEm () const
 
bool getKerningPairAdjustments (const SkGlyphID glyphs[], int count, int32_t adjustments[]) const
 
LocalizedStringscreateFamilyNameIterator () const
 
void getFamilyName (SkString *name) const
 
bool getPostScriptName (SkString *name) const
 
std::unique_ptr< SkStreamAssetopenStream (int *ttcIndex) const
 
std::unique_ptr< SkStreamAssetopenExistingStream (int *ttcIndex) const
 
std::unique_ptr< SkScalerContextcreateScalerContext (const SkScalerContextEffects &, const SkDescriptor *) const
 
SkRect getBounds () const
 
void filterRec (SkScalerContextRec *rec) const
 
void getFontDescriptor (SkFontDescriptor *desc, bool *isLocal) const
 
void * internal_private_getCTFontRef () const
 
- Public Member Functions inherited from SkWeakRefCnt
 SkWeakRefCnt ()
 
 ~SkWeakRefCnt () override
 
bool try_ref () const
 
void weak_ref () const
 
void weak_unref () const
 
bool weak_expired () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static int GetUnitsPerEm (FT_Face face)
 
static sk_sp< SkTypefaceMakeFromStream (std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
 
- Static Public Member Functions inherited from SkTypeface
static bool Equal (const SkTypeface *facea, const SkTypeface *faceb)
 
static sk_sp< SkTypefaceMakeEmpty ()
 
static sk_sp< SkTypefaceMakeDeserialize (SkStream *, sk_sp< SkFontMgr > lastResortMgr)
 
static void Register (FactoryId id, sk_sp< SkTypeface >(*make)(std::unique_ptr< SkStreamAsset >, const SkFontArguments &))
 

Static Public Attributes

static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('f','r','e','e')
 

Protected Member Functions

 SkTypeface_FreeType (const SkFontStyle &style, bool isFixedPitch)
 
 ~SkTypeface_FreeType () override
 
std::unique_ptr< SkFontDatacloneFontData (const SkFontArguments &, SkFontStyle *style) const
 
std::unique_ptr< SkScalerContextonCreateScalerContext (const SkScalerContextEffects &, const SkDescriptor *) const override
 
void onFilterRec (SkScalerContextRec *) const override
 
void getGlyphToUnicodeMap (SkUnichar *) const override
 
std::unique_ptr< SkAdvancedTypefaceMetricsonGetAdvancedMetrics () const override
 
void getPostScriptGlyphNames (SkString *dstArray) const override
 
bool onGetPostScriptName (SkString *) const override
 
int onGetUPEM () const override
 
bool onGetKerningPairAdjustments (const uint16_t glyphs[], int count, int32_t adjustments[]) const override
 
void onCharsToGlyphs (const SkUnichar uni[], int count, SkGlyphID glyphs[]) const override
 
int onCountGlyphs () const override
 
LocalizedStringsonCreateFamilyNameIterator () const override
 
bool onGlyphMaskNeedsCurrentColor () const override
 
int onGetVariationDesignPosition (SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const override
 
int onGetVariationDesignParameters (SkFontParameters::Variation::Axis parameters[], int parameterCount) const override
 
int onGetTableTags (SkFontTableTag tags[]) const override
 
size_t onGetTableData (SkFontTableTag, size_t offset, size_t length, void *data) const override
 
sk_sp< SkDataonCopyTableData (SkFontTableTag) const override
 
virtual std::unique_ptr< SkFontDataonMakeFontData () const =0
 
- Protected Member Functions inherited from SkTypeface
 SkTypeface (const SkFontStyle &style, bool isFixedPitch=false)
 
 ~SkTypeface () override
 
virtual sk_sp< SkTypefaceonMakeClone (const SkFontArguments &) const =0
 
void setIsFixedPitch (bool isFixedPitch)
 
void setFontStyle (SkFontStyle style)
 
virtual std::unique_ptr< SkStreamAssetonOpenStream (int *ttcIndex) const =0
 
virtual std::unique_ptr< SkStreamAssetonOpenExistingStream (int *ttcIndex) const
 
virtual void onGetFontDescriptor (SkFontDescriptor *, bool *isLocal) const =0
 
virtual void onCharsToGlyphs (const SkUnichar *chars, int count, SkGlyphID glyphs[]) const =0
 
virtual void onGetFamilyName (SkString *familyName) const =0
 
virtual bool onComputeBounds (SkRect *) const
 
virtual void * onGetCTFontRef () const
 
- Protected Member Functions inherited from SkWeakRefCnt
virtual void weak_dispose () const
 

Static Protected Member Functions

static void FontDataPaletteToDescriptorPalette (const SkFontData &, SkFontDescriptor *)
 

Additional Inherited Members

- Public Types inherited from SkTypeface
enum class  SerializeBehavior { kDoIncludeData , kDontIncludeData , kIncludeDataIfLocal }
 
using FactoryId = SkFourByteTag
 

Detailed Description

Definition at line 32 of file SkTypeface_FreeType.h.

Constructor & Destructor Documentation

◆ SkTypeface_FreeType()

SkTypeface_FreeType::SkTypeface_FreeType ( const SkFontStyle style,
bool  isFixedPitch 
)
protected

Definition at line 1706 of file SkFontHost_FreeType.cpp.

1707 : INHERITED(style, isFixedPitch)
1708{}
bool isFixedPitch() const
Definition SkTypeface.h:68

◆ ~SkTypeface_FreeType()

SkTypeface_FreeType::~SkTypeface_FreeType ( )
overrideprotected

Definition at line 1710 of file SkFontHost_FreeType.cpp.

1710 {
1711 if (fFaceRec) {
1713 fFaceRec.reset();
1714 }
1715}
static SkMutex & f_t_mutex()

Member Function Documentation

◆ cloneFontData()

std::unique_ptr< SkFontData > SkTypeface_FreeType::cloneFontData ( const SkFontArguments args,
SkFontStyle style 
) const
protected

Definition at line 749 of file SkFontHost_FreeType.cpp.

750 {
751 AutoFTAccess fta(this);
752 FT_Face face = fta.face();
753 if (!face) {
754 return nullptr;
755 }
756
757 SkFontScanner::AxisDefinitions axisDefinitions;
758 if (!SkFontScanner_FreeType::GetAxes(face, &axisDefinitions)) {
759 return nullptr;
760 }
761 int axisCount = axisDefinitions.size();
762
764 int currentAxisCount = GetVariationDesignPosition(fta, currentPosition, axisCount);
765
767 AutoSTMalloc<4, SkFixed> axisValues(axisCount);
769 axisDefinitions,
770 args.getVariationDesignPosition(),
771 axisValues,
772 name, style,
773 currentAxisCount == axisCount ? currentPosition.get() : nullptr);
774
775 int ttcIndex;
776 std::unique_ptr<SkStreamAsset> stream = this->openStream(&ttcIndex);
777
778 return std::make_unique<SkFontData>(std::move(stream),
779 ttcIndex,
780 args.getPalette().index,
781 axisValues.get(),
782 axisCount,
783 args.getPalette().overrides,
784 args.getPalette().overrideCount);
785}
static int GetVariationDesignPosition(AutoFTAccess &fta, SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount)
struct FT_FaceRec_ * FT_Face
static bool GetAxes(FT_Face face, AxisDefinitions *axes)
static void computeAxisValues(AxisDefinitions axisDefinitions, const SkFontArguments::VariationPosition position, SkFixed *axisValues, const SkString &name, SkFontStyle *style, const SkFontArguments::VariationPosition::Coordinate *currentPosition=nullptr)
std::unique_ptr< SkStreamAsset > openStream(int *ttcIndex) const
int size() const
Definition SkTArray.h:416
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const char * name
Definition fuchsia.cc:50

◆ FontDataPaletteToDescriptorPalette()

void SkTypeface_FreeType::FontDataPaletteToDescriptorPalette ( const SkFontData fontData,
SkFontDescriptor desc 
)
staticprotected

Utility to fill out the SkFontDescriptor palette information from the SkFontData.

Definition at line 1941 of file SkFontHost_FreeType.cpp.

1942 {
1943 desc->setPaletteIndex(fontData.getPaletteIndex());
1944 int paletteOverrideCount = fontData.getPaletteOverrideCount();
1945 auto overrides = desc->setPaletteEntryOverrides(paletteOverrideCount);
1946 for (int i = 0; i < paletteOverrideCount; ++i) {
1947 overrides[i] = fontData.getPaletteOverrides()[i];
1948 }
1949}
const SkFontArguments::Palette::Override * getPaletteOverrides() const
int getPaletteIndex() const
int getPaletteOverrideCount() const

◆ getFaceRec()

SkTypeface_FreeType::FaceRec * SkTypeface_FreeType::getFaceRec ( ) const

Definition at line 1931 of file SkFontHost_FreeType.cpp.

1931 {
1932 f_t_mutex().assertHeld();
1933 fFTFaceOnce([this]{ fFaceRec = SkTypeface_FreeType::FaceRec::Make(this); });
1934 return fFaceRec.get();
1935}
static std::unique_ptr< FaceRec > Make(const SkTypeface_FreeType *typeface)

◆ getGlyphToUnicodeMap()

void SkTypeface_FreeType::getGlyphToUnicodeMap ( SkUnichar dstArray) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 620 of file SkFontHost_FreeType.cpp.

620 {
621 AutoFTAccess fta(this);
622 FT_Face face = fta.face();
623 if (!face) {
624 return;
625 }
626
627 FT_Long numGlyphs = face->num_glyphs;
628 if (!dstArray) { SkASSERT(numGlyphs == 0); }
629 sk_bzero(dstArray, sizeof(SkUnichar) * numGlyphs);
630
631 FT_UInt glyphIndex;
632 SkUnichar charCode = FT_Get_First_Char(face, &glyphIndex);
633 while (glyphIndex) {
634 SkASSERT(glyphIndex < SkToUInt(numGlyphs));
635 // Use the first character that maps to this glyphID. https://crbug.com/359065
636 if (0 == dstArray[glyphIndex]) {
637 dstArray[glyphIndex] = charCode;
638 }
639 charCode = FT_Get_Next_Char(face, charCode, &glyphIndex);
640 }
641}
#define SkASSERT(cond)
Definition SkAssert.h:116
static void sk_bzero(void *buffer, size_t size)
Definition SkMalloc.h:105
constexpr unsigned SkToUInt(S x)
Definition SkTo.h:30
int32_t SkUnichar
Definition SkTypes.h:175

◆ getPostScriptGlyphNames()

void SkTypeface_FreeType::getPostScriptGlyphNames ( SkString dstArray) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 643 of file SkFontHost_FreeType.cpp.

643 {
644 AutoFTAccess fta(this);
645 FT_Face face = fta.face();
646 if (!face) {
647 return;
648 }
649
650 FT_Long numGlyphs = face->num_glyphs;
651 if (!dstArray) { SkASSERT(numGlyphs == 0); }
652
653 if (FT_HAS_GLYPH_NAMES(face)) {
654 for (int gID = 0; gID < numGlyphs; ++gID) {
655 char glyphName[128]; // PS limit for names is 127 bytes.
656 FT_Get_Glyph_Name(face, gID, glyphName, 128);
657 dstArray[gID] = glyphName;
658 }
659 }
660}

◆ GetUnitsPerEm()

int SkTypeface_FreeType::GetUnitsPerEm ( FT_Face  face)
static

Fetch units/EM from "head" table if needed (ie for bitmap fonts)

Definition at line 817 of file SkFontHost_FreeType.cpp.

817 {
818 SkASSERT(face);
819
820 SkScalar upem = SkIntToScalar(face->units_per_EM);
821 // At least some versions of FreeType set face->units_per_EM to 0 for bitmap only fonts.
822 if (upem == 0) {
823 TT_Header* ttHeader = (TT_Header*)FT_Get_Sfnt_Table(face, ft_sfnt_head);
824 if (ttHeader) {
825 upem = SkIntToScalar(ttHeader->Units_Per_EM);
826 }
827 }
828 return upem;
829}
#define SkIntToScalar(x)
Definition SkScalar.h:57
float SkScalar
Definition extension.cpp:12

◆ makeFontData()

std::unique_ptr< SkFontData > SkTypeface_FreeType::makeFontData ( ) const

Return the font data, or nullptr on failure.

Definition at line 1937 of file SkFontHost_FreeType.cpp.

1937 {
1938 return this->onMakeFontData();
1939}
virtual std::unique_ptr< SkFontData > onMakeFontData() const =0

◆ MakeFromStream()

sk_sp< SkTypeface > SkTypeface_FreeType::MakeFromStream ( std::unique_ptr< SkStreamAsset stream,
const SkFontArguments args 
)
static

Definition at line 1999 of file SkFontHost_FreeType.cpp.

2000 {
2001 static SkFontScanner_FreeType scanner;
2002 bool isFixedPitch;
2003 SkFontStyle style;
2004 SkString name;
2005 SkFontScanner::AxisDefinitions axisDefinitions;
2006 if (!scanner.scanInstance(stream.get(), args.getCollectionIndex(), 0,
2007 &name, &style, &isFixedPitch, &axisDefinitions)) {
2008 return nullptr;
2009 }
2010
2011 const SkFontArguments::VariationPosition position = args.getVariationDesignPosition();
2012 AutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.size());
2013 SkFontScanner_FreeType::computeAxisValues(axisDefinitions, position, axisValues, name, &style);
2014
2015 auto data = std::make_unique<SkFontData>(
2016 std::move(stream), args.getCollectionIndex(), args.getPalette().index,
2017 axisValues.get(), axisDefinitions.size(),
2018 args.getPalette().overrides, args.getPalette().overrideCount);
2019 return sk_make_sp<SkTypeface_FreeTypeStream>(std::move(data), name, style, isFixedPitch);
2020}
bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const override
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ onCharsToGlyphs()

void SkTypeface_FreeType::onCharsToGlyphs ( const SkUnichar  uni[],
int  count,
SkGlyphID  glyphs[] 
) const
overrideprotected

Definition at line 1720 of file SkFontHost_FreeType.cpp.

1721 {
1722 // Try the cache first, *before* accessing freetype lib/face, as that
1723 // can be very slow. If we do need to compute a new glyphID, then
1724 // access those freetype objects and continue the loop.
1725
1726 int i;
1727 {
1728 // Optimistically use a shared lock.
1729 SkAutoSharedMutexShared ama(fC2GCacheMutex);
1730 for (i = 0; i < count; ++i) {
1731 int index = fC2GCache.findGlyphIndex(uni[i]);
1732 if (index < 0) {
1733 break;
1734 }
1735 glyphs[i] = SkToU16(index);
1736 }
1737 if (i == count) {
1738 // we're done, no need to access the freetype objects
1739 return;
1740 }
1741 }
1742
1743 // Need to add more so grab an exclusive lock.
1744 SkAutoSharedMutexExclusive ama(fC2GCacheMutex);
1745 AutoFTAccess fta(this);
1746 FT_Face face = fta.face();
1747 if (!face) {
1748 sk_bzero(glyphs, count * sizeof(glyphs[0]));
1749 return;
1750 }
1751
1752 for (; i < count; ++i) {
1753 SkUnichar c = uni[i];
1754 int index = fC2GCache.findGlyphIndex(c);
1755 if (index >= 0) {
1756 glyphs[i] = SkToU16(index);
1757 } else {
1758 glyphs[i] = SkToU16(FT_Get_Char_Index(face, c));
1759 fC2GCache.insertCharAndGlyph(~index, c, glyphs[i]);
1760 }
1761 }
1762
1763 if (fC2GCache.count() > kMaxC2GCacheCount) {
1764 fC2GCache.reset();
1765 }
1766}
uint16_t glyphs[5]
int count
constexpr int kMaxC2GCacheCount
constexpr uint16_t SkToU16(S x)
Definition SkTo.h:24
int findGlyphIndex(SkUnichar c) const
void insertCharAndGlyph(int index, SkUnichar, SkGlyphID)

◆ onCopyTableData()

sk_sp< SkData > SkTypeface_FreeType::onCopyTableData ( SkFontTableTag  tag) const
overrideprotectedvirtual

Reimplemented from SkTypeface.

Definition at line 1904 of file SkFontHost_FreeType.cpp.

1904 {
1905 AutoFTAccess fta(this);
1906 FT_Face face = fta.face();
1907 if (!face) {
1908 return nullptr;
1909 }
1910
1911 FT_ULong tableLength = 0;
1912 FT_Error error;
1913
1914 // When 'length' is 0 it is overwritten with the full table length; 'offset' is ignored.
1915 error = FT_Load_Sfnt_Table(face, tag, 0, nullptr, &tableLength);
1916 if (error) {
1917 return nullptr;
1918 }
1919
1921 if (data) {
1922 error = FT_Load_Sfnt_Table(face, tag, 0,
1923 reinterpret_cast<FT_Byte*>(data->writable_data()), &tableLength);
1924 if (error) {
1925 data.reset();
1926 }
1927 }
1928 return data;
1929}
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition SkData.cpp:116
const uint8_t uint32_t uint32_t GError ** error

◆ onCountGlyphs()

int SkTypeface_FreeType::onCountGlyphs ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 1768 of file SkFontHost_FreeType.cpp.

1768 {
1769 AutoFTAccess fta(this);
1770 FT_Face face = fta.face();
1771 return face ? face->num_glyphs : 0;
1772}

◆ onCreateFamilyNameIterator()

SkTypeface::LocalizedStrings * SkTypeface_FreeType::onCreateFamilyNameIterator ( ) const
overrideprotectedvirtual

Returns an iterator over the family names in the font.

Implements SkTypeface.

Definition at line 1774 of file SkFontHost_FreeType.cpp.

1774 {
1777 if (!nameIter) {
1778 SkString familyName;
1779 this->getFamilyName(&familyName);
1780 SkString language("und"); //undetermined
1781 nameIter = sk_make_sp<SkOTUtils::LocalizedStrings_SingleName>(familyName, language);
1782 }
1783 return nameIter.release();
1784}
static sk_sp< LocalizedStrings_NameTable > MakeForFamilyNames(const SkTypeface &typeface)
void getFamilyName(SkString *name) const
T * release()
Definition SkRefCnt.h:324

◆ onCreateScalerContext()

std::unique_ptr< SkScalerContext > SkTypeface_FreeType::onCreateScalerContext ( const SkScalerContextEffects effects,
const SkDescriptor desc 
) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 692 of file SkFontHost_FreeType.cpp.

694{
695 auto c = std::make_unique<SkScalerContext_FreeType>(
696 sk_ref_sp(const_cast<SkTypeface_FreeType*>(this)), effects, desc);
697 if (c->success()) {
698 return c;
699 }
701 sk_ref_sp(const_cast<SkTypeface_FreeType*>(this)), effects, desc);
702}
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
static std::unique_ptr< SkScalerContext > MakeEmpty(sk_sp< SkTypeface > typeface, const SkScalerContextEffects &effects, const SkDescriptor *desc)

◆ onFilterRec()

void SkTypeface_FreeType::onFilterRec ( SkScalerContextRec rec) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 787 of file SkFontHost_FreeType.cpp.

787 {
788 //BOGUS: http://code.google.com/p/chromium/issues/detail?id=121119
789 //Cap the requested size as larger sizes give bogus values.
790 //Remove when http://code.google.com/p/skia/issues/detail?id=554 is fixed.
791 //Note that this also currently only protects against large text size requests,
792 //the total matrix is not taken into account here.
793 if (rec->fTextSize > SkIntToScalar(1 << 14)) {
794 rec->fTextSize = SkIntToScalar(1 << 14);
795 }
796
797 SkFontHinting h = rec->getHinting();
798 if (SkFontHinting::kFull == h && !isLCD(*rec)) {
799 // collapse full->normal hinting if we're not doing LCD
801 }
802
803 // rotated text looks bad with hinting, so we disable it as needed
804 if (!isAxisAligned(*rec)) {
806 }
807 rec->setHinting(h);
808
809#ifndef SK_GAMMA_APPLY_TO_A8
810 if (!isLCD(*rec)) {
811 // SRGBTODO: Is this correct? Do we want contrast boost?
812 rec->ignorePreBlend();
813 }
814#endif
815}
static bool isLCD(const SkScalerContextRec &rec)
static bool isAxisAligned(const SkScalerContextRec &rec)
SkFontHinting
Definition SkFontTypes.h:18
@ kNormal
glyph outlines modified to improve constrast
@ kNone
glyph outlines unchanged
@ kFull
modifies glyph outlines for maximum constrast
SkScalar h
SkFontHinting getHinting() const
void setHinting(SkFontHinting)

◆ onGetAdvancedMetrics()

std::unique_ptr< SkAdvancedTypefaceMetrics > SkTypeface_FreeType::onGetAdvancedMetrics ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 549 of file SkFontHost_FreeType.cpp.

549 {
550 AutoFTAccess fta(this);
551 FT_Face face = fta.face();
552 if (!face) {
553 return nullptr;
554 }
555
556 std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
557 info->fPostScriptName.set(FT_Get_Postscript_Name(face));
558
559 if (FT_HAS_MULTIPLE_MASTERS(face)) {
561 }
562 if (!canEmbed(face)) {
564 }
565 if (!canSubset(face)) {
567 }
568
569 info->fType = get_font_type(face);
573 {
575 }
576
578 if (FT_IS_FIXED_WIDTH(face)) {
580 }
581 if (face->style_flags & FT_STYLE_FLAG_ITALIC) {
583 }
584
585 PS_FontInfoRec psFontInfo;
586 TT_Postscript* postTable;
587 if (FT_Get_PS_Font_Info(face, &psFontInfo) == 0) {
588 info->fItalicAngle = psFontInfo.italic_angle;
589 } else if ((postTable = (TT_Postscript*)FT_Get_Sfnt_Table(face, ft_sfnt_post)) != nullptr) {
590 info->fItalicAngle = SkFixedFloorToInt(postTable->italicAngle);
591 } else {
592 info->fItalicAngle = 0;
593 }
594
595 info->fAscent = face->ascender;
596 info->fDescent = face->descender;
597
598 TT_PCLT* pcltTable;
599 TT_OS2* os2Table;
600 if ((pcltTable = (TT_PCLT*)FT_Get_Sfnt_Table(face, ft_sfnt_pclt)) != nullptr) {
601 info->fCapHeight = pcltTable->CapHeight;
602 uint8_t serif_style = pcltTable->SerifStyle & 0x3F;
603 if (2 <= serif_style && serif_style <= 6) {
605 } else if (9 <= serif_style && serif_style <= 12) {
607 }
608 } else if (((os2Table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != nullptr) &&
609 // sCapHeight is available only when version 2 or later.
610 os2Table->version != 0xFFFF &&
611 os2Table->version >= 2)
612 {
613 info->fCapHeight = os2Table->sCapHeight;
614 }
615 info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax,
616 face->bbox.xMax, face->bbox.yMin);
617 return info;
618}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkFixedFloorToInt(x)
Definition SkFixed.h:78
static SkAdvancedTypefaceMetrics::FontType get_font_type(FT_Face face)
static bool is_opentype_font_data_standard_format(const SkTypeface &typeface)
static bool canEmbed(FT_Face face)
static bool canSubset(FT_Face face)
@ kNotEmbeddable_FontFlag
May not be embedded.
@ kAltDataFormat_FontFlag
Data compressed. Table access may still work.
@ kNotSubsettable_FontFlag
May not be subset.
@ kVariable_FontFlag
May be true for Type1, CFF, or TrueType fonts.
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition SkRect.h:91

◆ onGetKerningPairAdjustments()

bool SkTypeface_FreeType::onGetKerningPairAdjustments ( const uint16_t  glyphs[],
int  count,
int32_t  adjustments[] 
) const
overrideprotectedvirtual

Reimplemented from SkTypeface.

Definition at line 840 of file SkFontHost_FreeType.cpp.

841 {
842 AutoFTAccess fta(this);
843 FT_Face face = fta.face();
844 if (!face || !FT_HAS_KERNING(face)) {
845 return false;
846 }
847
848 for (int i = 0; i < count - 1; ++i) {
849 FT_Vector delta;
850 FT_Error err = FT_Get_Kerning(face, glyphs[i], glyphs[i+1],
851 FT_KERNING_UNSCALED, &delta);
852 if (err) {
853 return false;
854 }
855 adjustments[i] = delta.x;
856 }
857 return true;
858}

◆ onGetPostScriptName()

bool SkTypeface_FreeType::onGetPostScriptName ( SkString skPostScriptName) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 662 of file SkFontHost_FreeType.cpp.

662 {
663 AutoFTAccess fta(this);
664 FT_Face face = fta.face();
665 if (!face) {
666 return false;
667 }
668
669 const char* ftPostScriptName = FT_Get_Postscript_Name(face);
670 if (!ftPostScriptName) {
671 return false;
672 }
673 if (skPostScriptName) {
674 *skPostScriptName = ftPostScriptName;
675 }
676 return true;
677}

◆ onGetTableData()

size_t SkTypeface_FreeType::onGetTableData ( SkFontTableTag  tag,
size_t  offset,
size_t  length,
void *  data 
) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 1872 of file SkFontHost_FreeType.cpp.

1874{
1875 AutoFTAccess fta(this);
1876 FT_Face face = fta.face();
1877 if (!face) {
1878 return 0;
1879 }
1880
1881 FT_ULong tableLength = 0;
1882 FT_Error error;
1883
1884 // When 'length' is 0 it is overwritten with the full table length; 'offset' is ignored.
1885 error = FT_Load_Sfnt_Table(face, tag, 0, nullptr, &tableLength);
1886 if (error) {
1887 return 0;
1888 }
1889
1890 if (offset > tableLength) {
1891 return 0;
1892 }
1893 FT_ULong size = std::min((FT_ULong)length, tableLength - (FT_ULong)offset);
1894 if (data) {
1895 error = FT_Load_Sfnt_Table(face, tag, offset, reinterpret_cast<FT_Byte*>(data), &size);
1896 if (error) {
1897 return 0;
1898 }
1899 }
1900
1901 return size;
1902}
size_t length
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
Point offset

◆ onGetTableTags()

int SkTypeface_FreeType::onGetTableTags ( SkFontTableTag  tags[]) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 1842 of file SkFontHost_FreeType.cpp.

1842 {
1843 AutoFTAccess fta(this);
1844 FT_Face face = fta.face();
1845 if (!face) {
1846 return 0;
1847 }
1848
1849 FT_ULong tableCount = 0;
1850 FT_Error error;
1851
1852 // When 'tag' is nullptr, returns number of tables in 'length'.
1853 error = FT_Sfnt_Table_Info(face, 0, nullptr, &tableCount);
1854 if (error) {
1855 return 0;
1856 }
1857
1858 if (tags) {
1859 for (FT_ULong tableIndex = 0; tableIndex < tableCount; ++tableIndex) {
1860 FT_ULong tableTag;
1861 FT_ULong tablelength;
1862 error = FT_Sfnt_Table_Info(face, tableIndex, &tableTag, &tablelength);
1863 if (error) {
1864 return 0;
1865 }
1866 tags[tableIndex] = static_cast<SkFontTableTag>(tableTag);
1867 }
1868 }
1869 return tableCount;
1870}
uint32_t SkFontTableTag
Definition SkTypeface.h:41

◆ onGetUPEM()

int SkTypeface_FreeType::onGetUPEM ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 831 of file SkFontHost_FreeType.cpp.

831 {
832 AutoFTAccess fta(this);
833 FT_Face face = fta.face();
834 if (!face) {
835 return 0;
836 }
837 return GetUnitsPerEm(face);
838}
static int GetUnitsPerEm(FT_Face face)

◆ onGetVariationDesignParameters()

int SkTypeface_FreeType::onGetVariationDesignParameters ( SkFontParameters::Variation::Axis  parameters[],
int  parameterCount 
) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 1805 of file SkFontHost_FreeType.cpp.

1807{
1808 AutoFTAccess fta(this);
1809 FT_Face face = fta.face();
1810 if (!face) {
1811 return -1;
1812 }
1813
1814 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) {
1815 return 0;
1816 }
1817
1818 FT_MM_Var* variations = nullptr;
1819 if (FT_Get_MM_Var(face, &variations)) {
1820 return -1;
1821 }
1822 UniqueVoidPtr autoFreeVariations(variations);
1823
1824 if (!parameters || parameterCount < SkToInt(variations->num_axis)) {
1825 return variations->num_axis;
1826 }
1827
1828 for (FT_UInt i = 0; i < variations->num_axis; ++i) {
1829 parameters[i].tag = variations->axis[i].tag;
1830 parameters[i].min = SkFixedToScalar(variations->axis[i].minimum);
1831 parameters[i].def = SkFixedToScalar(variations->axis[i].def);
1832 parameters[i].max = SkFixedToScalar(variations->axis[i].maximum);
1833 FT_UInt flags = 0;
1834 bool hidden = !FT_Get_Var_Axis_Flags(variations, i, &flags) &&
1835 (flags & FT_VAR_AXIS_FLAG_HIDDEN);
1836 parameters[i].setHidden(hidden);
1837 }
1838
1839 return variations->num_axis;
1840}
#define SkFixedToScalar(x)
Definition SkFixed.h:124
constexpr int SkToInt(S x)
Definition SkTo.h:29
FlutterSemanticsFlag flags
std::unique_ptr< void, SkOverloadedFunctionObject< void(void *), sk_free > > UniqueVoidPtr

◆ onGetVariationDesignPosition()

int SkTypeface_FreeType::onGetVariationDesignPosition ( SkFontArguments::VariationPosition::Coordinate  coordinates[],
int  coordinateCount 
) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 1798 of file SkFontHost_FreeType.cpp.

1800{
1801 AutoFTAccess fta(this);
1802 return GetVariationDesignPosition(fta, coordinates, coordinateCount);
1803}

◆ onGlyphMaskNeedsCurrentColor()

bool SkTypeface_FreeType::onGlyphMaskNeedsCurrentColor ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 1786 of file SkFontHost_FreeType.cpp.

1786 {
1787 fGlyphMasksMayNeedCurrentColorOnce([this]{
1788 static constexpr SkFourByteTag COLRTag = SkSetFourByteTag('C', 'O', 'L', 'R');
1789 fGlyphMasksMayNeedCurrentColor = this->getTableSize(COLRTag) > 0;
1790#if defined(FT_CONFIG_OPTION_SVG)
1791 static constexpr SkFourByteTag SVGTag = SkSetFourByteTag('S', 'V', 'G', ' ');
1792 fGlyphMasksMayNeedCurrentColor |= this->getTableSize(SVGTag) > 0 ;
1793#endif // FT_CONFIG_OPTION_SVG
1794 });
1795 return fGlyphMasksMayNeedCurrentColor;
1796}
uint32_t SkFourByteTag
Definition SkTypes.h:166
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
size_t getTableSize(SkFontTableTag) const

◆ onMakeFontData()

virtual std::unique_ptr< SkFontData > SkTypeface_FreeType::onMakeFontData ( ) const
protectedpure virtual

Member Data Documentation

◆ FactoryId

constexpr SkTypeface::FactoryId SkTypeface_FreeType::FactoryId = SkSetFourByteTag('f','r','e','e')
staticconstexpr

Definition at line 42 of file SkTypeface_FreeType.h.


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