diff --git a/crates/eps/src/import/native/compare.rs b/crates/eps/src/import/native/compare.rs index 424ac4079a..a34414a0ac 100644 --- a/crates/eps/src/import/native/compare.rs +++ b/crates/eps/src/import/native/compare.rs @@ -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], region: Rect, scale: f64, out: &mut Vec) { 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], region: Rect, scale: f64, out: &mut Vec>, 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 { - 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>], 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:?}"); - } -} diff --git a/crates/eps/src/import/native/slots.rs b/crates/eps/src/import/native/slots.rs index ebd6deef88..1056701d1e 100644 --- a/crates/eps/src/import/native/slots.rs +++ b/crates/eps/src/import/native/slots.rs @@ -610,10 +610,59 @@ pub(super) fn extent(parts: &[Arc]) -> Option { 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 { + 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() { diff --git a/crates/eps/src/import/tests_native.rs b/crates/eps/src/import/tests_native.rs index 4540f0940a..4bb8e8f837 100644 --- a/crates/eps/src/import/tests_native.rs +++ b/crates/eps/src/import/tests_native.rs @@ -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.