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

The name of the encoding, as used in the font object.

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("☺"));

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('☺'));

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.