Skip to content

Commit

Permalink
Show tabs in pre elements
Browse files Browse the repository at this point in the history
Display tab characters as 8 spaces for pre and other elements that don't
compress whitespace.
  • Loading branch information
bjwbell committed Apr 3, 2015
1 parent 225d7d2 commit 29852bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/gfx/text/shaping/harfbuzz.rs
Expand Up @@ -521,6 +521,9 @@ impl Shaper {
// We elect to only space the two required code points.
if character == ' ' || character == '\u{a0}' {
advance = advance + options.word_spacing
} else if character == '\t' {
let tab_size = 8f64;
advance = Au::from_frac_px(tab_size * glyph_space_advance(self.font_and_shaping_options.font));
}

advance
Expand Down Expand Up @@ -563,6 +566,19 @@ extern fn glyph_h_advance_func(_: *mut hb_font_t,
}
}

fn glyph_space_advance(font: *mut Font) -> f64 {
let space_unicode = ' ';
let space_glyph: hb_codepoint_t;
match unsafe {(*font).glyph_index(space_unicode)} {
Some(g) => {
space_glyph = g as hb_codepoint_t;
}
None => panic!("No space info")
}
let space_advance = unsafe {(*font).glyph_h_advance(space_glyph as GlyphId)};
space_advance
}

extern fn glyph_h_kerning_func(_: *mut hb_font_t,
font_data: *mut c_void,
first_glyph: hb_codepoint_t,
Expand Down
1 change: 1 addition & 0 deletions tests/ref/basic.list
Expand Up @@ -245,6 +245,7 @@ experimental != overconstrained_block.html overconstrained_block_ref.html
== position_relative_a.html position_relative_b.html
== position_relative_top_percentage_a.html position_relative_top_percentage_b.html
== pre_ignorable_whitespace_a.html pre_ignorable_whitespace_ref.html
== pre_with_tab.html pre_with_tab_ref.html
== pseudo_element_a.html pseudo_element_b.html
== pseudo_inherit.html pseudo_inherit_ref.html
== quotes_simple_a.html quotes_simple_ref.html
Expand Down
1 change: 1 addition & 0 deletions tests/ref/pre_with_tab.html
@@ -0,0 +1 @@
<html><body><pre> tab</pre></body></html>
1 change: 1 addition & 0 deletions tests/ref/pre_with_tab_ref.html
@@ -0,0 +1 @@
<html><body><pre> tab</pre></body></html>

6 comments on commit 29852bb

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from mbrubeck
at bjwbell@29852bb

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjwbell/servo/tab-in-pre = 29852bb into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjwbell/servo/tab-in-pre = 29852bb merged ok, testing candidate = 49ff683

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No active merge of candidate 29852bb found, likely manual push to master

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjwbell/servo/tab-in-pre = 29852bb into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjwbell/servo/tab-in-pre = 29852bb merged ok, testing candidate = 40fab8e

Please sign in to comment.