Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
SkTypeface_Fontations Class Reference

#include <SkTypeface_fontations_priv.h>

Inheritance diagram for SkTypeface_Fontations:
SkTypeface SkWeakRefCnt SkRefCnt SkRefCntBase

Public Member Functions

const fontations_ffi::BridgeFontRef & getBridgeFontRef ()
 
const fontations_ffi::BridgeNormalizedCoords & getBridgeNormalizedCoords ()
 
const fontations_ffi::BridgeOutlineCollection & getOutlines ()
 
SkSpan< const SkColorgetPalette () 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 sk_sp< SkTypefaceMakeFromData (sk_sp< SkData > fontData, const SkFontArguments &)
 
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', 'n', 't', 'a')
 

Protected Member Functions

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

Additional Inherited Members

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

Detailed Description

SkTypeface implementation based on Google Fonts Fontations Rust libraries.

Definition at line 205 of file SkTypeface_fontations_priv.h.

Member Function Documentation

◆ getBridgeFontRef()

const fontations_ffi::BridgeFontRef & SkTypeface_Fontations::getBridgeFontRef ( )
inline

Definition at line 217 of file SkTypeface_fontations_priv.h.

217{ return *fBridgeFontRef; }

◆ getBridgeNormalizedCoords()

const fontations_ffi::BridgeNormalizedCoords & SkTypeface_Fontations::getBridgeNormalizedCoords ( )
inline

Definition at line 218 of file SkTypeface_fontations_priv.h.

218 {
219 return *fBridgeNormalizedCoords;
220 }

◆ getGlyphToUnicodeMap()

void SkTypeface_Fontations::getGlyphToUnicodeMap ( SkUnichar codepointForGlyphMap) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 304 of file SkTypeface_fontations.cpp.

304 {
305 size_t numGlyphs = SkToSizeT(onCountGlyphs());
306 if (!codepointForGlyphMap) {
307 SkASSERT(numGlyphs == 0);
308 }
309 rust::Slice<uint32_t> codepointForGlyphSlice{reinterpret_cast<uint32_t*>(codepointForGlyphMap),
310 numGlyphs};
311 fontations_ffi::fill_glyph_to_unicode_map(*fBridgeFontRef, codepointForGlyphSlice);
312}
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
int onCountGlyphs() const override

◆ getOutlines()

const fontations_ffi::BridgeOutlineCollection & SkTypeface_Fontations::getOutlines ( )
inline

Definition at line 221 of file SkTypeface_fontations_priv.h.

221{ return *fOutlines; }

◆ getPalette()

SkSpan< const SkColor > SkTypeface_Fontations::getPalette ( ) const
inline

Definition at line 222 of file SkTypeface_fontations_priv.h.

222 {
223 return SkSpan(reinterpret_cast<const SkColor*>(fPalette.data()), fPalette.size());
224 }
uint32_t SkColor
Definition: SkColor.h:37
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >

◆ getPostScriptGlyphNames()

void SkTypeface_Fontations::getPostScriptGlyphNames ( SkString ) const
inlineoverrideprotectedvirtual

Implements SkTypeface.

Definition at line 241 of file SkTypeface_fontations_priv.h.

241{}

◆ MakeFromData()

sk_sp< SkTypeface > SkTypeface_Fontations::MakeFromData ( sk_sp< SkData fontData,
const SkFontArguments args 
)
static

Definition at line 118 of file SkTypeface_fontations.cpp.

