Class: Pdfrb::Font::CMap::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/font/cmap/parser.rb

Overview

Minimal CMap text parser. Extracts begincodespacerange, beginbfchar, beginbfrange sections into a simple Hash mapping source codes to target Unicode strings.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



12
13
14
15
16
# File 'lib/pdfrb/font/cmap/parser.rb', line 12

def initialize
  @codespace = []
  @bfchar = {}
  @bfrange = []
end

Instance Attribute Details

#bfcharObject (readonly)

Returns the value of attribute bfchar.



10
11
12
# File 'lib/pdfrb/font/cmap/parser.rb', line 10

def bfchar
  @bfchar
end

#bfrangeObject (readonly)

Returns the value of attribute bfrange.



10
11
12
# File 'lib/pdfrb/font/cmap/parser.rb', line 10

def bfrange
  @bfrange
end

#cmap_nameObject (readonly)

Returns the value of attribute cmap_name.



10
11
12
# File 'lib/pdfrb/font/cmap/parser.rb', line 10

def cmap_name
  @cmap_name
end

#codespaceObject (readonly)

Returns the value of attribute codespace.



10
11
12
# File 'lib/pdfrb/font/cmap/parser.rb', line 10

def codespace
  @codespace
end

#system_infoObject (readonly)

Returns the value of attribute system_info.



10
11
12
# File 'lib/pdfrb/font/cmap/parser.rb', line 10

def system_info
  @system_info
end

Class Method Details

.parse(text) ⇒ Object



18
19
20
# File 'lib/pdfrb/font/cmap/parser.rb', line 18

def self.parse(text)
  new.tap { |p| p.parse(text) }
end

Instance Method Details

#decode(code) ⇒ Object



35
36
37
# File 'lib/pdfrb/font/cmap/parser.rb', line 35

def decode(code)
  @bfchar[code]
end

#parse(text) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pdfrb/font/cmap/parser.rb', line 22

def parse(text)
  text.each_line do |line|
    stripped = line.strip
    case stripped
    when /\/CMapName\s+\/(\S+)/ then @cmap_name = Regexp.last_match(1)
    when /\Abegincodespacerange/
      read_section(text, line, :codespacerange)
    end
  end
  parse_bfchar_sections(text)
  parse_bfrange_sections(text)
end