diff options
Diffstat (limited to 'src/export/render.rs')
| -rw-r--r-- | src/export/render.rs | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/src/export/render.rs b/src/export/render.rs index 7dd78c5f..89e45b15 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -193,13 +193,21 @@ fn render_svg_glyph( // be on the safe size. We also compute the intersection // with the canvas rectangle let svg_ts = usvg::Transform::new( - ts.sx.into(), ts.kx.into(), - ts.ky.into(), ts.sy.into(), - ts.tx.into(), ts.ty.into()); - let bbox = bbox.transform(&svg_ts)? - .to_screen_rect(); - let bbox = usvg::ScreenRect::new(bbox.left()-5, bbox.y()-5, bbox.width()+10, bbox.height()+10)? - .fit_to_rect(canvas_rect); + ts.sx.into(), + ts.kx.into(), + ts.ky.into(), + ts.sy.into(), + ts.tx.into(), + ts.ty.into(), + ); + let bbox = bbox.transform(&svg_ts)?.to_screen_rect(); + let bbox = usvg::ScreenRect::new( + bbox.left() - 5, + bbox.y() - 5, + bbox.width() + 10, + bbox.height() + 10, + )? + .fit_to_rect(canvas_rect); let mut pixmap = sk::Pixmap::new(bbox.width(), bbox.height())?; @@ -207,7 +215,14 @@ fn render_svg_glyph( let ts = ts.post_translate(-bbox.left() as f32, -bbox.top() as f32); resvg::render(&tree, FitTo::Original, ts, pixmap.as_mut())?; - canvas.draw_pixmap(bbox.left(), bbox.top(), pixmap.as_ref(), &sk::PixmapPaint::default(), sk::Transform::identity(), mask) + canvas.draw_pixmap( + bbox.left(), + bbox.top(), + pixmap.as_ref(), + &sk::PixmapPaint::default(), + sk::Transform::identity(), + mask, + ) } /// Render a bitmap glyph into the canvas. @@ -282,32 +297,39 @@ fn render_outline_glyph( // Pad the pixmap with 1 pixel in each dimension so that we do // not get any problem with floating point errors along ther border - let mut pixmap = sk::Pixmap::new(mw+2, mh+2)?; + let mut pixmap = sk::Pixmap::new(mw + 2, mh + 2)?; for x in 0..mw { for y in 0..mh { let alpha = bitmap.coverage[(y * mw + x) as usize]; let color = sk::ColorU8::from_rgba(c.r, c.g, c.b, alpha).premultiply(); - pixmap.pixels_mut()[((y+1) * (mw+2) + (x+1)) as usize] = color; + pixmap.pixels_mut()[((y + 1) * (mw + 2) + (x + 1)) as usize] = color; } } let left = bitmap.left; let top = bitmap.top; - canvas.draw_pixmap(left-1, top-1, pixmap.as_ref(), &sk::PixmapPaint::default(), sk::Transform::identity(), mask) + canvas.draw_pixmap( + left - 1, + top - 1, + pixmap.as_ref(), + &sk::PixmapPaint::default(), + sk::Transform::identity(), + mask, + ) } else { - let cw = canvas.width() as i32; - let ch = canvas.height() as i32; - let mw = bitmap.width as i32; - let mh = bitmap.height as i32; - - // Determine the pixel bounding box that we actually need to draw. - let left = bitmap.left; - let right = left + mw; - let top = bitmap.top; - let bottom = top + mh; - - // Premultiply the text color. + let cw = canvas.width() as i32; + let ch = canvas.height() as i32; + let mw = bitmap.width as i32; + let mh = bitmap.height as i32; + + // Determine the pixel bounding box that we actually need to draw. + let left = bitmap.left; + let right = left + mw; + let top = bitmap.top; + let bottom = top + mh; + + // Premultiply the text color. let Paint::Solid(color) = text.fill; let c = color.to_rgba(); let color = sk::ColorU8::from_rgba(c.r, c.g, c.b, 255).premultiply().get(); |
