Skip to content
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

TiledVectorLayer: Couldn't load font name: Frutiger #632

Open
danielz-42 opened this issue Jun 10, 2024 · 6 comments
Open

TiledVectorLayer: Couldn't load font name: Frutiger #632

danielz-42 opened this issue Jun 10, 2024 · 6 comments

Comments

@danielz-42
Copy link

I tried to use the TiledVectorLayer by:

image

App crashed and in logcat I found the issue:

  • Couldn't load font name: Frutiger

Any hints to resolve that?

@rostopira
Copy link

Same crash happens on iOS with style url VectorLayer(styleURL: "https://tiles.openfreemap.org/styles/liberty").
But it crashes on attempts to load "Noto Sans Italic" and "Noto Sans Regular", despite those are available as system fonts.
I've looked into source code, and I can see that MCFontLoader uses some obscure code to get font image.
I would really appreciate any help with that.

@maurhofer-ubique
Copy link
Contributor

maurhofer-ubique commented Jan 3, 2025

Hi @danielz-42 and @rostopira,

Please excuse the (extremely) late reply and the non-existent documentation regarding the font handling in vector layers. At the current state, the layer does not load the glyph data from the url specified in the style.json, but instead relies on a FontLoader to provide a texture atlas and json with all the relevant symbols. While the support for the former might be added in the future, it is not worked actively on at the moment.

In your case on Android @danielz-42, there is the option to specify the path to an asset folder, from which the FontLoader tries to load the textures and glyph descriptions (png and json, respectively). When no such path is provided (such as with the constructor you used), this data can be added manually when loaded from a different source.

Regarding the format of this glyph data: In OpenMobileMaps we use multi-channel signed distance fields of the symbols to render them. A tool like msdf-bmfont can be used to create such a packed sprite atlas texture and descriptive json from a font file. Please note that while the default FontLoader on Android expects the json to match the structure of the class FontGlyphJsonData (which corresponds to the output of msdf-bmfont), it can easily be extended to load and provide the necessary Bitmap and FontData (only a subset msdf-bmfonts information) from another source format. Of course, a fully custom implementation of the FontLoaderInterface can be provided as well.

In short, the most convenient way to support the fonts specified would be to create the font texture and json via:

msdf-bmfont 'Open Sans Regular.ttf' -f json -m 512,512 -s 38 -i chars.txt -r 11 -o 'Open Sans Regular'

where chars.txt might contain:

!" #$%&'()*+,-.\0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz[/]^_`{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ‘’“”…€–ıŌōŪūĀāĪīĞğŞş
 

Ensure that all the symbols fit on one texture page.

On Android, the resulting OpenSansRegular.png/.json can then be added to the projects asset folder (e.g. at the path "fonts/") and the TiledVectorLayer can be created with:

val vectorLayer = TiledVectorLayer(
	context = context,
	styleUrl = "https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json",
	fontAssetFolder = "fonts/"
)

Please note, that the swisstopo style uses feature-dependent fonts, e.g. in the layer place_town_village, which is currently not supported (3.0.0-rc.3) but will be fixed with the next release.

On iOS (@rostopira), the MCFontLoader can be used to load the font image and data from the project resources.

I hope I was able to clear up the confusion you had about the vector layer font support. If not, please let me know.

@liodali
Copy link

liodali commented Jan 14, 2025

can you give us example of how we can achieve that on iOS ?
but current way will not support all language such as arabic or chinese etc

@stmitt
Copy link
Contributor

stmitt commented Jan 14, 2025

Hi @liodali,

To achieve this on iOS, the font texture atlases and json files need to be included in your app’s bundle. The MCFontLoader.swift can then load the font image and data directly from these resources. Regarding languages like Arabic or Chinese, support is possible as long as the provided font texture atlas includes the required characters for those scripts. You’ll need to ensure the atlas contains all glyphs needed for the language in question.

@liodali
Copy link

liodali commented Jan 14, 2025

thnx but i need more help if possible for sure since i dont have lot of experience with it
how we can have json file for font ? is there any tool should we use
typically i can get altases of the font without issue but i dont know how to get json file

@maurhofer-ubique
Copy link
Contributor

As mentioned above, msdf-bmfont can be used to generate both the texture atlas and the JSON file required for the vector layer. This is the same for both Android and iOS. The README on their repository provides instructions on how to install it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants