simplepath.rb revision facee090e6a4eb876ad2dc0b99ea8b4d06a71536
# 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
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
command = token
else
raise 'Invalid path, must begin with moveto.'
end
else
#command was omited
#use last command's implicit next command
if lastCommand
if lastCommand =~ /[A-Z]/
else
end
else
raise 'Invalid path, no initial command.'
end
end
else
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
def translatePath(p, x, y)
for i in 0...(params.length)
case coord_types[i]
end
end
end
end
for i in 0...(params.length)
case coord_types[i]
end
end
end
end
def rotatePath(p, a, cx = 0, cy = 0)
return p if a == 0
for i in 0...(params.length)
if coord_types[i] == :x
end
end
end
end
end