Use xi-unicode for line breaking

This commit is contained in:
Matt Brubeck 2016-04-28 10:50:30 -07:00
parent d3f55fbf60
commit 894f6395e6
243 changed files with 430 additions and 470 deletions

View file

@ -44,6 +44,7 @@ azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]}
layers = {git = "https://github.com/servo/rust-layers", features = ["plugins"]}
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
webrender_traits = {git = "https://github.com/servo/webrender_traits"}
xi-unicode = "0.0.1"
[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.2"

View file

@ -80,6 +80,7 @@ extern crate unicode_script;
extern crate url;
extern crate util;
extern crate webrender_traits;
extern crate xi_unicode;
pub use paint_context::PaintContext;

View file

@ -12,7 +12,9 @@ use std::cmp::{Ordering, max};
use std::slice::Iter;
use std::sync::Arc;
use text::glyph::{ByteIndex, GlyphStore};
use util::str::char_is_whitespace;
use webrender_traits;
use xi_unicode::LineBreakIterator;
thread_local! {
static INDEX_OF_FIRST_GLYPH_RUN_CACHE: Cell<Option<(*const TextRun, ByteIndex, usize)>> =
@ -191,73 +193,40 @@ impl<'a> TextRun {
pub fn break_and_shape(font: &mut Font, text: &str, options: &ShapingOptions)
-> Vec<GlyphRun> {
// TODO(Issue #230): do a better job. See Gecko's LineBreaker.
let mut glyphs = vec!();
let mut byte_i = 0;
let mut cur_slice_is_whitespace = false;
let mut byte_last_boundary = 0;
let mut slice = 0..0;
for ch in text.chars() {
// Slices alternate between whitespace and non-whitespace,
// representing line break opportunities.
let can_break_before = if cur_slice_is_whitespace {
match ch {
' ' | '\t' | '\n' => false,
_ => {
cur_slice_is_whitespace = false;
true
}
}
} else {
match ch {
' ' | '\t' | '\n' => {
cur_slice_is_whitespace = true;
true
},
_ => false
}
};
for (idx, _is_hard_break) in LineBreakIterator::new(text) {
// Extend the slice to the next UAX#14 line break opportunity.
slice.end = idx;
let word = &text[slice.clone()];
// Create a glyph store for this slice if it's nonempty.
if can_break_before && byte_i > byte_last_boundary {
let slice = &text[byte_last_boundary .. byte_i];
debug!("creating glyph store for slice {} (ws? {}), {} - {} in run {}",
slice, !cur_slice_is_whitespace, byte_last_boundary, byte_i, text);
let mut options = *options;
if !cur_slice_is_whitespace {
options.flags.insert(IS_WHITESPACE_SHAPING_FLAG);
// Split off any trailing whitespace into a separate glyph run.
let mut whitespace = slice.end..slice.end;
if let Some((i, _)) = word.char_indices().rev()
.take_while(|&(_, c)| char_is_whitespace(c)).last() {
whitespace.start = slice.start + i;
slice.end = whitespace.start;
}
if slice.len() > 0 {
glyphs.push(GlyphRun {
glyph_store: font.shape_text(slice, &options),
range: Range::new(ByteIndex(byte_last_boundary as isize),
ByteIndex((byte_i - byte_last_boundary) as isize)),
});
byte_last_boundary = byte_i;
}
byte_i = byte_i + ch.len_utf8();
}
// Create a glyph store for the final slice if it's nonempty.
if byte_i > byte_last_boundary {
let slice = &text[byte_last_boundary..];
debug!("creating glyph store for final slice {} (ws? {}), {} - {} in run {}",
slice, cur_slice_is_whitespace, byte_last_boundary, text.len(), text);
let mut options = *options;
if cur_slice_is_whitespace {
options.flags.insert(IS_WHITESPACE_SHAPING_FLAG);
}
glyphs.push(GlyphRun {
glyph_store: font.shape_text(slice, &options),
range: Range::new(ByteIndex(byte_last_boundary as isize),
ByteIndex((byte_i - byte_last_boundary) as isize)),
glyph_store: font.shape_text(&text[slice.clone()], options),
range: Range::new(ByteIndex(slice.start as isize),
ByteIndex(slice.len() as isize)),
});
}
if whitespace.len() > 0 {
let mut options = options.clone();
options.flags.insert(IS_WHITESPACE_SHAPING_FLAG);
glyphs.push(GlyphRun {
glyph_store: font.shape_text(&text[whitespace.clone()], &options),
range: Range::new(ByteIndex(whitespace.start as isize),
ByteIndex(whitespace.len() as isize)),
});
}
slice.start = whitespace.end;
}
glyphs
}

View file

@ -740,6 +740,7 @@ dependencies = [
"url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
"xi-unicode 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2510,6 +2511,11 @@ dependencies = [
"libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xi-unicode"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "xml-rs"
version = "0.2.2"

6
ports/cef/Cargo.lock generated
View file

@ -669,6 +669,7 @@ dependencies = [
"url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
"xi-unicode 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2375,6 +2376,11 @@ dependencies = [
"libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xi-unicode"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "xml-rs"
version = "0.2.2"

6
ports/gonk/Cargo.lock generated
View file

@ -672,6 +672,7 @@ dependencies = [
"url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
"xi-unicode 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2326,6 +2327,11 @@ dependencies = [
"libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xi-unicode"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "xml-rs"
version = "0.2.2"

View file

@ -1,4 +0,0 @@
[css-flexbox-column-reverse.htm]
type: reftest
expected:
if os == "linux": FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-002.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-003.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-004.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-005.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-006.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-007.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-008.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-009.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-010.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-011.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-012.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-015.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-017.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-018.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-019.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-025.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-026.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-030.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-031.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-032.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-033.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-034.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-035.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-036.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-037.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-038.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-039.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-040.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-041.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-042.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-043.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-044.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-045.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-046.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-047.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-048.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-060.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-061.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-066.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-067.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-091.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-108.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,5 +0,0 @@
[css3-text-line-break-baspglwj-111.htm]
type: testharness
[ ]
expected: FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-001.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-002.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-003.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-004.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-005.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-006.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-007.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-008.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-009.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-010.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-011.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-012.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-013.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-014.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-015.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-016.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-017.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-018.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-019.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-020.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-021.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-022.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-023.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-024.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-025.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-027.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-028.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-029.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-030.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-032.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-034.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-036.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-038.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-039.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-040.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-042.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-043.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-044.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-045.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-046.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-047.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-048.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-049.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-051.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-052.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-054.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-056.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-057.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-058.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

View file

@ -1,3 +1,4 @@
[css3-text-line-break-jazh-060.htm]
type: reftest
expected: FAIL
expected:
if os == "linux": FAIL

Some files were not shown because too many files have changed in this diff Show more