diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-31 16:31:21 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-31 16:33:33 +0200 |
| commit | 5f97e0a77348d4fb1c89a9adf671647f1fa86dc3 (patch) | |
| tree | 2800a61d06ac7cae8e57cb361804c530b1843bb8 /src/export | |
| parent | 00f11ae56d6d20b92a8c6ad6f2245c3ad3e94d86 (diff) | |
Make `Paint` not implement `Copy`
Diffstat (limited to 'src/export')
| -rw-r--r-- | src/export/pdf/page.rs | 20 | ||||
| -rw-r--r-- | src/export/render.rs | 12 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index f3c81cb8..8f767e87 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -215,8 +215,8 @@ impl PageContext<'_, '_> { } } - fn set_fill(&mut self, fill: Paint) { - if self.state.fill != Some(fill) { + fn set_fill(&mut self, fill: &Paint) { + if self.state.fill.as_ref() != Some(fill) { let f = |c| c as f32 / 255.0; let Paint::Solid(color) = fill; match color { @@ -233,7 +233,7 @@ impl PageContext<'_, '_> { self.content.set_fill_cmyk(f(c.c), f(c.m), f(c.y), f(c.k)); } } - self.state.fill = Some(fill); + self.state.fill = Some(fill.clone()); } } @@ -248,8 +248,8 @@ impl PageContext<'_, '_> { self.state.fill_space = None; } - fn set_stroke(&mut self, stroke: Stroke) { - if self.state.stroke != Some(stroke) { + fn set_stroke(&mut self, stroke: &Stroke) { + if self.state.stroke.as_ref() != Some(stroke) { let f = |c| c as f32 / 255.0; let Paint::Solid(color) = stroke.paint; match color { @@ -268,7 +268,7 @@ impl PageContext<'_, '_> { } self.content.set_line_width(stroke.thickness.to_f32()); - self.state.stroke = Some(stroke); + self.state.stroke = Some(stroke.clone()); } } @@ -335,7 +335,7 @@ fn write_text(ctx: &mut PageContext, x: f32, y: f32, text: &TextItem) { .or_default() .extend(text.glyphs.iter().map(|g| g.id)); - ctx.set_fill(text.fill); + ctx.set_fill(&text.fill); ctx.set_font(&text.font, text.size); ctx.content.begin_text(); @@ -386,11 +386,11 @@ fn write_shape(ctx: &mut PageContext, x: f32, y: f32, shape: &Shape) { return; } - if let Some(fill) = shape.fill { + if let Some(fill) = &shape.fill { ctx.set_fill(fill); } - if let Some(stroke) = shape.stroke { + if let Some(stroke) = &shape.stroke { ctx.set_stroke(stroke); } @@ -413,7 +413,7 @@ fn write_shape(ctx: &mut PageContext, x: f32, y: f32, shape: &Shape) { } } - match (shape.fill, shape.stroke) { + match (&shape.fill, &shape.stroke) { (None, None) => unreachable!(), (Some(_), None) => ctx.content.fill_nonzero(), (None, Some(_)) => ctx.content.stroke(), diff --git a/src/export/render.rs b/src/export/render.rs index 11ab5447..dc87f447 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -223,7 +223,7 @@ fn render_outline_glyph( builder.0.finish()? }; - let paint = text.fill.into(); + let paint = (&text.fill).into(); let rule = sk::FillRule::default(); // Flip vertically because font design coordinate @@ -302,7 +302,7 @@ fn render_shape( Geometry::Path(ref path) => convert_path(path)?, }; - if let Some(fill) = shape.fill { + if let Some(fill) = &shape.fill { let mut paint: sk::Paint = fill.into(); if matches!(shape.geometry, Geometry::Rect(_)) { paint.anti_alias = false; @@ -312,7 +312,7 @@ fn render_shape( canvas.fill_path(&path, &paint, rule, ts, mask); } - if let Some(Stroke { paint, thickness }) = shape.stroke { + if let Some(Stroke { paint, thickness }) = &shape.stroke { let paint = paint.into(); let stroke = sk::Stroke { width: thickness.to_f32(), ..Default::default() }; canvas.stroke_path(&path, &paint, &stroke, ts, mask); @@ -428,10 +428,10 @@ impl From<Transform> for sk::Transform { } } -impl From<Paint> for sk::Paint<'static> { - fn from(paint: Paint) -> Self { +impl From<&Paint> for sk::Paint<'static> { + fn from(paint: &Paint) -> Self { let mut sk_paint = sk::Paint::default(); - let Paint::Solid(color) = paint; + let Paint::Solid(color) = *paint; sk_paint.set_color(color.into()); sk_paint.anti_alias = true; sk_paint |
