summaryrefslogtreecommitdiff
path: root/src/export
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-20 13:05:55 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-20 16:37:15 +0200
commit757a701c1aa2a6fb80033c7e75666661818da6f9 (patch)
tree0415fec94d3856f4ebc97a1744cf2ba75fe8e7aa /src/export
parente29f55bb294cc298daad97accf6d8a76976b409c (diff)
A New World
Diffstat (limited to 'src/export')
-rw-r--r--src/export/pdf/image.rs70
-rw-r--r--src/export/render.rs4
2 files changed, 33 insertions, 41 deletions
diff --git a/src/export/pdf/image.rs b/src/export/pdf/image.rs
index 7886524c..f148bb7d 100644
--- a/src/export/pdf/image.rs
+++ b/src/export/pdf/image.rs
@@ -16,48 +16,40 @@ pub fn write_images(ctx: &mut PdfContext) {
let height = image.height();
// Add the primary image.
+ // TODO: Error if image could not be encoded.
match image.decode().unwrap() {
DecodedImage::Raster(dynamic) => {
- if let Ok((data, filter, has_color)) =
- encode_image(image.format(), &dynamic)
- {
- let mut image = ctx.writer.image_xobject(image_ref, &data);
- image.filter(filter);
- image.width(width as i32);
- image.height(height as i32);
- image.bits_per_component(8);
-
- let space = image.color_space();
- if has_color {
- space.device_rgb();
- } else {
- space.device_gray();
- }
-
- // Add a second gray-scale image containing the alpha values if
- // this image has an alpha channel.
- if dynamic.color().has_alpha() {
- let (alpha_data, alpha_filter) = encode_alpha(&dynamic);
- let mask_ref = ctx.alloc.bump();
- image.s_mask(mask_ref);
- image.finish();
-
- let mut mask = ctx.writer.image_xobject(mask_ref, &alpha_data);
- mask.filter(alpha_filter);
- mask.width(width as i32);
- mask.height(height as i32);
- mask.color_space().device_gray();
- mask.bits_per_component(8);
- }
+ // TODO: Error if image could not be encoded.
+ let (data, filter, has_color) =
+ encode_image(image.format(), &dynamic).unwrap();
+
+ let mut image = ctx.writer.image_xobject(image_ref, &data);
+ image.filter(filter);
+ image.width(width as i32);
+ image.height(height as i32);
+ image.bits_per_component(8);
+
+ let space = image.color_space();
+ if has_color {
+ space.device_rgb();
} else {
- // TODO: Warn that image could not be encoded.
- ctx.writer
- .image_xobject(image_ref, &[])
- .width(0)
- .height(0)
- .bits_per_component(1)
- .color_space()
- .device_gray();
+ space.device_gray();
+ }
+
+ // Add a second gray-scale image containing the alpha values if
+ // this image has an alpha channel.
+ if dynamic.color().has_alpha() {
+ let (alpha_data, alpha_filter) = encode_alpha(&dynamic);
+ let mask_ref = ctx.alloc.bump();
+ image.s_mask(mask_ref);
+ image.finish();
+
+ let mut mask = ctx.writer.image_xobject(mask_ref, &alpha_data);
+ mask.filter(alpha_filter);
+ mask.width(width as i32);
+ mask.height(height as i32);
+ mask.color_space().device_gray();
+ mask.bits_per_component(8);
}
}
DecodedImage::Svg(svg) => {
diff --git a/src/export/render.rs b/src/export/render.rs
index bf735ded..3fb57ad6 100644
--- a/src/export/render.rs
+++ b/src/export/render.rs
@@ -147,8 +147,8 @@ fn render_svg_glyph(
}
// Parse XML.
- let src = std::str::from_utf8(data).ok()?;
- let document = roxmltree::Document::parse(src).ok()?;
+ let xml = std::str::from_utf8(data).ok()?;
+ let document = roxmltree::Document::parse(xml).ok()?;
let root = document.root_element();
// Parse SVG.