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

Add doc about font #963

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ actix-rt = "2"
actix-web = "4"
anyhow = "1.0"
async-trait = "0.1"
bit-set = "0.5.3"
brotli = "3"
cargo-husky = { version = "1", features = ["user-hooks"], default-features = false }
clap = { version = "4", features = ["derive"] }
Expand All @@ -35,6 +36,7 @@ log = "0.4"
martin-mbtiles = { path = "./martin-mbtiles", version = "0.6.0", default-features = false }
martin-tile-utils = { path = "./martin-tile-utils", version = "0.1.0" }
num_cpus = "1"
pbf_font_tools = { version = "2.5.0", features = ["freetype"] }
pmtiles = { version = "0.3", features = ["mmap-async-tokio", "tilejson"] }
postgis = "0.9"
postgres = { version = "0.19", features = ["with-time-0_3", "with-uuid-1", "with-serde_json-1"] }
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [MBTiles and PMTiles File Sources](sources-files.md)
- [Composite Sources](sources-composite.md)
- [Sprite Sources](sources-sprites.md)
- [Font Sources](sources-fonts.md)
- [Usage and Endpoint API](using.md)
- [Using with MapLibre](using-with-maplibre.md)
- [Using with Leaflet](using-with-leaflet.md)
Expand Down
5 changes: 5 additions & 0 deletions docs/src/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ sprites:
sources:
# SVG images in this directory will be published as a "my_sprites" sprite source
my_sprites: /path/to/some_dir
# Font configuration
fonts:
# otf, ttf, ttc files will be find recursively
- /path/to/font_dir1
- /path/to/font_dir2
```
3 changes: 3 additions & 0 deletions docs/src/run-with-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Options:
-s, --sprite <SPRITE>
Export a directory with SVG files as a sprite source. Can be specified multiple times

-f, --font <FONT>
Export a directory with font files as a font source. Can be specified multiple times

-k, --keep-alive <KEEP_ALIVE>
Connection keep alive timeout. [DEFAULT: 75]

Expand Down
29 changes: 29 additions & 0 deletions docs/src/sources-fonts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Font Sources

Martin can serve font assests(`otf`, `ttf`, `ttc`) for map rendering, and there is no need to supply a large number of small pre-generated font protobuf files. Martin can generate them dynamically on the fly based on your request.

## API
You can request font protobuf of single or combination of fonts.

||API|Demo|
|----|----|----|
|Single|/font/{fontstack}/{start}-{end}|http://127.0.0.1:3000/font/Overpass Mono Bold/0-255|
|Combination|/font/{fontstack1},{fontstack2},{fontstack_n}/{start}-{end}|http://127.0.0.1:3000/font/Overpass Mono Bold,Overpass Mono Light/0-255|

## Configuring from CLI
A font directory can be configured from the [CLI](run-with-cli.md) with the `--font` flag. The flag can be used multiple times to configure multiple font directories.

```shell
martin --font /path/to/font_dir1 --font /path/to/font_dir2
```

## Configuring from Config File

A font directory can be configured from the config file with the `fonts` key.

```yaml
# Fonts configuration
fonts:
- /path/to/fonts_dir1
- /path/to/fonts_dir2
```
2 changes: 2 additions & 0 deletions martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ actix-http.workspace = true
actix-rt.workspace = true
actix-web.workspace = true
async-trait.workspace = true
bit-set.workspace = true
brotli.workspace = true
clap.workspace = true
deadpool-postgres.workspace = true
Expand All @@ -68,6 +69,7 @@ log.workspace = true
martin-mbtiles.workspace = true
martin-tile-utils.workspace = true
num_cpus.workspace = true
pbf_font_tools.workspace = true
pmtiles.workspace = true
postgis.workspace = true
postgres-protocol.workspace = true
Expand Down
9 changes: 8 additions & 1 deletion martin/src/args/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::args::srv::SrvArgs;
use crate::args::State::{Ignore, Share, Take};
use crate::config::Config;
use crate::file_config::FileConfigEnum;
use crate::{Error, Result};
use crate::{Error, OptOneMany, Result};

#[derive(Parser, Debug, PartialEq, Default)]
#[command(about, version)]
Expand Down Expand Up @@ -44,6 +44,9 @@ pub struct MetaArgs {
/// Export a directory with SVG files as a sprite source. Can be specified multiple times.
#[arg(short, long)]
pub sprite: Vec<PathBuf>,
/// Export a directory with font files as a font source. Can be specified multiple times.
#[arg(short, long)]
pub font: Vec<PathBuf>,
}

impl Args {
Expand Down Expand Up @@ -81,6 +84,10 @@ impl Args {
config.sprites = FileConfigEnum::new(self.meta.sprite);
}

if !self.meta.font.is_empty() {
config.fonts = OptOneMany::new(self.meta.font);
}

cli_strings.check()
}
}
Expand Down
Loading