-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Serve fonts for MapLibre rendering #704
Comments
So the API would be like:
I think it's quite intuitive and useful. Hehe The full font or transformation internallyMaybe we could ignore this part and start from a basic. Kepp watching is it import?
|
Here is draft implementation I did mbtileserver-rs, : [dependencies]
pbf_font_tools = "2.2.0"
protobuf = "3.2.0"
urlencoding = "2.1.2"
lazy_static = "1.4" use hyper::header::{CONTENT_ENCODING, CONTENT_TYPE, HOST};
use hyper::{Body, Request, Response, StatusCode};
use lazy_static::lazy_static;
use pbf_font_tools::get_font_stack;
use protobuf::Message;
use regex::Regex;
use serde_json::json;
use urlencoding::decode;
lazy_static! {
static ref FONT_URL_RE: Regex = Regex::new(r"^/fonts/(?P<font_names>.*)/(?P<start>\d+)-(?P<end>\d+)\.(?P<format>[a-zA-Z]+)").unwrap();
}
let path = decode(uri.path()).unwrap().into_owned();
if path.starts_with("/fonts") {
let matches = FONT_URL_RE.captures(&path).unwrap();
let font_names: Vec<&str> = matches
.name("font_names")
.unwrap()
.as_str()
.split(",")
.collect();
let start = matches
.name("start")
.unwrap()
.as_str()
.parse::<u32>()
.unwrap();
let end = matches
.name("end")
.unwrap()
.as_str()
.parse::<u32>()
.unwrap();
let fonts_stack =
get_font_stack(Path::new("./fonts"), &font_names, start, end)
.await
.unwrap();
return Ok(Response::builder()
.header(CONTENT_TYPE, "application/x-protobuf")
.body(Body::from(fonts_stack.write_to_bytes().unwrap()))
.unwrap());
}
}
}; |
Thanks @catalinconstant ! I have been looking at that lib to do exactly what you propose. I recently did the same implementation for sprites in #715 -- you may want to look at these two places
Let me know if you want to hack on it, or I could look at it later on to adapt your code |
If you could adapt the code will better for me. Thanks |
sure, i will try to get to it sometime next week - this week is FOSS4G, so i'm travelling |
Partial implementation is in #755 - still needs some polishing, but its getting there |
done in #755, will be released soon |
Martin should serve font assets for MapLibre rendering, given a font file.
API
I think source IDs could be used here as font IDs, and we could also, possibly as a subdirectory like
/fonts/...
/fonts/<font_source_id>
- returns some JSON font metadata. Any standards here?/fonts/<font_source_id>/<unicode_range>
- one of the ways fonts are sub-divided is by unicode pages - because it is assumed that you only need some unicode range for a specific region of the mapConfiguration
Config file and possibly CLI should have a simple option to serve a font file. Since font files are essentially identical to mbtiles and pmtiles from configuration perspective (a single file produces a single source), we can use identical config structure:
The idea of font serving was initially proposed here by @sharkAndshark
See also #705 for sprite serving
The text was updated successfully, but these errors were encountered: