From d2a6dd39a2d0418d93ce725d76381ba977e6341c Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 12 Oct 2026 04:17:15 +0000 Subject: [PATCH] =?UTF-8?q?Integration:=20character=20fill=20swatch=20erro?= =?UTF-8?q?rs=20go=20through=20known=5Fswatch=20(#403=20=C3=97=20#520)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #403 added validate_char_fill with its own message; #520 added known_swatch for object fills and strokes, which also suggests the intended name. validate_char_fill now calls known_swatch with key "fill", so one error path covers both. #403's tests still pass (the message names the fill, swatch.create and the returned name). --- crates/engine/src/cmd/object.rs | 2 +- crates/engine/src/cmd/text.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rs index 3ea23f01d..a9c9b75db 100644 --- a/crates/engine/src/cmd/object.rs +++ b/crates/engine/src/cmd/object.rs @@ -17,7 +17,7 @@ use crate::{Result, Session}; /// `name` must be a swatch of the document: an unknown name would paint nothing. The error names /// the swatch it was probably meant to be (`Paper` → `[Paper]`, a different case). -fn known_swatch(doc: &designcraft_doc::Document, name: &str, cmd: &str, key: &str) -> Result<()> { +pub(crate) fn known_swatch(doc: &designcraft_doc::Document, name: &str, cmd: &str, key: &str) -> Result<()> { if doc.swatch(name).is_some() { return Ok(()); } diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs index 54ae8631f..b1214c452 100644 --- a/crates/engine/src/cmd/text.rs +++ b/crates/engine/src/cmd/text.rs @@ -1297,16 +1297,12 @@ fn ruby_cmd(s: &mut Session, p: &Value) -> Result { format_chars(s, &Value::Object(body)) } +/// A character fill must name a swatch of the document. pub(crate) fn validate_char_fill(document: &designcraft_doc::Document, attrs: &CharAttrs, command_id: &str) -> Result<()> { - if let Some(fill) = &attrs.fill - && document.swatch(fill).is_none() - { - return Err(bad( - command_id, - format!("unknown character fill `{fill}`; create a swatch with `swatch.create` and use its returned name as `fill`"), - )); + match &attrs.fill { + Some(fill) => super::object::known_swatch(document, fill, command_id, "fill"), + None => Ok(()), } - Ok(()) } pub(crate) fn format_chars(s: &mut Session, attrs: &Value) -> Result {