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:



73
74
75
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 73

def initialize #:nodoc:
  load
end

Class Method Details

.name_to_unicode(name, zapf_dingbats: false) ⇒ Object

See #name_to_unicode



64
65
66
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 64

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.



59
60
61
# File 'lib/hexapdf/font/encoding/glyph_list.rb', line 59

def self.new
  @instance ||= super
end

.unicode_to_name(unicode, zapf_dingbats: false) ⇒ Object

See #unicode_to_name



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

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. Returns nil 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)!



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

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
    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.



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

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