Method: PDF::Reader::GlyphHash#name_to_unicode
- Defined in:
- lib/pdf/reader/glyph_hash.rb
#name_to_unicode(name) ⇒ Object
attempt to convert a PDF Name to a unicode codepoint. Returns nil if no conversion is possible.
h = GlyphHash.new
h.name_to_unicode(:A)
=> 65
h.name_to_unicode(:Euro)
=> 8364
h.name_to_unicode(:X4A)
=> 74
h.name_to_unicode(:G30)
=> 48
h.name_to_unicode(:34)
=> 34
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pdf/reader/glyph_hash.rb', line 62 def name_to_unicode(name) return nil unless name.is_a?(Symbol) name = name.to_s.gsub('_', '').intern str = name.to_s if @by_name.has_key?(name) @by_name[name] elsif str.match(/\AX[0-9a-fA-F]{2,4}\Z/) "0x#{str[1,4]}".hex 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,5}\Z/) str[1,5].to_i elsif str.match(/\A[A-Za-z]{2}\d{2,5}\Z/) str[2,5].to_i else nil end end |