mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
Add a text shaper. No impl yet
This commit is contained in:
parent
4565a37510
commit
7f8573243b
3 changed files with 33 additions and 20 deletions
|
@ -62,6 +62,7 @@ mod text {
|
|||
mod glyph;
|
||||
mod text_run;
|
||||
mod font;
|
||||
mod shaper;
|
||||
}
|
||||
|
||||
mod util {
|
||||
|
|
28
src/servo/text/shaper.rs
Normal file
28
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…
Add table
Add a link
Reference in a new issue