Stroke: the text Weight field keeps its value between 0 and 800 pt (#2808)

* Stroke: the text Weight field keeps its value between 0 and 800 pt

With text selected, the Stroke panel's Weight field sent the typed value
to type.char unchanged, so 2000 or -5 became the text's stroke weight.
The object Weight field keeps its value between 0 and 1000 pt. The text
field now keeps its value between 0 and 800 pt, the range of the
character style's Weight field.

* Properties: the text stroke Weight field keeps 0 to 800 pt

The Properties panel's text stroke Weight field capped typed values at
100 pt while the Stroke panel's text Weight field and the character
style's Weight field allow up to 800 pt. It now uses the same 0 to 800 pt
range.
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-15 05:03:55 +00:00
1 parent 85aae4499d
commit 0461ef4f5e
3 files changed
+63 -2

No files matched your search

@@ -147,7 +147,8 @@ fn text_stroke_panel(app: &mut DesignApp, ui: &mut egui::Ui, c: &Value) {
egui::Grid::new("text_stroke_panel").num_columns(2).spacing(vec2(8.0, 6.0)).show(ui, |ui| {
caption(ui, crate::i18n::tr(&app.ui.language, "Weight:"));
if let Some(v) = number(ui, "tsw_panel", c["strokeWeight"].as_f64(), " pt", 60.0, 3) {
let _ = app.run("type.char", json!({"attrs": {"strokeWeight": v}}));
// The character stroke weight's range, as the character style's Weight field has it.
let _ = app.run("type.char", json!({"attrs": {"strokeWeight": v.clamp(0.0, 800.0)}}));
}
ui.end_row();
caption(ui, crate::i18n::tr(&app.ui.language, "Color:"));
@@ -135,6 +135,66 @@ fn stroke_panel_shows_the_text_stroke_options_while_text_is_selected() {
h.get_by_label("Stroke Behind Fill");
}
/// The text Stroke panel's Weight keeps a typed value inside the character stroke weight's
/// range of 0 to 800 pt, as the character style's Weight field does.
#[test]
fn text_stroke_panel_keeps_the_weight_in_range() {
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "text": "Hello", "caret": true})).unwrap();
app.run("edit.selectAll", json!({})).unwrap();
let mut ready = false;
let mut h = Harness::builder().with_size(vec2(320.0, 400.0)).build_ui_state(
move |ui, app: &mut DesignApp| {
if !ready {
crate::theme::install_fonts(ui.ctx(), "");
crate::theme::apply(ui.ctx(), &Tokens::for_brightness(Default::default()));
ready = true;
return;
}
stroke_panel(app, ui);
},
app,
);
h.run_steps(3);
let weight = |h: &mut Harness<'_, DesignApp>| crate::panels::text_attrs(h.state_mut()).unwrap()["chars"]["strokeWeight"].as_f64();
for (typed, expected) in [("2000", 800.0), ("12", 12.0), ("-5", 0.0)] {
let field = h.get_all_by_role(egui::accesskit::Role::TextInput).next().unwrap().rect();
type_in_field(&mut h, field, typed);
assert_eq!(weight(&mut h), Some(expected), "{typed}");
}
}
/// The Properties panel's text stroke Weight keeps a typed value inside the same 0 to 800 pt
/// range as the Stroke panel and the character style's Weight field.
#[test]
fn properties_text_stroke_weight_keeps_the_character_range() {
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "text": "Hello", "caret": true})).unwrap();
app.run("edit.selectAll", json!({})).unwrap();
let mut ready = false;
let mut h = Harness::builder().with_size(vec2(320.0, 400.0)).build_ui_state(
move |ui, app: &mut DesignApp| {
if !ready {
crate::theme::install_fonts(ui.ctx(), "");
crate::theme::apply(ui.ctx(), &Tokens::for_brightness(Default::default()));
ready = true;
return;
}
super::text::text_appearance_section(app, ui);
},
app,
);
h.run_steps(3);
let weight = |h: &mut Harness<'_, DesignApp>| crate::panels::text_attrs(h.state_mut()).unwrap()["chars"]["strokeWeight"].as_f64();
for (typed, expected) in [("500", 500.0), ("2000", 800.0), ("-5", 0.0)] {
let field = h.get_all_by_role(egui::accesskit::Role::TextInput).next().unwrap().rect();
type_in_field(&mut h, field, typed);
assert_eq!(weight(&mut h), Some(expected), "{typed}");
}
}
/// As InDesign's: Edit Page takes the Page tool to the page in view, and Properties sets that
/// page alone; Back returns to the document.
#[test]
+1 -1
View File
@@ -148,7 +148,7 @@ pub(super) fn text_appearance_section(app: &mut DesignApp, ui: &mut Ui) {
}
const WEIGHTS: &[f64] = &[0.0, 0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0];
if let Some(v) = place(ui, sub(b, 96.0, 0.0, 69.0, FIELD_H), |ui| {
NumField::points("tsw", c["strokeWeight"].as_f64(), 3).width(69.0).spinner().presets(WEIGHTS).range(0.0, 100.0).show(ui)
NumField::points("tsw", c["strokeWeight"].as_f64(), 3).width(69.0).spinner().presets(WEIGHTS).range(0.0, 800.0).show(ui)
}) {
let _ = app.run("type.char", json!({"attrs": {"strokeWeight": v}}));
}