Fix text-transform:capitalize across text runs

This commit is contained in:
Matt Brubeck 2015-09-28 14:57:44 -07:00
parent 371e6897e1
commit 6304186f4f
3 changed files with 10 additions and 5 deletions

View file

@ -524,9 +524,12 @@ impl RunMapping {
// Account for `text-transform`. (Confusingly, this is not handled in "text // Account for `text-transform`. (Confusingly, this is not handled in "text
// transformation" above, but we follow Gecko in the naming.) // transformation" above, but we follow Gecko in the naming.)
let is_first_run = *start_position == 0;
let character_count = apply_style_transform_if_necessary(&mut run_info.text, let character_count = apply_style_transform_if_necessary(&mut run_info.text,
old_byte_length, old_byte_length,
text_transform); text_transform,
*last_whitespace,
is_first_run);
// Record the position of the insertion point if necessary. // Record the position of the insertion point if necessary.
if let Some(insertion_point) = insertion_point { if let Some(insertion_point) = insertion_point {
@ -557,7 +560,9 @@ impl RunMapping {
/// use graphemes instead of characters. /// use graphemes instead of characters.
fn apply_style_transform_if_necessary(string: &mut String, fn apply_style_transform_if_necessary(string: &mut String,
first_character_position: usize, first_character_position: usize,
text_transform: text_transform::T) text_transform: text_transform::T,
last_whitespace: bool,
is_first_run: bool)
-> usize { -> usize {
match text_transform { match text_transform {
text_transform::T::none => string[first_character_position..].chars().count(), text_transform::T::none => string[first_character_position..].chars().count(),
@ -585,9 +590,7 @@ fn apply_style_transform_if_necessary(string: &mut String,
let original = string[first_character_position..].to_owned(); let original = string[first_character_position..].to_owned();
string.truncate(first_character_position); string.truncate(first_character_position);
// FIXME(pcwalton): This may not always be correct in the case of something like let mut capitalize_next_letter = is_first_run || last_whitespace;
// `f<span>oo</span>`.
let mut capitalize_next_letter = true;
let mut count = 0; let mut count = 0;
for character in original.chars() { for character in original.chars() {
count += 1; count += 1;

View file

@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<meta charset="UTF-8">
<!-- Tests that `text-transform: capitalize` works. --> <!-- Tests that `text-transform: capitalize` works. -->
<body> <body>
<h1 style='text-transform: capitalize; font-family: Hiragino Maru Gothic Pro'>ュゥゥゥゥ can do ányThing at ゾムボ.cOm</h1> <h1 style='text-transform: capitalize; font-family: Hiragino Maru Gothic Pro'>ュゥゥゥゥ can do ányThing at ゾムボ.cOm</h1>

View file

@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<meta charset="UTF-8">
<!-- Tests that `text-transform: capitalize` works. --> <!-- Tests that `text-transform: capitalize` works. -->
<body> <body>
<h1 style='font-family: Hiragino Maru Gothic Pro'>ュゥゥゥゥ Can Do ÁnyThing At ゾムボ.cOm</h1> <h1 style='font-family: Hiragino Maru Gothic Pro'>ュゥゥゥゥ Can Do ÁnyThing At ゾムボ.cOm</h1>