diff --git a/src/servo/servo.rc b/src/servo/servo.rc index e0caa2ba59f..a773e46a160 100755 --- a/src/servo/servo.rc +++ b/src/servo/servo.rc @@ -62,6 +62,7 @@ mod text { mod glyph; mod text_run; mod font; + mod shaper; } mod util { diff --git a/src/servo/text/shaper.rs b/src/servo/text/shaper.rs new file mode 100644 index 00000000000..5fb22673db7 --- /dev/null +++ b/src/servo/text/shaper.rs @@ -0,0 +1,28 @@ +import libc::types::common::c99::int32_t; +import font::font; +import glyph::{glyph, glyph_pos}; + +#[doc = " +Calculate the layout metrics associated with a some given text +when rendered in a specific font. +"] +fn shape_text(_font: &font, text: str) -> [glyph] { + let mut glyphs = []; + let mut cur_x = 0u; + for text.each_char { + |ch| + // TODO: Use HarfBuzz! + let hb_pos = { + x_advance: 10 as int32_t, + y_advance: 0 as int32_t, + x_offset: cur_x as int32_t, + y_offset: 0 as int32_t, + var: 0 + }; + + vec::push(glyphs, glyph(ch as uint, glyph_pos(hb_pos))); + cur_x += 10u; + }; + + ret glyphs; +} diff --git a/src/servo/text/text_run.rs b/src/servo/text/text_run.rs index 79a6169dee4..76d2144e88b 100644 --- a/src/servo/text/text_run.rs +++ b/src/servo/text/text_run.rs @@ -1,6 +1,6 @@ import libc::{c_void}; -import libc::types::common::c99::int32_t; -import text::glyph::{glyph, glyph_pos}; +import text::glyph::glyph; +import shaper::shape_text; #[doc="A single, unbroken line of text."] class text_run { @@ -17,24 +17,8 @@ class text_run { line break positions. "] fn shape() { - let mut glyphs = []; - let mut cur_x = 0u; - for self.text.each_char { - |ch| - // TODO: Use HarfBuzz! - let hb_pos = { - x_advance: 10 as int32_t, - y_advance: 0 as int32_t, - x_offset: cur_x as int32_t, - y_offset: 0 as int32_t, - var: 0 - }; - - vec::push(glyphs, glyph(ch as uint, glyph_pos(hb_pos))); - cur_x += 10u; - }; - - self.glyphs = some(/* move */ glyphs); + let font = font::create(); + self.glyphs = some(shape_text(&font, self.text)); } }