Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkTypeface Class Referenceabstract

The SkTypeface class specifies the typeface and intrinsic style of a font. More...

#include <SkTypeface.h>

Inheritance diagram for SkTypeface:

Classes

struct  LocalizedString
 
class  LocalizedStrings
 

Public Types

enum  Style { kNormal = 0, kBold = 0x01, kItalic = 0x02, kBoldItalic = 0x03 }
 Style specifies the intrinsic style attributes of a given typeface.
 
enum  Encoding { kUTF8_Encoding, kUTF16_Encoding, kUTF32_Encoding }
 

Public Member Functions

SkFontStyle fontStyle () const
 Returns the typeface's intrinsic style attributes. More...
 
Style style () const
 Returns the typeface's intrinsic style attributes. More...
 
bool isBold () const
 Returns true if style() has the kBold bit set. More...
 
bool isItalic () const
 Returns true if style() has the kItalic bit set. More...
 
bool isFixedPitch () const
 Returns true if the typeface claims to be fixed-pitch. More...
 
int getVariationDesignPosition (SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
 Copy into 'coordinates' (allocated by the caller) the design variation coordinates. More...
 
SkFontID uniqueID () const
 Return a 32bit value for this typeface, unique for the underlying font data. More...
 
void serialize (SkWStream *) const
 Write a unique signature to a stream, sufficient to reconstruct a typeface referencing the same font when Deserialize is called.
 
int charsToGlyphs (const void *chars, Encoding encoding, SkGlyphID glyphs[], int glyphCount) const
 Given an array of character codes, of the specified encoding, optionally return their corresponding glyph IDs (if glyphs is not NULL). More...
 
int countGlyphs () const
 Return the number of glyphs in the typeface.
 
int countTables () const
 Return the number of tables in the font. More...
 
int getTableTags (SkFontTableTag tags[]) const
 Copy into tags[] (allocated by the caller) the list of table tags in the font, and return the number. More...
 
size_t getTableSize (SkFontTableTag) const
 Given a table tag, return the size of its contents, or 0 if not present.
 
size_t getTableData (SkFontTableTag tag, size_t offset, size_t length, void *data) const
 Copy the contents of a table into data (allocated by the caller). More...
 
int getUnitsPerEm () const
 Return the units-per-em value for this typeface, or zero if there is an error.
 
bool getKerningPairAdjustments (const SkGlyphID glyphs[], int count, int32_t adjustments[]) const
 Given a run of glyphs, return the associated horizontal adjustments. More...
 
LocalizedStringscreateFamilyNameIterator () const
 Returns an iterator which will attempt to enumerate all of the family names specified by the font. More...
 
void getFamilyName (SkString *name) const
 Return the family name for this typeface. More...
 
SkStreamAssetopenStream (int *ttcIndex) const
 Return a stream for the contents of the font data, or NULL on failure. More...
 
std::unique_ptr< SkFontData > makeFontData () const
 Return the font data, or nullptr on failure.
 
std::unique_ptr< SkScalerContext > createScalerContext (const SkScalerContextEffects &, const SkDescriptor *, bool allowFailure=false) const
 Return a scalercontext for the given descriptor. More...
 
SkRect 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,). More...
 
void filterRec (SkScalerContextRec *rec) const
 
void getFontDescriptor (SkFontDescriptor *desc, bool *isLocal) const
 
void * internal_private_getCTFontRef () const
 

Static Public Member Functions

static SkFontID UniqueID (const SkTypeface *face)
 Return the uniqueID for the specified typeface. More...
 
static bool Equal (const SkTypeface *facea, const SkTypeface *faceb)
 Returns true if the two typefaces reference the same underlying font, handling either being null (treating null as the default font)
 
static sk_sp< SkTypefaceMakeDefault (Style style=SkTypeface::kNormal)
 Returns the default typeface, which is never nullptr. More...
 
