Class: PDF::Reader::CMap

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/cmap.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CMap

Returns a new instance of CMap.



29
30
31
32
# File 'lib/pdf/reader/cmap.rb', line 29

def initialize(data)
  @map = {}
  process_data(data)
end

Instance Method Details

#decode(c) ⇒ Object



61
62
63
64
65
# File 'lib/pdf/reader/cmap.rb', line 61

def decode(c)
  # TODO: implement the conversion
  return c unless c.class == Fixnum
  @map[c]
end

#process_data(data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pdf/reader/cmap.rb', line 34

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

#sizeObject



57
58
59
# File 'lib/pdf/reader/cmap.rb', line 57

def size
  @map.size
end