Skip to content
Open
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
31 changes: 15 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ jobs:
with:
package: sdf_glyph_renderer
feature-group: default-features
features: freetype
features: font

- name: Check semver (PBF Font Tools)
uses: obi1kenobi/cargo-semver-checks-action@v2
with:
package: pbf_font_tools
feature-group: default-features
features: freetype
features: generate

test:
name: Run CI
Expand All @@ -56,13 +56,18 @@ jobs:
run: cargo fmt --all -- --check

- name: Test Debug
run: cargo test --workspace --features freetype --locked
run: cargo test --workspace --locked

- name: Test Release
run: cargo test --workspace --release --features freetype --locked
run: cargo test --workspace --release --locked

Comment thread
nyurik marked this conversation as resolved.
- name: Test without optional font generation
run: |
cargo test -p sdf_glyph_renderer --no-default-features --locked
cargo test -p pbf_font_tools --no-default-features --locked

- name: Lint
run: cargo clippy --workspace --all-targets --features freetype -- -D warnings
run: cargo clippy --workspace --all-targets -- -D warnings

- name: Test docs
run: |
Expand Down Expand Up @@ -96,14 +101,8 @@ jobs:
- name: Report Rust version
run: rustc --version && cargo --version

# freetype-sys 0.23.0 bundled build is broken on Windows (links system zlib)
- name: Run tests
run: cargo test --workspace --features freetype --locked
if: ${{ !startsWith(matrix.os, 'windows') }}

- name: Run tests (no freetype)
run: cargo test --workspace --exclude build_pbf_glyphs --locked
if: ${{ startsWith(matrix.os, 'windows') }}
run: cargo test --workspace --locked

# Make sure the vendored protoc-generated file is up to date by only checking it on one platform
# We remove the file first to make sure it gets properly regenerated.
Expand All @@ -125,11 +124,11 @@ jobs:
uses: vmactions/freebsd-vm@v1
with:
prepare: |
pkg install -y rust freetype2
pkg install -y rust
run: |
# Run tests with freetype
cargo test --workspace --features freetype --locked
# Run tests
cargo test --workspace --locked
# Run tests in release mode
cargo test --workspace --release --features freetype --locked
cargo test --workspace --release --locked


6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
release:
types: [published]
types: [ published ]

name: Cargo Publish

Expand All @@ -22,11 +22,11 @@ jobs:
case "$PREFIX" in
"sdf")
CRATE_NAME="sdf_glyph_renderer"
FLAGS="--features freetype"
FLAGS="--features font"
;;
"tools")
CRATE_NAME="pbf_font_tools"
FLAGS="--features freetype"
FLAGS="--features generate"
;;
"cli")
CRATE_NAME="build_pbf_glyphs"
Expand Down
114 changes: 70 additions & 44 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ rust-version = "1.87.0"

[workspace.dependencies]
clap = { version = "4.5.60", features = ["derive"] }
freetype-rs = "0.38.0"
futures = "0.3.32"
pbf_font_tools = { version = "3", path = "pbf_font_tools", default-features = false }
pbf_font_tools = { version = "4", path = "pbf_font_tools", default-features = false }
prost = "0.14.3"
prost-build = "0.14.3"
protobuf-src = "2.1.1"
protoc-bin-vendored = "3.2.0"
sdf_glyph_renderer = { version = "1", path = "sdf_glyph_renderer" }
sdf_glyph_renderer = { version = "2", path = "sdf_glyph_renderer" }
serde_json = "1.0.149"
spmc = "0.3.0"
swash = "0.2.7"
thiserror = "2.0.18"
tokio = { version = "1.50.0", features = ["rt", "fs", "io-util"] }
2 changes: 1 addition & 1 deletion build_pbf_glyphs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protoc-vendored = ["pbf_font_tools/protoc-vendored"]