119 {
120 uint32_t ttcIndex = args.getCollectionIndex();
121 rust::Box<fontations_ffi::BridgeFontRef> bridgeFontRef = make_bridge_font_ref(data, ttcIndex);
122 if (!fontations_ffi::font_ref_is_valid(*bridgeFontRef)) {
123 return nullptr;
124 }
125
126 rust::Box<fontations_ffi::BridgeMappingIndex> mappingIndex =
127 fontations_ffi::make_mapping_index(*bridgeFontRef);
128
129 SkFontArguments::VariationPosition variationPosition = args.getVariationDesignPosition();
130 std::unique_ptr<SkFontArguments::VariationPosition::Coordinate[]> concatenatedCoords = nullptr;
131 // Handle FreeType behaviour of upper 15 bits of collection index
132 // representing a named instance choice. If so, prepopulate the variation
133 // coordinates with the values from the named instance and append the user
134 // coordinates after that so they can override the named instance's
135 // coordinates.
136 if (args.getCollectionIndex() & 0xFFFF0000) {
137 size_t numNamedInstanceCoords =
138 fontations_ffi::coordinates_for_shifted_named_instance_index(
139 *bridgeFontRef,
140 args.getCollectionIndex(),
141 rust::cxxbridge1::Slice<fontations_ffi::SkiaDesignCoordinate>());
142 concatenatedCoords.reset(
144 [numNamedInstanceCoords + variationPosition.coordinateCount]);
145
146 rust::cxxbridge1::Slice<fontations_ffi::SkiaDesignCoordinate> targetSlice(
147 reinterpret_cast<fontations_ffi::SkiaDesignCoordinate*>(concatenatedCoords.get()),
148 numNamedInstanceCoords);
149 size_t retrievedNamedInstanceCoords =
150 fontations_ffi::coordinates_for_shifted_named_instance_index(
151 *bridgeFontRef, args.getCollectionIndex(), targetSlice);
152 if (numNamedInstanceCoords != retrievedNamedInstanceCoords) {
153 return nullptr;
154 }
155 for (int i = 0; i < variationPosition.coordinateCount; ++i) {
156 concatenatedCoords[numNamedInstanceCoords + i] = variationPosition.coordinates[i];
157 }
158 variationPosition.coordinateCount += numNamedInstanceCoords;
159 variationPosition.coordinates = concatenatedCoords.get();
160 }
161
162 rust::Box<fontations_ffi::BridgeNormalizedCoords> normalizedCoords =
163 make_normalized_coords(*bridgeFontRef, variationPosition);
164 SkFontStyle style;
165 fontations_ffi::BridgeFontStyle fontStyle;
166 if (fontations_ffi::get_font_style(*bridgeFontRef, *normalizedCoords, fontStyle)) {
169 static_cast<SkFontStyle::Slant>(fontStyle.slant));
170 }
171 rust::Box<fontations_ffi::BridgeOutlineCollection> outlines =
172 fontations_ffi::get_outline_collection(*bridgeFontRef);
173
174 rust::Slice<const fontations_ffi::PaletteOverride> paletteOverrides(
175 reinterpret_cast<const ::fontations_ffi::PaletteOverride*>(args.getPalette().overrides),
176 args.getPalette().overrideCount);
177 rust::Vec<uint32_t> palette =
178 resolve_palette(*bridgeFontRef, args.getPalette().index, paletteOverrides);
179
181 style,
182 ttcIndex,
183 std::move(bridgeFontRef),
184 std::move(mappingIndex),
185 std::move(normalizedCoords),
186 std::move(outlines),
187 std::move(palette)));
188}
Slant slant() const
Definition: SkFontStyle.h:64
int width() const
Definition: SkFontStyle.h:63
int weight() const
Definition: SkFontStyle.h:62
SkFontStyle fontStyle() const
Definition: SkTypeface.h:55
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ MakeFromStream()

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

Definition at line 113 of file SkTypeface_fontations.cpp.

114 {
115 return MakeFromData(streamToData(stream), args);
116}
static sk_sp< SkTypeface > MakeFromData(sk_sp< SkData > fontData, const SkFontArguments &)

◆ onCharsToGlyphs()

void SkTypeface_Fontations::onCharsToGlyphs ( const SkUnichar chars,
int  count,
SkGlyphID  glyphs[] 
) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 291 of file SkTypeface_fontations.cpp.

293 {
294 sk_bzero(glyphs, count * sizeof(glyphs[0]));
295
296 for (int i = 0; i < count; ++i) {
297 glyphs[i] = fontations_ffi::lookup_glyph_or_zero(*fBridgeFontRef, *fMappingIndex, chars[i]);
298 }
299}
sk_bzero(glyphs, sizeof(glyphs))
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50

◆ onCountGlyphs()

int SkTypeface_Fontations::onCountGlyphs ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 300 of file SkTypeface_fontations.cpp.

