Parent

Methods

Prawn::Svg::Parser::Path

Public Instance Methods

parse(data) click to toggle source

Parses an SVG path and returns a Prawn-compatible call tree.

# File lib/prawn/svg/parser/path.rb, line 17
def parse(data)
  @subpath_initial_point = @last_point = nil
  @previous_control_point = @previous_quadratic_control_point = nil
  @calls = []

  data = data.gsub(/#{OUTSIDE_SPACE_REGEXP}$/, '')

  matched_commands = match_all(data, COMMAND_REGEXP)
  raise InvalidError, "Invalid/unsupported syntax for SVG path data" if matched_commands.nil?

  matched_commands.each do |matched_command|
    command = matched_command[1]
    matched_values = match_all(matched_command[2], VALUES_REGEXP)
    raise "should be impossible to have invalid inside data, but we ended up here" if matched_values.nil?
    values = matched_values.collect {|value| value[1].to_f}
    run_path_command(command, values)
  end

  @calls
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.