Integration: character fill swatch errors go through known_swatch (#403 × #520)

#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).
This commit is contained in:
aiongg
2026-10-12 04:17:15 +00:00
parent 8f1c60e4fc
commit d2a6dd39a2
2 changed files with 5 additions and 9 deletions
+1 -1
View File
@@ -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(());
}
+4 -8
View File
@@ -1297,16 +1297,12 @@ fn ruby_cmd(s: &mut Session, p: &Value) -> Result<Value> {
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<Value> {