Skip to content

Commit 95d801a

Browse files
committed
Don't render jpg pictures with ghostscript
1 parent 9febc8a commit 95d801a

File tree

5 files changed

+38
-36
lines changed

5 files changed

+38
-36
lines changed
-860 Bytes
Binary file not shown.
-3.06 KB
Binary file not shown.

src/svg/image.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1+
use tiny_skia_path::Rect;
2+
use usvg::ImageKind;
3+
use crate::FillRule;
4+
use crate::image::Image;
15
use crate::surface::Surface;
2-
use crate::svg::ProcessContext;
6+
use crate::svg::{group, ProcessContext};
7+
use crate::util::RectExt;
38

49
/// Render an image into a surface.
510
pub fn render(image: &usvg::Image, surface: &mut Surface, process_context: &mut ProcessContext) {
611
if !image.is_visible() {
712
return;
813
}
914

10-
unimplemented!();
11-
// match image.kind() {
12-
// ImageKind::JPEG(d) => {
13-
// let dynamic_image =
14-
// image::load_from_memory_with_format(d.as_slice(), ImageFormat::Jpeg).unwrap();
15-
// let d_image = Image::new(&dynamic_image);
16-
// surface.draw_image(d_image, image.size());
17-
// }
18-
// ImageKind::PNG(d) => {
19-
// let dynamic_image =
20-
// image::load_from_memory_with_format(d.as_slice(), ImageFormat::Png).unwrap();
21-
// let d_image = Image::new(&dynamic_image);
22-
// surface.draw_image(d_image, image.size());
23-
// }
24-
// ImageKind::GIF(d) => {
25-
// let dynamic_image =
26-
// image::load_from_memory_with_format(d.as_slice(), ImageFormat::Gif).unwrap();
27-
// let d_image = Image::new(&dynamic_image);
28-
// surface.draw_image(d_image, image.size());
29-
// }
30-
// ImageKind::SVG(t) => {
31-
// surface.push_clip_path(
32-
// &Rect::from_xywh(0.0, 0.0, t.size().width(), t.size().height())
33-
// .unwrap()
34-
// .to_clip_path(),
35-
// &FillRule::NonZero,
36-
// );
37-
// group::render(t.root(), surface, process_context);
38-
// surface.pop();
39-
// }
40-
// _ => unimplemented!(),
41-
// }
15+
match image.kind() {
16+
ImageKind::JPEG(d) => {
17+
// TODO: Remove unwraps
18+
let d_image = Image::from_jpeg(&d).unwrap();
19+
surface.draw_image(d_image, image.size());
20+
}
21+
ImageKind::PNG(d) => {
22+
let d_image = Image::from_png(&d).unwrap();
23+
surface.draw_image(d_image, image.size());
24+
}
25+
ImageKind::GIF(d) => {
26+
let d_image = Image::from_gif(&d).unwrap();
27+
surface.draw_image(d_image, image.size());
28+
}
29+
ImageKind::SVG(t) => {
30+
surface.push_clip_path(
31+
&Rect::from_xywh(0.0, 0.0, t.size().width(), t.size().height())
32+
.unwrap()
33+
.to_clip_path(),
34+
&FillRule::NonZero,
35+
);
36+
group::render(t.root(), surface, process_context);
37+
surface.pop();
38+
}
39+
_ => unimplemented!(),
40+
}
4241
}

src/tests/manual.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::font::Font;
66
use crate::rgb::Rgb;
77
use crate::serialize::SerializeSettings;
88
use crate::stream::Glyph;
9-
use crate::tests::{write_manual_to_store, ASSETS_PATH, COLR_TEST_GLYPHS, DEJAVU_SANS_MONO, NOTO_SANS, NOTO_SANS_ARABIC, NOTO_SANS_CJK, NOTO_SANS_DEVANAGARI, load_jpg_image};
9+
use crate::tests::{
10+
load_jpg_image, write_manual_to_store, ASSETS_PATH, COLR_TEST_GLYPHS, DEJAVU_SANS_MONO,
11+
NOTO_SANS, NOTO_SANS_ARABIC, NOTO_SANS_CJK, NOTO_SANS_DEVANAGARI,
12+
};
1013
use crate::util::SliceExt;
1114
use crate::Fill;
1215
use skrifa::instance::{Location, LocationRef, Size};

src/tests/visreg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ fn image_rgba16_png(surface: &mut Surface) {
189189
png_image_impl(surface, "rgba16.png");
190190
}
191191

192-
#[visreg(all)]
192+
#[visreg(pdfium, mupdf, pdfbox, pdfjs, poppler, quartz)]
193193
fn image_luma8_jpg(surface: &mut Surface) {
194194
jpg_image_impl(surface, "luma8.jpg");
195195
}
196196

197-
#[visreg(all)]
197+
#[visreg(pdfium, mupdf, pdfbox, pdfjs, poppler, quartz)]
198198
fn image_rgb8_jpg(surface: &mut Surface) {
199199
jpg_image_impl(surface, "rgb8.jpg");
200200
}

0 commit comments

Comments
 (0)