Skip to content

Commit

Permalink
Think I removed printpdf::Line from the weekly API.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmadrid committed Jan 6, 2023
1 parent fc16555 commit f710861
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
11 changes: 4 additions & 7 deletions src/bin/projects.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use printpdf::PdfDocumentReference;
use weekly::{
save_one_page_document, Colors, HasRenderAttrs, Instructions, LineModifiers, NumericUnit, Unit,
WLine, WRect,
save_one_page_document, Colors, HasRenderAttrs, Instructions, NumericUnit, Unit, WLine, WRect,
};

fn render_projects(_: &PdfDocumentReference, page_bounds: &WRect) -> weekly::Result<Instructions> {
Expand Down Expand Up @@ -49,11 +48,9 @@ fn fill_project_into_rect(rect: WRect, instructions: &mut Instructions) {
instructions.set_stroke_width(1.0);

// Outline
instructions.push_shape(
rect.as_rounded_rect_shape(0.125.inches())
.fill(false)
.stroke(true),
);
let mut outline = rect.clone();
outline.set_corner_radius(0.125.inches());
instructions.push_shape(outline.fill().stroke());

// Project title line
instructions.push_shape(
Expand Down
12 changes: 5 additions & 7 deletions src/bin/weekly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use argh::FromArgs;
use printpdf::PdfDocumentReference;
use weekly::{
save_one_page_document, sizes, Attributes, Circle, Colors, GridDescription, HasRenderAttrs,
Instructions, LineModifiers, NumericUnit, Result, TGrid, TextContext, Unit, WLine, WRect,
Instructions, NumericUnit, Result, TGrid, TextContext, Unit, WLine, WRect,
};

const GOLDEN_RATIO: f64 = 1.618033988749894;
Expand Down Expand Up @@ -351,12 +351,10 @@ fn render_dotted(_: &PdfDocumentReference, dotted_rect: &WRect, instructions: &m
instructions.clear_fill_color();
instructions.set_stroke_color(Colors::gray(0.7));
instructions.set_stroke_width(0.5);
instructions.push_shape(
dotted_rect
.as_rounded_rect_shape(2.0.mm())
.fill(false)
.stroke(true),
);

let mut rounded_rect = dotted_rect.clone();
rounded_rect.set_corner_radius(2.0.mm());
instructions.push_shape(rounded_rect.stroke());

instructions.set_fill_color(Colors::gray(0.7));
let grid_spacing = 0.25.inches();
Expand Down
7 changes: 0 additions & 7 deletions src/shapes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,3 @@ where
line
}
}

impl ToPdfLine for Line {
fn to_pdf_line(&self) -> Line {
// TODO: make this thing go awqy! I think it's only used for rounded rects.
self.clone()
}
}
34 changes: 22 additions & 12 deletions src/shapes/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use printpdf::*;
#[derive(Debug, Clone)]
pub struct WRect {
render_attrs: RenderAttrsImpl,
corner_radius: Option<Unit>,

top: Unit,
left: Unit,
Expand All @@ -18,6 +19,7 @@ impl WRect {
pub const fn with_dimensions(width: Unit, height: Unit) -> WRect {
WRect {
render_attrs: RenderAttrsImpl::new(),
corner_radius: None,
top: Unit::zero(),
left: Unit::zero(),
width,
Expand All @@ -28,6 +30,7 @@ impl WRect {
pub fn at(left: Unit, top: Unit) -> WRect {
WRect {
render_attrs: RenderAttrsImpl::default(),
corner_radius: None,
top,
left,
width: Unit::zero(),
Expand Down Expand Up @@ -84,6 +87,10 @@ impl WRect {
self.inset_all_q1(xdelta, ydelta, xdelta, ydelta)
}

pub fn set_corner_radius(&mut self, radius: Unit) {
self.corner_radius = Some(radius);
}

pub fn inset_all_q1(
&self,
left_inset: Unit,
Expand All @@ -101,7 +108,7 @@ impl WRect {
}
}

pub fn as_rounded_rect_shape(&self, radius: Unit) -> Line {
fn as_rounded_rect_shape(&self, radius: Unit) -> Line {
let pv = 1.0_f64 - 0.55228;
Line {
points: vec![
Expand All @@ -122,7 +129,6 @@ impl WRect {
point_pair(self.left() + radius * pv, self.top(), false),
point_pair(self.left() + radius, self.top(), false),
],
has_fill: true,
is_closed: true,
..Line::default()
}
Expand All @@ -143,16 +149,20 @@ impl AsMut<RenderAttrsImpl> for WRect {

impl ToPlainPdfLine for WRect {
fn to_plain_pdf_line(&self) -> Line {
Line {
// In Q1, rects grow downward toward the bottom.
points: vec![
point_pair(self.left, self.top, false),
point_pair(self.left + self.width, self.top, false),
point_pair(self.left + self.width, self.top - self.height, false),
point_pair(self.left, self.top - self.height, false),
],
is_closed: true,
..Line::default()
if let Some(radius) = self.corner_radius {
self.as_rounded_rect_shape(radius)
} else {
Line {
// In Q1, rects grow downward toward the bottom.
points: vec![
point_pair(self.left, self.top, false),
point_pair(self.left + self.width, self.top, false),
point_pair(self.left + self.width, self.top - self.height, false),
point_pair(self.left, self.top - self.height, false),
],
is_closed: true,
..Line::default()
}
}
}
}

0 comments on commit f710861

Please sign in to comment.