static sk_sp< SkTypefaceMakeFromName (const char familyName[], SkFontStyle fontStyle)
 Creates a new reference to the typeface that most closely matches the requested familyName and fontStyle. More...
 
static sk_sp< SkTypefaceMakeFromTypeface (SkTypeface *family, Style)
 Return the typeface that most closely matches the requested typeface and style. More...
 
static sk_sp< SkTypefaceMakeFromFile (const char path[], int index=0)
 Return a new typeface given a file. More...
 
static sk_sp< SkTypefaceMakeFromStream (SkStreamAsset *stream, int index=0)
 Return a new typeface given a stream. More...
 
static sk_sp< SkTypefaceMakeFromFontData (std::unique_ptr< SkFontData >)
 Return a new typeface given font data and configuration. More...
 
static sk_sp< SkTypefaceMakeDeserialize (SkStream *)
 Given the data previously written by serialize(), return a new instance of a typeface referring to the same font. More...
 

Protected Member Functions

 SkTypeface (const SkFontStyle &style, bool isFixedPitch=false)
 uniqueID must be unique and non-zero
 
void setIsFixedPitch (bool isFixedPitch)
 Sets the fixedPitch bit. More...
 
void setFontStyle (SkFontStyle style)
 Sets the font style. More...
 
virtual SkScalerContext * onCreateScalerContext (const SkScalerContextEffects &, const SkDescriptor *) const =0
 
virtual void onFilterRec (SkScalerContextRec *) const =0
 
virtual std::unique_ptr
< SkAdvancedTypefaceMetrics > 
onGetAdvancedMetrics () const
 
virtual SkStreamAssetonOpenStream (int *ttcIndex) const =0
 
virtual std::unique_ptr
< SkFontData > 
onMakeFontData () const
 
virtual int onGetVariationDesignPosition (SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const =0
 
virtual void onGetFontDescriptor (SkFontDescriptor *, bool *isLocal) const =0
 
virtual int onCharsToGlyphs (const void *chars, Encoding, SkGlyphID glyphs[], int glyphCount) 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
 Returns the family name of the typeface as known by its font manager. More...
 
virtual LocalizedStringsonCreateFamilyNameIterator () const =0
 Returns an iterator over the family names in the font. More...
 
virtual int onGetTableTags (SkFontTableTag tags[]) const =0
 
virtual size_t onGetTableData (SkFontTableTag, size_t offset, size_t length, void *data) const =0
 
virtual bool onComputeBounds (SkRect *) const
 
virtual void * onGetCTFontRef () const
 

Static Protected Member Functions

static SkTypefaceGetDefaultTypeface (Style style=SkTypeface::kNormal)
 

Private Types

typedef SkWeakRefCnt INHERITED
 

Private Member Functions

std::unique_ptr
< SkAdvancedTypefaceMetrics > 
getAdvancedMetrics () const
 Retrieve detailed typeface metrics. More...
 

Private Attributes

SkFontID fUniqueID
 
SkFontStyle fStyle
 
SkRect fBounds
 
SkOnce fBoundsOnce
 
bool fIsFixedPitch
 

Friends

class SkScalerContext
 
class SkRandomTypeface
 
class SkPDFFont
 
class GrPathRendering
 
class GrGLPathRendering
 
class SkPaint
 
class SkGlyphCache
 

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.

Member Function Documentation

int SkTypeface::charsToGlyphs ( const void *  chars,
Encoding  encoding,
SkGlyphID  glyphs[],
int  glyphCount 
) const

Given an array of character codes, of the specified encoding, optionally return their corresponding glyph IDs (if glyphs is not NULL).

Parameters
charspointer to the array of character codes
encodinghow the characters are encoded
glyphs(optional) returns the corresponding glyph IDs for each character code, up to glyphCount values. If a character code is not found in the typeface, the corresponding glyph ID will be 0.
glyphCountnumber of code points in 'chars' to process. If glyphs is not NULL, then it must point sufficient memory to write glyphCount values into it.
Returns
the number of number of continuous non-zero glyph IDs computed from the beginning of chars. This value is valid, even if the glyphs parameter is NULL.
int SkTypeface::countTables ( ) const

Return the number of tables in the font.

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.

std::unique_ptr<SkScalerContext> SkTypeface::createScalerContext ( const SkScalerContextEffects &  ,
const SkDescriptor *  ,
bool  allowFailure = false 
) const

Return a scalercontext for the given descriptor.

If this fails, then if allowFailure is true, this returns NULL, else it returns a dummy scalercontext that will not crash, but will draw nothing.

SkFontStyle SkTypeface::fontStyle ( ) const
inline

Returns the typeface's intrinsic style attributes.

std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface::getAdvancedMetrics ( ) const
private

Retrieve detailed typeface metrics.

Used by the PDF backend.

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.

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.

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

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
fontIDthe font to copy the table from
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.
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()).

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.
bool SkTypeface::isBold ( ) const
inline

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

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.

