From b8e11fb2c75a91fed6534d583e0d51210dbe2c1b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 16:00:35 -0800 Subject: [PATCH] Place: a placed dimension reuses an equal composite font of the same name When the document defined a composite font with the same name and the same definition as one a placed dimension used, but spelled in more than the 256 bytes a dimension's family keeps (a case-insensitive match such as Kelvin signs for k), placement copied the incoming font under a new name instead of reusing the document's. The byte limit now applies only to an alias under another name; a same-name reuse keeps the dimension's own spelling. Merging main had also left a second, unguarded rename of a dimension's family next to the guarded one, so a renamed family that was too long or only differed in case was still written. The unguarded rename is removed. docs/mcp.md describes how file.place renames a placed dimension's family. --- crates/engine/src/cmd/compositefonts.rs | 13 +++----- .../engine/tests/native_composite_adoption.rs | 33 +++++++++++++++++++ docs/mcp.md | 2 ++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/compositefonts.rs b/crates/engine/src/cmd/compositefonts.rs index 35e47de772..3b15730f9a 100644 --- a/crates/engine/src/cmd/compositefonts.rs +++ b/crates/engine/src/cmd/compositefonts.rs @@ -155,10 +155,6 @@ pub(super) fn node_families(node: &mut Node, visit: &mut impl FnMut(&mut String) visit(&mut font.family); } } - // A live dimension makes its label again from its options. - if let Some(dimension) = node.extras_if_any().and_then(|extras| extras.dimension.as_deref_mut()) { - visit(&mut dimension.options.font_family); - } // A dimension redraws its label from its own options, so they follow the label's family. // A spelling that already names the same font, or one too long for the options, is kept. if let Some(dimension) = node.extras_if_any().and_then(|extras| extras.dimension.as_mut()) { @@ -267,13 +263,14 @@ pub(super) fn plan_import( let mut combined = target.composite_fonts.to_vec(); for font in source { let dimension = dimension_families.contains(&font.name.to_lowercase()); - let equivalent = - |other: &&CompositeFont| other.parts == font.parts && other.custom == font.custom && (!dimension || other.name.len() <= ALIAS_BYTES_MAX); - let mut reused = CompositeFont::named(&target.composite_fonts, &font.name).filter(equivalent); + let equal = |other: &&CompositeFont| other.parts == font.parts && other.custom == font.custom; + // A dimension keeps its own spelling of a reused name of the same font, so only an alias + // under another name has to fit the bytes its options keep. + let mut reused = CompositeFont::named(&target.composite_fonts, &font.name).filter(equal); let needs_alias = reused.is_none() && (target_taken.contains(&font.name.to_lowercase()) || db.has_installed_family(&font.name)); if needs_alias { // A repeated import reuses its already-installed equal alias. - reused = target.composite_fonts.iter().find(equivalent); + reused = target.composite_fonts.iter().find(|other| equal(other) && (!dimension || other.name.len() <= ALIAS_BYTES_MAX)); } let name = match reused { Some(other) => other.name.clone(), diff --git a/crates/engine/tests/native_composite_adoption.rs b/crates/engine/tests/native_composite_adoption.rs index 38f32cd1eb..d6eee8153c 100644 --- a/crates/engine/tests/native_composite_adoption.rs +++ b/crates/engine/tests/native_composite_adoption.rs @@ -186,6 +186,39 @@ fn assert_dimension_alias(path: &Path, name: &str) { } } +#[test] +fn native_dimension_reuses_an_equal_same_named_composite_font_with_a_longer_spelling() { + let _context = FontContext::hold(); + let dir = TempDir::new("native-composite-dimension-same-name"); + let path = dir.join("dimension.vectorcraft"); + // 86 ASCII letters are 86 bytes; 86 Kelvin signs are the same name in any case and 258 bytes. + let incoming = CompositeFont::new("k".repeat(86), "Source Sans 3", "Regular"); + let mut source = destination(std::slice::from_ref(&incoming)); + let options = json!({"fontFamily": incoming.name, "fontStyle": "Regular"}); + source.execute("dimension.create", &json!({"a": [4, 20], "b": [60, 20], "options": options})).unwrap(); + let source_doc = document(&source).clone(); + source.execute("type.compositeFonts.set", &json!({"fonts": []})).unwrap(); + write_native(&path, &source_doc); + let mut existing = incoming.clone(); + existing.name = "\u{212A}".repeat(86); + assert!(existing.name.len() > 256, "CONTROL: the destination's spelling is longer than a dimension's family keeps"); + assert!(CompositeFont::same_name(&existing.name, &incoming.name), "CONTROL: the two spellings are one name"); + for linked in [false, true] { + let mut session = destination(std::slice::from_ref(&existing)); + let id = place(&mut session, &path, linked); + assert_eq!( + document(&session).composite_fonts.len(), + 1, + "REGRESSION: an equal composite font of the same name is reused, not copied under a new name" + ); + let mut stored = Vec::new(); + document(&session).node(id).unwrap().walk(&mut |node| { + stored.extend(node.extras().dimension.as_ref().map(|d| d.options.font_family.clone())); + }); + assert_eq!(stored, vec![incoming.name.clone()], "REGRESSION: the dimension keeps its own spelling of the reused name"); + } +} + #[test] fn native_composite_alias_skips_a_family_named_by_a_dimension_in_brush_art() { let _context = FontContext::hold(); diff --git a/docs/mcp.md b/docs/mcp.md index 76d0797f83..3a9f3c75db 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -11790,6 +11790,8 @@ with `link: false` or from `dataBase64` it is one group. `at` centres it, `rect` swaps the selected object (keeping its place and transform), `template` puts it on a new template layer. When placed editable art names a font family it does not define as a composite font, and the document defines a composite font of that name, the placed type gets a free name such as "Name 2" so it keeps the font it was laid out in. +A placed live dimension's label options take the same new name, so a redrawn label keeps that font; a document +composite font with the same name and the same definition is reused, and the dimension keeps its own spelling of it. A DCS file (Desktop Color Separation, version 1.0 or 2.0: an EPS file whose header names one EPS program per printing plate, ) is placed only from its `path` with link, as one linked image ([Import DCS files](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/import-dcs-files.html)).