DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
UI: ruby, kenten, shatai and grid settings in the style dialogs and the Ruby dialog
aiongg48de197a2f25
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex ddbced490..48ddf65f4 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -70,6 +70,9 @@ impl Dialog {if id == "paragraphStyleOptions" || id == "characterStyleOptions" {fields.entry("section".to_string()).or_insert(json!("general"));}+ if id == "ruby" {+ fields.entry("section".to_string()).or_insert(json!("cjk.rubyPlacement"));+ }if id == "frameSize" {for k in ["width", "height"] {if let Some(v) = fields.get(k).and_then(Value::as_f64) {@@ -1666,13 +1669,7 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {text_field(ui, &mut d, "page", 80.0);});}- "ruby" => {- ui.horizontal(|ui| {- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Ruby:"));- text_field(ui, &mut d, "text", 200.0);- });- crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Set over the selected text; empty removes it.")).size(11.0));- }+ "ruby" => style_cjk::ruby_dialog(app, ui, &mut d),"insertTable" => {crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Table Dimensions")).font(semibold(12.0)));egui::Grid::new("ins_table").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {@@ -1770,7 +1767,7 @@ pub fn confirm(app: &mut DesignApp) -> Result<Value, String> {json!({"spread": d.fields.get("spread").cloned().unwrap_or(json!(0)), "shape": d.s("shape"), "content": d.s("content"), "rect": [x, y, x + w, y + h]}),)}- "ruby" => app.run("type.ruby", json!({"text": d.s("text")})),+ "ruby" => app.run("type.ruby", style_cjk::ruby_params(&d)),"goToPage" => {// A page name ("iv", "A-3"), a number, or "+n" for an absolute position.let typed = match d.fields.get("page") {@@ -2609,9 +2606,7 @@ fn paragraph_style_options(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialo});}"color" => character_color(&app.ui.language, ui, d, &CharFields { base: &cv, sparse: false }, &doc),- s if style_cjk::is_section(s) => {- style_cjk::section(&app.ui.language, ui, d, s, &CharFields { base: &cv, sparse: false }, Some(&pv), &doc)- }+ s if style_cjk::is_section(s) => style_cjk::section_ui(app, ui, d, s, &CharFields { base: &cv, sparse: false }, Some(&pv), &doc),_ => {egui::Grid::new("psg").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Style Name:"));@@ -2843,7 +2838,7 @@ fn character_style_options(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialo"openType" => open_type_features(&lang, ui, d, &cf),"underline" => line_options(&lang, ui, d, &cf, &doc, "underline"),"strikethrough" => line_options(&lang, ui, d, &cf, &doc, "strikethrough"),- s if style_cjk::is_section(s) => style_cjk::section(&lang, ui, d, s, &cf, None, &doc),+ s if style_cjk::is_section(s) => style_cjk::section_ui(app, ui, d, s, &cf, None, &doc),_ => {egui::Grid::new("csg").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {crate::rtl::label(ui, crate::i18n::tr(&lang, "Style Name:"));diff --git a/crates/ui-egui/src/dialogs/style_cjk.rs b/crates/ui-egui/src/dialogs/style_cjk.rsindex f4b7bbd17..28cf89141 100644--- a/crates/ui-egui/src/dialogs/style_cjk.rs+++ b/crates/ui-egui/src/dialogs/style_cjk.rs@@ -1,12 +1,17 @@//! The CJK sections of Paragraph Style Options and Character Style Options, listed while Show CJK-//! Features is on ([`crate::cjk_features`]): Tate-chu-yoko, Kenten, Japanese Composition, Grid-//! and Warichu settings. They edit `c.<attr>` and `p.<attr>` fields like the other sections, and-//! OK applies them with the dialog's style edit command.+//! Features is on ([`crate::cjk_features`]): Auto Tate-chu-yoko, Tate-chu-yoko, the four ruby+//! sections, Kenten, Kenten Color, Shatai, Japanese Composition, Grid and Warichu settings. They+//! edit `c.<attr>` and `p.<attr>` fields like the other sections, and OK applies them with the+//! dialog's style edit command. The Ruby dialog (Type › Ruby…) shows the four ruby sections over+//! the selected text and applies them with `type.ruby`.use designcraft_doc::cjk::Kinsoku;+use designcraft_doc::cjk_settings::KentenKind;use serde_json::{Value, json};use super::{CharFields, Dialog, char_check, char_choice, char_number};+use crate::DesignApp;+use crate::i18n::tr;struct Section {id: &'static str,@@ -17,12 +22,32 @@ struct Section {after_export: bool,}+const fn section(id: &'static str, label: &'static str, para_only: bool, after_export: bool) -> Section {+ Section { id, label, para_only, after_export }+}++/// In the order of the reference dialog.const SECTIONS: &[Section] = &[- Section { id: "cjk.tcy", label: "Tate-chu-yoko Settings", para_only: false, after_export: false },- Section { id: "cjk.kenten", label: "Kenten Settings", para_only: false, after_export: false },- Section { id: "cjk.composition", label: "Japanese Composition Settings", para_only: true, after_export: false },- Section { id: "cjk.grid", label: "Grid Settings", para_only: true, after_export: false },- Section { id: "cjk.warichu", label: "Warichu Settings", para_only: false, after_export: true },+ section("cjk.autoTcy", "Auto Tate-chu-yoko Settings", true, false),+ section("cjk.tcy", "Tate-chu-yoko Settings", false, false),+ section("cjk.rubyPlacement", "Ruby Placement and Spacing", false, false),+ section("cjk.rubyFont", "Ruby Font and Size", false, false),+ section("cjk.rubyLonger", "Adjustment When Ruby Is Longer Than Parent", false, false),+ section("cjk.rubyColor", "Ruby Color", false, false),+ section("cjk.kenten", "Kenten Settings", false, false),+ section("cjk.kentenColor", "Kenten Color", false, false),+ section("cjk.shatai", "Shatai", false, false),+ section("cjk.composition", "Japanese Composition Settings", true, false),+ section("cjk.grid", "Grid Settings", true, false),+ section("cjk.warichu", "Warichu Settings", false, true),+];++/// The Ruby dialog's sections, the same panes as in the style dialogs.+pub(super) const RUBY_SECTIONS: &[(&str, &str)] = &[+ ("cjk.rubyPlacement", "Ruby Placement and Spacing"),+ ("cjk.rubyFont", "Ruby Font and Size"),+ ("cjk.rubyLonger", "Adjustment When Ruby Is Longer Than Parent"),+ ("cjk.rubyColor", "Ruby Color"),];/// The section list of a style options dialog: `base` with the CJK sections when `cjk` is on.@@ -57,9 +82,10 @@ pub(super) fn is_section(id: &str) -> bool {}/// Draws CJK section `id`. `para` holds the paragraph style's resolved paragraph attributes; it-/// is `None` in Character Style Options, which have no paragraph-only sections.-pub(super) fn section(- lang: &str,+/// is `None` in Character Style Options and the Ruby dialog, which have no paragraph-only+/// sections.+pub(super) fn section_ui(+ app: &mut DesignApp,ui: &mut egui::Ui,d: &mut Dialog,id: &str,@@ -67,16 +93,107 @@ pub(super) fn section(para: Option<&Value>,doc: &designcraft_doc::Document,) {+ let lang = app.ui.language.clone();+ let lang = lang.as_str();match (id, para) {("cjk.tcy", _) => tate_chu_yoko(lang, ui, d, cf),- ("cjk.kenten", _) => kenten(lang, ui, d, cf),+ ("cjk.rubyPlacement", _) => ruby_placement(lang, ui, d, cf),+ ("cjk.rubyFont", _) => ruby_font(app, ui, d, cf),+ ("cjk.rubyLonger", _) => ruby_longer(lang, ui, d, cf),+ ("cjk.rubyColor", _) => adornment_color(lang, ui, d, cf, doc, "ruby"),+ ("cjk.kenten", _) => kenten(app, ui, d, cf),+ ("cjk.kentenColor", _) => adornment_color(lang, ui, d, cf, doc, "kenten"),+ ("cjk.shatai", _) => shatai(lang, ui, d, cf),("cjk.warichu", _) => warichu(lang, ui, d, cf),+ ("cjk.autoTcy", Some(pv)) => auto_tate_chu_yoko(lang, ui, d, pv),("cjk.composition", Some(pv)) => japanese_composition(lang, ui, d, cf, pv, doc),("cjk.grid", Some(pv)) => grid_settings(lang, ui, d, pv),_ => {}}}+fn grid(id: &str) -> egui::Grid {+ egui::Grid::new(id).num_columns(2).spacing([8.0, 6.0])+}++/// A number attribute that may be automatic (`null`: half the text size, the text's tint...):+/// emptying the field makes it automatic again.+fn char_auto_number(ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, key: &str, suffix: &str, scale: f64, range: (f64, f64)) {+ let v = cf.get(d, key).as_f64().map(|x| x * scale);+ let field = crate::widgets::NumField::number(key, v, suffix, 2).width(80.0).range(range.0, range.1);+ if let Some(n) = field.show_or_clear(ui) {+ cf.set(d, key, n.map_or(Value::Null, |n| json!(n / scale)));+ }+}++/// A font family and style pair of attributes; an empty family is the parent text's font.+fn font_fields(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, keys: (&str, &str), enabled: bool) {+ let lang = app.ui.language.clone();+ let lang = lang.as_str();+ let fonts = crate::panels::fonts(app);+ let menu = crate::panels::font_menu(app);+ let (fam_key, style_key) = keys;+ let raw = cf.get(d, fam_key);+ let fam = raw.as_str().unwrap_or("").to_string();+ let parent = tr(lang, "Parent's Font").to_string();+ let shown = match &raw {+ Value::Null if cf.sparse => String::new(),+ _ if fam.is_empty() => parent.clone(),+ _ => crate::panels::font_label(app, &menu, &fam),+ };+ crate::rtl::label(ui, tr(lang, "Font Family:"));+ ui.add_enabled_ui(enabled, |ui| {+ egui::ComboBox::from_id_salt(("cjkfam", fam_key))+ .selected_text(shown)+ .width(200.0)+ .height(440.0)+ .close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside)+ .show_ui(ui, |ui| {+ if cf.sparse && ui.selectable_label(raw.is_null(), " ").clicked() {+ cf.set(d, fam_key, Value::Null);+ cf.set(d, style_key, Value::Null);+ }+ if ui.selectable_label(!raw.is_null() && fam.is_empty(), crate::rtl::widget(ui, parent.as_str())).clicked() {+ cf.set(d, fam_key, json!(""));+ cf.set(d, style_key, json!(""));+ }+ if let Some(f) = crate::panels::font_menu_body(app, ui, &menu, &fam, 200.0) {+ cf.set(d, fam_key, json!(f));+ }+ });+ });+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Font Style:"));+ let sty = cf.get(d, style_key).as_str().unwrap_or("").to_string();+ ui.add_enabled_ui(enabled && !fam.is_empty(), |ui| {+ egui::ComboBox::from_id_salt(("cjksty", style_key)).selected_text(&sty).width(200.0).show_ui(ui, |ui| {+ for s in fonts.styles(&fam) {+ if ui.selectable_label(s == sty, &s).clicked() {+ cf.set(d, style_key, json!(s));+ }+ }+ });+ });+ ui.end_row();+}++/// An adornment's overprint (`auto`, `on` or `off`): checked is `on`; a character style also+/// has the unset state.+fn overprint_check(ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, key: &str, label: &str) {+ let cur = cf.get(d, key);+ let mut on = cur.as_str() == Some("on");+ let unset = cf.sparse && cur.is_null();+ if ui.add(egui::Checkbox::new(&mut on, crate::rtl::widget(ui, label)).indeterminate(unset)).clicked() {+ let next = match cur.as_str() {+ _ if !cf.sparse => json!(if on { "on" } else { "auto" }),+ None => json!("on"),+ Some("on") => json!("auto"),+ Some(_) => Value::Null,+ };+ cf.set(d, key, next);+ }+}+/// Tate-chu-yoko Settings: the switch and the run's offsets.fn tate_chu_yoko(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {char_check(ui, d, cf, "tateChuYoko", crate::i18n::tr(lang, "Tate-Chu-Yoko"));@@ -91,94 +208,388 @@ fn tate_chu_yoko(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields)});}-/// The preset kenten marks: (label, character). The sesame dot is the empty character, which the-/// composer draws as U+FE45 and IDML export writes as `KentenSesameDot`.-pub(super) const KENTEN: &[(&str, &str)] = &[- ("Sesame Dot", ""),- ("White Sesame Dot", "\u{FE46}"),- ("Bullseye", "\u{25C9}"),- ("Black Circle", "\u{25CF}"),- ("Small Black Circle", "\u{2022}"),- ("Double Circle", "\u{25CE}"),- ("Black Triangle", "\u{25B2}"),- ("White Triangle", "\u{25B3}"),- ("White Circle", "\u{25CB}"),- ("Small White Circle", "\u{25E6}"),-];+/// Ruby Placement and Spacing: type, alignment, position and offsets.+fn ruby_placement(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+ grid("cjkrubyplace").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Ruby Type:"));+ char_choice(lang, ui, d, cf, "rubyType", &[(json!("perCharacter"), "Per-Character Ruby"), (json!("group"), "Group Ruby")]);+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Alignment:"));+ char_choice(+ lang,+ ui,+ d,+ cf,+ "rubyAlignment",+ &[+ (json!("left"), "Left/Top"),+ (json!("center"), "Centered"),+ (json!("right"), "Right/Bottom"),+ (json!("fullJustify"), "Full Justify"),+ (json!("jis"), "1-2-1 (JIS) Rule"),+ (json!("equalAki"), "Equal Aki"),+ (json!("oneAki"), "1 Ruby Character Aki"),+ ],+ );+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Position:"));+ char_choice(lang, ui, d, cf, "rubyPosition", &[(json!("aboveRight"), "Above/Right"), (json!("belowLeft"), "Below/Left")]);+ ui.end_row();+ });+ ui.add_space(6.0);+ crate::rtl::label(ui, egui::RichText::new(tr(lang, "Offset from Parent")).font(crate::theme::semibold(12.0)));+ grid("cjkrubyoffset").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Across the Line:"));+ char_number(ui, d, cf, "rubyYOffset", " pt", 1.0, (-1000.0, 1000.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Along the Line:"));+ char_number(ui, d, cf, "rubyXOffset", " pt", 1.0, (-1000.0, 1000.0));+ ui.end_row();+ });+}-/// Dialog-only: Custom was picked, so the Character field is editable even while it holds a-/// preset mark.-const KENTEN_CUSTOM: &str = "cjk.kentenCustom";+/// Ruby Font and Size: font, size (empty: half the parent's), scales, OpenType ruby glyphs and+/// tate-chu-yoko of digits inside vertical ruby.+fn ruby_font(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+ let lang = app.ui.language.clone();+ let lang = lang.as_str();+ grid("cjkrubyfont").show(ui, |ui| {+ font_fields(app, ui, d, cf, ("rubyFont", "rubyFontStyle"), true);+ crate::rtl::label(ui, tr(lang, "Size:"));+ char_auto_number(ui, d, cf, "rubyFontSize", " pt", 1.0, (0.1, 1296.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Horizontal Scale:"));+ char_number(ui, d, cf, "rubyXScale", "%", 100.0, (1.0, 1000.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Vertical Scale:"));+ char_number(ui, d, cf, "rubyYScale", "%", 100.0, (1.0, 1000.0));+ ui.end_row();+ });+ char_check(ui, d, cf, "rubyOpenTypePro", tr(lang, "Use OpenType Pro Ruby Glyphs"));+ ui.add_space(4.0);+ grid("cjkrubytcy").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Tate-chu-yoko Digits:"));+ char_count(ui, d, cf, "rubyAutoTcyDigits", (0.0, 9.0));+ ui.end_row();+ });+ char_check(ui, d, cf, "rubyAutoTcyIncludeRoman", tr(lang, "Include Roman Characters"));+ char_check(ui, d, cf, "rubyAutoTcyAutoScale", tr(lang, "Fit to Width"));+}-fn kenten_preset(character: &str) -> Option<&'static (&'static str, &'static str)> {- let character = if character == "\u{FE45}" { "" } else { character };- KENTEN.iter().find(|k| k.1 == character)+/// Adjustment When Ruby Is Longer Than Parent: overhang, parent spacing, automatic narrowing+/// and alignment with the line edges.+fn ruby_longer(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+ grid("cjkrubylonger").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Ruby Overhang:"));+ char_choice(+ lang,+ ui,+ d,+ cf,+ "rubyOverhangAmount",+ &[+ (json!("none"), "None"),+ (json!("oneRuby"), "1 Ruby Character"),+ (json!("halfRuby"), "1/2 Ruby Character"),+ (json!("oneChar"), "1 Parent Character"),+ (json!("halfChar"), "1/2 Parent Character"),+ (json!("noLimit"), "Unlimited"),+ ],+ );+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Parent Character Spacing:"));+ char_choice(+ lang,+ ui,+ d,+ cf,+ "rubyParentSpacing",+ &[+ (json!("noAdjustment"), "No Adjustment"),+ (json!("bothSides"), "Both Sides"),+ (json!("aki121"), "1-2-1 Aki"),+ (json!("equalAki"), "Equal Aki"),+ (json!("fullJustify"), "Full Justify"),+ ],+ );+ ui.end_row();+ });+ ui.add_space(4.0);+ char_check(ui, d, cf, "rubyAutoScaling", tr(lang, "Shrink Ruby Width Automatically"));+ grid("cjkrubyscale").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Minimum Scale:"));+ let on = cf.get(d, "rubyAutoScaling").as_bool() == Some(true);+ ui.add_enabled_ui(on, |ui| char_number(ui, d, cf, "rubyScalingMin", "%", 100.0, (10.0, 100.0)));+ ui.end_row();+ });+ char_check(ui, d, cf, "rubyAutoAlign", tr(lang, "Auto Align at Line Start/End"));}-/// Kenten Type picks: `None` switches kenten off, `Some(mark)` sets that mark.-pub(super) fn pick_kenten(d: &mut Dialog, cf: &CharFields, mark: Option<&str>) {- d.fields.remove(KENTEN_CUSTOM);- match mark {- Some(m) => {- cf.set(d, "kenten", json!(true));- cf.set(d, "kentenCharacter", json!(m));+/// Ruby Color / Kenten Color (`prefix` "ruby" or "kenten"): the fill or stroke swatch (Text+/// Color: the text's own), its tint and the stroke weight (empty: the text's), and overprint.+fn adornment_color(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, doc: &designcraft_doc::Document, prefix: &str) {+ let target = format!("cjk.{prefix}ColorTarget");+ let stroke = d.s(&target) == "stroke";+ ui.horizontal(|ui| {+ for (t, label) in [("fill", "Fill"), ("stroke", "Stroke")] {+ if ui.selectable_label((t == "stroke") == stroke, crate::rtl::widget(ui, tr(lang, label))).clicked() {+ d.fields.insert(target.clone(), json!(t));+ }}- None => {- cf.set(d, "kenten", json!(false));- // IDML export writes any stored mark as a custom kenten, even with kenten off.- if cf.get(d, "kentenCharacter").as_str().is_some_and(|c| !c.is_empty()) {- cf.set(d, "kentenCharacter", json!(""));+ });+ let part = if stroke { "Stroke" } else { "Fill" };+ let key = format!("{prefix}{part}");+ let cur = cf.get(d, &key);+ let cur = cur.as_str();+ let mut pick: Option<Value> = None;+ egui::ScrollArea::vertical().id_salt(("cjkcolor", key.as_str())).max_height(150.0).show(ui, |ui| {+ let entry = |ui: &mut egui::Ui, name: &str, label: &str, pick: &mut Option<Value>| {+ if ui.selectable_label(cur == Some(name), crate::rtl::widget(ui, label)).clicked() {+ // A character style's chosen colour, clicked again, is no longer set.+ *pick = Some(if cf.sparse && cur == Some(name) { Value::Null } else { json!(name) });}+ };+ ui.horizontal(|ui| {+ ui.add_space(18.0);+ entry(ui, "", tr(lang, "Text Color"), &mut pick);+ });+ for sw in &doc.swatches {+ let (c, g) = crate::widgets::swatch_colors(doc, &sw.name, 1.0);+ ui.horizontal(|ui| {+ let (r, _) = ui.allocate_exact_size(egui::vec2(14.0, 14.0), egui::Sense::hover());+ crate::widgets::paint_chip(ui.painter(), r, c, g);+ entry(ui, &sw.name, &sw.name, &mut pick);+ });}+ });+ if let Some(v) = pick {+ cf.set(d, &key, v);}+ grid(&format!("cjkcolorg{prefix}")).show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Tint:"));+ char_auto_number(ui, d, cf, &format!("{prefix}{part}Tint"), "%", 100.0, (0.0, 100.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Weight:"));+ char_auto_number(ui, d, cf, &format!("{prefix}StrokeWeight"), " pt", 1.0, (0.0, 800.0));+ ui.end_row();+ });+ overprint_check(ui, d, cf, &format!("{prefix}OverprintFill"), tr(lang, "Overprint Fill"));+ overprint_check(ui, d, cf, &format!("{prefix}OverprintStroke"), tr(lang, "Overprint Stroke"));}-/// Kenten Settings: the mark (a preset or a custom character).-fn kenten(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+/// The `type.ruby` parameters for the Ruby dialog's edits: the reading and every `c.ruby*`+/// field, in the command's units (percentages for scales and tints).+pub(super) fn ruby_params(d: &Dialog) -> Value {+ let mut p = serde_json::Map::new();+ p.insert("text".into(), json!(d.s("text")));+ // (attribute, parameter, factor from the model's unit to the parameter's)+ const MAP: &[(&str, &str, f64)] = &[+ ("rubyType", "type", 0.0),+ ("rubyAlignment", "alignment", 0.0),+ ("rubyPosition", "position", 0.0),+ ("rubyXOffset", "xOffset", 1.0),+ ("rubyYOffset", "yOffset", 1.0),+ ("rubyFont", "font", 0.0),+ ("rubyFontStyle", "fontStyle", 0.0),+ ("rubyFontSize", "size", 1.0),+ ("rubyXScale", "xScale", 100.0),+ ("rubyYScale", "yScale", 100.0),+ ("rubyOpenTypePro", "openTypePro", 0.0),+ ("rubyAutoTcyDigits", "autoTcyDigits", 1.0),+ ("rubyAutoTcyIncludeRoman", "autoTcyIncludeRoman", 0.0),+ ("rubyAutoTcyAutoScale", "autoTcyAutoScale", 0.0),+ ("rubyOverhangAmount", "overhang", 0.0),+ ("rubyParentSpacing", "parentSpacing", 0.0),+ ("rubyAutoAlign", "autoAlign", 0.0),+ ("rubyAutoScaling", "autoScaling", 0.0),+ ("rubyScalingMin", "scalingPercent", 100.0),+ ("rubyFill", "fill", 0.0),+ ("rubyStroke", "stroke", 0.0),+ ("rubyFillTint", "fillTint", 100.0),+ ("rubyStrokeTint", "strokeTint", 100.0),+ ("rubyStrokeWeight", "strokeWeight", 1.0),+ ("rubyOverprintFill", "overprintFill", 0.0),+ ("rubyOverprintStroke", "overprintStroke", 0.0),+ ];+ for (attr, param, factor) in MAP {+ let Some(v) = d.fields.get(&format!("c.{attr}")) else { continue };+ let v = match v.as_f64() {+ Some(x) if *factor != 0.0 => json!(x * factor),+ _ => v.clone(),+ };+ p.insert((*param).into(), v);+ }+ Value::Object(p)+}++/// The Ruby dialog: the reading over the selected text and the four ruby panes. `base` holds the+/// selection's resolved character attributes.+pub(super) fn ruby_dialog(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {+ let lang = app.ui.language.clone();+ let Some(doc) = app.session.active().map(|s| s.doc.clone()) else { return };+ let base = d.fields.get("base").cloned().unwrap_or(Value::Null);+ let cf = CharFields { base: &base, sparse: false };+ ui.horizontal(|ui| {+ crate::rtl::label(ui, tr(&lang, "Ruby:"));+ super::text_field(ui, d, "text", 260.0);+ });+ crate::rtl::label(ui, egui::RichText::new(tr(&lang, "Set over the selected text; empty removes it.")).size(11.0));+ ui.add_space(6.0);+ ui.set_min_width(560.0);+ ui.horizontal_top(|ui| {+ ui.set_min_height(330.0);+ ui.set_max_height(330.0);+ super::section_list(&lang, ui, d, false, RUBY_SECTIONS);+ ui.separator();+ let id = d.s("section");+ ui.vertical(|ui| section_ui(app, ui, d, &id, &cf, None, &doc));+ });+}++/// Kenten Type menu labels, in [`KentenKind::ALL`] order.+fn kenten_label(kind: KentenKind) -> &'static str {+ match kind {+ KentenKind::SesameDot => "Sesame Dot",+ KentenKind::WhiteSesameDot => "White Sesame Dot",+ KentenKind::Fisheye => "Fisheye",+ KentenKind::BlackCircle => "Black Circle",+ KentenKind::SmallBlackCircle => "Small Black Circle",+ KentenKind::Bullseye => "Double Circle",+ KentenKind::BlackTriangle => "Black Triangle",+ KentenKind::WhiteTriangle => "White Triangle",+ KentenKind::WhiteCircle => "White Circle",+ KentenKind::SmallWhiteCircle => "Small White Circle",+ KentenKind::Custom => "Custom",+ }+}++/// The kind the menu shows for the stored kind and character. Documents made before kinds+/// existed store a preset as its character with the default kind.+fn shown_kenten_kind(kind: Option<KentenKind>, character: &str) -> KentenKind {+ match kind {+ Some(k) if k != KentenKind::SesameDot => k,+ _ if character.is_empty() || character == "\u{FE45}" => KentenKind::SesameDot,+ _ => KentenKind::ALL.into_iter().find(|k| k.mark() == Some(character)).unwrap_or(KentenKind::Custom),+ }+}++/// Kenten Type picks: `None` switches kenten off (keeping the other settings), `Some(kind)`+/// switches them on with that kind. A preset stores its mark as the character too, as+/// `type.kenten` does.+pub(super) fn pick_kenten(d: &mut Dialog, cf: &CharFields, kind: Option<KentenKind>) {+ let Some(kind) = kind else {+ cf.set(d, "kenten", json!(false));+ return;+ };+ cf.set(d, "kenten", json!(true));+ cf.set(d, "kentenKind", json!(kind));+ if let Some(mark) = kind.mark() {+ cf.set(d, "kentenCharacter", json!(mark));+ }+}++/// Kenten Settings: distance, position, size, alignment, scales, the kind, and for a custom mark+/// its font and characters.+fn kenten(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+ use designcraft_doc::cjk_settings::KENTEN_MARK_MAX_CHARS;+ let lang = app.ui.language.clone();+ let lang = lang.as_str();let on = cf.get(d, "kenten").as_bool();+ let stored: Option<KentenKind> = serde_json::from_value(cf.get(d, "kentenKind")).ok();let character = cf.get(d, "kentenCharacter").as_str().unwrap_or("").to_string();- let preset = kenten_preset(&character);- let custom = on == Some(true) && (d.b(KENTEN_CUSTOM) || preset.is_none());- let shown = match on {- None => String::new(),- Some(false) => crate::i18n::tr(lang, "None").to_string(),- Some(true) if custom => crate::i18n::tr(lang, "Custom").to_string(),- Some(true) => preset.map_or(String::new(), |p| crate::i18n::tr(lang, p.0).to_string()),- };- egui::Grid::new("cjkkenten").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {- crate::rtl::label(ui, crate::i18n::tr(lang, "Kenten Type:"));+ let kind = shown_kenten_kind(stored, &character);+ let custom = on == Some(true) && kind == KentenKind::Custom;+ grid("cjkkenten").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Distance from Parent:"));+ char_number(ui, d, cf, "kentenDistance", " pt", 1.0, (-1296.0, 1296.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Position:"));+ char_choice(lang, ui, d, cf, "kentenPosition", &[(json!("aboveRight"), "Above/Right"), (json!("belowLeft"), "Below/Left")]);+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Size:"));+ char_auto_number(ui, d, cf, "kentenSize", " pt", 1.0, (0.1, 1296.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Alignment:"));+ char_choice(lang, ui, d, cf, "kentenAlignment", &[(json!("center"), "Centered"), (json!("start"), "Left/Top")]);+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Horizontal Scale:"));+ char_number(ui, d, cf, "kentenXScale", "%", 100.0, (1.0, 1000.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Vertical Scale:"));+ char_number(ui, d, cf, "kentenYScale", "%", 100.0, (1.0, 1000.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Kenten Type:"));+ let shown = match on {+ None => String::new(),+ Some(false) => tr(lang, "None").to_string(),+ Some(true) => tr(lang, kenten_label(kind)).to_string(),+ };egui::ComboBox::from_id_salt("cjkkententype").selected_text(crate::rtl::widget(ui, shown)).width(200.0).show_ui(ui, |ui| {if cf.sparse && ui.selectable_label(on.is_none(), " ").clicked() {- d.fields.remove(KENTEN_CUSTOM);- cf.set(d, "kenten", Value::Null);- cf.set(d, "kentenCharacter", Value::Null);+ for key in ["kenten", "kentenKind", "kentenCharacter"] {+ cf.set(d, key, Value::Null);+ }}- if ui.selectable_label(on == Some(false), crate::rtl::widget(ui, crate::i18n::tr(lang, "None"))).clicked() {+ if ui.selectable_label(on == Some(false), crate::rtl::widget(ui, tr(lang, "None"))).clicked() {pick_kenten(d, cf, None);}- for (label, mark) in KENTEN {- let selected = on == Some(true) && !custom && preset.is_some_and(|p| p.1 == *mark);- if ui.selectable_label(selected, crate::rtl::widget(ui, crate::i18n::tr(lang, label))).clicked() {- pick_kenten(d, cf, Some(*mark));+ for k in KentenKind::ALL {+ if ui.selectable_label(on == Some(true) && kind == k, crate::rtl::widget(ui, tr(lang, kenten_label(k)))).clicked() {+ pick_kenten(d, cf, Some(k));}}- if ui.selectable_label(custom, crate::rtl::widget(ui, crate::i18n::tr(lang, "Custom"))).clicked() {- d.fields.insert(KENTEN_CUSTOM.into(), json!(true));- cf.set(d, "kenten", json!(true));- }});ui.end_row();- crate::rtl::label(ui, crate::i18n::tr(lang, "Character:"));+ font_fields(app, ui, d, cf, ("kentenFont", "kentenFontStyle"), custom);+ crate::rtl::label(ui, tr(lang, "Character:"));+ // Typed directly; a mark stored with another input mode (IDML) is kept as it is.let mut text = if custom { character.clone() } else { String::new() };- if ui.add_enabled(custom, egui::TextEdit::singleline(&mut text).desired_width(40.0)).changed() {- // One mark: the character typed last replaces the one before it.- let mark: String = text.chars().last().map(String::from).unwrap_or_default();+ if ui.add_enabled(custom, egui::TextEdit::singleline(&mut text).desired_width(80.0)).changed() {+ let mark: String = text.chars().filter(|c| !c.is_control()).take(KENTEN_MARK_MAX_CHARS).collect();cf.set(d, "kentenCharacter", json!(mark));}ui.end_row();});}+/// Shatai: magnification, angle, and the rotation and tsume adjustments.+fn shatai(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields) {+ grid("cjkshatai").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Magnification:"));+ char_number(ui, d, cf, "shataiMagnification", "%", 1.0, (0.0, 90.0));+ ui.end_row();+ crate::rtl::label(ui, tr(lang, "Angle:"));+ let v = cf.get(d, "shataiAngle").as_f64();+ let field = crate::widgets::NumField::number("shataiAngle", v, "°", 2).width(80.0).range(0.0, 180.0).presets(&[30.0, 45.0, 60.0]);+ let edit = if cf.sparse { field.show_or_clear(ui) } else { field.show(ui).map(Some) };+ if let Some(n) = edit {+ cf.set(d, "shataiAngle", n.map_or(Value::Null, |n| json!(n)));+ }+ ui.end_row();+ });+ char_check(ui, d, cf, "shataiAdjustRotation", tr(lang, "Adjust Rotation"));+ char_check(ui, d, cf, "shataiAdjustTsume", tr(lang, "Adjust Tsume"));+}++/// Auto Tate-chu-yoko Settings: the longest digit run set across the line, and whether roman+/// letters count.+fn auto_tate_chu_yoko(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, pv: &Value) {+ grid("cjkautotcy").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Tate-chu-yoko Digits:"));+ para_count(ui, d, pv, "autoTcy", (0.0, f64::from(designcraft_compose::shape::AUTO_TCY_MAX)));+ ui.end_row();+ });+ para_check(ui, d, pv, "autoTcyIncludeRoman", tr(lang, "Include Roman Characters"));+}++/// A whole-number paragraph attribute.+fn para_count(ui: &mut egui::Ui, d: &mut Dialog, pv: &Value, key: &str, range: (f64, f64)) {+ let v = para_value(d, pv, key).as_f64();+ if let Some(n) = crate::widgets::NumField::number(key, v, "", 0).width(80.0).range(range.0, range.1).show(ui) {+ d.fields.insert(format!("p.{key}"), json!(n.round().max(range.0).min(range.1) as u64));+ }+}+/// A whole-number attribute (stored as an integer: the model's fields are `u32`).fn char_count(ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, key: &str, range: (f64, f64)) {let v = cf.get(d, key).as_f64();@@ -309,7 +720,7 @@ pub(super) fn mojikumi_sets(doc: &designcraft_doc::Document, current: &str) -> V}/// Japanese Composition Settings: kinsoku, hanging, bunri-kinshi, mojikumi, the leading model,-/// rensuuji and line-end ideographic spaces.+/// rensuuji, rotated roman in vertical text, line-end ideographic spaces and roman word breaks.fn japanese_composition(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &CharFields, pv: &Value, doc: &designcraft_doc::Document) {egui::Grid::new("cjkcomp").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {crate::rtl::label(ui, crate::i18n::tr(lang, "Kinsoku Set:"));@@ -323,10 +734,10 @@ fn japanese_composition(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &Chard.fields.insert("p.kinsoku".into(), Value::Null);}for k in &sets {- if ui.selectable_label(name.as_deref() == Some(k.name.as_str()), crate::rtl::widget(ui, kinsoku_label(lang, &k.name))).clicked() {- if let Ok(v) = serde_json::to_value(k) {- d.fields.insert("p.kinsoku".into(), v);- }+ if ui.selectable_label(name.as_deref() == Some(k.name.as_str()), crate::rtl::widget(ui, kinsoku_label(lang, &k.name))).clicked()+ && let Ok(v) = serde_json::to_value(k)+ {+ d.fields.insert("p.kinsoku".into(), v);}}});@@ -375,13 +786,13 @@ fn japanese_composition(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &Char});ui.end_row();crate::rtl::label(ui, crate::i18n::tr(lang, "Leading Model:"));- // Labelled by where the composer measures the leading from (`cjk_line_reference` in- // compose): `akiAbove` from the em box top, `akiBelow` from its bottom.+ // Space below (`akiBelow`) measures the leading from the em box top, space above from its+ // bottom (`cjk_line_reference` in compose).let mut opts = vec![- (json!("akiAbove"), "Em Box Top/Right"),+ (json!("akiBelow"), "Em Box Top/Right"),(json!("center"), "Em Box Center"),(json!("roman"), "Roman Baseline"),- (json!("akiBelow"), "Em Box Bottom/Left"),+ (json!("akiAbove"), "Em Box Bottom/Left"),];// Kept from IDML; not offered otherwise.if cf.get(d, "leadingModel") == json!("centerDown") {@@ -391,37 +802,81 @@ fn japanese_composition(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, cf: &Charui.end_row();});para_check(ui, d, pv, "rensuuji", crate::i18n::tr(lang, "Rensuuji"));+ para_check(ui, d, pv, "rotateRoman", crate::i18n::tr(lang, "Rotate Roman Characters in Vertical Text"));para_check(ui, d, pv, "treatIdeographicSpaceAsSpace", crate::i18n::tr(lang, "Absorb Ideographic Space at Line End"));+ para_check(ui, d, pv, "romanWordBreak", crate::i18n::tr(lang, "Roman Word Break"));}-/// Grid Settings: whether lines align to the baseline grid, and only the first line.+/// Grid Settings: the point of each line that sits on the baseline grid (or none), only the+/// first line, gyoudori and paragraph gyoudori.fn grid_settings(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, pv: &Value) {use designcraft_doc::GridAlign;+ use designcraft_doc::cjk::CharacterAlignment as R;let cur: GridAlign = serde_json::from_value(para_value(d, pv, "gridAlign")).unwrap_or_default();+ let reference: R = serde_json::from_value(para_value(d, pv, "gridReference")).unwrap_or_default();let set = |d: &mut Dialog, g: GridAlign| {if let Ok(v) = serde_json::to_value(g) {d.fields.insert("p.gridAlign".into(), v);}};- egui::Grid::new("cjkgrid").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {- crate::rtl::label(ui, crate::i18n::tr(lang, "Grid Alignment:"));- let on = cur != GridAlign::None;- let shown = crate::i18n::tr(lang, if on { "Roman Baseline" } else { "None" });- egui::ComboBox::from_id_salt("cjkgridalign").selected_text(crate::rtl::widget(ui, shown)).width(220.0).show_ui(ui, |ui| {- if ui.selectable_label(!on, crate::rtl::widget(ui, crate::i18n::tr(lang, "None"))).clicked() {+ const REFERENCES: &[(R, &str)] = &[+ (R::EmTop, "Em Box Top"),+ (R::EmCenter, "Em Box Center"),+ (R::Baseline, "Roman Baseline"),+ (R::EmBottom, "Em Box Bottom"),+ (R::IcfTop, "ICF Top"),+ (R::IcfBottom, "ICF Bottom"),+ ];+ let on = cur != GridAlign::None;+ grid("cjkgrid").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Grid Alignment:"));+ let shown = if on { REFERENCES.iter().find(|r| r.0 == reference).map_or("", |r| r.1) } else { "None" };+ egui::ComboBox::from_id_salt("cjkgridalign").selected_text(crate::rtl::widget(ui, tr(lang, shown))).width(220.0).show_ui(ui, |ui| {+ if ui.selectable_label(!on, crate::rtl::widget(ui, tr(lang, "None"))).clicked() {set(d, GridAlign::None);}- if ui.selectable_label(on, crate::rtl::widget(ui, crate::i18n::tr(lang, "Roman Baseline"))).clicked() && !on {- set(d, GridAlign::AllLines);+ for (r, label) in REFERENCES {+ if ui.selectable_label(on && *r == reference, crate::rtl::widget(ui, tr(lang, label))).clicked() {+ if !on {+ set(d, GridAlign::AllLines);+ }+ if let Ok(v) = serde_json::to_value(r) {+ d.fields.insert("p.gridReference".into(), v);+ }+ }}});ui.end_row();});let mut first = cur == GridAlign::FirstLineOnly;- let check = egui::Checkbox::new(&mut first, crate::rtl::widget(ui, crate::i18n::tr(lang, "Align Only First Line to Grid")));- if ui.add_enabled(cur != GridAlign::None, check).changed() {+ let check = egui::Checkbox::new(&mut first, crate::rtl::widget(ui, tr(lang, "Align Only First Line to Grid")));+ if ui.add_enabled(on, check).changed() {set(d, if first { GridAlign::FirstLineOnly } else { GridAlign::AllLines });}+ ui.add_space(4.0);+ let lines = para_value(d, pv, "gridGyoudori").as_u64().unwrap_or(0);+ grid("cjkgyoudori").show(ui, |ui| {+ crate::rtl::label(ui, tr(lang, "Gyoudori:"));+ ui.horizontal(|ui| {+ // Empty or 0: automatic (as many grid lines as the leading needs).+ let field = crate::widgets::NumField::number("gridGyoudori", (lines > 0).then_some(lines as f64), "", 0)+ .width(80.0)+ .range(0.0, 100.0)+ .presets(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);+ if let Some(n) = field.show_or_clear(ui) {+ d.fields.insert("p.gridGyoudori".into(), json!(n.map_or(0, |n| n.round().clamp(0.0, 100.0) as u64)));+ }+ if lines == 0 {+ crate::rtl::label(ui, tr(lang, "Auto"));+ }+ });+ ui.end_row();+ });+ // No effect while gyoudori is automatic.+ let mut block = para_value(d, pv, "paragraphGyoudori").as_bool().unwrap_or(false);+ if ui.add_enabled(lines > 0, egui::Checkbox::new(&mut block, crate::rtl::widget(ui, tr(lang, "Use Paragraph Gyoudori")))).changed() {+ d.fields.insert("p.paragraphGyoudori".into(), json!(block));+ }}#[cfg(test)]@@ -473,12 +928,20 @@ mod tests {let base = [("general", "General"), ("export", "Export Tagging")];let ids = |app: &DesignApp, para: bool| sections(crate::cjk_features(app), para, &base).into_iter().map(|s| s.0).collect::<Vec<_>>();app.run("prefs.set", json!({"cjkFeatures": true})).unwrap();- assert_eq!(ids(&app, true), ["general", "cjk.tcy", "cjk.kenten", "cjk.composition", "cjk.grid", "export", "cjk.warichu"]);- assert_eq!(ids(&app, false), ["general", "cjk.tcy", "cjk.kenten", "export", "cjk.warichu"]);- assert_eq!(- sections(true, false, &[("general", "General")]).into_iter().map(|s| s.0).collect::<Vec<_>>(),- ["general", "cjk.tcy", "cjk.kenten", "cjk.warichu"]- );+ let character =+ ["cjk.tcy", "cjk.rubyPlacement", "cjk.rubyFont", "cjk.rubyLonger", "cjk.rubyColor", "cjk.kenten", "cjk.kentenColor", "cjk.shatai"];+ let mut para = vec!["general", "cjk.autoTcy"];+ para.extend(character);+ para.extend(["cjk.composition", "cjk.grid", "export", "cjk.warichu"]);+ assert_eq!(ids(&app, true), para);+ let mut chars = vec!["general"];+ chars.extend(character);+ chars.extend(["export", "cjk.warichu"]);+ assert_eq!(ids(&app, false), chars);+ let mut last = vec!["general"];+ last.extend(character);+ last.push("cjk.warichu");+ assert_eq!(sections(true, false, &[("general", "General")]).into_iter().map(|s| s.0).collect::<Vec<_>>(), last);app.run("prefs.set", json!({"cjkFeatures": false})).unwrap();assert_eq!(ids(&app, true), ["general", "export"]);assert_eq!(ids(&app, false), ["general", "export"]);@@ -506,6 +969,11 @@ mod tests {assert!(app.ui.dialog.is_some(), "{lang} {id} {} stays open", s.id);}}+ for (id, _) in RUBY_SECTIONS {+ app.ui.dialog = Some(Dialog::new("ruby", json!({"text": "かんじ", "base": {}, "section": id})));+ painted(&mut app, &ctx);+ assert!(app.ui.dialog.is_some(), "{lang} ruby {id} stays open");+ }}}@@ -527,7 +995,7 @@ mod tests {painted(&mut app, &ctx);{let d = app.ui.dialog.as_mut().unwrap();- pick_kenten(d, &CharFields { base: &Value::Null, sparse: false }, Some("\u{25CF}"));+ pick_kenten(d, &CharFields { base: &Value::Null, sparse: false }, Some(KentenKind::BlackCircle));d.fields.insert("section".into(), json!("cjk.composition"));d.fields.insert("p.kinsoku".into(), serde_json::to_value(&hard).unwrap());d.fields.insert("p.mojikumi".into(), json!(moji));@@ -541,12 +1009,13 @@ mod tests {assert_eq!(st.para.kinsoku, Some(Some(hard)));assert_eq!(st.para.mojikumi.as_deref(), Some("MojikumiTable/Body Text"));assert_eq!(st.para.kinsoku_hang, Some(designcraft_doc::cjk::KinsokuHang::Regular));- assert_eq!((st.chars.kenten, st.chars.kenten_character.as_deref()), (Some(true), Some("\u{25CF}")));+ assert_eq!((st.chars.kenten, st.chars.kenten_kind), (Some(true), Some(KentenKind::BlackCircle)));+ assert_eq!(st.chars.kenten_character.as_deref(), Some("\u{25CF}"));let a = app.run("type.selectionAttrs", json!({})).unwrap();assert_eq!(a["para"]["kinsoku"]["name"], "HardKinsoku", "the paragraph follows its style");assert_eq!(a["para"]["mojikumi"], "MojikumiTable/Body Text");assert_eq!(a["chars"]["kenten"], true);- assert_eq!(a["chars"]["kentenCharacter"], "\u{25CF}");+ assert_eq!(a["chars"]["kentenKind"], "blackCircle");// Default Rules (`null`) replaces the set.app.ui.dialog = Some(Dialog::new("paragraphStyleOptions", json!({"name": "Body", "section": "cjk.composition", "p.kinsoku": null})));@@ -561,10 +1030,77 @@ mod tests {{let d = app.ui.dialog.as_mut().unwrap();let base = json!({});- pick_kenten(d, &CharFields { base: &base, sparse: true }, Some(""));+ pick_kenten(d, &CharFields { base: &base, sparse: true }, Some(KentenKind::SesameDot));}crate::dialogs::confirm(&mut app).unwrap();let st = app.session.active().unwrap().doc.styles.char_style("Emphasis").cloned().unwrap();- assert_eq!((st.chars.kenten, st.chars.kenten_character.as_deref()), (Some(true), Some("")));+ assert_eq!((st.chars.kenten, st.chars.kenten_kind), (Some(true), Some(KentenKind::SesameDot)));+ assert!(st.chars.ruby_alignment.is_none() && st.chars.shatai_angle.is_none(), "nothing else is set");+ }++ #[test]+ fn ruby_alignment_and_shatai_angle_reach_the_style_and_its_paragraph() {+ use designcraft_doc::ruby::RubyAlignment;+ let mut app = app_with_text();+ app.run("prefs.set", json!({"cjkFeatures": true})).unwrap();+ let ctx = egui::Context::default();+ app.ui.dialog = Some(Dialog::new("paragraphStyleOptions", json!({"name": "Body", "section": "cjk.rubyPlacement"})));+ painted(&mut app, &ctx);+ {+ let d = app.ui.dialog.as_mut().unwrap();+ d.fields.insert("c.rubyAlignment".into(), json!("equalAki"));+ d.fields.insert("section".into(), json!("cjk.shatai"));+ d.fields.insert("c.shataiMagnification".into(), json!(20.0));+ d.fields.insert("c.shataiAngle".into(), json!(60.0));+ d.fields.insert("section".into(), json!("cjk.grid"));+ d.fields.insert("p.gridAlign".into(), json!("allLines"));+ d.fields.insert("p.gridReference".into(), json!("emCenter"));+ d.fields.insert("p.gridGyoudori".into(), json!(2));+ }+ painted(&mut app, &ctx);+ crate::dialogs::confirm(&mut app).unwrap();+ let doc = app.session.active().unwrap().doc.clone();+ let st = doc.styles.para("Body").unwrap();+ assert_eq!(st.chars.ruby_alignment, Some(RubyAlignment::EqualAki));+ assert_eq!((st.chars.shatai_magnification, st.chars.shatai_angle), (Some(20.0), Some(60.0)));+ assert_eq!((st.para.grid_reference, st.para.grid_gyoudori), (Some(designcraft_doc::cjk::CharacterAlignment::EmCenter), Some(2)));+ let a = app.run("type.selectionAttrs", json!({})).unwrap();+ assert_eq!(a["chars"]["rubyAlignment"], "equalAki", "the paragraph follows its style");+ assert_eq!(a["chars"]["shataiAngle"], 60.0);+ assert_eq!(a["para"]["gridGyoudori"], 2);+ }++ #[test]+ fn ruby_dialog_applies_its_settings_with_type_ruby() {+ let mut app = app_with_text();+ app.run("prefs.set", json!({"cjkFeatures": true})).unwrap();+ let story = app.run("type.selectionAttrs", json!({})).unwrap()["story"].clone();+ app.run("text.select", json!({"story": story, "anchor": 0, "focus": "漢字".len()})).unwrap();+ app.run("app.rubyDialog", json!({})).unwrap();+ let ctx = egui::Context::default();+ painted(&mut app, &ctx);+ {+ let d = app.ui.dialog.as_mut().unwrap();+ assert_eq!((d.id.as_str(), d.s("section").as_str()), ("ruby", "cjk.rubyPlacement"));+ assert_eq!(d.fields["base"]["rubyAlignment"], "jis", "the panes show the selection's settings");+ d.fields.insert("text".into(), json!("かんじ"));+ d.fields.insert("c.rubyAlignment".into(), json!("center"));+ d.fields.insert("section".into(), json!("cjk.rubyFont"));+ d.fields.insert("c.rubyFontSize".into(), json!(5.0));+ d.fields.insert("c.rubyXScale".into(), json!(0.8));+ }+ painted(&mut app, &ctx);+ let params = ruby_params(app.ui.dialog.as_ref().unwrap());+ assert_eq!(params, json!({"text": "かんじ", "alignment": "center", "size": 5.0, "xScale": 80.0}));+ crate::dialogs::confirm(&mut app).unwrap();+ let a = app.run("type.selectionAttrs", json!({})).unwrap();+ assert_eq!(a["chars"]["ruby"], "かんじ");+ assert_eq!(a["chars"]["rubyAlignment"], "center");+ assert_eq!(a["chars"]["rubyFontSize"], 5.0);+ assert!((a["chars"]["rubyXScale"].as_f64().unwrap() - 0.8).abs() < 1e-9);+ // Reopened, the dialog shows them.+ app.run("app.rubyDialog", json!({})).unwrap();+ let d = app.ui.dialog.as_ref().unwrap();+ assert_eq!((d.s("text").as_str(), d.fields["base"]["rubyFontSize"].as_f64()), ("かんじ", Some(5.0)));}}diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rsindex ed7c4f047..09a72e361 100644--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@ -98,6 +98,147 @@ const TABLE: &[(&str, [&str; 5])] = &[),("Grid Settings", ["Rastereinstellungen", "Paramètres de grille", "Ajustes de cuadrícula", "グリッド設定", "网格设置"]),("Warichu Settings", ["Warichu-Einstellungen", "Paramètres Warichu", "Ajustes de Warichu", "割注設定", "割注设置"]),+ (+ "Auto Tate-chu-yoko Settings",+ [+ "Automatische Tate-Chu-Yoko-Einstellungen",+ "Paramètres Tate-Chu-Yoko automatiques",+ "Ajustes de Tate-Chu-Yoko automático",+ "自動縦中横設定",+ "自动纵中横设置",+ ],+ ),+ (+ "Ruby Placement and Spacing",+ ["Ruby-Position und -Abstand", "Position et espacement ruby", "Posición y espaciado de ruby", "ルビの位置と間隔", "注音位置和间距"],+ ),+ (+ "Ruby Font and Size",+ ["Ruby-Schrift und -Größe", "Police et taille ruby", "Fuente y tamaño de ruby", "ルビのフォントとサイズ", "注音字体和大小"],+ ),+ (+ "Adjustment When Ruby Is Longer Than Parent",+ [+ "Anpassung bei Ruby länger als Grundtext",+ "Ajustement si le ruby dépasse le texte parent",+ "Ajuste cuando el ruby es más largo que la base",+ "ルビが親文字より長い時の調整",+ "注音长于基础文字时的调整",+ ],+ ),+ ("Ruby Color", ["Ruby-Farbe", "Couleur ruby", "Color de ruby", "ルビカラー", "注音颜色"]),+ ("Kenten Color", ["Kenten-Farbe", "Couleur kenten", "Color de kenten", "圏点カラー", "圈点颜色"]),+ ("Shatai", ["Shatai", "Shatai", "Shatai", "斜体", "斜体"]),+ ("Tate-chu-yoko Digits:", ["Tate-Chu-Yoko-Ziffern:", "Chiffres Tate-Chu-Yoko:", "Dígitos Tate-Chu-Yoko:", "組数字(桁まで):", "纵中横位数:"]),+ (+ "Include Roman Characters",+ ["Lateinische Zeichen einbeziehen", "Inclure les caractères latins", "Incluir caracteres latinos", "欧文も含める", "包括罗马字符"],+ ),+ ("Ruby Type:", ["Ruby-Art:", "Type de ruby:", "Tipo de ruby:", "種類:", "注音类型:"]),+ ("Per-Character Ruby", ["Einzelzeichen-Ruby", "Ruby par caractère", "Ruby por carácter", "モノルビ", "单字注音"]),+ ("Group Ruby", ["Gruppen-Ruby", "Ruby de groupe", "Ruby de grupo", "グループルビ", "组注音"]),+ ("Left/Top", ["Links/oben", "Gauche/haut", "Izquierda/arriba", "肩付き", "左/上"]),+ ("Centered", ["Zentriert", "Centré", "Centrado", "中付き", "居中"]),+ ("Right/Bottom", ["Rechts/unten", "Droite/bas", "Derecha/abajo", "右/下揃え", "右/下"]),+ ("Full Justify", ["Blocksatz", "Justifié", "Justificado", "両端揃え", "两端对齐"]),+ ("1-2-1 (JIS) Rule", ["1-2-1-Regel (JIS)", "Règle 1-2-1 (JIS)", "Regla 1-2-1 (JIS)", "1-2-1(JIS)ルール", "1-2-1 (JIS) 规则"]),+ ("Equal Aki", ["Gleicher Abstand", "Espacement égal", "Espaciado igual", "均等アキ", "均等间距"]),+ (+ "1 Ruby Character Aki",+ ["1 Ruby-Zeichen Abstand", "Espace de 1 caractère ruby", "Espacio de 1 carácter ruby", "1ルビ文字アキ", "1注音字符间距"],+ ),+ ("Above/Right", ["Oben/rechts", "Au-dessus/à droite", "Arriba/derecha", "上/右", "上/右"]),+ ("Below/Left", ["Unten/links", "En dessous/à gauche", "Abajo/izquierda", "下/左", "下/左"]),+ (+ "Offset from Parent",+ [+ "Versatz zum Grundtext",+ "Décalage par rapport au texte parent",+ "Desplazamiento respecto a la base",+ "親文字からのオフセット",+ "与基础文字的偏移",+ ],+ ),+ ("Across the Line:", ["Quer zur Zeile:", "Perpendiculaire à la ligne:", "Perpendicular a la línea:", "横組み上下/縦組み左右:", "垂直于行:"]),+ ("Along the Line:", ["Entlang der Zeile:", "Le long de la ligne:", "A lo largo de la línea:", "横組み左右/縦組み上下:", "沿行方向:"]),+ ("Parent's Font", ["Schrift des Grundtexts", "Police du texte parent", "Fuente de la base", "親文字と同じ", "基础文字的字体"]),+ (+ "Use OpenType Pro Ruby Glyphs",+ [+ "OpenType-Pro-Ruby-Glyphen verwenden",+ "Utiliser les glyphes ruby OpenType Pro",+ "Usar glifos ruby de OpenType Pro",+ "OpenType Pro のルビ字形を使用",+ "使用 OpenType Pro 注音字形",+ ],+ ),+ ("Fit to Width", ["An Breite anpassen", "Ajuster à la largeur", "Ajustar al ancho", "幅に合わせる", "适合宽度"]),+ ("Ruby Overhang:", ["Ruby-Überhang:", "Débordement ruby:", "Desbordamiento de ruby:", "文字かけ処理:", "注音悬挂:"]),+ ("1 Ruby Character", ["1 Ruby-Zeichen", "1 caractère ruby", "1 carácter ruby", "ルビ1文字分", "1个注音字符"]),+ ("1/2 Ruby Character", ["1/2 Ruby-Zeichen", "1/2 caractère ruby", "1/2 carácter ruby", "ルビ半文字分", "1/2个注音字符"]),+ ("1 Parent Character", ["1 Grundzeichen", "1 caractère parent", "1 carácter base", "親1文字分", "1个基础字符"]),+ ("1/2 Parent Character", ["1/2 Grundzeichen", "1/2 caractère parent", "1/2 carácter base", "親半文字分", "1/2个基础字符"]),+ ("Unlimited", ["Unbegrenzt", "Illimité", "Ilimitado", "無制限", "无限制"]),+ (+ "Parent Character Spacing:",+ ["Abstand im Grundtext:", "Espacement du texte parent:", "Espaciado de la base:", "親文字間の調整:", "基础文字间距调整:"],+ ),+ ("No Adjustment", ["Keine Anpassung", "Aucun ajustement", "Sin ajuste", "調整しない", "不调整"]),+ ("Both Sides", ["Beide Seiten", "Des deux côtés", "Ambos lados", "両サイド", "两侧"]),+ ("1-2-1 Aki", ["1-2-1-Abstand", "Espacement 1-2-1", "Espaciado 1-2-1", "1-2-1アキ", "1-2-1 间距"]),+ (+ "Shrink Ruby Width Automatically",+ [+ "Ruby-Breite automatisch verringern",+ "Réduire automatiquement la largeur ruby",+ "Reducir automáticamente el ancho de ruby",+ "ルビの文字幅を自動的に詰める",+ "自动压缩注音宽度",+ ],+ ),+ ("Minimum Scale:", ["Minimale Skalierung:", "Échelle minimale:", "Escala mínima:", "最小比率:", "最小比例:"]),+ (+ "Auto Align at Line Start/End",+ [+ "Am Zeilenanfang/-ende automatisch ausrichten",+ "Alignement auto en début/fin de ligne",+ "Alinear automáticamente al inicio/fin de línea",+ "自動行頭/行末揃え",+ "行首/行尾自动对齐",+ ],+ ),+ ("Text Color", ["Textfarbe", "Couleur du texte", "Color del texto", "[自動]", "文字颜色"]),+ (+ "Distance from Parent:",+ ["Abstand zum Grundtext:", "Distance au texte parent:", "Distancia a la base:", "親文字からの間隔:", "与基础文字的距离:"],+ ),+ ("Fisheye", ["Fischauge", "Œil de poisson", "Ojo de pez", "蛇の目", "蛇目"]),+ ("Magnification:", ["Verkleinerung:", "Réduction:", "Reducción:", "縮小率:", "缩小率:"]),+ ("Adjust Rotation", ["Drehung anpassen", "Ajuster la rotation", "Ajustar rotación", "ライン揃え", "调整旋转"]),+ ("Adjust Tsume", ["Tsume anpassen", "Ajuster le tsume", "Ajustar tsume", "ツメの調整", "调整字距压缩"]),+ (+ "Rotate Roman Characters in Vertical Text",+ [+ "Lateinische Zeichen in vertikalem Text drehen",+ "Faire pivoter les caractères latins en texte vertical",+ "Girar caracteres latinos en texto vertical",+ "縦組み中の欧文回転",+ "直排中旋转罗马字符",+ ],+ ),+ (+ "Roman Word Break",+ ["Lateinische Wörter beliebig trennen", "Coupure libre des mots latins", "Corte libre de palabras latinas", "欧文泣き別れ", "西文单词断开"],+ ),+ ("Em Box Top", ["Geviert oben", "Haut du cadratin", "Parte superior del cuadratín", "仮想ボディの上", "全角字框上"]),+ ("Em Box Bottom", ["Geviert unten", "Bas du cadratin", "Parte inferior del cuadratín", "仮想ボディの下", "全角字框下"]),+ ("ICF Top", ["ICF oben", "Haut ICF", "Parte superior ICF", "平均字面の上", "平均字面上"]),+ ("ICF Bottom", ["ICF unten", "Bas ICF", "Parte inferior ICF", "平均字面の下", "平均字面下"]),+ ("Gyoudori:", ["Gyoudori:", "Gyoudori:", "Gyoudori:", "行取り:", "行取:"]),+ (+ "Use Paragraph Gyoudori",+ ["Absatz-Gyoudori verwenden", "Utiliser le gyoudori de paragraphe", "Usar gyoudori de párrafo", "段落行取りを使用", "使用段落行取"],+ ),("Up/Down Position:", ["Position oben/unten:", "Position haut/bas:", "Posición arriba/abajo:", "上下位置:", "上下位置:"]),("Left/Right Position:", ["Position links/rechts:", "Position gauche/droite:", "Posición izquierda/derecha:", "左右位置:", "左右位置:"]),("Kenten Type:", ["Kenten-Art:", "Type de kenten:", "Tipo de kenten:", "圏点種類:", "圈点类型:"]),diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rsindex f218747c1..771f10297 100644--- a/crates/ui-egui/src/i18n/ja.rs+++ b/crates/ui-egui/src/i18n/ja.rs@@ -54,6 +54,60 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Japanese Composition Settings", "日本語文字組版"),("Grid Settings", "グリッド設定"),("Warichu Settings", "割注設定"),+ ("Auto Tate-chu-yoko Settings", "自動縦中横設定"),+ ("Ruby Placement and Spacing", "ルビの位置と間隔"),+ ("Ruby Font and Size", "ルビのフォントとサイズ"),+ ("Adjustment When Ruby Is Longer Than Parent", "ルビが親文字より長い時の調整"),+ ("Ruby Color", "ルビカラー"),+ ("Kenten Color", "圏点カラー"),+ ("Shatai", "斜体"),+ ("Tate-chu-yoko Digits:", "組数字(桁まで):"),+ ("Include Roman Characters", "欧文も含める"),+ ("Ruby Type:", "種類:"),+ ("Per-Character Ruby", "モノルビ"),+ ("Group Ruby", "グループルビ"),+ ("Left/Top", "肩付き"),+ ("Centered", "中付き"),+ ("Right/Bottom", "右/下揃え"),+ ("Full Justify", "両端揃え"),+ ("1-2-1 (JIS) Rule", "1-2-1(JIS)ルール"),+ ("Equal Aki", "均等アキ"),+ ("1 Ruby Character Aki", "1ルビ文字アキ"),+ ("Above/Right", "上/右"),+ ("Below/Left", "下/左"),+ ("Offset from Parent", "親文字からのオフセット"),+ ("Across the Line:", "横組み上下/縦組み左右:"),+ ("Along the Line:", "横組み左右/縦組み上下:"),+ ("Parent's Font", "親文字と同じ"),+ ("Use OpenType Pro Ruby Glyphs", "OpenType Pro のルビ字形を使用"),+ ("Fit to Width", "幅に合わせる"),+ ("Ruby Overhang:", "文字かけ処理:"),+ ("1 Ruby Character", "ルビ1文字分"),+ ("1/2 Ruby Character", "ルビ半文字分"),+ ("1 Parent Character", "親1文字分"),+ ("1/2 Parent Character", "親半文字分"),+ ("Unlimited", "無制限"),+ ("Parent Character Spacing:", "親文字間の調整:"),+ ("No Adjustment", "調整しない"),+ ("Both Sides", "両サイド"),+ ("1-2-1 Aki", "1-2-1アキ"),+ ("Shrink Ruby Width Automatically", "ルビの文字幅を自動的に詰める"),+ ("Minimum Scale:", "最小比率:"),+ ("Auto Align at Line Start/End", "自動行頭/行末揃え"),+ ("Text Color", "[自動]"),+ ("Distance from Parent:", "親文字からの間隔:"),+ ("Fisheye", "蛇の目"),+ ("Magnification:", "縮小率:"),+ ("Adjust Rotation", "ライン揃え"),+ ("Adjust Tsume", "ツメの調整"),+ ("Rotate Roman Characters in Vertical Text", "縦組み中の欧文回転"),+ ("Roman Word Break", "欧文泣き別れ"),+ ("Em Box Top", "仮想ボディの上"),+ ("Em Box Bottom", "仮想ボディの下"),+ ("ICF Top", "平均字面の上"),+ ("ICF Bottom", "平均字面の下"),+ ("Gyoudori:", "行取り:"),+ ("Use Paragraph Gyoudori", "段落行取りを使用"),("Up/Down Position:", "上下位置:"),("Left/Right Position:", "左右位置:"),("Kenten Type:", "圏点種類:"),diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 8e4f17a3f..a3e69ce8a 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -946,7 +946,10 @@ pub fn run_ui(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value,let at = if t.range().is_empty() { t.range().start } else { t.range().start + 1 };story.char_format_at(at).over.ruby.clone()});- app.ui.dialog = Some(crate::dialogs::Dialog::new("ruby", json!({"text": cur.unwrap_or_default()})));+ let cur = cur.unwrap_or_default();+ // The ruby settings the panes show: the selection's resolved character attributes.+ let base = crate::panels::text_attrs(app).and_then(|a| a.get("chars").cloned()).unwrap_or(Value::Null);+ app.ui.dialog = Some(crate::dialogs::Dialog::new("ruby", json!({"text": cur, "base": base})));Ok(Value::Null)}"app.paragraphRulesDialog" => {