class HexaPDF::Font::Encoding::GlyphList
-
github.com/adobe-type-tools/agl-specification<br>* github.com/adobe-type-tools/agl-aglfn<br>See:
of a particular Unicode string is reverse-mapped.
text, this (not unique) reverse mapping is also available. However, only the first occurence
Since a reverse mapping is needed for converting UTF-8 strings to glyph names when encoding
e.g. the glyph name for ‘A’ and the glyph name for ‘small capital A’.
is not a one-to-one mapping because some glyphs are mapped to the same Unicode sequence,
The Adobe Glyph List is used for mapping glyph names to Unicode values. The mapping itself
Provides access to and mapping functionality for the Adobe Glyph List.
def self.name_to_unicode(name, zapf_dingbats: false)
def self.name_to_unicode(name, zapf_dingbats: false) new.name_to_unicode(name, zapf_dingbats: zapf_dingbats) end
def self.new
def self.new @instance ||= super end
def self.unicode_to_name(unicode, zapf_dingbats: false)
def self.unicode_to_name(unicode, zapf_dingbats: false) new.unicode_to_name(unicode, zapf_dingbats: zapf_dingbats) end
def initialize #:nodoc:
def initialize #:nodoc: load end
def load
def load @standard_name_to_uni, @standard_uni_to_name = load_file(File.join(HexaPDF.data_dir, 'encoding', 'glyphlist.txt')) @zapf_name_to_uni, @zapf_uni_to_name = load_file(File.join(HexaPDF.data_dir, 'encoding', 'zapfdingbats.txt')) end
def load_file(file)
* The unicode-to-name mapping is *not* unique! It only uses the first occurence of a
more characters.
* The name-to-unicode mapping maps a name (Symbol) to an UTF-8 string consisting of one or
Regarding the mappings:
unicode-to-name mappings.
Loads an Adobe Glyph List from the specified file and returns the name-to-unicode and
def load_file(file) name2uni = {} uni2name = {} File.open(file, 'rb:UTF-8') do |f| 25.times { f.gets } # Skip comments while (line = f.gets) name, codes = line.split(';', 2) name = name.to_sym name2uni[name] = codes.chomp! uni2name[codes] = name unless uni2name.key?(codes) end end [name2uni.freeze, uni2name.freeze] end
def name_to_unicode(name, zapf_dingbats: false)
Assumes that the name is a Symbol and that it includes just one component (no
option needs to be set to +true+.
If this method is invoked when dealing with the ZapfDingbats font, the +zapf_dingbats+
if the name has no correct mapping.
Maps the given name to a string by following the Adobe Glyph Specification. Returns +nil+
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
def unicode_to_name(unicode, zapf_dingbats: false)
If this method is invoked when dealing with the ZapfDingbats font, the +zapf_dingbats+
if there is no mapping.
Maps the given Unicode codepoint/string to a name in the Adobe Glyph List, or to .notdef
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