[librsvg: 1/3] Rename struct Svg to Document
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/3] Rename struct Svg to Document
- Date: Mon, 28 Oct 2019 16:43:44 +0000 (UTC)
commit 354e42c1714a7f63b01cf4815a2ce762fd5bbfc1
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Oct 27 12:14:33 2019 +0100
Rename struct Svg to Document
Makefile.am | 4 +--
rsvg_internals/src/{svg.rs => document.rs} | 46 ++++++++++++++++--------------
rsvg_internals/src/drawing_ctx.rs | 22 +++++++-------
rsvg_internals/src/handle.rs | 26 ++++++++---------
rsvg_internals/src/lib.rs | 2 +-
rsvg_internals/src/xml.rs | 8 +++---
6 files changed, 56 insertions(+), 52 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e90e5b16..1e27115d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,6 +33,8 @@ LIBRSVG_INTERNALS_SRC = \
rsvg_internals/src/create_node.rs \
rsvg_internals/src/croco.rs \
rsvg_internals/src/css.rs \
+ rsvg_internals/src/error.rs \
+ rsvg_internals/src/document.rs \
rsvg_internals/src/dpi.rs \
rsvg_internals/src/drawing_ctx.rs \
rsvg_internals/src/filters/bounds.rs \
@@ -58,7 +60,6 @@ LIBRSVG_INTERNALS_SRC = \
rsvg_internals/src/filters/offset.rs \
rsvg_internals/src/filters/tile.rs \
rsvg_internals/src/filters/turbulence.rs \
- rsvg_internals/src/error.rs \
rsvg_internals/src/float_eq_cairo.rs \
rsvg_internals/src/font_props.rs \
rsvg_internals/src/gradient.rs \
@@ -93,7 +94,6 @@ LIBRSVG_INTERNALS_SRC = \
rsvg_internals/src/srgb.rs \
rsvg_internals/src/structure.rs \
rsvg_internals/src/style.rs \
- rsvg_internals/src/svg.rs \
rsvg_internals/src/text.rs \
rsvg_internals/src/transform.rs \
rsvg_internals/src/unit_interval.rs \
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/document.rs
similarity index 83%
rename from rsvg_internals/src/svg.rs
rename to rsvg_internals/src/document.rs
index f60ad413..32cc6c20 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/document.rs
@@ -19,7 +19,7 @@ use crate::xml::xml_load_from_possibly_compressed_stream;
///
/// This contains the tree of nodes (SVG elements), the mapping
/// of id to node, and the CSS styles defined for this SVG.
-pub struct Svg {
+pub struct Document {
tree: RsvgNode,
ids: HashMap<String, RsvgNode>,
@@ -34,16 +34,16 @@ pub struct Svg {
load_options: LoadOptions,
}
-impl Svg {
+impl Document {
pub fn new(
mut tree: RsvgNode,
ids: HashMap<String, RsvgNode>,
load_options: LoadOptions,
- ) -> Svg {
+ ) -> Document {
let values = ComputedValues::default();
tree.cascade(&values);
- Svg {
+ Document {
tree,
ids,
externs: RefCell::new(Resources::new()),
@@ -56,7 +56,7 @@ impl Svg {
load_options: &LoadOptions,
stream: &gio::InputStream,
cancellable: Option<&gio::Cancellable>,
- ) -> Result<Svg, LoadingError> {
+ ) -> Result<Document, LoadingError> {
xml_load_from_possibly_compressed_stream(load_options, stream, cancellable)
}
@@ -93,7 +93,7 @@ impl Svg {
}
struct Resources {
- resources: HashMap<AllowedUrl, Result<Rc<Svg>, LoadingError>>,
+ resources: HashMap<AllowedUrl, Result<Rc<Document>, LoadingError>>,
}
impl Resources {
@@ -109,28 +109,39 @@ impl Resources {
fragment: &Fragment,
) -> Result<RsvgNode, LoadingError> {
if let Some(ref href) = fragment.uri() {
- self.get_extern_svg(load_options, href).and_then(|svg| {
- svg.lookup_node_by_id(fragment.fragment())
- .ok_or(LoadingError::BadUrl)
- })
+ self.get_extern_document(load_options, href)
+ .and_then(|doc| {
+ doc.lookup_node_by_id(fragment.fragment())
+ .ok_or(LoadingError::BadUrl)
+ })
} else {
unreachable!();
}
}
- fn get_extern_svg(
+ fn get_extern_document(
&mut self,
load_options: &LoadOptions,
href: &str,
- ) -> Result<Rc<Svg>, LoadingError> {
+ ) -> Result<Rc<Document>, LoadingError> {
let aurl = AllowedUrl::from_href(href, load_options.base_url.as_ref())
.map_err(|_| LoadingError::BadUrl)?;
match self.resources.entry(aurl) {
Entry::Occupied(e) => e.get().clone(),
Entry::Vacant(e) => {
- let svg = load_svg(load_options, e.key()).map(Rc::new);
- let res = e.insert(svg);
+ let aurl = e.key();
+ // FIXME: pass a cancellable to these
+ let doc = io::acquire_stream(aurl, None)
+ .and_then(|stream| {
+ Document::load_from_stream(
+ &load_options.copy_with_base_url(aurl),
+ &stream,
+ None,
+ )
+ })
+ .map(Rc::new);
+ let res = e.insert(doc);
res.clone()
}
}
@@ -167,13 +178,6 @@ impl Images {
}
}
-fn load_svg(load_options: &LoadOptions, aurl: &AllowedUrl) -> Result<Svg, LoadingError> {
- // FIXME: pass a cancellable to these
- io::acquire_stream(aurl, None).and_then(|stream| {
- Svg::load_from_stream(&load_options.copy_with_base_url(aurl), &stream, None)
- })
-}
-
fn load_image(
load_options: &LoadOptions,
aurl: &AllowedUrl,
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index ad97c99a..33a22583 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -8,6 +8,7 @@ use crate::aspect_ratio::AspectRatio;
use crate::bbox::BoundingBox;
use crate::clip_path::{ClipPathUnits, NodeClipPath};
use crate::coord_units::CoordUnits;
+use crate::document::Document;
use crate::dpi::Dpi;
use crate::error::{AcquireError, RenderingError};
use crate::filters;
@@ -24,7 +25,6 @@ use crate::property_defs::{
};
use crate::rect::RectangleExt;
use crate::surface_utils::shared_surface::SharedImageSurface;
-use crate::svg::Svg;
use crate::unit_interval::UnitInterval;
use crate::viewbox::ViewBox;
@@ -75,7 +75,7 @@ pub enum ClipMode {
}
pub struct DrawingCtx {
- svg: Rc<Svg>,
+ document: Rc<Document>,
initial_affine: cairo::Matrix,
@@ -101,7 +101,7 @@ pub struct DrawingCtx {
impl DrawingCtx {
pub fn new(
- svg: Rc<Svg>,
+ document: Rc<Document>,
node: Option<&RsvgNode>,
cr: &cairo::Context,
viewport: &cairo::Rectangle,
@@ -147,10 +147,10 @@ impl DrawingCtx {
let mut view_box_stack = Vec::new();
view_box_stack.push(vbox);
- let acquired_nodes = AcquiredNodes::new(svg.clone());
+ let acquired_nodes = AcquiredNodes::new(document.clone());
let mut draw_ctx = DrawingCtx {
- svg,
+ document,
initial_affine,
rect,
dpi,
@@ -822,7 +822,7 @@ impl DrawingCtx {
}
pub fn lookup_image(&self, href: &str) -> Result<SharedImageSurface, RenderingError> {
- self.svg
+ self.document
.lookup_image(href)
.map_err(|_| RenderingError::InvalidHref)
}
@@ -1099,14 +1099,14 @@ impl AcquiredNode {
}
struct AcquiredNodes {
- svg: Rc<Svg>,
+ document: Rc<Document>,
node_stack: Rc<RefCell<NodeStack>>,
}
impl AcquiredNodes {
- fn new(svg: Rc<Svg>) -> AcquiredNodes {
+ fn new(document: Rc<Document>) -> AcquiredNodes {
AcquiredNodes {
- svg,
+ document,
node_stack: Rc::new(RefCell::new(NodeStack::new())),
}
}
@@ -1116,13 +1116,13 @@ impl AcquiredNodes {
fragment: &Fragment,
node_types: &[NodeType],
) -> Result<RsvgNode, AcquireError> {
- let node = self.svg.lookup(fragment).map_err(|_| {
+ let node = self.document.lookup(fragment).map_err(|_| {
// FIXME: callers shouldn't have to know that get_node() can initiate a file load.
// Maybe we should have the following stages:
// - load main SVG XML
//
// - load secondary SVG XML and other files like images;
- // all svg::Resources and svg::Images loaded
+ // all document::Resources and document::Images loaded
//
// - Now that all files are loaded, resolve URL references
AcquireError::LinkNotFound(fragment.clone())
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index d38c04cd..fb40f632 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -10,12 +10,12 @@ use locale_config::{LanguageRange, Locale};
use crate::allowed_url::{AllowedUrl, Href};
use crate::bbox::BoundingBox;
+use crate::document::Document;
use crate::dpi::Dpi;
use crate::drawing_ctx::{DrawingCtx, RsvgRectangle};
use crate::error::{DefsLookupErrorKind, LoadingError, RenderingError};
use crate::node::{CascadedValues, RsvgNode};
use crate::structure::{IntrinsicDimensions, NodeSvg};
-use crate::svg::Svg;
use url::Url;
#[derive(Clone)]
@@ -176,7 +176,7 @@ impl Drop for SizeCallback {
}
pub struct Handle {
- svg: Rc<Svg>,
+ document: Rc<Document>,
}
impl Handle {
@@ -186,7 +186,7 @@ impl Handle {
cancellable: Option<&gio::Cancellable>,
) -> Result<Handle, LoadingError> {
Ok(Handle {
- svg: Rc::new(Svg::load_from_stream(load_options, stream, cancellable)?),
+ document: Rc::new(Document::load_from_stream(load_options, stream, cancellable)?),
})
}
@@ -282,7 +282,7 @@ impl Handle {
let target = ImageSurface::create(cairo::Format::Rgb24, 1, 1)?;
let cr = cairo::Context::new(&target);
let mut draw_ctx = DrawingCtx::new(
- self.svg.clone(),
+ self.document.clone(),
Some(node),
&cr,
viewport,
@@ -290,7 +290,7 @@ impl Handle {
true,
is_testing,
);
- let root = self.svg.root();
+ let root = self.document.root();
let bbox = draw_ctx.draw_node_from_stack(&CascadedValues::new_from_node(&root), &root, false)?;
@@ -309,7 +309,7 @@ impl Handle {
) -> Result<(RsvgRectangle, RsvgRectangle), RenderingError> {
let node = self.get_node_or_root(id)?;
- let root = self.svg.root();
+ let root = self.document.root();
let is_root = node == root;
if is_root {
@@ -339,7 +339,7 @@ impl Handle {
if let Some(id) = id {
self.lookup_node(id).map_err(RenderingError::InvalidId)
} else {
- Ok(self.svg.root())
+ Ok(self.document.root())
}
}
@@ -379,7 +379,7 @@ impl Handle {
return Err(DefsLookupErrorKind::CannotLookupExternalReferences);
}
- match self.svg.lookup_node_by_id(fragment.fragment()) {
+ match self.document.lookup_node_by_id(fragment.fragment()) {
Some(n) => Ok(n),
None => Err(DefsLookupErrorKind::NotFound),
}
@@ -439,11 +439,11 @@ impl Handle {
None
};
- let root = self.svg.root();
+ let root = self.document.root();
cr.save();
let mut draw_ctx = DrawingCtx::new(
- self.svg.clone(),
+ self.document.clone(),
node.as_ref(),
cr,
viewport,
@@ -470,7 +470,7 @@ impl Handle {
let cr = cairo::Context::new(&target);
let mut draw_ctx = DrawingCtx::new(
- self.svg.clone(),
+ self.document.clone(),
None,
&cr,
&unit_rectangle(),
@@ -547,7 +547,7 @@ impl Handle {
cr.translate(-ink_r.x, -ink_r.y);
let mut draw_ctx = DrawingCtx::new(
- self.svg.clone(),
+ self.document.clone(),
None,
&cr,
&unit_rectangle(),
@@ -566,7 +566,7 @@ impl Handle {
}
pub fn get_intrinsic_dimensions(&self) -> IntrinsicDimensions {
- self.svg.get_intrinsic_dimensions()
+ self.document.get_intrinsic_dimensions()
}
}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 0ddd1abd..6e873ef0 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -55,6 +55,7 @@ mod cond;
mod create_node;
mod croco;
mod css;
+mod document;
mod dpi;
mod drawing_ctx;
mod error;
@@ -87,7 +88,6 @@ pub mod srgb;
mod structure;
mod style;
pub mod surface_utils;
-mod svg;
mod text;
mod transform;
mod unit_interval;
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 40646fd9..d74d8561 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -11,6 +11,7 @@ use std::str;
use crate::allowed_url::AllowedUrl;
use crate::create_node::create_node_and_register_id;
use crate::css::CssRules;
+use crate::document::Document;
use crate::error::LoadingError;
use crate::handle::LoadOptions;
use crate::io::{self, get_input_stream_for_loading};
@@ -18,7 +19,6 @@ use crate::limits::MAX_LOADED_ELEMENTS;
use crate::node::{NodeData, NodeType, RsvgNode};
use crate::property_bag::PropertyBag;
use crate::style::NodeStyle;
-use crate::svg::Svg;
use crate::text::NodeChars;
use crate::xml2_load::{ParseFromStreamError, Xml2Parser};
@@ -144,7 +144,7 @@ impl XmlState {
}
}
- fn steal_result(&self) -> Result<Svg, LoadingError> {
+ fn steal_result(&self) -> Result<Document, LoadingError> {
self.check_last_error()?;
let mut inner = self.inner.borrow_mut();
@@ -159,7 +159,7 @@ impl XmlState {
node.borrow_mut().set_style(css_rules);
}
- Ok(Svg::new(
+ Ok(Document::new(
root,
inner.ids.take().unwrap(),
self.load_options.clone(),
@@ -629,7 +629,7 @@ pub fn xml_load_from_possibly_compressed_stream(
load_options: &LoadOptions,
stream: &gio::InputStream,
cancellable: Option<&gio::Cancellable>,
-) -> Result<Svg, LoadingError> {
+) -> Result<Document, LoadingError> {
let state = Rc::new(XmlState::new(load_options));
state.inner.borrow_mut().weak = Some(Rc::downgrade(&state));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]