aboutsummaryrefslogtreecommitdiffstats
path: root/components/canvas/canvas_data.rs
diff options
context:
space:
mode:
authorpylbrecht <palbrecht@mailbox.org>2019-05-18 08:43:58 +0200
committerJosh Matthews <josh@joshmatthews.net>2019-05-31 15:55:18 -0400
commit3182eba73be84dc18e460055a8cddea47f8be752 (patch)
treefb21174d8011e547c2e94a7389df0111a6c813ea /components/canvas/canvas_data.rs
parent7c6460443c773e3f0ce8d3135c729d4eb9e81829 (diff)
downloadservo-3182eba73be84dc18e460055a8cddea47f8be752.tar.gz
servo-3182eba73be84dc18e460055a8cddea47f8be752.zip
Implement GenericPathBuilder for azure_hl::PathBuilder
Diffstat (limited to 'components/canvas/canvas_data.rs')
-rw-r--r--components/canvas/canvas_data.rs106
1 files changed, 105 insertions, 1 deletions
diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs
index b33855b9038..6507f17589d 100644
--- a/components/canvas/canvas_data.rs
+++ b/components/canvas/canvas_data.rs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use azure::azure::{AzFloat, AzGradientStop, AzIntSize};
+use azure::azure::{AzFloat, AzGradientStop, AzIntSize, AzPoint};
use azure::azure_hl;
use azure::azure_hl::SurfacePattern;
use azure::azure_hl::{AntialiasMode, AsAzurePoint, CapStyle, JoinStyle};
@@ -57,6 +57,110 @@ impl PathState {
}
}
+/// A generic PathBuilder that abstracts the interface for
+/// azure's and raqote's PathBuilder.
+trait GenericPathBuilder {
+ fn arc(
+ &self,
+ origin: Point2D<f32>,
+ radius: f32,
+ start_angle: f32,
+ end_angle: f32,
+ anticlockwise: bool,
+ );
+ fn bezier_curve_to(
+ &self,
+ control_point1: &Point2D<f32>,
+ control_point2: &Point2D<f32>,
+ control_point3: &Point2D<f32>,
+ );
+ fn close(&self);
+ fn ellipse(
+ &self,
+ origin: Point2D<f32>,
+ radius_x: f32,
+ radius_y: f32,
+ rotation_angle: f32,
+ start_angle: f32,
+ end_angle: f32,
+ anticlockwise: bool,
+ );
+ fn get_current_point(&self) -> Point2D<f32>;
+ fn line_to(&self, point: Point2D<f32>);
+ fn move_to(&self, point: Point2D<f32>);
+ fn quadratic_curve_to(&self, control_point: &Point2D<f32>, end_point: &Point2D<f32>);
+}
+
+impl GenericPathBuilder for azure_hl::PathBuilder {
+ fn arc(
+ &self,
+ origin: Point2D<f32>,
+ radius: f32,
+ start_angle: f32,
+ end_angle: f32,
+ anticlockwise: bool,
+ ) {
+ self.arc(
+ origin as Point2D<AzFloat>,
+ radius as AzFloat,
+ start_angle as AzFloat,
+ end_angle as AzFloat,
+ anticlockwise,
+ );
+ }
+ fn bezier_curve_to(
+ &self,
+ control_point1: &Point2D<f32>,
+ control_point2: &Point2D<f32>,
+ control_point3: &Point2D<f32>,
+ ) {
+ self.bezier_curve_to(
+ control_point1 as &Point2D<AzFloat>,
+ control_point2 as &Point2D<AzFloat>,
+ control_point3 as &Point2D<AzFloat>,
+ );
+ }
+ fn close(&self) {
+ self.close();
+ }
+ fn ellipse(
+ &self,
+ origin: Point2D<f32>,
+ radius_x: f32,
+ radius_y: f32,
+ rotation_angle: f32,
+ start_angle: f32,
+ end_angle: f32,
+ anticlockwise: bool,
+ ) {
+ self.ellipse(
+ origin as Point2D<AzFloat>,
+ radius_x as AzFloat,
+ radius_y as AzFloat,
+ rotation_angle as AzFloat,
+ start_angle as AzFloat,
+ end_angle as AzFloat,
+ anticlockwise,
+ );
+ }
+ fn get_current_point(&self) -> Point2D<f32> {
+ let AzPoint { x, y } = self.get_current_point();
+ Point2D::new(x as f32, y as f32)
+ }
+ fn line_to(&self, point: Point2D<f32>) {
+ self.line_to(point as Point2D<AzFloat>);
+ }
+ fn move_to(&self, point: Point2D<f32>) {
+ self.move_to(point as Point2D<AzFloat>);
+ }
+ fn quadratic_curve_to(&self, control_point: &Point2D<f32>, end_point: &Point2D<f32>) {
+ self.quadratic_curve_to(
+ control_point as &Point2D<AzFloat>,
+ end_point as &Point2D<AzFloat>,
+ );
+ }
+}
+
/// A wrapper around a stored PathBuilder and an optional transformation that should be
/// applied to any points to ensure they are in the matching device space.
struct PathBuilderRef<'a> {