Files
designcraft/crates/doc/src/cjk.rs
T
aiongg aadd54a926 Merge upstream main 736acff into next
Upstream main moved 9e4f694 -> 736acff by 10 squashes: #258, #285, #153, #280, #288, #281,
#176, #299, #298, #297. New to next: #258 (datamerge test), #153 (temporary files and release
inputs), #280 (warichu), #176 (PDF image conversion cache), #297 (graphics backend before the
window). Already on next: #285, #288, #281, #299, #298.

Conflict: ROADMAP.md: next's lines; CJK1 takes main's wording (ruby unfinished, warichu set after the line is broken)
Conflict: crates/compose/src/lib.rs: list labels (#298): next's list_label structure; paragraph start / break moves: next's `go` (with #295's sub-columns) under the maintainer's #285 comment; Cursor: next's start/next_page/next_baseline with tops; line placement: #280's warichu::place right after layout_line, before next's trimmed trailing spaces and the drop cap splice (so neither is stacked and the spaces follow the closed-up end_x); caret(): next's drop-cap branch first, then #280's stacked-row metrics
Conflict: crates/compose/src/tests.rs: next's tests kept; #280's tests auto-merged
Conflict: crates/engine/src/cmd/text.rs: both (next's TypingFormat/typing_format, #280's warichu_cmd)
Conflict: crates/idml/src/tests.rs: next's side; #280's warichu round-trip test auto-merged
Conflict: crates/pdf/src/export.rs: #176's content cache and test counter with next's RasterMode (no Exporter `interpolate` field on next, so the maintainer's `mode.interpolate &= self.interpolate` is not carried); test exporter gets next's drawing_items field
Conflict: crates/ui-egui/src/canvas.rs: #280's compose::highlight_quads (its RTL branch equals next's mixed-direction spans) followed by next's drop-cap highlight
Conflict: crates/ui-egui/src/menus.rs: next's formatting_affects_text test kept

Auto-merge duplicates removed: #288's table-style tests and #298's list test in idml tests.rs,
#288's tests in doc styles.rs and #285's docx test (both files equal next's), #281's dialog
tests in dialogs.rs (equals next's) and its menu_button/menu_max_height/clipped_submenu in
menus.rs. contributors/people.toml takes main's (next had a duplicated
[people.emanuelebonaventura] table from the 9e4f694 merge, which broke the ui-egui build
script's TOML parse).

Maintainer edits carried over: #285 break characters and Next Column through one closure
(next's `go`, comment added); #281 viewport-aware menu_button in the app bar and the Paragraph
menu, per-dialog widths clamped to the window (all already on next); #280 warichu after the
last-line rules (layout_line with ends_para/forced_mid) and rules at each warichu row's
baseline (rule_baseline in render and pdf text_rules); #176 CMYK fallback through
lossless(.., mode) and its updated contract tests; #258 test fixes; #153 and #297 as landed.
2026-10-10 08:20:36 +00:00

163 lines
4.9 KiB
Rust

//! Portable CJK typography data. No platform fonts or UI dependencies.
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct CompositeFont {
pub name: String,
pub entries: Vec<CompositeFontEntry>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct CompositeFontEntry {
pub name: String,
/// Empty character set is the base entry, independent of its localized name.
pub characters: String,
pub family: String,
pub style: String,
pub relative_size: f64,
pub horizontal_scale: f64,
pub vertical_scale: f64,
/// Percentage of the original em, as a fraction.
pub baseline_shift: f64,
pub scale_option: bool,
}
impl Default for CompositeFontEntry {
fn default() -> Self {
Self {
name: String::new(),
characters: String::new(),
family: String::new(),
style: "Regular".into(),
relative_size: 1.0,
horizontal_scale: 1.0,
vertical_scale: 1.0,
baseline_shift: 0.0,
scale_option: true,
}
}
}
impl CompositeFont {
pub fn entry(&self, c: char) -> Option<&CompositeFontEntry> {
self.entries
.iter()
.rev()
.find(|e| !e.characters.is_empty() && e.characters.contains(c))
.or_else(|| self.entries.iter().find(|e| e.characters.is_empty()))
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Kinsoku {
pub name: String,
pub no_start: String,
pub no_end: String,
pub inseparable: String,
pub hanging: String,
}
impl Kinsoku {
/// Explicitly supplied character sets take precedence over the fallback table.
pub fn allows(&self, a: char, b: char) -> bool {
!(self.no_end.contains(a) || self.no_start.contains(b) || (a == b && self.inseparable.contains(a)))
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum LeadingModel {
#[default]
Roman,
AkiBelow,
AkiAbove,
Center,
CenterDown,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum CharacterAlignment {
#[default]
Baseline,
EmTop,
EmCenter,
EmBottom,
IcfTop,
IcfBottom,
}
/// How the short lines of a warichu run sit inside the run's block.
/// `Auto` centres them. `Justify` spreads a short line out to the block width.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum WarichuAlignment {
#[default]
Auto,
Left,
Center,
Right,
Justify,
}
impl Kinsoku {
/// Clean-room Unicode rules for the named CJK sets. Explicit document tables
/// are imported separately and always take precedence over these defaults.
pub fn named(name: &str) -> Option<Self> {
let name = name.trim_start_matches("KinsokuTable/").trim_start_matches("$ID/");
let hard = match name {
"HardKinsoku" | "kHardKinsokuName" => true,
"SoftKinsoku"
| "kSoftKinsokuName"
| "SimplifiedChineseKinsoku"
| "kSimpChineseKinsokuName"
| "TraditionalChineseKinsoku"
| "kTradChineseKinsokuName"
| "KoreanKinsoku"
| "kKoreanKinsokuName" => false,
_ => return None,
};
let mut no_start = "、。,.・:;?!)」』】〕〉》}]〙〗’”!),.:;?]}".to_string();
if hard {
no_start.push_str("ーぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮヵヶ々〻ゝゞヽヾ");
}
Some(Self {
name: name.into(),
no_start,
no_end: "(「『【〔〈《{[〘〖‘“([{".into(),
hanging: "、。,.,.".into(),
inseparable: String::new(),
})
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum KinsokuHang {
#[default]
None,
Regular,
Force,
}
/// IDML spacing tables resolved by `mojikumi::Rules` for composition and diagnostics.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct MojikumiTable {
pub name: String,
pub based_on: String,
pub overrides: Vec<MojikumiAki>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct MojikumiAki {
pub target_class: i16,
pub side_class: i16,
pub after: bool,
pub minimum: f64,
pub desired: f64,
pub maximum: f64,
pub priority: i16,
pub does_not_float: bool,
}