Class: PDF::Reader::CMap

Inherits:
Object
  • Object
show all
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)

Instance Method Summary (collapse)

Constructor Details

- (CMap) initialize(data)

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

- (Object) map (readonly)

:nodoc:



35
36
37
# File 'lib/pdf/reader/cmap.rb', line 35

def map
  @map
end

Instance Method Details

- (Object) decode(c)

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

- (Object) process_data(data)



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

- (Object) size



65
66
67
# File 'lib/pdf/reader/cmap.rb', line 65

def size
  @map.size
end