Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions Rules/Braille/Russian/Russian_Rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
- x: "*[2]"

-
name: gost-58511-small-font
name: small-font
tag: [mrow, mstyle, semantics]
match: "@data-braille-typeform='small' or contains(@intent, ':small-font')"
replace:
Expand All @@ -345,7 +345,7 @@
- t: "⠔"

-
name: gost-58511-letter-spacing
name: letter-spacing
tag: [mrow, mstyle, semantics]
match: "@data-braille-typeform='letter-spacing' or contains(@intent, ':letter-spacing')"
replace:
Expand All @@ -354,7 +354,7 @@
- t: "⠌"

-
name: gost-58511-insertion
name: insertion
tag: [mrow, mstyle, semantics]
match: "@data-braille-typeform='insertion' or contains(@intent, ':insertion')"
replace:
Expand Down Expand Up @@ -1558,26 +1558,36 @@
-
name: contextual-square-bracket-recognition-point
tag: mo
variables:
- PreviousLeaf: "(preceding-sibling::*/descendant-or-self::*[not(*) and not(self::m:mo[translate(., '\u2061\u2062\u2063\u2064', '')=''])] |
ancestor::m:mrow[parent::m:mrow or parent::m:math or parent::m:mtd]/preceding-sibling::*/descendant-or-self::*[not(*) and not(self::m:mo[translate(., '\u2061\u2062\u2063\u2064', '')=''])])[last()]"
- NextLeaf: "(following-sibling::*/descendant-or-self::*[not(*) and not(self::m:mo[translate(., '\u2061\u2062\u2063\u2064', '')=''])] |
ancestor::m:mrow[parent::m:mrow or parent::m:math or parent::m:mtd]/following-sibling::*/descendant-or-self::*[not(*) and not(self::m:mo[translate(., '\u2061\u2062\u2063\u2064', '')=''])])[1]"
match:
- "parent::*[IsBracketed(., '[', ']')] and"
- "((.='[' and not(preceding-sibling::*) and following-sibling::*[1][self::m:mi or self::m:mtext]) or"
- " (.=']' and not(following-sibling::*) and preceding-sibling::*[1][self::m:mi or self::m:mtext]))"
- "(.='[' or .=']') and"
- "$PreviousLeaf[self::m:mi or self::m:mtext] and"
- "contains('бвгджзйклмнпрстфхцчшщъьБВГДЖЗЙКЛМНПРСТФХЦЧШЩЪЬbcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZβγδζθκλμνξπρστφχψΒΓΔΖΘΚΛΜΝΞΠΡΣΤΦΧΨ',"
- " substring($PreviousLeaf, string-length($PreviousLeaf), 1)) and"
- "not($NextLeaf[self::m:mn or self::m:mo[contains('.,!?;:…', .)]])"
replace:
- T: "⠠"
- x: "text()"

-
name: contextual-angle-bracket-recognition-point
tag: mo
variables:
- LeftEdge: "(parent::*/*[position() > 1 and position() < last()]/descendant-or-self::*[not(*) and not(self::m:mo[translate(., '\u2061\u2062\u2063\u2064', '')=''])])[1]"
- RightEdge: "(parent::*/*[position() > 1 and position() < last()]/descendant-or-self::*[not(*) and not(self::m:mo[translate(., '\u2061\u2062\u2063\u2064', '')=''])])[last()]"
match:
- "parent::*[IsBracketed(., '⟨', '⟩')] and"
- "((.='⟨' and not(preceding-sibling::*)) or (.='⟩' and not(following-sibling::*))) and"
- "(parent::*/*[2][self::m:mi or self::m:mtext] or"
- " parent::*/*[last()-1][self::m:mi or self::m:mtext])"
- "(parent::*[IsBracketed(., '⟨', '⟩')] or parent::*[IsBracketed(., '〈', '〉')]) and"
- "(((.='⟨' or .='〈') and not(preceding-sibling::*)) or ((.='⟩' or .='〉') and not(following-sibling::*))) and"
- "($LeftEdge[self::m:mi or self::m:mtext] or"
- " $RightEdge[self::m:mi or self::m:mtext])"
replace:
- T: "⠈"
- test:
- if: ".='⟨'"
- if: ".='⟨' or .='〈'"
then: [T: "⠪"]
else: [T: "⠕"]

Expand Down Expand Up @@ -1613,7 +1623,7 @@
- "ancestor::m:mtr[preceding-sibling::*] and"
- "translate(., '0123456789', '')=''"
replace:
- x: "BrailleChars(translate(., '0123456789', '\ue020\ue021\ue022\ue023\ue024\ue025\ue026\ue027\ue028\ue029'), 'Russian')"
- x: "BrailleChars(translate(., '0123456789', '\ue040\ue041\ue042\ue043\ue044\ue045\ue046\ue047\ue048\ue049'), 'Russian')"

