# functions for digesting paths into a simple list structure
#
# Ruby port by MenTaLguY
#
# Copyright (C) 2005 Aaron Spike <aaron@ekips.org>
# Copyright (C) 2006 MenTaLguY <mental@rydia.net>
#
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require 'strscan'
# iterator which breaks path data
# identifies command and parameter tokens
delim = /[ \t\r\n,]+/
command = /[MLHVCSQTAZmlhvcsqtaz]/
until scanner.eos?
if m = scanner.scan(command)
yield m, true
elsif m = scanner.scan(parameter)
yield m, false
else
#TODO: create new exception
raise 'Invalid path data!'
end
end
end
PATHDEFS = {
}
# Parse SVG path and return an array of segments.
# Removes all shorthand notation.
# Converts coordinates to absolute.
retval = []
command = nil
params = []
unless command
if isCommand
raise 'Invalid path, must begin with moveto.' \
command = token
else
#command was omited
#use last command's implicit next command
if lastCommand =~ /[A-Z]/
else
end
end
end
if command =~ /[a-z]/
end
end
end
#Flesh out shortcut notation
case outputCommand
case outputCommand
end
outputCommand = 'L'
case outputCommand
end
end
#current values become "last" values
case outputCommand
when 'M'
when 'Z'
else
end
case outputCommand
else
end
lastCommand = command
command = nil
params = []
end
end
raise 'Unexpected end of path' if command
return retval
end
# Format SVG path data from an array
end
for i in 0...(params.length)
yield params, i, coord_types[i]
end
end
end
def translatePath(p, x, y)
case coord_type
end
end
end
case coord_type
end
end
end
def rotatePath(p, a, cx = 0, cy = 0)
return p if a == 0
if coord_type == :x
end
end
end
end