decoder: Use glycin for decoding SVGs as well

Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/267>
This commit is contained in:
Sophie Herold 2023-08-04 13:20:41 +02:00
parent 0aff4ef350
commit a027513447
9 changed files with 140 additions and 978 deletions

View file

@ -847,7 +847,7 @@ impl LpPrint {
let texture_scale = self.user_width() / orig_width as f64;
let cairo_scale = cairo_dpi / self.dpi();
let cairo_surface = if image.format().map_or(false, |x| x.is_svg()) {
let texture = if image.format().map_or(false, |x| x.is_svg()) {
// Render SVG to exact needed sizes
// TODO: This should be async
decoder::formats::Svg::render_print(
@ -857,8 +857,10 @@ impl LpPrint {
)
.unwrap()
} else {
let texture = image.print_data(texture_scale).unwrap();
image.print_data(texture_scale).unwrap()
};
let cairo_surface = {
let mut downloader = gdk::TextureDownloader::new(&texture);
downloader.set_format(gdk::MemoryFormat::B8g8r8a8Premultiplied);

View file

@ -306,31 +306,7 @@ impl LpPropertiesView {
fn image_size(&self, _image_size: Option<glib::Variant>) -> String {
if let Some(image) = self.image() {
match image.dimension_details() {
ImageDimensionDetails::Svg((width, height))
if width.unit != rsvg::LengthUnit::Px
&& height.unit != rsvg::LengthUnit::Px =>
{
// Percent is not stored as percentile
let width_factor = if width.unit == rsvg::LengthUnit::Percent {
100.
} else {
1.
};
let height_factor = if height.unit == rsvg::LengthUnit::Percent {
100.
} else {
1.
};
// Only show two digits
let width_n = (width.length * width_factor * 100.).round() / 100.;
let height_n = (height.length * height_factor * 100.).round() / 100.;
let width_unit = width.unit;
let height_unit = height.unit;
format!("{width_n}\u{202F}{width_unit} \u{D7} {height_n}\u{202F}{height_unit}")
}
ImageDimensionDetails::Svg(string) => string,
_ => {
let (width, height) = image.image_size();
if width > 0 && height > 0 {