-
name: periodic-decimal-period-digits
Expand All @@ -1624,7 +1634,7 @@
- "following-sibling::*[1][self::m:mo and .=')'] and"
- "preceding-sibling::*[2][self::m:mn and contains(., ',')]"
replace:
- x: "BrailleChars(translate(., '0123456789', '\ue020\ue021\ue022\ue023\ue024\ue025\ue026\ue027\ue028\ue029'), 'Russian')"
- x: "BrailleChars(translate(., '0123456789', '\ue030\ue031\ue032\ue033\ue034\ue035\ue036\ue037\ue038\ue039'), 'Russian')"

-
name: periodic-decimal
Expand All @@ -1633,9 +1643,9 @@
replace:
- x: "BrailleChars(substring-before(., ','), 'Russian')"
- t: "⠂"
- x: "BrailleChars(translate(substring-before(substring-after(., ','), '('), '0123456789', '\ue020\ue021\ue022\ue023\ue024\ue025\ue026\ue027\ue028\ue029'), 'Russian')"
- x: "BrailleChars(translate(substring-before(substring-after(., ','), '('), '0123456789', '\ue030\ue031\ue032\ue033\ue034\ue035\ue036\ue037\ue038\ue039'), 'Russian')"
- t: "⠣"
- x: "BrailleChars(translate(substring-before(substring-after(., '('), ')'), '0123456789', '\ue020\ue021\ue022\ue023\ue024\ue025\ue026\ue027\ue028\ue029'), 'Russian')"
- x: "BrailleChars(translate(substring-before(substring-after(., '('), ')'), '0123456789', '\ue030\ue031\ue032\ue033\ue034\ue035\ue036\ue037\ue038\ue039'), 'Russian')"
- t: "⠜"

-
Expand All @@ -1645,7 +1655,7 @@
replace:
- x: "BrailleChars(substring-before(., ','), 'Russian')"
- t: "⠂"
- x: "BrailleChars(translate(substring-after(., ','), '0123456789', '\ue020\ue021\ue022\ue023\ue024\ue025\ue026\ue027\ue028\ue029'), 'Russian')"
- x: "BrailleChars(translate(substring-after(., ','), '0123456789', '\ue030\ue031\ue032\ue033\ue034\ue035\ue036\ue037\ue038\ue039'), 'Russian')"

-
name: default
Expand Down
95 changes: 87 additions & 8 deletions Rules/Braille/Russian/unicode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
- "<": [t: "⠀⠪⠀"]
- "%": [t: "⠼⠴"]
- "‰": [t: "⠼⠴⠴"]
- "±": [t: "⠀⠖⠤"]
- "÷": [T: "⠀⠲"]
- "±": [T: "⠖⠤"]
- ";": [t: "⠠⠢"]
- "Ϳ": [t: "⠰⠊"]
- "·": [t: "⠰"]
Expand Down Expand Up @@ -98,6 +99,7 @@
- "‴": [t: "⠔⠔⠔"]
- "°": [t: "⠨⠴"]
- "℃": [t: "⠨⠴⠨⠉"]
- "℉": [T: "⠨⠴⠨⠋"]
- "∀": [t: "⠫⠄"]
- "∂": [t: "⠹"]
- "∃": [t: "⠫⠢"]
Expand All @@ -111,9 +113,10 @@
- "∏": [t: "⠸⠏"]
- "∑": [t: "⠸⠎"]
- "−": [t: "⠀⠤"]
- "∓": [t: "⠤⠖"]
- "∓": [T: "⠤⠖"]
- "∔": [t: "⠈⠖"]
- "∕": [t: "⠠⠌"]
- "∕": [T: "⠴"]
- "⁄": [T: "⠳"]
- "∖": [t: "⠀⠰⠤"]
- "∗": [t: "⠔"]
- "·": [t: "⠄"]
Expand Down Expand Up @@ -166,7 +169,8 @@
- "\uE138": [t: "⠖"]
- "\uE139": [t: "⠤"]
- "\uE13A": [t: "⠠⠢"]
- "\uE13B": [t: "⠦⠶"]
- "\uE13B": [T: "⠐⠒"]
- "\uE02A": [T: "𝒢"] # internal Russian digit-group separator
- "\ue020": [t: "⠚"]
- "\ue021": [t: "⠁"]
- "\ue022": [t: "⠃"]
Expand All @@ -177,12 +181,33 @@
- "\ue027": [t: "⠛"]
- "\ue028": [t: "⠓"]
- "\ue029": [t: "⠊"]
- "\ue030": [t: "⠚"]
- "\ue031": [t: "⠁"]
- "\ue032": [t: "⠃"]
- "\ue033": [t: "⠉"]
- "\ue034": [t: "⠙"]
- "\ue035": [t: "⠑"]
- "\ue036": [t: "⠋"]
- "\ue037": [t: "⠛"]
- "\ue038": [t: "⠓"]
- "\ue039": [t: "⠊"]
- "\ue040": [t: "⠚"]
- "\ue041": [t: "⠁"]
- "\ue042": [t: "⠃"]
- "\ue043": [t: "⠉"]
- "\ue044": [t: "⠙"]
- "\ue045": [t: "⠑"]
- "\ue046": [t: "⠋"]
- "\ue047": [t: "⠛"]
- "\ue048": [t: "⠓"]
- "\ue049": [t: "⠊"]
- "∘": [t: "⠴"]
- "√": [t: "⠩⠱"]
- "∛": [t: "⠩⠒⠱"]
- "∜": [t: "⠩⠲⠱"]
- "∞": [t: "⠻"]
- "∠": [t: "⠸⠪"]
- "⌒": [T: "⠸⠜"]
- "∣": [t: "⠸"]
- "∤": [t: "⠀⠼⠀"]
- "∥": [t: "⠸⠸#"]
Expand Down Expand Up @@ -230,6 +255,7 @@
- "⊇": [t: "⠀⠹⠶"]
- "⊕": [t: "⠀⠰⠖"]
- "⊥": [t: "⠼⠄"]
- "⟂": [T: "⠼⠄"]
- "⊨": [t: "⠼⠎"]
- "⊼": [t: "⠰⠌"]
- "⊽": [t: "⠘⠡"]
Expand All @@ -240,17 +266,29 @@
- "⋰": [t: "⠠⠲⠲⠲"]
- "⋱": [t: "⠠⠲⠲⠲"]
- "△": [t: "⠸⠙"]
- "〈": [T: "⠪"]
- "〉": [T: "⠕"]
- "⟨": [T: "⠪"]
- "⟩": [T: "⠕"]
- "¬": [T: "⠩"]
- "~": [T: "⠢"]
- "↑": [T: "⠰⠌"]
- "↓": [T: "⠘⠡"]
- "→": [t: "⠀⠒⠕"]
- "⟶": [t: "⠀⠒⠕"]
- "←": [t: "⠀⠦⠶"]
- "⟵": [t: "⠀⠦⠶"]
- "↔": [T: "⠪⠒⠕"]
- "↕": [T: "⠹⠄"]
- "↖": [T: "⠐⠢"]
- "↗": [T: "⠔⠂"]
- "↘": [T: "⠢⠄"]
- "↙": [T: "⠠⠔"]
- "→": [T: "⠀⠒⠕⠀"]
- "⟶": [T: "⠀⠒⠕⠀"]
- "←": [T: "⠀⠪⠒⠀"]
- "⟵": [T: "⠀⠪⠒⠀"]
- "⇒": [t: "⠀⠶⠜"]
- "⇐": [t: "⠀⠦⠶"]
- "⇔": [t: "⠀⠦⠶⠜"]
- "⇑": [T: "⠌⠌"]
- "⇓": [T: "⠡⠡"]
- "◻": [t: "⠶"]
- "♮": [t: "⠻⠨⠝⠻"]

Expand Down Expand Up @@ -330,6 +368,47 @@
- "\ue008": [t: "⠦"]
- "\ue009": [t: "⠔"]

# Precomposed Unicode fractions and script digits, verified against liblouis.
- "¼": [T: "⠼⠁⠲"]
- "½": [T: "⠼⠁⠆"]
- "¾": [T: "⠼⠉⠲"]
- "⅐": [T: "⠼⠁⠶"]
- "⅑": [T: "⠼⠁⠔"]
- "⅒": [T: "⠼⠁⠂⠴"]
- "⅓": [T: "⠼⠁⠒"]
- "⅔": [T: "⠼⠃⠒"]
- "⅕": [T: "⠼⠁⠢"]
- "⅖": [T: "⠼⠃⠢"]
- "⅗": [T: "⠼⠉⠢"]
- "⅘": [T: "⠼⠙⠢"]
- "⅙": [T: "⠼⠁⠖"]
- "⅚": [T: "⠼⠑⠖"]
- "⅛": [T: "⠼⠁⠦"]
- "⅜": [T: "⠼⠉⠦"]
- "⅝": [T: "⠼⠑⠦"]
- "⅞": [T: "⠼⠛⠦"]
- "↉": [T: "⠼⠚⠒"]
- "⁰": [T: "⠴"]
- "¹": [T: "⠂"]
- "²": [T: "⠆"]
- "³": [T: "⠒"]
- "⁴": [T: "⠲"]
- "⁵": [T: "⠢"]
- "⁶": [T: "⠖"]
- "⁷": [T: "⠶"]
- "⁸": [T: "⠦"]
- "⁹": [T: "⠔"]
- "₀": [T: "⠴"]
- "₁": [T: "⠂"]
- "₂": [T: "⠆"]
- "₃": [T: "⠒"]
- "₄": [T: "⠲"]
- "₅": [T: "⠢"]
- "₆": [T: "⠖"]
- "₇": [T: "⠶"]
- "₈": [T: "⠦"]
- "₉": [T: "⠔"]

