Commit 7bfa6228 authored by Guillaume Seguin's avatar Guillaume Seguin

Reset svg to an older version as well

parent 3d0f4985
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" """
""" """
import wx import wx
def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise = False): def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise=False):
""" Draws an arc of an ellipse within bounding rect (x, y, w, h) """ Draws an arc of an ellipse within bounding rect (x,y,w,h)
from startArc to endArc (in radians, relative to the horizontal line of the eclipse)""" from startArc to endArc (in radians, relative to the horizontal line of the eclipse)"""
if True: if True:
import warnings import warnings
warnings.warn("elliptical arcs are not supported") warnings.warn("elliptical arcs are not supported")
...@@ -30,7 +15,7 @@ def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise = False): ...@@ -30,7 +15,7 @@ def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise = False):
h = h/2.0 h = h/2.0
self.AddArc(x+w, y+h, ((w+h)/2), startAngle, endAngle, clockwise) self.AddArc(x+w, y+h, ((w+h)/2), startAngle, endAngle, clockwise)
return return
else: else:
#implement in terms of AddArc by applying a transformation matrix #implement in terms of AddArc by applying a transformation matrix
#Sigh this can't work, still need to patch wx to allow #Sigh this can't work, still need to patch wx to allow
#either a) AddPath that's not a closed path or #either a) AddPath that's not a closed path or
...@@ -40,18 +25,19 @@ def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise = False): ...@@ -40,18 +25,19 @@ def AddEllipticalArc(self, x, y, w, h, startAngle, endAngle, clockwise = False):
#possibly be simulated by combining the current transform with option a. #possibly be simulated by combining the current transform with option a.
mtx = wx.GraphicsRenderer_GetDefaultRenderer().CreateMatrix() mtx = wx.GraphicsRenderer_GetDefaultRenderer().CreateMatrix()
path = wx.GraphicsRenderer_GetDefaultRenderer().CreatePath() path = wx.GraphicsRenderer_GetDefaultRenderer().CreatePath()
mtx.Translate(x+(w/2.0), y+(h/2.0)) mtx.Translate(x+(w/2.0), y+(h/2.0))
mtx.Scale(w/2.0, y/2.0) mtx.Scale(w/2.0, y/2.0)
path.AddArc(0, 0, 1, startAngle, endAngle, clockwise) path.AddArc(0, 0, 1, startAngle, endAngle, clockwise)
path.Transform(mtx) path.Transform(mtx)
self.AddPath(path) self.AddPath(path)
self.MoveToPoint(path.GetCurrentPoint()) self.MoveToPoint(path.GetCurrentPoint())
self.CloseSubpath() self.CloseSubpath()
if not hasattr(wx.GraphicsPath, "AddEllipticalArc"): if not hasattr(wx.GraphicsPath, "AddEllipticalArc"):
wx.GraphicsPath.AddEllipticalArc = AddEllipticalArc wx.GraphicsPath.AddEllipticalArc = AddEllipticalArc
del AddEllipticalArc del AddEllipticalArc
\ No newline at end of file
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" """
Parsers for specific attributes Parsers for specific attributes
""" """
import urlparse import urlparse
from pyparsing import (Literal, from pyparsing import (Literal,
Optional, oneOf, Group, StringEnd, Combine, Word, alphas, hexnums, Optional, oneOf, Group, StringEnd, Combine, Word, alphas, hexnums,
CaselessLiteral, SkipTo CaselessLiteral, SkipTo
) )
...@@ -36,23 +21,23 @@ def parsePossibleURL(t): ...@@ -36,23 +21,23 @@ def parsePossibleURL(t):
colorDeclaration = none | currentColor | colourValue colorDeclaration = none | currentColor | colourValue
urlEnd = ( urlEnd = (
Literal(")").suppress() + Literal(")").suppress() +
Optional(Group(colorDeclaration), default = ()) + Optional(Group(colorDeclaration), default=()) +
StringEnd() StringEnd()
) )
url = ( url = (
CaselessLiteral("URL") CaselessLiteral("URL")
+ +
Literal("(").suppress()+ Literal("(").suppress()+
Group(SkipTo(urlEnd, include = True).setParseAction(parsePossibleURL)) Group(SkipTo(urlEnd, include=True).setParseAction(parsePossibleURL))
) )
#paint value will parse into a (type, details) tuple. #paint value will parse into a (type, details) tuple.
#For none and currentColor, the details tuple will be the empty tuple #For none and currentColor, the details tuple will be the empty tuple
#for CSS color declarations, it will be (type, (R, G, B)) #for CSS color declarations, it will be (type, (R,G,B))
#for URLs, it will be ("URL", ((url tuple), fallback)) #for URLs, it will be ("URL", ((url tuple), fallback))
#The url tuple will be as returned by urlparse.urlsplit, and can be #The url tuple will be as returned by urlparse.urlsplit, and can be
#an empty tuple if the parser has an error #an empty tuple if the parser has an error
#The fallback will be another (type, details) tuple as a parsed #The fallback will be another (type, details) tuple as a parsed
#colorDeclaration, but may be the empty tuple if it is not present #colorDeclaration, but may be the empty tuple if it is not present
......
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import from __future__ import absolute_import
from .transform import transformList from .transform import transformList
from .inline import inlineStyle from .inline import inlineStyle
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" CSS at-rules""" """ CSS at-rules"""
from pyparsing import Literal, Combine from pyparsing import Literal, Combine
from .identifier import identifier from .identifier import identifier
atkeyword = Combine(Literal("@") + identifier) atkeyword = Combine(Literal("@") + identifier)
\ No newline at end of file
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" """
CSS blocks CSS blocks
""" """
...@@ -20,3 +5,4 @@ ...@@ -20,3 +5,4 @@
from pyparsing import nestedExpr from pyparsing import nestedExpr
block = nestedExpr(opener="{", closer="}") block = nestedExpr(opener="{", closer="}")
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" """
Parsing for CSS colour values. Parsing for CSS colour values.
Supported formats: Supported formats:
...@@ -36,31 +21,31 @@ comma = Literal(",").suppress() ...@@ -36,31 +21,31 @@ comma = Literal(",").suppress()
def clampColourByte(val): def clampColourByte(val):
val = int(val) val = int(val)
return min(max(0,val), 255) return min(max(0,val), 255)
def clampColourPerc(val): def clampColourPerc(val):
val = float(val) val = float(val)
return min(max(0,val), 100) return min(max(0,val), 100)
def parseColorPerc(token): def parseColorPerc(token):
val = token[0] val = token[0]
val = clampColourPerc(val) val = clampColourPerc(val)
#normalize to bytes #normalize to bytes
return int(255 * (val / 100.0)) return int(255 * (val / 100.0))
colorByte = Optional(sign) + integerConstant.setParseAction(lambda t: clampColourByte(t[0])) colorByte = Optional(sign) + integerConstant.setParseAction(lambda t: clampColourByte(t[0]))
colorPerc = number.setParseAction(parseColorPerc) + Literal("%").suppress() colorPerc = number.setParseAction(parseColorPerc) + Literal("%").suppress()
rgb = ( rgb = (
Literal("rgb(").setParseAction(lambda t: "RGB") + Literal("rgb(").setParseAction(lambda t: "RGB") +
( (
#integer constants, ie 255,255,255 #integer constants, ie 255,255,255
Group(colorByte + comma + colorByte + comma + colorByte) ^ Group(colorByte + comma + colorByte + comma + colorByte) ^
#percentage values, ie 100%, 50% #percentage values, ie 100%, 50%
Group(colorPerc + comma + colorPerc + comma + colorPerc) Group(colorPerc + comma + colorPerc + comma + colorPerc)
) )
+ +
Literal(")").suppress() + StringEnd() Literal(")").suppress() + StringEnd()
) )
...@@ -69,10 +54,10 @@ def parseShortHex(t): ...@@ -69,10 +54,10 @@ def parseShortHex(t):
doubleHex = Word(hexnums, exact=2).setParseAction(lambda t: int(t[0], 16)) doubleHex = Word(hexnums, exact=2).setParseAction(lambda t: int(t[0], 16))
hexLiteral = (Literal("#").setParseAction(lambda t: "RGB") + hexLiteral = (Literal("#").setParseAction(lambda t: "RGB") +
( (
Group(doubleHex + doubleHex + doubleHex) | Group(doubleHex + doubleHex + doubleHex) |
Word(hexnums, exact=3).setParseAction(parseShortHex) Word(hexnums, exact=3).setParseAction(parseShortHex)
) + StringEnd() ) + StringEnd()
) )
...@@ -81,7 +66,7 @@ def parseNamedColour(t): ...@@ -81,7 +66,7 @@ def parseNamedColour(t):
return ["RGB", NamedColours[t[0].lower()]] return ["RGB", NamedColours[t[0].lower()]]
except KeyError: except KeyError:
return ["RGB", (0,0,0)] return ["RGB", (0,0,0)]
namedColour = Word(alphas).setParseAction(parseNamedColour) namedColour = Word(alphas).setParseAction(parseNamedColour)
...@@ -261,7 +246,7 @@ NamedColours = { ...@@ -261,7 +246,7 @@ NamedColours = {
def fillCSS2SystemColours(): def fillCSS2SystemColours():
#The system colours require a wxApp to be present to retrieve, #The system colours require a wxApp to be present to retrieve,
#so if you wnat support for them you'll need #so if you wnat support for them you'll need
#to call this function after your wxApp instance starts #to call this function after your wxApp instance starts
systemColors = { systemColors = {
"ActiveBorder": wx.SYS_COLOUR_ACTIVEBORDER, "ActiveBorder": wx.SYS_COLOUR_ACTIVEBORDER,
...@@ -295,4 +280,4 @@ def fillCSS2SystemColours(): ...@@ -295,4 +280,4 @@ def fillCSS2SystemColours():
NamedColours.update( NamedColours.update(
#strip the alpha from the system colors. Is this really what we want to do? #strip the alpha from the system colors. Is this really what we want to do?
(k.lower(), wx.SystemSettings.GetColour(v)[:3]) for (k,v) in systemColors.iteritems() (k.lower(), wx.SystemSettings.GetColour(v)[:3]) for (k,v) in systemColors.iteritems()
) )
\ No newline at end of file
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" Parse CSS identifiers. More complicated than it sounds""" """ Parse CSS identifiers. More complicated than it sounds"""
from pyparsing import Word, Literal, Regex, Combine, Optional, White, oneOf, ZeroOrMore from pyparsing import Word, Literal, Regex, Combine, Optional, White, oneOf, ZeroOrMore
...@@ -25,7 +10,7 @@ class White(White): ...@@ -25,7 +10,7 @@ class White(White):
super(White, self).__init__(ws, min, max, exact) super(White, self).__init__(ws, min, max, exact)
escaped = ( escaped = (
Literal("\\").suppress() + Literal("\\").suppress() +
#chr(20)-chr(126) + chr(128)-unichr(sys.maxunicode) #chr(20)-chr(126) + chr(128)-unichr(sys.maxunicode)
Regex(u"[\u0020-\u007e\u0080-\uffff]", re.IGNORECASE) Regex(u"[\u0020-\u007e\u0080-\uffff]", re.IGNORECASE)
) )
...@@ -33,7 +18,7 @@ escaped = ( ...@@ -33,7 +18,7 @@ escaped = (
def convertToUnicode(t): def convertToUnicode(t):
return unichr(int(t[0], 16)) return unichr(int(t[0], 16))
hex_unicode = ( hex_unicode = (
Literal("\\").suppress() + Literal("\\").suppress() +
Regex("[0-9a-f]{1,6}", re.IGNORECASE) + Regex("[0-9a-f]{1,6}", re.IGNORECASE) +
Optional(White(exact=1)).suppress() Optional(White(exact=1)).suppress()
).setParseAction(convertToUnicode) ).setParseAction(convertToUnicode)
...@@ -44,9 +29,9 @@ escape = hex_unicode | escaped ...@@ -44,9 +29,9 @@ escape = hex_unicode | escaped
#any unicode literal outside the 0-127 ascii range #any unicode literal outside the 0-127 ascii range
nonascii = Regex(u"[^\u0000-\u007f]") nonascii = Regex(u"[^\u0000-\u007f]")
#single character for starting an identifier. #single character for starting an identifier.
nmstart = Regex(u"[A-Z]", re.IGNORECASE) | nonascii | escape nmstart = Regex(u"[A-Z]", re.IGNORECASE) | nonascii | escape
nmchar = Regex(u"[0-9A-Z-]", re.IGNORECASE) | nonascii | escape nmchar = Regex(u"[0-9A-Z-]", re.IGNORECASE) | nonascii | escape
identifier = Combine(nmstart + ZeroOrMore(nmchar)) identifier = Combine(nmstart + ZeroOrMore(nmchar))
\ No newline at end of file
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" Parser for inline CSS in style attributes """ """ Parser for inline CSS in style attributes """
def inlineStyle(styleString): def inlineStyle(styleString):
...@@ -20,4 +5,4 @@ def inlineStyle(styleString): ...@@ -20,4 +5,4 @@ def inlineStyle(styleString):
return {} return {}
styles = styleString.split(";") styles = styleString.split(";")
rv = dict(style.split(":") for style in styles if len(style) != 0) rv = dict(style.split(":") for style in styles if len(style) != 0)
return rv return rv
\ No newline at end of file
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" """
Parsing for CSS and CSS-style values, such as transform and filter attributes. Parsing for CSS and CSS-style values, such as transform and filter attributes.
""" """
...@@ -63,4 +48,4 @@ transformList = delimitedList(Group(transform), delim=maybeComma) ...@@ -63,4 +48,4 @@ transformList = delimitedList(Group(transform), delim=maybeComma)
if __name__ == '__main__': if __name__ == '__main__':
from tests.test_css import * from tests.test_css import *
unittest.main() unittest.main()
\ No newline at end of file
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" """
Parser for various kinds of CSS values as per CSS2 spec section 4.3 Parser for various kinds of CSS values as per CSS2 spec section 4.3
""" """
...@@ -58,4 +43,4 @@ length = lengthValue + Optional(lengthUnit, default=None) + StringEnd() ...@@ -58,4 +43,4 @@ length = lengthValue + Optional(lengthUnit, default=None) + StringEnd()
length.leaveWhitespace() length.leaveWhitespace()
#set the parse action aftward so it doesn't "infect" the parsers that build on it #set the parse action aftward so it doesn't "infect" the parsers that build on it
number.setParseAction(asFloat) number.setParseAction(asFloat)
\ No newline at end of file
This diff is collapsed.
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
""" """
SVG path data parser SVG path data parser
Usage: Usage:
steps = svg.parseString(pathdata) steps = svg.parseString(pathdata)
for command, arguments in steps: for command, arguments in steps:
pass pass
""" """
from pyparsing import (ParserElement, Literal, Word, CaselessLiteral, from pyparsing import (ParserElement, Literal, Word, CaselessLiteral,
Optional, Combine, Forward, ZeroOrMore, nums, oneOf, Group, ParseException, OneOrMore) Optional, Combine, Forward, ZeroOrMore, nums, oneOf, Group, ParseException, OneOrMore)
#ParserElement.enablePackrat() #ParserElement.enablePackrat()
def Command(char): def Command(char):
""" Case insensitive but case preserving""" """ Case insensitive but case preserving"""
return CaselessPreservingLiteral(char) return CaselessPreservingLiteral(char)
def Arguments(token): def Arguments(token):
return Group(token) return Group(token)
class CaselessPreservingLiteral(CaselessLiteral): class CaselessPreservingLiteral(CaselessLiteral):
""" Like CaselessLiteral, but returns the match as found """ Like CaselessLiteral, but returns the match as found
instead of as defined. instead of as defined.
""" """
def __init__( self, matchString ): def __init__( self, matchString ):
super(CaselessPreservingLiteral, self).__init__( matchString.upper() ) super(CaselessPreservingLiteral,self).__init__( matchString.upper() )
self.name = "'%s'" % matchString self.name = "'%s'" % matchString
self.errmsg = "Expected " + self.name self.errmsg = "Expected " + self.name
self.myException.msg = self.errmsg self.myException.msg = self.errmsg
def parseImpl( self, instring, loc, doActions = True ): def parseImpl( self, instring, loc, doActions=True ):
test = instring[ loc:loc+self.matchLen ] test = instring[ loc:loc+self.matchLen ]
if test.upper() == self.match: if test.upper() == self.match:
return loc+self.matchLen, test return loc+self.matchLen, test
...@@ -55,8 +40,8 @@ class CaselessPreservingLiteral(CaselessLiteral): ...@@ -55,8 +40,8 @@ class CaselessPreservingLiteral(CaselessLiteral):
exc = self.myException exc = self.myException
exc.loc = loc exc.loc = loc
exc.pstr = instring exc.pstr = instring
raise exc raise exc
def Sequence(token): def Sequence(token):
""" A sequence of the token""" """ A sequence of the token"""
return OneOrMore(token+maybeComma) return OneOrMore(token+maybeComma)
...@@ -73,13 +58,13 @@ def convertToFloat(s, loc, toks): ...@@ -73,13 +58,13 @@ def convertToFloat(s, loc, toks):
exponent = CaselessLiteral("e")+Optional(sign)+Word(nums) exponent = CaselessLiteral("e")+Optional(sign)+Word(nums)
#note that almost all these fields are optional, #note that almost all these fields are optional,
#and this can match almost anything. We rely on Pythons built-in #and this can match almost anything. We rely on Pythons built-in
#float() function to clear out invalid values - loosely matching like this #float() function to clear out invalid values - loosely matching like this
#speeds up parsing quite a lot #speeds up parsing quite a lot
floatingPointConstant = Combine( floatingPointConstant = Combine(
Optional(sign) + Optional(sign) +
Optional(Word(nums)) + Optional(Word(nums)) +
Optional(Literal(".") + Optional(Word(nums)))+ Optional(Literal(".") + Optional(Word(nums)))+
Optional(exponent) Optional(exponent)
) )
...@@ -90,7 +75,7 @@ number = floatingPointConstant ...@@ -90,7 +75,7 @@ number = floatingPointConstant
#same as FP constant but don't allow a - sign #same as FP constant but don't allow a - sign
nonnegativeNumber = Combine( nonnegativeNumber = Combine(
Optional(Word(nums)) + Optional(Word(nums)) +
Optional(Literal(".") + Optional(Word(nums)))+ Optional(Literal(".") + Optional(Word(nums)))+
Optional(exponent) Optional(exponent)
) )
...@@ -132,10 +117,10 @@ ellipticalArcArgument = Group( ...@@ -132,10 +117,10 @@ ellipticalArcArgument = Group(
arcRadius + maybeComma + #rx, ry arcRadius + maybeComma + #rx, ry
number + maybeComma +#rotation number + maybeComma +#rotation
arcFlags + #large-arc-flag, sweep-flag arcFlags + #large-arc-flag, sweep-flag
coordinatePair #(x, y) coordinatePair #(x,y)
) )
ellipticalArc = Group(Command("A") + Arguments(Sequence(ellipticalArcArgument))) ellipticalArc = Group(Command("A") + Arguments(Sequence(ellipticalArcArgument)))
smoothQuadraticBezierCurveto = Group(Command("T") + Arguments(coordinatePairSequence)) smoothQuadraticBezierCurveto = Group(Command("T") + Arguments(coordinatePairSequence))
...@@ -170,37 +155,39 @@ def profile(): ...@@ -170,37 +155,39 @@ def profile():
p.disable() p.disable()
p.print_stats() p.print_stats()
bpath = """M204.33 139.83 C196.33 133.33 206.68 132.82 206.58 132.58 C192.33 97.08 169.35 bpath = """M204.33 139.83 C196.33 133.33 206.68 132.82 206.58 132.58 C192.33 97.08 169.35
81.41 167.58 80.58 C162.12 78.02 159.48 78.26 160.45 76.97 C161.41 75.68 167.72 79.72 168.58 81.41 167.58 80.58 C162.12 78.02 159.48 78.26 160.45 76.97 C161.41 75.68 167.72 79.72 168.58
80.33 C193.83 98.33 207.58 132.33 207.58 132.33 C207.58 132.33 209.33 133.33 209.58 132.58 80.33 C193.83 98.33 207.58 132.33 207.58 132.33 C207.58 132.33 209.33 133.33 209.58 132.58
C219.58 103.08 239.58 87.58 246.33 81.33 C253.08 75.08 256.63 74.47 247.33 81.58 C218.58 103.58 C219.58 103.08 239.58 87.58 246.33 81.33 C253.08 75.08 256.63 74.47 247.33 81.58 C218.58 103.58
210.34 132.23 210.83 132.33 C222.33 134.83 211.33 140.33 211.83 139.83 C214.85 136.81 214.83 145.83 214.83 210.34 132.23 210.83 132.33 C222.33 134.83 211.33 140.33 211.83 139.83 C214.85 136.81 214.83 145.83 214.83
145.83 C214.83 145.83 231.83 110.83 298.33 66.33 C302.43 63.59 445.83 -14.67 395.83 80.83 C393.24 85.79 375.83 145.83 C214.83 145.83 231.83 110.83 298.33 66.33 C302.43 63.59 445.83 -14.67 395.83 80.83 C393.24 85.79 375.83
105.83 375.83 105.83 C375.83 105.83 377.33 114.33 371.33 121.33 C370.3 122.53 367.83 134.33 361.83 140.83 C360.14 142.67 105.83 375.83 105.83 C375.83 105.83 377.33 114.33 371.33 121.33 C370.3 122.53 367.83 134.33 361.83 140.83 C360.14 142.67
361.81 139.25 361.83 140.83 C362.33 170.83 337.76 170.17 339.33 170.33 C348.83 171.33 350.19 183.66 350.33 183.83 C355.83 361.81 139.25 361.83 140.83 C362.33 170.83 337.76 170.17 339.33 170.33 C348.83 171.33 350.19 183.66 350.33 183.83 C355.83
190.33 353.83 191.83 355.83 194.83 C366.63 211.02 355.24 210.05 356.83 212.83 C360.83 219.83 355.99 222.72 357.33 224.83 190.33 353.83 191.83 355.83 194.83 C366.63 211.02 355.24 210.05 356.83 212.83 C360.83 219.83 355.99 222.72 357.33 224.83
C360.83 230.33 354.75 233.84 354.83 235.33 C355.33 243.83 349.67 240.73 349.83 244.33 C350.33 255.33 346.33 250.83 343.83 254.83 C360.83 230.33 354.75 233.84 354.83 235.33 C355.33 243.83 349.67 240.73 349.83 244.33 C350.33 255.33 346.33 250.83 343.83 254.83
C336.33 266.83 333.46 262.38 332.83 263.83 C329.83 270.83 325.81 269.15 324.33 270.83 C320.83 274.83 317.33 274.83 315.83 276.33 C336.33 266.83 333.46 262.38 332.83 263.83 C329.83 270.83 325.81 269.15 324.33 270.83 C320.83 274.83 317.33 274.83 315.83 276.33
C308.83 283.33 304.86 278.39 303.83 278.83 C287.83 285.83 280.33 280.17 277.83 280.33 C270.33 280.83 271.48 279.67 269.33 277.83 C308.83 283.33 304.86 278.39 303.83 278.83 C287.83 285.83 280.33 280.17 277.83 280.33 C270.33 280.83 271.48 279.67 269.33 277.83
C237.83 250.83 219.33 211.83 215.83 206.83 C214.4 204.79 211.35 193.12 212.33 195.83 C214.33 201.33 213.33 250.33 207.83 250.33 C237.83 250.83 219.33 211.83 215.83 206.83 C214.4 204.79 211.35 193.12 212.33 195.83 C214.33 201.33 213.33 250.33 207.83 250.33
C202.33 250.33 201.83 204.33 205.33 195.83 C206.43 193.16 204.4 203.72 201.79 206.83 C196.33 213.33 179.5 250.83 147.59 277.83 C202.33 250.33 201.83 204.33 205.33 195.83 C206.43 193.16 204.4 203.72 201.79 206.83 C196.33 213.33 179.5 250.83 147.59 277.83
C145.42 279.67 146.58 280.83 138.98 280.33 C136.46 280.17 128.85 285.83 112.65 278.83 C111.61 278.39 107.58 283.33 100.49 276.33 C145.42 279.67 146.58 280.83 138.98 280.33 C136.46 280.17 128.85 285.83 112.65 278.83 C111.61 278.39 107.58 283.33 100.49 276.33
C98.97 274.83 95.43 274.83 91.88 270.83 C90.39 269.15 86.31 270.83 83.27 263.83 C82.64 262.38 79.73 266.83 72.13 254.83 C69.6 250.83 C98.97 274.83 95.43 274.83 91.88 270.83 C90.39 269.15 86.31 270.83 83.27 263.83 C82.64 262.38 79.73 266.83 72.13 254.83 C69.6 250.83
65.54 255.33 66.05 244.33 C66.22 240.73 60.48 243.83 60.99 235.33 C61.08 233.84 54.91 230.33 58.45 224.83 C59.81 222.72 54.91 219.83 65.54 255.33 66.05 244.33 C66.22 240.73 60.48 243.83 60.99 235.33 C61.08 233.84 54.91 230.33 58.45 224.83 C59.81 222.72 54.91 219.83
58.96 212.83 C60.57 210.05 49.04 211.02 59.97 194.83 C62 191.83 59.97 190.33 65.54 183.83 C65.69 183.66 67.06 171.33 76.69 170.33 58.96 212.83 C60.57 210.05 49.04 211.02 59.97 194.83 C62 191.83 59.97 190.33 65.54 183.83 C65.69 183.66 67.06 171.33 76.69 170.33
C78.28 170.17 53.39 170.83 53.9 140.83 C53.92 139.25 55.61 142.67 53.9 140.83 C47.82 134.33 45.32 122.53 44.27 121.33 C38.19 114.33 C78.28 170.17 53.39 170.83 53.9 140.83 C53.92 139.25 55.61 142.67 53.9 140.83 C47.82 134.33 45.32 122.53 44.27 121.33 C38.19 114.33
39.71 105.83 39.71 105.83 C39.71 105.83 22.08 85.79 19.46 80.83 C-31.19 -14.67 114.07 63.59 118.22 66.33 C185.58 110.83 202 145.83 39.71 105.83 39.71 105.83 C39.71 105.83 22.08 85.79 19.46 80.83 C-31.19 -14.67 114.07 63.59 118.22 66.33 C185.58 110.83 202 145.83
202 145.83 C202 145.83 202.36 143.28 203 141.83 C203.64 140.39 204.56 140.02 204.33 139.83 z""" 202 145.83 C202 145.83 202.36 143.28 203 141.83 C203.64 140.39 204.56 140.02 204.33 139.83 z"""
def ptest(): def ptest():
svg.parseString(bpath) svg.parseString(bpath)
if __name__ == '__main__': if __name__ == '__main__':
#~ from tests.test_pathdata import * #~ from tests.test_pathdata import *
#~ unittest.main() #~ unittest.main()
profile() profile()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment