From dacd6acd5e73d35c6e7a7a3b144f16ae70d03daa Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 8 Jan 2025 11:57:56 +0100 Subject: More flexible and efficient `Bytes` representation (#5670) --- crates/typst-library/src/text/font/color.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/typst-library/src/text') diff --git a/crates/typst-library/src/text/font/color.rs b/crates/typst-library/src/text/font/color.rs index 08f6fe0a..e3183e88 100644 --- a/crates/typst-library/src/text/font/color.rs +++ b/crates/typst-library/src/text/font/color.rs @@ -7,6 +7,7 @@ use typst_syntax::Span; use usvg::tiny_skia_path; use xmlwriter::XmlWriter; +use crate::foundations::Bytes; use crate::layout::{Abs, Frame, FrameItem, Point, Size}; use crate::text::{Font, Glyph}; use crate::visualize::{FixedStroke, Geometry, Image, RasterFormat, VectorFormat}; @@ -101,8 +102,12 @@ fn draw_raster_glyph( upem: Abs, raster_image: ttf_parser::RasterGlyphImage, ) -> Option<()> { - let image = - Image::new(raster_image.data.into(), RasterFormat::Png.into(), None).ok()?; + let image = Image::new( + Bytes::new(raster_image.data.to_vec()), + RasterFormat::Png.into(), + None, + ) + .ok()?; // Apple Color emoji doesn't provide offset information (or at least // not in a way ttf-parser understands), so we artificially shift their @@ -175,7 +180,7 @@ fn draw_colr_glyph( let data = svg.end_document().into_bytes(); - let image = Image::new(data.into(), VectorFormat::Svg.into(), None).ok()?; + let image = Image::new(Bytes::new(data), VectorFormat::Svg.into(), None).ok()?; let y_shift = Abs::pt(upem.to_pt() - y_max); let position = Point::new(Abs::pt(x_min), y_shift); @@ -251,7 +256,7 @@ fn draw_svg_glyph( ); let image = - Image::new(wrapper_svg.into_bytes().into(), VectorFormat::Svg.into(), None) + Image::new(Bytes::new(wrapper_svg.into_bytes()), VectorFormat::Svg.into(), None) .ok()?; let position = Point::new(Abs::pt(left), Abs::pt(top) + upem); -- cgit v1.2.3