Use cleaner StrokeOptions interface introduced by https://github.com/servo/rust-azure/pull/145.

This commit is contained in:
Andreas Gal 2015-02-20 01:45:54 -08:00
parent 49ff6b2ccc
commit ad5671bc14
5 changed files with 18 additions and 23 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use azure::azure_hl::{DrawTarget, SurfaceFormat, BackendType, StrokeOptions, DrawOptions}; use azure::azure_hl::{DrawTarget, SurfaceFormat, BackendType, StrokeOptions, DrawOptions};
use azure::azure_hl::{ColorPattern, PatternRef}; use azure::azure_hl::{ColorPattern, PatternRef, JoinStyle, CapStyle};
use geom::rect::Rect; use geom::rect::Rect;
use geom::size::Size2D; use geom::size::Size2D;
use gfx::color; use gfx::color;
@ -22,20 +22,20 @@ pub enum CanvasMsg {
Close, Close,
} }
pub struct CanvasPaintTask { pub struct CanvasPaintTask<'a> {
drawtarget: DrawTarget, drawtarget: DrawTarget,
fill_color: ColorPattern, fill_color: ColorPattern,
stroke_color: ColorPattern, stroke_color: ColorPattern,
stroke_opts: StrokeOptions, stroke_opts: StrokeOptions<'a>,
} }
impl CanvasPaintTask { impl<'a> CanvasPaintTask<'a> {
fn new(size: Size2D<i32>) -> CanvasPaintTask { fn new(size: Size2D<i32>) -> CanvasPaintTask<'a> {
CanvasPaintTask { CanvasPaintTask {
drawtarget: CanvasPaintTask::create(size), drawtarget: CanvasPaintTask::create(size),
fill_color: ColorPattern::new(color::black()), fill_color: ColorPattern::new(color::black()),
stroke_color: ColorPattern::new(color::black()), stroke_color: ColorPattern::new(color::black()),
stroke_opts: StrokeOptions::new(1.0, 1.0), stroke_opts: StrokeOptions::new(1.0, JoinStyle::MiterOrBevel, CapStyle::Butt, 1.0, &[]),
} }
} }

View file

@ -10,8 +10,9 @@ use azure::azure_hl::{DrawOptions, DrawSurfaceOptions, DrawTarget, ExtendMode, F
use azure::azure_hl::{GaussianBlurInput, GradientStop, Filter, LinearGradientPattern}; use azure::azure_hl::{GaussianBlurInput, GradientStop, Filter, LinearGradientPattern};
use azure::azure_hl::{PatternRef, Path, PathBuilder, CompositionOp}; use azure::azure_hl::{PatternRef, Path, PathBuilder, CompositionOp};
use azure::azure_hl::{GaussianBlurAttribute, StrokeOptions, SurfaceFormat}; use azure::azure_hl::{GaussianBlurAttribute, StrokeOptions, SurfaceFormat};
use azure::azure_hl::{JoinStyle, CapStyle};
use azure::scaled_font::ScaledFont; use azure::scaled_font::ScaledFont;
use azure::{AZ_CAP_BUTT, AzFloat, struct__AzDrawOptions, struct__AzGlyph}; use azure::{AzFloat, struct__AzDrawOptions, struct__AzGlyph};
use azure::{struct__AzGlyphBuffer, struct__AzPoint, AzDrawTargetFillGlyphs}; use azure::{struct__AzGlyphBuffer, struct__AzPoint, AzDrawTargetFillGlyphs};
use color; use color;
use display_list::TextOrientation::{SidewaysLeft, SidewaysRight, Upright}; use display_list::TextOrientation::{SidewaysLeft, SidewaysRight, Upright};
@ -23,7 +24,6 @@ use geom::point::Point2D;
use geom::rect::Rect; use geom::rect::Rect;
use geom::side_offsets::SideOffsets2D; use geom::side_offsets::SideOffsets2D;
use geom::size::Size2D; use geom::size::Size2D;
use libc::size_t;
use libc::types::common::c99::{uint16_t, uint32_t}; use libc::types::common::c99::{uint16_t, uint32_t};
use png::PixelsByColorType; use png::PixelsByColorType;
use net::image::base::Image; use net::image::base::Image;
@ -608,24 +608,19 @@ impl<'a> PaintContext<'a> {
dash_size: DashSize) { dash_size: DashSize) {
let rect = bounds.to_azure_rect(); let rect = bounds.to_azure_rect();
let draw_opts = DrawOptions::new(1u as AzFloat, 0 as uint16_t); let draw_opts = DrawOptions::new(1u as AzFloat, 0 as uint16_t);
let mut stroke_opts = StrokeOptions::new(0u as AzFloat, 10u as AzFloat);
let mut dash: [AzFloat; 2] = [0u as AzFloat, 0u as AzFloat];
stroke_opts.set_cap_style(AZ_CAP_BUTT as u8);
let border_width = match direction { let border_width = match direction {
Direction::Top => border.top, Direction::Top => border.top,
Direction::Left => border.left, Direction::Left => border.left,
Direction::Right => border.right, Direction::Right => border.right,
Direction::Bottom => border.bottom Direction::Bottom => border.bottom
}; };
let dash_pattern = [border_width * (dash_size as int) as AzFloat,
stroke_opts.line_width = border_width; border_width * (dash_size as int) as AzFloat];
dash[0] = border_width * (dash_size as int) as AzFloat; let stroke_opts = StrokeOptions::new(border_width as AzFloat,
dash[1] = border_width * (dash_size as int) as AzFloat; JoinStyle::MiterOrBevel,
stroke_opts.mDashPattern = dash.as_mut_ptr(); CapStyle::Butt,
stroke_opts.mDashLength = dash.len() as size_t; 10u as AzFloat,
&dash_pattern);
let (start, end) = match direction { let (start, end) = match direction {
Direction::Top => { Direction::Top => {
let y = rect.origin.y + border.top * 0.5; let y = rect.origin.y + border.top * 0.5;

View file

@ -36,7 +36,7 @@ dependencies = [
[[package]] [[package]]
name = "azure" name = "azure"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-azure#ec5fddfe96f889e35cc83abd2255f8325f2ec147" source = "git+https://github.com/servo/rust-azure#2c60291733afe631eba90105e9ac9c8847e89cac"
dependencies = [ dependencies = [
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",

2
ports/cef/Cargo.lock generated
View file

@ -39,7 +39,7 @@ dependencies = [
[[package]] [[package]]
name = "azure" name = "azure"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-azure#ec5fddfe96f889e35cc83abd2255f8325f2ec147" source = "git+https://github.com/servo/rust-azure#2c60291733afe631eba90105e9ac9c8847e89cac"
dependencies = [ dependencies = [
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",

2
ports/gonk/Cargo.lock generated
View file

@ -18,7 +18,7 @@ dependencies = [
[[package]] [[package]]
name = "azure" name = "azure"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-azure#ec5fddfe96f889e35cc83abd2255f8325f2ec147" source = "git+https://github.com/servo/rust-azure#2c60291733afe631eba90105e9ac9c8847e89cac"
dependencies = [ dependencies = [
"core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)", "core_foundation 0.1.0 (git+https://github.com/servo/rust-core-foundation)",
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)", "core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",