# Russian literary braille letters for mtext and Cyrillic identifiers.
- "а": [t: "⠁"]
- "А": [t: "C⠁"]
Expand Down
46 changes: 42 additions & 4 deletions src/braille.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,9 @@ fn russian_cleanup(_pref_manager: Ref<PreferenceManager>, raw_braille: String) -
continue;
}
raw_braille_without_repeated_number_indicators.push(ch);
previous_char_was_digit = matches!(ch, '⠚' | '⠁' | '⠃' | '⠉' | '⠙' | '⠑' | '⠋' | '⠛' | '⠓' | '⠊');
if ch != '𝒢' {
previous_char_was_digit = matches!(ch, '⠚' | '⠁' | '⠃' | '⠉' | '⠙' | '⠑' | '⠋' | '⠛' | '⠓' | '⠊');
}
}

let raw_braille_without_periodic_number_indicator = PERIODIC_DECIMAL_NUM_INDICATOR
Expand All @@ -2417,7 +2419,8 @@ fn russian_cleanup(_pref_manager: Ref<PreferenceManager>, raw_braille: String) -
_ => "",
}
});
let result = result.replace("⠠⠙⠊⠧", "⠫⠙⠊⠧");
let result = result.replace("⠠⠙⠊⠧", "⠫⠙⠊⠧")
.replace('𝒢', "⠄");
return COLLAPSE_SPACES.replace_all(&result, "⠀")
.trim_matches('⠀')
.to_string();
Expand Down Expand Up @@ -2503,8 +2506,8 @@ fn russian_cleanup(_pref_manager: Ref<PreferenceManager>, raw_braille: String) -

fn russian_typeform_indicator(typeform: char) -> &'static str {
match typeform {
'B' => "⠻", // ГОСТ Р 58511: жирный шрифт, точки 12456.
'I' | 'T' | 'D' | 'S' | '𝔹' => "⠸", // ГОСТ Р 58511: курсив/шрифтовое выделение, точки 456.
'B' => "⠻", // Russian bold indicator, dots 12456.
'I' | 'T' | 'D' | 'S' | '𝔹' => "⠸", // Russian typeform indicator, dots 456.
_ => "",
}
}
Expand Down Expand Up @@ -2850,6 +2853,7 @@ impl BrailleChars {

fn get_braille_russian_chars(node: Element, text_range: Option<Range<usize>>) -> Result<String> {
let text = BrailleChars::substring(as_str!(as_text(node)), &text_range);
let text = add_russian_digit_group_separators(text, node);
let braille_chars = braille_replace_chars(&text, node)?;
let Some(raw_math_variant) = node.attribute_value("mathvariant") else {
return Ok(braille_chars);
Expand Down Expand Up @@ -2882,6 +2886,40 @@ impl BrailleChars {
}

return Ok(prefix + &braille_chars + &suffix);

fn add_russian_digit_group_separators(text: String, node: Element) -> String {
const GROUP_SEPARATOR: char = '\u{e02a}';

// Column arithmetic keeps the digit columns contiguous. The Russian
// examples for this layout omit the point-3 separator even for results
// longer than four digits.
let mut ancestor = Some(node);
while let Some(element) = ancestor {
if element.attribute_value("intent").is_some_and(|intent| intent.contains(":column-arithmetic")) {
return text;
}
ancestor = element.parent().and_then(|parent| parent.element());
}

let is_groupable_digit = |ch: char| ch.is_ascii_digit() || ('\u{e020}'..='\u{e029}').contains(&ch);
let digit_count = text.chars().count();
if digit_count <= 4 || !text.chars().all(is_groupable_digit) {
return text;
}

let first_group_len = match digit_count % 3 {
0 => 3,
remainder => remainder,
};
let mut result = String::with_capacity(text.len() + digit_count / 3);
for (index, ch) in text.chars().enumerate() {
if index > 0 && index >= first_group_len && (index - first_group_len) % 3 == 0 {
result.push(GROUP_SEPARATOR);
}
result.push(ch);
}
return result;
}
}

fn get_braille_cmu_chars(node: Element, text_range: Option<Range<usize>>) -> Result<String> {
Expand Down
Loading
Loading