Skip to content

Commit

Permalink
src/types/pdf_layer.rs: add write_positioned_codepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerdietmar committed Oct 2, 2020
1 parent f338198 commit 8e0d883
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/types/pdf_layer.rs
Expand Up @@ -403,6 +403,31 @@ impl PdfLayerReference {
));
}

/// Add text to the file at the current position by specifying
/// font codepoints with additional kerning offset
pub fn write_positioned_codepoints<I>(&self, codepoints: I)
where I: IntoIterator<Item = (i64, u16)>
{
use lopdf::Object::*;
use lopdf::StringFormat::Hexadecimal;

let mut list = Vec::new();

for (pos, codepoint) in codepoints {
if pos != 0 {
list.push(Integer(pos));
}
let bytes = codepoint.to_be_bytes().to_vec();
list.push(String(bytes, Hexadecimal));
}

let doc = self.document.upgrade().unwrap();
let mut doc = doc.borrow_mut();
doc.pages[self.page.0]
.layers[self.layer.0]
.operations.push(Operation::new("TJ", vec![Array(list)]));
}

/// Add text to the file at the current position
#[inline]
pub fn write_text<S>(&self, text: S, font: &IndirectFontRef)
Expand Down

0 comments on commit 8e0d883

Please sign in to comment.