Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
SkTypeface Class Referenceabstract

#include <SkTypeface.h>

Inheritance diagram for SkTypeface:
SkWeakRefCnt SkRefCnt SkRefCntBase DWriteFontTypeface SkRandomTypeface SkTypefaceProxy SkTypeface_Fontations SkTypeface_FreeType SkUserTypeface TestEmptyTypeface TestTypeface

Classes

struct  LocalizedString
 
class  LocalizedStrings
 

Public Types

enum class  SerializeBehavior { kDoIncludeData , kDontIncludeData , kIncludeDataIfLocal }
 
using FactoryId = SkFourByteTag
 

Public Member Functions

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 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 &))
 

Protected Member Functions

 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
 

Friends

class SkScalerContext
 
class SkStrikeServerImpl
 
class SkTypefaceProxyPrototype
 
class SkRandomTypeface
 
class SkPDFFont
 
class SkFontPriv
 

Detailed Description

The SkTypeface class specifies the typeface and intrinsic style of a font. This is used in the paint, along with optionally algorithmic settings like textSize, textSkewX, textScaleX, kFakeBoldText_Mask, to specify how text appears when drawn (and measured).

Typeface objects are immutable, and so they can be shared between threads.

Definition at line 52 of file SkTypeface.h.

Member Typedef Documentation

◆ FactoryId

Definition at line 335 of file SkTypeface.h.

Member Enumeration Documentation

◆ SerializeBehavior

enum class SkTypeface::SerializeBehavior
strong

A typeface can serialize just a descriptor (names, etc.), or it can also include the actual font data (which can be large). This enum controls how serialize() decides what to serialize.

Enumerator
kDoIncludeData 
kDontIncludeData 
kIncludeDataIfLocal 

Definition at line 124 of file SkTypeface.h.

124 {
125 kDoIncludeData,
126 kDontIncludeData,
127 kIncludeDataIfLocal,
128 };

Constructor & Destructor Documentation

◆ SkTypeface()

SkTypeface::SkTypeface ( const SkFontStyle style,
bool  isFixedPitch = false 
)
explicitprotected

Definition at line 56 of file SkTypeface.cpp.

57 : fUniqueID(SkTypefaceCache::NewTypefaceID()), fStyle(style), fIsFixedPitch(isFixedPitch) { }
static SkTypefaceID NewTypefaceID()
bool isFixedPitch() const
Definition: SkTypeface.h:68

◆ ~SkTypeface()

SkTypeface::~SkTypeface ( )
overrideprotected

Definition at line 59 of file SkTypeface.cpp.

59{ }

Member Function Documentation

◆ copyTableData()

sk_sp< SkData > SkTypeface::copyTableData ( SkFontTableTag  tag) const

Return an immutable copy of the requested font table, or nullptr if that table was not found. This can sometimes be faster than calling getTableData() twice: once to find the length, and then again to copy the data.

Parameters
tagThe table tag whose contents are to be copied
Returns
an immutable copy of the table's data, or nullptr.

Definition at line 318 of file SkTypeface.cpp.

318 {
319 return this->onCopyTableData(tag);
320}
virtual sk_sp< SkData > onCopyTableData(SkFontTableTag) const
Definition: SkTypeface.cpp:322

◆ countGlyphs()

int SkTypeface::countGlyphs ( ) const

Return the number of glyphs in the typeface.

Definition at line 432 of file SkTypeface.cpp.

432 {
433 return this->onCountGlyphs();
434}
virtual int onCountGlyphs() const =0

◆ countTables()

int SkTypeface::countTables ( ) const

Return the number of tables in the font.

Definition at line 301 of file SkTypeface.cpp.

301 {
302 return this->onGetTableTags(nullptr);
303}
virtual int onGetTableTags(SkFontTableTag tags[]) const =0

◆ createFamilyNameIterator()

SkTypeface::LocalizedStrings * SkTypeface::createFamilyNameIterator ( ) const

Returns an iterator which will attempt to enumerate all of the family names specified by the font. It is the caller's responsibility to unref() the returned pointer.

Definition at line 455 of file SkTypeface.cpp.

455 {
456 return this->onCreateFamilyNameIterator();
457}
virtual LocalizedStrings * onCreateFamilyNameIterator() const =0

◆ createScalerContext()

std::unique_ptr< SkScalerContext > SkTypeface::createScalerContext ( const SkScalerContextEffects effects,
const SkDescriptor desc 
) const

Return a scalercontext for the given descriptor. It may return a stub scalercontext that will not crash, but will draw nothing.

Definition at line 350 of file SkTypeface.cpp.

351 {
352 std::unique_ptr<SkScalerContext> scalerContext = this->onCreateScalerContext(effects, desc);
353 SkASSERT(scalerContext);
354 return scalerContext;
355}
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *) const =0

◆ Equal()

bool SkTypeface::Equal ( const SkTypeface facea,
const SkTypeface faceb 
)
static

Returns true if the two typefaces reference the same underlying font, handling either being null (treating null as not equal to any font).

Definition at line 149 of file SkTypeface.cpp.

149 {
150 if (facea == faceb) {
151 return true;
152 }
153 if (!facea || !faceb) {
154 return false;
155 }
156 return facea->uniqueID() == faceb->uniqueID();
157}
SkTypefaceID uniqueID() const
Definition: SkTypeface.h:101

◆ filterRec()

void SkTypeface::filterRec ( SkScalerContextRec rec) const
inline

Definition at line 322 of file SkTypeface.h.

322 {
323 this->onFilterRec(rec);
324 }
virtual void onFilterRec(SkScalerContextRec *) const =0

◆ fontStyle()

SkFontStyle SkTypeface::fontStyle ( ) const
inline

Returns the typeface's intrinsic style attributes.

Definition at line 55 of file SkTypeface.h.

55 {
56 return fStyle;
57 }

◆ getBounds()

SkRect SkTypeface::getBounds ( ) const

Return a rectangle (scaled to 1-pt) that represents the union of the bounds of all of the glyphs, but each one positioned at (0,). This may be conservatively large, and will not take into account any hinting or other size-specific adjustments.

Definition at line 507 of file SkTypeface.cpp.

507 {
508 fBoundsOnce([this] {
509 if (!this->onComputeBounds(&fBounds)) {
510 fBounds.setEmpty();
511 }
512 });
513 return fBounds;
514}
virtual bool onComputeBounds(SkRect *) const
Definition: SkTypeface.cpp:516
void setEmpty()
Definition: SkRect.h:842

◆ getFamilyName()

void SkTypeface::getFamilyName ( SkString name) const

Return the family name for this typeface. It will always be returned encoded as UTF8, but the language of the name is whatever the host platform chooses.

Definition at line 459 of file SkTypeface.cpp.

459 {
460 SkASSERT(name);
461 this->onGetFamilyName(name);
462}
virtual void onGetFamilyName(SkString *familyName) const =0
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ getFontDescriptor()

void SkTypeface::getFontDescriptor ( SkFontDescriptor desc,
bool *  isLocal 
) const
inline

Definition at line 326 of file SkTypeface.h.

326 {
327 this->onGetFontDescriptor(desc, isLocal);
328 }
virtual void onGetFontDescriptor(SkFontDescriptor *, bool *isLocal) const =0

◆ getGlyphToUnicodeMap()

void SkTypeface::getGlyphToUnicodeMap ( SkUnichar dstArray) const
protectedpure virtual

Implemented in SkTypefaceProxy, SkTypeface_Fontations, SkTypeface_FreeType, SkRandomTypeface, TestEmptyTypeface, DWriteFontTypeface, and TestTypeface.

Definition at line 468 of file SkTypeface.cpp.

468 {
469 sk_bzero(dst, sizeof(SkUnichar) * this->countGlyphs());
470}
sk_bzero(glyphs, sizeof(glyphs))
int32_t SkUnichar
Definition: SkTypes.h:175
int countGlyphs() const
Definition: SkTypeface.cpp:432
dst
Definition: cp.py:12

◆ getKerningPairAdjustments()

bool SkTypeface::getKerningPairAdjustments ( const SkGlyphID  glyphs[],
int  count,
int32_t  adjustments[] 
) const

Given a run of glyphs, return the associated horizontal adjustments. Adjustments are in "design units", which are integers relative to the typeface's units per em (see getUnitsPerEm).

Some typefaces are known to never support kerning. Calling this method with all zeros (e.g. getKerningPairAdustments(NULL, 0, NULL)) returns a boolean indicating if the typeface might support kerning. If it returns false, then it will always return false (no kerning) for all possible glyph runs. If it returns true, then it may return true for somne glyph runs.

If count is non-zero, then the glyphs parameter must point to at least [count] valid glyph IDs, and the adjustments parameter must be sized to at least [count - 1] entries. If the method returns true, then [count-1] entries in the adjustments array will be set. If the method returns false, then no kerning should be applied, and the adjustments array will be in an undefined state (possibly some values may have been written, but none of them should be interpreted as valid values).

Definition at line 441 of file SkTypeface.cpp.

442 {
443 SkASSERT(count >= 0);
444 // check for the only legal way to pass a nullptr.. everything is 0
445 // in which case they just want to know if this face can possibly support
446 // kerning (true) or never (false).
447 if (nullptr == glyphs || nullptr == adjustments) {
448 SkASSERT(nullptr == glyphs);
449 SkASSERT(0 == count);
450 SkASSERT(nullptr == adjustments);
451 }
452 return this->onGetKerningPairAdjustments(glyphs, count, adjustments);
453}
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
int count
Definition: FontMgrTest.cpp:50
virtual bool onGetKerningPairAdjustments(const SkGlyphID glyphs[], int count, int32_t adjustments[]) const
Definition: SkTypeface.cpp:496

◆ getPostScriptGlyphNames()

virtual void SkTypeface::getPostScriptGlyphNames ( SkString ) const
protectedpure virtual

◆ getPostScriptName()

bool SkTypeface::getPostScriptName ( SkString name) const

Return the PostScript name for this typeface. Value may change based on variation parameters. Returns false if no PostScript name is available.

Definition at line 464 of file SkTypeface.cpp.

464 {
465 return this->onGetPostScriptName(name);
466}
virtual bool onGetPostScriptName(SkString *) const =0

◆ getTableData()

size_t SkTypeface::getTableData ( SkFontTableTag  tag,
size_t  offset,
size_t  length,
void *  data 
) const

Copy the contents of a table into data (allocated by the caller). Note that the contents of the table will be in their native endian order (which for most truetype tables is big endian). If the table tag is not found, or there is an error copying the data, then 0 is returned. If this happens, it is possible that some or all of the memory pointed to by data may have been written to, even though an error has occured.

Parameters
tagThe table tag whose contents are to be copied
offsetThe offset in bytes into the table's contents where the copy should start from.
lengthThe number of bytes, starting at offset, of table data to copy.
datastorage address where the table contents are copied to
Returns
the number of bytes actually copied into data. If offset+length exceeds the table's size, then only the bytes up to the table's size are actually copied, and this is the value returned. If offset > the table's size, or tag is not a valid table, then 0 is returned.

Definition at line 313 of file SkTypeface.cpp.

314 {
315 return this->onGetTableData(tag, offset, length, data);
316}
virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void *data) const =0
size_t length
SeparatedVector2 offset
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ getTableSize()

size_t SkTypeface::getTableSize ( SkFontTableTag  tag) const

Given a table tag, return the size of its contents, or 0 if not present

Definition at line 309 of file SkTypeface.cpp.

309 {
310 return this->onGetTableData(tag, 0, ~0U, nullptr);
311}

◆ getTableTags()

int SkTypeface::getTableTags ( SkFontTableTag  tags[]) const

Copy into tags[] (allocated by the caller) the list of table tags in the font, and return the number. This will be the same as CountTables() or 0 if an error occured. If tags == NULL, this only returns the count (the same as calling countTables()).

Definition at line 305 of file SkTypeface.cpp.

305 {
306 return this->onGetTableTags(tags);
307}

◆ getUnitsPerEm()

int SkTypeface::getUnitsPerEm ( ) const

Return the units-per-em value for this typeface, or zero if there is an error.

Definition at line 436 of file SkTypeface.cpp.

436 {
437 // should we try to cache this in the base-class?
438 return this->onGetUPEM();
439}
virtual int onGetUPEM() const =0

◆ getVariationDesignParameters()

int SkTypeface::getVariationDesignParameters ( SkFontParameters::Variation::Axis  parameters[],
int  parameterCount 
) const

Copy into 'parameters' (allocated by the caller) the design variation parameters.

Parameters
parametersthe buffer into which to write the design variation parameters.
coordinateCountthe number of entries available through 'parameters'.
Returns
The number of axes, or -1 if there is an error. If 'parameters != nullptr' and 'parameterCount >= numAxes' then 'parameters' will be filled with the variation parameters describing the position of this typeface in design variation space. It is possible the number of axes can be retrieved but actual parameters cannot.

Definition at line 295 of file SkTypeface.cpp.

297{
298 return this->onGetVariationDesignParameters(parameters, parameterCount);
299}
virtual int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], int parameterCount) const =0

◆ getVariationDesignPosition()

int SkTypeface::getVariationDesignPosition ( SkFontArguments::VariationPosition::Coordinate  coordinates[],
int  coordinateCount 
) const

Copy into 'coordinates' (allocated by the caller) the design variation coordinates.

Parameters
coordinatesthe buffer into which to write the design variation coordinates.
coordinateCountthe number of entries available through 'coordinates'.
Returns
The number of axes, or -1 if there is an error. If 'coordinates != nullptr' and 'coordinateCount >= numAxes' then 'coordinates' will be filled with the variation coordinates describing the position of this typeface in design variation space. It is possible the number of axes can be retrieved but actual position cannot.

Definition at line 289 of file SkTypeface.cpp.

291{
292 return this->onGetVariationDesignPosition(coordinates, coordinateCount);
293}
virtual int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const =0

◆ internal_private_getCTFontRef()

void * SkTypeface::internal_private_getCTFontRef ( ) const
inline

Definition at line 330 of file SkTypeface.h.

330 {
331 return this->onGetCTFontRef();
332 }
virtual void * onGetCTFontRef() const
Definition: SkTypeface.h:407

◆ isBold()

bool SkTypeface::isBold ( ) const
inline

Returns true if style() has the kBold bit set.

Definition at line 60 of file SkTypeface.h.

60{ return fStyle.weight() >= SkFontStyle::kSemiBold_Weight; }
@ kSemiBold_Weight
Definition: SkFontStyle.h:25
int weight() const
Definition: SkFontStyle.h:62

◆ isFixedPitch()

bool SkTypeface::isFixedPitch ( ) const
inline

Returns true if the typeface claims to be fixed-pitch. This is a style bit, advance widths may vary even if this returns true.

Definition at line 68 of file SkTypeface.h.

68{ return fIsFixedPitch; }

◆ isItalic()

bool SkTypeface::isItalic ( ) const
inline

Returns true if style() has the kItalic bit set.

Definition at line 63 of file SkTypeface.h.

63{ return fStyle.slant() != SkFontStyle::kUpright_Slant; }
Slant slant() const
Definition: SkFontStyle.h:64

◆ makeClone()

sk_sp< SkTypeface > SkTypeface::makeClone ( const SkFontArguments args) const

Return a new typeface based on this typeface but parameterized as specified in the SkFontArguments. If the SkFontArguments does not supply an argument for a parameter in the font then the value from this typeface will be used as the value for that argument. If the cloned typeface would be exaclty the same as this typeface then this typeface may be ref'ed and returned. May return nullptr on failure.

Definition at line 190 of file SkTypeface.cpp.

190 {
191 return this->onMakeClone(args);
192}
virtual sk_sp< SkTypeface > onMakeClone(const SkFontArguments &) const =0

◆ MakeDeserialize()

sk_sp< SkTypeface > SkTypeface::MakeDeserialize ( SkStream stream,
sk_sp< SkFontMgr lastResortMgr 
)
static

Given the data previously written by serialize(), return a new instance of a typeface referring to the same font. If that font is not available, return nullptr. Goes through all registered typeface factories and lastResortMgr (if non-null). Does not affect ownership of SkStream.

Definition at line 241 of file SkTypeface.cpp.

