Type: Insert Aki Left and Right add space before and after a character

Characters take two new attributes, `akiLeft` and `akiRight`: space
before and after each character in reading order, in thousandths of an
em from 0 to 1000, measured as tracking is. `text.setFormat`,
`text.setRangeStyle` and character styles set them; values that are not
numbers or are outside the range are refused, and a file holding one
outside the range opens with the nearer end. Both are saved only when
not 0.

- Layout: Left is the space above a character in vertical type and on
  its right in right-to-left type. Wrapping counts the space, a line's
  end keeps it when aligned, and justification and Optical kerning
  leave it at its set width. A ligature, a letter with its marks and a
  tate-chu-yoko block take the values of their first character.
- With Fractional Widths off or System Layout on, the space before and
  the space after a character are each set in whole points and added
  to its rounded width, so justification keeps them at that width. A
  tate-chu-yoko block rounds the space above and below it the same way.
- Character panel: with Show East Asian Options on, Insert Aki Left and
  Insert Aki Right fields with 0, 250, 500 and 1000 in their menus;
  Reset Panel sets both to 0.
- Character Style Options › Advanced Character Formats shows Insert
  Aki Left and Insert Aki Right, with the Character panel's 0, 250, 500
  and 1000 in their menus; a typed value below 0 or past 1000 sets 0 or
  1000, and Reset Panel unsets both.
- SVG export: live text places each character the space moves, and
  type on a path with Insert Aki is written as outlines.

Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo committed 2026-11-12 10:24:38 -08:00
1 parent a15a4abc5c
commit 89748b0360
54 files changed
+818 -68

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ mod wrap;
pub use area::{AreaFit, AreaOptions, PathAlign, PathEffect, TextFlow, TextWrap, VerticalAlign, WrapShape};
use char_style::yes;
pub use char_style::{CharAlign, CharPosition, CharStyle, Digits, FontHeightReference, GlyphChoice, ScriptMetrics};
pub use char_style::{CharAlign, CharPosition, CharStyle, Digits, FontHeightReference, GlyphChoice, MAX_AKI, ScriptMetrics};
pub use composite::{
COMPOSITE_BASELINE, COMPOSITE_FONTS_MAX, COMPOSITE_NAME_MAX, COMPOSITE_SCALE, COMPOSITE_SIZE, CharClass, CompositeFont, CompositePart,
CompositeParts,
+20 -1
View File
@@ -34,6 +34,16 @@ pub struct CharStyle {
/// before it whose [`Self::kerning`] could space it. Elsewhere it has no effect.
#[serde(default, rename = "kerningBefore", skip_serializing_if = "crate::skip::is_default")]
pub kerning_before: f64,
/// Insert Aki Left (Character panel, East Asian options): space added before the character in
/// reading order, in 1/1000 em as [`Self::tracking`], 0 to 1000. Before is on the left in
/// left-to-right type, on the right in right-to-left type and above in vertical type. A
/// cluster takes the value of its first character, and full justification leaves it as it is.
/// <https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html>
#[serde(default, rename = "akiLeft", skip_serializing_if = "crate::skip::is_default")]
pub aki_left: f64,
/// Insert Aki Right: space added after the character in reading order, as [`Self::aki_left`].
#[serde(default, rename = "akiRight", skip_serializing_if = "crate::skip::is_default")]
pub aki_right: f64,
/// Use glyph shapes for automatic pair spacing; false uses font metrics.
#[serde(default, rename = "opticalKerning", skip_serializing_if = "crate::skip::is_default")]
pub optical_kerning: bool,
@@ -404,6 +414,9 @@ fn hundred() -> f64 {
100.0
}
/// The largest Insert Aki Left or Right ([`CharStyle::aki_left`]), in 1/1000 em: one em.
pub const MAX_AKI: f64 = 1000.0;
pub(super) fn yes() -> bool {
true
}
@@ -420,6 +433,8 @@ impl Default for CharStyle {
tracking: 0.0,
kerning: None,
kerning_before: 0.0,
aki_left: 0.0,
aki_right: 0.0,
optical_kerning: false,
baseline_shift: 0.0,
h_scale: 100.0,
@@ -468,7 +483,8 @@ impl CharStyle {
/// becomes Auto, and a value past [`crate::MAX_COORD`] (a baseline shift past it either way)
/// becomes the nearer end. A leading of 0, which legacy `.ai` import stores, stays, and a
/// baseline shift that is not a number becomes 0. The Tate-chu-yoko Up/Down and Left/Right
/// offsets are kept as the baseline shift is.
/// offsets are kept as the baseline shift is. Insert Aki Left and Right are kept from 0 to
/// [`MAX_AKI`], and one that is not a number becomes 0.
pub fn keep_dimensions_in_range(&mut self) {
let default = Self::default();
let within = |v: f64, or: f64| if v > 0.0 { v.min(crate::MAX_COORD) } else { or };
@@ -480,6 +496,9 @@ impl CharStyle {
self.baseline_shift = shift(self.baseline_shift);
self.tcy_up_down = shift(self.tcy_up_down);
self.tcy_left_right = shift(self.tcy_left_right);
let aki = |v: f64| if v.is_nan() { 0.0 } else { v.clamp(0.0, MAX_AKI) };
self.aki_left = aki(self.aki_left);
self.aki_right = aki(self.aki_right);
}
/// Do the characters draw a stroke (a paint and a positive weight)?
pub fn has_stroke(&self) -> bool {
+4
View File
@@ -490,6 +490,8 @@ impl crate::Document {
st.baseline_shift = num("baseline_shift").unwrap_or(st.baseline_shift);
st.tcy_up_down = num("tcyUpDown").unwrap_or(st.tcy_up_down);
st.tcy_left_right = num("tcyLeftRight").unwrap_or(st.tcy_left_right);
st.aki_left = num("akiLeft").unwrap_or(st.aki_left);
st.aki_right = num("akiRight").unwrap_or(st.aki_right);
st.keep_dimensions_in_range();
let kept = [
("size", Some(st.size)),
@@ -498,6 +500,8 @@ impl crate::Document {
("baseline_shift", Some(st.baseline_shift)),
("tcyUpDown", Some(st.tcy_up_down)),
("tcyLeftRight", Some(st.tcy_left_right)),
("akiLeft", Some(st.aki_left)),
("akiRight", Some(st.aki_right)),
("leading", st.leading),
];
for (k, v) in kept {
+3 -1
View File
@@ -357,7 +357,7 @@ impl ParaList {
/// The style the marker is set in: `first` (the style of the paragraph's first character)
/// without its baseline shift, rotation, superscript or subscript, tracking, manual kerning,
/// tate-chu-yoko, underline and strikethrough.
/// Insert Aki, tate-chu-yoko, underline and strikethrough.
pub fn marker_style(first: &CharStyle) -> CharStyle {
CharStyle {
baseline_shift: 0.0,
@@ -366,6 +366,8 @@ impl ParaList {
tracking: 0.0,
kerning: None,
kerning_before: 0.0,
aki_left: 0.0,
aki_right: 0.0,
optical_kerning: first.optical_kerning,
tate_chu_yoko: false,
underline: false,
+37
View File
@@ -92,6 +92,43 @@ fn font_height_reference_is_saved_only_when_not_the_em_box() {
assert_eq!(serde_json::from_value::<CharStyle>(old).unwrap().font_height_reference, FontHeightReference::EmBox);
}
/// Insert Aki Left and Right are 0 by default and saved only when not 0, each side on its own;
/// styles written before them read as 0, and a value out of range from a file is kept from 0 to one
/// em.
#[test]
fn insert_aki_is_saved_only_when_set() {
let st = CharStyle::default();
assert_eq!((st.aki_left, st.aki_right), (0.0, 0.0));
let saved = serde_json::to_value(&st).unwrap();
assert!(saved.get("akiLeft").is_none() && saved.get("akiRight").is_none());
for set in [
CharStyle { aki_left: 250.0, ..CharStyle::default() },
CharStyle { aki_right: 500.0, ..CharStyle::default() },
CharStyle { aki_left: 125.5, aki_right: 1000.0, ..CharStyle::default() },
] {
let saved = serde_json::to_value(&set).unwrap();
assert_eq!(saved.get("akiLeft").and_then(serde_json::Value::as_f64).unwrap_or(0.0), set.aki_left);
assert_eq!(saved.get("akiRight").and_then(serde_json::Value::as_f64).unwrap_or(0.0), set.aki_right);
assert_eq!(saved.get("akiLeft").is_some(), set.aki_left != 0.0);
assert_eq!(serde_json::from_value::<CharStyle>(saved).unwrap(), set);
}
let old = serde_json::to_value(&st).unwrap();
let read = serde_json::from_value::<CharStyle>(old).unwrap();
assert_eq!((read.aki_left, read.aki_right), (0.0, 0.0));
let mut damaged = CharStyle { aki_left: -20.0, aki_right: 4000.0, ..CharStyle::default() };
damaged.keep_dimensions_in_range();
assert_eq!((damaged.aki_left, damaged.aki_right), (0.0, MAX_AKI));
let mut damaged = CharStyle { aki_left: f64::NAN, aki_right: f64::INFINITY, ..CharStyle::default() };
damaged.keep_dimensions_in_range();
assert_eq!((damaged.aki_left, damaged.aki_right), (0.0, MAX_AKI));
// A character style from a file is kept in range the same way.
let mut d = crate::Document::new(100.0, 100.0);
let attrs = serde_json::json!({"akiLeft": 5000, "akiRight": -1});
d.char_styles.push(TextStyleDef { name: "Spaced".into(), attrs: attrs.as_object().cloned().unwrap_or_default() });
d.keep_type_values_in_range();
assert_eq!((d.char_styles[0].attrs["akiLeft"].as_f64(), d.char_styles[0].attrs["akiRight"].as_f64()), (Some(MAX_AKI), Some(0.0)));
}
/// Each Indic numeral system draws 0–9 (and the Arabic-Indic sets) as the ten digits of its
/// script's block; every system saves under its id, which reads back, and other names are refused.
#[test]
+11 -1
View File
@@ -67,7 +67,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Character / Paragraph",
[],
None,
"{ids?|id?, kerning?: 1/1000 em|\"auto\"|\"optical\", baselineShift?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright), underline?, strikethrough?, allCaps?, smallCaps?: bool, position?: \"normal\"|\"superscript\"|\"subscript\" (sizes from Document Setup), antiAlias?: \"none\"|\"sharp\"|\"crisp\"|\"strong\" (Character panel › Anti-aliasing Method, how the type's edges are drawn as pixels; it sets each targeted type object, with or without a range; each frame of a thread keeps its own method; graph labels keep it for every label of their kind when the graph is drawn again; new type: \"sharp\"), leftIndent?, rightIndent?, firstLineIndent?, spaceBefore?, spaceAfter?: pt (±1296), list?: \"none\"|\"bullet\"|\"number\", bullet?: \"none\"|\"dot\"|\"dash\"|\"circle\"|\"square\", number?: \"none\"|\"arabic\"|\"upperLetters\"|\"lowerLetters\"|\"upperRoman\"|\"lowerRoman\"|\"twoDigits\"|\"threeDigits\", listAlign?: \"left\"|\"right\", listLevel?: 1..9 (Paragraph panel › Bullets and Numbered List: each paragraph of a list starts with its marker, drawn in the font, size and color of the paragraph's first character, and its text starts at the next tab stop after the marker, the left indent counting as a stop; a bulleted list's marker is its bullet, and a numbered list's is the paragraph's number and a period: 1, 2, 3; A to Z, then AA, BB; a to z, then aa, bb; I, II, III; i, ii, iii; 01 to 99, then 100; 001 to 999, then 1000; letters and roman numerals past 3999 in Arabic digits; the numbers count the story's numbered paragraphs, its threaded frames included, from 1 after a paragraph in no list, and an empty or bulleted paragraph is not counted; list \"bullet\" keeps a list's bullet, else a dot, and list \"number\" keeps a numbered list's style, else arabic; without list, a number style makes a numbered list and a bullet makes a bulleted one; \"none\" in any of the three turns the list off; a paragraph that joins a list with left and first-line indents of 0 gets 18 and -18 unless the call sets an indent; a horizontal right-to-left list paragraph has its indents mirrored, measured from the right; listAlign \"right\" (Bullets and Numbering…'s Alignment) puts the marker against the text, and \"left\" (the default) puts it at the first line's start, the text starting at the same place with either; it sets the paragraphs that are in a list or that the call puts in one, and a list keeps it when it changes between bullets and numbers; listLevel (Tab and Shift+Tab at the start of a list paragraph, Bullets and Numbering…'s Level) is a whole number from 1 to 9 that sets the paragraphs in a list or that the call puts in one, a list keeping it when it changes between bullets and numbers, and a list turned on without listLevel starting at level 1; each level past the first sets the paragraph 18 pt further in than its left indent, and each level counts its own numbers: a list paragraph with text sets the counts of the levels deeper than its own back to 0, so a deeper numbered paragraph after it counts from 1, and a paragraph back at a shallower level goes on with that level's count), hyphenate?: bool, wordsLongerThan?: letters 1..25 (5), afterFirst?, beforeLast?: letters 1..15 (3), hyphenLimit?: lines 0..25 (0: no limit), hyphenationZone?: pt 0..1296 (0; Single-line Composer only), hyphenateCapitalized?: bool (true) (Paragraph panel menu › Hyphenation…: only words longer than wordsLongerThan break, keeping afterFirst letters before the hyphen and beforeLast after it; at most hyphenLimit lines in a row end with a hyphen; a line whose text already ends within hyphenationZone of its right edge breaks before the next word instead of hyphenating it; the counts are rounded, and every value is clamped to its range), wordSpacing?: % 0..1000 (80, 100, 133), letterSpacing?: % of a word space -100..500 (0, 0, 0), glyphScaling?: % 50..200 (100, 100, 100): each [min, desired, max] or {min?, desired?, max?} (Paragraph panel menu › Justification…: Desired applies to every line, Minimum and Maximum bound what justified lines may use; values are clamped to their range, and Minimum ≤ Desired ≤ Maximum must hold afterwards or nothing changes), autoLeading?: % of the size 0..500 (120; the leading of characters whose leading is Auto), singleWordJustification?: \"fullJustify\"|\"alignLeft\"|\"alignCenter\"|\"alignRight\" (a justified line holding one word), mojikumi?: \"none\"|\"lineEndHalf\" (Japanese punctuation spacing), kinsoku?: \"none\"|\"hard\"|\"soft\" (Kinsoku Set: Soft lets 々, ー and small kana start a line), kinsokuType?: \"pushInFirst\"|\"pushOutFirst\"|\"pushOutOnly\" (Paragraph panel menu › Kinsoku Shori Type: how area type keeps those characters off a line's ends; pushInFirst sets them on the line when its gaps next to CJK characters can close up enough, by at most a tenth of an em each, pushOutFirst does so only when moving the character before them to the next line would leave Line truncated
"{ids?|id?, kerning?: 1/1000 em|\"auto\"|\"optical\", baselineShift?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright), underline?, strikethrough?, allCaps?, smallCaps?: bool, position?: \"normal\"|\"superscript\"|\"subscript\" (sizes from Document Setup), antiAlias?: \"none\"|\"sharp\"|\"crisp\"|\"strong\" (Character panel › Anti-aliasing Method, how the type's edges are drawn as pixels; it sets each targeted type object, with or without a range; each frame of a thread keeps its own method; graph labels keep it for every label of their kind when the graph is drawn again; new type: \"sharp\"), leftIndent?, rightIndent?, firstLineIndent?, spaceBefore?, spaceAfter?: pt (±1296), list?: \"none\"|\"bullet\"|\"number\", bullet?: \"none\"|\"dot\"|\"dash\"|\"circle\"|\"square\", number?: \"none\"|\"arabic\"|\"upperLetters\"|\"lowerLetters\"|\"upperRoman\"|\"lowerRoman\"|\"twoDigits\"|\"threeDigits\", listAlign?: \"left\"|\"right\", listLevel?: 1..9 (Paragraph panel › Bullets and Numbered List: each paragraph of a list starts with its marker, drawn in the font, size and color of the paragraph's first character, and its text starts at the next tab stop after the marker, the left indent counting as a stop; a bulleted list's marker is its bullet, and a numbered list's is the paragraph's number and a period: 1, 2, 3; A to Z, then AA, BB; a to z, then aa, bb; I, II, III; i, ii, iii; 01 to 99, then 100; 001 to 999, then 1000; letters and roman numerals past 3999 in Arabic digits; the numbers count the story's numbered paragraphs, its threaded frames included, from 1 after a paragraph in no list, and an empty or bulleted paragraph is not counted; list \"bullet\" keeps a list's bullet, else a dot, and list \"number\" keeps a numbered list's style, else arabic; without list, a number style makes a numbered list and a bullet makes a bulleted one; \"none\" in any of the three turns the list off; a paragraph that joins a list with left and first-line indents of 0 gets 18 and -18 unless the call sets an indent; a horizontal right-to-left list paragraph has its indents mirrored, measured from the right; listAlign \"right\" (Bullets and Numbering…'s Alignment) puts the marker against the text, and \"left\" (the default) puts it at the first line's start, the text starting at the same place with either; it sets the paragraphs that are in a list or that the call puts in one, and a list keeps it when it changes between bullets and numbers; listLevel (Tab and Shift+Tab at the start of a list paragraph, Bullets and Numbering…'s Level) is a whole number from 1 to 9 that sets the paragraphs in a list or that the call puts in one, a list keeping it when it changes between bullets and numbers, and a list turned on without listLevel starting at level 1; each level past the first sets the paragraph 18 pt further in than its left indent, and each level counts its own numbers: a list paragraph with text sets the counts of the levels deeper than its own back to 0, so a deeper numbered paragraph after it counts from 1, and a paragraph back at a shallower level goes on with that level's count), hyphenate?: bool, wordsLongerThan?: letters 1..25 (5), afterFirst?, beforeLast?: letters 1..15 (3), hyphenLimit?: lines 0..25 (0: no limit), hyphenationZone?: pt 0..1296 (0; Single-line Composer only), hyphenateCapitalized?: bool (true) (Paragraph panel menu › Hyphenation…: only words longer than wordsLongerThan break, keeping afterFirst letters before the hyphen and beforeLast after it; at most hyphenLimit lines in a row end with a hyphen; a line whose text already ends within hyphenationZone of its right edge breaks before the next word instead of hyphenating it; the counts are rounded, and every value is clamped to its range), wordSpacing?: % 0..1000 (80, 100, 133), letterSpacing?: % of a word space -100..500 (0, 0, 0), glyphScaling?: % 50..200 (100, 100, 100): each [min, desired, max] or {min?, desired?, max?} (Paragraph panel menu › Justification…: Desired applies to every line, Minimum and Maximum bound what justified lines may use; values are clamped to their range, and Minimum ≤ Desired ≤ Maximum must hold afterwards or nothing changes), autoLeading?: % of the size 0..500 (120; the leading of characters whose leading is Auto), singleWordJustification?: \"fullJustify\"|\"alignLeft\"|\"alignCenter\"|\"alignRight\" (a justified line holding one word), mojikumi?: \"none\"|\"lineEndHalf\" (Japanese punctuation spacing), kinsoku?: \"none\"|\"hard\"|\"soft\" (Kinsoku Set: Soft lets 々, ー and small kana start a line), kinsokuType?: \"pushInFirst\"|\"pushOutFirst\"|\"pushOutOnly\" (Paragraph panel menu › Kinsoku Shori Type: how area type keeps those characters off a line's ends; pushInFirst sets them on the line when its gaps next to CJK characters can close up enough, by at most a tenth of an em each, pushOutFirst does so only when moving the character before them to the next line would leave Line truncated
has_doc,
set_format
),
@@ -545,6 +545,8 @@ fn set_format(s: &mut Session, p: &Value) -> Result<Value> {
"tateChuYoko",
"tcyUpDown",
"tcyLeftRight",
"akiLeft",
"akiRight",
"standardVerticalRoman",
"noBreak",
"digits",
@@ -586,6 +588,8 @@ fn set_format(s: &mut Session, p: &Value) -> Result<Value> {
let font_height_reference = super::textedit::font_height_reference_param(p, C)?;
let tcy_up_down = super::textedit::tcy_offset_param(p, "tcyUpDown", C)?;
let tcy_left_right = super::textedit::tcy_offset_param(p, "tcyLeftRight", C)?;
let aki_left = super::textedit::aki_param(p, "akiLeft", C)?;
let aki_right = super::textedit::aki_param(p, "akiRight", C)?;
let mojikumi = match p.get("mojikumi") {
None => None,
Some(v) => Some(match v.as_str() {
@@ -746,6 +750,12 @@ fn set_format(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(v) = tcy.1 {
st.tcy_left_right = v;
}
if let Some(v) = aki_left {
st.aki_left = v;
}
if let Some(v) = aki_right {
st.aki_right = v;
}
if let Some(v) = flag("standardVerticalRoman") {
st.standard_vertical_roman = v;
}
+23 -1
View File
@@ -40,7 +40,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Character",
[],
None,
"{id? (default: the one selected type object), start?: byte, end?: byte (default: all text), story?: bool = false (all the text of every frame of the threaded story `id` is a frame of, in one undo step; no `start` or `end`), font?, style?, size?: pt, leading?: pt|\"auto\", tracking?, kerning?: 1/1000 em|\"auto\"|\"optical\" (the space after each character), kerningBefore?: 1/1000 em -1000..10000 (the space before a character that starts a line by itself: the first character of the text, of a paragraph or after a forced line break; no effect elsewhere; 0 by default), baselineShift?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright), fill?: colour|\"none\", stroke?: colour|\"none\" (#rrggbbaa and #rgba are refused in both), keepModel?: bool (fill and stroke, as paint.setFill), strokeWidth?: pt, strokeOptions?: {weight?, cap?, join?, miterLimit?, align?, dash?, dashOffset?, alignDashes?} (as stroke.set: the character stroke), underline?, strikethrough?, allCaps?: bool, smallCaps?: bool, position?: \"normal\"|\"superscript\"|\"subscript\" (sizes from Document Setup), features?: [\"dlig\", \"-liga\", \"salt=2\", …] (swsh, ss01–ss20, salt, titl, pnum, lnum, sups, subs, numr, dnom and aalt take the font's alternate number as `tag=N`, N 0–65535: \"salt=2\" draws the second alternate of each glyph that has one, \"salt\" is \"salt=1\", \"-salt\" and \"salt=0\" are off; the range is shaped with its word, so a letter's alternate keeps it joined to its neighbours), featureChanges?: [\"tnum\", \"-onum\", \"salt=2\", …] (OpenType features turned on, or with - off, on top of each character's own, a value replacing the feature's last one; its other features are kept), charAlign?: \"romanBaseline\"|\"emBoxTop\"|\"emBoxCenter\"|\"emBoxBottom\"|\"icfTop\"|\"icfBottom\", proportionalMetrics?: bool (full-width glyphs on the font's proportional widths: `palt` in horizontal type, `vpal` in vertical type), tateChuYoko?: bool (Character panel menu › Tate-chu-yoko, with Show East Asian Options: in vertical type those characters stand side by side across one em of the column; kept on the characters and ignored in horizontal type), tcyUpDown?, tcyLeftRight?: pt -1296..1296 (Character panel menu › Tate-chu-yoko Settings: in vertical type a block of tate-chu-yoko characters moves up by a positive Up/Down and down by a negative one, right by a positive Left/Right and left by a negative one, as one piece with the values of its first character; on a vertical path a positive Up/Down moves it toward the path's start and a positive Left/Right to the path's left; 0 by default; automatic digit blocks and horizontal type do not move; neither turns tateChuYoko on), standardVerticalRoman?: bool (Character panel menu › Standard Vertical Roman Alignment, with Show East Asian Options: in vertical type those half-width characters, such as Latin letters and digits, stand upright one below the other instead of being rotated; spaces and tate-chu-yoko blocks are not changed; kept on the characters and ignored in horizontal type; off by default), noBreak?: bool (Character panel menu › No Break: these characters stay on one line, including across a space inside the run), kashidas?: bool (Character panel menu › Kashidas: selected characters allow insertion only when both joined neighbors have it on; on by default), charDirection?: \"default\"|\"leftToRight\"|\"rightToLeft\" (Character panel menu › Character Direction: the characters are set left to right or right to left inside their paragraph, as a Unicode bidi embedding; default: as the bidi algorithm sets them), digits?: \"default\"|\"arabic\"|\"hindi\"|\"farsi\"|\"devanagari\"|\"bengali\"|\"gurmukhi\"|\"gujarati\"|\"odia\"|\"tamil\"|\"telugu\"|\"kannada\"|\"malayalam\" (Character panel menu › Digits: the numeral system every digit is drawn in, whatever was typed: Western, Arabic-Indic (hindi), Eastern Arabic-Indic (farsi) or an Indic script's own digits), fontHeightReference?: \"emBox\"|\"capHeight\"|\"xHeight\"|\"icfBox\" (Character panel › Set Font Height Reference: the height of the font that size measures, the em box by default; with a font that has no such height, or one outside 0.1 to 2 em, the em box), language?: name|tag (Character panel › Language: one of Document Setup's languages by name or BCP 47 tag, case-insensitive, such as \"Turkish\" or \"tr\"; the characters are shaped in it, so the font uses that language's forms (OpenType `locl`); saved as the tag, English: USA, the default, as none; new type takes the document's language), fontAxes?: {\"wght\": 650, …} (Character panel › Variable Font: the setting of each variation axis named, in the axis's units and clamped to its range; null: back to the style's own setting; other axes keep theirs; tags the font has no axis for are left out; a font or style change clears them; text.fontList {family, style} lists the axes), glyphAlternate?: null (takes away the glyph choice text.setGl Line truncated
"{id? (default: the one selected type object), start?: byte, end?: byte (default: all text), story?: bool = false (all the text of every frame of the threaded story `id` is a frame of, in one undo step; no `start` or `end`), font?, style?, size?: pt, leading?: pt|\"auto\", tracking?, kerning?: 1/1000 em|\"auto\"|\"optical\" (the space after each character), kerningBefore?: 1/1000 em -1000..10000 (the space before a character that starts a line by itself: the first character of the text, of a paragraph or after a forced line break; no effect elsewhere; 0 by default), baselineShift?: pt, hScale?: %, vScale?: %, rotation?: deg counter-clockwise (0: upright), fill?: colour|\"none\", stroke?: colour|\"none\" (#rrggbbaa and #rgba are refused in both), keepModel?: bool (fill and stroke, as paint.setFill), strokeWidth?: pt, strokeOptions?: {weight?, cap?, join?, miterLimit?, align?, dash?, dashOffset?, alignDashes?} (as stroke.set: the character stroke), underline?, strikethrough?, allCaps?: bool, smallCaps?: bool, position?: \"normal\"|\"superscript\"|\"subscript\" (sizes from Document Setup), features?: [\"dlig\", \"-liga\", \"salt=2\", …] (swsh, ss01–ss20, salt, titl, pnum, lnum, sups, subs, numr, dnom and aalt take the font's alternate number as `tag=N`, N 0–65535: \"salt=2\" draws the second alternate of each glyph that has one, \"salt\" is \"salt=1\", \"-salt\" and \"salt=0\" are off; the range is shaped with its word, so a letter's alternate keeps it joined to its neighbours), featureChanges?: [\"tnum\", \"-onum\", \"salt=2\", …] (OpenType features turned on, or with - off, on top of each character's own, a value replacing the feature's last one; its other features are kept), charAlign?: \"romanBaseline\"|\"emBoxTop\"|\"emBoxCenter\"|\"emBoxBottom\"|\"icfTop\"|\"icfBottom\", proportionalMetrics?: bool (full-width glyphs on the font's proportional widths: `palt` in horizontal type, `vpal` in vertical type), tateChuYoko?: bool (Character panel menu › Tate-chu-yoko, with Show East Asian Options: in vertical type those characters stand side by side across one em of the column; kept on the characters and ignored in horizontal type), tcyUpDown?, tcyLeftRight?: pt -1296..1296 (Character panel menu › Tate-chu-yoko Settings: in vertical type a block of tate-chu-yoko characters moves up by a positive Up/Down and down by a negative one, right by a positive Left/Right and left by a negative one, as one piece with the values of its first character; on a vertical path a positive Up/Down moves it toward the path's start and a positive Left/Right to the path's left; 0 by default; automatic digit blocks and horizontal type do not move; neither turns tateChuYoko on), akiLeft?, akiRight?: 1/1000 em 0..1000 (Character panel › Insert Aki Left and Right, with Show East Asian Options: space before and after each character in reading order, on its left and right in left-to-right type, on its right and left in right-to-left type, above and below it in vertical type; a ligature or a letter with its marks takes the values of its first character; line wrapping counts it, alignment keeps it at a line's ends and justification does not stretch or narrow it; 0 by default; a value that is not a number or is outside the range is refused, naming the key), standardVerticalRoman?: bool (Character panel menu › Standard Vertical Roman Alignment, with Show East Asian Options: in vertical type those half-width characters, such as Latin letters and digits, stand upright one below the other instead of being rotated; spaces and tate-chu-yoko blocks are not changed; kept on the characters and ignored in horizontal type; off by default), noBreak?: bool (Character panel menu › No Break: these characters stay on one line, including across a space inside the run), kashidas?: bool (Character panel menu › Kashidas: selected characters allow insertion only when both joined neighbors have it on; on by default), charDirection?: \"default\"|\"leftToRight\"|\"rightToLeft\" (Character panel menu › Character Direction: the characters are set left to right or right to left inside their paragraph, as a Unicode bidi embedding; default: as the bidi algorithm sets them), digits?: \"default\"|\"arabic\"|\"hindi\"|\"farsi\"|\"devanagari\"|\"bengali\"|\"gurmukhi\"|\"gujarati\"|\"odia\"|\"tamil\"|\"telugu\"|\"kannada\"|\"malayalam\" (Character panel menu › Digits: the numeral system every digit is drawn in, whatever was typed: Western, Arabic-Indic (hindi), Eastern Arabic-Indic (farsi) or an Indic script's own digits), fontHeightReference?: \"emBox\"|\"capHeight\"|\"xHeight\"|\"icfBox\" (Character panel › Set Font Height Reference: the height of the font that size measures, the em box by default; with a font that has no such height, or one outside 0.1 to 2 em, the em box), language?: name|tag (Character panel › Language: one of Document Setup's languages by name or BCP 47 tag, case-insensitive, such as \"Turkish\" or \"tr\"; the char Line truncated
has_doc,
set_range_style
),
@@ -459,6 +459,9 @@ pub(crate) struct CharChange {
/// Tate-chu-yoko Settings › Up/Down and Left/Right, in points.
tcy_up_down: Option<f64>,
tcy_left_right: Option<f64>,
/// Insert Aki Left and Right, in 1/1000 em.
aki_left: Option<f64>,
aki_right: Option<f64>,
standard_vertical_roman: Option<bool>,
no_break: Option<bool>,
digits: Option<vectorcraft_doc::Digits>,
@@ -492,6 +495,15 @@ pub(crate) fn tcy_offset_param(p: &Value, key: &str, cmd: &str) -> Result<Option
if (lo..=hi).contains(&v) { Ok(Some(v)) } else { Err(bad(cmd, format!("`{key}` must be from {lo} to {hi}"))) }
}
/// `akiLeft` or `akiRight` (Insert Aki Left and Right): a number of thousandths of an em from 0 to
/// [`vectorcraft_doc::text::MAX_AKI`]. Any other value is an error.
pub(crate) fn aki_param(p: &Value, key: &str, cmd: &str) -> Result<Option<f64>> {
let Some(v) = p.get(key).filter(|v| !v.is_null()) else { return Ok(None) };
let v = v.as_f64().filter(|v| v.is_finite()).ok_or_else(|| bad(cmd, format!("`{key}` must be a number")))?;
let (lo, hi) = (0.0, vectorcraft_doc::text::MAX_AKI);
if (lo..=hi).contains(&v) { Ok(Some(v)) } else { Err(bad(cmd, format!("`{key}` must be from {lo} to {hi}"))) }
}
/// `digits: "default"|"arabic"|"hindi"|"farsi"|"devanagari"|…` ([`Digits::id`]) → the numeral
/// system the digits are drawn in.
///
@@ -754,6 +766,8 @@ impl CharChange {
tate_chu_yoko: flag("tateChuYoko"),
tcy_up_down: tcy_offset_param(p, "tcyUpDown", cmd)?,
tcy_left_right: tcy_offset_param(p, "tcyLeftRight", cmd)?,
aki_left: aki_param(p, "akiLeft", cmd)?,
aki_right: aki_param(p, "akiRight", cmd)?,
standard_vertical_roman: flag("standardVerticalRoman"),
no_break: flag("noBreak"),
digits: digits_param(p, cmd)?,
@@ -814,6 +828,8 @@ impl CharChange {
&& self.tate_chu_yoko.is_none()
&& self.tcy_up_down.is_none()
&& self.tcy_left_right.is_none()
&& self.aki_left.is_none()
&& self.aki_right.is_none()
&& self.standard_vertical_roman.is_none()
&& self.no_break.is_none()
&& self.digits.is_none()
@@ -880,6 +896,12 @@ impl CharChange {
if let Some(v) = self.tcy_left_right {
st.tcy_left_right = v;
}
if let Some(v) = self.aki_left {
st.aki_left = v;
}
if let Some(v) = self.aki_right {
st.aki_right = v;
}
if let Some(v) = self.standard_vertical_roman {
st.standard_vertical_roman = v;
}
+12 -2
View File
@@ -215,6 +215,8 @@ pub fn char_attrs(v: &CharStyle) -> Map<String, Value> {
("tateChuYoko", json!(v.tate_chu_yoko)),
("tcyUpDown", json!(v.tcy_up_down)),
("tcyLeftRight", json!(v.tcy_left_right)),
("akiLeft", json!(v.aki_left)),
("akiRight", json!(v.aki_right)),
("standardVerticalRoman", json!(v.standard_vertical_roman)),
("noBreak", json!(v.no_break)),
("digits", json!(v.digits)),
@@ -557,6 +559,12 @@ fn attrs_param(d: &Document, p: &Value, kind: Kind, verb: &str, kept: Option<&Ma
return Err(bad(&c, format!("`{key}` must be from {} to {shift_max}", -shift_max)));
}
}
let (lo, hi) = (0.0, vectorcraft_doc::text::MAX_AKI);
for (key, value) in [("akiLeft", st.aki_left), ("akiRight", st.aki_right)] {
if changed(key) && !(lo..=hi).contains(&value) {
return Err(bad(&c, format!("`{key}` must be from {lo} to {hi}")));
}
}
// A language of the list, stored as its tag (as text.setFormat takes it).
if let Some(l) = &st.language
&& kept.and_then(|k| k.get("language")) != m.get("language")
@@ -1041,17 +1049,19 @@ fn unused(s: &mut Session, kind: Kind) -> Result<Value> {
/// The styles of `kind` in `src` that load, with their source names so that art in the file keeps
/// referring to them: not the Normal style, and not one whose attributes don't read, whose sizes,
/// scales, leading, shifts or stroke width are out of the range `charStyle.new` takes, whose
/// scales, leading, shifts, Insert Aki or stroke width are out of the range `charStyle.new` takes, whose
/// indents, spacing, Hyphenation or Justification options or tab stops are out of the range
/// `paraStyle.new` takes, or whose name is empty, which are skipped. → (the styles, the names in
/// `src` of those skipped)
fn loadable(src: &Document, kind: Kind) -> (Vec<TextStyleDef>, Vec<String>) {
const RANGED: [&str; 16] = [
const RANGED: [&str; 18] = [
"size",
"h_scale",
"v_scale",
"leading",
"baseline_shift",
"akiLeft",
"akiRight",
"tcyUpDown",
"tcyLeftRight",
"stroke_width",
+4 -1
View File
@@ -395,6 +395,8 @@ fn character_style_dimensions_are_checked_before_a_definition_changes() {
json!({"baseline_shift": 1296.1}),
json!({"tcyUpDown": 1296.1}),
json!({"tcyLeftRight": -1296.1}),
json!({"akiLeft": -0.1}),
json!({"akiRight": 1000.1}),
] {
let key = attrs.as_object().unwrap().keys().next().unwrap();
for cmd in ["charStyle.edit", "charStyle.setAttrs", "charStyle.new"] {
@@ -416,7 +418,8 @@ fn character_style_dimensions_are_checked_before_a_definition_changes() {
"size": 1296.0, "leading": 5000.0,
"h_scale": 1.0, "v_scale": 10000.0,
"baseline_shift": -1296.0,
"tcyUpDown": 1296.0, "tcyLeftRight": -1296.0
"tcyUpDown": 1296.0, "tcyLeftRight": -1296.0,
"akiLeft": 0.0, "akiRight": 1000.0
}}),
)
.unwrap();
@@ -1610,6 +1610,63 @@ fn tate_chu_yoko_settings_are_character_attributes_saved_only_when_set() {
assert_eq!(offsets(&s), before);
}
/// Insert Aki Left and Right (Character panel, East Asian options): character attributes in
/// thousandths of an em, 0 by default and saved only when not 0. Both commands set either side
/// alone, keeping the other side of every run, in one undo step; a value that is not a number or
/// lies outside 0 to 1000 is refused, naming the key, before anything changes; a character style
/// captured from the characters carries them.
#[test]
fn insert_aki_is_a_character_attribute_set_one_side_at_a_time() {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap();
let id = s.execute("text.create", &json!({"x": 10, "y": 50, "text": "(日本)"})).unwrap()["id"].as_u64().unwrap();
let runs = |s: &Session| match &s.doc().unwrap().doc.node(NodeId(id)).unwrap().kind {
NodeKind::Text(t) => t.runs.clone(),
_ => panic!("text"),
};
let aki = |s: &Session| runs(s).iter().map(|r| (r.text.clone(), r.style.aki_left, r.style.aki_right)).collect::<Vec<_>>();
let saved = serde_json::to_value(&runs(&s)[0].style).unwrap();
assert!(saved.get("akiLeft").is_none() && saved.get("akiRight").is_none());
s.execute("select.set", &json!({"ids": [id]})).unwrap();
s.execute("text.setFormat", &json!({"akiLeft": 250})).unwrap();
assert_eq!(aki(&s), [("(日本)".to_string(), 250.0, 0.0)]);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(aki(&s), [("(日本)".to_string(), 0.0, 0.0)], "one undo step");
s.execute("edit.redo", &json!({})).unwrap();
assert_eq!(aki(&s), [("(日本)".to_string(), 250.0, 0.0)]);
// One side on part of the text: the runs keep their other side.
let paren = "(".len();
s.execute("text.setRangeStyle", &json!({"id": id, "start": 0, "end": paren, "akiRight": 500})).unwrap();
assert_eq!(aki(&s), [("(".to_string(), 250.0, 500.0), ("日本)".to_string(), 250.0, 0.0)]);
s.execute("text.setFormat", &json!({"akiLeft": 0})).unwrap();
assert_eq!(aki(&s), [("(".to_string(), 0.0, 500.0), ("日本)".to_string(), 0.0, 0.0)]);
let saved = serde_json::to_value(&runs(&s)[0].style).unwrap();
assert_eq!((saved.get("akiLeft"), saved["akiRight"].clone()), (None, json!(500.0)));
// Saved and reopened as they were.
let back = vectorcraft_format::load(&vectorcraft_format::save(&s.doc().unwrap().doc, false)).unwrap();
let NodeKind::Text(t) = &back.node(NodeId(id)).unwrap().kind else { panic!("text") };
let reopened: Vec<_> = t.runs.iter().map(|r| (r.text.clone(), r.style.aki_left, r.style.aki_right)).collect();
assert_eq!(reopened, aki(&s));
let attrs = super::super::textstyles::char_attrs(&runs(&s)[0].style);
assert_eq!((attrs["akiLeft"].clone(), attrs["akiRight"].clone()), (json!(0.0), json!(500.0)));
let before = aki(&s);
let undo = s.doc().unwrap().history.undo.len();
for (cmd, p, want) in [
("text.setFormat", json!({"akiLeft": "250"}), "`akiLeft` must be a number"),
("text.setFormat", json!({"akiRight": -1}), "`akiRight` must be from 0 to 1000"),
("text.setFormat", json!({"akiLeft": 250, "akiRight": 1000.5}), "`akiRight` must be from 0 to 1000"),
("text.setRangeStyle", json!({"id": id, "akiRight": true}), "`akiRight` must be a number"),
("text.setRangeStyle", json!({"id": id, "start": 0, "end": paren, "akiLeft": 2000}), "`akiLeft` must be from 0 to 1000"),
] {
let e = s.execute(cmd, &p).unwrap_err();
assert!(matches!(&e, EngineError::BadParams { msg, .. } if msg == want), "{cmd} {p}: {e}");
}
assert_eq!(aki(&s), before);
assert_eq!(s.doc().unwrap().history.undo.len(), undo, "no undo step for a refused call");
}
/// Standard Vertical Roman Alignment (Character panel menu, East Asian options): a character
/// attribute, off by default and saved only when on. Documents written before it read as off; a
/// character style captured from the characters carries it.
+15 -4
View File
@@ -271,6 +271,12 @@ impl Writer<'_> {
self.warn("type on a path with space before a character after a line break is outlined to keep its look");
return self.text_outlines(n, t);
}
// A `<textPath>` places its characters one after the other: Insert Aki keeps its look as
// outlines.
if t.runs.iter().any(|r| r.style.aki_left != 0.0 || r.style.aki_right != 0.0) {
self.warn("type on a path with Insert Aki is outlined to keep its look");
return self.text_outlines(n, t);
}
// A `<textPath>` holds the characters of the text, not the bullets or numbers drawn
// before them.
if !lay.markers.is_empty() {
@@ -702,11 +708,14 @@ const PLACE_TOLERANCE: f64 = 1e-6;
/// caps are upper case. Unless `fewer`, a line that is justified or composed with Mojikumi also
/// starts a new segment at each character the layout draws elsewhere than a reader continuing
/// the segment would ([`reader_advances`]): a Justify All line's letter gaps, the gaps between
/// the characters of a justified Japanese line, and the spacing Mojikumi changes.
/// the characters of a justified Japanese line, and the spacing Mojikumi changes. Text with Insert
/// Aki does so on every line, with `fewer` too.
fn text_lines(t: &TextObject, lay: &vectorcraft_text::TextLayout, fewer: bool) -> Vec<Line> {
let plain = t.plain_text();
let mut lines = Vec::with_capacity(lay.lines.len());
let (mut kerned, mut unkerned) = (None, None);
// Insert Aki moves characters from where a reader draws them, with `fewer` too.
let aki = t.runs.iter().any(|r| r.style.aki_left != 0.0 || r.style.aki_right != 0.0);
for line in &lay.lines {
let para = plain.as_bytes().get(..line.start).map_or(0, |b| b.iter().filter(|&&c| c == b'\n').count());
let style = t.para_at(para);
@@ -715,7 +724,7 @@ fn text_lines(t: &TextObject, lay: &vectorcraft_text::TextLayout, fewer: bool) -
// Justification…'s Desired word and letter spacing and glyph scaling move characters from
// where a reader draws them, on every line (Block's word gap among them).
let spaced = !fewer && !t.layout_justification(style).desired_is_default();
let reader = if split_words || spaced || (!fewer && !style.mojikumi.is_none()) {
let reader = if aki || split_words || spaced || (!fewer && !style.mojikumi.is_none()) {
Some(&*kerned.get_or_insert_with(|| reader_advances(t, lay, true)))
} else {
None
@@ -870,9 +879,11 @@ fn reader_advances(t: &TextObject, lay: &vectorcraft_text::TextLayout, kerning:
if !kerning {
r.style.kerning.get_or_insert(0.0);
}
// A reader puts no space before a line's first character (`kerningBefore`): the segment
// starts that much further along instead.
// A reader puts no space before a line's first character (`kerningBefore`) and no Insert
// Aki: the segment starts that much further along instead.
r.style.kerning_before = 0.0;
r.style.aki_left = 0.0;
r.style.aki_right = 0.0;
}
let relaid;
let glyphs = if set == *t {
+28
View File
@@ -163,6 +163,34 @@ fn the_space_before_the_first_character_on_a_path_is_its_dx() {
assert!(!out.svg.contains("<textPath") && out.warnings.iter().any(|w| w.contains("line break")), "{:?}", out.warnings);
}
/// Insert Aki: each character the layout moves by its Aki starts a `<tspan>` where the character is
/// drawn, so a reader draws the text where the canvas does, with fewer `<tspan>`s asked for too.
/// On a path the type is outlined.
#[test]
fn insert_aki_places_each_moved_character() {
// 250/1000 em of 12 pt before the O (3 pt) and 500/1000 after it (6 pt), then a run with Aki
// after every character, and a second line.
let spaced = CharStyle { aki_left: 250.0, aki_right: 500.0, ..style(12.0) };
let runs = vec![run("H", style(12.0)), run("O", spaced), run("H ", style(12.0)), run("OHO\nHO", CharStyle { aki_right: 500.0, ..style(12.0) })];
let d = area_doc(runs, 200.0, Justify::Left);
assert_drawn_in_place(&d);
let plain = tspans(&export(&area_doc(vec![run("HOH OHO\nHO", style(12.0))], 200.0, Justify::Left), &ExportOptions::default())).len();
let fewer = tspans(&export(&d, &ExportOptions { fewer_tspans: true, ..Default::default() })).len();
assert!(fewer > plain, "each moved character is placed with fewer tspans too: {plain} {fewer}");
let mut t = TextObject::point(Point::ZERO, "", style(12.0));
t.runs = vec![run("HO", CharStyle { aki_left: 250.0, ..style(12.0) })];
let mut line = BezPath::new();
line.move_to((20.0, 100.0));
line.line_to((280.0, 100.0));
t.kind = TextKind::OnPath { path: PathData::from_bezpath(&line), start: 0.0, end: None };
let mut d = Document::new(300.0, 200.0);
let n = Node::new(d.alloc_id(), NodeKind::Text(Box::new(t)));
let l = d.layers[0].id;
d.insert(Some(l), 0, n).unwrap();
let out = vectorcraft_svg::export_full(&d, &ExportOptions::default(), None);
assert!(!out.svg.contains("<textPath") && out.warnings.iter().any(|w| w.contains("Insert Aki")), "{:?}", out.warnings);
}
/// Proportional Metrics (#966) is written as the `palt` feature, beside the character's own.
#[test]
fn proportional_metrics_write_palt() {
+2
View File
@@ -54,6 +54,8 @@ pub(crate) fn paint_only(a: &CharStyle, b: &CharStyle) -> bool {
tracking,
kerning,
kerning_before: _,
aki_left: _,
aki_right: _,
optical_kerning,
baseline_shift,
h_scale,
+8 -6
View File
@@ -147,25 +147,27 @@ pub(crate) fn apply_desired(sg: &mut [SGlyph], j: &JustificationOptions, scale_g
}
continue;
}
// Insert Aki keeps its width: only the rest of the advance is spaced or scaled.
let aki = if g.aki.is_finite() { g.aki } else { 0.0 };
if is_word_space(g) {
// The font's word space (with its tracking), set at Desired.
let base = g.adv;
g.adv = base * w_des;
let base = g.adv - aki;
g.adv = base * w_des + aki;
f.word = (base * (w_max - w_des).max(0.0), base * (w_des - w_min).max(0.0));
continue;
}
if g.is_space() || g.inline.is_some() || g.ch == '\u{2028}' {
continue;
}
let base = g.adv;
let base = g.adv - aki;
if g_des != 1.0 {
g.adv *= g_des;
g.adv = base * g_des + aki;
g.tracking *= g_des;
g.sx *= g_des;
g.dx *= g_des;
g.kern_shift *= g_des;
g.kern_shift = (g.kern_shift - g.aki_shift) * g_des + g.aki_shift;
}
f.width = g.adv;
f.width = g.adv - aki;
f.scale = g_des;
f.glyph = (base * (g_max - g_des).max(0.0), base * (g_des - g_min).max(0.0));
if gap {
+9 -1
View File
@@ -241,7 +241,7 @@ impl Ctx<'_> {
/// Layout on or Fractional Widths off, whole-point advances.
fn finish_shaping<'s>(&self, v: &mut [SGlyph], style: impl Fn(&SGlyph) -> &'s CharStyle) {
if self.vertical {
tate_chu_yoko(v, |g| {
tate_chu_yoko(v, self.system_layout || !self.fractional_widths, |g| {
let st = style(g);
TcyStyle { size: st.size, marked: st.tate_chu_yoko, up: st.tcy_up_down, right: st.tcy_left_right }
});
@@ -318,6 +318,8 @@ impl Ctx<'_> {
tab.dx = 0.0;
tab.dy = 0.0;
tab.kern_shift = 0.0;
tab.aki_shift = 0.0;
tab.aki = 0.0;
tab.tcy = None;
tab.vpal = None;
let left = para.laid_out_left_indent();
@@ -617,6 +619,8 @@ impl Ctx<'_> {
k.dx = 0.0;
k.dy = 0.0;
k.kern_shift = 0.0;
k.aki_shift = 0.0;
k.aki = 0.0;
k.len = 0;
k.lead = 0.0;
k.ch = kashida::TATWEEL;
@@ -674,6 +678,8 @@ mod emit_kashida_mark_last {
dx: 0.0,
dy: 0.0,
kern_shift: 0.0,
aki_shift: 0.0,
aki: 0.0,
sx: face.upem.recip() * 48.0,
sy: face.upem.recip() * 48.0,
bshift: 0.0,
@@ -736,6 +742,8 @@ mod emit_kashida_mark_last {
dx: 0.0,
dy: 0.0,
kern_shift: 0.0,
aki_shift: 0.0,
aki: 0.0,
sx: face.upem.recip() * 48.0,
sy: face.upem.recip() * 48.0,
bshift: 0.0,
+7 -1
View File
@@ -1005,7 +1005,13 @@ fn emit_flow_line(cx: &mut Ctx<'_>, pen: &mut Pen<'_>, paragraph: &ParagraphData
.map(|item| item.1);
advance += kashida.unwrap_or(0.0);
let y = line.position.baseline - align_shift(glyph, cx.style_at(glyph.byte).char_align, line_em, cx.vertical);
let transform = if scale != 1.0 { Affine::translate((x, y)) * Affine::scale_non_uniform(scale, 1.0) } else { Affine::translate((x, y)) };
// A glyph scaled to fill the line keeps its Insert Aki before it at its width.
let transform = if scale != 1.0 {
let aki = if glyph.aki_shift.is_finite() { glyph.aki_shift * (1.0 - scale) } else { 0.0 };
Affine::translate((x + aki, y)) * Affine::scale_non_uniform(scale, 1.0)
} else {
Affine::translate((x, y))
};
if glyph_index < paragraph.marker {
let at = cx.out.glyphs.len();
marker_glyphs = Some(marker_glyphs.map_or(at..at + 1, |range: Range<usize>| range.start.min(at)..range.end.max(at + 1)));
+44 -16
View File
@@ -7,18 +7,23 @@ use super::{Affine, Ctx, Punct, Range, Rect, SGlyph, Tcy, TextLayout, TextObject
/// tate-chu-yoko continuation, a zero-width mark) stays zero. Right to left, a cluster with manual
/// kerning moves by the difference the kerning makes to its rounded advance, so the rounding
/// changes the space before the next character in reading order and not the space after the one
/// before it.
/// before it. Each side of the Insert Aki is rounded to whole points on its own and added to the
/// rounded advance, so justification keeps it at that width.
pub(super) fn whole_character_widths(glyphs: &mut [SGlyph]) {
let whole = |adv: f64| if adv.is_finite() && adv > 0.0 { adv.round().max(1.0) } else { adv };
let points = |aki: f64| if aki.is_finite() { aki.round() } else { 0.0 };
for cluster in glyphs.chunk_by_mut(|a, b| continues_cluster(Some(a), Some(b))) {
// The cluster's last glyph carries the manual kerning in its advance.
let (adv, shift) = cluster.last().map_or((0.0, 0.0), |g| (g.adv, g.kern_shift));
// The cluster's last glyph carries the manual kerning and the Insert Aki in its advance.
let (adv, shift) = cluster.last().map_or((0.0, 0.0), |g| (g.adv - g.aki, g.kern_shift - g.aki_shift));
let rounded_shift = Some(whole(adv) - whole(adv - shift)).filter(|s| s.is_finite()).unwrap_or(shift);
for g in cluster {
g.adv = whole(g.adv);
if shift != 0.0 {
g.kern_shift = rounded_shift;
}
// The space before the character and the space after it are each rounded.
let aki_shift = points(g.aki_shift);
let aki = if g.aki == 0.0 { 0.0 } else { aki_shift + points(g.aki - g.aki_shift) };
g.adv = whole(g.adv - g.aki) + aki;
g.kern_shift = if shift != 0.0 { rounded_shift } else { g.kern_shift - g.aki_shift } + aki_shift;
g.aki = aki;
g.aki_shift = aki_shift;
}
}
}
@@ -33,7 +38,10 @@ pub(super) fn whole_character_widths(glyphs: &mut [SGlyph]) {
/// before the automatic digit rule. A marked block moves by the Tate-chu-yoko Settings Up/Down
/// and Left/Right of its first character; an automatic block does not move.
/// <https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html>
pub(super) fn tate_chu_yoko(g: &mut [SGlyph], style: impl Fn(&SGlyph) -> TcyStyle) {
///
/// With `whole` (System Layout on or Fractional Widths off), each side of a block's Insert Aki is
/// set in whole points ([`whole_character_widths`]).
pub(super) fn tate_chu_yoko(g: &mut [SGlyph], whole: bool, style: impl Fn(&SGlyph) -> TcyStyle) {
let manual: Vec<bool> = g.iter().map(|gl| gl.ch != '\u{2028}' && style(gl).marked).collect();
let digits: Vec<bool> = g.iter().map(|gl| gl.inline.is_none() && gl.ch.is_ascii_digit()).collect();
let mut i = 0;
@@ -44,7 +52,7 @@ pub(super) fn tate_chu_yoko(g: &mut [SGlyph], style: impl Fn(&SGlyph) -> TcyStyl
end += 1;
}
let first = style(&g[i]);
place_tcy_block(&mut g[i..end], first.size, (first.up, first.right));
place_tcy_block(&mut g[i..end], first.size, (first.up, first.right), whole);
i = end;
continue;
}
@@ -58,7 +66,7 @@ pub(super) fn tate_chu_yoko(g: &mut [SGlyph], style: impl Fn(&SGlyph) -> TcyStyl
}
if (2..=3).contains(&(end - i)) {
let em = style(&g[i]).size;
place_tcy_block(&mut g[i..end], em, (0.0, 0.0));
place_tcy_block(&mut g[i..end], em, (0.0, 0.0), whole);
}
i = end;
}
@@ -74,15 +82,35 @@ pub(super) struct TcyStyle {
}
/// Lay `g` across one em of the column, moved by `(up, right)` points. The first glyph takes the
/// em; the rest share its cell.
fn place_tcy_block(g: &mut [SGlyph], em: f64, (up, right): (f64, f64)) {
let width: f64 = g.iter().map(|gl| gl.adv).sum();
/// em; the rest share its cell. The Insert Aki of the block's first character is space above and
/// below the block, and the Insert Aki of its other characters is left out: the block is set
/// down the column that much further, and its last glyph carries the space in its advance. With
/// `whole`, the space above and the space below are each rounded to whole points.
fn place_tcy_block(g: &mut [SGlyph], em: f64, (up, right): (f64, f64), whole: bool) {
let Some(first) = g.first() else { return };
let (byte, before) = (first.byte, first.aki_shift);
let aki: f64 = g.iter().filter(|gl| gl.byte == byte).map(|gl| gl.aki).sum();
let points = |v: f64| {
if !whole {
v
} else if v.is_finite() {
v.round()
} else {
0.0
}
};
let (before, aki) = (points(before), points(before) + points(aki - before));
let width: f64 = g.iter().map(|gl| gl.adv - gl.aki).sum();
let squeeze = if width > em && width > 0.0 { em / width } else { 1.0 };
let last = g.len() - 1;
let mut ink = 0.0;
for (k, gl) in g.iter_mut().enumerate() {
let adv = gl.adv;
gl.tcy = Some(Tcy { pen: if k == 0 { 0.0 } else { em }, ink, width, squeeze, up, right });
gl.adv = if k == 0 { em } else { 0.0 };
let adv = gl.adv - gl.aki;
gl.tcy = Some(Tcy { pen: if k == 0 { 0.0 } else { em }, ink, width, squeeze, up: up - before, right });
gl.kern_shift -= gl.aki_shift;
gl.aki_shift = 0.0;
gl.aki = if k == last { aki } else { 0.0 };
gl.adv = if k == 0 { em } else { 0.0 } + gl.aki;
ink += adv;
}
}
+2
View File
@@ -20,6 +20,8 @@ fn synthetic_glyphs(specs: &[(usize, usize, f64, char)]) -> Vec<SGlyph> {
dx: 0.0,
dy: 0.0,
kern_shift: 0.0,
aki_shift: 0.0,
aki: 0.0,
sx: 1.0,
sy: 1.0,
bshift: 0.0,
+1 -1
View File
@@ -54,7 +54,7 @@ pub use svg_glyph::{SvgGlyphReader, set_svg_glyph_reader};
pub use kept::{KeptLayoutsFrame, LayoutStamp, keep_layout, take_kept_layout};
use kurbo::{Affine, BezPath, Point, Rect, Shape, Vec2};
pub use layout::{decorations, drawn, fit_first_line, fit_source_lines, layout, layout_with, scaled};
pub use shape::{line_start_space, spacing_scale};
pub use shape::{aki_space, line_start_space, spacing_scale};
pub use vectorcraft_doc::TextObject;
pub use vectorcraft_doc::{AreaFit, FirstBaseline, TextFlow, VerticalAlign};
+64 -19
View File
@@ -13,7 +13,7 @@ use kurbo::Shape;
use skrifa::MetadataProvider;
use skrifa::charmap::Charmap;
use skrifa::instance::Size;
use vectorcraft_doc::text::INLINE_CHAR;
use vectorcraft_doc::text::{INLINE_CHAR, MAX_AKI};
use vectorcraft_doc::{CharStyle, Digits, InlineArt};
use crate::features::{OtFeatures, ligatures_suppressed_by};
@@ -41,8 +41,14 @@ pub(crate) struct SGlyph {
/// outside its Character Rotation; with whole-point advances, the difference the kerning makes
/// to the cluster's rounded advance. Left to right and in vertical type: the space before a
/// line's first character ([`CharStyle::kerning_before`]), which moves it along the line the
/// same way. 0 otherwise.
/// same way. Insert Aki ([`aki`]) adds the space before the cluster in reading order: left to
/// right and in vertical type the Aki Left, right to left the Aki Right. 0 otherwise.
pub kern_shift: f64,
/// The Insert Aki `kern_shift` holds, in points, on every glyph of its cluster.
pub aki_shift: f64,
/// The Insert Aki Left and Right `adv` holds, in points: on the last glyph of its cluster, 0
/// on the others. Justification does not stretch or narrow it.
pub aki: f64,
/// Outline scale (font units -> points).
pub sx: f64,
pub sy: f64,
@@ -190,6 +196,8 @@ pub(crate) fn hyphen_glyph(g: &SGlyph) -> SGlyph {
h.dx = 0.0;
h.dy = 0.0;
h.kern_shift = 0.0;
h.aki_shift = 0.0;
h.aki = 0.0;
h.byte = g.byte + g.len;
h.len = 0;
h.ch = '-';
@@ -573,6 +581,22 @@ pub fn line_start_space(text: &str, byte: usize, st: &CharStyle, vertical: bool)
space_before(text, byte, st, glyph_size(st, small) * spacing_scale(st, vertical))
}
/// Insert Aki Left and Right ([`CharStyle::aki_left`], [`CharStyle::aki_right`]) of characters in
/// style `st`, in points of `spacing_em`: the space before and after each cluster in reading order,
/// each from 0 to [`MAX_AKI`] thousandths of it. Its cluster takes both in its advance.
fn aki(st: &CharStyle, spacing_em: f64) -> (f64, f64) {
let side = |v: f64| Some(v.clamp(0.0, MAX_AKI) / 1000.0 * spacing_em).filter(|s| s.is_finite()).unwrap_or(0.0);
(side(st.aki_left), side(st.aki_right))
}
/// The Insert Aki before and after the character at `byte` of `text` in style `st`, in points, as
/// the layout sets it ([`CharStyle::aki_left`]): its thousandths of the em the character is set in.
/// For writers that place characters themselves.
pub fn aki_space(text: &str, byte: usize, st: &CharStyle, vertical: bool) -> (f64, f64) {
let small = st.small_caps.is_some() && !st.all_caps && text.get(byte..).and_then(|s| s.chars().next()).is_some_and(char::is_lowercase);
aki(st, glyph_size(st, small) * spacing_scale(st, vertical))
}
/// The size characters in style `st` are shaped at: Superscript, Subscript and synthesized Small
/// Caps (`small`: a lowercase letter in them) shrink the glyphs; line metrics keep the full size.
fn glyph_size(st: &CharStyle, small: bool) -> f64 {
@@ -808,8 +832,10 @@ fn optical_pairs(db: &FontDb, text: &str, glyphs: &mut [SGlyph], runs: &[(Range<
continue;
}
// Neither glyph is rotated, so a right-to-left manual kerning shift adds to the offset.
let left_x = left.dx + left.kern_shift;
let right_x = right.dx + right.kern_shift;
// Insert Aki is measured as no space: the pair is spaced as it would be without it, and
// the Aki stays on top of that.
let left_x = left.dx + left.kern_shift - left.aki_shift;
let right_x = right.dx + right.kern_shift - right.aki_shift;
let left_y = left.dy - left.bshift;
let right_y = right.dy - right.bshift;
let Some(left_style) = runs.get(left.run).map(|(_, s)| *s) else { continue };
@@ -818,7 +844,7 @@ fn optical_pairs(db: &FontDb, text: &str, glyphs: &mut [SGlyph], runs: &[(Range<
let tracking = left_style.tracking / 1000.0 * em * spacing_scale(left_style, false);
// A manual kerning value on the left glyph is part of its advance and, right to left, of
// its offset too (it spaces the left glyph from its left neighbor): it is not taken off.
let advance = glyphs[cluster_start..=cluster_end].iter().map(|g| g.adv).sum::<f64>() - tracking;
let advance = glyphs[cluster_start..=cluster_end].iter().map(|g| g.adv - g.aki).sum::<f64>() - tracking;
let key = [
u64::from(left.face.id()),
u64::from(left.gid),
@@ -878,8 +904,9 @@ fn source_run_at(runs: &[(Range<usize>, &CharStyle)], span: &Range<usize>, byte:
/// Can one glyph draw characters in styles `a` and `b`? OpenType features already apply to their
/// own character ranges during shaping, so feature-only differences do not split a cluster.
/// Horizontal type does not read Standard Vertical Roman Alignment or the tate-chu-yoko offsets.
/// The space before a line's first character ([`space_before`]) comes from the cluster's first
/// character, so it does not split a ligature either.
/// The space before a line's first character ([`space_before`]) and Insert Aki ([`aki`]) come
/// from the cluster's first character, so they do not split a ligature or a letter from its marks
/// either.
fn drawn_alike(a: &CharStyle, b: &CharStyle, vertical: bool) -> bool {
// Exhaustive, like `shapes_alike`: compare borrowed fields without copying feature lists.
let CharStyle {
@@ -892,6 +919,8 @@ fn drawn_alike(a: &CharStyle, b: &CharStyle, vertical: bool) -> bool {
tracking,
kerning,
kerning_before,
aki_left,
aki_right,
optical_kerning,
baseline_shift,
h_scale,
@@ -932,6 +961,8 @@ fn drawn_alike(a: &CharStyle, b: &CharStyle, vertical: bool) -> bool {
let offsets = (standard_vertical_roman, tcy_up_down, tcy_left_right);
let other_offsets = if vertical { (&b.standard_vertical_roman, &b.tcy_up_down, &b.tcy_left_right) } else { offsets };
kerning_before == &a.kerning_before
&& aki_left == &a.aki_left
&& aki_right == &a.aki_right
&& offsets == other_offsets
&& font_family == &b.font_family
&& font_style == &b.font_style
@@ -979,9 +1010,9 @@ fn drawn_alike(a: &CharStyle, b: &CharStyle, vertical: bool) -> bool {
/// character style's name, leading, baseline shift, rotation, Character Alignment, Character
/// Direction (text is shaped apart where its bidi level changes), Kashidas, the kerning (each glyph takes its
/// run's, see [`shape_segment`]), the space before a line's first character ([`space_before`]),
/// the OpenType features (each run's apply to its own characters, as features over a range of the
/// one buffer) and the tracking, as long as the tracking keeps or drops standard ligatures alike
/// ([`crate::features::ligatures_suppressed_by`]).
/// Insert Aki ([`aki`]), the OpenType features (each run's apply to its own characters, as features
/// over a range of the one buffer) and the tracking, as long as the tracking keeps or drops
/// standard ligatures alike ([`crate::features::ligatures_suppressed_by`]).
fn shapes_alike(a: &CharStyle, b: &CharStyle) -> bool {
// Every field is named, so that a new attribute has to be sorted into one group or the other.
let CharStyle {
@@ -994,6 +1025,8 @@ fn shapes_alike(a: &CharStyle, b: &CharStyle) -> bool {
tracking,
kerning: _,
kerning_before: _,
aki_left: _,
aki_right: _,
optical_kerning: _,
baseline_shift: _,
h_scale,
@@ -1095,9 +1128,9 @@ fn shaping_script(c: char) -> Script {
/// The art is scaled uniformly to `scale` x the font size tall, its left edge on the pen and its
/// vertical centre on the middle of the cap height raised by the inline's shift (see
/// [`InlineArt`]). Its advance is the scaled art width plus tracking, its character's manual
/// kerning and the space before it at a line's start ([`space_before`]). Right to left in
/// horizontal type the manual kerning also moves the art right by the value, as it
/// moves a letter's glyph. The art doesn't take the run's Horizontal Scale; the tracking and the
/// kerning, the space before it at a line's start ([`space_before`]) and its Insert Aki ([`aki`]).
/// Right to left in horizontal type the manual kerning also moves the art right by the value, as it
/// moves a letter's glyph, and Insert Aki moves it as it moves a letter's glyph. The art doesn't take the run's Horizontal Scale; the tracking and the
/// kerning do, as after a letter ([`spacing_scale`]). The glyph's ascent and descent grow to the
/// art's extent so a tall graphic opens up its line. A missing symbol takes a square of the same
/// height and draws nothing.
@@ -1131,7 +1164,9 @@ fn inline_glyph(
let tracking = Some(st.tracking / 1000.0 * spacing_em).filter(|t| t.is_finite()).unwrap_or(0.0);
let manual_kern = st.kerning.map(|v| v / 1000.0 * spacing_em).filter(|k| k.is_finite()).unwrap_or(0.0);
let before = space_before(text, range.start, st, spacing_em);
let adv = width + tracking + manual_kern + before;
let (aki_left, aki_right) = aki(st, spacing_em);
let adv = width + tracking + manual_kern + before + aki_left + aki_right;
let aki_shift = if level.is_rtl() && !vertical { aki_right } else { aki_left };
SGlyph {
face: face.clone(),
gid: 0,
@@ -1142,7 +1177,9 @@ fn inline_glyph(
tracking: if adv.is_finite() { tracking } else { 0.0 },
dx: 0.0,
dy: 0.0,
kern_shift: if level.is_rtl() && !vertical { manual_kern } else { before },
kern_shift: if level.is_rtl() && !vertical { manual_kern } else { before } + aki_shift,
aki_shift,
aki: if adv.is_finite() { aki_left + aki_right } else { 0.0 },
// Not used to draw (the art has its own transform), but they make the glyph's em box
// its run's em: Character Alignment and Top-to-Top leading treat an inline graphic as a
// character of its run's size, whatever its scale (see `layout::glyph_em`).
@@ -1590,23 +1627,29 @@ fn shape_segment(text: &str, context: &Range<usize>, seg: &Segment, feats: &OtFe
};
let mut kern_shift = 0.0;
let mut tracked = 0.0;
let (mut aki_shift, mut aki_in_adv) = (0.0, 0.0);
if ch == SOFT_HYPHEN || ch == '\u{2028}' {
adv = 0.0;
} else {
let manual_kern = gst.kerning.map(|v| v / 1000.0 * spacing_em).unwrap_or(0.0);
let before = space_before(text, cl, gst, spacing_em);
let (aki_left, aki_right) = aki(gst, spacing_em);
// Manual kerning spaces a character from the next one in reading order. Right to left,
// that one is drawn to its left: the cluster's glyphs move right along the baseline by
// the value, so that the space its last glyph's advance gains is at the cluster's left.
// The space before a line's first character moves them the other way.
// The space before a line's first character moves them the other way. Insert Aki moves
// them past the space before them in reading order: Aki Left, or right to left Aki Right.
if level.is_rtl() && !feats.vertical {
kern_shift = manual_kern;
aki_shift = aki_right;
kern_shift = manual_kern + aki_shift;
} else {
kern_shift = before;
aki_shift = aki_left;
kern_shift = before + aki_shift;
}
if last_in_cluster {
tracked = gst.tracking / 1000.0 * spacing_em;
adv += tracked + manual_kern + before;
aki_in_adv = aki_left + aki_right;
adv += tracked + manual_kern + before + aki_in_adv;
}
}
out.push(SGlyph {
@@ -1620,6 +1663,8 @@ fn shape_segment(text: &str, context: &Range<usize>, seg: &Segment, feats: &OtFe
dx: xo as f64 * k * hs,
dy: -(yo as f64) * k * vs,
kern_shift,
aki_shift,
aki: aki_in_adv,
sx: k * hs,
sy: k * vs,
bshift: gst.baseline_shift + pos_shift,
+1
View File
@@ -3,6 +3,7 @@ use kurbo::{Affine, Shape};
use vectorcraft_doc::{CharStyle, Justify, TextKind, TextRun};
use vectorcraft_geom::PathData;
mod aki;
mod alternates;
mod axes;
mod bidi;
+243
View File
@@ -0,0 +1,243 @@
//! Insert Aki Left and Right (`CharStyle::aki_left`, `CharStyle::aki_right`): space before and
//! after a character in reading order, in thousandths of its em, that wrapping counts, alignment
//! keeps at a line's end and justification does not stretch.
use super::{area, db, point, serif, style};
use crate::*;
use kurbo::Shape;
use vectorcraft_doc::{CharStyle, Justify};
/// Where glyph `byte` is drawn along a horizontal line.
fn drawn_x(l: &TextLayout, byte: usize) -> f64 {
l.glyphs.iter().find(|g| g.byte == byte).map(|g| g.xf.as_coeffs()[4]).unwrap()
}
/// `t` with `f` applied to the style of the character at `byte`.
fn with(t: &TextObject, byte: usize, f: impl Fn(&mut CharStyle)) -> TextObject {
let mut t = t.clone();
let end = edit::next_char(&t.plain_text(), byte);
edit::style_range(&mut t.runs, byte, end, f);
t
}
/// How far each of `bytes` moved along the line from `a` to `b`, laid out in `fonts`.
fn moves_in(fonts: &FontDb, a: &TextObject, b: &TextObject, bytes: &[usize]) -> Vec<f64> {
let (la, lb) = (layout(fonts, a), layout(fonts, b));
bytes.iter().map(|&i| drawn_x(&lb, i) - drawn_x(&la, i)).collect()
}
fn moves(a: &TextObject, b: &TextObject, bytes: &[usize]) -> Vec<f64> {
moves_in(db(), a, b, bytes)
}
fn near(values: &[f64], expected: &[f64]) -> bool {
values.len() == expected.len() && values.iter().zip(expected).all(|(v, e)| (v - e).abs() < 1e-6)
}
#[test]
fn aki_left_spaces_before_a_character_and_aki_right_after_it() {
let plain = point("HOH", style(100.0));
// 250/1000 em of 100 pt before the O: 25 pt, the O and the H after it move.
let left = moves(&plain, &with(&plain, 1, |s| s.aki_left = 250.0), &[0, 1, 2]);
assert!(near(&left, &[0.0, 25.0, 25.0]), "{left:?}");
// After the O: only the H after it moves.
let right = moves(&plain, &with(&plain, 1, |s| s.aki_right = 250.0), &[0, 1, 2]);
assert!(near(&right, &[0.0, 0.0, 25.0]), "{right:?}");
// Both sides add up, and a value above one em is kept to one em.
let both = moves(&plain, &with(&plain, 1, |s| (s.aki_left, s.aki_right) = (250.0, 500.0)), &[0, 1, 2]);
assert!(near(&both, &[0.0, 25.0, 75.0]), "{both:?}");
let most = moves(&plain, &with(&plain, 1, |s| s.aki_right = 5000.0), &[2]);
assert!(near(&most, &[100.0]), "{most:?}");
let not_a_number = moves(&plain, &with(&plain, 1, |s| s.aki_left = f64::NAN), &[1, 2]);
assert!(near(&not_a_number, &[0.0, 0.0]), "{not_a_number:?}");
assert_eq!(aki_space("HOH", 1, &with(&plain, 1, |s| s.aki_left = 500.0).runs[1].style, false), (50.0, 0.0));
}
#[test]
fn aki_takes_the_em_of_the_character_as_tracking_does() {
let narrow = point("HOH", CharStyle { h_scale: 50.0, ..style(100.0) });
let moved = moves(&narrow, &with(&narrow, 1, |s| s.aki_left = 250.0), &[1, 2]);
assert!(near(&moved, &[12.5, 12.5]), "{moved:?}");
}
#[test]
fn optical_kerning_spaces_the_pair_as_without_the_aki() {
let optical = point("AVA", CharStyle { optical_kerning: true, ..style(100.0) });
let moved = moves(&optical, &with(&optical, 1, |s| s.aki_left = 250.0), &[0, 1, 2]);
assert!(near(&moved, &[0.0, 25.0, 25.0]), "{moved:?}");
let moved = moves(&optical, &with(&optical, 0, |s| s.aki_right = 250.0), &[0, 1, 2]);
assert!(near(&moved, &[0.0, 25.0, 25.0]), "{moved:?}");
}
#[test]
fn a_right_aligned_line_keeps_the_aki_after_its_last_character() {
let mut right = point("HOH", style(100.0));
right.para.justify = Justify::Right;
// Unlike the tracking after a line's last character, the Aki is part of the line.
let moved = moves(&right, &with(&right, 2, |s| s.aki_right = 250.0), &[0, 1, 2]);
assert!(near(&moved, &[-25.0, -25.0, -25.0]), "{moved:?}");
let tracked = moves(&right, &with(&right, 2, |s| s.tracking = 250.0), &[0, 2]);
assert!(near(&tracked, &[0.0, 0.0]), "{tracked:?}");
// At the line's start the Aki Left is kept too.
let mut left = point("HOH", style(100.0));
left.para.justify = Justify::Left;
let moved = moves(&left, &with(&left, 0, |s| s.aki_left = 250.0), &[0, 2]);
assert!(near(&moved, &[25.0, 25.0]), "{moved:?}");
}
#[test]
fn a_line_too_wide_with_its_aki_wraps() {
let one = layout(db(), &point("HOH HOH", style(50.0)));
let wide = one.lines[0].x1 - one.lines[0].x0;
let line_of = |t: &TextObject, byte: usize| layout(db(), t).glyphs.iter().find(|g| g.byte == byte).unwrap().line;
let fits = area("HOH HOH", style(50.0), Rect::new(0.0, 0.0, wide + 5.0, 400.0), Justify::Left);
assert_eq!(line_of(&fits, 4), 0, "both words fit");
// 250/1000 em of 50 pt is 12.5 pt, more than the 5 pt the frame has left.
assert_eq!(line_of(&with(&fits, 1, |s| s.aki_right = 250.0), 4), 1, "the second word wraps");
// The Aki after the last letter of a wrapped line stays on that line: the next line starts
// where it did.
let narrow = area("HOH HOH", style(50.0), Rect::new(0.0, 0.0, wide * 0.6, 400.0), Justify::Left);
let spaced = with(&narrow, 2, |s| s.aki_right = 250.0);
assert_eq!((line_of(&narrow, 4), line_of(&spaced, 4)), (1, 1));
let moved = moves(&narrow, &spaced, &[0, 4, 5]);
assert!(near(&moved, &[0.0, 0.0, 0.0]), "{moved:?}");
}
#[test]
fn justification_does_not_stretch_or_narrow_the_aki() {
// Desired Glyph Scaling 150% widens every glyph, and Word Spacing 200% every word space; the Aki
// stays 25 pt wide.
let mut scaled = point("HOH", style(100.0));
scaled.para.justification.glyph_scaling = [150.0, 150.0, 150.0];
let moved = moves(&scaled, &with(&scaled, 0, |s| s.aki_right = 250.0), &[0, 1, 2]);
assert!(near(&moved, &[0.0, 25.0, 25.0]), "{moved:?}");
let moved = moves(&scaled, &with(&scaled, 1, |s| s.aki_left = 250.0), &[1, 2]);
assert!(near(&moved, &[25.0, 25.0]), "{moved:?}");
let mut spaced = point("H H", style(100.0));
spaced.para.justification.word_spacing = [200.0, 200.0, 200.0];
let moved = moves(&spaced, &with(&spaced, 1, |s| s.aki_right = 250.0), &[0, 2]);
assert!(near(&moved, &[0.0, 25.0]), "{moved:?}");
}
#[test]
fn with_whole_point_widths_the_aki_is_whole_points_and_justification_keeps_it() {
// 250/1000 em of 10 pt is 2.5 pt, set as 3 pt with Fractional Widths off, with or without
// Desired Glyph Scaling 150%.
for scaling in [100.0, 150.0] {
let mut plain = point("HOH", style(10.0));
plain.fractional_widths = false;
plain.para.justification.glyph_scaling = [scaling; 3];
let left = moves(&plain, &with(&plain, 1, |s| s.aki_left = 250.0), &[0, 1, 2]);
assert!(near(&left, &[0.0, 3.0, 3.0]), "Glyph Scaling {scaling}: {left:?}");
let right = moves(&plain, &with(&plain, 1, |s| s.aki_right = 250.0), &[0, 1, 2]);
assert!(near(&right, &[0.0, 0.0, 3.0]), "Glyph Scaling {scaling}: {right:?}");
// 1.5 pt on each side: each side is set as 2 pt.
let both = moves(&plain, &with(&plain, 1, |s| (s.aki_left, s.aki_right) = (150.0, 150.0)), &[0, 1, 2]);
assert!(near(&both, &[0.0, 2.0, 4.0]), "Glyph Scaling {scaling}: {both:?}");
}
}
#[test]
fn a_ligature_and_a_letter_with_its_mark_take_the_aki_of_their_first_character() {
let plain = point("fit", serif(100.0));
let glyphs = |t: &TextObject| layout(db(), t).glyphs.len();
assert_eq!(glyphs(&plain), 2, "the font joins fi");
let spaced = with(&plain, 0, |s| (s.aki_left, s.aki_right) = (250.0, 250.0));
assert_eq!(glyphs(&spaced), 2, "still joined");
let moved = moves(&plain, &spaced, &[0, 2]);
assert!(near(&moved, &[25.0, 50.0]), "{moved:?}");
// On the i alone it is not read: the ligature's first character is the f.
let on_i = with(&plain, 1, |s| s.aki_right = 250.0);
assert_eq!(glyphs(&on_i), 2);
let moved = moves(&plain, &on_i, &[0, 2]);
assert!(near(&moved, &[0.0, 0.0]), "{moved:?}");
// A combining acute after e: the letter's Aki spaces the pair, the mark's own is not read.
let marked = point("e\u{301}a", style(100.0));
let after = "e\u{301}".len();
let moved = moves(&marked, &with(&marked, 0, |s| s.aki_right = 250.0), &[0, after]);
assert!(near(&moved, &[0.0, 25.0]), "{moved:?}");
let moved = moves(&marked, &with(&marked, 1, |s| s.aki_right = 250.0), &[0, after]);
assert!(near(&moved, &[0.0, 0.0]), "{moved:?}");
}
#[test]
fn right_to_left_aki_left_is_on_the_right_of_the_character() {
// Reading order א ב ג is drawn right to left: Aki Left on ב widens the gap between א and ב,
// Aki Right the gap between ב and ג.
let fonts = FontDb::global();
let plain = point("אבג", style(100.0));
let (a, b, c) = (0, "א".len(), "אב".len());
let gaps = |t: &TextObject| {
let l = layout(fonts, t);
(drawn_x(&l, a) - drawn_x(&l, b), drawn_x(&l, b) - drawn_x(&l, c))
};
let base = gaps(&plain);
let left = gaps(&with(&plain, b, |s| s.aki_left = 250.0));
assert!((left.0 - base.0 - 25.0).abs() < 1e-6 && (left.1 - base.1).abs() < 1e-6, "{base:?} {left:?}");
let right = gaps(&with(&plain, b, |s| s.aki_right = 250.0));
assert!((right.0 - base.0).abs() < 1e-6 && (right.1 - base.1 - 25.0).abs() < 1e-6, "{base:?} {right:?}");
}
#[test]
fn in_vertical_type_aki_left_is_above_the_character_and_aki_right_below() {
// An upright glyph (§) and letters lying on their side: 250/1000 em of 20 pt is 5 pt down the
// column.
for text in ["§§", "ab"] {
let mut plain = point(text, style(20.0));
plain.xf = Affine::IDENTITY;
plain.vertical = true;
let centers = |t: &TextObject| layout(db(), t).glyphs.iter().map(|g| g.outline.bounding_box().center()).collect::<Vec<_>>();
let base = centers(&plain);
let second = edit::next_char(text, 0);
// [first, second] glyph moved down the column, for Aki on one character.
for (spaced, down) in [
(with(&plain, 0, |s| s.aki_left = 250.0), [5.0, 5.0]),
(with(&plain, 0, |s| s.aki_right = 250.0), [0.0, 5.0]),
(with(&plain, second, |s| s.aki_left = 250.0), [0.0, 5.0]),
(with(&plain, second, |s| s.aki_right = 250.0), [0.0, 0.0]),
] {
let moved = centers(&spaced);
for i in 0..2 {
assert!((moved[i].y - base[i].y - down[i]).abs() < 1e-6, "{text} {i}: {base:?} {moved:?}");
assert!((moved[i].x - base[i].x).abs() < 1e-6, "{text} {i}: {base:?} {moved:?}");
}
}
}
}
/// A tate-chu-yoko block takes the Insert Aki of its first character above and below it, and
/// keeps its characters across the column as without it.
#[test]
fn a_tate_chu_yoko_block_is_spaced_by_the_aki_of_its_first_character() {
let mut plain = point("a12b", style(20.0));
plain.xf = Affine::IDENTITY;
plain.vertical = true;
let centers = |t: &TextObject| layout(db(), t).glyphs.iter().map(|g| g.outline.bounding_box().center()).collect::<Vec<_>>();
let base = centers(&plain);
assert_eq!(base.len(), 4);
// [a, 1, 2, b] moved down the column: 250/1000 em of 20 pt is 5 pt.
for (spaced, down) in [
(with(&plain, 1, |s| s.aki_left = 250.0), [0.0, 5.0, 5.0, 5.0]),
(with(&plain, 1, |s| s.aki_right = 250.0), [0.0, 0.0, 0.0, 5.0]),
(with(&plain, 1, |s| (s.aki_left, s.aki_right) = (250.0, 500.0)), [0.0, 5.0, 5.0, 15.0]),
(with(&plain, 2, |s| (s.aki_left, s.aki_right) = (250.0, 500.0)), [0.0; 4]),
] {
let moved = centers(&spaced);
for i in 0..4 {
assert!((moved[i].y - base[i].y - down[i]).abs() < 1e-6, "{i}: {base:?} {moved:?}");
assert!((moved[i].x - base[i].x).abs() < 1e-6, "{i}: {base:?} {moved:?}");
}
}
// With Fractional Widths off, 150/1000 em of 10 pt on each side (1.5 pt) is set as 2 pt above
// the block and 2 pt below it.
let mut whole = point("a12b", style(10.0));
whole.xf = Affine::IDENTITY;
whole.vertical = true;
whole.fractional_widths = false;
let base = centers(&whole);
let moved = centers(&with(&whole, 1, |s| (s.aki_left, s.aki_right) = (150.0, 150.0)));
let down = [0.0, 2.0, 2.0, 4.0];
for i in 0..4 {
assert!((moved[i].y - base[i].y - down[i]).abs() < 1e-6, "{i}: {base:?} {moved:?}");
assert!((moved[i].x - base[i].x).abs() < 1e-6, "{i}: {base:?} {moved:?}");
}
}
@@ -26,9 +26,12 @@ const NUMBERS: &[&str] = &["size", "leading", "kerning", "tracking"];
/// The on, off or unset checkboxes.
const SWITCHES: &[&str] = &["underline", "strikethrough", "standardVerticalRoman"];
/// The attributes of Advanced Character Formats, in the order the section shows them.
const ADVANCED: &[&str] = &["h_scale", "v_scale", "baseline_shift", "tcyUpDown", "tcyLeftRight", "rotation", "language"];
const ADVANCED: &[&str] = &["h_scale", "v_scale", "baseline_shift", "tcyUpDown", "tcyLeftRight", "rotation", "akiLeft", "akiRight", "language"];
/// The number fields of Advanced Character Formats.
const ADVANCED_NUMBERS: &[&str] = &["h_scale", "v_scale", "baseline_shift", "tcyUpDown", "tcyLeftRight", "rotation"];
const ADVANCED_NUMBERS: &[&str] = &["h_scale", "v_scale", "baseline_shift", "tcyUpDown", "tcyLeftRight", "rotation", "akiLeft", "akiRight"];
/// The Insert Aki Left and Right fields, which take the Character panel's presets and stop at
/// [`vectorcraft_doc::text::MAX_AKI`].
const AKI: [&str; 2] = ["akiLeft", "akiRight"];
/// The attributes of Character Color.
const COLOR: &[&str] = &["fill", "stroke", "stroke_width", "overprint_fill", "overprint_stroke"];
/// The fields of Character Color: the fill and stroke paints, their tints in percent, the stroke
@@ -81,6 +84,8 @@ pub(super) const SPEC: DialogSpec = DialogSpec {
"tcyUpDown",
"tcyLeftRight",
"rotation",
"akiLeft",
"akiRight",
"language",
"fill",
"fill_tint",
@@ -268,6 +273,8 @@ fn optional_number(d: &Dialog, key: &str) -> Result<Option<Value>, String> {
"tcyUpDown" => tl!("Tate-chu-yoko Up/Down"),
"tcyLeftRight" => tl!("Tate-chu-yoko Left/Right"),
"rotation" => tl!("Character Rotation"),
"akiLeft" => tl!("Insert Aki Left"),
"akiRight" => tl!("Insert Aki Right"),
"fill_tint" => tl!("Fill Tint"),
"stroke_tint" => tl!("Stroke Tint"),
"stroke_width" => tl!("Weight"),
@@ -312,6 +319,9 @@ fn optional_number(d: &Dialog, key: &str) -> Result<Option<Value>, String> {
}
// An angle from -180 to 180 degrees, as text.setFormat stores it.
let n = if key == "rotation" { (n + 180.0).rem_euclid(360.0) - 180.0 } else { n };
// Insert Aki stops at 0 and at the largest value the style takes, as the Character
// panel's fields do.
let n = if AKI.contains(&key) { n.clamp(0.0, vectorcraft_doc::text::MAX_AKI) } else { n };
Ok(Some(json!(n)))
}
}
@@ -590,7 +600,7 @@ pub(crate) fn reset_basic(d: &mut Dialog) {
}
}
/// Reset Panel in Advanced Character Formats: its seven attributes become unset.
/// Reset Panel in Advanced Character Formats: its nine attributes become unset.
pub(crate) fn reset_advanced(d: &mut Dialog) {
d.fields.insert("__resetAdvanced".into(), json!(true));
for key in ADVANCED_NUMBERS {
@@ -745,7 +755,8 @@ pub(crate) fn basic_body(ui: &mut egui::Ui, d: &mut Dialog) {
}
/// Advanced Character Formats: Horizontal Scale, Vertical Scale, Baseline Shift, the Tate-chu-yoko
/// Up/Down and Left/Right, Character Rotation and Language, each empty (unset) or set.
/// Up/Down and Left/Right, Character Rotation, Insert Aki Left and Right (with the Character
/// panel's presets) and Language, each empty (unset) or set.
pub(crate) fn advanced_body(ui: &mut egui::Ui, d: &mut Dialog) {
egui::Grid::new("character-style-advanced").num_columns(2).spacing([18.0, 8.0]).show(ui, |ui| {
for (key, caption, unit) in [
@@ -766,6 +777,16 @@ pub(crate) fn advanced_body(ui: &mut egui::Ui, d: &mut Dialog) {
});
ui.end_row();
}
let presets: Vec<String> = crate::panels::character::AKI_PRESETS.iter().map(f64::to_string).collect();
let presets: Vec<&str> = presets.iter().map(String::as_str).collect();
for (key, caption) in [("akiLeft", tl!("Insert Aki Left")), ("akiRight", tl!("Insert Aki Right"))] {
let row = ui.label(caption);
let value = if d.fields.get(key).is_none_or(Value::is_null) { String::new() } else { d.str(key) };
if let Some(v) = ui.label_inputs_by(row.id, |ui| crate::widgets::text_presets(ui, (KIND, key), &value, &presets, 160.0)) {
d.fields.insert(key.into(), json!(v));
}
ui.end_row();
}
let row = ui.label(tl!("Language:"));
let names: Vec<&str> = std::iter::once(" ").chain(vectorcraft_doc::setup::LANGUAGES.iter().map(|(name, _, _)| *name)).collect();
let current = d.fields.get("language").and_then(Value::as_str).unwrap_or("").to_string();
@@ -1684,6 +1705,60 @@ mod tests {
assert_eq!(def.attrs["tcyLeftRight"], json!(6.0));
}
#[test]
fn insert_aki_fields_show_set_reset_and_stop_at_the_character_panel_limits() {
let d = dialog_for(json!({"akiLeft": 250.0, "size": 12.0}));
assert_eq!((d.fields["akiLeft"].clone(), d.fields["akiRight"].clone()), (json!(250.0), json!("")));
assert_eq!(edited_attrs(&d).unwrap(), attrs(json!({"akiLeft": 250.0, "size": 12.0})));
let mut d = dialog_for(json!({"akiLeft": 250.0}));
d.fields.insert("akiLeft".into(), json!(""));
d.fields.insert("akiRight".into(), json!("500"));
assert_eq!(edited_attrs(&d).unwrap(), attrs(json!({"akiRight": 500.0})));
// A typed value stops at 0 and at 1000, as in the Character panel's fields.
for (typed, kept) in [("5000", 1000.0), ("-5", 0.0), ("1000", 1000.0)] {
d.fields.insert("akiRight".into(), json!(typed));
assert_eq!(edited_attrs(&d).unwrap(), attrs(json!({"akiRight": kept})), "{typed}");
}
d.fields.insert("akiLeft".into(), json!("wide"));
assert_eq!(edited_attrs(&d).unwrap_err(), "Insert Aki Left must be a number");
let mut d = dialog_for(json!({"akiLeft": 250.0, "akiRight": 500.0, "size": 12.0}));
d.fields.insert("section".into(), json!("advanced"));
reset_section(&mut d);
assert_eq!(edited_attrs(&d).unwrap(), attrs(json!({"size": 12.0})));
}
#[test]
fn insert_aki_fields_are_drawn_and_commit_to_the_style_and_its_text() {
let mut app = app();
app.run("charStyle.new", json!({"name": "Body", "attrs": {"size": 24.0}})).unwrap();
let id = app.run("text.create", json!({"x": 10, "y": 40, "text": "Text"})).unwrap()["id"].as_u64().unwrap();
app.run("charStyle.apply", json!({"name": "Body", "id": id})).unwrap();
open(&mut app, "Body").unwrap();
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 900.0));
let mut d = app.ui.dialog.clone().unwrap();
let input = egui::RawInput { screen_rect: Some(screen), ..Default::default() };
let mut out = ctx.run_ui(input, |ui| advanced_body(ui, &mut d));
let texts = texts_of(&out);
out.textures_delta.clear();
for label in ["Insert Aki Left", "Insert Aki Right"] {
assert!(texts.iter().any(|(text, _)| text == label), "{label} is drawn: {texts:?}");
}
{
let d = app.ui.dialog.as_mut().unwrap();
d.fields.insert("akiLeft".into(), json!("250"));
d.fields.insert("akiRight".into(), json!("2000"));
}
super::super::confirm(&mut app).unwrap();
let state = app.session.doc().unwrap();
assert_eq!(state.doc.char_styles[0].attrs, attrs(json!({"size": 24.0, "akiLeft": 250.0, "akiRight": 1000.0})));
let vectorcraft_doc::NodeKind::Text(t) = &state.doc.node(vectorcraft_doc::NodeId(id)).unwrap().kind else { panic!("text") };
assert!(t.runs.iter().all(|r| (r.style.aki_left, r.style.aki_right) == (250.0, 1000.0)));
}
/// The negated tags of the twenty stylistic sets: an explicit empty Stylistic Sets choice.
fn no_sets() -> Vec<String> {
vectorcraft_text::EXTRA_FEATURES[..20].iter().map(|s| format!("-{s}")).collect()
+2
View File
@@ -2540,6 +2540,8 @@ font-technology Variable Променливи
Proof Setup Настройка на пробен печат
Properties Свойства
Proportional Metrics Пропорционални метрики
Insert Aki Left Вмъкване на аки отляво
Insert Aki Right Вмъкване на аки отдясно
Character Direction Посока на знаците
Digits Цифри
Arabic Арабски
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1558,6 +1558,8 @@ lighting Light Svjetlo
Leading Prored
No Break Bez preloma
Proportional Metrics Proporcionalna metrika
Insert Aki Left Umetni aki lijevo
Insert Aki Right Umetni aki desno
Character Direction Smjer znakova
Digits Cifre
Arabic Arapski
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -3298,6 +3298,8 @@ digits Malayalam Malaiàlam
Proof Setup Configuració de prova
Properties Propietats
Proportional Metrics Mètriques proporcionals
Insert Aki Left Insereix aki a l'esquerra
Insert Aki Right Insereix aki a la dreta
Proportional Lining Xifres proporcionals alineades
Position: Posició:
Default Position Posició predeterminada
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1586,6 +1586,8 @@ lighting Light Světlo
Leading Proklad
No Break Nezalamovat
Proportional Metrics Proporcionální metrika
Insert Aki Left Vložit aki vlevo
Insert Aki Right Vložit aki vpravo
Character Direction Směr znaků
Digits Číslice
Arabic Arabské
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1494,6 +1494,8 @@ lighting Light Lys
Leading Linjeafstand
No Break Ingen ombrydning
Proportional Metrics Proportionale metrikker
Insert Aki Left Indsæt aki til venstre
Insert Aki Right Indsæt aki til højre
Character Direction Tegnretning
Digits Cifre
Arabic Arabisk
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -2584,6 +2584,8 @@ mark-style Japanese Japanisch
Proof Setup Proof einrichten
Properties Eigenschaften
Proportional Metrics Proportionale Metrik
Insert Aki Left Aki links einfügen
Insert Aki Right Aki rechts einfügen
Character Direction Zeichenrichtung
Digits Ziffern
Arabic Arabisch
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -3281,6 +3281,8 @@ theme Appearance Εμφάνιση
Profile inclusion: Συμπερίληψη προφίλ:
Projecting Cap Προεξέχον άκρο
Proportional Metrics Αναλογικές μετρικές
Insert Aki Left Εισαγωγή aki αριστερά
Insert Aki Right Εισαγωγή aki δεξιά
Arabic Αραβικά
Hindi Χίντι
Farsi Περσικά
Can't render this file because it is too large.
+2
View File
@@ -2618,6 +2618,8 @@ font-technology Variable Variables
Proof Setup Ajuste de prueba
Properties Propiedades
Proportional Metrics Métrica proporcional
Insert Aki Left Insertar aki a la izquierda
Insert Aki Right Insertar aki a la derecha
Character Direction Dirección de caracteres
Digits Dígitos
Arabic Árabes
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1561,6 +1561,8 @@ lighting Light Valo
Leading Riviväli
No Break Ei katkoa
Proportional Metrics Suhteelliset metriikat
Insert Aki Left Lisää aki vasemmalle
Insert Aki Right Lisää aki oikealle
Character Direction Merkkien suunta
Digits Numerot
Arabic Arabia
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -2610,6 +2610,8 @@ font-technology Variable Variables
Proof Setup Format d’épreuve
Properties Propriétés
Proportional Metrics Métrique proportionnelle
Insert Aki Left Insérer un aki à gauche
Insert Aki Right Insérer un aki à droite
Character Direction Direction des caractères
Digits Chiffres
Arabic Arabes
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -3601,6 +3601,8 @@ antiAlias Sharp शार्प
Properties प्रॉपर्टीज़
Proportional Lining आनुपातिक लाइनिंग
Proportional Metrics आनुपातिक मीट्रिक
Insert Aki Left बाईं ओर आकी जोड़ें
Insert Aki Right दाईं ओर आकी जोड़ें
Proportional Oldstyle आनुपातिक ओल्डस्टाइल
Protect Corners कॉर्नर को सुरक्षित रखें
Proximity Guides निकटता गाइड
Can't render this file because it is too large.
+2
View File
@@ -3169,6 +3169,8 @@ mark-style Japanese Japán
Proof Setup Színpróba beállítása
Properties Tulajdonságok
Proportional Metrics Arányos metrika
Insert Aki Left Aki beszúrása balra
Insert Aki Right Aki beszúrása jobbra
Proportional Lining Arányos modern
Position: Pozíció:
Default Position Alapértelmezett pozíció
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1494,6 +1494,8 @@ lighting Light Cahaya
Leading Leading
No Break Tanpa pemenggalan
Proportional Metrics Metrik proporsional
Insert Aki Left Sisipkan aki kiri
Insert Aki Right Sisipkan aki kanan
Character Direction Arah karakter
Digits Digit
Arabic Arab
1 # Indonesian (id) catalog. Same format as zh-hant.tsv: context <TAB> source <TAB> translation
1494
1495
1496
1497
1498
1499
1500
1501
+2
View File
@@ -2660,6 +2660,8 @@ mark-style Japanese Giapponese
Proof Setup Impostazione prova
Properties Proprietà
Proportional Metrics Metrica proporzionale
Insert Aki Left Inserisci aki a sinistra
Insert Aki Right Inserisci aki a destra
Character Direction Direzione caratteri
Digits Cifre
Arabic Arabe
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -50,6 +50,8 @@ font-technology Variable バリアブル
x-Height x ハイト
ICF Box 平均字面
Proportional Metrics プロポーショナルメトリクス
Insert Aki Left 前にアキを挿入
Insert Aki Right 後ろにアキを挿入
Character Direction 文字の方向
Digits 数字
Arabic アラビア数字
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1431,6 +1431,8 @@ lighting Light სინათლე
Leading სტრიქონთა დაშორება
No Break გადატანის გარეშე
Proportional Metrics პროპორციული მეტრიკა
Insert Aki Left აკის ჩასმა მარცხნივ
Insert Aki Right აკის ჩასმა მარჯვნივ
Character Direction სიმბოლოების მიმართულება
Digits ციფრები
Arabic არაბული
Can't render this file because it is too large.
+2
View File
@@ -44,6 +44,8 @@ font-technology Variable 가변
x-Height x 높이
ICF Box ICF 박스
Proportional Metrics 비례 메트릭
Insert Aki Left 앞 아키 삽입
Insert Aki Right 뒤 아키 삽입
Character Direction 문자 방향
Digits 숫자
Arabic 아라비아어
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1508,6 +1508,8 @@ lighting Light Licht
Leading Regelafstand
No Break Niet afbreken
Proportional Metrics Proportionele metingen
Insert Aki Left Aki links invoegen
Insert Aki Right Aki rechts invoegen
Character Direction Tekenrichting
Digits Cijfers
Arabic Arabisch
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -1499,6 +1499,8 @@ lighting Light Światło
Leading Interlinia
No Break Bez podziału
Proportional Metrics Metryka proporcjonalna
Insert Aki Left Wstaw aki z lewej
Insert Aki Right Wstaw aki z prawej
Character Direction Kierunek znaków
Digits Cyfry
Arabic Arabskie
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -2188,6 +2188,8 @@ antiAlias Sharp Nítido
Proof Setup Configuração de Prova
Properties Propriedades
Proportional Metrics Métrica Proporcional
Insert Aki Left Inserir Aki à Esquerda
Insert Aki Right Inserir Aki à Direita
Character Direction Direção de Caracteres
Digits Dígitos
Arabic Arábicos
Can't render this file because it contains an unexpected character in line 6 and column 47.
+2
View File
@@ -2647,6 +2647,8 @@ mark-style Japanese Японский
Proof Setup Настройка цветопробы
Properties Свойства
Proportional Metrics Пропорциональные метрики
Insert Aki Left Вставить аки слева
Insert Aki Right Вставить аки справа
Character Direction Направление символов
Digits Цифры
Arabic Арабские
Can't render this file because it is too large.
+2
View File
@@ -2555,6 +2555,8 @@ font-technology Variable Variabla
Proof Setup Provtrycksinställningar
Properties Egenskaper
Proportional Metrics Proportionella mått
Insert Aki Left Infoga aki till vänster
Insert Aki Right Infoga aki till höger
Character Direction Teckenriktning
Digits Siffror
Arabic Arabiska
Can't render this file because it contains an unexpected character in line 5 and column 25.
+2
View File
@@ -2428,6 +2428,8 @@ shape Open Açık
Proof Setup Prova Kurulumu
Properties Özellikler
Proportional Metrics Orantılı Metrikler
Insert Aki Left Sola Aki Ekle
Insert Aki Right Sağa Aki Ekle
Digits Rakamlar
Arabic Arapça
Hindi Hintçe
Can't render this file because it contains an unexpected character in line 5 and column 25.
+2
View File
@@ -2652,6 +2652,8 @@ mark-style Japanese Японський
Proof Setup Налаштування кольоропроби
Properties Властивості
Proportional Metrics Пропорційні метрики
Insert Aki Left Вставити акі ліворуч
Insert Aki Right Вставити акі праворуч
Character Direction Напрямок символів
Digits Цифри
Arabic Арабські
Can't render this file because it contains an unexpected character in line 182 and column 5.
+2
View File
@@ -2960,6 +2960,8 @@ mark-style Japanese Kiểu Nhật
Proof Setup Thiết lập thử nghiệm
Properties Thuộc tính
Proportional Metrics Số liệu theo tỷ lệ
Insert Aki Left Chèn aki bên trái
Insert Aki Right Chèn aki bên phải
Proportional Lining Số tỷ lệ đứng
Position: Vị trí:
Default Position Vị trí mặc định
Can't render this file because it contains an unexpected character in line 204 and column 5.
+2
View File
@@ -2519,6 +2519,8 @@ font-script Japanese 汉字
Proof Setup 校样设置
Properties 属性
Proportional Metrics 比例度量
Insert Aki Left 在前方插入空白
Insert Aki Right 在后方插入空白
Character Direction 字符方向
Digits 数字
Arabic 阿拉伯数字
Can't render this file because it contains an unexpected character in line 2 and column 73.
+2
View File
@@ -3627,6 +3627,8 @@ font-script Japanese 漢字
Proof Setup 校樣設定
Properties 內容
Proportional Metrics 比例度量
Insert Aki Left 在前方插入空白
Insert Aki Right 在後方插入空白
Character Direction 字元方向
Digits 數字
Arabic 阿拉伯數字
Can't render this file because it contains an unexpected character in line 6 and column 47.
+23 -3
View File
@@ -22,6 +22,9 @@ pub const SIZE_PRESETS: [f64; 15] = [6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 14.0,
/// The Kerning and Tracking dropdowns' presets in 1/1000 em.
pub const TRACKING_PRESETS: [f64; 14] = [-100.0, -75.0, -50.0, -25.0, -10.0, -5.0, 0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 200.0];
pub const SCALE_PRESETS: [f64; 8] = [25.0, 50.0, 75.0, 90.0, 100.0, 110.0, 125.0, 150.0];
/// Insert Aki Left and Right presets, in thousandths of an em: none, a quarter, half and a whole
/// full-width space.
pub const AKI_PRESETS: [f64; 4] = [0.0, 250.0, 500.0, 1000.0];
/// The stored character style: the selected range's (or the caret's) while the Type
/// tool edits text, else the first selected text object's first run (including groups). With it, the paragraph
@@ -766,7 +769,8 @@ fn cell(ui: &mut Ui, label: &str, tip: &str, add: impl FnOnce(&mut Ui)) {
/// The Character panel's grid of fields, `w` wide: Font Size, Leading, Kerning and Tracking,
/// then with `more` the scales, Baseline Shift and Character Rotation, and a row with the
/// Anti-aliasing Method dropdown under Character Rotation (`s`: the style shown). With Show Font
/// Anti-aliasing Method dropdown under Character Rotation (`s`: the style shown), and with Show East
/// Asian Options on a row with Insert Aki Left and Right. With Show Font
/// Height Options on, a row under Font Size holds the Set Font Height Reference dropdown. The
/// Properties panel shows its first rows.
pub(crate) fn metrics_grid(app: &mut VectorcraftApp, ui: &mut Ui, id: &str, s: &CharStyle, w: f32, more: bool) {
@@ -847,6 +851,22 @@ pub(crate) fn metrics_grid(app: &mut VectorcraftApp, ui: &mut Ui, id: &str, s: &
ui.label("");
cell(ui, "aa", tl!("Anti-aliasing Method"), |ui| anti_alias_method(app, ui, fw));
ui.end_row();
// Insert Aki Left and Right, with the East Asian options: space before and after each
// character, in thousandths of an em.
if app.session.prefs.show_east_asian_options {
for (field, label, key, icon) in
[("ch-aki-left", tl!("Insert Aki Left"), "akiLeft", "↔A"), ("ch-aki-right", tl!("Insert Aki Right"), "akiRight", "A↔")]
{
cell(ui, icon, label, |ui| {
let value = shared(app, |s| if key == "akiLeft" { s.aki_left } else { s.aki_right });
if let Some(v) = widgets::spin_plain(ui, field, value, "", 0, fw, 10.0, 0.0, &AKI_PRESETS) {
// The field stops at the largest value the command takes.
format(app, json!({ key: v.min(vectorcraft_doc::text::MAX_AKI) }));
}
});
}
ui.end_row();
}
});
}
@@ -1445,7 +1465,7 @@ fn fractional_widths_on(app: &VectorcraftApp) -> bool {
/// kerning, no baseline shift, 100% scales, no rotation, no underline or strikethrough, All Caps
/// and Small Caps off, the normal position (neither superscript nor subscript), Roman Baseline
/// character alignment, Proportional Metrics, Tate-chu-yoko, Standard Vertical Roman Alignment and
/// No Break off, Tate-chu-yoko Settings Up/Down and Left/Right 0, the Default character direction,
/// No Break off, Tate-chu-yoko Settings Up/Down and Left/Right 0, Insert Aki Left and Right 0, the Default character direction,
/// Kashidas on, the Default digits and the Em Box font height reference, whether or not Show East Asian
/// Options, Show Indic Options and Show Font Height Options are on. Inside an undo group that is
/// already open, the reset is part of that group's step.
@@ -1464,7 +1484,7 @@ fn reset_panel(app: &mut VectorcraftApp) {
"kerning": "auto", "baselineShift": 0, "hScale": 100, "vScale": 100, "rotation": 0, "underline": false, "strikethrough": false,
"allCaps": false, "smallCaps": d.small_caps.is_some(), "position": d.position.id(), "charAlign": d.char_align,
"proportionalMetrics": d.proportional_metrics, "tateChuYoko": d.tate_chu_yoko,
"tcyUpDown": d.tcy_up_down, "tcyLeftRight": d.tcy_left_right,
"tcyUpDown": d.tcy_up_down, "tcyLeftRight": d.tcy_left_right, "akiLeft": d.aki_left, "akiRight": d.aki_right,
"standardVerticalRoman": d.standard_vertical_roman, "noBreak": d.no_break, "charDirection": "default", "kashidas": d.kashidas,
"digits": d.digits, "fontHeightReference": d.font_height_reference
}),
+39 -3
View File
@@ -746,6 +746,40 @@ fn character_alignment_shows_with_the_east_asian_options() {
assert_eq!(shown(&mut app), (true, true));
}
/// Insert Aki Left and Right are fields of the panel with the East Asian options only, and show
/// the selected characters' values, blank where they differ. A value typed past 1000 sets 1000.
#[test]
fn insert_aki_fields_show_with_the_east_asian_options() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "(日本)"})).unwrap()["id"].as_u64().unwrap();
app.run("select.set", json!({"ids": [id]})).unwrap();
app.run("text.setFormat", json!({"akiLeft": 250, "akiRight": 750})).unwrap();
let text = crate::tests_labels::painted_text(&mut app, show);
assert!(!text.contains("↔A") && !text.contains("750"), "{text}");
app.session.prefs.show_east_asian_options = true;
let text = crate::tests_labels::painted_text(&mut app, show);
assert!(text.contains("↔A") && text.contains("A↔") && text.contains("250") && text.contains("750"), "{text}");
// Only the first character has 750 after it: the Right field is blank.
app.run("text.setRangeStyle", json!({"id": id, "start": 3, "end": 12, "akiRight": 0})).unwrap();
let text = crate::tests_labels::painted_text(&mut app, show);
assert!(text.contains("250") && !text.contains("750"), "{text}");
use super::super::tests_appearance::{click, frame_events, text_rect};
let ctx = egui::Context::default();
let texts = frame_events(&ctx, &mut app, vec![], show);
click(&ctx, &mut app, text_rect(&texts, "250").center(), show);
let key = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers };
frame_events(&ctx, &mut app, vec![key(egui::Key::A, egui::Modifiers::COMMAND)], show);
frame_events(&ctx, &mut app, vec![egui::Event::Text("1500".into())], show);
frame_events(&ctx, &mut app, vec![key(egui::Key::Enter, egui::Modifiers::NONE)], show);
frame_events(&ctx, &mut app, vec![], show);
let left = |app: &VectorcraftApp| match &app.session.active().unwrap().doc.node(NodeId(id)).unwrap().kind {
NodeKind::Text(t) => t.runs.iter().map(|r| r.style.aki_left).collect::<Vec<_>>(),
_ => panic!("text"),
};
assert!(left(&app).iter().all(|v| *v == 1000.0), "{:?}", left(&app));
}
/// The panel menu's Show Font Height Options shows the Set Font Height Reference dropdown,
/// which shows the selected type's reference and sets the one picked (one undo step); Hide
/// Font Height Options hides it again.
@@ -1242,6 +1276,8 @@ fn reset_panel_resets_every_attribute_but_the_font() {
s.tate_chu_yoko != d.tate_chu_yoko,
s.tcy_up_down != d.tcy_up_down,
s.tcy_left_right != d.tcy_left_right,
s.aki_left != d.aki_left,
s.aki_right != d.aki_right,
s.standard_vertical_roman != d.standard_vertical_roman,
s.no_break != d.no_break,
s.char_direction != d.char_direction,
@@ -1256,16 +1292,16 @@ fn reset_panel_resets_every_attribute_but_the_font() {
"id": id, "tracking": 50, "leading": 30, "kerning": 20, "baselineShift": 3, "hScale": 120, "vScale": 90, "rotation": 15,
"underline": true, "strikethrough": true, "allCaps": true, "smallCaps": true, "position": "superscript",
"charAlign": "emBoxCenter", "proportionalMetrics": true, "tateChuYoko": true, "tcyUpDown": 2, "tcyLeftRight": -3,
"standardVerticalRoman": true, "noBreak": true, "charDirection": "rightToLeft", "digits": "hindi", "fontHeightReference": "capHeight"
"akiLeft": 250, "akiRight": 500, "standardVerticalRoman": true, "noBreak": true, "charDirection": "rightToLeft", "digits": "hindi", "fontHeightReference": "capHeight"
}),
)
.unwrap();
};
let plain = runs(&app)[0].1.clone();
assert_eq!(differs(&plain, &CharStyle::default()), [false; 22]);
assert_eq!(differs(&plain, &CharStyle::default()), [false; 24]);
custom(&mut app);
let styled = runs(&app)[0].1.clone();
assert_eq!(differs(&styled, &CharStyle::default()), [true; 22]);
assert_eq!(differs(&styled, &CharStyle::default()), [true; 24]);
app.run("select.set", json!({"ids": [id]})).unwrap();
reset_panel(&mut app);
assert_eq!(runs(&app), [("One 12".to_string(), plain.clone())]);
+26 -2
View File
@@ -7590,6 +7590,28 @@ dialog open.
{"name":"run_command","arguments":{"command":"text.setRangeStyle","params":{"id":12,"start":0,"end":4,"tateChuYoko":true,"tcyUpDown":2,"tcyLeftRight":-1}}}
```
## Insert Aki
`text.setFormat` and `text.setRangeStyle {akiLeft?, akiRight?}` set Insert Aki Left and Insert Aki Right of the
characters: space added before and after each character, in thousandths of an em from 0 to 1000, measured as tracking
is ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)). 250 adds a quarter of
a full-width space and 500 half of one. Left is the space before the character in reading order and Right the space
after it: above and below the character in vertical type, and on the right and left of it in right-to-left type. The
space stays the same width when a line is justified and when Optical kerning measures the characters. A ligature, a
letter with its marks and a tate-chu-yoko block take the values of their first character. Setting one value leaves the other as it is. Both are 0
by default and saved only when not 0, and character styles carry them (`charStyle.new`, `charStyle.setAttrs` and
`charStyle.edit` refuse a value outside the range). A value that is not a number is refused with `` `akiLeft` must be a number ``, and one outside
the range with `` `akiLeft` must be from 0 to 1000 ``, naming the key. One undo step. With Show East Asian Options on,
the Character panel shows both fields, blank where the selected characters differ, with 0, 250, 500 and 1000 in their
menus, and a value typed past 1000 sets 1000; Reset Panel sets both to 0. Character Style Options shows both fields
in Advanced Character Formats. With Fractional Widths off or System Layout on, each side is set in whole points, and
justification keeps that width. Live SVG text places each character the space moves, and type on a path with
Insert Aki is written as outlines.
```json
{"name":"run_command","arguments":{"command":"text.setRangeStyle","params":{"id":12,"start":0,"end":3,"akiRight":500}}}
```
## Composite Fonts
A composite font sets each class of character in a font of its own
@@ -8270,13 +8292,15 @@ attribute map in one undo step. `to` is trimmed and must be unique. The command
while preserving local overrides; Undo/Redo restores the definition and its users. The `charStyleOptions`
dialog exposes `name`, `font_family`, `font_style`, `size`, `leading`, `kerning`, `tracking`, `case`,
`position`, `underline`, `strikethrough`, `charAlign`, `h_scale`, `v_scale`, `baseline_shift`, `tcyUpDown`,
`tcyLeftRight`, `rotation`, `language`, `fill`, `fill_tint`, `stroke`, `stroke_tint`, `stroke_width`, `overprint_fill`, `overprint_stroke`,
`tcyLeftRight`, `rotation`, `akiLeft`, `akiRight`, `language`, `fill`, `fill_tint`, `stroke`, `stroke_tint`, `stroke_width`, `overprint_fill`, `overprint_stroke`,
`ot_figure`, `ot_position`, `ot_liga`, `ot_calt`, `ot_dlig`, `ot_swsh`, `ot_salt`, `ot_titl`, `ot_ordn`, `ot_frac`,
`ot_sets`, `section` (`general`, `basic`, `advanced`, `color` or `opentype`), and `preview`. An empty field leaves its
attribute unset. `leading` and `kerning` also accept `Auto` to store an explicit automatic value.
Advanced Character Formats holds `h_scale` and `v_scale` (percent, 1 to 10000),
`baseline_shift` (points, -1296 to 1296), the Tate-chu-yoko Settings `tcyUpDown` and `tcyLeftRight` (points,
-1296 to 1296, as `text.setRangeStyle` takes them; an explicit 0 stays distinct from unset), `rotation` (degrees, stored from -180 to 180) and `language` (a name or tag from Document
-1296 to 1296, as `text.setRangeStyle` takes them; an explicit 0 stays distinct from unset), `rotation` (degrees, stored from -180 to 180), Insert Aki Left and Right `akiLeft` and `akiRight` (thousandths of
an em, with the Character panel's 0, 250, 500 and 1000 in their menus; a value typed below 0 or past 1000 sets 0 or
1000) and `language` (a name or tag from Document
Setup's languages; English: USA stores the explicit default `null`, and a tag not in the list that the style
already has is kept). Language sets the language the characters are shaped in; it does not change hyphenation
or spelling.
+1
View File
@@ -1248,6 +1248,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Character panel menu › Standard Vertical Roman Alignment (with the East Asian options; `text.setFormat` or `text.setRangeStyle {standardVerticalRoman}`, off by default) stands the selected Latin letters, digits and other half-width characters upright one below the other in vertical type instead of rotating them ([formatting Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); spaces keep their width, tate-chu-yoko blocks stay across the column, and Character Style Options gives it its own checkbox beside Character Alignment.
Character panel menu › Tate-chu-yoko Settings… (with the East Asian options; `ui.tateChuYokoSettings`, `text.setFormat` or `text.setRangeStyle {tcyUpDown, tcyLeftRight}`, in points, 0 by default) moves a marked tate-chu-yoko block in vertical type up by a positive Up/Down and right by a positive Left/Right ([format East Asian characters in vertical text](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/format-east-asian-characters-in-vertical-text.html), [formatting Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); the block moves as one piece with its first character's values and keeps its one em down the column, on a vertical path it moves toward the path's start and to the path's left, automatic digit blocks do not move, Reset Panel sets both back to 0, and character styles and the native file keep them.
A file whose character styles hold a Tate-chu-yoko Up/Down or Left/Right offset past the coordinate limit (`MAX_COORD`) either way opens with the nearer end, as the type's own offsets do; an offset within it stays as saved.
Character panel › Insert Aki Left and Insert Aki Right (with the East Asian options; `text.setFormat` or `text.setRangeStyle {akiLeft, akiRight}`, thousandths of an em from 0 to 1000, 0 by default) add space before and after each selected character, measured as tracking is, and kept as set through justification ([the help page](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)); before and after follow the reading order in vertical and right-to-left type, character styles carry both values (Character Style Options › Advanced Character Formats edits them), and a file holding a value outside the range opens with the nearer end.
The Character panel's All Caps, Underline and Strikethrough buttons and its menu's All Caps, Underline, Strikethrough, Proportional Metrics, Tate-chu-yoko and No Break show off while only some of the selected characters have the attribute, and choosing one then turns it on for all of them, as `type.underline` (Cmd+Shift+U) does for underlining; the Character Alignment and Digits submenus check no item while the selected characters differ. `text.setFormat` refuses a value that is not true or false for its on/off attributes, as `text.setRangeStyle` does.
- **Transparency:** opacity masks (clip/invert/disable/link), exported as SVG `<mask>` and PDF soft masks. The constant alpha soft mask that PDF and `.ai` export draw a CMYK page with transparency through is white, so applications that read every soft mask by its luminosity show the page too (#1359, part of #1286).
Isolation mode and opacity mask editing exclude each other ([transparency and blending modes](https://web.archive.org/web/20230102045151/https://helpx.adobe.com/illustrator/using/transparency-blending-modes.html)): in isolation mode a click or Alt-click on the mask thumbnail does not edit the mask, and Make Mask is off for one object; while a mask is edited, Enter Isolation Mode and Object › Perspective › Edit Text are off, the Contextual Task Bar leaves out Isolate, and Quick Actions leave out Isolate Group.