Optionally owned data in PDF crate ✈

This commit is contained in:
Laurenz 2019-03-29 23:55:48 +01:00
parent af212da34e
commit 094648e86b

View File

@ -142,23 +142,19 @@ impl<'a, W: Write> PdfCreator<'a, W> {
} }
fn write_text(&mut self, id: u32, text: &DocText) -> PdfResult<()> { 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 object = Text::new();
let mut nr = 0; let mut current_font = 0;
for command in &text.commands { for command in &text.commands {
match command { match command {
TextCommand::Text(_) => { TextCommand::Text(string) => {
object.tj(&encoded[nr]); let encoded = self.fonts[current_font].encode(&string);
nr += 1; 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()); }, TextCommand::Move(x, y) => { object.td(x.to_points(), y.to_points()); },
} }
} }