241 {
244 return nullptr;
245 }
246
247 if (desc.hasStream()) {
248 for (const DecoderProc& proc : *decoders()) {
249 if (proc.id == desc.getFactoryId()) {
250 return proc.makeFromStream(desc.detachStream(), desc.getFontArguments());
251 }
252 }
253
254 [[maybe_unused]] FactoryId id = desc.getFactoryId();
255 SkDEBUGF("Could not find factory %c%c%c%c for %s.\n",
256 (char)((id >> 24) & 0xFF),
257 (char)((id >> 16) & 0xFF),
258 (char)((id >> 8) & 0xFF),
259 (char)((id >> 0) & 0xFF),
260 desc.getFamilyName());
261
262 if (lastResortMgr) {
263 // If we've gotten to here, we will try desperately to find something that might match
264 // as a kind of last ditch effort to make something work (and maybe this SkFontMgr knows
265 // something about the serialization and can look up the right thing by name anyway if
266 // the user provides it).
267 // Any time it is used the user will probably get the wrong glyphs drawn (and if they're
268 // right it is totally by accident). But sometimes drawing something or getting lucky
269 // while debugging is better than drawing nothing at all.
270 sk_sp<SkTypeface> typeface = lastResortMgr->makeFromStream(desc.detachStream(),
271 desc.getFontArguments());
272 if (typeface) {
273 return typeface;
274 }
275 }
276 }
277 if (lastResortMgr) {
278 return lastResortMgr->legacyMakeTypeface(desc.getFamilyName(), desc.getStyle());
279 }
280 return SkEmptyTypeface::Make();
281}
#define SkDEBUGF(...)
Definition: SkDebug.h:24
static bool Deserialize(SkStream *, SkFontDescriptor *result)
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
Definition: SkFontMgr.cpp:127
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
Definition: SkFontMgr.cpp:150
SkFourByteTag FactoryId
Definition: SkTypeface.h:335
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)

◆ MakeEmpty()

sk_sp< SkTypeface > SkTypeface::MakeEmpty ( )
static

Returns a non-null typeface which contains no glyphs.

Definition at line 145 of file SkTypeface.cpp.

145 {
146 return SkEmptyTypeface::Make();
147}

◆ onCharsToGlyphs()

virtual void SkTypeface::onCharsToGlyphs ( const SkUnichar chars,
int  count,
SkGlyphID  glyphs[] 
) const
protectedpure virtual

◆ onComputeBounds()

bool SkTypeface::onComputeBounds ( SkRect bounds) const
protectedvirtual

Definition at line 516 of file SkTypeface.cpp.

