mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
auto merge of #1709 : sankha93/servo/issue221, r=larsbergstrom
This fixes #221. I used the `BaseDisplayItem` class to define rectangle in which the line will be drawn. The width of the rectangle will be used as the thickness of the line segment.
This commit is contained in:
commit
061269f963
3 changed files with 55 additions and 8 deletions
|
@ -127,6 +127,7 @@ pub enum DisplayItem<E> {
|
||||||
TextDisplayItemClass(~TextDisplayItem<E>),
|
TextDisplayItemClass(~TextDisplayItem<E>),
|
||||||
ImageDisplayItemClass(~ImageDisplayItem<E>),
|
ImageDisplayItemClass(~ImageDisplayItem<E>),
|
||||||
BorderDisplayItemClass(~BorderDisplayItem<E>),
|
BorderDisplayItemClass(~BorderDisplayItem<E>),
|
||||||
|
LineDisplayItemClass(~LineDisplayItem<E>),
|
||||||
ClipDisplayItemClass(~ClipDisplayItem<E>)
|
ClipDisplayItemClass(~ClipDisplayItem<E>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +207,17 @@ pub struct BorderDisplayItem<E> {
|
||||||
style: SideOffsets2D<border_style::T>
|
style: SideOffsets2D<border_style::T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Renders a line segment
|
||||||
|
pub struct LineDisplayItem<E> {
|
||||||
|
base: BaseDisplayItem<E>,
|
||||||
|
|
||||||
|
/// The line segment color.
|
||||||
|
color: Color,
|
||||||
|
|
||||||
|
/// The line segemnt style.
|
||||||
|
style: border_style::T
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ClipDisplayItem<E> {
|
pub struct ClipDisplayItem<E> {
|
||||||
base: BaseDisplayItem<E>,
|
base: BaseDisplayItem<E>,
|
||||||
child_list: ~[DisplayItem<E>],
|
child_list: ~[DisplayItem<E>],
|
||||||
|
@ -303,6 +315,12 @@ impl<E> DisplayItem<E> {
|
||||||
border.color,
|
border.color,
|
||||||
border.style)
|
border.style)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LineDisplayItemClass(ref line) => {
|
||||||
|
render_context.draw_line(&line.base.bounds,
|
||||||
|
line.color,
|
||||||
|
line.style)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,6 +332,7 @@ impl<E> DisplayItem<E> {
|
||||||
TextDisplayItemClass(ref text) => transmute_region(&text.base),
|
TextDisplayItemClass(ref text) => transmute_region(&text.base),
|
||||||
ImageDisplayItemClass(ref image_item) => transmute_region(&image_item.base),
|
ImageDisplayItemClass(ref image_item) => transmute_region(&image_item.base),
|
||||||
BorderDisplayItemClass(ref border) => transmute_region(&border.base),
|
BorderDisplayItemClass(ref border) => transmute_region(&border.base),
|
||||||
|
LineDisplayItemClass(ref line) => transmute_region(&line.base),
|
||||||
ClipDisplayItemClass(ref clip) => transmute_region(&clip.base),
|
ClipDisplayItemClass(ref clip) => transmute_region(&clip.base),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +348,8 @@ impl<E> DisplayItem<E> {
|
||||||
SolidColorDisplayItemClass(..) |
|
SolidColorDisplayItemClass(..) |
|
||||||
TextDisplayItemClass(..) |
|
TextDisplayItemClass(..) |
|
||||||
ImageDisplayItemClass(..) |
|
ImageDisplayItemClass(..) |
|
||||||
BorderDisplayItemClass(..) => EmptyDisplayItemIterator,
|
BorderDisplayItemClass(..) |
|
||||||
|
LineDisplayItemClass(..) => EmptyDisplayItemIterator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,6 +370,7 @@ impl<E> DisplayItem<E> {
|
||||||
TextDisplayItemClass(_) => "Text",
|
TextDisplayItemClass(_) => "Text",
|
||||||
ImageDisplayItemClass(_) => "Image",
|
ImageDisplayItemClass(_) => "Image",
|
||||||
BorderDisplayItemClass(_) => "Border",
|
BorderDisplayItemClass(_) => "Border",
|
||||||
|
LineDisplayItemClass(_) => "Line",
|
||||||
ClipDisplayItemClass(_) => "Clip",
|
ClipDisplayItemClass(_) => "Clip",
|
||||||
};
|
};
|
||||||
format!("{} @ {:?}", class, self.base().bounds)
|
format!("{} @ {:?}", class, self.base().bounds)
|
||||||
|
|
|
@ -62,6 +62,15 @@ impl<'a> RenderContext<'a> {
|
||||||
self.draw_border_segment(Left, bounds, border, color, style);
|
self.draw_border_segment(Left, bounds, border, color, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw_line(&self,
|
||||||
|
bounds: &Rect<Au>,
|
||||||
|
color: Color,
|
||||||
|
style: border_style::T) {
|
||||||
|
self.draw_target.make_current();
|
||||||
|
|
||||||
|
self.draw_line_segment(bounds, color, style);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn draw_push_clip(&self, bounds: &Rect<Au>) {
|
pub fn draw_push_clip(&self, bounds: &Rect<Au>) {
|
||||||
let rect = bounds.to_azure_rect();
|
let rect = bounds.to_azure_rect();
|
||||||
let path_builder = self.draw_target.create_path_builder();
|
let path_builder = self.draw_target.create_path_builder();
|
||||||
|
@ -148,6 +157,25 @@ impl<'a> RenderContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_line_segment(&self, bounds: &Rect<Au>, color: Color, style: border_style::T) {
|
||||||
|
let border = SideOffsets2D::new_all_same(bounds.size.width).to_float_px();
|
||||||
|
|
||||||
|
match style{
|
||||||
|
border_style::none | border_style::hidden => {}
|
||||||
|
border_style::dotted => {
|
||||||
|
//FIXME(sankha93): Dotted style should be implemented.
|
||||||
|
}
|
||||||
|
border_style::dashed => {
|
||||||
|
self.draw_dashed_border_segment(Right,bounds,border,color);
|
||||||
|
}
|
||||||
|
border_style::solid => {
|
||||||
|
self.draw_solid_border_segment(Right,bounds,border,color);
|
||||||
|
}
|
||||||
|
//FIXME(sankha93): Five more styles should be implemented.
|
||||||
|
//double, groove, ridge, inset, outset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_dashed_border_segment(&self, direction: Direction, bounds: &Rect<Au>, border: SideOffsets2D<f32>, color: Color) {
|
fn draw_dashed_border_segment(&self, direction: Direction, bounds: &Rect<Au>, border: SideOffsets2D<f32>, color: Color) {
|
||||||
let rect = bounds.to_azure_rect();
|
let rect = bounds.to_azure_rect();
|
||||||
let draw_opts = DrawOptions(1 as AzFloat, 0 as uint16_t);
|
let draw_opts = DrawOptions(1 as AzFloat, 0 as uint16_t);
|
||||||
|
|
|
@ -9,6 +9,7 @@ use extra::arc::{MutexArc, Arc};
|
||||||
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
|
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
|
||||||
use gfx::color::rgb;
|
use gfx::color::rgb;
|
||||||
use gfx::display_list::{BaseDisplayItem, BorderDisplayItem, BorderDisplayItemClass};
|
use gfx::display_list::{BaseDisplayItem, BorderDisplayItem, BorderDisplayItemClass};
|
||||||
|
use gfx::display_list::{LineDisplayItem, LineDisplayItemClass};
|
||||||
use gfx::display_list::{ImageDisplayItem, ImageDisplayItemClass};
|
use gfx::display_list::{ImageDisplayItem, ImageDisplayItemClass};
|
||||||
use gfx::display_list::{SolidColorDisplayItem, SolidColorDisplayItemClass, TextDisplayItem};
|
use gfx::display_list::{SolidColorDisplayItem, SolidColorDisplayItemClass, TextDisplayItem};
|
||||||
use gfx::display_list::{TextDisplayItemClass, TextDisplayItemFlags, ClipDisplayItem};
|
use gfx::display_list::{TextDisplayItemClass, TextDisplayItemFlags, ClipDisplayItem};
|
||||||
|
@ -1086,25 +1087,22 @@ impl Box {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Draw a rectangle representing the baselines.
|
// Draw a rectangle representing the baselines.
|
||||||
//
|
|
||||||
// TODO(Issue #221): Create and use a Line display item for the baseline.
|
|
||||||
let ascent = text_box.run.get().metrics_for_range(
|
let ascent = text_box.run.get().metrics_for_range(
|
||||||
&text_box.range).ascent;
|
&text_box.range).ascent;
|
||||||
let baseline = Rect(absolute_box_bounds.origin + Point2D(Au(0), ascent),
|
let baseline = Rect(absolute_box_bounds.origin + Point2D(Au(0), ascent),
|
||||||
Size2D(absolute_box_bounds.size.width, Au(0)));
|
Size2D(absolute_box_bounds.size.width, Au(0)));
|
||||||
|
|
||||||
lists.with_mut(|lists| {
|
lists.with_mut(|lists| {
|
||||||
let border_display_item = ~BorderDisplayItem {
|
let line_display_item = ~LineDisplayItem {
|
||||||
base: BaseDisplayItem {
|
base: BaseDisplayItem {
|
||||||
bounds: baseline,
|
bounds: baseline,
|
||||||
extra: ExtraDisplayListData::new(self),
|
extra: ExtraDisplayListData::new(self),
|
||||||
},
|
},
|
||||||
border: debug_border,
|
color: rgb(0, 200, 0),
|
||||||
color: SideOffsets2D::new_all_same(rgb(0, 200, 0)),
|
style: border_style::dashed
|
||||||
style: SideOffsets2D::new_all_same(border_style::dashed)
|
|
||||||
|
|
||||||
};
|
};
|
||||||
lists.lists[index].append_item(BorderDisplayItemClass(border_display_item));
|
lists.lists[index].append_item(LineDisplayItemClass(line_display_item));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue