Typeface

class Typeface

The Typeface 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.

Example:

typeface = skia.Typeface()
typeface = skia.Typeface('Arial')
typeface = skia.Typeface('Arial', skia.FontStyle.Bold())

Classes

SerializeBehavior

A typeface can serialize just a descriptor (names, etc.), or it can also

Methods

Equal

Equal(self: skia.Typeface, other: skia.Typeface) -> bool

MakeDefault

MakeDefault() -> skia.Typeface

MakeDeserialize

MakeDeserialize(dats: skia.Data, lastResortMgr: SkFontMgr) -> skia.Typeface

MakeEmpty

MakeEmpty() -> skia.Typeface

MakeFromData

MakeFromData(data: skia.Data, index: int = 0) -> skia.Typeface

MakeFromFile

MakeFromFile(path: str, index: int = 0) -> skia.Typeface

MakeFromName

MakeFromName(familyName: object, fontStyle: skia.FontStyle = None) -> skia.Typeface

__init__

__init__(*args, **kwargs) Overloaded function.

copyTableData

copyTableData(self: skia.Typeface, tag: int) -> skia.Data

countGlyphs

countGlyphs(self: skia.Typeface) -> int

countTables

countTables(self: skia.Typeface) -> int

fontStyle

fontStyle(self: skia.Typeface) -> skia.FontStyle

getBounds

getBounds(self: skia.Typeface) -> skia.Rect

getFamilyName

getFamilyName(self: skia.Typeface) -> str

getFamilyNames

getFamilyNames(self: skia.Typeface) -> list

getKerningPairAdjustments

getKerningPairAdjustments(self: skia.Typeface, glyphs: list[int]) -> object

getPostScriptName

getPostScriptName(self: skia.Typeface) -> str

getTableData

getTableData(self: skia.Typeface, tag: int) -> bytes

getTableSize

getTableSize(self: skia.Typeface, tag: int) -> int

getTableTags

getTableTags(self: skia.Typeface) -> list[int]

getUnitsPerEm

getUnitsPerEm(self: skia.Typeface) -> int

getVariationDesignParameters

getVariationDesignParameters(self: skia.Typeface) -> list[skia.FontParameters.Variation.Axis]

getVariationDesignPosition

getVariationDesignPosition(self: skia.Typeface) -> skia.FontArguments.VariationPosition.Coordinates

isBold

isBold(self: skia.Typeface) -> bool

isFixedPitch

isFixedPitch(self: skia.Typeface) -> bool

isItalic

isItalic(self: skia.Typeface) -> bool

makeClone

makeClone(self: skia.Typeface, fontArguments: skia.FontArguments) -> skia.Typeface

ref

ref(self: skia.RefCntBase) -> None

serialize

serialize(self: skia.Typeface, behavior: skia.Typeface.SerializeBehavior = skia.Typeface.SerializeBehavior.kIncludeDataIfLocal) -> skia.Data

unicharToGlyph

unicharToGlyph(self: skia.Typeface, unichar: int) -> int

unicharsToGlyphs

unicharsToGlyphs(self: skia.Typeface, chars: list[int]) -> list[int]

unique

unique(self: skia.RefCntBase) -> bool

uniqueID

uniqueID(self: skia.Typeface) -> int

unref

unref(self: skia.RefCntBase) -> None

Attributes

kDoIncludeData

kDontIncludeData

kIncludeDataIfLocal

Methods

static Typeface.Equal(self: skia.Typeface, other: skia.Typeface) bool

Returns true if the two typefaces reference the same underlying font, handling either being null (treating null as the default font)

static Typeface.MakeDefault() skia.Typeface

Returns the default normal typeface, which is never nullptr.

static Typeface.MakeDeserialize(dats: skia.Data, lastResortMgr: SkFontMgr) skia.Typeface

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.

static Typeface.MakeEmpty() skia.Typeface

Returns a non-null typeface which contains no glyphs.

static Typeface.MakeFromData(data: skia.Data, index: int = 0) skia.Typeface

Return a new typeface given a Data.

If the data is null, or is not a valid font file, returns nullptr.

Use MakeDeserialize() for the result of serialize().

static Typeface.MakeFromFile(path: str, index: int = 0) skia.Typeface

Return a new typeface given a file.

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

static Typeface.MakeFromName(familyName: object, fontStyle: skia.FontStyle = None) skia.Typeface

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 FontStyle type. Will never return null.

Parameters:
  • familyName (str) – May be NULL. The name of the font family.

  • fontStyle (skia.FontStyle) – The style of the typeface.

Returns:

reference to the closest-matching typeface.

Typeface.__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: skia.Typeface) -> None

    Returns the default normal typeface.

  2. __init__(self: skia.Typeface, familyName: object, fontStyle: skia.FontStyle = None) -> None

    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 FontStyle type. Will never return null.

    param str familyName:

    May be NULL. The name of the font family.

    param skia.FontStyle fontStyle:

    The style of the typeface.

    return:

    reference to the closest-matching typeface.

Typeface.copyTableData(self: skia.Typeface, tag: int) skia.Data

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:

tag – The table tag whose contents are to be copied

Returns:

an immutable copy of the table’s data, or nullptr.

Typeface.countGlyphs(self: skia.Typeface) int

Return the number of glyphs in the typeface.

Typeface.countTables(self: skia.Typeface) int

Return the number of tables in the font.

Typeface.fontStyle(self: skia.Typeface) skia.FontStyle

Returns the typeface’s intrinsic style attributes.

Typeface.getBounds(self: skia.Typeface) skia.Rect

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.

Typeface.getFamilyName(self: skia.Typeface) str

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.

Typeface.getFamilyNames(self: skia.Typeface) list

Returns a list of (family name, language) pairs specified by the font.

Typeface.getKerningPairAdjustments(self: skia.Typeface, glyphs: list[int]) object

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. If the typeface does not support kerning, then this method will return None (no kerning) for all possible glyph runs.

Typeface.getPostScriptName(self: skia.Typeface) str

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

Typeface.getTableData(self: skia.Typeface, tag: int) bytes

Returns the contents of a table.

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:

tag (int) – The table tag whose contents are to be copied.

Returns:

table contents

Typeface.getTableSize(self: skia.Typeface, tag: int) int

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

Typeface.getTableTags(self: skia.Typeface) list[int]

Returns the list of table tags in the font.

Typeface.getUnitsPerEm(self: skia.Typeface) int

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

Typeface.getVariationDesignParameters(self: skia.Typeface) list[skia.FontParameters.Variation.Axis]

Returns the design variation parameters.

Returns:

List of axes.

Return type:

List[skia.FontParameters.Variation.Axis]

Typeface.getVariationDesignPosition(self: skia.Typeface) skia.FontArguments.VariationPosition.Coordinates

Returns the design variation coordinates.

Parameters:

coordinateCount (int) – the maximum number of entries to get.

Returns:

list of coordinates

Return type:

List[skia.FontArguments.VariationPosition.Coordinate]

Typeface.isBold(self: skia.Typeface) bool

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

Typeface.isFixedPitch(self: skia.Typeface) bool

Returns true if the typeface claims to be fixed-pitch.

Typeface.isItalic(self: skia.Typeface) bool

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

Typeface.makeClone(self: skia.Typeface, fontArguments: skia.FontArguments) skia.Typeface

Return a new typeface based on this typeface but parameterized as specified in the FontArguments.

If the FontArguments 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.

Typeface.ref(self: skia.RefCntBase) None

Increment the reference count.

Must be balanced by a call to unref().

Typeface.serialize(self: skia.Typeface, behavior: skia.Typeface.SerializeBehavior = skia.Typeface.SerializeBehavior.kIncludeDataIfLocal) skia.Data

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

Typeface.unicharToGlyph(self: skia.Typeface, unichar: int) int

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

Typeface.unicharsToGlyphs(self: skia.Typeface, chars: list[int]) list[int]

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

Parameters:

chars (List[int]) – the array of UTF32 chars.

Returns:

the corresponding glyph IDs for each character.

Typeface.unique(self: skia.RefCntBase) bool

May return true if the caller is the only owner.

Ensures that all previous owner’s actions are complete.

Typeface.uniqueID(self: skia.Typeface) int

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

Will never return 0.

Typeface.unref(self: skia.RefCntBase) None

Decrement the reference count.

If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.

Attributes

Typeface.kDoIncludeData = <SerializeBehavior.kDoIncludeData: 0>
Typeface.kDontIncludeData = <SerializeBehavior.kDontIncludeData: 1>
Typeface.kIncludeDataIfLocal = <SerializeBehavior.kIncludeDataIfLocal: 2>