fuchsia.fonts

Added: 7

PROTOCOLS

FontSetEventListener

Defined in fuchsia.fonts/events.fidl

Protocol for listening to possible events that may occur in the Provider's set of fonts.

Register a listener using fuchsia.fonts/Provider.RegisterFontSetEventListener.

OnFontSetUpdated

The set of fonts available in the Provider has changed. See fuchsia.fonts/FontSetUpdatedEvent.

Request

NameType
event FontSetUpdatedEvent

Response

<EMPTY>

Provider

Defined in fuchsia.fonts/font_provider.fidl

Provider of digital font files and metadata.

TODO(https://fxbug.dev/42170326): Remove deprecated methods and move to provider.fidl.

GetFamilyInfo

Deprecated. See GetFontFamilyInfo.

Returns information for the specified font family or null if there is no family with the specified name. This function respects family name aliases and ignores case, so request for "robotoSLAB" will return FamilyInfo for "Roboto Slab".

Request

NameType
family string[128]

Response

NameType
family_info FamilyInfo?

GetFont

Deprecated. See GetTypeface.

Returns font that matches specified request.

Request

NameType
request Request

Response

NameType
response Response?

GetFontFamilyInfo

Returns information for the specified font family, or an empty table if there is no family with the specified name.

This function respects family name aliases and ignores case. For example, "RobotoSlab" is an alias for the canonical name "Roboto Slab". A request for "robotoSLAB" would return the FontFamilyInfo for "Roboto Slab" due to the case-insensitivity and alias resolution.

Request

NameType
family FamilyName

Response

NameType
family_info FontFamilyInfo

GetTypeface

Returns a typeface that matches the specified request, or an empty table if no matching face is found. (The latter is more likely to happen if TypefaceRequestFlags.EXACT_FAMILY is used to disable fallbacks.)

Request

NameType
request TypefaceRequest

Response

NameType
response TypefaceResponse

RegisterFontSetEventListener

Register a listener to be notified when the set of available fonts or mappings has changed. A client can register as many listeners as it wishes.

To unregister, close the channel.

Request

NameType
listener FontSetEventListener

Response

<EMPTY>

STRUCTS

FamilyInfo

Defined in fuchsia.fonts/font_provider.fidl

Deprecated. See FontFamilyInfo.

Information about font family that can be requested using GetFamilyInfo().

FieldTypeDescriptionDefault
name string[128]

Canonical font family name. Note that this may be different from the value passed to GetFamilyInfo() because GetFamilyInfo() also resolves font aliases and ignores case. For example GetFamilyInfo("robotoslab") will FamilyInfo.name = "Robot Slab".

No default
styles vector<Style>[300]

Unordered list of all available styles in the family.

No default

FamilyName

Defined in fuchsia.fonts/provider.fidl

The name of a family of fonts.

Examples: "Roboto", "Noto Serif".

FieldTypeDescriptionDefault
name string[128]

The characters that make up the name.

No default

Request

Defined in fuchsia.fonts/font_provider.fidl

Deprecated. See FaceRequest.

FieldTypeDescriptionDefault
family string[128]?

Desired font family name, e.g. "Roboto". Font family search is case-insensitive. In case when there is no specified family or the specified family doesn't have glyph for the requested character then a font from another family may be returned. This behavior can be disabled using REQUEST_FLAG_NO_FALLBACK.

No default
weight uint32

For example, 400 is normal, 700 is bold.

400
width uint32

Numeric values matching OS/2 & Windows Metrics usWidthClass table. https://www.microsoft.com/typography/otspec/os2.htm For example, 5 is normal.

5
slant Slant Slant.UPRIGHT
language vector<string>[8]?

BCP47 language tags in order of preference. See https://tools.ietf.org/html/bcp47 .

No default
character uint32

Codepoint for the character that must be present in the returned font or 0. Caller that specify this field are expected to extract character set from the result and cache it in order to avoid calling the API more than necessary.

0
fallback_group FallbackGroup

Fallback group preference. Caller can leave this field set to NONE. In that case the font provider will use fallback group of the specified font family.

FallbackGroup.NONE
flags uint32 0

Response resource

Defined in fuchsia.fonts/font_provider.fidl

FieldTypeDescriptionDefault
buffer fuchsia.mem/Buffer No default
buffer_id uint32

Buffer identifier for the buffer. Responses with the same buffer_id are guaranteed to contain the same data in the buffer. Clients may use this value to detect if they already have the font cached in parsed form.

No default
font_index uint32

Font index within buffer. Used for font formats that may contain more than one font per file, e.g. TTC (TrueType Collection).

No default

Style

Defined in fuchsia.fonts/font_provider.fidl

Deprecated. See Style2.

FieldTypeDescriptionDefault
weight uint32 No default
width uint32 No default
slant Slant No default

ENUMS

CacheMissPolicy strict

Type: uint32

Defined in fuchsia.fonts/provider.fidl

Options for what the font server should do if the client requests a typeface that is not yet cached.

NameValueDescription
1

The server will attempt to load the uncached typeface before providing a response. This is the default behavior.

This option is not recommended for synchronous clients that block rendering while waiting for a font.

2

The server will tell the client that the uncached typeface is unavailable, by returning an empty fuchsia.fonts/TypefaceResponse. The uncached typeface may be downloaded asynchronously to be available for future requests.

This is similar to font-display: block in CSS.

3

The server will attempt to provide a cached fallback typeface (if allowed by the fallback restrictions in fuchsia.fonts/TypefaceRequestFlags). The uncached typeface may be downloaded asynchronously to be available for future requests.

This is similar to font-display: swap in CSS.

FallbackGroup strict

Type: uint32

Defined in fuchsia.fonts/font_provider.fidl

Deprecated. See GenericFontFamily.

NameValueDescription
0
1
2
3
4
5

GenericFontFamily strict

Type: uint32

Defined in fuchsia.fonts/styles.fidl

Generic groups of font families that can serve as fallbacks for a specific family.

Every font family belongs to some generic font family (see examples below).

If an exact requested family is unavailable but a fallback group is specified in the request, the provider may return some other family that belongs to the fallback group. For example, if the client requests the "Arial" family with a SANS_SERIF fallback, and "Arial" is unavailable, the provider may return another available sans serif family, such as "Roboto Regular", instead.

See also: https://www.w3.org/TR/css-fonts-4/#generic-font-families

NameValueDescription
1

Glyphs have little "serifs", hooks, or notches at the ends of most strokes. Examples: Georgia, Noto Serif, Times New Roman.

2

Glyphs that have no serifs at the ends of most strokes. Examples: Arial, Noto Sans, Roboto, Tahoma.

3

Fixed-width fonts. Examples: Consolas, Courier New, Inconsolata.

4

Handwritten or cursive fonts. Examples: Brush Script, Comic Sans, Lucida Calligraphy.

5

Decorative fonts. Examples: Impact, Papyrus.

6

The default user interface font on the target platform. This is included for completeness with the CSS specification; font manifests should not declare that a font belongs to the SYSTEM_UI generic family, but instead should declare a more specific option (e.g. SERIF for Roboto).

Not commonly used.

7

Fonts that are used specifically for rendering emoji code points. Examples: Noto Color Emoji.

8

Fonts that are used primarily for rendering mathematical expressions.

Not commonly used.

9

A group of Chinese fonts between serif and cursive, often used for official Chinese Government documents.

Not commonly used.

Slant strict

Type: uint32

Defined in fuchsia.fonts/styles.fidl

The type of slant of a type face.

NameValueDescription
1

The default; upright glyphs.

2

Specially designed, slanted and slightly calligraphic glyphs.

3

Skewed glyphs. Oblique usually means an geometric transformation of the upright variant, rather than a custom-designed variant.

Width strict

Type: uint32

Defined in fuchsia.fonts/styles.fidl

Horizontal width class of the glyphs.

See https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass.

NameValueDescription
1

50% of normal width

2

62.5% of normal width

3

75% of normal width

4

87.5% of normal width

5

Normal width

6

112.5% of normal width

7

125% of normal width

8

150% of normal width

9

200% of normal width

TABLES

FontFamilyInfo

Defined in fuchsia.fonts/provider.fidl

Information about a font family that can be requested using Provider.GetFontFamilyInfo().

If a matching font family is not found, the table will be empty.

OrdinalFieldTypeDescription
name FamilyName

Canonical font family name. Note that this may be different from the value passed to GetFontFamilyInfo() due to the resolution of font aliases, and/or differences in whitespace and capitalization.

styles vector<Style2>[300]

Unordered list of all available styles in the family.

FontSetUpdatedEvent

Defined in fuchsia.fonts/events.fidl

An event indicating that the set of fonts available in the Provider has changed. This is most frequently caused by an ephemeral font being downloaded and cached. Clients should consider re-requesting fonts and re-rendering any displayed text.

OrdinalFieldTypeDescription

Style2

Defined in fuchsia.fonts/styles.fidl

Style properties that can be used when requesting or describing a type face.

OrdinalFieldTypeDescription
slant Slant

See Slant.

weight Weight

Weight or thickness of the glyphs. Allowed values are integers in the range [1, 1000], but most real-world font families only support some integer multiples of 100: {100, 200, ..., 900}. Normal text (WEIGHT_NORMAL) is 400; WEIGHT_BOLD is 700.

See: https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#Common_weight_name_mapping https://docs.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass

width Width

See Width.

TypefaceQuery

Defined in fuchsia.fonts/provider.fidl

Parameters for looking up a typeface.

OrdinalFieldTypeDescription
family FamilyName

Desired font family name, e.g. "Roboto". Font family search is case-insensitive.

Note: In cases where the specified family doesn't exist, or the specified family doesn't have a glyph for the requested code_point, a face from another family may be returned. This behavior can be disabled using TypefaceRequestFlags.EXACT_FAMILY.

style Style2

Style properties of the desired typeface.

languages vector<fuchsia.intl/LocaleId>[8]

Language tags in order of preference. This allows disambiguating code points that map to different glyphs in different languages (e.g. CJK code points).

See fuchsia.intl.LocaleId.

code_points vector<uint32>[128]

Optional code points for which glyphs must be present in the returned face.

Callers that specify this field are expected to extract the character set from the result and cache it in order to avoid calling the API more than necessary.

fallback_family GenericFontFamily

A generic font family to fall back to if an exact match is unavailable or does not contain the requested code point.

Every font family belongs to a generic family (configured in the font manifest). If a particular font family doesn't contain a requested code point, the provider can search for the code point in other font families in the same generic family as a fallback.

Specifying fallback_family in a query allows the client to override the generic family that would be used as a fallback.

postscript_name string[63]

The exact Postscript name of the typeface to look up. This corresponds to name ID 6 in the TrueType/OpenType name table.

All characters must be in the printable ASCII range (U+0021 to U+007E), and must not be '[', ']', '(', ')', '{', '}', '<', '>', '/', or '%'.

If this field is specified, all the other query fields are ignored.

full_name string[128]

The exact full name of the typeface to look up. This corresponds to name ID 4 in the TrueType/OpenType name table.

If this field is specified, all the other query fields are ignored.

TypefaceRequest

Defined in fuchsia.fonts/provider.fidl

Parameters for requesting a typeface.

OrdinalFieldTypeDescription
query TypefaceQuery

Parameters for looking up a typeface.

flags TypefaceRequestFlags

Flags for how to process the request, such as which kinds of substitutions are permitted.

cache_miss_policy CacheMissPolicy

Setting for what to do if the requested typeface exists but is not cached, and therefore cannot be served immediately.

If this field is empty, the default policy is fuchsia.fonts/CacheMissPolicy.BLOCK_UNTIL_DOWNLOADED.

If the client needs an immediate response, it can choose one of the non-blocking policies. In this case, clients can also register to be notified when new fonts have been added to the cache by calling fuchsia.fonts/Provider.RegisterFontSetEventListener.

TypefaceResponse resource

Defined in fuchsia.fonts/provider.fidl

Response to a TypefaceRequest. Contains the digital font file and metadata corresponding to a returned typeface. Clients are expected to cache the results if they plan to reuse them.

If a matching typeface cannot be found, the table will be empty.

OrdinalFieldTypeDescription
buffer fuchsia.mem/Buffer

A memory buffer containing the bytes of a digital font file. It is the client's responsibility to identify the type of file and to parse it (usually by delegating to FreeType or a similar library).

buffer_id uint32

Identifier for the buffer. Responses with the same buffer_id are guaranteed to contain the same data in the buffer. Clients may use this value to detect if they already have the font cached in parsed form.

font_index uint32

Index of the returned typeface within buffer. Used for digital font formats that may contain more than one typeface per file, e.g. TTC (TrueType Collection).

BITS

TypefaceRequestFlags strict

Type: uint32

Defined in fuchsia.fonts/provider.fidl

Boolean flags for TypefaceRequest.

NameValueDescription
1

Disables font family fallback. The service won't try to search the fallback font set if the requested font family doesn't exist or if it doesn't contain the requested code point.

2

Disables approximate style matching. The service will only return a face that matches the requested style exactly. For example, there will be no substitutions of "medium" for a requested "semi-bold" weight, or "oblique" for a requested "italic" slant.

CONSTANTS

NameValueTypeDescription
DEFAULT_SLANT

Default slant of a typeface when none is specified.

DEFAULT_WEIGHT WEIGHT_NORMAL uint16

Default weight of a typeface when none is specified.

DEFAULT_WIDTH

Default width of a typeface when none is specified.

MAX_FACE_QUERY_CODE_POINTS 128 uint32

The maximum number of code points allowed in a typeface query.

MAX_FACE_QUERY_LANGUAGES 8 uint32

The maximum number of preferred languages allowed in a typeface query.

MAX_FAMILY_NAME_LENGTH 128 uint32

The maximum length of a font family name.

MAX_FAMILY_STYLES 300 uint32

The maximum number of styles that will be returned for a font family.

MAX_POSTSCRIPT_TYPEFACE_NAME_LENGTH 63 uint32

The maximum length of a typeface's Postscript name. The limit comes from the OpenType name table specification.

MAX_TYPEFACE_NAME_LENGTH 128 uint32

The maximum length of a typeface's full name.

REQUEST_FLAG_EXACT_MATCH 2 uint32

Deprecated. See FaceRequestFlags. Disables approximate style matching. The service will only return font that matches the requested style exactly.

REQUEST_FLAG_NO_FALLBACK 1 uint32

Deprecated. See FaceRequestFlags. Disables font fallback. The service won't try to search fallback font set if there is no requested font family or if it doesn't contain requested character.

WEIGHT_BLACK 900 uint16
WEIGHT_BOLD 700 uint16
WEIGHT_EXTRA_BOLD 800 uint16
WEIGHT_EXTRA_LIGHT 200 uint16
WEIGHT_LIGHT 300 uint16
WEIGHT_MEDIUM 500 uint16
WEIGHT_NORMAL 400 uint16
WEIGHT_SEMI_BOLD 600 uint16
WEIGHT_THIN 100 uint16

ALIASES

NameValueDescription
Weight uint16