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.
Constant Summary collapse
- CMAP_KEYWORDS =
:nodoc:
{ "begincodespacerange" => 1, "endcodespacerange" => 1, "beginbfchar" => 1, "endbfchar" => 1, "beginbfrange" => 1, "endbfrange" => 1, "begin" => 1, "begincmap" => 1, "def" => 1 }
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
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.
48 49 50 51 |
# File 'lib/pdf/reader/cmap.rb', line 48 def initialize(data) @map = {} process_data(data) end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
46 47 48 |
# File 'lib/pdf/reader/cmap.rb', line 46 def map @map end |
Instance Method Details
#decode(c) ⇒ Object
Convert a glyph code into one or more Codepoints.
Returns an array of Integers.
85 86 87 88 89 |
# File 'lib/pdf/reader/cmap.rb', line 85 def decode(c) # TODO: implement the conversion return c unless Integer === c @map[c] end |
#process_data(data) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pdf/reader/cmap.rb', line 53 def process_data(data) parser = build_parser(data) mode = nil instructions = [] while token = parser.parse_token(CMAP_KEYWORDS) if token == "beginbfchar" mode = :char elsif token == "endbfchar" process_bfchar_instructions(instructions) instructions = [] mode = nil elsif token == "beginbfrange" mode = :range elsif token == "endbfrange" process_bfrange_instructions(instructions) instructions = [] mode = nil elsif mode == :char || mode == :range instructions << token end end end |
#size ⇒ Object
77 78 79 |
# File 'lib/pdf/reader/cmap.rb', line 77 def size @map.size end |