'''
Copyright (C) 2001-2002 Matt Chisholm matt@theory.org
Copyright (C) 2008 Joel Holdsworth joel@airwebreathe.org.uk
for AP
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
'''
# standard library
import copy
import math
import cmath
import string
import random
import os
import sys
import re
# local library
import inkex
import simplestyle
import render_alphabetsoup_config
import bezmisc
import simplepath
import simpletransform
# Loads a super-path from a given SVG file
)
# __file__ is better then sys.argv[0] because this file may be a module
# for another one.
if pathElement == None:
return None, 0, 0
return None
elif pathA == None:
return pathB
elif pathB == None:
return pathA
else:
def reverseComponent(c):
nc = []
while c:
if cmd == 'C':
else:
return nc
rp = []
component = []
for p in sp:
if cmd == 'Z':
component = []
else:
return rp
def solveQuadratic(a, b, c):
det = b*b - 4.0*a*c
else: # complex roots
def cbrt(x):
if x >= 0:
return x**(1.0/3.0)
else:
return -((-x)**(1.0/3.0))
def findRealRoots(a,b,c,d):
if a != 0:
t = b / 3.0
p, q = c - 3 * t**2, d - c * t + 2 * t**3
else: # Complex Real Root
return [y1 - t]
elif b != 0:
det=c*c - 4.0*b*d
if det >= 0:
elif c != 0:
return [-d/c]
return []
box = None
last = None
lostctrl = None
segmentBox = None
if cmd == 'M':
# A move cannot contribute to the bounding box
elif cmd == 'L':
if last:
segmentBox = (min(params[0], last[0]), max(params[0], last[0]), min(params[1], last[1]), max(params[1], last[1]))
elif cmd == 'C':
if last:
segmentBox = (min(params[4], last[0]), max(params[4], last[0]), min(params[5], last[1]), max(params[5], last[1]))
# Compute the x limits
for t in ts:
if t >= 0 and t <= 1:
# Compute the y limits
for t in ts:
if t >= 0 and t <= 1:
elif cmd == 'Q':
# Provisional
if last:
segmentBox = (min(params[0], last[0]), max(params[0], last[0]), min(params[1], last[1]), max(params[1], last[1]))
elif cmd == 'A':
# Provisional
if last:
segmentBox = (min(params[0], last[0]), max(params[0], last[0]), min(params[1], last[1]), max(params[1], last[1]))
if segmentBox:
if box:
box = (min(segmentBox[0],box[0]), max(segmentBox[1],box[1]), min(segmentBox[2],box[2]), max(segmentBox[3],box[3]))
else:
return box
return lrimage
pass
else: return 0
return 1
return rule
return
return stack
else:
#else:
#inkex.debug("found end of list in generate( state =", state, ")") # this should be deprecated/never happen
return stack
#print state,
else:
else:
#inkex.debug("[")
images = [] # list of daughter images
nodes = [] # list of daughter names
if (newimage):
else:
#inkex.debug(("recurse on",newstate,"failed")) # this should never happen
return None, 0, 0
if currimg:
#box = getPathBoundingBox(currimg)
#newbox = ((box[0]+dx),(box[1]+dy),(box[2]+dx),(box[3]+dy))
def randomize_input_string(tokens, zoom ): # generate a glyph starting from each token in the input string
imagelist = []
#if ( re.match("[a-zA-Z0-9?]", char)):
else: # generate image for letter
#stack = string.split( alphabet[char][random.randint(0,(len(alphabet[char])-2))] , "." )
else: # this character is not in config.alphabet, skip it
return imagelist
def generate_random_string( tokens, zoom ): # generate a totally random glyph for each glyph in the input string
imagelist = []
else:
else: # this character is not in config.alphabet, skip it
return imagelist
left = []
right = []
resolution = 8
xmin = None
xmax = None
segmentBox = None
if cmd == 'M':
# A move cannot contribute to the bounding box
elif cmd == 'L':
x = params[0]
else:
if a != 0:
x = (y - b) / a
else: x = None
if x:
elif cmd == 'C':
if last:
d = by0 - y
ts = findRealRoots(a, b, c, d)
for t in ts:
if t >= 0 and t <= 1:
elif cmd == 'Q':
# Quadratic beziers are ignored
elif cmd == 'A':
# Arcs are ignored
else:
kernlist = []
else:
workspace = None
while(imagelist[i] == " "):
# set the kerning
else:
kerncompare = [] # kerning comparison array
return workspace
"""Tokenize the string, looking for LaTeX style, multi-character tokens in the string, like \\yogh."""
tokens = []
i = 0
c = text[i]
i += 1
if c == '\\': # found the beginning of an escape
t = ''
c = text[i]
if c == '\\': # found another escape, stop this one
break
i += 1
if c == ' ': # a space terminates this escape
break
t += c # stick this character onto the token
if t:
else:
return tokens
help="The text for alphabet soup")
help="The zoom on the output graphics")
help="Generate random (unreadable) text")
else:
if image:
s = { 'stroke': 'none', 'fill': '#000000' }
# compensate preserved transforms of parent layer
if __name__ == '__main__':
e = AlphabetSoup()
e.affect()