300 {
301 return fontations_ffi::num_glyphs(*fBridgeFontRef);
302}

◆ onCreateFamilyNameIterator()

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

Returns an iterator over the family names in the font.

Implements SkTypeface.

Definition at line 350 of file SkTypeface_fontations.cpp.

350 {
351 return new SkrifaLocalizedStrings(fontations_ffi::get_localized_strings(*fBridgeFontRef));
352}

◆ onCreateScalerContext()

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

Implements SkTypeface.

Definition at line 913 of file SkTypeface_fontations.cpp.

914 {
915 return std::make_unique<SkFontationsScalerContext>(
916 sk_ref_sp(const_cast<SkTypeface_Fontations*>(this)), effects, desc);
917}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381

◆ onFilterRec()

void SkTypeface_Fontations::onFilterRec ( SkScalerContextRec rec) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 314 of file SkTypeface_fontations.cpp.

314 {
315 // Opportunistic hinting downgrades copied from SkFontHost_FreeType.cpp
316 SkFontHinting h = rec->getHinting();
317 if (SkFontHinting::kFull == h && !isLCD(*rec)) {
318 // Collapse full->normal hinting if we're not doing LCD.
320 }
321
322 // Rotated text looks bad with hinting, so we disable it as needed.
323 if (!isAxisAligned(*rec)) {
325 }
326 rec->setHinting(h);
327}
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_Fontations::onGetAdvancedMetrics ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 919 of file SkTypeface_fontations.cpp.

919 {
920 std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
921
922 if (!fontations_ffi::is_embeddable(*fBridgeFontRef)) {
924 }
925
926 if (!fontations_ffi::is_subsettable(*fBridgeFontRef)) {
928 }
929
930 if (fontations_ffi::table_data(
931 *fBridgeFontRef, SkSetFourByteTag('f', 'v', 'a', 'r'), 0, rust::Slice<uint8_t>())) {
933 }
934
935 // Metrics information.
936 fontations_ffi::Metrics metrics =
937 fontations_ffi::get_unscaled_metrics(*fBridgeFontRef, *fBridgeNormalizedCoords);
938 info->fAscent = metrics.ascent;
939 info->fDescent = metrics.descent;
940 info->fCapHeight = metrics.cap_height;
941
942 info->fBBox = SkIRect::MakeLTRB((int32_t)metrics.x_min,
943 (int32_t)metrics.top,
944 (int32_t)metrics.x_max,
945 (int32_t)metrics.bottom);
946
947 // Style information.
948 if (fontations_ffi::is_fixed_pitch(*fBridgeFontRef)) {
950 }
951
952 fontations_ffi::BridgeFontStyle fontStyle;
953 if (fontations_ffi::get_font_style(*fBridgeFontRef, *fBridgeNormalizedCoords, fontStyle)) {
954 if (fontStyle.slant == SkFontStyle::Slant::kItalic_Slant) {
956 }
957 }
958
959 if (fontations_ffi::is_serif_style(*fBridgeFontRef)) {
961 } else if (fontations_ffi::is_script_style(*fBridgeFontRef)) {
963 }
964
965 info->fItalicAngle = fontations_ffi::italic_angle(*fBridgeFontRef);
966
967 return info;
968}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
@ kNotEmbeddable_FontFlag
May not be embedded.
@ 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

◆ onGetFamilyName()

void SkTypeface_Fontations::onGetFamilyName ( SkString familyName) const
overrideprotectedvirtual

Returns the family name of the typeface as known by its font manager. This name may or may not be produced by the family name iterator.

Implements SkTypeface.

Definition at line 266 of file SkTypeface_fontations.cpp.

266 {
267 rust::String readFamilyName = fontations_ffi::family_name(*fBridgeFontRef);
268 *familyName = SkString(readFamilyName.data(), readFamilyName.size());
269}

◆ onGetFontDescriptor()

void SkTypeface_Fontations::onGetFontDescriptor ( SkFontDescriptor desc,
bool *  serialize 
) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 970 of file SkTypeface_fontations.cpp.

