Improved handling of glyph urls as commonly used in styles
#1,443 opened on Jul 28, 2024
Repository metrics
- Stars
- (3,761 stars)
- PR merge metrics
- (PR metrics pending)
Description
When trying to make the font service working, I stumbled across a small problem that is easy to fix, but not so easy to find out why it didn't work (at least for me).
I'm using a tilemaker mbtiles file together with publicly available openmaptiles style, for example, https://github.com/openmaptiles/osm-bright-gl-style/blob/master/style.json. Practically all openmapstyle styles listed on https://openmaptiles.org/styles/, have one thing in common in how they specify the glph url. They do it as something like
{
"glyphs": "https://api.maptiler.com/fonts/{fontstack}/{range}.pbf?key={key}"
}
When I first tried to make Martin work as glyph server, I adapted the url to
{
"glyphs": "font/{fontstack}/{range}.pbf"
}
This didn't work. Martin successfully scanned the font directory that I have provided:
Configured font Open Sans Regular with 883 glyphs (0020-FFFD) from fonts/open-sans/OpenSans-Regular.ttf
But when I tried to access the service with http://localhost:3000/font/Open%20Sans%20Regular/0-255.pbf as I have watched maplibre request the glyphs, I would get a response can not parse "255.pbf" to a u32.
After enabling the debug logs, I got
2024-07-28T10:59:28Z DEBUG actix_web::types::path] Failed during Path extractor deserialization. Request path: "/font/Open%20Sans%20Regular/0-255.pbf"
[2024-07-28T10:59:28Z DEBUG actix_web::middleware::logger] Error in response: Error("can not parse \"255.pbf\" to a u32")
After some tinkering, I found out that http://localhost:3000/font/Open%20Sans%20Regular/0-255 works, but http://localhost:3000/font/Open%20Sans%20Regular/0-255.pbf doesn't. After changing the glyph urls in the styles to the following everything started to work perfectly
{
- "glyphs": "font/{fontstack}/{range}.pbf"
+ "glyphs": "font/{fontstack}/{range}"
}
Ideally there would be either a pointer in the documentation how the glyph urls need to look like or the server would automatically detect such pbf urls and handle them correctly.
Thanks for this great server. I really enjoy tinkering with it!