summaryrefslogtreecommitdiff
path: root/src/export/pdf.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/pdf.rs
parent7b6f3a0ab9ae0dac19f62b62b9ecc96ea942a89e (diff)
Move rounding logic out of exporters
Diffstat (limited to 'src/export/pdf.rs')
-rw-r--r--src/export/pdf.rs46
1 files changed, 13 insertions, 33 deletions
diff --git a/src/export/pdf.rs b/src/export/pdf.rs
index f5401dfb..7cd6fbfc 100644
--- a/src/export/pdf.rs
+++ b/src/export/pdf.rs
@@ -16,9 +16,10 @@ use ttf_parser::{name_id, GlyphId, Tag};
use super::subset::subset;
use crate::font::{find_name, FaceId, FontStore};
-use crate::frame::{rect_path, rect_paths, Element, Frame, Geometry, Group, Shape, Text};
+use crate::frame::{Element, Frame, Group, Text};
use crate::geom::{
- self, Color, Em, Length, Numeric, Paint, Point, Sides, Size, Stroke, Transform,
+ self, Color, Em, Geometry, Length, Numeric, Paint, Point, Shape, Size, Stroke,
+ Transform,
};
use crate::image::{Image, ImageId, ImageStore, RasterImage};
use crate::Context;
@@ -499,16 +500,16 @@ impl<'a> PageExporter<'a> {
}
fn write_shape(&mut self, x: f32, y: f32, shape: &Shape) {
- if shape.fill.is_none() && shape.stroke.iter().all(Option::is_none) {
+ if shape.fill.is_none() && shape.stroke.is_none() {
return;
}
match shape.geometry {
- Geometry::Rect(size, radius) => {
+ Geometry::Rect(size) => {
let w = size.x.to_f32();
let h = size.y.to_f32();
if w > 0.0 && h > 0.0 {
- self.write_path(x, y, &rect_path(size, radius));
+ self.content.rect(x, y, w, h);
}
}
Geometry::Ellipse(size) => {
@@ -530,37 +531,16 @@ impl<'a> PageExporter<'a> {
self.set_fill(fill);
}
- // The stroke does not exist or is non-uniform.
- let mut use_stroke = false;
- if shape.stroke.is_uniform() || !matches!(shape.geometry, Geometry::Rect(_, _)) {
- if let Some(stroke) = shape.stroke.top {
- self.set_stroke(stroke);
- use_stroke = true;
- }
+ if let Some(stroke) = shape.stroke {
+ self.set_stroke(stroke);
}
- match (shape.fill, use_stroke) {
- (None, false) => self.content.end_path(),
- (Some(_), false) => self.content.fill_nonzero(),
- (None, true) => self.content.stroke(),
- (Some(_), true) => self.content.fill_nonzero_and_stroke(),
+ match (shape.fill, shape.stroke) {
+ (None, None) => unreachable!(),
+ (Some(_), None) => self.content.fill_nonzero(),
+ (None, Some(_)) => self.content.stroke(),
+ (Some(_), Some(_)) => self.content.fill_nonzero_and_stroke(),
};
-
- if let Geometry::Rect(size, radius) = shape.geometry {
- if !use_stroke {
- for (path, stroke) in rect_paths(size, radius, Some(shape.stroke)) {
- if let Some(stroke) = stroke {
- self.write_shape(x, y, &Shape {
- geometry: Geometry::Path(path),
- fill: None,
- stroke: Sides::splat(Some(stroke)),
- });
- } else {
- continue;
- }
- }
- }
- }
}
fn write_path(&mut self, x: f32, y: f32, path: &geom::Path) {