[librsvg: 28/37] Annotate each Span with its nesting depth within the topmost <text> element
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 28/37] Annotate each Span with its nesting depth within the topmost <text> element
- Date: Fri, 28 Dec 2018 03:26:19 +0000 (UTC)
commit 525aa6f74eeb1e8c4f41686275cece3e1b59e41d
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Nov 1 17:31:49 2018 -0600
Annotate each Span with its nesting depth within the topmost <text> element
We will use this to know when to trim spaces at the ends of Spans.
rsvg_internals/src/text.rs | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 27874dab..9054305c 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -63,6 +63,7 @@ struct Span {
text: String,
dx: Option<Length>,
dy: Option<Length>,
+ depth: usize,
}
struct MeasuredSpan {
@@ -181,12 +182,19 @@ fn text_anchor_advance(
}
impl Span {
- fn new(text: &str, values: ComputedValues, dx: Option<Length>, dy: Option<Length>) -> Span {
+ fn new(
+ text: &str,
+ values: ComputedValues,
+ dx: Option<Length>,
+ dy: Option<Length>,
+ depth: usize,
+ ) -> Span {
Span {
values,
text: text.to_string(),
dx,
dy,
+ depth,
}
}
}
@@ -207,6 +215,8 @@ impl MeasuredSpan {
(w, 0.0)
};
+ println!("span \"{}\" advance={}", span.text, w);
+
MeasuredSpan {
values,
layout,
@@ -290,13 +300,14 @@ fn children_to_chunks(
cascaded: &CascadedValues<'_>,
dx: Option<Length>,
dy: Option<Length>,
+ depth: usize,
) {
let values = cascaded.get();
for child in node.children() {
match child.get_type() {
NodeType::Chars => child.with_impl(|chars: &NodeChars| {
- let span = chars.make_span(&child, values, dx, dy);
+ let span = chars.make_span(&child, values, dx, dy, depth);
let num_chunks = chunks.len();
assert!(num_chunks > 0);
@@ -307,12 +318,12 @@ fn children_to_chunks(
NodeType::TSpan => child.with_impl(|tspan: &NodeTSpan| {
let cascaded = CascadedValues::new(cascaded, &child);
- tspan.to_chunks(&child, &cascaded, chunks);
+ tspan.to_chunks(&child, &cascaded, chunks, depth + 1);
}),
NodeType::TRef => child.with_impl(|tref: &NodeTRef| {
let cascaded = CascadedValues::new(cascaded, &child);
- tref.to_chunks(&child, &cascaded, chunks);
+ tref.to_chunks(&child, &cascaded, chunks, depth + 1);
}),
_ => (),
@@ -388,6 +399,7 @@ impl NodeChars {
values: &ComputedValues,
dx: Option<Length>,
dy: Option<Length>,
+ depth: usize,
) -> Span {
self.ensure_normalized_string(node, values);
@@ -396,6 +408,7 @@ impl NodeChars {
values.clone(),
dx,
dy,
+ depth,
)
}
}
@@ -434,7 +447,7 @@ impl NodeText {
println!("Chunk new x={:?}, y={:?}", Some(x), Some(y));
chunks.push(Chunk::new(cascaded.get(), Some(x), Some(y)));
- children_to_chunks(&mut chunks, node, cascaded, dx, dy);
+ children_to_chunks(&mut chunks, node, cascaded, dx, dy, 0);
chunks
}
}
@@ -525,6 +538,7 @@ impl NodeTRef {
_node: &RsvgNode,
_cascaded: &CascadedValues<'_>,
_chunks: &mut Vec<Chunk>,
+ _depth: usize,
) {
// let x = self.x.get().or(x);
// let y = self.y.get().or(y);
@@ -565,7 +579,13 @@ impl NodeTSpan {
}
}
- fn to_chunks(&self, node: &RsvgNode, cascaded: &CascadedValues<'_>, chunks: &mut Vec<Chunk>) {
+ fn to_chunks(
+ &self,
+ node: &RsvgNode,
+ cascaded: &CascadedValues<'_>,
+ chunks: &mut Vec<Chunk>,
+ depth: usize,
+ ) {
let x = self.x.get();
let y = self.y.get();
let dx = self.dx.get();
@@ -578,7 +598,7 @@ impl NodeTSpan {
chunks.push(Chunk::new(values, x, y));
}
- children_to_chunks(chunks, node, cascaded, dx, dy);
+ children_to_chunks(chunks, node, cascaded, dx, dy, depth);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]