Class: PDF::Reader::GlyphHash
- Inherits:
-
Object
- Object
- PDF::Reader::GlyphHash
- Defined in:
- lib/pdf/reader/glyph_hash.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#[](name) ⇒ Object
attempt to convert a PDF Name to a unicode codepoint.
-
#initialize ⇒ GlyphHash
constructor
A new instance of GlyphHash.
Constructor Details
#initialize ⇒ GlyphHash
Returns a new instance of GlyphHash.
28 29 30 |
# File 'lib/pdf/reader/glyph_hash.rb', line 28 def initialize @adobe = 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]
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pdf/reader/glyph_hash.rb', line 48 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 |