mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Add display_item_text
This commit is contained in:
parent
756cc775b5
commit
96c44f9726
3 changed files with 68 additions and 14 deletions
|
@ -135,15 +135,18 @@ fn draw_display_list(
|
||||||
#debug["drawing %?", item];
|
#debug["drawing %?", item];
|
||||||
|
|
||||||
alt item.item_type {
|
alt item.item_type {
|
||||||
dl::display_item_solid_color(r, g, b) {
|
dl::display_item_solid_color(r, g, b) {
|
||||||
draw_solid_color(draw_target, item, r, g, b);
|
draw_solid_color(draw_target, item, r, g, b);
|
||||||
}
|
}
|
||||||
dl::display_item_image(image) {
|
dl::display_item_image(image) {
|
||||||
draw_image(draw_target, item, image);
|
draw_image(draw_target, item, image);
|
||||||
}
|
}
|
||||||
dl::padding(*) {
|
dl::display_item_text(text_run) {
|
||||||
fail "should never see padding";
|
// FIXME
|
||||||
}
|
}
|
||||||
|
dl::padding(*) {
|
||||||
|
fail "should never see padding";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +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;
|
||||||
|
|
||||||
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),
|
||||||
// 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,15 @@ export build_display_list;
|
||||||
|
|
||||||
import dl = display_list;
|
import dl = display_list;
|
||||||
import dom::rcu::Scope;
|
import dom::rcu::Scope;
|
||||||
|
import dom::base::{Text, NodeScope};
|
||||||
import gfx::geometry::{au, au_to_px, box, px_to_au};
|
import gfx::geometry::{au, au_to_px, box, px_to_au};
|
||||||
import gfx::renderer;
|
import gfx::renderer;
|
||||||
import layout::base::*;
|
import layout::base::*;
|
||||||
import util::color::methods;
|
import util::color::methods;
|
||||||
|
import util::tree;
|
||||||
|
import box_builder::box_builder_methods;
|
||||||
|
import text::text_layout_methods;
|
||||||
|
import geom::size::Size2D;
|
||||||
import geom::point::Point2D;
|
import geom::point::Point2D;
|
||||||
import geom::rect::Rect;
|
import geom::rect::Rect;
|
||||||
|
|
||||||
|
@ -63,21 +67,29 @@ fn box_to_display_item(box: @Box, origin: Point2D<au>) -> dl::display_item {
|
||||||
|
|
||||||
let bounds = Rect(origin, copy box.bounds.size);
|
let bounds = Rect(origin, copy box.bounds.size);
|
||||||
|
|
||||||
alt (box.appearance.background_image, box.appearance.background_color) {
|
alt (box.kind, box.appearance.background_image, box.appearance.background_color) {
|
||||||
(some(image), some(*)) | (some(image), none) {
|
(TextBox(subbox), _, _) {
|
||||||
|
let run = copy subbox.run;
|
||||||
|
assert run.is_some();
|
||||||
|
item = dl::display_item({
|
||||||
|
item_type: dl::display_item_text(run.get()),
|
||||||
|
bounds: bounds
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(_, some(image), some(*)) | (_, some(image), none) {
|
||||||
item = dl::display_item({
|
item = dl::display_item({
|
||||||
item_type: dl::display_item_image(~copy *image),
|
item_type: dl::display_item_image(~copy *image),
|
||||||
bounds: bounds
|
bounds: bounds
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
(none, some(col)) {
|
(_, none, some(col)) {
|
||||||
#debug("Assigning color %? to box with bounds %?", col, bounds);
|
#debug("Assigning color %? to box with bounds %?", col, bounds);
|
||||||
item = dl::display_item({
|
item = dl::display_item({
|
||||||
item_type: dl::display_item_solid_color(col.red, col.green, col.blue),
|
item_type: dl::display_item_solid_color(col.red, col.green, col.blue),
|
||||||
bounds: bounds
|
bounds: bounds
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
(none, none) {
|
(_, none, none) {
|
||||||
let r = rand::rng();
|
let r = rand::rng();
|
||||||
item = dl::display_item({
|
item = dl::display_item({
|
||||||
item_type: dl::display_item_solid_color(r.next() as u8,
|
item_type: dl::display_item_solid_color(r.next() as u8,
|
||||||
|
@ -91,3 +103,40 @@ fn box_to_display_item(box: @Box, origin: Point2D<au>) -> dl::display_item {
|
||||||
#debug("layout: display item: %?", item);
|
#debug("layout: display item: %?", item);
|
||||||
ret item;
|
ret item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn should_convert_text_boxes_to_text_items() {
|
||||||
|
#[test];
|
||||||
|
|
||||||
|
let s = Scope();
|
||||||
|
let n = s.new_node(Text("firecracker"));
|
||||||
|
let b = n.construct_boxes();
|
||||||
|
let subbox = alt check b.kind { TextBox(subbox) { subbox } };
|
||||||
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
|
let di = box_to_display_item(b, Point2D(px_to_au(0), px_to_au(0)));
|
||||||
|
|
||||||
|
alt di.item_type {
|
||||||
|
dl::display_item_text(_) { }
|
||||||
|
_ { fail }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_calculate_the_bounds_of_the_text_box() {
|
||||||
|
#[test];
|
||||||
|
|
||||||
|
let s = Scope();
|
||||||
|
let n = s.new_node(Text("firecracker"));
|
||||||
|
let b = n.construct_boxes();
|
||||||
|
let subbox = alt check b.kind { TextBox(subbox) { subbox } };
|
||||||
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
|
let di = box_to_display_item(b, Point2D(px_to_au(0), px_to_au(0)));
|
||||||
|
|
||||||
|
let expected = Rect(
|
||||||
|
Point2D(px_to_au(0), px_to_au(0)),
|
||||||
|
Size2D(px_to_au(110), px_to_au(14))
|
||||||
|
);
|
||||||
|
|
||||||
|
#error("%?", di.bounds);
|
||||||
|
#error("%?", expected);
|
||||||
|
|
||||||
|
assert di.bounds == expected;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue