mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #18361 from ruchirguitar/digits-dropdown-10996
ui-egui: Digits select in the Character panel (#10996)
This commit is contained in:
9 files changed
+203
-7
No files matched your search
@@ -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,9 +157,28 @@ 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 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",
|
||||
}
|
||||
}
|
||||
|
||||
/// The values the Paragraph controls show for `style`.
|
||||
pub(crate) fn paragraph_values(style: &ParagraphStyle) -> ParagraphValues {
|
||||
use photocraft_doc::text::TextDirection as D;
|
||||
|
||||
@@ -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<PhotocraftApp>, 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<PhotocraftApp>) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
// 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<Digits> {
|
||||
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<PhotocraftApp>>) -> 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");
|
||||
}
|
||||
@@ -240,6 +240,8 @@ pub(super) fn apply(app: &mut PhotocraftApp, props: serde_json::Value, coalesce:
|
||||
if insertion_style::set_font(app, &props) {
|
||||
return;
|
||||
}
|
||||
// A font chosen at the caret and not yet typed outlives another character change there (#10996).
|
||||
let kept = insertion_style::pending(app).cloned();
|
||||
app.ui.type_insertion_style = None;
|
||||
let Some(mut p) = formatting_params(app) else {
|
||||
apply_defaults(app, &props);
|
||||
@@ -253,7 +255,11 @@ pub(super) fn apply(app: &mut PhotocraftApp, props: serde_json::Value, coalesce:
|
||||
if let Some(key) = app.ui.text_edit.as_ref().map(|ed| ed.session.clone()).or(coalesce) {
|
||||
p["coalesce"] = json!(key);
|
||||
}
|
||||
let _ = app.run("type.setStyle", p);
|
||||
if app.run("type.setStyle", p).is_ok()
|
||||
&& let Some(kept) = kept
|
||||
{
|
||||
insertion_style::rebase(app, kept, &props);
|
||||
}
|
||||
}
|
||||
|
||||
/// Open the shared Color Picker with a snapshot of the text target. Sampling or cancelling
|
||||
|
||||
@@ -385,3 +385,52 @@ fn an_existing_empty_layer_keeps_its_font_when_committed() {
|
||||
assert_eq!(families(&saved(&h, id)), [FONTS[1]]);
|
||||
}
|
||||
}
|
||||
|
||||
/// A font chosen at the caret survives a Digits change there before typing (#10996): the typed digit takes the
|
||||
/// chosen font and the picked digit style.
|
||||
#[test]
|
||||
fn a_digits_change_at_the_caret_keeps_the_chosen_typing_font() {
|
||||
let (mut h, id) = fixture(0, "abcdef");
|
||||
select(&mut h, [3, 3]);
|
||||
h.run();
|
||||
choose(&mut h, FONTS[1], "enter");
|
||||
assert!(super::insertion_style::pending(h.state()).is_some(), "a pending font at the caret");
|
||||
super::apply(h.state_mut(), json!({"digits": "devanagari"}), None);
|
||||
assert!(super::insertion_style::pending(h.state()).is_some(), "the Digits change keeps the pending font");
|
||||
super::host::type_text(h.state_mut(), "5");
|
||||
h.run();
|
||||
assert_eq!(families(&saved(&h, id))[3], FONTS[1], "the typed digit takes the chosen font");
|
||||
let t = layer(&h.state().session.active().unwrap().doc, id);
|
||||
let mut offset = 0;
|
||||
let digits = t.char_runs().into_iter().find_map(|r| {
|
||||
offset += r.len;
|
||||
(offset > 3).then_some(r.style.digits)
|
||||
});
|
||||
assert_eq!(digits, Some(photocraft_doc::text::Digits::Devanagari), "the typed digit takes the picked digit style");
|
||||
}
|
||||
|
||||
/// An axis change at the caret after a font was chosen there wins over the chosen font's saved axes; the axes it does
|
||||
/// not set keep their chosen values.
|
||||
#[test]
|
||||
fn an_axis_change_at_the_caret_keeps_its_value_with_the_chosen_typing_font() {
|
||||
let (mut h, id) = fixture(0, "abcdef");
|
||||
h.state_mut().run("type.setStyle", json!({"layer": id.0, "variations": {"wght": 650, "wdth": 95}})).unwrap();
|
||||
select(&mut h, [3, 3]);
|
||||
h.run();
|
||||
choose(&mut h, FONTS[1], "enter");
|
||||
super::apply(h.state_mut(), json!({"variations": {"wdth": 110}}), None);
|
||||
super::host::type_text(h.state_mut(), "X");
|
||||
h.run();
|
||||
assert_eq!(families(&saved(&h, id))[3], FONTS[1], "the typed letter takes the chosen font");
|
||||
let mut offset = 0;
|
||||
let axes = layer(&h.state().session.active().unwrap().doc, id)
|
||||
.char_runs()
|
||||
.into_iter()
|
||||
.find_map(|r| {
|
||||
offset += r.len;
|
||||
(offset > 3).then_some(r.style.variations)
|
||||
})
|
||||
.unwrap();
|
||||
assert!(axes.iter().any(|v| v.axis == "wdth" && v.value == 110.0), "the changed axis holds: {axes:?}");
|
||||
assert!(axes.iter().any(|v| v.axis == "wght" && v.value == 650.0), "an axis the change left keeps its value: {axes:?}");
|
||||
}
|
||||
@@ -49,6 +49,33 @@ pub(super) fn set_font(app: &mut PhotocraftApp, props: &serde_json::Value) -> bo
|
||||
true
|
||||
}
|
||||
|
||||
/// Keeps the caret's pending font `kept` after another character change at the same caret: the style the command
|
||||
/// stored there (in the layer's own units) with the chosen font on it, for the new revision, so the next typed text
|
||||
/// still takes the chosen font and the change.
|
||||
pub(super) fn rebase(app: &mut PhotocraftApp, mut kept: TypeInsertionStyle, props: &serde_json::Value) {
|
||||
let Some((mut style, _)) = styles_at(app) else { return };
|
||||
let Some(st) = app.session.active() else { return };
|
||||
let chosen = &kept.style;
|
||||
style.font_family.clone_from(&chosen.font_family);
|
||||
style.weight = chosen.weight;
|
||||
style.italic = chosen.italic;
|
||||
style.postscript_name.clone_from(&chosen.postscript_name);
|
||||
style.variations.clone_from(&chosen.variations);
|
||||
// An axis the change set itself wins over the chosen font's saved value; the others stay as chosen.
|
||||
if let Some(axes) = props.get("variations").and_then(serde_json::Value::as_object) {
|
||||
for (axis, value) in axes {
|
||||
let Some(value) = value.as_f64() else { continue };
|
||||
match style.variations.iter_mut().find(|v| v.axis == *axis) {
|
||||
Some(v) => v.value = value as f32,
|
||||
None => style.variations.push(photocraft_doc::text::FontVariation { axis: axis.clone(), value: value as f32 }),
|
||||
}
|
||||
}
|
||||
}
|
||||
kept.style = style;
|
||||
kept.revision = st.revision;
|
||||
app.ui.type_insertion_style = Some(kept);
|
||||
}
|
||||
|
||||
/// How many characters `text` adds once the engine stores it: a CRLF pair becomes one `\n` (a lone CR is one
|
||||
/// character either way), so a pasted Windows line break moves the caret by one, not two.
|
||||
pub(super) fn stored_chars(text: &str) -> usize {
|
||||
|
||||
@@ -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;
|
||||
@@ -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<CharStyle>, Vec<ParagraphS
|
||||
(!chars.is_empty() && !paras.is_empty()).then_some((chars, paras))
|
||||
}
|
||||
|
||||
/// The Character panel's Digits choices: the engine's `digits` name of each style and its label.
|
||||
pub(crate) fn digit_entries() -> 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<Step> {
|
||||
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<String, serde_json::Value> =
|
||||
axes.iter().map(|(tag, v)| (String::from_utf8_lossy(tag).trim().to_string(), json!(v))).collect();
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
+1
-1
@@ -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"
|
||||
Reference in new issue
Block a user