Skip to content

Commit

Permalink
Eliminating need for call to as_pdf_line() in push_shape()
Browse files Browse the repository at this point in the history
  • Loading branch information
gmadrid committed Jan 5, 2023
1 parent 6a4ec25 commit 62fa877
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/bin/weekly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<F: Fn(&WRect, usize, &mut Instructions)> GridDescription for SimpleDescript

if row == 0 {
instructions.set_fill_color(Colors::black());
instructions.push_shape(cell_rect.as_pdf_line());
instructions.push_shape(cell_rect);

instructions.set_fill_color(Colors::white());
instructions.push_text(
Expand Down Expand Up @@ -146,7 +146,7 @@ fn render_left_circle(rect: &WRect, instructions: &mut Instructions) {
let y = rect.bottom_q1() + radius;

let circle = Circle::at_zero(radius - 1.15.mm()).move_to(x, y);
instructions.push_shape(circle.as_pdf_line());
instructions.push_shape(circle);
}

fn render_days(rect: &WRect) -> Result<Instructions> {
Expand Down Expand Up @@ -235,7 +235,7 @@ fn render_weekly(_: &PdfDocumentReference, page_rect: &WRect) -> Result<Instruct
for i in 0..7 {
let l = small_grid_left + rect.height() * i;
let wline = WLine::line(l, rect.bottom_q1(), l, rect.top());
instructions.push_shape(wline.as_pdf_line())
instructions.push_shape(wline)
}
instructions.pop_state();
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/pdfutils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::units::Unit;
use crate::{Result, WRect};
use crate::{AsPdfLine, Result, WRect};
use printpdf::*;
use std::collections::HashMap;
use std::fs::File;
Expand Down Expand Up @@ -37,8 +37,9 @@ impl Instructions {
self.instructions.push(Instruction::Translate(x, y));
}

pub fn push_shape(&mut self, shape: Line) {
self.instructions.push(Instruction::Shape(shape));
pub fn push_shape(&mut self, shape: impl AsPdfLine) {
self.instructions
.push(Instruction::Shape(shape.as_pdf_line()))
}

pub fn push_text(&mut self, s: &str, text_height: f64, x: Unit, y: Unit, font: FontProxy) {
Expand Down
6 changes: 6 additions & 0 deletions src/shapes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ pub(crate) mod rect;
pub trait AsPdfLine {
fn as_pdf_line(&self) -> Line;
}

impl AsPdfLine for Line {
fn as_pdf_line(&self) -> Line {
self.clone()
}
}
7 changes: 7 additions & 0 deletions src/shapes/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,10 @@ impl AsPdfLine for WRect {
}
}
}

impl AsPdfLine for &WRect {
fn as_pdf_line(&self) -> Line {
// TODO: Can I eliminate this clone?
(*self).clone().as_pdf_line()
}
}

0 comments on commit 62fa877

Please sign in to comment.