class HexaPDF::Font::Encoding::Base

Base for encoding classes that are used for mapping codes in the range of 0 to 255 to glyph names.

Attributes

code_to_name[R]

The hash mapping codes to names.

encoding_name[R]

The name of the encoding or nil if the encoding has not been assigned a name.

Public Class Methods

new() click to toggle source

Creates a new encoding object containing no default mappings.

# File lib/hexapdf/font/encoding/base.rb, line 53
def initialize
  @code_to_name = {}
  @unicode_cache = {}
  @encoding_name = nil
end

Public Instance Methods

code(name) click to toggle source

Returns the code for the given glyph name (a Symbol) or nil if there is no code for the given glyph name.

If multiple codes reference the given glyph name, the first found is always returned.

# File lib/hexapdf/font/encoding/base.rb, line 79
def code(name)
  @code_to_name.key(name)
end
name(code) click to toggle source

Returns the name for the given code, or .notdef if no glyph for the code is defined.

The returned value is always a Symbol object!

# File lib/hexapdf/font/encoding/base.rb, line 62
def name(code)
  @code_to_name.fetch(code, :'.notdef')
end
unicode(code) click to toggle source

Returns the Unicode value in UTF-8 for the given code, or nil if the code cannot be mapped.

Note that this method caches the result of the Unicode mapping and therefore should only be called after all codes have been defined.

# File lib/hexapdf/font/encoding/base.rb, line 71
def unicode(code)
  @unicode_cache[code] ||= GlyphList.name_to_unicode(name(code))
end