mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-13 02:39:42 +00:00
address review: a collapsed line break keeps its measured leading in tiny type
This commit is contained in:
@@ -950,7 +950,9 @@ fn lines(
|
||||
// A line's characters take its spacing as leading unless it is their auto leading.
|
||||
for (k, b) in breaks.iter().enumerate() {
|
||||
let end = breaks.get(k + 1).map_or(n, |nb| nb.at);
|
||||
if cells[b.at..end].iter().any(|c| (c.style.effective_leading() - b.leading).abs() > 0.01) {
|
||||
// 0.01 absolute, but never more than a thousandth of the spacing itself (tiny type has tiny gaps).
|
||||
let tolerance = 0.01_f64.min(b.leading.abs() * 1e-3);
|
||||
if cells[b.at..end].iter().any(|c| (c.style.effective_leading() - b.leading).abs() > tolerance) {
|
||||
for c in &mut cells[b.at..end] {
|
||||
c.style.leading = Some(b.leading);
|
||||
}
|
||||
|
||||
@@ -232,6 +232,15 @@ fn per_character_positions_with_middle_anchor() {
|
||||
assert!(close(mid(0), 50.0, 0.05) && close(mid(1), 100.0, 0.05), "{} {}", mid(0), mid(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_small_line_gap_in_tiny_type_keeps_its_leading() {
|
||||
// 0.0085 against an auto leading of 0.006 differs by less than 0.01 but is not a whole multiple of it.
|
||||
let d = open(r#"<text x="1" y="1" font-size="0.005">One<tspan x="1" dy="0.0085">Two</tspan></text>"#);
|
||||
let t = only_text(&d);
|
||||
let two = t.runs.iter().find(|r| r.text.contains("Two")).unwrap().style.leading;
|
||||
assert!(two.is_some_and(|l| close(l, 0.0085, 1e-9)), "{two:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tspan_lines_dx_and_baseline_shift() {
|
||||
let d = open(
|
||||
|
||||
Reference in New Issue
Block a user