[librsvg: 5/7] structure: move clip_path, link, and mask in structure.rs
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/7] structure: move clip_path, link, and mask in structure.rs
- Date: Sun, 5 Jan 2020 22:56:46 +0000 (UTC)
commit e00cd8bdd6b17b6164d92ceb0beb55dc864d80e8
Author: Paolo Borelli <pborelli gnome org>
Date: Thu Jan 2 12:41:44 2020 +0100
structure: move clip_path, link, and mask in structure.rs
Now they are very simple, so move them together with the
other container nodes.
Makefile.am | 3 -
po/POTFILES.in | 3 -
rsvg_internals/src/clip_path.rs | 34 ----------
rsvg_internals/src/create_node.rs | 5 +-
rsvg_internals/src/drawing_ctx.rs | 3 +-
rsvg_internals/src/lib.rs | 3 -
rsvg_internals/src/link.rs | 45 -------------
rsvg_internals/src/mask.rs | 83 -----------------------
rsvg_internals/src/structure.rs | 136 +++++++++++++++++++++++++++++++++++++-
9 files changed, 137 insertions(+), 178 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 6aa74e56..8a795cb4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -26,7 +26,6 @@ LIBRSVG_INTERNALS_SRC = \
rsvg_internals/src/angle.rs \
rsvg_internals/src/aspect_ratio.rs \
rsvg_internals/src/bbox.rs \
- rsvg_internals/src/clip_path.rs \
rsvg_internals/src/color.rs \
rsvg_internals/src/cond.rs \
rsvg_internals/src/coord_units.rs \
@@ -71,9 +70,7 @@ LIBRSVG_INTERNALS_SRC = \
rsvg_internals/src/lib.rs \
rsvg_internals/src/limits.rs \
rsvg_internals/src/log.rs \
- rsvg_internals/src/link.rs \
rsvg_internals/src/marker.rs \
- rsvg_internals/src/mask.rs \
rsvg_internals/src/node.rs \
rsvg_internals/src/number_list.rs \
rsvg_internals/src/paint_server.rs \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ee8ef9ff..4b749b9f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -18,7 +18,6 @@ rsvg_internals/src/allowed_url.rs
rsvg_internals/src/aspect_ratio.rs
rsvg_internals/src/attributes.rs
rsvg_internals/src/bbox.rs
-rsvg_internals/src/clip_path.rs
rsvg_internals/src/color.rs
rsvg_internals/src/cond.rs
rsvg_internals/src/coord_units.rs
@@ -58,10 +57,8 @@ rsvg_internals/src/io.rs
rsvg_internals/src/iri.rs
rsvg_internals/src/length.rs
rsvg_internals/src/lib.rs
-rsvg_internals/src/link.rs
rsvg_internals/src/log.rs
rsvg_internals/src/marker.rs
-rsvg_internals/src/mask.rs
rsvg_internals/src/node.rs
rsvg_internals/src/paint_server.rs
rsvg_internals/src/parsers.rs
diff --git a/rsvg_internals/src/create_node.rs b/rsvg_internals/src/create_node.rs
index 9e194bb5..0d1501ae 100644
--- a/rsvg_internals/src/create_node.rs
+++ b/rsvg_internals/src/create_node.rs
@@ -10,7 +10,6 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns, QualName};
use once_cell::sync::Lazy;
use std::collections::HashMap;
-use crate::clip_path::ClipPath;
use crate::filters::{
blend::FeBlend,
color_matrix::FeColorMatrix,
@@ -38,14 +37,12 @@ use crate::filters::{
use crate::filter::Filter;
use crate::gradient::{LinearGradient, RadialGradient, Stop};
use crate::image::Image;
-use crate::link::Link;
use crate::marker::Marker;
-use crate::mask::Mask;
use crate::node::*;
use crate::pattern::Pattern;
use crate::property_bag::PropertyBag;
use crate::shapes::{Circle, Ellipse, Line, Path, Polygon, Polyline, Rect};
-use crate::structure::{Group, NonRendering, Svg, Switch, Symbol, Use};
+use crate::structure::{ClipPath, Group, Link, Mask, NonRendering, Svg, Switch, Symbol, Use};
use crate::style::Style;
use crate::text::{TRef, TSpan, Text};
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 46beb4d8..470784b7 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -11,7 +11,6 @@ use std::rc::{Rc, Weak};
use crate::allowed_url::Fragment;
use crate::aspect_ratio::AspectRatio;
use crate::bbox::BoundingBox;
-use crate::clip_path::ClipPath;
use crate::coord_units::CoordUnits;
use crate::dasharray::Dasharray;
use crate::document::Document;
@@ -20,7 +19,6 @@ use crate::error::{AcquireError, RenderingError};
use crate::filters;
use crate::gradient::{LinearGradient, RadialGradient};
use crate::limits;
-use crate::mask::Mask;
use crate::node::{CascadedValues, NodeDraw, NodeType, RsvgNode};
use crate::paint_server::{PaintServer, PaintSource};
use crate::pattern::Pattern;
@@ -29,6 +27,7 @@ use crate::property_defs::{
ClipRule, FillRule, Opacity, ShapeRendering, StrokeDasharray, StrokeLinecap, StrokeLinejoin,
};
use crate::rect::{Rect, TransformRect};
+use crate::structure::{ClipPath, Mask};
use crate::surface_utils::{shared_surface::SharedImageSurface, shared_surface::SurfaceType};
use crate::unit_interval::UnitInterval;
use crate::viewbox::ViewBox;
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 30178697..eb1760a9 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -87,7 +87,6 @@ mod allowed_url;
mod angle;
mod aspect_ratio;
mod bbox;
-mod clip_path;
mod color;
mod cond;
mod create_node;
@@ -107,9 +106,7 @@ mod io;
mod iri;
mod length;
mod limits;
-mod link;
mod marker;
-mod mask;
mod node;
mod number_list;
mod paint_server;
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 974f2573..c6b50af6 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -1,10 +1,11 @@
-//! Structural elements in SVG: the `g`, `switch`, `svg`, `use`, `symbol` elements.
+//! Structural elements in SVG: the `g`, `switch`, `svg`, `use`, `symbol`, `clip_path`, `mask`, `link`
elements.
use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::allowed_url::Fragment;
use crate::aspect_ratio::*;
use crate::bbox::BoundingBox;
+use crate::coord_units::CoordUnits;
use crate::dpi::Dpi;
use crate::drawing_ctx::{ClipMode, DrawingCtx, ViewParams};
use crate::error::*;
@@ -442,3 +443,136 @@ impl NodeTrait for Symbol {
true
}
}
+
+coord_units!(ClipPathUnits, CoordUnits::UserSpaceOnUse);
+
+#[derive(Default)]
+pub struct ClipPath {
+ units: ClipPathUnits,
+}
+
+impl ClipPath {
+ pub fn get_units(&self) -> CoordUnits {
+ CoordUnits::from(self.units)
+ }
+}
+
+impl NodeTrait for ClipPath {
+ fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
+ for (attr, value) in pbag.iter() {
+ match attr.expanded() {
+ expanded_name!(svg "clipPathUnits") => self.units = attr.parse(value)?,
+ _ => (),
+ }
+ }
+
+ Ok(())
+ }
+}
+
+coord_units!(MaskUnits, CoordUnits::ObjectBoundingBox);
+coord_units!(MaskContentUnits, CoordUnits::UserSpaceOnUse);
+
+pub struct Mask {
+ x: Length<Horizontal>,
+ y: Length<Vertical>,
+ width: Length<Horizontal>,
+ height: Length<Vertical>,
+
+ units: MaskUnits,
+ content_units: MaskContentUnits,
+}
+
+impl Default for Mask {
+ fn default() -> Mask {
+ Mask {
+ // these values are per the spec
+ x: Length::<Horizontal>::parse_str("-10%").unwrap(),
+ y: Length::<Vertical>::parse_str("-10%").unwrap(),
+ width: Length::<Horizontal>::parse_str("120%").unwrap(),
+ height: Length::<Vertical>::parse_str("120%").unwrap(),
+
+ units: MaskUnits::default(),
+ content_units: MaskContentUnits::default(),
+ }
+ }
+}
+
+impl Mask {
+ pub fn get_units(&self) -> CoordUnits {
+ CoordUnits::from(self.content_units)
+ }
+
+ pub fn get_content_units(&self) -> CoordUnits {
+ CoordUnits::from(self.content_units)
+ }
+
+ pub fn get_rect(&self, values: &ComputedValues, params: &ViewParams) -> Rect {
+ let x = self.x.normalize(&values, ¶ms);
+ let y = self.y.normalize(&values, ¶ms);
+ let w = self.width.normalize(&values, ¶ms);
+ let h = self.height.normalize(&values, ¶ms);
+
+ Rect::new(x, y, x + w, y + h)
+ }
+}
+
+impl NodeTrait for Mask {
+ fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
+ for (attr, value) in pbag.iter() {
+ match attr.expanded() {
+ expanded_name!(svg "x") => self.x = attr.parse(value)?,
+ expanded_name!(svg "y") => self.y = attr.parse(value)?,
+ expanded_name!(svg "width") => {
+ self.width =
+ attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?
+ }
+ expanded_name!(svg "height") => {
+ self.height =
+ attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?
+ }
+ expanded_name!(svg "maskUnits") => self.units = attr.parse(value)?,
+ expanded_name!(svg "maskContentUnits") => self.content_units = attr.parse(value)?,
+ _ => (),
+ }
+ }
+
+ Ok(())
+ }
+}
+
+#[derive(Default)]
+pub struct Link {
+ link: Option<String>,
+}
+
+impl NodeTrait for Link {
+ fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
+ for (attr, value) in pbag.iter() {
+ match attr.expanded() {
+ expanded_name!(xlink "href") => self.link = Some(value.to_owned()),
+ _ => (),
+ }
+ }
+
+ Ok(())
+ }
+
+ fn draw(
+ &self,
+ node: &RsvgNode,
+ cascaded: &CascadedValues<'_>,
+ draw_ctx: &mut DrawingCtx,
+ clipping: bool,
+ ) -> Result<BoundingBox, RenderingError> {
+ let cascaded = CascadedValues::new(cascaded, node);
+ let values = cascaded.get();
+
+ draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| match self.link.as_ref() {
+ Some(l) if !l.is_empty() => {
+ dc.with_link_tag(l, &mut |dc| node.draw_children(&cascaded, dc, clipping))
+ }
+ _ => node.draw_children(&cascaded, dc, clipping),
+ })
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]