Struct pdf_canvas::Encoding
source · [−]pub struct Encoding { /* private fields */ }
Expand description
Represent a text encoding used in PDF. An encoding maintains the connection between unicode code points, bytes in PDF strings, and glyph names.
Currently, only WIN_ANSI_ENCODING, SYMBOL_ENCODING, and ZAPFDINGBATS_ENCODING are supported, and they are provided as built-in.
Example
use pdf_canvas::{BuiltinFont, FontSource};
assert_eq!("WinAnsiEncoding",
BuiltinFont::Helvetica.get_encoding().get_name());
assert_eq!("SymbolEncoding",
BuiltinFont::Symbol.get_encoding().get_name());
Implementations
sourceimpl Encoding
impl Encoding
sourcepub fn get_code(&self, name: &str) -> Option<u8>
pub fn get_code(&self, name: &str) -> Option<u8>
Get the encoded code point from a type1 character name. Character names are case sensitive and contains only ascii letters. If the name is not available in the encoding, or is not a proper character name, None is returned.
Example
use pdf_canvas::{BuiltinFont, FontSource};
let enc = BuiltinFont::Helvetica.get_encoding();
assert_eq!(Some(32), enc.get_code("space"));
assert_eq!(Some(65), enc.get_code("A"));
assert_eq!(Some(229), enc.get_code("aring"));
assert_eq!(None, enc.get_code("Lslash"));
assert_eq!(None, enc.get_code(""));
assert_eq!(None, enc.get_code("☺"));
sourcepub fn encode_char(&self, ch: char) -> Option<u8>
pub fn encode_char(&self, ch: char) -> Option<u8>
Get the encoded code point from a (unicode) character. If the character is not available in the encoding, None is returned.
Example
use pdf_canvas::{BuiltinFont, FontSource};
let enc = BuiltinFont::Helvetica.get_encoding();
assert_eq!(Some(b' '), enc.encode_char(' '));
assert_eq!(Some(b'A'), enc.encode_char('A'));
assert_eq!(Some(b'\\'), enc.encode_char('\\'));
assert_eq!(Some(229), enc.encode_char('å'));
assert_eq!(None, enc.encode_char('Ł'));
assert_eq!(None, enc.encode_char(char::from(0)));
assert_eq!(None, enc.encode_char('☺'));
sourcepub fn encode_string(&self, text: &str) -> Vec<u8>
pub fn encode_string(&self, text: &str) -> Vec<u8>
Convert a rust string to a vector of bytes in the encoding.
Example
use pdf_canvas::{BuiltinFont, FontSource};
let enc = BuiltinFont::Helvetica.get_encoding();
let symb_enc = BuiltinFont::Symbol.get_encoding();
assert_eq!(vec![b'A', b'B', b'C'], enc.encode_string("ABC"));
assert_eq!(vec![b'R', 228, b'k',
b's', b'm', 246, b'r', b'g', 229, b's'],
enc.encode_string("Räksmörgås"));
assert_eq!(vec![b'C', b'o', b'f', b'f', b'e', b'e', b' ',
128, b'1', b'.', b'2', b'0'],
enc.encode_string("Coffee €1.20"));
assert_eq!(vec![b'a', b' ', 206, b' ', 194],
symb_enc.encode_string("α ∈ ℜ"));
Trait Implementations
impl Eq for Encoding
impl StructuralEq for Encoding
impl StructuralPartialEq for Encoding
Auto Trait Implementations
impl RefUnwindSafe for Encoding
impl Send for Encoding
impl Sync for Encoding
impl Unpin for Encoding
impl UnwindSafe for Encoding
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more