summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/layout
diff options
context:
space:
mode:
authordamaxwell <damaxwell@alaska.edu>2023-07-19 02:25:24 -0800
committerGitHub <noreply@github.com>2023-07-19 12:25:24 +0200
commit8a57395ee48ecee02c2eb833d232979730f0e445 (patch)
tree7a66d64f2f4b8afd509db0a89d5bf25a2ab1c72b /crates/typst-library/src/layout
parentf39bfa476222aa92a590d65f7c2d58612f24eef2 (diff)
Support OpenType writing script (#1697)
Diffstat (limited to 'crates/typst-library/src/layout')
-rw-r--r--crates/typst-library/src/layout/par.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs
index fe86f62a..6d1b653f 100644
--- a/crates/typst-library/src/layout/par.rs
+++ b/crates/typst-library/src/layout/par.rs
@@ -750,6 +750,7 @@ fn shape_range<'a>(
spans: &SpanMapper,
styles: StyleChain<'a>,
) {
+ let script = TextElem::script_in(styles);
let lang = TextElem::lang_in(styles);
let region = TextElem::region_in(styles);
let mut process = |range: Range, level: BidiLevel| {
@@ -763,25 +764,31 @@ fn shape_range<'a>(
let mut prev_script = Script::Unknown;
let mut cursor = range.start;
- // Group by embedding level and script.
+ // Group by embedding level and script. If the text's script is explicitly
+ // set (rather than inferred from the glpyhs), we keep the script at an
+ // unchanging `Script::Unknown` so that only level changes cause breaks.
for i in range.clone() {
if !bidi.text.is_char_boundary(i) {
continue;
}
let level = bidi.levels[i];
- let script =
- bidi.text[i..].chars().next().map_or(Script::Unknown, |c| c.script());
+ let curr_script = match script {
+ Smart::Auto => {
+ bidi.text[i..].chars().next().map_or(Script::Unknown, |c| c.script())
+ }
+ Smart::Custom(_) => Script::Unknown,
+ };
- if level != prev_level || !is_compatible(script, prev_script) {
+ if level != prev_level || !is_compatible(curr_script, prev_script) {
if cursor < i {
process(cursor..i, prev_level);
}
cursor = i;
prev_level = level;
- prev_script = script;
+ prev_script = curr_script;
} else if is_generic_script(prev_script) {
- prev_script = script;
+ prev_script = curr_script;
}
}