From 2a682f0008b91e7c33c6e65b3ecfc690268ab405 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Thu, 20 Apr 2023 11:23:03 +0200 Subject: Add alt text to image function and PDF (#823) --- library/src/visualize/image.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'library/src/visualize') 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::>("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>, + /// A text describing the image. + pub alt: Option, + /// 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 { 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, full: &str, fallback_family: Option<&str>, + alt: Option, ) -> StrResult { 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) } -- cgit v1.2.3