mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #16779 - behnam:bidi-0.3, r=mbrubeck
[gfx] [layout] [style] Upgrade unicode-bidi to 0.3 Depends on https://github.com/servo/unicode-bidi/pull/27 , which upgrades `unicode-bidi` crate to `0.3.0`. Summary of changes: * Use `unicode_bidi::Level` (instead of `u8`) in all relevant places and replace magic computations with (inline) method calls to Level API. * Doing so required adding `unicode-bidi` crate dependency to two more components here: `style` and `gfx`. IMHO, totally makes sense, as replaces local integer manipulations/checks with well-tested ones already available in a common dependency. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). [N/A] <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because `unicode-bidi` has its own tests and there's no logic change in this diff. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16779) <!-- Reviewable:end -->
This commit is contained in:
commit
edd6c2cecb
10 changed files with 61 additions and 34 deletions
|
@ -43,6 +43,6 @@ servo_url = {path = "../url"}
|
|||
smallvec = "0.3"
|
||||
style = {path = "../style"}
|
||||
style_traits = {path = "../style_traits"}
|
||||
unicode-bidi = "0.2"
|
||||
unicode-bidi = {version = "0.3", features = ["with_serde"]}
|
||||
unicode-script = {version = "0.1", features = ["harfbuzz"]}
|
||||
webrender_traits = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||
|
|
|
@ -36,7 +36,7 @@ use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
|
|||
use style::properties::{longhands, ServoComputedValues};
|
||||
use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPOSITION, RESOLVE_GENERATED_CONTENT};
|
||||
use text;
|
||||
use unicode_bidi;
|
||||
use unicode_bidi as bidi;
|
||||
|
||||
/// `Line`s are represented as offsets into the child list, rather than
|
||||
/// as an object that "owns" fragments. Choosing a different set of line
|
||||
|
@ -95,7 +95,7 @@ pub struct Line {
|
|||
/// The bidirectional embedding level runs for this line, in visual order.
|
||||
///
|
||||
/// Can be set to `None` if the line is 100% left-to-right.
|
||||
pub visual_runs: Option<Vec<(Range<FragmentIndex>, u8)>>,
|
||||
pub visual_runs: Option<Vec<(Range<FragmentIndex>, bidi::Level)>>,
|
||||
|
||||
/// The bounds are the exact position and extents of the line with respect
|
||||
/// to the parent box.
|
||||
|
@ -293,22 +293,25 @@ impl LineBreaker {
|
|||
// (because we split fragments on level run boundaries during flow
|
||||
// construction), so we can build a level array with just one entry per
|
||||
// fragment.
|
||||
let levels: Vec<u8> = self.new_fragments.iter().map(|fragment| match fragment.specific {
|
||||
SpecificFragmentInfo::ScannedText(ref info) => info.run.bidi_level,
|
||||
_ => para_level
|
||||
}).collect();
|
||||
let levels: Vec<bidi::Level> = self.new_fragments.iter().map(
|
||||
|fragment| match fragment.specific {
|
||||
SpecificFragmentInfo::ScannedText(ref info) => info.run.bidi_level,
|
||||
_ => para_level
|
||||
}
|
||||
).collect();
|
||||
|
||||
let mut lines = mem::replace(&mut self.lines, Vec::new());
|
||||
|
||||
// If everything is LTR, don't bother with reordering.
|
||||
let has_rtl = levels.iter().cloned().any(unicode_bidi::is_rtl);
|
||||
|
||||
if has_rtl {
|
||||
if bidi::level::has_rtl(&levels) {
|
||||
// Compute and store the visual ordering of the fragments within the
|
||||
// line.
|
||||
for line in &mut lines {
|
||||
let range = line.range.begin().to_usize()..line.range.end().to_usize();
|
||||
let runs = unicode_bidi::visual_runs(range, &levels);
|
||||
// FIXME: Update to use BidiInfo::visual_runs, as this algorithm needs access to
|
||||
// the original text and original BidiClass of its characters.
|
||||
#[allow(deprecated)]
|
||||
let runs = bidi::deprecated::visual_runs(range, &levels);
|
||||
line.visual_runs = Some(runs.iter().map(|run| {
|
||||
let start = FragmentIndex(run.start as isize);
|
||||
let len = FragmentIndex(run.len() as isize);
|
||||
|
@ -957,11 +960,11 @@ impl InlineFlow {
|
|||
let (range, level) = match line.visual_runs {
|
||||
Some(ref runs) if is_ltr => runs[run_idx],
|
||||
Some(ref runs) => runs[run_count - run_idx - 1], // reverse order for RTL runs
|
||||
None => (line.range, 0)
|
||||
None => (line.range, bidi::Level::ltr())
|
||||
};
|
||||
// If the bidi embedding direction is opposite the layout direction, lay out this
|
||||
// run in reverse order.
|
||||
let reverse = unicode_bidi::is_ltr(level) != is_ltr;
|
||||
let reverse = level.is_ltr() != is_ltr;
|
||||
let fragment_indices = if reverse {
|
||||
(range.end().get() - 1..range.begin().get() - 1).step_by(-1)
|
||||
} else {
|
||||
|
|
|
@ -28,7 +28,7 @@ use style::computed_values::{word_break, white_space};
|
|||
use style::logical_geometry::{LogicalSize, WritingMode};
|
||||
use style::properties::ServoComputedValues;
|
||||
use style::properties::style_structs;
|
||||
use unicode_bidi::{is_rtl, process_text};
|
||||
use unicode_bidi as bidi;
|
||||
use unicode_script::{Script, get_script};
|
||||
|
||||
/// Returns the concatenated text of a list of unscanned text fragments.
|
||||
|
@ -74,10 +74,10 @@ impl TextRunScanner {
|
|||
// Calculate bidi embedding levels, so we can split bidirectional fragments for reordering.
|
||||
let text = text(&fragments);
|
||||
let para_level = fragments.front().unwrap().style.writing_mode.to_bidi_level();
|
||||
let bidi_info = process_text(&text, Some(para_level));
|
||||
let bidi_info = bidi::BidiInfo::new(&text, Some(para_level));
|
||||
|
||||
// Optimization: If all the text is LTR, don't bother splitting on bidi levels.
|
||||
let bidi_levels = if bidi_info.levels.iter().cloned().any(is_rtl) {
|
||||
let bidi_levels = if bidi_info.has_rtl() {
|
||||
Some(&bidi_info.levels[..])
|
||||
} else {
|
||||
None
|
||||
|
@ -126,7 +126,7 @@ impl TextRunScanner {
|
|||
font_context: &mut FontContext,
|
||||
out_fragments: &mut Vec<Fragment>,
|
||||
paragraph_bytes_processed: &mut usize,
|
||||
bidi_levels: Option<&[u8]>,
|
||||
bidi_levels: Option<&[bidi::Level]>,
|
||||
mut last_whitespace: bool)
|
||||
-> bool {
|
||||
debug!("TextRunScanner: flushing {} fragments in range", self.clump.len());
|
||||
|
@ -211,7 +211,7 @@ impl TextRunScanner {
|
|||
|
||||
let bidi_level = match bidi_levels {
|
||||
Some(levels) => levels[*paragraph_bytes_processed],
|
||||
None => 0
|
||||
None => bidi::Level::ltr(),
|
||||
};
|
||||
|
||||
// Break the run if the new character has a different explicit script than the
|
||||
|
@ -310,7 +310,7 @@ impl TextRunScanner {
|
|||
run_info_list.into_iter().map(|run_info| {
|
||||
let mut options = options;
|
||||
options.script = run_info.script;
|
||||
if is_rtl(run_info.bidi_level) {
|
||||
if run_info.bidi_level.is_rtl() {
|
||||
options.flags.insert(RTL_FLAG);
|
||||
}
|
||||
let mut font = fontgroup.fonts.get(run_info.font_index).unwrap().borrow_mut();
|
||||
|
@ -522,7 +522,7 @@ struct RunInfo {
|
|||
/// The index of the applicable font in the font group.
|
||||
font_index: usize,
|
||||
/// The bidirection embedding level of this text run.
|
||||
bidi_level: u8,
|
||||
bidi_level: bidi::Level,
|
||||
/// The Unicode script property of this text run.
|
||||
script: Script,
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ impl RunInfo {
|
|||
text: String::new(),
|
||||
insertion_point: None,
|
||||
font_index: 0,
|
||||
bidi_level: 0,
|
||||
bidi_level: bidi::Level::ltr(),
|
||||
script: Script::Common,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue