mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
layout: Simplify and improve the correctness of whitespace stripping in
text layout, and unify the inline layout paths for pre- and normally-formatted text. This fixes a lot of "jumpiness" and removes the `new_line_pos` stuff. Closes #2260.
This commit is contained in:
parent
88aa07b7e0
commit
6d61468160
12 changed files with 485 additions and 461 deletions
|
@ -2,8 +2,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use text::glyph::CharIndex;
|
||||
|
||||
#[derive(PartialEq, Eq, Copy)]
|
||||
pub enum CompressionMode {
|
||||
CompressNone,
|
||||
|
@ -25,12 +23,10 @@ pub enum CompressionMode {
|
|||
pub fn transform_text(text: &str,
|
||||
mode: CompressionMode,
|
||||
incoming_whitespace: bool,
|
||||
output_text: &mut String,
|
||||
new_line_pos: &mut Vec<CharIndex>)
|
||||
output_text: &mut String)
|
||||
-> bool {
|
||||
let out_whitespace = match mode {
|
||||
CompressionMode::CompressNone | CompressionMode::DiscardNewline => {
|
||||
let mut new_line_index = CharIndex(0);
|
||||
for ch in text.chars() {
|
||||
if is_discardable_char(ch, mode) {
|
||||
// TODO: record skipped char
|
||||
|
@ -38,15 +34,6 @@ pub fn transform_text(text: &str,
|
|||
// TODO: record kept char
|
||||
if ch == '\t' {
|
||||
// TODO: set "has tab" flag
|
||||
} else if ch == '\n' {
|
||||
// Save new-line's position for line-break
|
||||
// This value is relative(not absolute)
|
||||
new_line_pos.push(new_line_index);
|
||||
new_line_index = CharIndex(0);
|
||||
}
|
||||
|
||||
if ch != '\n' {
|
||||
new_line_index = new_line_index + CharIndex(1);
|
||||
}
|
||||
output_text.push(ch);
|
||||
}
|
||||
|
@ -124,6 +111,6 @@ pub fn fixed_to_rounded_int(before: isize, f: i32) -> isize {
|
|||
if f > 0i32 {
|
||||
((half + f) >> before) as isize
|
||||
} else {
|
||||
-((half - f) >> before) as isize
|
||||
-((half - f) >> before as usize) as isize
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue