diff --git a/crates/ui-egui/src/panels/type_panels_ui/style_options.rs b/crates/ui-egui/src/panels/type_panels_ui/style_options.rs index 255a6aeddb..c69fdf91fc 100644 --- a/crates/ui-egui/src/panels/type_panels_ui/style_options.rs +++ b/crates/ui-egui/src/panels/type_panels_ui/style_options.rs @@ -7,7 +7,7 @@ use craft::text::ui::character::{ StyleOptionValues, StyleOptionsChange, TextAlign, TextStyleOptions, }; use craft::theme::Rgba; -use photocraft_doc::text::{CharStyle, ParagraphStyle}; +use photocraft_doc::text::{CharStyle, Digits, ParagraphStyle}; use serde_json::{Value, json}; use super::{color_picker, run}; @@ -157,10 +157,29 @@ pub(crate) fn character_values(style: &CharStyle) -> CharacterValues { values.strikethrough = Some(style.strikethrough); values.opentype = opentype; values.language = style.language.clone(); + values.digits = Some(digit_name(style.digits).to_string()); values } /// The values the Paragraph controls show for `style`. +/// The engine's `digits` name of a digit style. +pub(crate) fn digit_name(d: Digits) -> &'static str { + match d { + Digits::AsTyped => "asTyped", + Digits::Western => "western", + Digits::Contextual => "contextual", + Digits::Devanagari => "devanagari", + Digits::Bengali => "bengali", + Digits::Gurmukhi => "gurmukhi", + Digits::Gujarati => "gujarati", + Digits::Odia => "odia", + Digits::Tamil => "tamil", + Digits::Telugu => "telugu", + Digits::Kannada => "kannada", + Digits::Malayalam => "malayalam", + } +} + pub(crate) fn paragraph_values(style: &ParagraphStyle) -> ParagraphValues { use photocraft_doc::text::TextDirection as D; let mut values = ParagraphValues::default(); diff --git a/crates/ui-egui/src/tools/type_tool/character_panel_digits_tests.rs b/crates/ui-egui/src/tools/type_tool/character_panel_digits_tests.rs new file mode 100644 index 0000000000..1e35edee68 --- /dev/null +++ b/crates/ui-egui/src/tools/type_tool/character_panel_digits_tests.rs @@ -0,0 +1,68 @@ +//! The Character panel's Digits select (#10996): it shows the selected layer's digit style, and a pick restyles the +//! selected type layer's digits through the type command, in one history step. + +use egui::accesskit::Role; +use egui::vec2; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use photocraft_doc::LayerId; +use photocraft_doc::text::Digits; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::app::framework::BuildApp; + +const SELECT: &str = "Digits"; + +/// One selected type layer with digits in its text. +fn one_layer() -> (Box, LayerId) { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600})).unwrap(); + app.sync_views(); + app.ui.tool = crate::state::Tool::Type; + let made = app.run("type.create", json!({"text": "Room 42", "font": "Inter", "size": 24, "x": 40, "y": 80})).unwrap(); + let id = LayerId(made["layer"].as_u64().unwrap()); + app.run("layer.select", json!({"layer": id.0, "mode": "replace"})).unwrap(); + (app, id) +} + +fn harness(app: Box) -> Harness<'static, Box> { + // Wait for the font scan: while it runs the panels repaint every 100 ms and `Harness::run` gives up. + let _ = photocraft_text::shared(); + let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(vec2(760.0, 1200.0)).with_max_steps(16).build_app( + move |ui, app: &mut PhotocraftApp| { + ui.set_width(340.0); + super::character_panel(app, ui, false); + }, + app, + ); + h.run_steps(4); + h +} + +fn digits(app: &PhotocraftApp, id: LayerId) -> Vec { + let text = super::super::text_layer(&app.session.active().unwrap().doc, id).unwrap(); + text.char_runs().into_iter().map(|r| r.style.digits).collect() +} + +fn shown(h: &Harness<'static, Box>) -> String { + h.get_by_role_and_label(Role::ComboBox, SELECT).value().unwrap_or_default() +} + +#[test] +fn a_digits_pick_restyles_the_selected_layer_in_one_history_step() { + let (app, id) = one_layer(); + let before = digits(&app, id); + let steps = app.session.active().unwrap().history.entries().len(); + let mut h = harness(app); + let was = shown(&h); + h.get_by_role_and_label(Role::ComboBox, SELECT).click(); + h.run(); + h.get_by_role_and_label(Role::ListBoxOption, "Devanagari").click(); + h.run(); + let after = digits(h.state(), id); + assert_ne!(after, before, "the pick changed the layer's digits"); + assert!(after.iter().all(|d| *d == Digits::Devanagari), "every run takes the picked style: {after:?}"); + assert_eq!(h.state().session.active().unwrap().history.entries().len(), steps + 1, "one history step"); + assert_ne!(shown(&h), was, "the select shows the new style"); +} diff --git a/crates/ui-egui/src/tools/type_tool/panel.rs b/crates/ui-egui/src/tools/type_tool/panel.rs index e9eb1a7d1f..32cb870607 100644 --- a/crates/ui-egui/src/tools/type_tool/panel.rs +++ b/crates/ui-egui/src/tools/type_tool/panel.rs @@ -78,7 +78,8 @@ fn character_controls(app: &mut PhotocraftApp, ui: &mut egui::Ui, unit: DocUnit, let styles = values::style_names(app, &shown); let face = values::face_axes(app); let mut font_state = fonts::font_state(app); - let mut controls = CharacterControls::new(tl!("Character"), &shown, &families, &styles).unit(unit); + let digits = values::digit_entries(); + let mut controls = CharacterControls::new(tl!("Character"), &shown, &families, &styles).unit(unit).digits(&digits); controls = controls.font_picker(font_state.source()); if let Some(face) = &face { controls = controls.axes(face.view()); @@ -147,6 +148,10 @@ fn type_options(app: &mut PhotocraftApp, ui: &mut egui::Ui) { }); } +#[cfg(test)] +#[path = "character_panel_digits_tests.rs"] +mod character_panel_digits_tests; + #[cfg(test)] #[path = "character_panel_anti_alias_tests.rs"] mod character_panel_anti_alias_tests; diff --git a/crates/ui-egui/src/tools/type_tool/values.rs b/crates/ui-egui/src/tools/type_tool/values.rs index c9bdb4fe9e..6653f9db7d 100644 --- a/crates/ui-egui/src/tools/type_tool/values.rs +++ b/crates/ui-egui/src/tools/type_tool/values.rs @@ -16,14 +16,14 @@ use craft::text::ui::character::{ use craft::text::ui::type_bar::TypeBarChange; use craft::text::ui::type_options::{TextAntiAlias, TextOrientation}; use craft::ui::runtime::env::UnitKind; -use photocraft_doc::text::{CharStyle, ParagraphStyle}; +use photocraft_doc::text::{CharStyle, Digits, ParagraphStyle}; use super::defaults::{apply, default_styles, formatting_params, open_color_picker, shown_scale, target, target_doc, target_text}; use super::fonts; use super::options_bar::{kerning_at, styles_at}; use super::panel::{OPENTYPE_BUTTONS, toggle_opentype}; use super::{LayerId, PhotocraftApp, byte_of, json, text_layer}; -use crate::panels::type_panels_ui::style_options::{character_values as style_character_values, paragraph_values as style_paragraph_values}; +use crate::panels::type_panels_ui::style_options::{character_values as style_character_values, digit_name, paragraph_values as style_paragraph_values}; /// The unit the type controls show lengths in (Preferences ▸ Units & Rulers ▸ Type); pixels follow the document's /// resolution. Values stay in points. @@ -93,6 +93,27 @@ fn runs_at_target(app: &PhotocraftApp) -> Option<(Vec, Vec Vec<(String, String)> { + [ + (Digits::AsTyped, tl!("As Typed")), + (Digits::Western, tl!("Western")), + (Digits::Contextual, tl!("Contextual")), + (Digits::Devanagari, tl!("Devanagari")), + (Digits::Bengali, tl!("Bengali")), + (Digits::Gurmukhi, tl!("Gurmukhi")), + (Digits::Gujarati, tl!("Gujarati")), + (Digits::Odia, tl!("Odia")), + (Digits::Tamil, tl!("Tamil")), + (Digits::Telugu, tl!("Telugu")), + (Digits::Kannada, tl!("Kannada")), + (Digits::Malayalam, tl!("Malayalam")), + ] + .into_iter() + .map(|(d, label)| (digit_name(d).to_string(), label.to_string())) + .collect() +} + /// The character values at the target: equal values shown, differing ones mixed. Sizes show as the layer appears /// (a 12 pt layer scaled 200 % reads 24 pt). pub(crate) fn character_values(app: &PhotocraftApp) -> CharacterValues { @@ -305,6 +326,7 @@ fn character_step(change: &CharacterChange) -> Option { CharacterChange::Strikethrough(on) => json!({"strikethrough": on}), CharacterChange::OpenType { tag, on, .. } => return Some(Step::OpenType { tag, on: *on }), CharacterChange::Language(tag) => json!({"language": tag}), + CharacterChange::Digits(tag) => json!({"digits": tag}), CharacterChange::Axes(axes) => { let map: serde_json::Map = axes.iter().map(|(tag, v)| (String::from_utf8_lossy(tag).trim().to_string(), json!(v))).collect(); diff --git a/docs/scorecard.md b/docs/scorecard.md index e984cf914e..4579ee1b59 100644 --- a/docs/scorecard.md +++ b/docs/scorecard.md @@ -261,7 +261,7 @@ Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace. | TYPE-218-8 | Text editing: select all, double/triple/quadruple-click selection, paste, with tests | done | [#218](https://github.com/storytold/photocraft/issues/218) | Like Photoshop, 2 clicks select the word, 3 the laid-out line (a column in vertical type), 4 the paragraph up to the hard return, 5 all text, and the next quick click starts over (#3493; type_tool.rs next_click_count, click_selection, multi_click). Tested through real canvas clicks in point, paragraph and vertical type, with paste replacing the selection and Cmd+A selecting all (type_tool_tests.rs multi_click_selects_word_line_paragraph_and_all_in_point_text, multi_click_separates_wrapped_lines_from_paragraphs, click_counts_cycle_and_restart, click_selection_without_layout_and_on_hostile_input, multi_click_without_a_session_does_nothing) | | TYPE-218-9 | Distort/Perspective/Warp on live type as in Photoshop (was: offer 'Rasterize and continue?'; Photoshop doesn't prompt) | done | [#218](https://github.com/storytold/photocraft/issues/218) | Photoshop 2026 prompts for none of these: Edit › Transform › Warp on live type stays enabled with no rasterize prompt and offers only the warp styles (the mesh can't be dragged), so the type stays editable; Distort, Perspective and the split warps are greyed. PhotoCraft does the same: Warp on type commits the layer's Warp Text in one step (transform_tool.rs enter_type_warp, warp_cmds.rs warp_type_layer, #3004; warp_on_type_takes_a_style_and_keeps_the_type_editable), Distort/Perspective greyed (enable_rules.rs, #2701) | | TYPE-218-10 | Area type: Type tool click inside a closed path or shape wraps text inside it, holes and dents included, PSD round trip | partial | [#218](https://github.com/storytold/photocraft/issues/218) | TextShape::Area (doc text.rs) laid out line by line into the spans the path leaves (text area.rs, layout.rs break_area), type.fillPath (engine type_area_cmds.rs), released to box text by type.detachFromPath, area/path cursors and click-to-place (ui-egui type_tool.rs path_target), .pcraft round trip. Missing: PSD area type (saves as paragraph text over the path's bounds, with an export warning); mixed type sizes in one area paragraph space at its largest line; area type takes paths of at most 4096 anchors: beyond that a Type tool click makes point text (the pointer shows the plain I-beam), and type.fillPath refuses the path with "the path has too many anchor points" (type.attachToPath still takes a subpath of up to 100,000 anchors); a word too wide for every span in the shape overflows its span (box text breaks it at the edge, #6694); the first line starts about 0.24 em lower than in a text box of the same size; Photoshop area type in a PSD opens as box text; the area path has no handles to edit it after the type is placed | -| TYPE-10996-1 | Digit style: digits drawn as typed, Western, by the script of the letters before them, or in an Indic script (Devanagari, Bengali, Gurmukhi, Gujarati, Odia, Tamil, Telugu, Kannada, Malayalam) | partial | [#10996](https://github.com/storytold/photocraft/issues/10996) | CharStyle `digits` (doc text.rs), drawn in shaping (text digits.rs) while the layer text keeps the typed digits; set through the type commands' `digits` key. No Character panel control yet (needs the shared panel in craft-libs); Arabic and Persian digits are #6685; not saved in PSD | +| TYPE-10996-1 | Digit style: digits drawn as typed, Western, by the script of the letters before them, or in an Indic script (Devanagari, Bengali, Gurmukhi, Gujarati, Odia, Tamil, Telugu, Kannada, Malayalam) | partial | [#10996](https://github.com/storytold/photocraft/issues/10996) | CharStyle `digits` (doc text.rs), drawn in shaping (text digits.rs) while the layer text keeps the typed digits; set through the type commands' `digits` key. The Character panel's Digits select sets it; Arabic and Persian digits are #6685; not saved in PSD | ## Automation diff --git a/scorecard/type.toml b/scorecard/type.toml index 579e92e571..9626765742 100644 --- a/scorecard/type.toml +++ b/scorecard/type.toml @@ -79,4 +79,4 @@ id = "TYPE-10996-1" target = "Digit style: digits drawn as typed, Western, by the script of the letters before them, or in an Indic script (Devanagari, Bengali, Gurmukhi, Gujarati, Odia, Tamil, Telugu, Kannada, Malayalam)" status = "partial" issue = 10996 -note = "CharStyle `digits` (doc text.rs), drawn in shaping (text digits.rs) while the layer text keeps the typed digits; set through the type commands' `digits` key. No Character panel control yet (needs the shared panel in craft-libs); Arabic and Persian digits are #6685; not saved in PSD" +note = "CharStyle `digits` (doc text.rs), drawn in shaping (text digits.rs) while the layer text keeps the typed digits; set through the type commands' `digits` key. The Character panel's Digits select sets it; Arabic and Persian digits are #6685; not saved in PSD"