bool SkTypeface::isItalic ( ) const
inline

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

static sk_sp<SkTypeface> SkTypeface::MakeDefault ( Style  style = SkTypeface::kNormal)
static

Returns the default typeface, which is never nullptr.

static sk_sp<SkTypeface> SkTypeface::MakeDeserialize ( SkStream )
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. Does not affect ownership of SkStream.

static sk_sp<SkTypeface> SkTypeface::MakeFromFile ( const char  path[],
int  index = 0 
)
static

Return a new typeface given a file.

If the file does not exist, or is not a valid font file, returns nullptr.

static sk_sp<SkTypeface> SkTypeface::MakeFromFontData ( std::unique_ptr< SkFontData >  )
static

Return a new typeface given font data and configuration.

If the data is not valid font data, returns nullptr.

static sk_sp<SkTypeface> SkTypeface::MakeFromName ( const char  familyName[],
SkFontStyle  fontStyle 
)
static

Creates a new reference to the typeface that most closely matches the requested familyName and fontStyle.

This method allows extended font face specifiers as in the SkFontStyle type. Will never return null.

Parameters
familyNameMay be NULL. The name of the font family.
fontStyleThe style of the typeface.
Returns
reference to the closest-matching typeface. Call must call unref() when they are done.
static sk_sp<SkTypeface> SkTypeface::MakeFromStream ( SkStreamAsset stream,
int  index = 0 
)
static

Return a new typeface given a stream.

If the stream is not a valid font file, returns nullptr. Ownership of the stream is transferred, so the caller must not reference it again.

static sk_sp<SkTypeface> SkTypeface::MakeFromTypeface ( SkTypeface family,
Style   
)
static

Return the typeface that most closely matches the requested typeface and style.

Use this to pick a new style from the same family of the existing typeface. If family is nullptr, this selects from the default font's family.

Parameters
familyMay be NULL. The name of the existing type face.
sThe style (normal, bold, italic) of the type face.
Returns
the closest-matching typeface.
virtual LocalizedStrings* SkTypeface::onCreateFamilyNameIterator ( ) const
protectedpure virtual

Returns an iterator over the family names in the font.

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.

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.

void SkTypeface::setFontStyle ( SkFontStyle  style)
inlineprotected

Sets the font style.

If used, must be called in the constructor.

void SkTypeface::setIsFixedPitch ( bool  isFixedPitch)
inlineprotected

Sets the fixedPitch bit.

If used, must be called in the constructor.

Style SkTypeface::style ( ) const
inline

Returns the typeface's intrinsic style attributes.

Deprecated:
use fontStyle() instead.
SkFontID SkTypeface::uniqueID ( ) const
inline

Return a 32bit value for this typeface, unique for the underlying font data.

Will never return 0.

static SkFontID SkTypeface::UniqueID ( const SkTypeface face)
static

Return the uniqueID for the specified typeface.

If the face is null, resolve it to the default font and return its uniqueID. Will never return 0.


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