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, 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());

Methods

impl Encoding
[src]

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

impl Debug for Encoding
[src]

Formats the value using the given formatter. Read more

impl PartialEq for Encoding
[src]

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

This method tests for !=.

impl Eq for Encoding
[src]

impl Hash for Encoding
[src]

Feeds this value into the given [Hasher]. Read more

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

impl Clone for Encoding
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Encoding

impl Sync for Encoding