Camel-case text types

This commit is contained in:
Brian Anderson 2012-06-21 13:49:25 -07:00
parent ce615bf12a
commit 5f8493e3a9
7 changed files with 33 additions and 34 deletions

View file

@ -6,7 +6,7 @@ import dl = layout::display_list;
import azure::*;
import azure::bindgen::*;
import libc::size_t;
import text::text_run::text_run;
import text::text_run::TextRun;
enum Msg {
RenderMsg(dl::display_list),
@ -151,13 +151,13 @@ fn draw_image(draw_target: AzDrawTargetRef, item: dl::display_item,
}
}
fn draw_text(draw_target: AzDrawTargetRef, item: dl::display_item, text_run: text_run) {
fn draw_text(draw_target: AzDrawTargetRef, item: dl::display_item, text_run: TextRun) {
import ptr::{addr_of, null};
import vec::unsafe::to_ptr;
import libc::types::common::c99::{uint16_t, uint32_t};
import geom::point::Point2D;
import text::font::{font, create_test_font};
import text::font::{Font, create_test_font};
import azure::{AzNativeFont, AzFloat, AZ_NATIVE_FONT_CAIRO_FONT_FACE};
import azure::bindgen::{AzCreateScaledFontWithCairo,
AzReleaseScaledFont,

View file

@ -1,12 +1,12 @@
import gfx::geometry::*;
import geom::rect::Rect;
import image::base::image;
import servo_text::text_run::text_run;
import servo_text::text_run::TextRun;
enum item_type {
display_item_solid_color(u8, u8, u8),
display_item_image(~image),
display_item_text(text_run),
display_item_text(TextRun),
// FIXME: Shape code does not understand the alignment without this
padding(u8, u8, u8, u8)
}

View file

@ -3,12 +3,12 @@
import geom::size::Size2D;
import gfx::geometry::au;
import layout::base::*; // FIXME: Can't get around import *; resolve bug.
import servo_text::text_run::text_run;
import servo_text::text_run::TextRun;
import servo_text::font::create_test_font;
class text_box {
let text: str;
let mut run: option<text_run>;
let mut run: option<TextRun>;
new(-text: str) {
self.text = text;
@ -25,7 +25,7 @@ impl text_layout_methods for @Box {
};
let font = create_test_font();
let run = text_run(&font, subbox.text);
let run = TextRun(&font, subbox.text);
self.bounds.size = run.size();
subbox.run = some(run);
}

View file

@ -1,4 +1,4 @@
export font, create_test_font, test_font_bin;
export Font, create_test_font, test_font_bin;
import vec_to_ptr = vec::unsafe::to_ptr;
import libc::{ c_int, c_double, c_ulong };
@ -25,7 +25,7 @@ A font handle. Layout can use this to calculate glyph metrics
and the renderer can use it to render text.
"]
#[warn(no_non_implicitly_copyable_typarams)]
class font/& {
class Font/& {
let fontbuf: [u8];
let cairo_font: *cairo_scaled_font_t;
let font_dtor: fn@();
@ -260,8 +260,8 @@ fn get_cairo_face(buf: &[u8]) -> (*cairo_font_face_t, fn@()) {
(cface, dtor)
}
fn create_test_font() -> font {
font(test_font_bin())
fn create_test_font() -> Font {
Font(test_font_bin())
}
fn test_font_bin() -> [u8] { #include_bin("JosefinSans-SemiBold.ttf") }

View file

@ -2,7 +2,7 @@ import gfx::geometry::au;
import geom::point::Point2D;
#[doc="The position of a glyph on the screen."]
class glyph_pos {
class GlyphPos {
let advance: Point2D<au>;
let offset: Point2D<au>;
new(advance: Point2D<au>, offset: Point2D<au>) {
@ -12,13 +12,12 @@ class glyph_pos {
}
#[doc="A single glyph."]
class glyph {
class Glyph {
let codepoint: uint;
let pos: glyph_pos;
let pos: GlyphPos;
new(codepoint: uint, pos: glyph_pos) {
new(codepoint: uint, pos: GlyphPos) {
self.codepoint = codepoint;
self.pos = copy pos;
}
}

View file

@ -4,8 +4,8 @@ export shape_text;
import libc::types::common::c99::int32_t;
import libc::{c_uint, c_int, c_void};
import font::font;
import glyph::{glyph, glyph_pos};
import font::Font;
import glyph::{Glyph, GlyphPos};
import ptr::{null, addr_of, offset};
import gfx::geometry::{au, px_to_au};
import geom::point::Point2D;
@ -35,7 +35,7 @@ import harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy,
Calculate the layout metrics associated with a some given text
when rendered in a specific font.
"]
fn shape_text(font: &font, text: str) -> [glyph] unsafe {
fn shape_text(font: &Font, text: str) -> [Glyph] unsafe {
#debug("shaping text '%s'", text);
let face_blob = vec::as_buf(*(*font).buf()) { |buf|
@ -89,7 +89,7 @@ fn shape_text(font: &font, text: str) -> [glyph] unsafe {
#debug("glyph %?: codep %?, x_adv %?, y_adv %?, x_off %?, y_of %?",
i, codepoint, pos.advance.x, pos.advance.y, pos.offset.x, pos.offset.y);
glyphs += [glyph(codepoint, pos)];
glyphs += [Glyph(codepoint, pos)];
}
hb_buffer_destroy(buffer);
@ -108,7 +108,7 @@ crust fn glyph_func(_font: *hb_font_t,
glyph: *mut hb_codepoint_t,
_user_data: *c_void) -> hb_bool_t unsafe {
let font: *font = reinterpret_cast(font_data);
let font: *Font = reinterpret_cast(font_data);
assert font.is_not_null();
ret alt (*font).glyph_idx(unicode as char) {
@ -126,7 +126,7 @@ crust fn glyph_h_advance_func(_font: *hb_font_t,
font_data: *c_void,
glyph: hb_codepoint_t,
_user_data: *c_void) -> hb_position_t unsafe {
let font: *font = reinterpret_cast(font_data);
let font: *Font = reinterpret_cast(font_data);
assert font.is_not_null();
let h_advance = (*font).glyph_h_advance(glyph as uint);
@ -134,11 +134,11 @@ crust fn glyph_h_advance_func(_font: *hb_font_t,
ret h_advance as hb_position_t;
}
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> glyph_pos {
glyph_pos(Point2D(px_to_au(hb_pos.x_advance as int),
px_to_au(hb_pos.y_advance as int)),
Point2D(px_to_au(hb_pos.x_offset as int),
px_to_au(hb_pos.y_offset as int)))
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> GlyphPos {
GlyphPos(Point2D(px_to_au(hb_pos.x_advance as int),
px_to_au(hb_pos.y_advance as int)),
Point2D(px_to_au(hb_pos.x_offset as int),
px_to_au(hb_pos.y_offset as int)))
}
fn should_get_glyph_codepoints() {

View file

@ -2,15 +2,15 @@ import geom::point::Point2D;
import geom::size::Size2D;
import gfx::geometry::{au, px_to_au};
import libc::{c_void};
import font::{font, create_test_font};
import glyph::glyph;
import font::{Font, create_test_font};
import glyph::Glyph;
import shaper::shape_text;
#[doc="A single, unbroken line of text."]
class text_run {
let glyphs: [glyph];
class TextRun {
let glyphs: [Glyph];
new(font: &font, text: str) {
new(font: &Font, text: str) {
self.glyphs = shape_text(font, text);
}
@ -32,7 +32,7 @@ fn should_calculate_the_total_size() {
#[ignore(reason = "random failures")];
let font = create_test_font();
let run = text_run(&font, "firecracker");
let run = TextRun(&font, "firecracker");
let expected = Size2D(px_to_au(84), px_to_au(20));
assert run.size() == expected;
}