mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Break text runs by unicode script
This commit is contained in:
parent
062493fac6
commit
371e6897e1
8 changed files with 51 additions and 1 deletions
|
@ -23,6 +23,7 @@ use style::computed_values::{white_space};
|
|||
use style::properties::ComputedValues;
|
||||
use style::properties::style_structs::Font as FontStyle;
|
||||
use unicode_bidi::{is_rtl, process_text};
|
||||
use unicode_script::{get_script, Script};
|
||||
use util::geometry::Au;
|
||||
use util::linked_list::split_off_head;
|
||||
use util::logical_geometry::{LogicalSize, WritingMode};
|
||||
|
@ -204,8 +205,22 @@ impl TextRunScanner {
|
|||
None => 0
|
||||
};
|
||||
|
||||
// Break the run if the new character has a different explicit script than the
|
||||
// previous characters.
|
||||
//
|
||||
// TODO: Special handling of paired punctuation characters.
|
||||
// http://www.unicode.org/reports/tr24/#Common
|
||||
let script = get_script(character);
|
||||
let compatible_script = is_compatible(script, run_info.script);
|
||||
if compatible_script && !is_specific(run_info.script) && is_specific(script) {
|
||||
run_info.script = script;
|
||||
}
|
||||
|
||||
// Now, if necessary, flush the mapping we were building up.
|
||||
if run_info.font_index != font_index || run_info.bidi_level != bidi_level {
|
||||
if run_info.font_index != font_index ||
|
||||
run_info.bidi_level != bidi_level ||
|
||||
!compatible_script
|
||||
{
|
||||
if end_position > start_position {
|
||||
mapping.flush(&mut mappings,
|
||||
&mut run_info,
|
||||
|
@ -226,6 +241,7 @@ impl TextRunScanner {
|
|||
}
|
||||
run_info.font_index = font_index;
|
||||
run_info.bidi_level = bidi_level;
|
||||
run_info.script = script;
|
||||
}
|
||||
|
||||
// Consume this character.
|
||||
|
@ -269,12 +285,14 @@ impl TextRunScanner {
|
|||
let options = ShapingOptions {
|
||||
letter_spacing: letter_spacing,
|
||||
word_spacing: word_spacing,
|
||||
script: Script::Common,
|
||||
flags: flags,
|
||||
};
|
||||
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
run_info_list.into_iter().map(|run_info| {
|
||||
let mut options = options;
|
||||
options.script = run_info.script;
|
||||
if is_rtl(run_info.bidi_level) {
|
||||
options.flags.insert(RTL_FLAG);
|
||||
}
|
||||
|
@ -440,6 +458,8 @@ struct RunInfo {
|
|||
character_length: usize,
|
||||
/// The bidirection embedding level of this text run.
|
||||
bidi_level: u8,
|
||||
/// The Unicode script property of this text run.
|
||||
script: Script,
|
||||
}
|
||||
|
||||
impl RunInfo {
|
||||
|
@ -450,6 +470,7 @@ impl RunInfo {
|
|||
font_index: 0,
|
||||
character_length: 0,
|
||||
bidi_level: 0,
|
||||
script: Script::Common,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -599,3 +620,13 @@ struct ScannedTextRun {
|
|||
run: Arc<TextRun>,
|
||||
insertion_point: Option<CharIndex>,
|
||||
}
|
||||
|
||||
/// Can a character with script `b` continue a text run with script `a`?
|
||||
fn is_compatible(a: Script, b: Script) -> bool {
|
||||
a == b || !is_specific(a) || !is_specific(b)
|
||||
}
|
||||
|
||||
/// Returns true if the script is not invalid or inherited.
|
||||
fn is_specific(script: Script) -> bool {
|
||||
script != Script::Common && script != Script::Inherited
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue