Module: Fontisan::SvgToGlyf::Path::Parser

Defined in:
lib/fontisan/svg_to_glyf/path/parser.rb

Overview

Tokenizes an SVG path d attribute string and groups the tokens into typed Command objects, handling implicit command repetition.

Arc (A/a) is not supported — ucode chart SVGs use cubic curves exclusively. Encountering A raises a clear ArgumentError.

Constant Summary collapse

COMMAND_RE =
/[MmLlHhVvCcSsQqTtAaZz]/
NUMBER_RE =
/[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/
TOKEN_RE =
/#{COMMAND_RE}|#{NUMBER_RE}/
ARITY =

Expected argument count per command letter.

{
  "M" => 2, "L" => 2, "H" => 1, "V" => 1,
  "C" => 6, "S" => 4, "Q" => 4, "T" => 2,
  "Z" => 0
}.freeze

Class Method Summary collapse

Class Method Details

.parse(d_string) ⇒ Array<Command>

Parameters:

  • d_string (String)

    SVG path data

Returns:



26
27
28
29
# File 'lib/fontisan/svg_to_glyf/path/parser.rb', line 26

def self.parse(d_string)
  tokens = tokenize(d_string)
  group_into_commands(tokens)
end