Class: PDF::Reader::CMap
- Inherits:
-
Object
- Object
- PDF::Reader::CMap
- Defined in:
- lib/pdf/reader/cmap.rb
Overview
wraps a string containing a PDF CMap and provides convenience methods for extracting various useful information.
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#decode(c) ⇒ Object
Convert a glyph code into one or more Codepoints.
-
#initialize(data) ⇒ CMap
constructor
A new instance of CMap.
- #process_data(data) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(data) ⇒ CMap
Returns a new instance of CMap.
37 38 39 40 |
# File 'lib/pdf/reader/cmap.rb', line 37 def initialize(data) @map = {} process_data(data) end |
Instance Attribute Details
#map ⇒ Object (readonly)
:nodoc:
35 36 37 |
# File 'lib/pdf/reader/cmap.rb', line 35 def map @map end |
Instance Method Details
#decode(c) ⇒ Object
Convert a glyph code into one or more Codepoints.
Returns an array of Fixnums.
73 74 75 76 77 |
# File 'lib/pdf/reader/cmap.rb', line 73 def decode(c) # TODO: implement the conversion return c unless c.class == Fixnum @map[c] end |
#process_data(data) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pdf/reader/cmap.rb', line 42 def process_data(data) mode = nil instructions = "" data.each_line do |l| if l.include?("beginbfchar") mode = :char elsif l.include?("endbfchar") process_bfchar_instructions(instructions) instructions = "" mode = nil elsif l.include?("beginbfrange") mode = :range elsif l.include?("endbfrange") process_bfrange_instructions(instructions) instructions = "" mode = nil elsif mode == :char || mode == :range instructions << l end end end |
#size ⇒ Object
65 66 67 |
# File 'lib/pdf/reader/cmap.rb', line 65 def size @map.size end |