-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding TextContext to try to simplify text rendering. (Moved pdfutils…
… to subdir.)
- Loading branch information
Showing
4 changed files
with
81 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::{FontProxy, Instructions, NumericUnit, Unit}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct TextContext { | ||
proxy: FontProxy, | ||
text_height: Unit, | ||
} | ||
|
||
impl TextContext { | ||
pub fn times() -> TextContext { | ||
TextContext { | ||
proxy: FontProxy::Times(false, false), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn helvetica() -> TextContext { | ||
TextContext { | ||
proxy: FontProxy::Helvetica(false, false), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn with_text_height(&self, text_height: Unit) -> TextContext { | ||
TextContext { | ||
text_height, | ||
..*self | ||
} | ||
} | ||
|
||
pub fn bold(&self, bold: bool) -> TextContext { | ||
TextContext { | ||
proxy: self.proxy.bold(bold), | ||
..*self | ||
} | ||
} | ||
|
||
pub fn render(&self, txt: impl AsRef<str>, x: Unit, y: Unit, instructions: &mut Instructions) { | ||
instructions.push_text(txt.as_ref(), self.text_height.to_mm(), x, y, self.proxy); | ||
} | ||
} | ||
|
||
impl Default for TextContext { | ||
fn default() -> Self { | ||
TextContext { | ||
proxy: Default::default(), | ||
text_height: 12.0.mm(), | ||
} | ||
} | ||
} |