-
-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fall back to local glyph rendering if glyph PBF is unavailable #4564
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import {loadGlyphRange} from '../style/load_glyph_range'; | |
|
||
import TinySDF from '@mapbox/tiny-sdf'; | ||
import {AlphaImage} from '../util/image'; | ||
import {warnOnce} from '../util/util'; | ||
|
||
import type {StyleGlyph} from '../style/style_glyph'; | ||
import type {RequestManager} from '../util/request_manager'; | ||
|
@@ -84,7 +85,7 @@ export class GlyphManager { | |
return {stack, id, glyph}; | ||
} | ||
|
||
glyph = this._tinySDF(entry, stack, id); | ||
glyph = this._tinySDF(entry, stack, id, false); | ||
if (glyph) { | ||
entry.glyphs[id] = glyph; | ||
return {stack, id, glyph}; | ||
|
@@ -108,7 +109,22 @@ export class GlyphManager { | |
entry.requests[range] = promise; | ||
} | ||
|
||
const response = await entry.requests[range]; | ||
let response; | ||
try { | ||
response = await entry.requests[range]; | ||
} catch (e) { | ||
glyph = this._tinySDF(entry, stack, id, true); | ||
const begin = range * 256; | ||
const end = begin + 255; | ||
const codePoint = id.toString(16).toUpperCase(); | ||
if (glyph) { | ||
warnOnce(`Unable to load glyph range ${range}, ${begin}-${end}. Rendering codepoint U+${codePoint} locally instead. ${e}`); | ||
entry.glyphs[id] = glyph; | ||
return {stack, id, glyph}; | ||
} else { | ||
warnOnce(`Unable to load glyph range ${range}, ${begin}-${end}, or render codepoint U+${codePoint} locally. ${e}`); | ||
} | ||
} | ||
for (const id in response) { | ||
if (!this._doesCharSupportLocalGlyph(+id)) { | ||
entry.glyphs[+id] = response[+id]; | ||
|
@@ -129,13 +145,13 @@ export class GlyphManager { | |
/\p{Ideo}|\p{sc=Hang}|\p{sc=Hira}|\p{sc=Kana}/u.test(String.fromCodePoint(id)); | ||
} | ||
|
||
_tinySDF(entry: Entry, stack: string, id: number): StyleGlyph { | ||
_tinySDF(entry: Entry, stack: string, id: number, force: boolean): StyleGlyph { | ||
const fontFamily = this.localIdeographFontFamily; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m wary of choosing a font for non-ideographic text based on an option called Unfortunately, many non-Mapbox-hosted fontstacks are named according to the styles for which they were created, obscuring the PostScript names of the fonts from which they were derived. For example, OpenHistoricalMap has “OpenHistorical Bold”, and OSM Americana has “Americana-Bold”. These fontstacks are a pastiche of various fonts from different families. The style authors can’t simply append Open Sans, Unifont, or Noto Sans to the array, because In order to typeset these layers in the designer’s choice of fonts, we could interpret There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think fallback is better than introducing a new field which would create confusion. |
||
if (!fontFamily) { | ||
return; | ||
} | ||
|
||
if (!this._doesCharSupportLocalGlyph(id)) { | ||
if (!force && !this._doesCharSupportLocalGlyph(id)) { | ||
return; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"pixelRatio": 2, | ||
"localIdeographFontFamily": "sans-serif", | ||
"width": 800, | ||
"height": 600 | ||
} | ||
}, | ||
"zoom": 8, | ||
"sources": { | ||
"sample": { | ||
"type": "geojson", | ||
"data": { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [0, 0] | ||
}, | ||
"properties": { | ||
"name_en": "Georgia", | ||
"name_ka": "საქართველო" | ||
} | ||
} | ||
} | ||
}, | ||
"glyphs": "local://glyphs/{fontstack}/{range}.pbf", | ||
"layers": [ | ||
{ | ||
"id": "sample-text", | ||
"type": "symbol", | ||
"source": "sample", | ||
"layout": { | ||
"text-anchor": "top", | ||
"text-field": "{name_en} ({name_ka})", | ||
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], | ||
"text-size": 30, | ||
"text-offset": [0, 0] | ||
} | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this block to a different method maybe? This method is already too long I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, looking at the code above this part, can we now handle the case where
url
is not defined? I know it's not optimal, but there are situations where you just want the text to be render without finding a glyph server. You'd need to definelocalIdeographFontFamily
anyway, which doesn't have a default, so you'd need to know what you are doing...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately, I would love to make glyph PBFs completely optional. However, the style specification currently states that
glyphs
is required as long as any layer has atext-field
property. Would relaxing that requirement constitute a breaking change in either the style spec or GL JS?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it will be a breaking change as changing a required field to optional doesn't sound like a breaking change (unless you have invalid styles, which I'm not sure are interesting).
Relaxing it would make a far better developer experience, IMHO, as I find these glyphs requirement non-friendly...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this should be brought in the style spec repo first...