From 8cf8907996acef022bc5126183166a2c13ec846e Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Sun, 24 Apr 2022 10:31:13 -0500 Subject: [PATCH] fix: apply api changes from updated gnome deps --- src/graphics/raster.rs | 14 ++++---------- src/graphics/raster_test.rs | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/graphics/raster.rs b/src/graphics/raster.rs index 98a809f..43d6839 100644 --- a/src/graphics/raster.rs +++ b/src/graphics/raster.rs @@ -5,7 +5,7 @@ use crate::badge::BadgeStyle; // for tests use self::librsvg_imports::{CairoRenderer, Loader}; use cairo::{Context, ImageSurface, Rectangle}; -use gio::{MemoryInputStream, NONE_CANCELLABLE, NONE_FILE}; +use gio::{Cancellable, File, MemoryInputStream}; use glib::Bytes; use librsvg::IntrinsicDimensions; @@ -21,15 +21,9 @@ pub enum SvgToPngConversionError { // Returns tuple with (width, height) fn get_dimensions(renderer: &CairoRenderer) -> (f64, f64) { - let IntrinsicDimensions { - width: width_dim, - height: height_dim, - .. - } = renderer.intrinsic_dimensions(); - let width = width_dim.map_or(0f64, |w| w.length); - let height = height_dim.map_or(0f64, |h| h.length); + let IntrinsicDimensions { width, height, .. } = renderer.intrinsic_dimensions(); - (width, height) + (width.length, height.length) } fn get_bytes_stream( @@ -56,7 +50,7 @@ pub(super) fn convert_svg_to_png( let stream = MemoryInputStream::from_bytes(&get_bytes_stream(svg_bytes, &badge_style, &svg_processor)?); let handle = Loader::new() - .read_stream(&stream, NONE_FILE, NONE_CANCELLABLE) + .read_stream(&stream, File::NONE, Cancellable::NONE) .map_err(|_| SvgHandleCreationFailure)?; let renderer = CairoRenderer::new(&handle); diff --git a/src/graphics/raster_test.rs b/src/graphics/raster_test.rs index 66e5047..210d58d 100644 --- a/src/graphics/raster_test.rs +++ b/src/graphics/raster_test.rs @@ -8,14 +8,19 @@ mod get_dimensions_tests { use super::{get_dimensions, CairoRenderer as MockCairoRenderer}; use librsvg::{IntrinsicDimensions, Length, LengthUnit}; + const ZERO_LENGTH: Length = Length { + length: 0f64, + unit: LengthUnit::Px, + }; + #[test] fn handles_zero_dimensions() { let mut mock_renderer = MockCairoRenderer::default(); mock_renderer .expect_intrinsic_dimensions() .return_const(IntrinsicDimensions { - width: None, - height: None, + width: ZERO_LENGTH, + height: ZERO_LENGTH, vbox: None, }); let (width, height) = get_dimensions(&mock_renderer); @@ -30,11 +35,11 @@ mod get_dimensions_tests { mock_renderer .expect_intrinsic_dimensions() .return_const(IntrinsicDimensions { - width: Some(Length { + width: Length { length: exp_width, unit: LengthUnit::Px, - }), - height: None, + }, + height: ZERO_LENGTH, vbox: None, }); let (width, height) = get_dimensions(&mock_renderer); @@ -49,11 +54,11 @@ mod get_dimensions_tests { mock_renderer .expect_intrinsic_dimensions() .return_const(IntrinsicDimensions { - width: None, - height: Some(Length { + width: ZERO_LENGTH, + height: Length { length: exp_height, unit: LengthUnit::Px, - }), + }, vbox: None, }); let (width, height) = get_dimensions(&mock_renderer);