[librsvg: 8/15] Svg - extract method to push the new viewport
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 8/15] Svg - extract method to push the new viewport
- Date: Tue, 24 Nov 2020 18:09:20 +0000 (UTC)
commit f9bf169b11e8c0eaaaf94a187fb916eea8017421
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Nov 17 18:54:07 2020 -0600
Svg - extract method to push the new viewport
We'll use this to implement the recursion in draw_node_from_stack by hand.
src/structure.rs | 81 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 45 insertions(+), 36 deletions(-)
---
diff --git a/src/structure.rs b/src/structure.rs
index 2198f56b..2e0dfa89 100644
--- a/src/structure.rs
+++ b/src/structure.rs
@@ -157,44 +157,13 @@ impl Svg {
Rect::new(nx, ny, nx + nw, ny + nh)
}
-}
-
-impl SetAttributes for Svg {
- fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
- for (attr, value) in attrs.iter() {
- match attr.expanded() {
- expanded_name!("", "preserveAspectRatio") => {
- self.preserve_aspect_ratio = attr.parse(value)?
- }
- expanded_name!("", "x") => self.x = Some(attr.parse(value)?),
- expanded_name!("", "y") => self.y = Some(attr.parse(value)?),
- expanded_name!("", "width") => {
- self.w = Some(
- attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?,
- )
- }
- expanded_name!("", "height") => {
- self.h =
- Some(attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?)
- }
- expanded_name!("", "viewBox") => self.vbox = attr.parse(value).map(Some)?,
- _ => (),
- }
- }
- Ok(())
- }
-}
-
-impl Draw for Svg {
- fn draw(
+ pub fn push_viewport(
&self,
node: &Node,
- acquired_nodes: &mut AcquiredNodes<'_>,
cascaded: &CascadedValues<'_>,
draw_ctx: &mut DrawingCtx,
- clipping: bool,
- ) -> Result<BoundingBox, RenderingError> {
+ ) -> Option<ViewParams> {
let values = cascaded.get();
let params = draw_ctx.get_view_params();
@@ -231,10 +200,50 @@ impl Draw for Svg {
)
};
- draw_ctx.with_discrete_layer(node, acquired_nodes, values, clipping, &mut |an, dc| {
- let _params =
- dc.push_new_viewport(vbox, viewport, self.preserve_aspect_ratio, clip_mode);
+ draw_ctx.push_new_viewport(vbox, viewport, self.preserve_aspect_ratio, clip_mode)
+ }
+}
+impl SetAttributes for Svg {
+ fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
+ for (attr, value) in attrs.iter() {
+ match attr.expanded() {
+ expanded_name!("", "preserveAspectRatio") => {
+ self.preserve_aspect_ratio = attr.parse(value)?
+ }
+ expanded_name!("", "x") => self.x = Some(attr.parse(value)?),
+ expanded_name!("", "y") => self.y = Some(attr.parse(value)?),
+ expanded_name!("", "width") => {
+ self.w = Some(
+ attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?,
+ )
+ }
+ expanded_name!("", "height") => {
+ self.h =
+ Some(attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?)
+ }
+ expanded_name!("", "viewBox") => self.vbox = attr.parse(value).map(Some)?,
+ _ => (),
+ }
+ }
+
+ Ok(())
+ }
+}
+
+impl Draw for Svg {
+ fn draw(
+ &self,
+ node: &Node,
+ acquired_nodes: &mut AcquiredNodes<'_>,
+ cascaded: &CascadedValues<'_>,
+ draw_ctx: &mut DrawingCtx,
+ clipping: bool,
+ ) -> Result<BoundingBox, RenderingError> {
+ let values = cascaded.get();
+
+ draw_ctx.with_discrete_layer(node, acquired_nodes, values, clipping, &mut |an, dc| {
+ let _params = self.push_viewport(node, cascaded, dc);
node.draw_children(an, cascaded, dc, clipping)
})
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]