diff options
| author | Martin Haug <mhaug@live.de> | 2023-04-20 11:23:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-20 11:23:03 +0200 |
| commit | 2a682f0008b91e7c33c6e65b3ecfc690268ab405 (patch) | |
| tree | 1af18b7de6230bafce1a2e7eaff20f614b88f7df /src/export | |
| parent | 4524539c2bc5f3a9f53bc57a1902264fc894969b (diff) | |
Add alt text to image function and PDF (#823)
Diffstat (limited to 'src/export')
| -rw-r--r-- | src/export/pdf/page.rs | 16 | ||||
| -rw-r--r-- | src/export/render.rs | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index d6ead124..94650a3f 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -483,7 +483,21 @@ fn write_image(ctx: &mut PageContext, x: f32, y: f32, image: &Image, size: Size) let h = size.y.to_f32(); ctx.content.save_state(); ctx.content.transform([w, 0.0, 0.0, -h, x, y + h]); - ctx.content.x_object(Name(name.as_bytes())); + + if let Some(alt) = image.alt() { + let mut image_span = + ctx.content.begin_marked_content_with_properties(Name(b"Span")); + let mut image_alt = image_span.properties_direct(); + image_alt.pair(Name(b"Alt"), pdf_writer::Str(alt.as_bytes())); + image_alt.finish(); + image_span.finish(); + + ctx.content.x_object(Name(name.as_bytes())); + ctx.content.end_marked_content(); + } else { + ctx.content.x_object(Name(name.as_bytes())); + } + ctx.content.restore_state(); } diff --git a/src/export/render.rs b/src/export/render.rs index 3c2cea8d..b3a8f5ce 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -238,7 +238,7 @@ fn render_bitmap_glyph( let size = text.size.to_f32(); let ppem = size * ts.sy; let raster = text.font.ttf().glyph_raster_image(id, ppem as u16)?; - let image = Image::new(raster.data.into(), raster.format.into()).ok()?; + let image = Image::new(raster.data.into(), raster.format.into(), None).ok()?; // FIXME: Vertical alignment isn't quite right for Apple Color Emoji, // and maybe also for Noto Color Emoji. And: Is the size calculation |
