[librsvg: 16/37] MeasuredChunk: compute the advance of all the MeasuredSpans



commit af22df9b183fbbd3fffd50c89fd860eb9c98f1d8
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Oct 31 07:58:35 2018 -0600

    MeasuredChunk: compute the advance of all the MeasuredSpans

 rsvg_internals/src/text.rs | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 13b5c72b..b0681092 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -48,6 +48,7 @@ struct MeasuredChunk {
     values: ComputedValues,
     x: Option<Length>,
     y: Option<Length>,
+    advance: (f64, f64),
     spans: Vec<MeasuredSpan>,
 }
 
@@ -89,15 +90,22 @@ impl Chunk {
 
 impl MeasuredChunk {
     fn from_chunk(chunk: &Chunk, draw_ctx: &DrawingCtx) -> MeasuredChunk {
+        let measured_spans: Vec<MeasuredSpan> = chunk
+            .spans
+            .iter()
+            .map(|span| MeasuredSpan::from_span(span, draw_ctx))
+            .collect();
+
+        let advance = measured_spans.iter().fold((0.0, 0.0), |acc, measured| {
+            (acc.0 + measured.advance.0, acc.1 + measured.advance.1)
+        });
+
         MeasuredChunk {
             values: chunk.values.clone(),
             x: chunk.x,
             y: chunk.y,
-            spans: chunk
-                .spans
-                .iter()
-                .map(|span| MeasuredSpan::from_span(span, draw_ctx))
-                .collect(),
+            advance,
+            spans: measured_spans,
         }
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]