Struct pdf_canvas::Encoding
[−]
[src]
pub struct Encoding { /* fields omitted */ }
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 and SYMBOL_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());
Methods
impl Encoding
[src]
fn get_name(&self) -> String
The name of the encoding, as used in the font object.
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("☺"));
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!(65, 66, 67), enc.encode_string("ABC")); assert_eq!(vec!(82, 228, 107, 115, 109, 246, 114, 103, 229, 115), enc.encode_string("Räksmörgås")); assert_eq!(vec!(67, 111, 102, 102, 101, 101, 32, 128, 49, 46, 50, 48), enc.encode_string("Coffee €1.20")); assert_eq!(vec!(97, 32, 206, 32, 194), symb_enc.encode_string("α ∈ ℜ"));
Trait Implementations
impl Debug for Encoding
[src]
impl PartialEq for Encoding
[src]
fn eq(&self, __arg_0: &Encoding) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Encoding) -> bool
This method tests for !=
.
impl Eq for Encoding
[src]
impl Hash for Encoding
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl Clone for Encoding
[src]
fn clone(&self) -> Encoding
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more