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:
bors-servo 2017-05-22 23:06:07 -05:00 committed by GitHub
commit edd6c2cecb
10 changed files with 61 additions and 34 deletions

View file

@ -67,6 +67,7 @@ style_derive = {path = "../style_derive"}
style_traits = {path = "../style_traits"}
servo_url = {path = "../url", optional = true}
time = "0.1"
unicode-bidi = {version = "0.3", features = ["with_serde"]}
unicode-segmentation = "1.0"
[target.'cfg(windows)'.dependencies]

View file

@ -83,6 +83,7 @@ extern crate style_derive;
#[macro_use]
extern crate style_traits;
extern crate time;
extern crate unicode_bidi;
#[allow(unused_extern_crates)]
extern crate unicode_segmentation;

View file

@ -10,6 +10,7 @@ use euclid::side_offsets::SideOffsets2D;
use std::cmp::{max, min};
use std::fmt::{self, Debug, Error, Formatter};
use std::ops::{Add, Sub};
use unicode_bidi as bidi;
pub enum BlockFlowDirection {
TopToBottom,
@ -131,9 +132,13 @@ impl WritingMode {
#[inline]
/// The default bidirectional embedding level for this writing mode.
///
/// Returns 0 if the mode is LTR, or 1 otherwise.
pub fn to_bidi_level(&self) -> u8 {
!self.is_bidi_ltr() as u8
/// Returns bidi level 0 if the mode is LTR, or 1 otherwise.
pub fn to_bidi_level(&self) -> bidi::Level {
if self.is_bidi_ltr() {
bidi::Level::ltr()
} else {
bidi::Level::rtl()
}
}
}