516 {
517 // we use a big size to ensure lots of significant bits from the scalercontext.
518 // then we scale back down to return our final answer (at 1-pt)
519 const SkScalar textSize = 2048;
520 const SkScalar invTextSize = 1 / textSize;
521
522 SkFont font;
523 font.setTypeface(sk_ref_sp(const_cast<SkTypeface*>(this)));
524 font.setSize(textSize);
525 font.setLinearMetrics(true);
526
529
531
533 SkScalerContextEffects noeffects;
535
536 std::unique_ptr<SkScalerContext> ctx = this->createScalerContext(noeffects, ad.getDesc());
537
538 SkFontMetrics fm;
539 ctx->getFontMetrics(&fm);
540 if (!fm.hasBounds()) {
541 return false;
542 }
543 bounds->setLTRB(fm.fXMin * invTextSize, fm.fTop * invTextSize,
544 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
545 return true;
546}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
SkDescriptor * getDesc() const
Definition: SkDescriptor.h:103
Definition: SkFont.h:35
static SkDescriptor * AutoDescriptorGivenRecAndEffects(const SkScalerContextRec &rec, const SkScalerContextEffects &effects, SkAutoDescriptor *ad)
static void MakeRecAndEffectsFromFont(const SkFont &font, SkScalerContextRec *rec, SkScalerContextEffects *effects)
std::unique_ptr< SkScalerContext > createScalerContext(const SkScalerContextEffects &, const SkDescriptor *) const
Definition: SkTypeface.cpp:350
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189
font
Font Metadata and Metrics.
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
Definition: SkFontMetrics.h:53
bool hasBounds() const
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
Definition: SkFontMetrics.h:56
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
Definition: SkFontMetrics.h:60
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...
Definition: SkFontMetrics.h:61

◆ onCopyTableData()

sk_sp< SkData > SkTypeface::onCopyTableData ( SkFontTableTag  tag) const
protectedvirtual

Reimplemented in SkTypeface_FreeType, and DWriteFontTypeface.

Definition at line 322 of file SkTypeface.cpp.

322 {
323 size_t size = this->getTableSize(tag);
324 if (size) {
326 (void)this->getTableData(tag, 0, size, data->writable_data());
327 return data;
328 }
329 return nullptr;
330}
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
size_t getTableSize(SkFontTableTag) const
Definition: SkTypeface.cpp:309
size_t getTableData(SkFontTableTag tag, size_t offset, size_t length, void *data) const
Definition: SkTypeface.cpp:313
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

◆ onCountGlyphs()

virtual int SkTypeface::onCountGlyphs ( ) const
protectedpure virtual

◆ onCreateFamilyNameIterator()

virtual LocalizedStrings * SkTypeface::onCreateFamilyNameIterator ( ) const
protectedpure virtual

Returns an iterator over the family names in the font.

Implemented in SkTypefaceProxy, SkTypeface_Fontations, SkTypeface_FreeType, DWriteFontTypeface, SkRandomTypeface, TestEmptyTypeface, and TestTypeface.

◆ onCreateScalerContext()

virtual std::unique_ptr< SkScalerContext > SkTypeface::onCreateScalerContext ( const SkScalerContextEffects ,
const SkDescriptor  
) const
protectedpure virtual

◆ onFilterRec()

virtual void SkTypeface::onFilterRec ( SkScalerContextRec ) const
protectedpure virtual

◆ onGetAdvancedMetrics()

virtual std::unique_ptr< SkAdvancedTypefaceMetrics > SkTypeface::onGetAdvancedMetrics ( ) const
protectedpure virtual

◆ onGetCTFontRef()

virtual void * SkTypeface::onGetCTFontRef ( ) const
inlineprotectedvirtual

Reimplemented in SkTypefaceProxy.

Definition at line 407 of file SkTypeface.h.

407{ return nullptr; }

◆ onGetFamilyName()

virtual void SkTypeface::onGetFamilyName ( SkString familyName) const
protectedpure virtual

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.

Implemented in SkTypefaceProxy, SkTypeface_FCI, SkTypeface_Custom, SkTypeface_fontconfig, SkTypeface_Fontations, SkTypeface_FreeTypeStream, DWriteFontTypeface, SkRandomTypeface, TestEmptyTypeface, and TestTypeface.

◆ onGetFontDescriptor()

virtual void SkTypeface::onGetFontDescriptor ( SkFontDescriptor ,
bool *  isLocal 
) const
protectedpure virtual

◆ onGetKerningPairAdjustments()

bool SkTypeface::onGetKerningPairAdjustments ( const SkGlyphID  glyphs[],
int  count,
int32_t  adjustments[] 
) const
protectedvirtual

Reimplemented in SkTypeface_FreeType.

Definition at line 496 of file SkTypeface.cpp.

497 {
498 return false;
499}

◆ onGetPostScriptName()

virtual bool SkTypeface::onGetPostScriptName ( SkString ) const
protectedpure virtual

◆ onGetTableData()

virtual size_t SkTypeface::onGetTableData ( SkFontTableTag  ,
size_t  offset,
size_t  length,
void *  data 
) const
protectedpure virtual

◆ onGetTableTags()

virtual int SkTypeface::onGetTableTags ( SkFontTableTag  tags[]) const
protectedpure virtual

◆ onGetUPEM()

virtual int SkTypeface::onGetUPEM ( ) const
protectedpure virtual

◆ onGetVariationDesignParameters()

virtual int SkTypeface::onGetVariationDesignParameters ( SkFontParameters::Variation::Axis  parameters[],
int  parameterCount 
) const
protectedpure virtual

◆ onGetVariationDesignPosition()

virtual int SkTypeface::onGetVariationDesignPosition ( SkFontArguments::VariationPosition::Coordinate  coordinates[],
int  coordinateCount 
) const
protectedpure virtual

◆ onGlyphMaskNeedsCurrentColor()

virtual bool SkTypeface::onGlyphMaskNeedsCurrentColor ( ) const
protectedpure virtual

◆ onMakeClone()

virtual sk_sp< SkTypeface > SkTypeface::onMakeClone ( const SkFontArguments ) const
protectedpure virtual

◆ onOpenExistingStream()

std::unique_ptr< SkStreamAsset > SkTypeface::onOpenExistingStream ( int ttcIndex) const
protectedvirtual

Definition at line 501 of file SkTypeface.cpp.

501 {
502 return this->onOpenStream(ttcIndex);
503}
virtual std::unique_ptr< SkStreamAsset > onOpenStream(int *ttcIndex) const =0

◆ onOpenStream()

virtual std::unique_ptr< SkStreamAsset > SkTypeface::onOpenStream ( int ttcIndex) const
protectedpure virtual

◆ openExistingStream()

std::unique_ptr< SkStreamAsset > SkTypeface::openExistingStream ( int ttcIndex) const

Return a stream for the contents of the font data. Returns nullptr on failure or if the font data isn't already available in stream form. Use when the stream can be used opportunistically but the calling code would prefer to fall back to table access if creating the stream would be expensive. Otherwise acts the same as openStream.

Definition at line 341 of file SkTypeface.cpp.

341 {
342 int ttcIndexStorage;
343 if (nullptr == ttcIndex) {
344 // So our subclasses don't need to check for null param
345 ttcIndex = &ttcIndexStorage;
346 }
347 return this->onOpenExistingStream(ttcIndex);
348}
virtual std::unique_ptr< SkStreamAsset > onOpenExistingStream(int *ttcIndex) const
Definition: SkTypeface.cpp:501

◆ openStream()

std::unique_ptr< SkStreamAsset > SkTypeface::openStream ( int ttcIndex) const

Return a stream for the contents of the font data, or NULL on failure. If ttcIndex is not null, it is set to the TrueTypeCollection index of this typeface within the stream, or 0 if the stream is not a collection. The caller is responsible for deleting the stream.

Definition at line 332 of file SkTypeface.cpp.

332 {
333 int ttcIndexStorage;
334 if (nullptr == ttcIndex) {
335 // So our subclasses don't need to check for null param
336 ttcIndex = &ttcIndexStorage;
337 }
338 return this->onOpenStream(ttcIndex);
339}

◆ Register()

void SkTypeface::Register ( FactoryId  id,
sk_sp< SkTypeface >(*)(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)  make 
)
static

Definition at line 196 of file SkTypeface.cpp.

198 {
199 decoders()->push_back(DecoderProc{id, make});
200}
static void make(SkBitmap *bitmap, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
Definition: encode_srgb.cpp:35
const uintptr_t id

◆ serialize() [1/2]

sk_sp< SkData > SkTypeface::serialize ( SerializeBehavior  behavior = SerializeBehavior::kIncludeDataIfLocal) const

Same as serialize(SkWStream*, ...) but returns the serialized data in SkData, instead of writing it to a stream.

Definition at line 235 of file SkTypeface.cpp.

235 {
237 this->serialize(&stream, behavior);
238 return stream.detachAsData();
239}
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
Definition: SkTypeface.cpp:202

◆ serialize() [2/2]

void SkTypeface::serialize ( SkWStream wstream,
SerializeBehavior  behavior = SerializeBehavior::kIncludeDataIfLocal 
) const

Write a unique signature to a stream, sufficient to reconstruct a typeface referencing the same font when Deserialize is called.

Definition at line 202 of file SkTypeface.cpp.

202 {
203 bool isLocalData = false;
205 this->onGetFontDescriptor(&desc, &isLocalData);
206 if (desc.getFactoryId() == 0) {
207 SkDEBUGF("Factory was not set for %s.\n", desc.getFamilyName());
208 }
209
210 bool shouldSerializeData = false;
211 switch (behavior) {
212 case SerializeBehavior::kDoIncludeData: shouldSerializeData = true; break;
213 case SerializeBehavior::kDontIncludeData: shouldSerializeData = false; break;
214 case SerializeBehavior::kIncludeDataIfLocal: shouldSerializeData = isLocalData; break;
215 }
216
217 if (shouldSerializeData) {
218 int index;
219 desc.setStream(this->openStream(&index));
220 if (desc.hasStream()) {
221 desc.setCollectionIndex(index);
222 }
223
224 int numAxes = this->getVariationDesignPosition(nullptr, 0);
225 if (0 < numAxes) {
226 numAxes = this->getVariationDesignPosition(desc.setVariationCoordinates(numAxes), numAxes);
227 if (numAxes <= 0) {
228 desc.setVariationCoordinates(0);
229 }
230 }
231 }
232 desc.serialize(wstream);
233}
SkFontArguments::VariationPosition::Coordinate * setVariationCoordinates(int coordinateCount)
int getVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
Definition: SkTypeface.cpp:289
std::unique_ptr< SkStreamAsset > openStream(int *ttcIndex) const
Definition: SkTypeface.cpp:332

◆ setFontStyle()

void SkTypeface::setFontStyle ( SkFontStyle  style)
inlineprotected

Sets the font style. If used, must be called in the constructor.

Definition at line 349 of file SkTypeface.h.

349{ fStyle = style; }

◆ setIsFixedPitch()

void SkTypeface::setIsFixedPitch ( bool  isFixedPitch)
inlineprotected

Sets the fixedPitch bit. If used, must be called in the constructor.

Definition at line 347 of file SkTypeface.h.

347{ fIsFixedPitch = isFixedPitch; }

◆ textToGlyphs()

int SkTypeface::textToGlyphs ( const void *  text,
size_t  byteLength,
SkTextEncoding  encoding,
SkGlyphID  glyphs[],
int  maxGlyphCount 
) const

Definition at line 407 of file SkTypeface.cpp.

408 {
409 if (0 == byteLength) {
410 return 0;
411 }
412
413 SkASSERT(text);
414
415 int count = SkFontPriv::CountTextElements(text, byteLength, encoding);
416 if (!glyphs || count > maxGlyphCount) {
417 return count;
418 }
419
420 if (encoding == SkTextEncoding::kGlyphID) {
421 memcpy(glyphs, text, count << 1);
422 return count;
423 }
424
425 SkConvertToUTF32 storage;
426 const SkUnichar* uni = storage.convert(text, byteLength, encoding);
427
428 this->unicharsToGlyphs(uni, count, glyphs);
429 return count;
430}
@ kGlyphID
uses two byte words to represent glyph indices
static int CountTextElements(const void *text, size_t byteLength, SkTextEncoding)
Definition: SkFont.cpp:381
void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const
Definition: SkTypeface.cpp:357
std::u16string text

◆ unicharsToGlyphs()

void SkTypeface::unicharsToGlyphs ( const SkUnichar  uni[],
int  count,
SkGlyphID  glyphs[] 
) const

Given an array of UTF32 character codes, return their corresponding glyph IDs.

Parameters
charspointer to the array of UTF32 chars
numberof chars and glyphs
glyphsreturns the corresponding glyph IDs for each character.

Definition at line 357 of file SkTypeface.cpp.

357 {
358 if (count > 0 && glyphs && uni) {
359 this->onCharsToGlyphs(uni, count, glyphs);
360 }
361}
virtual void onCharsToGlyphs(const SkUnichar *chars, int count, SkGlyphID glyphs[]) const =0

◆ unicharToGlyph()

SkGlyphID SkTypeface::unicharToGlyph ( SkUnichar  unichar) const

Return the glyphID that corresponds to the specified unicode code-point (in UTF32 encoding). If the unichar is not supported, returns 0.

This is a short-cut for calling unicharsToGlyphs().

Definition at line 363 of file SkTypeface.cpp.

363 {
364 SkGlyphID glyphs[1] = { 0 };
365 this->onCharsToGlyphs(&uni, 1, glyphs);
366 return glyphs[0];
367}
uint16_t SkGlyphID
Definition: SkTypes.h:179

◆ uniqueID()

SkTypefaceID SkTypeface::uniqueID ( ) const
inline

Return a 32bit value for this typeface, unique for the underlying font data. Will never return 0.

Definition at line 101 of file SkTypeface.h.

101{ return fUniqueID; }

Friends And Related Function Documentation

◆ SkFontPriv

friend class SkFontPriv
friend

Definition at line 423 of file SkTypeface.h.

◆ SkPDFFont

friend class SkPDFFont
friend

Definition at line 421 of file SkTypeface.h.

◆ SkRandomTypeface

friend class SkRandomTypeface
friend

Definition at line 420 of file SkTypeface.h.

◆ SkScalerContext

friend class SkScalerContext
friend

Definition at line 355 of file SkTypeface.h.

◆ SkStrikeServerImpl

friend class SkStrikeServerImpl
friend

Definition at line 415 of file SkTypeface.h.

◆ SkTypefaceProxyPrototype

friend class SkTypefaceProxyPrototype
friend

Definition at line 416 of file SkTypeface.h.


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