[librsvg: 4/5] image: shorten code
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 4/5] image: shorten code
- Date: Fri, 28 Aug 2020 15:30:35 +0000 (UTC)
commit d05956ca614327563a51dc78f2cd185c31bbc36f
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Aug 28 15:08:39 2020 +0200
image: shorten code
rsvg_internals/src/image.rs | 34 +++++++++++-----------------------
1 file changed, 11 insertions(+), 23 deletions(-)
---
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index 979486ff..481f4519 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -6,14 +6,13 @@ use crate::allowed_url::Href;
use crate::aspect_ratio::AspectRatio;
use crate::bbox::BoundingBox;
use crate::document::AcquiredNodes;
-use crate::drawing_ctx::{DrawingCtx, ViewParams};
+use crate::drawing_ctx::DrawingCtx;
use crate::element::{Draw, ElementResult, SetAttributes};
use crate::error::*;
use crate::href::{is_href, set_href};
use crate::length::*;
use crate::node::{CascadedValues, Node};
use crate::parsers::ParseValue;
-use crate::properties::ComputedValues;
use crate::property_bag::PropertyBag;
use crate::rect::Rect;
@@ -67,20 +66,15 @@ impl Draw for Image {
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- if self.href.is_none() {
- return Ok(draw_ctx.empty_bbox());
- }
-
- let href = self.href.as_ref().unwrap();
- let surface = match *href {
- Href::PlainUrl(ref url) => match acquired_nodes.lookup_image(url) {
+ let surface = match self.href {
+ Some(Href::PlainUrl(ref url)) => match acquired_nodes.lookup_image(url) {
Ok(surf) => surf,
Err(e) => {
rsvg_log!("could not load image \"{}\": {}", url, e);
return Ok(draw_ctx.empty_bbox());
}
},
- Href::WithFragment(_) => {
+ Some(_) => {
rsvg_log!(
"not rendering {} because its href cannot contain a fragment identifier",
node
@@ -88,15 +82,20 @@ impl Draw for Image {
return Ok(draw_ctx.empty_bbox());
}
+ None => return Ok(draw_ctx.empty_bbox()),
};
let values = cascaded.get();
+
let params = draw_ctx.get_view_params();
- let rect = self.get_rect(values, ¶ms);
+ let x = self.x.normalize(&values, ¶ms);
+ let y = self.y.normalize(&values, ¶ms);
+ let w = self.width.normalize(&values, ¶ms);
+ let h = self.height.normalize(&values, ¶ms);
draw_ctx.draw_image(
&surface,
- rect,
+ Rect::new(x, y, x + w, y + h),
self.aspect,
node,
acquired_nodes,
@@ -105,14 +104,3 @@ impl Draw for Image {
)
}
}
-
-impl Image {
- fn get_rect(&self, values: &ComputedValues, params: &ViewParams) -> Rect {
- let x = self.x.normalize(&values, ¶ms);
- let y = self.y.normalize(&values, ¶ms);
- let w = self.width.normalize(&values, ¶ms);
- let h = self.height.normalize(&values, ¶ms);
-
- Rect::new(x, y, x + w, y + h)
- }
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]