mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 20:18:38 -05:00
.ai import: a text variable bound to its story binds the type
The variable library can name a text object by its story's XML id (AI11_StoryUID in the text object's /StoryDictionary) rather than the object's own AI10_ArtUID. The reader only remembered AI10_ArtUID, so such a binding found no object: the type came in unbound and the import noted the bindings as skipped. The story's id now names the slot of the story's first frame, the same way the object's id names the object; for a story also written on %_ lines, the plain copy's slot, which is the one the reader keeps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
38846fcdf3
commit
923f6bd7ee
4 files changed
+67
-2
No files matched your search
@@ -245,8 +245,9 @@ pub struct Structure {
|
||||
/// The data's symbols are at their own size, whatever its scale: VectorCraft wrote it (its
|
||||
/// `%%Creator` is [`crate::ai_editing::CREATOR_TEXT`]).
|
||||
pub symbols_own_size: bool,
|
||||
/// The objects by their XML id (`AI10_ArtUID`), a text object by its slot's id: `None` for an
|
||||
/// id two objects have.
|
||||
/// The objects by their XML id (`AI10_ArtUID`), a text object by its slot's id, and the slot of
|
||||
/// a story's first frame by the story's XML id (`AI11_StoryUID`): `None` for an id two objects
|
||||
/// have.
|
||||
pub xml_ids: HashMap<String, Option<NodeId>>,
|
||||
/// The objects the variable library binds to its variables, by their XML ids: the importer
|
||||
/// binds those it keeps.
|
||||
|
||||
@@ -111,7 +111,23 @@ impl<'a> Reader<'a> {
|
||||
n.knockout_shape = gs.knockout_shape;
|
||||
// An `Xy` before the text object was the object's, not its layer's, when the layer's `LB` follows.
|
||||
self.layer_state = None;
|
||||
// The story's XML id (`AI11_StoryUID` in its `/StoryDictionary`), which the variable
|
||||
// library's text variables bind it by, besides the object's own `AI10_ArtUID`: the first
|
||||
// frame's slot is the story's. A story written twice, plainly and on `%_` lines, keeps
|
||||
// the plain copy's slot, the one [`super::containers::drop_commented_copies`] keeps.
|
||||
let hidden = self.obj_hidden;
|
||||
if story.is_some()
|
||||
&& frame == 0
|
||||
&& let Some(uid) = o.obj("StoryDictionary").and_then(|d| d.obj("AI11_StoryUID")).and_then(Obj::content_text).filter(|u| !u.is_empty())
|
||||
{
|
||||
match self.xml_ids.get(&uid).copied().flatten() {
|
||||
Some(seen) if hidden && !self.hidden_ids.contains(&seen) => {}
|
||||
Some(seen) if !hidden && self.hidden_ids.contains(&seen) => {
|
||||
self.xml_ids.insert(uid, Some(n.id));
|
||||
}
|
||||
_ => super::remember_xml_id(&mut self.xml_ids, &mut self.xml_id_bytes, uid, n.id),
|
||||
}
|
||||
}
|
||||
self.add(n, hidden)
|
||||
}
|
||||
|
||||
|
||||
@@ -2240,6 +2240,53 @@ fn ai_variable_bindings_bind_the_objects_they_name() {
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("variable library")), "{:?}", r.warnings);
|
||||
}
|
||||
|
||||
/// A text variable bound to a story by the story's own XML id (`AI11_StoryUID` in the text object's
|
||||
/// `/StoryDictionary`, not the object's `AI10_ArtUID`) binds the type made from that story, also
|
||||
/// when the story is written twice, plainly and on `%_` lines, and leaves no note.
|
||||
#[test]
|
||||
fn a_text_variable_bound_to_its_story_binds_the_type() {
|
||||
use vectorcraft_testkit::ai::{XmlValue, named, variable_library_data, xml_element, xml_node};
|
||||
let declare = |name: &str, id: &str| {
|
||||
let docref = format!("/XMLUIDREF : ({id}) ;");
|
||||
let attributes = [("trait", XmlValue::Str("textcontent")), ("varName", XmlValue::Unicode(name)), ("docRef", XmlValue::Raw(&docref))];
|
||||
xml_node(1, "variable", XmlValue::Str(""), &attributes, &[])
|
||||
};
|
||||
let declared = vec![declare("v_name", "story_x5F_1"), declare("v_number", "story_x5F_2")];
|
||||
let set = xml_element("variableSet", &[("locked", "none")], &[xml_element("variables", &[], &declared)]);
|
||||
let library = variable_library_data(&xml_element("variableSets", &[], &[set]));
|
||||
let with_story = |story: u32, uid: &str| {
|
||||
text_object(story).replace(
|
||||
"2 /TextAntialiasing ,",
|
||||
&format!("/Dictionary :\n/XMLUID : ({uid}) ; (AI11_StoryUID) ,\n; /StoryDictionary ,\n2 /TextAntialiasing ,"),
|
||||
)
|
||||
};
|
||||
// Each story is also written on `%_` lines, before the plain copy for one and after it for the
|
||||
// other: the commented copy goes, and the story's id names the plain one.
|
||||
let commented = |text: String| text.lines().map(|l| format!("%_{l}\n")).collect::<String>();
|
||||
let spare = format!(
|
||||
"{}{}{}{}{}{}",
|
||||
commented(with_story(0, "story_x5F_1")),
|
||||
with_story(0, "story_x5F_1"),
|
||||
named("art_x5F_1"),
|
||||
with_story(1, "story_x5F_2"),
|
||||
named("art_x5F_2"),
|
||||
commented(with_story(1, "story_x5F_2"))
|
||||
);
|
||||
let doc = text_document(&[("Name\r", 0, (8200.0, 8180.0), (0.0, 0.0), 0.0), ("23\r", 0, (8200.0, 8150.0), (0.0, 0.0), 0.0)]);
|
||||
// A layer that shows and doesn't print, which the page doesn't draw: the type is made from the text document.
|
||||
let spare = layer("Spare", true, &spare).replace("1 1 1 1 0 0 1 0 79", "1 1 1 0 0 0 1 0 79");
|
||||
let art = native_with_text(&(library + &layer("Back", true, &square(10, 10)) + &spare), &doc);
|
||||
let r = import(&eps(&page_square(10, 10), &art)).unwrap();
|
||||
assert_eq!(names(&r.document), ["Back", "Spare"], "{:?}", r.warnings);
|
||||
let types: Vec<vectorcraft_doc::NodeId> =
|
||||
r.document.layers[1].children().unwrap().iter().filter(|n| matches!(n.kind, NodeKind::Text(_))).map(|n| n.id).collect();
|
||||
assert_eq!(types.len(), 2, "{:?}", r.warnings);
|
||||
let vars = &r.document.variables;
|
||||
assert_eq!(vars.objects_of("v_name"), [types[0]], "{:?}", r.warnings);
|
||||
assert_eq!(vars.objects_of("v_number"), [types[1]], "{:?}", r.warnings);
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("variable bindings")), "{:?}", r.warnings);
|
||||
}
|
||||
|
||||
/// An EPS whose editing data can't be used, a palette with no layers among others, comes in as its
|
||||
/// page with the swatches and color groups of that palette in place of the defaults.
|
||||
#[test]
|
||||
|
||||
@@ -425,6 +425,7 @@ Stop opacity on translated artboards remains outside this regression coverage.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-30 | minor | `.ai` and EPS import: a text variable bound to a story binds its type. The variable library can name a text object by its story's XML id (`AI11_StoryUID` in the text object's `/StoryDictionary`) instead of the object's own `AI10_ArtUID`; the reader kept only the latter, so such a binding found no object and the import noted it as skipped. The story's id now names the slot of its first frame (the plain copy's, for a story also written on `%_` lines), as the object's id names the object; test `a_text_variable_bound_to_its_story_binds_the_type`. In 3 users' files (used locally, never committed) both text variables of each file bind and the note goes; in 2 of them the bound type is in an envelope, which now keeps its drawn art, as type in an envelope bound to a text variable already did. |
|
||||
| 2026-11-30 | minor | `.ai` and EPS import: a word the page draws from two text objects in a row is their type. Where the text document makes the type of every text object that shows, a word of the page's type is the type of the made type holding its piece when that type spells it. The page can draw two text objects as one word: a word and a letter set apart from it (a swash "h" after "Spirit") come out of the page as one piece, "Spirith", that neither spells. It 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), though both text objects come in and draw it. Now a word left that is the last word of one text object holding the piece joined to the first word of another holding it that draws after it, along the first one's lines, is theirs (`joined_by_two` in `see_page_type`). Each part is a whole word of its text object, and the two the other way round don't make the word. Tests: `a_word_the_page_draws_from_two_text_objects_in_a_row_is_their_type`, `two_text_objects_the_other_way_round_arent_the_word_the_page_draws`. |
|
||||
| 2026-11-27 | minor | `.ai` save: type in a spot ink, a global process colour or Registration keeps its swatch link and its tint. Its fill and stroke in the text document name (key 5 of the paint) an art style of one paint, `0 1 Xd`, whose paint is the colour as a path's fill writes it (`x`, `Xx`, `Xk`, `Xs`), the form `.ai` import reads since the change below; key 0 still holds the process values at the tint. Each style is read back before it is written and kept only when the reader gives the same swatch and tint, so such type no longer counts among the attributes of type left out; a link to a process swatch that isn't global still does. Test `ai_editing::tests::type_in_spot_and_global_colors_reads_back_linked_at_its_tint` |
|
||||
| 2026-11-27 | minor | `.ai` and EPS import: type set in a spot ink or a global process colour keeps its ink. In the text document a character's fill or stroke is a colour (key 0: grey, RGB or CMYK) and the name of an art style (key 5). In users' files (used locally, never committed) that style is one paint (`/SimpleStyle`), always its fill's, for a stroke too; for a spot ink or a global process colour it is `c m y k (name) tint x`, `Xx` or `Xk`, and key 0 keeps only the ink's process values at that tint. Such type came in as that process colour, so it separated onto the process plates, and white type in a white ink onto none. It now takes the style's paint: the colour at its tint, linked to the document's swatch of that name, which the style's colour makes when the art doesn't (after the art's colours, before the header's custom colours). A style whose paint is a process colour or a gradient, one that also sets a stroke's colour or pattern (before or after the fill's) or another fill paint after it, one whose `Xd` doesn't turn on its fill alone, and a paint that names no style of the file, keep the colour of key 0 as before; type filled with a gradient still comes in black. Tests `type_set_in_a_spot_ink_takes_it_from_the_art_style_its_paint_names` in `crates/eps/src/import/tests_native.rs`, `a_run_painted_by_a_swatch_colours_art_style_takes_the_swatch` in `crates/eps/src/import/ate.rs` and `only_a_style_of_one_swatch_colour_holds_it_for_type` in `crates/eps/src/import/ai/style/tests.rs`. Scores and estimates unchanged. |
|
||||
|
||||
Reference in new issue
Block a user