Class: HexaPDF::Font::Encoding::GlyphList

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

Overview

Provides access to and mapping functionality for the Adobe Glyph List.

The Adobe Glyph List is used for mapping glyph names to Unicode values. The mapping itself is not a one-to-one mapping because some glyphs are mapped to the same Unicode sequence, e.g. the glyph name for ‘A’ and the glyph name for ‘small capital A’.

Since a reverse mapping is needed for converting UTF-8 strings to glyph names when encoding text, this (not unique) reverse mapping is also available. However, only the first occurence of a particular Unicode string is reverse-mapped.

See:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlyphList

:nodoc:



70
71
72
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 70

def initialize #:nodoc:
  load
end

Class Method Details

.name_to_unicode(name, zapf_dingbats: false) ⇒ Object

See #name_to_unicode



61
62
63
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 61

def self.name_to_unicode(name, zapf_dingbats: false)
  new.name_to_unicode(name, zapf_dingbats: zapf_dingbats)
end

.newObject

Creates and returns the single GlyphList instance.



56
57
58
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 56

def self.new
  @instance ||= super
end

.unicode_to_name(unicode, zapf_dingbats: false) ⇒ Object

See #unicode_to_name



66
67
68
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 66

def self.unicode_to_name(unicode, zapf_dingbats: false)
  new.unicode_to_name(unicode, zapf_dingbats: zapf_dingbats)
end

Instance Method Details

#name_to_unicode(name, zapf_dingbats: false) ⇒ Object

Maps the given name to a string by following the Adobe Glyph Specification. An empty string is returned if the name has no correct mapping.

If this method is invoked when dealing with the ZapfDingbats font, the zapf_dingbats option needs to be set to true.

Assumes that the name is a Symbol and that it includes just one component (no underscores)!



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 82

def name_to_unicode(name, zapf_dingbats: false)
  if zapf_dingbats && @zapf_name_to_uni.key?(name)
    @zapf_name_to_uni[name]
  elsif @standard_name_to_uni.key?(name)
    @standard_name_to_uni[name]
  else
    name = name.to_s
    if name =~ /\Auni([0-9A-F]{4})\Z/ || name =~ /\Au([0-9A-f]{4,6})\Z/
      '' << $1.hex
    else
      ''
    end
  end
end

#unicode_to_name(unicode, zapf_dingbats: false) ⇒ Object

Maps the given Unicode codepoint/string to a name in the Adobe Glyph List, or to .notdef if there is no mapping.

If this method is invoked when dealing with the ZapfDingbats font, the zapf_dingbats option needs to be set to true.



102
103
104
105
106
107
108
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 102

def unicode_to_name(unicode, zapf_dingbats: false)
  if zapf_dingbats
    @zapf_uni_to_name.fetch(unicode, :'.notdef')
  else
    @standard_uni_to_name.fetch(unicode, :'.notdef')
  end
end