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
272 273 274 275 276 |
# File 'lib/fontisan/type1/charstrings.rb', line 272 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.
261 262 263 |
# File 'lib/fontisan/type1/charstrings.rb', line 261 def commands @commands end |
#private_dict ⇒ PrivateDict (readonly)
Returns Private dictionary.
267 268 269 |
# File 'lib/fontisan/type1/charstrings.rb', line 267 def private_dict @private_dict end |
#seac_components ⇒ Hash? (readonly)
Returns seac components if seac found.
264 265 266 |
# File 'lib/fontisan/type1/charstrings.rb', line 264 def seac_components @seac_components end |
Instance Method Details
#parse(charstring) ⇒ Array
Parse CharString bytecode
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/fontisan/type1/charstrings.rb', line 282 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 |