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

Implement dynamic font support /font/<name>/<start>-<end> #755

Merged
merged 10 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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
12 changes: 11 additions & 1 deletion martin/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use std::collections::HashMap;
use std::fs::File;
use std::future::Future;
use std::io::prelude::*;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::pin::Pin;

use futures::future::try_join_all;
use serde::{Deserialize, Serialize};
use subst::VariableMap;

use crate::file_config::{resolve_files, FileConfigEnum};
use crate::fonts::FontSources;
use crate::mbtiles::MbtSource;
use crate::pg::PgConfig;
use crate::pmtiles::PmtSource;
Expand All @@ -24,6 +25,7 @@ pub type UnrecognizedValues = HashMap<String, serde_yaml::Value>;
pub struct ServerState {
pub tiles: TileSources,
pub sprites: SpriteSources,
pub fonts: FontSources,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand All @@ -43,6 +45,9 @@ pub struct Config {
#[serde(default, skip_serializing_if = "FileConfigEnum::is_none")]
pub sprites: FileConfigEnum,

#[serde(default, skip_serializing_if = "OptOneMany::is_none")]
pub fonts: OptOneMany<PathBuf>,

#[serde(flatten)]
pub unrecognized: UnrecognizedValues,
}
Expand All @@ -61,10 +66,14 @@ impl Config {
res.extend(self.mbtiles.finalize("mbtiles.")?);
res.extend(self.sprites.finalize("sprites.")?);

// TODO: support for unrecognized fonts?
// res.extend(self.fonts.finalize("fonts.")?);

if self.postgres.is_empty()
&& self.pmtiles.is_empty()
&& self.mbtiles.is_empty()
&& self.sprites.is_empty()
&& self.fonts.is_empty()
{
Err(NoSources)
} else {
Expand All @@ -76,6 +85,7 @@ impl Config {
Ok(ServerState {
tiles: self.resolve_tile_sources(idr).await?,
sprites: SpriteSources::resolve(&mut self.sprites)?,
fonts: FontSources::resolve(&mut self.fonts)?,
})
}

Expand Down
Loading
Loading