Class: PDF::Reader::GlyphHash
- Inherits:
-
Object
- Object
- PDF::Reader::GlyphHash
- Defined in:
- lib/pdf/reader/glyph_hash.rb
Overview
A Hash-like object that can convert glyph names into a unicode codepoint. The mapping is read from a data file on disk the first time it’s needed.
Instance Method Summary collapse
-
#[](name) ⇒ Object
attempt to convert a PDF Name to a unicode codepoint.
-
#initialize ⇒ GlyphHash
constructor
:nodoc:.
Constructor Details
#initialize ⇒ GlyphHash
:nodoc:
33 34 35 36 |
# File 'lib/pdf/reader/glyph_hash.rb', line 33 def initialize # only parse the glyph list once, and cache the results (for performance) @adobe = @@cache ||= load_adobe_glyph_mapping end |
Instance Method Details
#[](name) ⇒ Object
attempt to convert a PDF Name to a unicode codepoint. Returns nil if no conversion is possible.
h = GlyphHash.new
h[:A]
=> 65
h[:Euro]
=> 8364
h[:G30]
=> 48
h[:34]
=> 34
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pdf/reader/glyph_hash.rb', line 55 def [](name) return nil unless name.is_a?(Symbol) name = name.to_s.gsub('_', '').intern str = name.to_s if @adobe.has_key?(name) @adobe[name] elsif str.match(/\Auni[A-F\d]{4}\Z/) "0x#{str[3,4]}".hex elsif str.match(/\Au[A-F\d]{4,6}\Z/) "0x#{str[1,6]}".hex elsif str.match(/\A[A-Za-z]\d{1,4}\Z/) str[1,4].to_i elsif str.match(/\A[A-Za-z]{2}\d{2,4}\Z/) str[2,4].to_i else nil end end |