Class: Fontisan::Type1::CharStrings::CharStringParser
- Inherits:
-
Object
- Object
- Fontisan::Type1::CharStrings::CharStringParser
- Defined in:
- lib/fontisan/type1/charstrings.rb
Overview
CharString parser
Parses Type 1 CharString bytecode into commands.
Instance Attribute Summary collapse
-
#commands ⇒ Array
readonly
Parsed commands.
-
#private_dict ⇒ PrivateDict
readonly
Private dictionary.
-
#seac_components ⇒ Hash?
readonly
Seac components if seac found.
Instance Method Summary collapse
-
#initialize(private_dict = nil) ⇒ CharStringParser
constructor
Initialize parser.
-
#parse(charstring) ⇒ Array
Parse CharString bytecode.
Constructor Details
#initialize(private_dict = nil) ⇒ CharStringParser
Initialize parser
305 306 307 308 309 |
# File 'lib/fontisan/type1/charstrings.rb', line 305 def initialize(private_dict = nil) @private_dict = private_dict || PrivateDict.new @commands = [] @seac_components = nil end |
Instance Attribute Details
#commands ⇒ Array (readonly)
Returns Parsed commands.
294 295 296 |
# File 'lib/fontisan/type1/charstrings.rb', line 294 def commands @commands end |
#private_dict ⇒ PrivateDict (readonly)
Returns Private dictionary.
300 301 302 |
# File 'lib/fontisan/type1/charstrings.rb', line 300 def private_dict @private_dict end |
#seac_components ⇒ Hash? (readonly)
Returns seac components if seac found.
297 298 299 |
# File 'lib/fontisan/type1/charstrings.rb', line 297 def seac_components @seac_components end |
Instance Method Details
#parse(charstring) ⇒ Array
Parse CharString bytecode
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/fontisan/type1/charstrings.rb', line 315 def parse(charstring) return [] if charstring.nil? || charstring.empty? @commands = [] @seac_components = nil i = 0 while i < charstring.length byte = charstring.getbyte(i) if byte <= 31 # Operator parse_operator(charstring, byte, i) break if @seac_components # Stop at seac for now i += 1 elsif byte == 255 # Escaped number (2 bytes follow) num = charstring.getbyte(i + 1) | (charstring.getbyte(i + 2) << 8) num = num - 32768 if num >= 32768 @commands << [:number, num] i += 3 elsif byte >= 32 && byte <= 246 # Small number (-107 to 107) num = byte - 139 @commands << [:number, num] i += 1 else # Unknown i += 1 end end @commands end |