.ai import: made point type that differs from the page counts as type where it draws

The page comparison tells type that differs from art that differs by
where the layers' text objects are (`type_areas` and `all_type_areas` in
`crates/eps/src/import/native/compare.rs`). Type made from the file's
text document has no layout then, so its box was the estimate of type
without one, running right from its anchor: right-aligned type draws on
the other side of it, centered type half outside it, vertical type
across it. What differed there (type laid out again, or in another
font) was counted as art, which is held to a stricter limit: the layers
could be refused and the file sent to its PDF part or page, or the note
said the art differs where the type does.

The type areas now come from where the type draws: `drawn_box`, the box
the first commit matches by, moved to `slots.rs` so both use it. The
page's own type keeps its measured box, as before.

`prune_unseen` and the boxes of made type that doesn't show still use
the estimate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jmvergesandClaude Opus 5.5 committed 2026-11-26 19:51:10 +00:00
1 parent 62af02a78c
commit 57bb305f83
4 files changed
+73 -61

No files matched your search

+7 -5
View File
@@ -1,5 +1,5 @@
use super::build::Frame;
use super::slots::OUTLINE_REACH;
use super::slots::{OUTLINE_REACH, drawn_box};
use super::{Arc, Document, Node, NodeKind, Rect};
/// `doc` with its layers that don't print hidden, when it has any.
@@ -756,12 +756,14 @@ fn differing_pixels(
}
/// Where the type that shows in `nodes` is, in pixels of `region` drawn at `scale` (with a margin
/// for the strokes round it). The type in a live envelope isn't: the envelope draws it bent, away
/// from its text object's box, and is weighed as the art it draws, as its drawn art would be.
/// for the strokes round it): where it draws ([`drawn_box`]), so that type made from the text
/// document that differs from the page's counts as type whatever its alignment. The type in a
/// live envelope isn't: the envelope draws it bent, away from its text object's box, and is
/// weighed as the art it draws, as its drawn art would be.
fn type_areas(nodes: &[Arc<Node>], region: Rect, scale: f64, out: &mut Vec<Rect>) {
for n in nodes.iter().filter(|n| n.visible) {
if let NodeKind::Text(_) = n.kind
&& let Some(b) = n.visual_bounds()
&& let Some(b) = drawn_box(n)
{
let px =
|r: Rect| Rect::new((r.x0 - region.x0) * scale, (r.y0 - region.y0) * scale, (r.x1 - region.x0) * scale, (r.y1 - region.y0) * scale);
@@ -780,7 +782,7 @@ fn all_type_areas(nodes: &[Arc<Node>], region: Rect, scale: f64, out: &mut Vec<R
for n in nodes {
let placed = matches!(&n.kind, NodeKind::Image(im) if im.link.is_some());
if (placed || matches!(n.kind, NodeKind::Text(_)))
&& let Some(b) = n.visual_bounds()
&& let Some(b) = drawn_box(n)
{
let b = b.inflate(OUTLINE_REACH, OUTLINE_REACH);
out.push(Rect::new((b.x0 - region.x0) * scale, (b.y0 - region.y0) * scale, (b.x1 - region.x0) * scale, (b.y1 - region.y0) * scale));
+2 -56
View File
@@ -1,7 +1,7 @@
use super::layers::closed_where_ends_meet;
use super::slots::{
Content, MAX_PAIRS, OUTLINE_REACH, PAGE_TYPE_LEFT_OUT, PAGE_TYPE_UNCHECKED, SlotInfo, assign, covered, extent, join_pieces, letters, same_type,
word_pieces, words,
Content, MAX_PAIRS, OUTLINE_REACH, PAGE_TYPE_LEFT_OUT, PAGE_TYPE_UNCHECKED, SlotInfo, assign, covered, drawn_box, extent, join_pieces, letters,
same_type, word_pieces, words,
};
use super::{Affine, Arc, Node, NodeId, NodeKind, Point, Rect, Story, TextKind};
@@ -334,26 +334,6 @@ fn made_content(infos: &[SlotInfo], made: Vec<Option<Made>>, laid: bool) -> Vec<
.collect()
}
/// Where made type draws: its visual box, point type laid out first. Made type has no layout yet,
/// 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. [`made_only`] matches
/// by this box; [`plan`] doesn't yet.
fn drawn_box(node: &Node) -> Option<Rect> {
if let NodeKind::Text(t) = &node.kind
&& matches!(t.kind, TextKind::Point)
&& t.cached_bounds.is_none()
{
let mut laid = node.clone();
if let NodeKind::Text(t) = &mut laid.kind {
t.cached_bounds = Some(vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t).bounds);
}
return laid.visual_bounds();
}
node.visual_bounds()
}
/// Mark the made type that has at least half of a piece of the page's type where it draws (or round
/// it, as far as strokes round type reach) as type the page draws. How many of the page's text
/// objects no made type takes, shown or not: none that holds a piece of the object has its words
@@ -574,37 +554,3 @@ fn fill_hidden(infos: &[SlotInfo], stories: &[Option<Arc<Story>>], content: &mut
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use vectorcraft_doc::{CharStyle, Justify, TextObject};
/// Made point type is matched with the page's type where it draws: right-aligned type before its
/// anchor, centered type round it, vertical type down from it. Its node keeps no layout.
#[test]
fn made_point_type_s_box_is_where_its_alignment_and_orientation_draw_it() {
let anchor = 300.0;
let made = |justify: Justify, vertical: bool| {
let mut t = TextObject::point(Point::new(anchor, 200.0), "Wide heading", CharStyle { size: 40.0, ..CharStyle::default() });
t.para.justify = justify;
for p in t.para_styles_mut() {
p.justify = justify;
}
t.vertical = vertical;
Node::new(NodeId(1), NodeKind::Text(Box::new(t)))
};
let boxed = |justify, vertical| {
let node = made(justify, vertical);
let b = drawn_box(&node).unwrap();
assert!(matches!(&node.kind, NodeKind::Text(t) if t.cached_bounds.is_none()));
b
};
let (left, right, centered, down) =
(boxed(Justify::Left, false), boxed(Justify::Right, false), boxed(Justify::Center, false), boxed(Justify::Left, true));
assert!(left.x0 > anchor - 20.0 && left.width() > 100.0, "{left:?}");
assert!(right.x1 < anchor + 20.0 && (right.width() - left.width()).abs() < 1.0, "{right:?}");
assert!((centered.center().x - anchor).abs() < 20.0 && (centered.width() - left.width()).abs() < 1.0, "{centered:?}");
assert!(down.height() > 2.0 * down.width() && down.height() > 100.0, "{down:?}");
}
}
+49
View File
@@ -610,10 +610,59 @@ 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.
pub(super) fn drawn_box(node: &Node) -> Option<Rect> {
if let NodeKind::Text(t) = &node.kind
&& matches!(t.kind, vectorcraft_doc::TextKind::Point)
&& t.cached_bounds.is_none()
{
let mut laid = node.clone();
if let NodeKind::Text(t) = &mut laid.kind {
t.cached_bounds = Some(vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t).bounds);
}
return laid.visual_bounds();
}
node.visual_bounds()
}
#[cfg(test)]
mod tests {
use super::*;
/// Made point type's box is where its alignment and orientation draw it: right-aligned type
/// before its anchor, centered type round it, vertical type down from it. Its node keeps no
/// layout.
#[test]
fn made_point_type_s_box_is_where_its_alignment_and_orientation_draw_it() {
use vectorcraft_doc::{CharStyle, Justify, TextObject};
let anchor = 300.0;
let boxed = |justify: Justify, vertical: bool| {
let mut t = TextObject::point(Point::new(anchor, 200.0), "Wide heading", CharStyle { size: 40.0, ..CharStyle::default() });
t.para.justify = justify;
for p in t.para_styles_mut() {
p.justify = justify;
}
t.vertical = vertical;
let node = Node::new(NodeId(1), NodeKind::Text(Box::new(t)));
let b = drawn_box(&node).unwrap();
assert!(matches!(&node.kind, NodeKind::Text(t) if t.cached_bounds.is_none()));
b
};
let (left, right, centered, down) =
(boxed(Justify::Left, false), boxed(Justify::Right, false), boxed(Justify::Center, false), boxed(Justify::Left, true));
assert!(left.x0 > anchor - 20.0 && left.width() > 100.0, "{left:?}");
assert!(right.x1 < anchor + 20.0 && (right.width() - left.width()).abs() < 1.0, "{right:?}");
assert!((centered.center().x - anchor).abs() < 20.0 && (centered.width() - left.width()).abs() < 1.0, "{centered:?}");
assert!(down.height() > 2.0 * down.width() && down.height() > 100.0, "{down:?}");
}
/// Past the limits, the slots of type that looks draw go, in groups too, and other slots stay.
#[test]
fn look_type_slots_are_dropped_from_groups() {
+15
View File
@@ -5529,6 +5529,21 @@ fn right_aligned_and_centered_point_type_takes_the_pages_type_where_it_draws() {
}
}
/// 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.)
#[test]
fn right_aligned_point_type_that_differs_from_the_page_differs_as_type() {
let doc = text_document(&[("Hi there\r", 1, (8231.5, 8180.0), (0.0, 0.0), 0.0)]);
let art = native_with_text(&layer("Art", true, &text_object(0)), &doc);
// The text document's type is magenta; the page draws it black, ending at the anchor.
let page = "0 0 0 1 setcmykcolor /Helvetica findfont 14 scalefont setfont 41 61.5 moveto (Hi there) show";
let r = import(&eps(page, &art)).unwrap();
assert_eq!(names(&r.document), ["Art"], "{:?}", r.warnings);
assert!(r.warnings.iter().any(|w| w.starts_with("the type on the layers differs from the file's own page")), "{:?}", r.warnings);
assert!(!r.warnings.iter().any(|w| w.starts_with("the art on the layers differs")), "{:?}", r.warnings);
}
/// A ligature the page shows by a glyph its font's encoding names `uniE028` (a private-use
/// character, without the letters it stands for) is the letters of its text object: the page's type
/// has one, and nothing is noted as left out.