Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

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

aionggd2a6dd39a2d0
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<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> {