diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-11-30 22:07:08 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-11-30 22:07:08 +0100 |
| commit | fdc1b378a3eb3cf325592b801c43e2ec2478ddff (patch) | |
| tree | 0e83aa07d7ec49ac494746b44869d0306f5648fe /tests | |
| parent | 21857064db8ca1bdf61b6e5ee37dff1a15083189 (diff) | |
Compress images in PDFs ⚙
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/README.md | 2 | ||||
| -rw-r--r-- | tests/cmp/coma.png (renamed from tests/ref/coma.png) | bin | 79107 -> 79107 bytes | |||
| -rw-r--r-- | tests/cmp/image.png | bin | 0 -> 281515 bytes | |||
| -rw-r--r-- | tests/ref/image.png | bin | 299090 -> 0 bytes | |||
| -rw-r--r-- | tests/res/rhino.png | bin | 0 -> 232243 bytes | |||
| -rw-r--r-- | tests/res/tiger-alpha.png | bin | 122035 -> 0 bytes | |||
| -rw-r--r-- | tests/typ/image.typ | 4 | ||||
| -rw-r--r-- | tests/typeset.rs | 16 |
8 files changed, 11 insertions, 11 deletions
diff --git a/tests/README.md b/tests/README.md index 6ebba237..89c31c89 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,6 +3,6 @@ - `typ`: Input files - `pdf`: PDF files produced by tests - `png`: PNG files produced by tests -- `ref`: Reference images which the PNGs are compared to byte-wise to determine +- `cmp`: Reference images which the PNGs are compared to byte-wise to determine whether the test passed or failed - `res`: Resource files used by tests diff --git a/tests/ref/coma.png b/tests/cmp/coma.png Binary files differindex d0c524ec..d0c524ec 100644 --- a/tests/ref/coma.png +++ b/tests/cmp/coma.png diff --git a/tests/cmp/image.png b/tests/cmp/image.png Binary files differnew file mode 100644 index 00000000..5bf744e9 --- /dev/null +++ b/tests/cmp/image.png diff --git a/tests/ref/image.png b/tests/ref/image.png Binary files differdeleted file mode 100644 index 37349600..00000000 --- a/tests/ref/image.png +++ /dev/null diff --git a/tests/res/rhino.png b/tests/res/rhino.png Binary files differnew file mode 100644 index 00000000..f9d47dd3 --- /dev/null +++ b/tests/res/rhino.png diff --git a/tests/res/tiger-alpha.png b/tests/res/tiger-alpha.png Binary files differdeleted file mode 100644 index 178b4b65..00000000 --- a/tests/res/tiger-alpha.png +++ /dev/null diff --git a/tests/typ/image.typ b/tests/typ/image.typ index 0dd22950..6ae349a1 100644 --- a/tests/typ/image.typ +++ b/tests/typ/image.typ @@ -6,8 +6,8 @@ # Tiger [image: "res/tiger.jpg", width=2cm] -[image: "res/tiger-alpha.png", width=1cm] -[image: "res/tiger-alpha.png", height=2cm] +[image: "res/rhino.png", width=1cm] +[image: "res/rhino.png", height=2cm] [pagebreak] diff --git a/tests/typeset.rs b/tests/typeset.rs index cc146fe4..807215ed 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -6,7 +6,7 @@ use std::path::Path; use std::rc::Rc; use fontdock::fs::{FsIndex, FsSource}; -use image::{DynamicImage, GenericImageView, Rgba}; +use image::{GenericImageView, Rgba}; use memmap::Mmap; use tiny_skia::{ Canvas, Color, ColorU8, FillRule, FilterQuality, Paint, PathBuilder, Pattern, Pixmap, @@ -15,7 +15,7 @@ use tiny_skia::{ use ttf_parser::OutlineBuilder; use typst::diag::{Feedback, Pass}; -use typst::env::{Env, ResourceLoader, SharedEnv}; +use typst::env::{Env, ImageResource, ResourceLoader, SharedEnv}; use typst::eval::State; use typst::export::pdf; use typst::font::FontLoader; @@ -29,7 +29,7 @@ const FONT_DIR: &str = "../fonts"; const TYP_DIR: &str = "typ"; const PDF_DIR: &str = "pdf"; const PNG_DIR: &str = "png"; -const REF_DIR: &str = "ref"; +const CMP_DIR: &str = "cmp"; fn main() { env::set_current_dir(env::current_dir().unwrap().join("tests")).unwrap(); @@ -46,7 +46,7 @@ fn main() { let name = src_path.file_stem().unwrap().to_string_lossy().to_string(); let pdf_path = Path::new(PDF_DIR).join(&name).with_extension("pdf"); let png_path = Path::new(PNG_DIR).join(&name).with_extension("png"); - let ref_path = Path::new(REF_DIR).join(&name).with_extension("png"); + let ref_path = Path::new(CMP_DIR).join(&name).with_extension("png"); if filter.matches(&name) { filtered.push((name, src_path, pdf_path, png_path, ref_path)); @@ -247,8 +247,8 @@ fn draw_text(canvas: &mut Canvas, pos: Point, env: &Env, shaped: &Shaped) { } } -fn draw_image(canvas: &mut Canvas, pos: Point, env: &Env, image: &ImageElement) { - let buf = env.resources.get_loaded::<DynamicImage>(image.res); +fn draw_image(canvas: &mut Canvas, pos: Point, env: &Env, img: &ImageElement) { + let buf = &env.resources.get_loaded::<ImageResource>(img.res).buf; let mut pixmap = Pixmap::new(buf.width(), buf.height()).unwrap(); for ((_, _, src), dest) in buf.pixels().zip(pixmap.pixels_mut()) { @@ -256,8 +256,8 @@ fn draw_image(canvas: &mut Canvas, pos: Point, env: &Env, image: &ImageElement) *dest = ColorU8::from_rgba(r, g, b, a).premultiply(); } - let view_width = image.size.width.to_pt() as f32; - let view_height = image.size.height.to_pt() as f32; + let view_width = img.size.width.to_pt() as f32; + let view_height = img.size.height.to_pt() as f32; let x = pos.x.to_pt() as f32; let y = pos.y.to_pt() as f32; |
