[librsvg: 8/12] shapes.rs: Move the common draw() code to a trait Shape
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 8/12] shapes.rs: Move the common draw() code to a trait Shape
- Date: Tue, 10 Dec 2019 19:45:12 +0000 (UTC)
commit 56c0be088d7065f054ef2d20d8ee53ffd2ffeb78
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 10 10:31:48 2019 -0600
shapes.rs: Move the common draw() code to a trait Shape
That trait also defines the make_path_builder() and uses_markers()
methods.
rsvg_internals/src/shapes.rs | 64 +++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 28 deletions(-)
---
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index 71bd48cb..3abdc6a5 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -49,6 +49,28 @@ fn render_path_builder(
}
}
+trait Shape {
+ fn draw_shape(
+ &self,
+ node: &RsvgNode,
+ cascaded: &CascadedValues<'_>,
+ draw_ctx: &mut DrawingCtx,
+ clipping: bool,
+ ) -> Result<BoundingBox, RenderingError> {
+ let values = cascaded.get();
+ let builder = self.make_path_builder(values, draw_ctx);
+ render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ }
+
+ fn make_path_builder(
+ &self,
+ values: &ComputedValues,
+ draw_ctx: &mut DrawingCtx,
+ ) -> Cow<PathBuilder>;
+
+ fn uses_markers(&self) -> bool;
+}
+
fn make_ellipse(
cx: f64,
cy: f64,
@@ -138,13 +160,11 @@ impl NodeTrait for Path {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- let values = cascaded.get();
- let builder = self.make_path_builder(values, draw_ctx);
- render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ self.draw_shape(node, cascaded, draw_ctx, clipping)
}
}
-impl Path {
+impl Shape for Path {
fn make_path_builder(
&self,
_values: &ComputedValues,
@@ -239,13 +259,11 @@ impl NodeTrait for Polygon {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- let values = cascaded.get();
- let builder = self.make_path_builder(values, draw_ctx);
- render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ self.draw_shape(node, cascaded, draw_ctx, clipping)
}
}
-impl Polygon {
+impl Shape for Polygon {
fn make_path_builder(
&self,
_values: &ComputedValues,
@@ -282,13 +300,11 @@ impl NodeTrait for Polyline {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- let values = cascaded.get();
- let builder = self.make_path_builder(values, draw_ctx);
- render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ self.draw_shape(node, cascaded, draw_ctx, clipping)
}
}
-impl Polyline {
+impl Shape for Polyline {
fn make_path_builder(
&self,
_values: &ComputedValues,
@@ -332,13 +348,11 @@ impl NodeTrait for Line {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- let values = cascaded.get();
- let builder = self.make_path_builder(values, draw_ctx);
- render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ self.draw_shape(node, cascaded, draw_ctx, clipping)
}
}
-impl Line {
+impl Shape for Line {
fn make_path_builder(
&self,
values: &ComputedValues,
@@ -412,13 +426,11 @@ impl NodeTrait for Rect {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- let values = cascaded.get();
- let builder = self.make_path_builder(values, draw_ctx);
- render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ self.draw_shape(node, cascaded, draw_ctx, clipping)
}
}
-impl Rect {
+impl Shape for Rect {
fn make_path_builder(
&self,
values: &ComputedValues,
@@ -629,13 +641,11 @@ impl NodeTrait for Circle {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- let values = cascaded.get();
- let builder = self.make_path_builder(values, draw_ctx);
- render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ self.draw_shape(node, cascaded, draw_ctx, clipping)
}
}
-impl Circle {
+impl Shape for Circle {
fn make_path_builder(
&self,
values: &ComputedValues,
@@ -689,13 +699,11 @@ impl NodeTrait for Ellipse {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- let values = cascaded.get();
- let builder = self.make_path_builder(values, draw_ctx);
- render_path_builder(&builder, draw_ctx, node, values, self.uses_markers(), clipping)
+ self.draw_shape(node, cascaded, draw_ctx, clipping)
}
}
-impl Ellipse {
+impl Shape for Ellipse {
fn make_path_builder(
&self,
values: &ComputedValues,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]