mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Introduce GlyphIndex type to distinguish glyph codepoints vs unicode codepoints
This commit is contained in:
parent
5f8493e3a9
commit
7d56150947
4 changed files with 15 additions and 9 deletions
|
@ -192,7 +192,7 @@ fn draw_text(draw_target: AzDrawTargetRef, item: dl::display_item, text_run: Tex
|
||||||
let mut origin = Point2D(bounds.origin.x, bounds.origin.y.add(bounds.size.height));
|
let mut origin = Point2D(bounds.origin.x, bounds.origin.y.add(bounds.size.height));
|
||||||
let azglyphs = text_run.glyphs.map { |glyph|
|
let azglyphs = text_run.glyphs.map { |glyph|
|
||||||
let azglyph: AzGlyph = {
|
let azglyph: AzGlyph = {
|
||||||
mIndex: glyph.codepoint as uint32_t,
|
mIndex: glyph.index as uint32_t,
|
||||||
mPosition: {
|
mPosition: {
|
||||||
x: au_to_px(origin.x.add(glyph.pos.offset.x)) as AzFloat,
|
x: au_to_px(origin.x.add(glyph.pos.offset.x)) as AzFloat,
|
||||||
y: au_to_px(origin.y.add(glyph.pos.offset.y)) as AzFloat
|
y: au_to_px(origin.y.add(glyph.pos.offset.y)) as AzFloat
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export Font, create_test_font, test_font_bin;
|
export Font, create_test_font, test_font_bin;
|
||||||
|
|
||||||
|
import glyph::GlyphIndex;
|
||||||
import vec_to_ptr = vec::unsafe::to_ptr;
|
import vec_to_ptr = vec::unsafe::to_ptr;
|
||||||
import libc::{ c_int, c_double, c_ulong };
|
import libc::{ c_int, c_double, c_ulong };
|
||||||
import ptr::{ null, addr_of };
|
import ptr::{ null, addr_of };
|
||||||
|
@ -48,7 +49,7 @@ class Font/& {
|
||||||
&self.fontbuf
|
&self.fontbuf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_idx(codepoint: char) -> option<uint> {
|
fn glyph_idx(codepoint: char) -> option<GlyphIndex> {
|
||||||
#debug("getting glyph for codepoint %u", codepoint as uint);
|
#debug("getting glyph for codepoint %u", codepoint as uint);
|
||||||
let codepoint_str = str::from_char(codepoint);
|
let codepoint_str = str::from_char(codepoint);
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ class Font/& {
|
||||||
// This might not be true, but at least we'll know if it isn't
|
// This might not be true, but at least we'll know if it isn't
|
||||||
assert num_glyphs == 1 as c_int;
|
assert num_glyphs == 1 as c_int;
|
||||||
|
|
||||||
let glyph_index = unsafe { *glyphs }.index as uint;
|
let glyph_index = unsafe { *glyphs }.index as GlyphIndex;
|
||||||
#debug("glyph index is %?", glyph_index);
|
#debug("glyph index is %?", glyph_index);
|
||||||
cairo_glyph_free(glyphs);
|
cairo_glyph_free(glyphs);
|
||||||
some(glyph_index)
|
some(glyph_index)
|
||||||
|
@ -80,7 +81,7 @@ class Font/& {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_h_advance(glyph: uint) -> int {
|
fn glyph_h_advance(glyph: GlyphIndex) -> int {
|
||||||
|
|
||||||
#debug("getting h advance for glyph %?", glyph);
|
#debug("getting h advance for glyph %?", glyph);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
export GlyphIndex, GlyphPos, Glyph;
|
||||||
|
|
||||||
import gfx::geometry::au;
|
import gfx::geometry::au;
|
||||||
import geom::point::Point2D;
|
import geom::point::Point2D;
|
||||||
|
|
||||||
|
#[doc = "The index of a particular glyph within a font"]
|
||||||
|
type GlyphIndex = uint;
|
||||||
|
|
||||||
#[doc="The position of a glyph on the screen."]
|
#[doc="The position of a glyph on the screen."]
|
||||||
class GlyphPos {
|
class GlyphPos {
|
||||||
let advance: Point2D<au>;
|
let advance: Point2D<au>;
|
||||||
|
@ -13,11 +18,11 @@ class GlyphPos {
|
||||||
|
|
||||||
#[doc="A single glyph."]
|
#[doc="A single glyph."]
|
||||||
class Glyph {
|
class Glyph {
|
||||||
let codepoint: uint;
|
let index: GlyphIndex;
|
||||||
let pos: GlyphPos;
|
let pos: GlyphPos;
|
||||||
|
|
||||||
new(codepoint: uint, pos: GlyphPos) {
|
new(index: GlyphIndex, pos: GlyphPos) {
|
||||||
self.codepoint = codepoint;
|
self.index = index;
|
||||||
self.pos = copy pos;
|
self.pos = copy pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,12 +141,12 @@ fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> GlyphPos {
|
||||||
px_to_au(hb_pos.y_offset as int)))
|
px_to_au(hb_pos.y_offset as int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_get_glyph_codepoints() {
|
fn should_get_glyph_indexes() {
|
||||||
#[test];
|
#[test];
|
||||||
|
|
||||||
let font = font::create_test_font();
|
let font = font::create_test_font();
|
||||||
let glyphs = shape_text(&font, "firecracker");
|
let glyphs = shape_text(&font, "firecracker");
|
||||||
let idxs = glyphs.map { |glyph| glyph.codepoint };
|
let idxs = glyphs.map { |glyph| glyph.index };
|
||||||
assert idxs == [32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u];
|
assert idxs == [32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue