diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-03-29 23:55:48 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-03-29 23:55:48 +0100 |
| commit | 094648e86b71e8850e9218a30810d10d3922b122 (patch) | |
| tree | b3fd257282db1be63cbf957ebd756cc48b72e7da /src | |
| parent | af212da34e09540181ccff7b5aca1b1a2633dfbf (diff) | |
Optionally owned data in PDF crate ✈
Diffstat (limited to 'src')
| -rw-r--r-- | src/pdf.rs | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -142,23 +142,19 @@ impl<'a, W: Write> PdfCreator<'a, W> { } fn write_text(&mut self, id: u32, text: &DocText) -> PdfResult<()> { - let mut current_font = 0; - let encoded = text.commands.iter().filter_map(|cmd| match cmd { - TextCommand::Text(string) => Some(self.fonts[current_font].encode(&string)), - TextCommand::SetFont(id, _) => { current_font = *id; None }, - _ => None, - }).collect::<Vec<_>>(); - let mut object = Text::new(); - let mut nr = 0; + let mut current_font = 0; for command in &text.commands { match command { - TextCommand::Text(_) => { - object.tj(&encoded[nr]); - nr += 1; + TextCommand::Text(string) => { + let encoded = self.fonts[current_font].encode(&string); + object.tj(encoded); + }, + TextCommand::SetFont(id, size) => { + current_font = *id; + object.tf(*id as u32 + 1, *size); }, - TextCommand::SetFont(id, size) => { object.tf(*id as u32 + 1, *size); }, TextCommand::Move(x, y) => { object.td(x.to_points(), y.to_points()); }, } } |
