pub struct EmbeddedFont { /* private fields */ }Expand description
A font dictionary this session added, ready to name from a content stream.
EmbeddedFont::object is the /Font resource crate::content::ResourceTable::realize
will allocate a name for. EmbeddedFont::encode turns Unicode into the
character codes a Tj/TJ of that font expects.
Implementations§
Source§impl EmbeddedFont
impl EmbeddedFont
Sourcepub fn encode(&self, text: &str) -> Vec<u8> ⓘ
pub fn encode(&self, text: &str) -> Vec<u8> ⓘ
Character codes for text in this font’s encoding.
Unmappable characters become .notdef (code 0). A composite font
writes two-byte big-endian GIDs (Identity-H); a simple or standard
font writes one byte.
A font from EditDoc::embed_cid_font writes two-byte big-endian
CIDs, and finds them by inverting the caller’s /ToUnicode CMap
rather than by consulting the program’s cmap. That is not a
convenience: under a caller-supplied CMap the program’s cmap does not
describe the file’s code space, and the CMap is the document’s only
statement of what its codes mean. A character the CMap does not reach
is code 0, as everywhere else.
Sourcepub fn encode_checked(&self, text: &str) -> Result<Vec<u8>, MissingGlyph>
pub fn encode_checked(&self, text: &str) -> Result<Vec<u8>, MissingGlyph>
Character codes for text, refusing a character this font cannot
draw.
The same encoding as EmbeddedFont::encode, with the .notdef
fallback replaced by an error. This is what a caller who is placing
text wants: a watermark whose degree sign silently became a blank is
worse than one that refused to be written.
use pdfrum_edit::{EditDoc, StandardFont};
use pdfrum_parser::{LoadOptions, load};
use std::sync::Arc;
let bytes: Arc<[u8]> = Arc::from(&include_bytes!("../../tests/files/hello.pdf")[..]);
let doc = load(bytes, &LoadOptions::default())?;
let mut edit = EditDoc::new(&doc);
let font = edit.standard_font(StandardFont::Helvetica)?;
assert!(font.encode_checked("Hi").is_ok());
// WinAnsi has no Han: refused rather than drawn blank.
assert_eq!(font.encode_checked("\u{4e00}").unwrap_err().character, '\u{4e00}');§Errors
MissingGlyph naming the first character with no glyph, and its
byte offset in text.
Trait Implementations§
Source§impl Clone for EmbeddedFont
impl Clone for EmbeddedFont
Source§fn clone(&self) -> EmbeddedFont
fn clone(&self) -> EmbeddedFont
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more