summaryrefslogtreecommitdiffstats
path: root/third_party/rust/unicode-bidi/src/deprecated.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/unicode-bidi/src/deprecated.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/unicode-bidi/src/deprecated.rs')
-rw-r--r--third_party/rust/unicode-bidi/src/deprecated.rs92
1 files changed, 92 insertions, 0 deletions
diff --git a/third_party/rust/unicode-bidi/src/deprecated.rs b/third_party/rust/unicode-bidi/src/deprecated.rs
new file mode 100644
index 0000000000..74a24f5b8b
--- /dev/null
+++ b/third_party/rust/unicode-bidi/src/deprecated.rs
@@ -0,0 +1,92 @@
+// Copyright 2015 The Servo Project Developers. See the
+// COPYRIGHT file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! This module holds deprecated assets only.
+
+use alloc::vec::Vec;
+
+use super::*;
+
+/// Find the level runs within a line and return them in visual order.
+///
+/// NOTE: This implementation is incomplete. The algorithm needs information about the text,
+/// including original `BidiClass` property of each character, to be able to perform correctly.
+/// Please see [`BidiInfo::visual_runs()`](../struct.BidiInfo.html#method.visual_runs) for the
+/// improved implementation.
+///
+/// `line` is a range of bytes indices within `levels`.
+///
+/// <http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels>
+#[deprecated(
+ since = "0.3.0",
+ note = "please use `BidiInfo::visual_runs()` instead."
+)]
+pub fn visual_runs(line: Range<usize>, levels: &[Level]) -> Vec<LevelRun> {
+ assert!(line.start <= levels.len());
+ assert!(line.end <= levels.len());
+
+ let mut runs = Vec::new();
+
+ // Find consecutive level runs.
+ let mut start = line.start;
+ let mut run_level = levels[start];
+ let mut min_level = run_level;
+ let mut max_level = run_level;
+
+ for (i, &new_level) in levels.iter().enumerate().take(line.end).skip(start + 1) {
+ if new_level != run_level {
+ // End of the previous run, start of a new one.
+ runs.push(start..i);
+ start = i;
+ run_level = new_level;
+
+ min_level = cmp::min(run_level, min_level);
+ max_level = cmp::max(run_level, max_level);
+ }
+ }
+ runs.push(start..line.end);
+
+ let run_count = runs.len();
+
+ // Re-order the odd runs.
+ // <http://www.unicode.org/reports/tr9/#L2>
+
+ // Stop at the lowest *odd* level.
+ min_level = min_level.new_lowest_ge_rtl().expect("Level error");
+
+ while max_level >= min_level {
+ // Look for the start of a sequence of consecutive runs of max_level or higher.
+ let mut seq_start = 0;
+ while seq_start < run_count {
+ if levels[runs[seq_start].start] < max_level {
+ seq_start += 1;
+ continue;
+ }
+
+ // Found the start of a sequence. Now find the end.
+ let mut seq_end = seq_start + 1;
+ while seq_end < run_count {
+ if levels[runs[seq_end].start] < max_level {
+ break;
+ }
+ seq_end += 1;
+ }
+
+ // Reverse the runs within this sequence.
+ runs[seq_start..seq_end].reverse();
+
+ seq_start = seq_end;
+ }
+ max_level
+ .lower(1)
+ .expect("Lowering embedding level below zero");
+ }
+
+ runs
+}