Class: HexaPDF::Font::Encoding::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/font/encoding/base.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Creates a new encoding object containing no default mappings.



54
55
56
57
58
# File 'lib/hexapdf/font/encoding/base.rb', line 54

def initialize
  @code_to_name = {}
  @unicode_cache = {}
  @encoding_name = nil
end

Instance Attribute Details

#code_to_nameObject (readonly)

The hash mapping codes to names.



51
52
53
# File 'lib/hexapdf/font/encoding/base.rb', line 51

def code_to_name
  @code_to_name
end

#encoding_nameObject (readonly)

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



48
49
50
# File 'lib/hexapdf/font/encoding/base.rb', line 48

def encoding_name
  @encoding_name
end

Instance Method Details

#code(name) ⇒ Object

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.



80
81
82
# File 'lib/hexapdf/font/encoding/base.rb', line 80

def code(name)
  @code_to_name.key(name)
end

#name(code) ⇒ Object

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!



63
64
65
# File 'lib/hexapdf/font/encoding/base.rb', line 63

def name(code)
  @code_to_name.fetch(code, :'.notdef')
end

#unicode(code) ⇒ Object

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.



72
73
74
# File 'lib/hexapdf/font/encoding/base.rb', line 72

def unicode(code)
  @unicode_cache[code] ||= GlyphList.name_to_unicode(name(code))
end