Merge pull request #9491 from jmverges/fix/ai-made-point-type-box

.ai import: made point type is matched with the page's type where it draws
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-26 21:32:36 -08:00
commit 3d71a5027f
5 files changed
+138 -14

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));
+16 -9
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};
@@ -145,7 +145,8 @@ pub(super) fn made_only(
warn: &mut Vec<String>,
) -> Vec<Content> {
let [shown, hidden] = pages;
let mut content = made_content(infos, made);
// Every text object that shows has made type: each is matched with the page's type where it draws.
let mut content = made_content(infos, made, true);
// The page's type where no made type draws, in the copies that looks draw, is theirs (past
// `MAX_PAIRS` comparisons it isn't looked for).
let looks = infos.iter().any(|i| i.shown && i.look.is_some());
@@ -315,15 +316,18 @@ fn object_words(o: &[Arc<Node>]) -> Vec<String> {
}
/// Each slot's made type as its content, else nothing yet. Made type that shows has where it draws,
/// or where its story lies when it draws nothing.
fn made_content(infos: &[SlotInfo], made: Vec<Option<Made>>) -> Vec<Content> {
/// or where its story lies when it draws nothing. `laid`: point type is laid out for its box
/// ([`drawn_box`]); without it the box is that of type without a layout, as it always was.
fn made_content(infos: &[SlotInfo], made: Vec<Option<Made>>, laid: bool) -> Vec<Content> {
infos
.iter()
.zip(made)
.map(|(info, m)| match m {
Some((node, region)) => {
let drawn = node.visual_bounds().filter(|b| !b.is_zero_area()).or(region);
Content::Made(node, drawn.filter(|_| info.shown), false)
// Type that doesn't show has no region: it isn't laid out for one.
let own = || if laid { drawn_box(&node) } else { node.visual_bounds() };
let drawn = info.shown.then(|| own().filter(|b| !b.is_zero_area() && b.is_finite()).or(region)).flatten();
Content::Made(node, drawn, false)
}
None => Content::Empty,
})
@@ -391,8 +395,11 @@ pub(super) fn plan(
// Where the made type that doesn't show lies, by slot.
let hidden_at: Vec<(usize, Rect)> =
infos.iter().zip(&made).enumerate().filter_map(|(k, (info, m))| Some((k, m.as_ref().filter(|_| !info.shown)?.1?))).collect();
// Type the text document makes, shown or not: the page's pieces of it aren't needed.
let mut content = made_content(infos, made);
// Type the text document makes, shown or not: the page's pieces of it aren't needed. Its box
// stays that of type without a layout here: with text objects whose type isn't made stacked on
// made type that has their words (the copies of an outlined heading), the page's pieces in the
// box where the made type draws are theirs too, and the made type would take them all.
let mut content = made_content(infos, made, false);
// Is `object` the type of a text object that doesn't show, as the page draws it: in its frame,
// with its words? (A copied object's lines are where its original's are, so they don't say.)
let hidden_type = |object: &[Arc<Node>]| {
+54
View File
@@ -610,10 +610,64 @@ pub(super) fn extent(parts: &[Arc<Node>]) -> Option<Rect> {
parts.iter().filter_map(|n| n.visual_bounds()).reduce(|a, b| a.union(b))
}
/// 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)
&& 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() {
+60
View File
@@ -5509,6 +5509,66 @@ fn a_small_label_of_the_page_in_no_text_object_is_noted() {
assert!(note.is_some_and(|w| crate::is_loss(w)), "{:?}", r.warnings);
}
/// Point type that isn't aligned left is matched with the page's type where it draws: right-aligned
/// type ends at its anchor and centered type lies round it, so the page's type there is theirs and
/// nothing is noted as left out. (The box of type that isn't laid out yet runs right from its
/// anchor, past the page's type.)
#[test]
fn right_aligned_and_centered_point_type_takes_the_pages_type_where_it_draws() {
// "Hi there" in 14 point Helvetica is about 49 points wide. The anchors are 90 and 50 across the
// art; the page draws the line so that it ends at the first and lies round the second.
for (align, anchor, at) in [(1, 8231.5, 41.0), (2, 8191.5, 25.5)] {
let doc = text_document(&[("Hi there\r", align, (anchor, 8180.0), (0.0, 0.0), 0.0)]);
let art = native_with_text(&layer("Art", true, &text_object(0)), &doc);
let page = format!("0 1 0 0 setcmykcolor /Helvetica findfont 14 scalefont setfont {at} 61.5 moveto (Hi there) show");
let r = import(&eps(&page, &art)).unwrap();
assert_eq!(names(&r.document), ["Art"], "{align}: {:?}", r.warnings);
let texts: Vec<String> = text_of(&r.document.layers[0]).iter().map(|t| t.plain_text()).collect();
assert_eq!(texts, ["Hi there"], "{align}: {:?}", r.warnings);
assert!(!r.warnings.iter().any(|w| crate::is_loss(w)), "{align}: {:?}", r.warnings);
}
}
/// 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.)
#[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.
+1
View File
@@ -422,6 +422,7 @@ Stop opacity on translated artboards remains outside this regression coverage.
| Date | Change | Summary |
|---|---|---|
| 2026-11-26 | minor | `.ai` and EPS import: where the text document makes the type of every text object that shows, point type made from it is matched with the page's type where it draws. Made type has no layout when it is matched, and its box was the estimate of type without one (0.55 em a character, running right from its anchor): beside right-aligned type, over half of centered type, across vertical type, and too short for a wide font. The page's type there was counted as type with no text object, with the note "some of the page's type has no text object in the layers, so it is left out" (a loss, so `convert` wouldn't write over the file), and the made type went on to be weighed against the page as type the page may not draw, and could be taken out. The box of made point type that shows now comes from its layout in the fonts the import has; the text object keeps no layout, so the document measures it when it opens, as before. Files where some text object's type isn't made keep the estimate: there the page's pieces where made type draws can belong to text objects stacked on it. The page comparison takes the same box for the layers' type areas (`type_areas` in `compare.rs`): made point type that differs from the page (laid out again, or in another font) counts as type where it draws, whatever its alignment. Counted as art beside the estimate, it could send the file to its PDF part or page, or be noted as art that differs. A file whose layers failed the comparison that way and opened without it now passes it and shows its notes. Tests `right_aligned_and_centered_point_type_takes_the_pages_type_where_it_draws`, `centered_point_type_at_a_heading_s_size_takes_the_pages_type_where_it_draws` and `right_aligned_point_type_that_differs_from_the_page_differs_as_type` in `crates/eps/src/import/tests_native.rs`, and `made_point_type_s_box_is_where_its_alignment_and_orientation_draw_it` in `crates/eps/src/import/native/slots.rs`. Scores and estimates unchanged. |
| 2026-11-22 | minor | EPS import: type in a Type 1 or Type 42 font the file carries, whose family isn't available, is drawn in a TrueType font built from the glyphs the file shows (outlines and advances from the font program), kept with the document as PDF import keeps a PDF's (#4569), and spaced by those glyphs' own advances; once its text is edited it takes the fallback font. A string that draws a character with another glyph than the one kept for it comes in as outlines. The warning names those families with PDF import's words ("show as the file draws them, in the fonts it carries, until their text is edited"). Fonts the file only names, Type 3 fonts and type from an Illustrator editing copy are unchanged. Tests `embedded_type1_type_draws_with_the_files_glyphs`, `a_second_glyph_for_a_character_keeps_its_type_as_outlines`, `kept_type1_glyphs_survive_saving_and_go_when_the_text_is_edited`, `type_in_fonts_that_arent_available_is_named_in_a_warning` in `crates/eps/src/import/tests_type1.rs`, `type_in_a_carried_type42_font_draws_with_the_files_glyphs` in `crates/eps/src/import/tests_type42.rs`; scores unchanged |
| 2026-11-19 | minor | `.ai` import: a stroke's arrowheads were left out, so lines came in without their heads (#8188). A Stroke Style filter's stroke dictionary names each end's head as a symbol of the file (`/GObjRef : (name) /SymbolArt ; (BSArrowBeginSymbol)` or `(BSArrowEndSymbol)`), with its scale in percent (`BSArrowEndScale`, and `BSArrowBeginScale` read the same way; 100 without one). As the files have it, such a symbol's art (y down, as symbols are read) points right along a straight, level sample of the line: an open stroked path with no fill, which ends where the line stops under the head. The rest of the art that paints is the head, its tip its rightmost point, at one symbol unit a head weight (the stroke's weight at the scale). The head comes in as a custom arrowhead with that outline and that stop (a custom head now carries an optional stop, else its line ends halfway along it, as before). Its placement is the one of the two (tip on the end of the path, or Extend, the tip past it by the line's length under the head) that gives the object its drawn art's bounds; the user's file has every tip on its path's end. A stroke keeps its drawn look when neither placement gives those bounds (heads on other subpaths, say) or both do while a head moves 0.2 pt or more between them (a line whose end lies inside the bounds of its other segments), when its symbol isn't read whole or isn't read as a head (no sample or more than one, a sample that isn't 1 pt wide, as in art stored at a Large Canvas scale, art other than paths, compound paths and groups such as a clip group, a group with fills or strokes of its own, effects, brushes, partial opacity or an opacity mask), when its dictionary holds another `BSArrow` entry beside heads, when a scale is outside 1–1000 %, or when the head's weight would be under the 0.25 pt least one VectorCraft draws; a graphic style with such a stroke isn't read rather than read without its heads, and one with heads takes them on the end of the path, so an object whose heads are read past its ends isn't linked to its listed style. Measured on a user's file of ten arrows (used locally, never committed): every line gets its heads, and drawn at 4× its pixels match the file's own page but for 3 of 9,825 inked ones (0.24.1: 1,232 differ). Tests `a_strokes_arrowhead_symbols_are_its_arrowheads`, `a_strokes_start_arrowhead_points_back_and_keeps_its_side`, `a_stroke_takes_both_heads_at_their_own_scales`, `heads_drawn_past_the_path_extend_it`, `arrowheads_this_does_not_read_keep_the_drawn_look`, `an_arrowhead_entry_without_heads_leaves_the_stroke_read` in `crates/eps/src/import/ai/tests.rs`, `heads_whose_placement_the_drawn_bounds_leave_open_keep_the_drawn_look`, `a_head_that_stays_put_leaves_a_moving_heads_placement_open`, `a_style_library_reads_the_heads_of_symbols_defined_after_its_styles` in it, `a_symbol_entry_cut_short_leaves_the_next_style_read` and `a_comment_inside_a_symbol_entry_is_skipped` in `crates/eps/src/import/ai/style/tests.rs`, `partly_transparent_or_masked_art_makes_no_head` in `crates/eps/src/import/ai/arrowhead.rs`, fuzzed by `ai_arrowhead_strokes_never_panic`; scores unchanged |
| 2026-11-19 | minor | PDF import (#8549 follow-up): type filled and stroked after a page of type filled only came in as a filled object and a stroked one: since #8549 lines filled only are kept for a stroke pass too, and the glyphs of the lines finished past the 64 kept were remembered until the next stroke, so `2 Tr (Title) Tj` after more than 64 lines of type filled only took its first stroke for the start of a stroke pass over them, always once more than 4,096 glyphs had been finished so. Those glyphs are now forgotten when anything else is drawn (a path, an image, a Type 3 glyph's art, a change of blend mode or soft mask: nothing is drawn between an operator's fill pass and its stroke pass), and past the first 4,096 glyphs none are remembered instead of every stroke matching. A `TJ` over more lines than are kept still comes in as a filled object and a stroked one for each part, also when it ends where it began, and when a glyph kept as an outline comes before that (the line it starts keeps the glyphs of the lines finished). Remaining: with nothing drawn between them, type filled and stroked at exactly the place, font, size and text of a glyph filled only on a line finished so still comes in as a filled object and a stroked one, as the device can't tell its stroke pass from the start of one over that glyph. Tests: `type_filled_and_stroked_after_a_dense_page_of_filled_type_is_filled_and_stroked`, `type_filled_and_stroked_over_a_finished_glyph_after_a_path_is_filled_and_stroked`, `an_outline_glyph_in_a_tj_over_more_lines_than_are_kept_leaves_fill_and_stroke_apart`; scores and estimates unchanged. |