mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Camel-case text types
This commit is contained in:
parent
ce615bf12a
commit
5f8493e3a9
7 changed files with 33 additions and 34 deletions
|
@ -6,7 +6,7 @@ import dl = layout::display_list;
|
||||||
import azure::*;
|
import azure::*;
|
||||||
import azure::bindgen::*;
|
import azure::bindgen::*;
|
||||||
import libc::size_t;
|
import libc::size_t;
|
||||||
import text::text_run::text_run;
|
import text::text_run::TextRun;
|
||||||
|
|
||||||
enum Msg {
|
enum Msg {
|
||||||
RenderMsg(dl::display_list),
|
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 ptr::{addr_of, null};
|
||||||
import vec::unsafe::to_ptr;
|
import vec::unsafe::to_ptr;
|
||||||
import libc::types::common::c99::{uint16_t, uint32_t};
|
import libc::types::common::c99::{uint16_t, uint32_t};
|
||||||
import geom::point::Point2D;
|
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::{AzNativeFont, AzFloat, AZ_NATIVE_FONT_CAIRO_FONT_FACE};
|
||||||
import azure::bindgen::{AzCreateScaledFontWithCairo,
|
import azure::bindgen::{AzCreateScaledFontWithCairo,
|
||||||
AzReleaseScaledFont,
|
AzReleaseScaledFont,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import gfx::geometry::*;
|
import gfx::geometry::*;
|
||||||
import geom::rect::Rect;
|
import geom::rect::Rect;
|
||||||
import image::base::image;
|
import image::base::image;
|
||||||
import servo_text::text_run::text_run;
|
import servo_text::text_run::TextRun;
|
||||||
|
|
||||||
enum item_type {
|
enum item_type {
|
||||||
display_item_solid_color(u8, u8, u8),
|
display_item_solid_color(u8, u8, u8),
|
||||||
display_item_image(~image),
|
display_item_image(~image),
|
||||||
display_item_text(text_run),
|
display_item_text(TextRun),
|
||||||
// FIXME: Shape code does not understand the alignment without this
|
// FIXME: Shape code does not understand the alignment without this
|
||||||
padding(u8, u8, u8, u8)
|
padding(u8, u8, u8, u8)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
import geom::size::Size2D;
|
import geom::size::Size2D;
|
||||||
import gfx::geometry::au;
|
import gfx::geometry::au;
|
||||||
import layout::base::*; // FIXME: Can't get around import *; resolve bug.
|
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;
|
import servo_text::font::create_test_font;
|
||||||
|
|
||||||
class text_box {
|
class text_box {
|
||||||
let text: str;
|
let text: str;
|
||||||
let mut run: option<text_run>;
|
let mut run: option<TextRun>;
|
||||||
|
|
||||||
new(-text: str) {
|
new(-text: str) {
|
||||||
self.text = text;
|
self.text = text;
|
||||||
|
@ -25,7 +25,7 @@ impl text_layout_methods for @Box {
|
||||||
};
|
};
|
||||||
|
|
||||||
let font = create_test_font();
|
let font = create_test_font();
|
||||||
let run = text_run(&font, subbox.text);
|
let run = TextRun(&font, subbox.text);
|
||||||
self.bounds.size = run.size();
|
self.bounds.size = run.size();
|
||||||
subbox.run = some(run);
|
subbox.run = some(run);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 vec_to_ptr = vec::unsafe::to_ptr;
|
||||||
import libc::{ c_int, c_double, c_ulong };
|
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.
|
and the renderer can use it to render text.
|
||||||
"]
|
"]
|
||||||
#[warn(no_non_implicitly_copyable_typarams)]
|
#[warn(no_non_implicitly_copyable_typarams)]
|
||||||
class font/& {
|
class Font/& {
|
||||||
let fontbuf: [u8];
|
let fontbuf: [u8];
|
||||||
let cairo_font: *cairo_scaled_font_t;
|
let cairo_font: *cairo_scaled_font_t;
|
||||||
let font_dtor: fn@();
|
let font_dtor: fn@();
|
||||||
|
@ -260,8 +260,8 @@ fn get_cairo_face(buf: &[u8]) -> (*cairo_font_face_t, fn@()) {
|
||||||
(cface, dtor)
|
(cface, dtor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_test_font() -> font {
|
fn create_test_font() -> Font {
|
||||||
font(test_font_bin())
|
Font(test_font_bin())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_font_bin() -> [u8] { #include_bin("JosefinSans-SemiBold.ttf") }
|
fn test_font_bin() -> [u8] { #include_bin("JosefinSans-SemiBold.ttf") }
|
||||||
|
|
|
@ -2,7 +2,7 @@ import gfx::geometry::au;
|
||||||
import geom::point::Point2D;
|
import geom::point::Point2D;
|
||||||
|
|
||||||
#[doc="The position of a glyph on the screen."]
|
#[doc="The position of a glyph on the screen."]
|
||||||
class glyph_pos {
|
class GlyphPos {
|
||||||
let advance: Point2D<au>;
|
let advance: Point2D<au>;
|
||||||
let offset: Point2D<au>;
|
let offset: Point2D<au>;
|
||||||
new(advance: Point2D<au>, offset: Point2D<au>) {
|
new(advance: Point2D<au>, offset: Point2D<au>) {
|
||||||
|
@ -12,13 +12,12 @@ class glyph_pos {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc="A single glyph."]
|
#[doc="A single glyph."]
|
||||||
class glyph {
|
class Glyph {
|
||||||
let codepoint: uint;
|
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.codepoint = codepoint;
|
||||||
self.pos = copy pos;
|
self.pos = copy pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ export shape_text;
|
||||||
|
|
||||||
import libc::types::common::c99::int32_t;
|
import libc::types::common::c99::int32_t;
|
||||||
import libc::{c_uint, c_int, c_void};
|
import libc::{c_uint, c_int, c_void};
|
||||||
import font::font;
|
import font::Font;
|
||||||
import glyph::{glyph, glyph_pos};
|
import glyph::{Glyph, GlyphPos};
|
||||||
import ptr::{null, addr_of, offset};
|
import ptr::{null, addr_of, offset};
|
||||||
import gfx::geometry::{au, px_to_au};
|
import gfx::geometry::{au, px_to_au};
|
||||||
import geom::point::Point2D;
|
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
|
Calculate the layout metrics associated with a some given text
|
||||||
when rendered in a specific font.
|
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);
|
#debug("shaping text '%s'", text);
|
||||||
|
|
||||||
let face_blob = vec::as_buf(*(*font).buf()) { |buf|
|
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 %?",
|
#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);
|
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);
|
hb_buffer_destroy(buffer);
|
||||||
|
@ -108,7 +108,7 @@ crust fn glyph_func(_font: *hb_font_t,
|
||||||
glyph: *mut hb_codepoint_t,
|
glyph: *mut hb_codepoint_t,
|
||||||
_user_data: *c_void) -> hb_bool_t unsafe {
|
_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();
|
assert font.is_not_null();
|
||||||
|
|
||||||
ret alt (*font).glyph_idx(unicode as char) {
|
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,
|
font_data: *c_void,
|
||||||
glyph: hb_codepoint_t,
|
glyph: hb_codepoint_t,
|
||||||
_user_data: *c_void) -> hb_position_t unsafe {
|
_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();
|
assert font.is_not_null();
|
||||||
|
|
||||||
let h_advance = (*font).glyph_h_advance(glyph as uint);
|
let h_advance = (*font).glyph_h_advance(glyph as uint);
|
||||||
|
@ -134,8 +134,8 @@ crust fn glyph_h_advance_func(_font: *hb_font_t,
|
||||||
ret h_advance as hb_position_t;
|
ret h_advance as hb_position_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> glyph_pos {
|
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> GlyphPos {
|
||||||
glyph_pos(Point2D(px_to_au(hb_pos.x_advance as int),
|
GlyphPos(Point2D(px_to_au(hb_pos.x_advance as int),
|
||||||
px_to_au(hb_pos.y_advance as int)),
|
px_to_au(hb_pos.y_advance as int)),
|
||||||
Point2D(px_to_au(hb_pos.x_offset as int),
|
Point2D(px_to_au(hb_pos.x_offset as int),
|
||||||
px_to_au(hb_pos.y_offset as int)))
|
px_to_au(hb_pos.y_offset as int)))
|
||||||
|
|
|
@ -2,15 +2,15 @@ import geom::point::Point2D;
|
||||||
import geom::size::Size2D;
|
import geom::size::Size2D;
|
||||||
import gfx::geometry::{au, px_to_au};
|
import gfx::geometry::{au, px_to_au};
|
||||||
import libc::{c_void};
|
import libc::{c_void};
|
||||||
import font::{font, create_test_font};
|
import font::{Font, create_test_font};
|
||||||
import glyph::glyph;
|
import glyph::Glyph;
|
||||||
import shaper::shape_text;
|
import shaper::shape_text;
|
||||||
|
|
||||||
#[doc="A single, unbroken line of text."]
|
#[doc="A single, unbroken line of text."]
|
||||||
class text_run {
|
class TextRun {
|
||||||
let glyphs: [glyph];
|
let glyphs: [Glyph];
|
||||||
|
|
||||||
new(font: &font, text: str) {
|
new(font: &Font, text: str) {
|
||||||
self.glyphs = shape_text(font, text);
|
self.glyphs = shape_text(font, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ fn should_calculate_the_total_size() {
|
||||||
#[ignore(reason = "random failures")];
|
#[ignore(reason = "random failures")];
|
||||||
|
|
||||||
let font = create_test_font();
|
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));
|
let expected = Size2D(px_to_au(84), px_to_au(20));
|
||||||
assert run.size() == expected;
|
assert run.size() == expected;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue