[librsvg: 2/37] NodeChars.measure(): Return a value; don't mutate an argument
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/37] NodeChars.measure(): Return a value; don't mutate an argument
- Date: Fri, 28 Dec 2018 03:24:08 +0000 (UTC)
commit 038607872f24840ebfd3758e27470a6854c1c8f8
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Oct 29 18:09:31 2018 -0600
NodeChars.measure(): Return a value; don't mutate an argument
Have the caller use the result to mutate its running length
rsvg_internals/src/text.rs | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
---
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index d7c8a190..192679a3 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -98,17 +98,11 @@ impl NodeChars {
create_pango_layout(draw_ctx, values, &s)
}
- fn measure(
- &self,
- node: &RsvgNode,
- values: &ComputedValues,
- draw_ctx: &DrawingCtx,
- length: &mut f64,
- ) {
+ fn measure(&self, node: &RsvgNode, values: &ComputedValues, draw_ctx: &DrawingCtx) -> f64 {
let layout = self.create_layout(node, values, draw_ctx);
let (width, _) = layout.get_size();
- *length += f64::from(width) / f64::from(pango::SCALE);
+ f64::from(width) / f64::from(pango::SCALE)
}
fn render(
@@ -684,7 +678,7 @@ fn measure_child(
// instead of child_values because NodeChars does not
// represent a real SVG element - it is just our container
// for character data.
- node.with_impl(|chars: &NodeChars| chars.measure(node, values, draw_ctx, length));
+ *length += node.with_impl(|chars: &NodeChars| chars.measure(node, values, draw_ctx));
}
(_, true) => {
done = measure_children(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]