[dependencies]
clap.workspace = true
pbf_font_tools = { workspace = true, features = ["freetype"] }
pbf_font_tools = { workspace = true, features = ["generate"] }
prost.workspace = true
serde_json.workspace = true
spmc.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion build_pbf_glyphs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ isn't really anything novel; it's just a frontend to
[pbf_font_tools](../pbf_font_tools) that behaves similar to
[node-fontnik](https://github.com/mapbox/node-fontnik), but is faster and (in our opinion)
a bit easier to use since it doesn't depend on node and all its headaches, or C++ libraries
that need to be built from scratch. FreeType is bundled and compiled from source by default.
that need to be built from scratch.

Check out
[sdf_glyph_renderer](https://github.com/stadiamaps/sdf_font_tools/tree/main/sdf_glyph_renderer) for more technical
Expand Down
20 changes: 7 additions & 13 deletions build_pbf_glyphs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! [pbf_font_tools](https://github.com/stadiamaps/pbf_font_tools) that behaves similar to
//! [node-fontnik](https://github.com/mapbox/node-fontnik), but is faster and (in our opinion)
//! a bit easier to use since it doesn't depend on node and all its headaches, or C++ libraries
//! that need to be built from scratch. FreeType is bundled and compiled from source by default.
//! that need to be built from scratch.
//!
//! Check out
//! [sdf_glyph_renderer](https://github.com/stadiamaps/sdf_glyph_renderer) for more technical
Expand All @@ -24,12 +24,12 @@ use std::collections::HashMap;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::Instant;

use clap::Parser;
use pbf_font_tools::freetype::{Face, Library};
use pbf_font_tools::{get_named_font_stack, glyph_range_for_face, Glyphs};
use pbf_font_tools::{get_named_font_stack, glyph_range_for_face, FontFace, Glyphs};
use prost::Message;
use spmc::{channel, Receiver};
use tokio::fs::{create_dir_all, File};
Expand Down Expand Up @@ -107,24 +107,18 @@ fn render_worker(
cutoff: f64,
rx: Receiver<Option<(PathBuf, PathBuf)>>,
) {
let lib = Library::init().expect("Unable to initialize FreeType");

while let Ok(Some((path, stem))) = rx.recv() {
let out_dir = base_out_dir.join(stem.to_str().expect("Unable to extract file stem"));
std::fs::create_dir_all(&out_dir).expect("Unable to create output directory");

println!("Processing {}", path.display());

// Load the font once to save useless I/O
// FIXME: lib.new_face is called twice for face_index=0
// instead, call it once, create a pre-allocated vector of faces for num_faces count
// add the already open 0th, and add all remaining ones to it
let face = lib.new_face(&path, 0).expect("Unable to load font");
let num_faces = face.num_faces() as usize;
let faces: Vec<Face> = (0..num_faces)
let data: Arc<[u8]> = std::fs::read(&path).expect("Unable to read font").into();
let num_faces = FontFace::count(data.as_ref()).expect("Unable to count font faces");
let faces: Vec<FontFace> = (0..num_faces)
.map(|face_index| {
lib.new_face(&path, face_index as isize)
.expect("Unable to load face")
FontFace::from_bytes(Arc::clone(&data), face_index).expect("Unable to load face")
})
.collect();

Expand Down
5 changes: 2 additions & 3 deletions pbf_font_tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pbf_font_tools"
version = "3.1.1"
version = "4.0.0"
description = "Tools for working with SDF font glyphs encoded in protobuf format."
readme = "README.md"
keywords = ["sdf", "protobuf", "fonts"]
Expand All @@ -13,8 +13,7 @@ license.workspace = true

[features]
default = []
freetype = ["dep:sdf_glyph_renderer", "sdf_glyph_renderer?/freetype"]
freetype-system = ["dep:sdf_glyph_renderer", "sdf_glyph_renderer?/freetype-system"]
generate = ["dep:sdf_glyph_renderer", "sdf_glyph_renderer?/font"]
# Regenerate the protobuf source file using protoc, and write it back to the source tree.
Comment thread
nyurik marked this conversation as resolved.
# Combine with protoc-vendored or protoc-from-src to control which protoc binary is used.
# Without either of those features, protoc must be available in $PATH.
Expand Down
Loading
Loading