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 /library | |
| parent | 4524539c2bc5f3a9f53bc57a1902264fc894969b (diff) | |
Add alt text to image function and PDF (#823)
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/visualize/image.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/library/src/visualize/image.rs b/library/src/visualize/image.rs index 4b8be5c7..86f87931 100644 --- a/library/src/visualize/image.rs +++ b/library/src/visualize/image.rs @@ -32,7 +32,7 @@ pub struct ImageElem { let Spanned { v: path, span } = args.expect::<Spanned<EcoString>>("path to image file")?; let path: EcoString = vm.locate(&path).at(span)?.to_string_lossy().into(); - let _ = load(vm.world(), &path, None).at(span)?; + let _ = load(vm.world(), &path, None, None).at(span)?; path )] pub path: EcoString, @@ -43,6 +43,9 @@ pub struct ImageElem { /// The height of the image. pub height: Smart<Rel<Length>>, + /// A text describing the image. + pub alt: Option<EcoString>, + /// How the image should adjust itself to a given area. #[default(ImageFit::Cover)] pub fit: ImageFit, @@ -57,7 +60,8 @@ impl Layout for ImageElem { ) -> SourceResult<Fragment> { let first = families(styles).next(); let fallback_family = first.as_ref().map(|f| f.as_str()); - let image = load(vt.world, &self.path(), fallback_family).unwrap(); + let image = + load(vt.world, &self.path(), fallback_family, self.alt(styles)).unwrap(); let sizing = Axes::new(self.width(styles), self.height(styles)); let region = sizing .zip(regions.base()) @@ -163,6 +167,7 @@ fn load( world: Tracked<dyn World>, full: &str, fallback_family: Option<&str>, + alt: Option<EcoString>, ) -> StrResult<Image> { let full = Path::new(full); let buffer = world.file(full)?; @@ -174,5 +179,5 @@ fn load( "svg" | "svgz" => ImageFormat::Vector(VectorFormat::Svg), _ => return Err("unknown image format".into()), }; - Image::with_fonts(buffer, format, world, fallback_family) + Image::with_fonts(buffer, format, world, fallback_family, alt) } |
