Compare commits

...
4 changed files with 37 additions and 38 deletions
Generated
+32
View File
@@ -746,6 +746,7 @@ version = "0.21.0"
dependencies = [
"cadcraft-geom",
"craft-dxf",
"craft-font-catalog",
"craft-shx",
"encoding_rs",
"harfrust 0.14.0",
@@ -1206,6 +1207,16 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-font-catalog"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=c07e38090879ffa994f893df9956c6d5b96c049c#c07e38090879ffa994f893df9956c6d5b96c049c"
dependencies = [
"skrifa 0.47.0",
"thiserror 2.0.21",
"windows-registry",
]
[[package]]
name = "craft-fonts-build"
version = "0.1.0"
@@ -4173,6 +4184,17 @@ dependencies = [
"once_cell",
]
[[package]]
name = "read-fonts"
version = "0.44.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5a0cf4bb6cbce4c29756270d189a5e400ac05e91192161d83a0bcb6e68492e8"
dependencies = [
"bytemuck",
"font-types 0.12.7",
"once_cell",
]
[[package]]
name = "read-fonts"
version = "0.45.1"
@@ -4637,6 +4659,16 @@ dependencies = [
"read-fonts 0.41.0",
]
[[package]]
name = "skrifa"
version = "0.47.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "526e654b303ff4ad73a5a40b25de2b3ce3d039c5e3b6da5f89ae6e57004cb40f"
dependencies = [
"bytemuck",
"read-fonts 0.44.0",
]
[[package]]
name = "skrifa"
version = "0.48.0"
+2
View File
@@ -35,6 +35,8 @@ craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-l
# PDF writing (krilla) for plots, and reading them back in tests. The root patches below pin
# craft-pdf's patched backends to the same revision (Cargo ignores dependency-local patches).
craft-pdf = { version = "=0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", default-features = false }
# TrueType embedding-permission classification for plotted fonts (craft-libs#778).
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "c07e38090879ffa994f893df9956c6d5b96c049c", default-features = false }
clap = { version = "4", features = ["derive", "env"] }
clap_complete = "4.6.11"
clap_mangen = { version = "0.3.3", features = ["env"] }
+1
View File
@@ -11,6 +11,7 @@ workspace = true
[dependencies]
cadcraft-geom = { workspace = true }
craft-dxf = { workspace = true }
craft-font-catalog = { workspace = true }
craft-shx = { workspace = true }
skrifa = { workspace = true }
harfrust = { workspace = true }
+2 -38
View File
@@ -3,50 +3,14 @@
//! never embedded; callers draw their text as outlines instead. Fonts without TrueType outlines
//! (CFF-flavoured OpenType) aren't embedded either.
use skrifa::FontRef;
use skrifa::raw::types::Tag;
use crate::ttf::Face;
/// Whether a face may be embedded as a subset.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Embedding {
/// Installable, editable or preview & print embedding (or no OS/2 table).
Allowed,
/// `fsType` restricted licence: no embedding.
Restricted,
/// `fsType` bit 8: the font may only be embedded whole.
NoSubsetting,
/// `fsType` bit 9: only bitmaps may be embedded.
BitmapOnly,
/// No TrueType outlines (`glyf` / `loca`), or the font doesn't parse.
NotTrueType,
}
fn table<'a>(f: &FontRef<'a>, t: [u8; 4]) -> Option<&'a [u8]> {
f.table_data(Tag::new(&t)).map(|d| d.as_bytes())
}
fn u16_at(b: &[u8], i: usize) -> Option<u16> {
Some(u16::from_be_bytes([*b.get(i)?, *b.get(i + 1)?]))
}
pub use craft_font_catalog::SubsetEmbedding as Embedding;
/// The embedding permission of a face.
pub fn embedding(face: &Face) -> Embedding {
let Ok(f) = FontRef::from_index(&face.bytes, face.index) else { return Embedding::NotTrueType };
if table(&f, *b"glyf").is_none() || table(&f, *b"loca").is_none() || table(&f, *b"head").is_none() {
return Embedding::NotTrueType;
}
let Some(fs_type) = table(&f, *b"OS/2").and_then(|o| u16_at(o, 8)) else { return Embedding::Allowed };
if fs_type & 0x0200 != 0 {
Embedding::BitmapOnly
} else if fs_type & 0x000F == 0x0002 {
Embedding::Restricted
} else if fs_type & 0x0100 != 0 {
Embedding::NoSubsetting
} else {
Embedding::Allowed
}
craft_font_catalog::subset_embedding(&face.bytes, face.index)
}
#[cfg(test)]