Object styles: the paragraph style and text frame parameter helpers in main's split module; Object Styles in the styles icon family

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
moppeeerandClaude Opus 5.5 committed 2026-10-30 15:31:56 +01:00
1 parent 1fe2e6b7e5
commit 2ea8aa6739
3 files changed
+33 -2

No files matched your search

+31
View File
@@ -159,6 +159,37 @@ pub(super) fn create_object(s: &mut Session, p: &Value) -> Result<Value> {
})
}
/// `paragraphStyle`: a paragraph style's name, or null (the object style sets none).
fn paragraph_style_param(cmd: &str, s: &Session, p: &Value) -> Result<Option<Option<String>>> {
match p.get("paragraphStyle") {
None => Ok(None),
Some(Value::Null) => Ok(Some(None)),
Some(Value::String(n)) if s.doc()?.doc.styles.para(n).is_some() => Ok(Some(Some(n.clone()))),
Some(Value::String(n)) => Err(bad(cmd, format!("no paragraph style `{n}`"))),
Some(_) => Err(bad(cmd, "`paragraphStyle` must be a paragraph style's name or null")),
}
}
/// `textFrame` (a text frame's options, as `document.inspect` shows them) merged over `base`, or
/// null; refused when the columns aren't 1–40 or a gutter, width or inset isn't 0–15552 pt.
fn text_frame_param(
cmd: &str,
p: &Value,
base: Option<&designcraft_doc::TextFrameOptions>,
) -> Result<Option<Option<designcraft_doc::TextFrameOptions>>> {
let tf = group_param(cmd, p, "textFrame", base.unwrap_or(&designcraft_doc::TextFrameOptions::default()))?;
if let Some(Some(o)) = &tf {
if !(1..=40).contains(&o.columns) {
return Err(bad(cmd, "text frame columns must be 1–40"));
}
let mut lengths = [o.gutter, o.column_width, o.vj_paragraph_spacing_limit, o.first_baseline_min].into_iter().chain(o.inset);
if !lengths.all(|v| v.is_finite() && (0.0..=15552.0).contains(&v)) {
return Err(bad(cmd, "a text frame's gutter, widths and insets must be 0–15552 pt"));
}
}
Ok(tf)
}
/// A true/false parameter, when given.
fn bool_param(cmd: &str, p: &Value, key: &str) -> Result<Option<bool>> {
match p.get(key) {
+1 -1
View File
@@ -114,7 +114,7 @@ impl Placed {
const ICON_GROUPS: &[&[&str]] = &[
&["stroke", "color", "swatches", "gradient"],
&["effects"],
&["characterStyles", "paragraphStyles"],
&["characterStyles", "paragraphStyles", "objectStyles"],
&["character", "paragraph", "typography"],
&["glyphs", "story"],
&["table"],
+1 -1
View File
@@ -881,7 +881,7 @@ fn placed_panels_leave_their_icon_groups() {
let column = icon_column(None, &mut placed).unwrap();
let groups: Vec<Vec<&str>> = column.groups.iter().map(|g| g.panels.iter().map(String::as_str).collect()).collect();
assert_eq!(groups.first().unwrap(), &["stroke", "color", "gradient"]);
assert_eq!(groups.get(1).unwrap(), &["characterStyles", "paragraphStyles"]);
assert_eq!(groups.get(1).unwrap(), &["characterStyles", "paragraphStyles", "objectStyles"]);
assert_eq!(groups.len(), ICON_GROUPS.len() - 1);
}