diff options
| author | Sébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com> | 2024-07-04 11:27:34 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-04 18:27:34 +0000 |
| commit | b847cccba41371a8ab485ed0f774890188c3ca98 (patch) | |
| tree | 28b9bfd072984c587e8c8388cb6f2f99c40290d6 | |
| parent | 3b32aa7929e9e7cc411647c3e32f1538ba2bf5c2 (diff) | |
Go from `String` to `&str` when passing font names to SVG code (#4500)
| -rw-r--r-- | crates/typst/src/visualize/image/mod.rs | 4 | ||||
| -rw-r--r-- | crates/typst/src/visualize/image/svg.rs | 10 |
2 files changed, 7 insertions, 7 deletions
diff --git a/crates/typst/src/visualize/image/mod.rs b/crates/typst/src/visualize/image/mod.rs index fbbedfb3..5d952b1a 100644 --- a/crates/typst/src/visualize/image/mod.rs +++ b/crates/typst/src/visualize/image/mod.rs @@ -196,7 +196,7 @@ fn layout_image( format, elem.alt(styles), engine.world, - &families(styles).map(|s| s.into()).collect::<Vec<_>>(), + &families(styles).collect::<Vec<_>>(), ) .at(span)?; @@ -360,7 +360,7 @@ impl Image { format: ImageFormat, alt: Option<EcoString>, world: Tracked<dyn World + '_>, - families: &[String], + families: &[&str], ) -> StrResult<Image> { let kind = match format { ImageFormat::Raster(format) => { diff --git a/crates/typst/src/visualize/image/svg.rs b/crates/typst/src/visualize/image/svg.rs index 09319ccd..f7a498a8 100644 --- a/crates/typst/src/visualize/image/svg.rs +++ b/crates/typst/src/visualize/image/svg.rs @@ -40,7 +40,7 @@ impl SvgImage { pub fn with_fonts( data: Bytes, world: Tracked<dyn World + '_>, - families: &[String], + families: &[&str], ) -> StrResult<SvgImage> { let book = world.book(); let resolver = Mutex::new(FontResolver::new(world, book, families)); @@ -142,7 +142,7 @@ struct FontResolver<'a> { /// The world we use to load fonts. world: Tracked<'a, dyn World + 'a>, /// The active list of font families at the location of the SVG. - families: &'a [String], + families: &'a [&'a str], /// A mapping from Typst font indices to fontdb IDs. to_id: HashMap<usize, Option<fontdb::ID>>, /// The reverse mapping. @@ -156,7 +156,7 @@ impl<'a> FontResolver<'a> { fn new( world: Tracked<'a, dyn World + 'a>, book: &'a FontBook, - families: &'a [String], + families: &'a [&'a str], ) -> Self { Self { book, @@ -191,11 +191,11 @@ impl FontResolver<'_> { font.families() .iter() .filter_map(|family| match family { - usvg::FontFamily::Named(named) => Some(named), + usvg::FontFamily::Named(named) => Some(named.as_str()), // We don't support generic families at the moment. _ => None, }) - .chain(self.families) + .chain(self.families.iter().copied()) .filter_map(|named| self.book.select(&named.to_lowercase(), variant)) .find_map(|index| self.get_or_load(index, db)) } |
