Class: Pdfrb::Font::CMap::Parser
- Inherits:
-
Object
- Object
- Pdfrb::Font::CMap::Parser
- 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
-
#bfchar ⇒ Object
readonly
Returns the value of attribute bfchar.
-
#bfrange ⇒ Object
readonly
Returns the value of attribute bfrange.
-
#cmap_name ⇒ Object
readonly
Returns the value of attribute cmap_name.
-
#codespace ⇒ Object
readonly
Returns the value of attribute codespace.
-
#system_info ⇒ Object
readonly
Returns the value of attribute system_info.
Class Method Summary collapse
Instance Method Summary collapse
- #decode(code) ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(text) ⇒ Object
Constructor Details
#initialize ⇒ Parser
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
#bfchar ⇒ Object (readonly)
Returns the value of attribute bfchar.
10 11 12 |
# File 'lib/pdfrb/font/cmap/parser.rb', line 10 def bfchar @bfchar end |
#bfrange ⇒ Object (readonly)
Returns the value of attribute bfrange.
10 11 12 |
# File 'lib/pdfrb/font/cmap/parser.rb', line 10 def bfrange @bfrange end |
#cmap_name ⇒ Object (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 |
#codespace ⇒ Object (readonly)
Returns the value of attribute codespace.
10 11 12 |
# File 'lib/pdfrb/font/cmap/parser.rb', line 10 def codespace @codespace end |
#system_info ⇒ Object (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 |