This commit is contained in:
bflatastic committed 2026-11-18 22:03:50 +07:00
commit 8daff960fe
6 files changed
+29 -79

No files matched your search

Generated
+3 -1
View File
@@ -1047,12 +1047,14 @@ source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167
[[package]]
name = "craft-font-catalog"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d0a9c79933a54883cd5bc3dfe839f1dd699f2c69#d0a9c79933a54883cd5bc3dfe839f1dd699f2c69"
source = "git+https://github.com/storytold/craft-libs?rev=23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3#23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3"
dependencies = [
"harfrust 0.13.3",
"kurbo 0.13.1",
"skrifa 0.47.0",
"thiserror 2.0.21",
"unicode-bidi",
"unicode-segmentation",
"windows-registry",
]
+2 -2
View File
@@ -9,8 +9,8 @@ description = "VectorCraft text: font database, shaping, layout, glyph outlines"
workspace = true
[dependencies]
# Pending shared extraction; pin the immutable official PR head until it merges.
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "d0a9c79933a54883cd5bc3dfe839f1dd699f2c69", default-features = false }
# The shared font catalog from craft-libs main (it has the outline, bidi and caret helpers used here).
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3", default-features = false }
vectorcraft-geom = { workspace = true }
vectorcraft-doc = { workspace = true }
kurbo = { workspace = true }
+1 -4
View File
@@ -10,10 +10,7 @@ use super::names::{norm, norm_chars, script_families};
#[cfg(not(target_arch = "wasm32"))]
use super::scan::{enumerate_faces, font_files};
use super::traits::{Alias, FontMatch, FontTraits, regular_rank};
use super::{
Arc, BezPath, CANONICAL_CACHE_MAX, Color, ColourContent, FontDb, GlyphId, GlyphImage, MetadataProvider, NEXT_ID, OUTLINE_CACHE_MAX, Ordering,
Size,
};
use super::{Arc, BezPath, CANONICAL_CACHE_MAX, Color, ColourContent, FontDb, GlyphImage, MetadataProvider, NEXT_ID, OUTLINE_CACHE_MAX, Ordering};
/// The most faces [`FontDb::postscript_faces`] gives, and the most families it loads.
const MAX_POSTSCRIPT_FACES: usize = 16;
+16 -24
View File
@@ -62,30 +62,22 @@ fn continues_cluster(prev: Option<&SGlyph>, g: Option<&SGlyph>) -> bool {
/// ([`upright_extent`]) as a share of `upright`, the length in font units its own width runs down.
/// Empty for a glyph of one character.
fn ligature_carets(text: &str, g: &SGlyph, rtl: bool, upright: Option<f64>) -> Vec<(usize, f64)> {
use unicode_segmentation::UnicodeSegmentation;
let Some(s) = text.get(g.byte..g.byte + g.len).filter(|_| g.len > 1) else { return Vec::new() };
let starts: Vec<usize> = s.grapheme_indices(true).skip(1).map(|(i, _)| g.byte + i).collect();
if starts.is_empty() {
return Vec::new();
}
let parts = starts.len() + 1;
let from_font = if let Some(length) = upright {
let (cell, top) = upright_extent(g);
g.face
.vertical_ligature_carets(g.gid, starts.len(), top, cell)
.filter(|c| c.len() == starts.len() && length > 0.0)
.map(|c| c.into_iter().map(|d| d / length).collect::<Vec<f64>>())
.filter(|c| c.iter().all(|f| *f > 0.0 && *f < 1.0))
} else {
let advance = g.face.advance(g.gid);
g.face
.ligature_carets(g.gid, starts.len())
.filter(|c| c.len() == starts.len() && advance > 0.0)
.map(|c| c.into_iter().map(|x| if rtl { 1.0 - x / advance } else { x / advance }).collect::<Vec<f64>>())
};
let mut at = from_font.unwrap_or_else(|| (1..parts).map(|j| j as f64 / parts as f64).collect());
at.sort_by(f64::total_cmp);
starts.into_iter().zip(at).collect()
craft_font_catalog::ligature_caret_stops(text, g.byte, g.len, |count| {
if let Some(length) = upright {
let (cell, top) = upright_extent(g);
g.face
.vertical_ligature_carets(g.gid, count, top, cell)
.filter(|c| c.len() == count && length > 0.0)
.map(|c| c.into_iter().map(|d| d / length).collect::<Vec<f64>>())
.filter(|c| c.iter().all(|f| *f > 0.0 && *f < 1.0))
} else {
let advance = g.face.advance(g.gid);
g.face
.ligature_carets(g.gid, count)
.filter(|c| c.len() == count && advance > 0.0)
.map(|c| c.into_iter().map(|x| if rtl { 1.0 - x / advance } else { x / advance }).collect::<Vec<f64>>())
}
})
}
/// Does glyph `g`, standing upright in vertical type, take a cell of its own down the column? Every
+5 -30
View File
@@ -81,34 +81,9 @@ pub(super) fn visual_order(bidi: Option<&BidiInfo<'_>>, paragraph_start: usize,
return vec![];
}
let levels = bidi.reordered_levels(para, line.start.saturating_sub(paragraph_start)..line.end.saturating_sub(paragraph_start));
// A list marker (length 0) is a cluster of its own.
let mut clusters: Vec<Range<usize>> = Vec::new();
for (i, g) in glyphs.iter().enumerate() {
if i > 0 && glyphs.get(i - 1).is_some_and(|p| p.byte == g.byte && (p.len == 0) == (g.len == 0)) {
if let Some(c) = clusters.last_mut() {
c.end = i + 1;
}
} else {
clusters.push(i..i + 1);
}
}
// A list marker is at the paragraph's level, and at a right-to-left one its tab is drawn
// before (left of) its characters.
let cluster_levels: Vec<_> = clusters
.iter()
.filter_map(|c| glyphs.get(c.start))
.map(|g| if g.len == 0 { g.level } else { levels.get(g.byte.saturating_sub(paragraph_start)).copied().unwrap_or(g.level) })
.collect();
let reversed = |i: usize| glyphs.get(clusters.get(i).map_or(0, |c| c.start)).is_some_and(|g| g.len == 0 && g.level.is_rtl());
unicode_bidi::BidiInfo::reorder_visual(&cluster_levels)
.into_iter()
.filter_map(|i| clusters.get(i).map(|c| (c.clone(), reversed(i))))
.flat_map(|(c, rev)| {
let mut v: Vec<usize> = c.collect();
if rev {
v.reverse();
}
v
})
.collect()
craft_font_catalog::visual_order(
glyphs.iter().map(|g| craft_font_catalog::VisualGlyph { byte: g.byte, len: g.len, level: g.level }),
paragraph_start,
&levels,
)
}
+2 -18
View File
@@ -458,24 +458,8 @@ pub(super) fn break_line(
line_end: &[f64],
fits: Option<&dyn Fn(usize, bool) -> bool>,
) -> (usize, bool) {
// The line ending at `chosen`, once it holds a tab, when it fits as drawn; otherwise the latest
// of the legal `breaks` before it that fits as drawn, measuring at most `checks` of them from
// the latest back and bisecting the earlier ones without a hyphen; the first of them when none
// of those measured fits.
let settle = |tabbed: bool, checks: usize, chosen: (usize, bool), breaks: &[(usize, bool)]| -> (usize, bool) {
let Some(fits) = fits.filter(|_| tabbed) else { return chosen };
if fits(chosen.0, chosen.1) {
return chosen;
}
let earlier = breaks.get(breaks.partition_point(|b| b.0 <= i)..breaks.partition_point(|b| b.0 < chosen.0)).unwrap_or_default();
if let Some(&b) = earlier.iter().rev().take(checks).find(|b| fits(b.0, b.1)) {
return b;
}
// Without a hyphen, a line that ends later is drawn no narrower, so those breaks bisect.
let rest = earlier.get(..earlier.len().saturating_sub(checks)).unwrap_or_default();
let plain: Vec<&(usize, bool)> = rest.iter().filter(|b| !b.1).collect();
let fitting = plain.partition_point(|b| fits(b.0, b.1));
fitting.checked_sub(1).and_then(|k| plain.get(k).copied()).or(earlier.first()).copied().unwrap_or(chosen)
let settle = |tabbed: bool, checks: usize, chosen: (usize, bool), breaks: &[(usize, bool)]| {
craft_font_catalog::settle_line_break(tabbed, checks, i, chosen, breaks, fits)
};
// How many breaks a line measures as drawn one by one.
let checks = |back: f64| if back > 0.0 { MAX_DRAWN_CHECKS_STEPPING_BACK } else { MAX_DRAWN_CHECKS };