Merge pull request #10698 from dotCooCoo/fix/script-text-spot-color

Scripts: a text color assigned in a CMYK document is compared as the document stores it
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-03 08:47:10 -08:00
commit dbacda04ee
4 files changed
+54 -5

No files matched your search

+13 -4
View File
@@ -1026,8 +1026,16 @@ fn stroke_scale(t: &TextObject) -> f64 {
vectorcraft_doc::Scaling::factor(t.xf).filter(|k| k.is_finite() && *k > 1e-12).unwrap_or(1.0)
}
/// The `text.setRangeStyle` parameter for `attr` set to `v`, and the value it reads as after.
fn attr_param(h: &Host, attr: Attr, name: &str, v: &Data, first: (&TextObject, &CharStyle, usize)) -> std::result::Result<(Value, Data), HostError> {
/// The `text.setRangeStyle` parameter for `attr` set to `v`, and the value it reads as after in
/// the document `doc` (a color as given when there is none).
fn attr_param(
h: &Host,
attr: Attr,
name: &str,
v: &Data,
first: (&TextObject, &CharStyle, usize),
doc: Option<&vectorcraft_doc::Document>,
) -> std::result::Result<(Value, Data), HostError> {
let finite = || number(v, name);
Ok(match attr {
Attr::Size => {
@@ -1096,8 +1104,9 @@ fn attr_param(h: &Host, attr: Attr, name: &str, v: &Data, first: (&TextObject, &
}
Attr::FillColor | Attr::StrokeColor => {
let color = colors::assigned(v, name)?;
let paint = color.map_or(Paint::None, Paint::solid);
let given = color.map_or_else(|| json!("none"), |c| colors::param(&c));
// The paint reads back as the text's document stores it: an RGB color in a CMYK document as CMYK.
let paint = color.map_or(Paint::None, |c| Paint::solid(doc.map_or(c, |d| crate::cmd::newart::stored_color_in(d, c))));
let key = if matches!(attr, Attr::FillColor) { "fill" } else { "stroke" };
(json!({ key: given }), colors::of_paint(&paint))
}
@@ -1138,7 +1147,7 @@ fn write_attr(h: &Host, a: &[Data], attr: Attr, name: &str) -> Answer {
let t = text_of(st, r.item.id).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?;
let styles = styles_in(t, ba, bb, false)?;
let first = styles.first().map(|(s, p)| (s.clone(), *p)).unwrap_or_else(|| (CharStyle::default(), 0));
let (param, wants) = attr_param(h, attr, name, arg(a, 1), (t, &first.0, first.1))?;
let (param, wants) = attr_param(h, attr, name, arg(a, 1), (t, &first.0, first.1), Some(&st.doc))?;
// A leading set on characters with auto leading fixes it even where auto gives that value.
let has = |st: &CharStyle, p: usize| (!matches!(attr, Attr::Leading) || st.leading.is_some()) && same(&attr_value(h, attr, t, st, p), &wants);
// An empty range changes nothing, also one inside a character that `ba..bb` widens to it.
+1 -1
View File
@@ -471,7 +471,7 @@ fn write_char(h: &Host, a: &[Data], attr: Attr, name: &str) -> Answer {
let leading = old.get("leading").and_then(Value::as_f64);
let sample = CharStyle { size, leading, ..base };
let t = TextObject::point(Point::default(), "", sample.clone());
let (param, _) = attr_param(h, attr, name, arg(a, 1), (&t, &sample, 0))?;
let (param, _) = attr_param(h, attr, name, arg(a, 1), (&t, &sample, 0), None)?;
let mut attrs = old.clone();
for (k, v) in param.as_object().into_iter().flatten() {
let Some((_, key)) = CHAR_KEYS.iter().find(|(p, _)| *p == k.as_str()) else { continue };