summaryrefslogtreecommitdiff
path: root/src/export/render.rs
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2022-05-02 16:51:14 +0200
committerMartin Haug <mhaug@live.de>2022-05-02 17:20:47 +0200
commitf07395f9a47502c50f767f78a233d0e2a6e4445f (patch)
treec54fe2afeaaf265780279c893c272f1abfd12393 /src/export/render.rs
parent7b6f3a0ab9ae0dac19f62b62b9ecc96ea942a89e (diff)
Move rounding logic out of exporters
Diffstat (limited to 'src/export/render.rs')
-rw-r--r--src/export/render.rs42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/export/render.rs b/src/export/render.rs
index 9c674acb..50257e1c 100644
--- a/src/export/render.rs
+++ b/src/export/render.rs
@@ -7,10 +7,11 @@ use tiny_skia as sk;
use ttf_parser::{GlyphId, OutlineBuilder};
use usvg::FitTo;
-use crate::frame::{Element, Frame, Geometry, Group, Shape, Text};
-use crate::geom::{self, Length, Paint, PathElement, Sides, Size, Stroke, Transform};
+use crate::frame::{Element, Frame, Group, Text};
+use crate::geom::{
+ self, Geometry, Length, Paint, PathElement, Shape, Size, Stroke, Transform,
+};
use crate::image::{Image, RasterImage, Svg};
-use crate::library::prelude::{rect_path, rect_paths};
use crate::Context;
/// Export a frame into a rendered image.
@@ -299,7 +300,12 @@ fn render_shape(
shape: &Shape,
) -> Option<()> {
let path = match shape.geometry {
- Geometry::Rect(size, radius) => convert_path(&rect_path(size, radius))?,
+ Geometry::Rect(size) => {
+ let w = size.x.to_f32();
+ let h = size.y.to_f32();
+ let rect = sk::Rect::from_xywh(0.0, 0.0, w, h)?;
+ sk::PathBuilder::from_rect(rect)
+ }
Geometry::Ellipse(size) => convert_path(&geom::Path::ellipse(size))?,
Geometry::Line(target) => {
let mut builder = sk::PathBuilder::new();
@@ -311,7 +317,7 @@ fn render_shape(
if let Some(fill) = shape.fill {
let mut paint: sk::Paint = fill.into();
- if matches!(shape.geometry, Geometry::Rect(_, _)) {
+ if matches!(shape.geometry, Geometry::Rect(_)) {
paint.anti_alias = false;
}
@@ -319,27 +325,11 @@ fn render_shape(
canvas.fill_path(&path, &paint, rule, ts, mask);
}
- if shape.stroke.is_uniform() || !matches!(shape.geometry, Geometry::Rect(_, _)) {
- if let Some(Stroke { paint, thickness }) = shape.stroke.top {
- let paint = paint.into();
- let mut stroke = sk::Stroke::default();
- stroke.width = thickness.to_f32();
- canvas.stroke_path(&path, &paint, &stroke, ts, mask);
- }
- } else {
- if let Geometry::Rect(size, radius) = shape.geometry {
- for (path, stroke) in rect_paths(size, radius, Some(shape.stroke)) {
- if let Some(stroke) = stroke {
- render_shape(canvas, ts, mask, &Shape {
- geometry: Geometry::Path(path),
- fill: None,
- stroke: Sides::splat(Some(stroke)),
- })?;
- } else {
- continue;
- }
- }
- }
+ if let Some(Stroke { paint, thickness }) = shape.stroke {
+ let paint = paint.into();
+ let mut stroke = sk::Stroke::default();
+ stroke.width = thickness.to_f32();
+ canvas.stroke_path(&path, &paint, &stroke, ts, mask);
}
Some(())