mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
servo: Add a text shaper. No impl yet
Source-Repo: https://github.com/servo/servo Source-Revision: 7f8573243b156ee2189381a559c066377a7dca74
This commit is contained in:
parent
3b78af7d4b
commit
2460640bbe
@ -62,6 +62,7 @@ mod text {
|
||||
mod glyph;
|
||||
mod text_run;
|
||||
mod font;
|
||||
mod shaper;
|
||||
}
|
||||
|
||||
mod util {
|
||||
|
28
servo/src/servo/text/shaper.rs
Normal file
28
servo/src/servo/text/shaper.rs
Normal file
@ -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;
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user