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.



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

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

Instance Attribute Details

#code_to_nameObject (readonly)

The hash mapping codes to names.



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

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.



45
46
47
# File 'lib/hexapdf/font/encoding/base.rb', line 45

def encoding_name
  @encoding_name
end

Instance Method Details

#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!



60
61
62
# File 'lib/hexapdf/font/encoding/base.rb', line 60

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.



69
70
71
# File 'lib/hexapdf/font/encoding/base.rb', line 69

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