import tests: centered point type at a heading's size is matched where it draws

A centered line of 72 point type on a tight leading, as garment
headings are set: with the estimate box the page's type has no text
object and the import notes a loss; with the laid-out box it is the
text object's. The 14 point centered case passes either way, as the 6
points round the estimate cover half of so short a line.

`drawn_box`'s comment says what it lays out (any point type without a
layout, in the installed fonts) and where it is used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jmvergesandClaude Opus 5.5 committed 2026-11-26 21:48:17 +00:00
1 parent cc13866e99
commit 870c640fcb
2 files changed
+38 -8

No files matched your search

+13 -8
View File
@@ -610,14 +610,19 @@ pub(super) fn extent(parts: &[Arc<Node>]) -> Option<Rect> {
parts.iter().filter_map(|n| n.visual_bounds()).reduce(|a, b| a.union(b))
}
/// Where type made from the file's text document draws: its visual box, point type laid out
/// first. Made type has no layout during the import, and without one the box of point type is an
/// estimate that runs right from its anchor ([`vectorcraft_doc::TextObject::estimate_bounds`]):
/// beside where right-aligned type draws, over one half of centered type, across vertical type, and
/// as wide as an average font would set it. The node keeps no layout: the document's type is
/// measured when it opens. Any other object's box is its visual box. `made_only`
/// matches made type with the page's type by this box, and the page comparison counts what differs
/// in it as type; `plan` doesn't match by it yet.
/// Where a text object draws: its visual box, point type that has no layout laid out first, in
/// the fonts the import has ([`vectorcraft_text::FontDb::global`]), so the box depends on which
/// fonts are installed, as the opened document's does. Any point type without a layout is laid
/// out, not only type made from the file's text document, which is the type that has none during
/// the import (the page's own type is measured when it is read). Without a layout the box of point
/// type is an estimate that runs right from its anchor
/// ([`vectorcraft_doc::TextObject::estimate_bounds`]): beside where right-aligned type draws, over
/// one half of centered type, across vertical type, and as wide as an average font would set it,
/// which can be wider than the type is. The node keeps no layout: the document's type is measured
/// when it opens. Any other object's box is its visual box.
///
/// `made_only` matches made type with the page's type by this box; `plan` doesn't match by it yet.
/// The page comparison's type areas use it for every file's layers, those `plan` fills included.
pub(super) fn drawn_box(node: &Node) -> Option<Rect> {
if let NodeKind::Text(t) = &node.kind
&& matches!(t.kind, vectorcraft_doc::TextKind::Point)
+25
View File
@@ -5529,6 +5529,31 @@ fn right_aligned_and_centered_point_type_takes_the_pages_type_where_it_draws() {
}
}
/// Centered point type at a heading's size, set tight, is matched with the page's type where it
/// draws, round its anchor. (The box of type that isn't laid out yet runs right from the anchor and
/// holds the right half of the line; with a leading under the type's size it ends at the baseline,
/// so it holds less than the half of the page's type the match needs. At 14 points the 6 points
/// round the box make up for it.)
#[test]
fn centered_point_type_at_a_heading_s_size_takes_the_pages_type_where_it_draws() {
// A 500 × 150 artboard, its centre (250, 75) the canvas centre 8191.5. "Hi there, hi" in 72 point
// Helvetica on a 58 point leading is about 348 points wide; its anchor is the artboard's middle,
// 86.5 points up.
let doc = text_document(&[("Hi there, hi\r", 2, (8191.5, 8180.0), (0.0, 0.0), 0.0)]).replacen("/1 14.0 /53", "/1 72.0 /4 false /5 58.0 /53", 1);
let art = native_with_text(&layer("Art", true, &text_object(0)), &doc).replace("0 0 100 100", "0 0 500 150").replacen(
"%AI3_TemplateBox: 50 50 50 50",
"%AI3_TemplateBox: 250 75 250 75",
1,
);
let page = "0 1 0 0 setcmykcolor /Helvetica findfont 72 scalefont setfont 76 86.5 moveto (Hi there, hi) show";
let file = String::from_utf8(eps(page, &art)).unwrap().replacen("%%BoundingBox: 0 0 100 100", "%%BoundingBox: 0 0 500 150", 1);
let r = import(file.as_bytes()).unwrap();
assert_eq!(names(&r.document), ["Art"], "{:?}", r.warnings);
let texts: Vec<String> = text_of(&r.document.layers[0]).iter().map(|t| t.plain_text()).collect();
assert_eq!(texts, ["Hi there, hi"], "{:?}", r.warnings);
assert!(!r.warnings.iter().any(|w| crate::is_loss(w)), "{:?}", r.warnings);
}
/// Right-aligned point type that the page draws in another colour differs from the page as type,
/// where it draws, before its anchor: the layers are read and the note says the type differs.
/// (Counted as art, away from the box of type that isn't laid out, it sent the file to its page.)