[librsvg: 12/26] Store the stylesheet data in the Style node and load it when the element is closed
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 12/26] Store the stylesheet data in the Style node and load it when the element is closed
- Date: Sun, 10 Nov 2019 20:17:43 +0000 (UTC)
commit 892816826cfacb185dc7c50d27c757ecce0a5995
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Nov 8 08:57:29 2019 -0600
Store the stylesheet data in the Style node and load it when the element is closed
This goes a bit back to the old scheme, and it is ugly, but hopefully
will be cleaned up the next commits.
rsvg_internals/src/document.rs | 26 +++++---------------------
rsvg_internals/src/text.rs | 4 ++++
rsvg_internals/src/xml.rs | 33 +++++++++++++++++++++++++++++++--
3 files changed, 40 insertions(+), 23 deletions(-)
---
diff --git a/rsvg_internals/src/document.rs b/rsvg_internals/src/document.rs
index c8bbd500..2bfa7876 100644
--- a/rsvg_internals/src/document.rs
+++ b/rsvg_internals/src/document.rs
@@ -16,7 +16,6 @@ use crate::node::{NodeCascade, NodeData, NodeType, RsvgNode};
use crate::properties::ComputedValues;
use crate::property_bag::PropertyBag;
use crate::structure::{IntrinsicDimensions, Svg};
-use crate::style::{Style, StyleType};
use crate::surface_utils::shared_surface::SharedImageSurface;
use crate::text::NodeChars;
use crate::xml::xml_load_from_possibly_compressed_stream;
@@ -274,27 +273,12 @@ impl DocumentBuilder {
node
}
- pub fn append_characters(&mut self, text: &str, parent: &mut RsvgNode) {
- if text.is_empty() {
- return;
- }
+ pub fn append_stylesheet_from_text(&mut self, text: &str) {
+ self.inline_css.push_str(text);
+ }
- if parent.borrow().get_type() == NodeType::Style {
- // If the "type" attribute is not present, fall back to the
- // "contentStyleType" attribute of the svg element.
- let style_type = parent.borrow().get_impl::<Style>().style_type().unwrap_or_else(|| {
- if self.tree.is_some()
- && self.tree.as_ref().unwrap().borrow().get_type() == NodeType::Svg
- {
- self.tree.as_ref().unwrap().borrow().get_impl::<Svg>().content_style_type()
- } else {
- StyleType::TextCss
- }
- });
- if style_type == StyleType::TextCss {
- self.inline_css.push_str(text);
- }
- } else {
+ pub fn append_characters(&mut self, text: &str, parent: &mut RsvgNode) {
+ if !text.is_empty() {
self.append_chars_to_parent(text, parent);
}
}
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index d25b0762..3807e664 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -560,6 +560,10 @@ impl NodeChars {
chunks[num_chunks - 1].spans.push(span);
}
+
+ pub fn get_string(&self) -> String {
+ self.string.borrow().clone()
+ }
}
impl NodeTrait for NodeChars {
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index dae651b8..c7312ac1 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -13,8 +13,10 @@ use crate::document::{Document, DocumentBuilder};
use crate::error::LoadingError;
use crate::io::{self, get_input_stream_for_loading};
use crate::limits::MAX_LOADED_ELEMENTS;
-use crate::node::RsvgNode;
+use crate::node::{NodeType, RsvgNode};
use crate::property_bag::PropertyBag;
+use crate::style::{Style, StyleType};
+use crate::text::NodeChars;
use crate::xml2_load::{ParseFromStreamError, Xml2Parser};
#[derive(Clone)]
@@ -342,10 +344,37 @@ impl XmlState {
}
fn style_end_element(&self) {
- // FIXME: inner.document_builder...add_inline_stylesheet(text)
+ self.add_inline_stylesheet();
self.element_creation_end_element()
}
+ fn add_inline_stylesheet(&self) {
+ let mut inner = self.inner.borrow_mut();
+ let current_node = inner.current_node.as_ref().unwrap();
+
+ assert!(current_node.borrow().get_type() == NodeType::Style);
+
+ let style_type = current_node
+ .borrow()
+ .get_impl::<Style>()
+ .style_type()
+ .unwrap_or(StyleType::TextCss);
+
+ if style_type == StyleType::TextCss {
+ let stylesheet_text = current_node.children()
+ .map(|child| {
+ let child_borrow = child.borrow();
+
+ assert!(child_borrow.get_type() == NodeType::Chars);
+ child_borrow.get_impl::<NodeChars>().get_string()
+ })
+ .collect::<String>();
+
+ let builder = inner.document_builder.as_mut().unwrap();
+ builder.append_stylesheet_from_text(&stylesheet_text);
+ }
+ }
+
fn inside_style_start_element(&self, name: &QualName) -> Context {
self.unsupported_style_start_element(name)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]