970 {
971 SkString familyName;
972 onGetFamilyName(&familyName);
973 desc->setFamilyName(familyName.c_str());
974 desc->setStyle(this->fontStyle());
975 desc->setFactoryId(FactoryId);
976
977 // TODO: keep the index to emit here
978 desc->setPaletteIndex(0);
980 // TODO: omit override when palette[n] == CPAL[paletteIndex][n]
981 size_t paletteOverrideCount = palette.size();
982 auto overrides = desc->setPaletteEntryOverrides(paletteOverrideCount);
983 for (size_t i = 0; i < paletteOverrideCount; ++i) {
984 overrides[i] = {(uint16_t)i, palette[i]};
985 }
986
987 *serialize = true;
988}
void setFactoryId(SkTypeface::FactoryId factoryId)
constexpr size_t size() const
Definition: SkSpan_impl.h:95
const char * c_str() const
Definition: SkString.h:133
SkSpan< const SkColor > getPalette() const
static constexpr SkTypeface::FactoryId FactoryId
void onGetFamilyName(SkString *familyName) const override
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
Definition: SkTypeface.cpp:202

◆ onGetPostScriptName()

bool SkTypeface_Fontations::onGetPostScriptName ( SkString postscriptName) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 271 of file SkTypeface_fontations.cpp.

271 {
272 rust::String readPsName;
273 if (fontations_ffi::postscript_name(*fBridgeFontRef, readPsName)) {
274 if (postscriptName) {
275 *postscriptName = SkString(readPsName.data(), readPsName.size());
276 }
277 return true;
278 }
279
280 return false;
281}

◆ onGetTableData()

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

Implements SkTypeface.

Definition at line 990 of file SkTypeface_fontations.cpp.

993 {
994 rust::Slice<uint8_t> dataSlice;
995 if (data) {
996 dataSlice = rust::Slice<uint8_t>(reinterpret_cast<uint8_t*>(data), length);
997 }
998 size_t copied = fontations_ffi::table_data(*fBridgeFontRef, tag, offset, dataSlice);
999 // If data is nullptr, the Rust side doesn't see a length limit.
1000 return std::min(copied, length);
1001}
static float min(float r, float g, float b)
Definition: hsl.cpp:48
size_t length
SeparatedVector2 offset

◆ onGetTableTags()

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

Implements SkTypeface.

Definition at line 1003 of file SkTypeface_fontations.cpp.

1003 {
1004 uint16_t numTables = fontations_ffi::table_tags(*fBridgeFontRef, rust::Slice<uint32_t>());
1005 if (!tags) {
1006 return numTables;
1007 }
1008 rust::Slice<uint32_t> copyToTags(tags, numTables);
1009 return fontations_ffi::table_tags(*fBridgeFontRef, copyToTags);
1010}

◆ onGetUPEM()

int SkTypeface_Fontations::onGetUPEM ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 262 of file SkTypeface_fontations.cpp.

262 {
263 return fontations_ffi::units_per_em_or_zero(*fBridgeFontRef);
264}

◆ onGetVariationDesignParameters()

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

Implements SkTypeface.

Definition at line 1023 of file SkTypeface_fontations.cpp.

1024 {
1025 sk_fontations::AxisWrapper axisWrapper(parameters, parameterCount);
1026 return fontations_ffi::populate_axes(*fBridgeFontRef, axisWrapper);
1027}

◆ onGetVariationDesignPosition()

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

Implements SkTypeface.

Definition at line 1012 of file SkTypeface_fontations.cpp.

1013 {
1014 rust::Slice<fontations_ffi::SkiaDesignCoordinate> copyToCoordinates;
1015 if (coordinates) {
1016 copyToCoordinates = rust::Slice<fontations_ffi::SkiaDesignCoordinate>(
1017 reinterpret_cast<fontations_ffi::SkiaDesignCoordinate*>(coordinates),
1018 coordinateCount);
1019 }
1020 return fontations_ffi::variation_position(*fBridgeNormalizedCoords, copyToCoordinates);
1021}

◆ onGlyphMaskNeedsCurrentColor()

bool SkTypeface_Fontations::onGlyphMaskNeedsCurrentColor ( ) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 283 of file SkTypeface_fontations.cpp.

283 {
284 fGlyphMasksMayNeedCurrentColorOnce([this] {
285 static constexpr SkFourByteTag COLRTag = SkSetFourByteTag('C', 'O', 'L', 'R');
286 fGlyphMasksMayNeedCurrentColor = this->getTableSize(COLRTag) > 0;
287 });
288 return fGlyphMasksMayNeedCurrentColor;
289}
uint32_t SkFourByteTag
Definition: SkTypes.h:166
size_t getTableSize(SkFontTableTag) const
Definition: SkTypeface.cpp:309

◆ onMakeClone()

sk_sp< SkTypeface > SkTypeface_Fontations::onMakeClone ( const SkFontArguments args) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 862 of file SkTypeface_fontations.cpp.

862 {
863 // Matching DWrite implementation, return self if ttc index mismatches.
864 if (fTtcIndex != SkTo<uint32_t>(args.getCollectionIndex())) {
865 return sk_ref_sp(this);
866 }
867
868 int numAxes = onGetVariationDesignPosition(nullptr, 0);
869 auto fusedDesignPosition =
870 std::make_unique<SkFontArguments::VariationPosition::Coordinate[]>(numAxes);
871 int retrievedAxes = onGetVariationDesignPosition(fusedDesignPosition.get(), numAxes);
872 if (numAxes != retrievedAxes) {
873 return nullptr;
874 }
875
876 // We know the internally retrieved axes are normalized, contain a value for every possible
877 // axis, other axes do not exist, so we only need to override any of those.
878 for (int i = 0; i < numAxes; ++i) {
879 const SkFontArguments::VariationPosition& argPosition = args.getVariationDesignPosition();
880 for (int j = 0; j < argPosition.coordinateCount; ++j) {
881 if (fusedDesignPosition[i].axis == argPosition.coordinates[j].axis) {
882 fusedDesignPosition[i].value = argPosition.coordinates[j].value;
883 }
884 }
885 }
886
887 SkFontArguments fusedArgs;
888 fusedArgs.setVariationDesignPosition({fusedDesignPosition.get(), SkToInt(numAxes)});
889 fusedArgs.setPalette(args.getPalette());
890
891 rust::cxxbridge1::Box<fontations_ffi::BridgeNormalizedCoords> normalized_args =
892 make_normalized_coords(*fBridgeFontRef, fusedArgs.getVariationDesignPosition());
893
894 if (!fontations_ffi::normalized_coords_equal(*normalized_args, *fBridgeNormalizedCoords)) {
895 return MakeFromData(fFontData, fusedArgs);
896 }
897
898 // TODO(crbug.com/skia/330149870): Palette differences are not fused, see DWrite backend impl.
899 rust::Slice<const fontations_ffi::PaletteOverride> argPaletteOverrides(
900 reinterpret_cast<const fontations_ffi::PaletteOverride*>(args.getPalette().overrides),
901 args.getPalette().overrideCount);
902 rust::Vec<uint32_t> newPalette =
903 resolve_palette(*fBridgeFontRef, args.getPalette().index, argPaletteOverrides);
904
905 if (fPalette.size() != newPalette.size() ||
906 memcmp(fPalette.data(), newPalette.data(), fPalette.size() * sizeof(fPalette[0]))) {
907 return MakeFromData(fFontData, fusedArgs);
908 }
909
910 return sk_ref_sp(this);
911}
constexpr int SkToInt(S x)
Definition: SkTo.h:29
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const override
SkFontArguments & setVariationDesignPosition(VariationPosition position)
SkFontArguments & setPalette(Palette palette)
VariationPosition getVariationDesignPosition() const

◆ onOpenStream()

std::unique_ptr< SkStreamAsset > SkTypeface_Fontations::onOpenStream ( int ttcIndex) const
overrideprotectedvirtual

Implements SkTypeface.

Definition at line 857 of file SkTypeface_fontations.cpp.

857 {
858 *ttcIndex = fTtcIndex;
859 return std::make_unique<SkMemoryStream>(fFontData);
860}

Member Data Documentation

◆ FactoryId

constexpr SkTypeface::FactoryId SkTypeface_Fontations::FactoryId = SkSetFourByteTag('f', 'n', 't', 'a')
staticconstexpr

Definition at line 226 of file SkTypeface_fontations_priv.h.


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