mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Give DisplayList its own GlyphRun type
This commit is contained in:
parent
4bb240ac79
commit
c079d337f3
3 changed files with 29 additions and 13 deletions
|
@ -1,12 +1,12 @@
|
||||||
use azure::azure_hl::DrawTarget;
|
use azure::azure_hl::DrawTarget;
|
||||||
use gfx::render_task::{draw_solid_color, draw_image, draw_text};
|
use gfx::render_task::{draw_solid_color, draw_image, draw_glyphs};
|
||||||
use gfx::geometry::*;
|
use gfx::geometry::*;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use image::base::Image;
|
use image::base::Image;
|
||||||
use servo_text::text_run::TextRun;
|
|
||||||
|
|
||||||
use std::arc::{ARC, clone};
|
use std::arc::{ARC, clone};
|
||||||
use dvec::DVec;
|
use dvec::DVec;
|
||||||
|
use text::glyph::Glyph;
|
||||||
|
|
||||||
struct DisplayItem {
|
struct DisplayItem {
|
||||||
draw: ~fn((&DisplayItem), (&DrawTarget)),
|
draw: ~fn((&DisplayItem), (&DrawTarget)),
|
||||||
|
@ -16,11 +16,20 @@ struct DisplayItem {
|
||||||
|
|
||||||
enum DisplayItemData {
|
enum DisplayItemData {
|
||||||
SolidColorData(u8, u8, u8),
|
SolidColorData(u8, u8, u8),
|
||||||
TextData(TextRun),
|
GlyphData(GlyphRun),
|
||||||
ImageData(ARC<~image::base::Image>),
|
ImageData(ARC<~image::base::Image>),
|
||||||
PaddingData(u8, u8, u8, u8) // This is a hack to make fonts work (?)
|
PaddingData(u8, u8, u8, u8) // This is a hack to make fonts work (?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
A run of glyphs in a single font. This is distinguished from any similar
|
||||||
|
structure used by layout in that this must be sendable, whereas the text
|
||||||
|
shaping data structures may end up unsendable.
|
||||||
|
*/
|
||||||
|
struct GlyphRun {
|
||||||
|
glyphs: ~[Glyph]
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_SolidColor(self: &DisplayItem, ctx: &DrawTarget) {
|
fn draw_SolidColor(self: &DisplayItem, ctx: &DrawTarget) {
|
||||||
match self.data {
|
match self.data {
|
||||||
SolidColorData(r,g,b) => draw_solid_color(ctx, &self.bounds, r, g, b),
|
SolidColorData(r,g,b) => draw_solid_color(ctx, &self.bounds, r, g, b),
|
||||||
|
@ -28,9 +37,9 @@ fn draw_SolidColor(self: &DisplayItem, ctx: &DrawTarget) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_Text(self: &DisplayItem, ctx: &DrawTarget) {
|
fn draw_Glyphs(self: &DisplayItem, ctx: &DrawTarget) {
|
||||||
match self.data {
|
match self.data {
|
||||||
TextData(run) => draw_text(ctx, self.bounds, &run),
|
GlyphData(run) => draw_glyphs(ctx, self.bounds, &run),
|
||||||
_ => fail
|
_ => fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,11 +60,11 @@ fn SolidColor(bounds: Rect<au>, r: u8, g: u8, b: u8) -> DisplayItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Text(bounds: Rect<au>, run: TextRun) -> DisplayItem {
|
fn Glyphs(bounds: Rect<au>, run: GlyphRun) -> DisplayItem {
|
||||||
DisplayItem {
|
DisplayItem {
|
||||||
draw: |self, ctx| draw_Text(self, ctx),
|
draw: |self, ctx| draw_Glyphs(self, ctx),
|
||||||
bounds: bounds,
|
bounds: bounds,
|
||||||
data: TextData(run)
|
data: GlyphData(run)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use azure::*;
|
||||||
use azure::bindgen::*;
|
use azure::bindgen::*;
|
||||||
use libc::size_t;
|
use libc::size_t;
|
||||||
use text::font::Font;
|
use text::font::Font;
|
||||||
use text::text_run::TextRun;
|
use display_list::GlyphRun;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use geom::rect::Rect;
|
use geom::rect::Rect;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
|
@ -118,7 +118,7 @@ pub fn draw_image(draw_target: &DrawTarget, bounds: Rect<au>, image: ARC<~Image>
|
||||||
draw_options);
|
draw_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_text(draw_target: &DrawTarget, bounds: Rect<au>, text_run: &TextRun) {
|
pub fn draw_glyphs(draw_target: &DrawTarget, bounds: Rect<au>, text_run: &GlyphRun) {
|
||||||
use ptr::{addr_of, null};
|
use ptr::{addr_of, null};
|
||||||
use vec::raw::to_ptr;
|
use vec::raw::to_ptr;
|
||||||
use libc::types::common::c99::{uint16_t, uint32_t};
|
use libc::types::common::c99::{uint16_t, uint32_t};
|
||||||
|
|
|
@ -11,7 +11,7 @@ use geom::rect::Rect;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use gfx::geometry::{au, au_to_px, box, px_to_au};
|
use gfx::geometry::{au, au_to_px, box, px_to_au};
|
||||||
use util::tree;
|
use util::tree;
|
||||||
|
use servo_text::text_run::TextRun;
|
||||||
use dvec::DVec;
|
use dvec::DVec;
|
||||||
use vec::push;
|
use vec::push;
|
||||||
|
|
||||||
|
@ -87,8 +87,15 @@ fn box_to_display_items(list: dl::DisplayList, box: @Box, origin: Point2D<au>) {
|
||||||
let run = copy subbox.run;
|
let run = copy subbox.run;
|
||||||
assert run.is_some();
|
assert run.is_some();
|
||||||
list.push(~dl::SolidColor(bounds, 255u8, 255u8, 255u8));
|
list.push(~dl::SolidColor(bounds, 255u8, 255u8, 255u8));
|
||||||
list.push(~dl::Text(bounds, run.get()));
|
let glyph_run = text_run_to_dl_glyph_run(run.get_ref());
|
||||||
|
list.push(~dl::Glyphs(bounds, glyph_run));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
fn text_run_to_dl_glyph_run(text_run: &TextRun) -> dl::GlyphRun {
|
||||||
|
dl::GlyphRun {
|
||||||
|
glyphs: copy text_run.glyphs
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Fall through
|
// Fall through
|
||||||
|
@ -156,7 +163,7 @@ fn should_convert_text_boxes_to_text_items() {
|
||||||
|
|
||||||
do list.borrow |l| {
|
do list.borrow |l| {
|
||||||
match l[1].data {
|
match l[1].data {
|
||||||
dl::TextData(_) => { }
|
dl::GlyphData(_) => { }
|
||||||
_ => { fail }
|
_ => { fail }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue