Skip to content

Commit 1a8d407

Browse files
louwersHarelM
andauthored
Add font-faces with text-font as cascading fallback list (#1204)
* Add fonts property to style spec * Add simple type for object * get unit tests to pass? * fix link * Update src/index.test.ts * Update src/reference/v8.json Co-authored-by: Harel M <[email protected]> * Update docs * fix sdk-support * Commit update * Give example for single font specified * fix example * use imported formatJSON * run linter * add examples as known key * Add type for font-faces * revert multiple examples with array * extract out FontFace type --------- Co-authored-by: Harel M <[email protected]>
1 parent bf22224 commit 1a8d407

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

build/generate-style-spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@ export type SchemaSpecification = {
389389
// State
390390
export type StateSpecification = Record<string, SchemaSpecification>;
391391
392+
export type FontFace = string | {
393+
url: string,
394+
"unicode-range"?: string[]
395+
};
396+
397+
export type FontFacesSpecification = Record<string, FontFace>;
398+
392399
${objectDeclaration('StyleSpecification', spec.$root)}
393400
394401
${objectDeclaration('LightSpecification', spec.light)}

src/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function validSchema(k, v, obj, ref, version, kind) {
7474
'variableAnchorOffsetCollection',
7575
'sprite',
7676
'projectionDefinition',
77-
'state'
77+
'state',
78+
'fontFaces'
7879
]);
7980
const keys = [
8081
'default',

src/reference/v8.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,44 @@
218218
}
219219
}
220220
},
221+
"font-faces": {
222+
"type": "array",
223+
"value": "fontFaces",
224+
"doc": "The `font-faces` property can be used to specify what font files to use for rendering text. Font faces contain information needed to render complex texts such as [Devanagari](https://en.wikipedia.org/wiki/Devanagari), [Khmer](https://en.wikipedia.org/wiki/Khmer_script) among many others.<h2>Unicode range</h2>The optional `unicode-range` property can be used to only use a particular font file for characters within the specified unicode range(s). Its value should be an array of strings, each indicating a start and end of a unicode range, similar to the [CSS descriptor with the same name](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range). This allows specifying multiple non-consecutive unicode ranges. When not specified, the default value is `U+0-10FFFF`, meaning the font file will be used for all unicode characters.\n\nRefer to the [Unicode Character Code Charts](https://www.unicode.org/charts/) to see ranges for scripts supported by Unicode. To see what unicode code-points are available in a font, use a tool like [FontDrop](https://fontdrop.info/).\n\n<h2>Font Resolution</h2>For every name in a symbol layer’s [`text-font`](./layers.md/#text-font) array, characters are matched if they are covered one of the by the font files in the corresponding entry of the `font-faces` map. Any still-unmatched characters then fall back to the [`glyphs`](./glyphs.md) URL if provided.\n\n<h2>Supported Fonts</h2>What type of fonts are supported is implementation-defined. Unsupported fonts are ignored.",
225+
"example": {
226+
"Noto Sans Regular": [
227+
{
228+
"url": "https://example.com/fonts/Noto%20Sans%20Regular/khmer.ttf",
229+
"unicode-range": [
230+
"U+1780-17FF"
231+
]
232+
},
233+
{
234+
"url": "https://example.com/fonts/Noto%20Sans%20Regular/myanmar.ttf",
235+
"unicode-range": [
236+
"U+1000-109F",
237+
"U+A9E0-A9FF",
238+
"U+AA60-AA7F"
239+
]
240+
},
241+
{
242+
"url": "https://example.com/fonts/Noto%20Sans%20Regular/devanagari.ttf",
243+
"unicode-range": [
244+
"U+0900-097F",
245+
"U+A8E0-A8FF"
246+
]
247+
}
248+
],
249+
"Open Sans": "https://example.com/fonts/Open%20Sans.ttf"
250+
},
251+
"sdk-support": {
252+
"basic functionality": {
253+
"js": "https://github.com/maplibre/maplibre-gl-js/issues/50",
254+
"android": "https://github.com/maplibre/maplibre-native/issues/3578",
255+
"ios": "https://github.com/maplibre/maplibre-native/issues/3578"
256+
}
257+
}
258+
},
221259
"transition": {
222260
"type": "transition",
223261
"doc": "A global transition definition to use as a default across properties, to be used for timing transitions between one value and the next when no property-specific transition is set. Collision-based symbol fading is controlled independently of the style's `transition` property.",

0 commit comments

Comments
 (0)