Merge branch 'master' of git+ssh://gitbox/piccreate

This commit is contained in:
Eva Möller
2012-08-20 14:53:50 +02:00
7 changed files with 166 additions and 110 deletions
+7 -40
View File
@@ -10,6 +10,7 @@ Usage: `basename $0` [-h] [-i] [-j nb_jobs] command arg_list
-c give the path to the cfg file -c give the path to the cfg file
-i give the path of the svg files without the last / -i give the path of the svg files without the last /
-k chek if the jpg already exist -k chek if the jpg already exist
-s set the sleeptime while there are too many simultanious jobs
-j Set number of simultanious jobs. Default is 2 -j Set number of simultanious jobs. Default is 2
-o directory where the files should be moved to after creation. -o directory where the files should be moved to after creation.
Default ist PICCREATE_OUT Default ist PICCREATE_OUT
@@ -17,40 +18,10 @@ Usage: `basename $0` [-h] [-i] [-j nb_jobs] command arg_list
`basename $0` -i file -c config `basename $0` -i file -c config
`basename $0` -j 3 -i file -c config" `basename $0` -j 3 -i file -c config"
function queue {
QUEUE="$QUEUE $1"
NUM=$(($NUM+1))
}
function regeneratequeue {
OLDREQUEUE=$QUEUE
QUEUE=""
NUM=0
for PID in $OLDREQUEUE
do
if [ -d /proc/$PID ] ; then
QUEUE="$QUEUE $PID"
NUM=$(($NUM+1))
fi
done
}
function checkqueue {
OLDCHQUEUE=$QUEUE
for PID in $OLDCHQUEUE
do
if [ ! -d /proc/$PID ] ; then
regeneratequeue # at least one PID has finished
echo $PID
break
fi
done
}
function cfg_parser { function cfg_parser {
INI_FILE=$1 INI_FILE=$1
SECTION=$2 SECTION=$2
echo $1
echo $2
eval `sed -n -e "/^\[$SECTION\]/,/^\s*\[/{/^[^;].*\=.*/p;}" < $INI_FILE`>> trr.txt eval `sed -n -e "/^\[$SECTION\]/,/^\s*\[/{/^[^;].*\=.*/p;}" < $INI_FILE`>> trr.txt
echo 'helololo'
} }
function get_filepath { function get_filepath {
# probiere alle möglichen Kombinationen wo das file stehen könnte je # probiere alle möglichen Kombinationen wo das file stehen könnte je
@@ -116,8 +87,9 @@ if [ $# -eq 0 ]; then # must be at least one arg
fi fi
CHECKFILE=0 CHECKFILE=0
SLEEPTIME=0.5
while getopts "j:i:kc:o:hc:" OPT; do # "j:" waits for an argument "h" doesnt while getopts "j:i:kc:s:o:hc:" OPT; do # "j:" waits for an argument "h" doesnt
case $OPT in case $OPT in
h) echo "$USAGE" h) echo "$USAGE"
exit 0 ;; exit 0 ;;
@@ -125,6 +97,7 @@ while getopts "j:i:kc:o:hc:" OPT; do # "j:" waits for an argument "h" doesnt
k) CHECKFILE=1 ;; k) CHECKFILE=1 ;;
c) CFG_FILENAME=$OPTARG ;; c) CFG_FILENAME=$OPTARG ;;
o) OUTDIR=$OPTARG ;; o) OUTDIR=$OPTARG ;;
s) SLEEPTIME=$OPTARG ;;
i) INPUT_FILENAME=$OPTARG ;; i) INPUT_FILENAME=$OPTARG ;;
*) echo "$USAGE" >&2; exit 1; # Default. *) echo "$USAGE" >&2; exit 1; # Default.
esac esac
@@ -139,27 +112,21 @@ check_params
echo $INPUT_FILE echo $INPUT_FILE
for i in `ls $INPUT_FILE| grep .svg ` for i in `ls $INPUT_FILE| grep .svg `
do do
echo $i
echo $CHECKFILE
ID=`echo "$i" | sed -e 's/;.*//g'` ID=`echo "$i" | sed -e 's/;.*//g'`
PIC_NAME=`echo "$i" | sed -e 's/.svg/.jpg/g'` PIC_NAME=`echo "$i" | sed -e 's/.svg/.jpg/g'`
FILE_PATH=$INPUT_FILE/$PIC_NAME FILE_PATH=$INPUT_FILE/$PIC_NAME
if [ -s $FILE_PATH ] && [ $CHECKFILE -eq 1 ] if [ -s $FILE_PATH ] && [ $CHECKFILE -eq 1 ]
then then
echo $PIC_NAME exists! echo $PIC_NAME exists
else else
RESIZE="${width}x${height}" RESIZE="${width}x${height}"
SWITCHES="-density $density $INPUT_FILE/$ID -resize $RESIZE $INPUT_FILE/$PIC_NAME" SWITCHES="-density $density $INPUT_FILE/$ID -resize $RESIZE $INPUT_FILE/$PIC_NAME"
CMDLINE="$CMD $SWITCHES" CMDLINE="$CMD $SWITCHES"
echo $CMDLINE
(echo $ID; $CMDLINE) & (echo $ID; $CMDLINE) &
PID=$!
queue $PID
while [ $NUM -ge $MAX_NPROC ]; do while [ `ps -clx|grep -w 'convert' |wc -l` -ge $MAX_NPROC ]; do
checkqueue sleep $SLEEPTIME
sleep 0.5
done done
fi fi
done done
+8 -5
View File
@@ -29,18 +29,21 @@ name = Name
# hier der Inhalt aus der Eingabedatei, der geschrieben werden soll # hier der Inhalt aus der Eingabedatei, der geschrieben werden soll
content=${name} content=${name}
# Ab dem Punkt wird zu schreiben begonnen # Ab dem Punkt wird zu schreiben begonnen
x=0 x=-10
y=0 y=0
length=200 height=850
width=2640
# Fontname und Fonttyp # Fontname und Fonttyp
fontname=ausgangsschrift fontname=ausgangsschrift
glyph_space=20 glyph_space=20
counter_replace=True counter_replace=True
#align=center,left,right #align=center,left,right
align=left align=center
yalign=center
autoscale=True
[jpgs] [jpgs]
width=1900 width=2776
height=700 height=898
format=jpg format=jpg
density=300 density=300
+3 -3
View File
@@ -39,7 +39,7 @@ NPATTERN=9
FONTNAME=d.svg FONTNAME=d.svg
# #
[e] [e]
XSTEP=40 XSTEP=40.0
XMIN=34.977264 XMIN=34.977264
XMAX=67.112206 XMAX=67.112206
YSTEP=56.548093 YSTEP=56.548093
@@ -69,7 +69,7 @@ NPATTERN=10
FONTNAME=g.svg FONTNAME=g.svg
# #
[h] [h]
XSTEP=39.362423 XSTEP=45.0
XMIN=40.923481 XMIN=40.923481
XMAX=80.285904 XMAX=80.285904
YSTEP=83.657337 YSTEP=83.657337
@@ -99,7 +99,7 @@ NPATTERN=4
FONTNAME=j.svg FONTNAME=j.svg
# #
[k] [k]
XSTEP=39.362423 XSTEP=45.0
XMIN=40.923481 XMIN=40.923481
XMAX=80.285904 XMAX=80.285904
YSTEP=84.097073 YSTEP=84.097073
+24 -24
View File
@@ -1,98 +1,98 @@
<g transform="translate(${posx},${posy})"> <g transform="translate(${posx},${posy})">
<text <text
x="46.606346" x="26.606346"
y="93.957718" y="93.957718"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:end;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:end;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="46.606346" x="26.606346"
y="93.957718" y="93.957718"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x1}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x1}</tspan></text>
<text <text
x="56.4799" x="36.4799"
y="59.880642" y="59.880642"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:end;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:end;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="56.4799" x="36.4799"
y="59.880642" y="59.880642"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:end;text-anchor:end;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x3}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:end;text-anchor:end;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x3}</tspan></text>
<text <text
x="60.868507" x="40.868507"
y="87.16584" y="87.16584"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="60.868507" x="40.868507"
y="87.16584" y="87.16584"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;text-anchor:start;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x6}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;text-anchor:start;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x6}</tspan></text>
<text <text
x="80.285904" x="60.285904"
y="104.04529" y="104.04529"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="80.285904" x="60.285904"
y="104.04529" y="104.04529"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;text-anchor:start;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x7}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;text-anchor:start;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x7}</tspan></text>
<text <text
x="53.390858" x="33.390858"
y="110.72576" y="110.72576"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="53.390858" x="33.390858"
y="110.72576" y="110.72576"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x5}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x5}</tspan></text>
<text <text
x="41.175716" x="21.175716"
y="140.00911" y="140.00911"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="41.175716" x="21.175716"
y="140.00911" y="140.00911"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x4}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x4}</tspan></text>
<text <text
x="73.59874" x="53.59874"
y="61.912037" y="61.912037"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="73.59874" x="53.59874"
y="61.912037" y="61.912037"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;text-anchor:start;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x2}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;text-anchor:start;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x2}</tspan></text>
<text <text
x="74.532158" x="54.532158"
y="139.71278" y="139.71278"
xml:space="preserve" xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan style="font-size:40px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#808080;fill-opacity:1;stroke:none;font-family:Sans"><tspan
x="74.532158" x="54.532158"
y="139.71278" y="139.71278"
style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x8}</tspan></text> style="font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Ubuntu;-inkscape-font-specification:Ubuntu">${x8}</tspan></text>
<circle <circle
r="2.2" r="2.2"
transform="translate(40.923481,129.55195)" transform="translate(20.923481,129.55195)"
id="circle4" /> id="circle4" />
<circle <circle
r="2.2" r="2.2"
transform="translate(60.861691,56.351773)" transform="translate(40.861691,56.351773)"
id="circle4-6" /> id="circle4-6" />
<circle <circle
r="2.2" r="2.2"
transform="translate(52.540236,100.51006)" transform="translate(32.540236,100.51006)"
id="circle4-5" /> id="circle4-5" />
<circle <circle
r="2.2" r="2.2"
transform="translate(74.433397,129.29941)" transform="translate(54.433397,129.29941)"
id="circle4-9" /> id="circle4-9" />
<circle <circle
r="2.2" r="2.2"
transform="translate(49.099514,90.933613)" transform="translate(29.099514,90.933613)"
id="circle4-3" /> id="circle4-3" />
<circle <circle
r="2.2" r="2.2"
transform="translate(65.637986,90.933613)" transform="translate(45.637986,90.933613)"
id="circle4-91" /> id="circle4-91" />
<circle <circle
r="2.2" r="2.2"
transform="translate(69.953063,59.165573)" transform="translate(49.953063,59.165573)"
id="circle4-6-0" /> id="circle4-6-0" />
<circle <circle
r="2.2" r="2.2"
transform="translate(76.771595,100.54595)" transform="translate(56.771595,100.54595)"
id="circle4-6-7" /> id="circle4-6-7" />
</g> </g>
+1 -1
View File
@@ -76,7 +76,7 @@ z;z
Z;Z Z;Z
plus;+ plus;+
scharfs;ß scharfs;ß
slash; slash;/
space; space;
minus;- minus;-
komma;, komma;,
1 Kennummer Name
76 Z Z
77 plus +
78 scharfs ß
79 slash /
80 space
81 minus -
82 komma ,
+5 -8
View File
@@ -1,9 +1,6 @@
Kennummer;Name Kennummer;Name
a-z;mnopqrstuvwxyzabcdefghijkl 001;Au
A-Z;ABCDEFGHIJKLMNOPQRSTUVWXYZ 002;Rau
ü;:.:.:.:...---++!!&& 003;Lux
001;Michael 004;May
yxelbüxel;Eva 005;Johnson-Kronh-Wattenberg
063453;Nicola Jane
333;&
12;ä Ä é è ëïóöÖß/-,:!'a&b+úüÜ
1 Kennummer Name
2 a-z 001 mnopqrstuvwxyzabcdefghijkl Au
3 A-Z 002 ABCDEFGHIJKLMNOPQRSTUVWXYZ Rau
4 ü 003 :.:.:.:...---++!!&& Lux
5 001 004 Michael May
6 yxelbüxel 005 Eva Johnson-Kronh-Wattenberg
063453 Nicola Jane
333 &
12 ä Ä é è ëïóöÖß/-,:!'a&b+úüÜ
+118 -29
View File
@@ -21,19 +21,34 @@ def create_picture_frame( config ):
params = dict() params = dict()
params['width'] = config.get('globals', 'width') params['width'] = config.get('globals', 'width')
params['height'] = config.get('globals', 'height') params['height'] = config.get('globals', 'height')
params['background'] = config.get('globals', 'background')
#echo '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">' #echo '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">'
begintpl = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?> begintpl = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg <svg
xmlns:svg="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1" version="1.1"
width="${width}" width="${width}"
height="${height}" height="${height}"
> >
''' '''
imagetpl = ''' <image width="${width}" height="${height}"
xlink:href="file://${background}">
</image>
'''
svgbegin = Template( begintpl ).substitute(params) svgbegin = Template( begintpl ).substitute(params)
# falls ein Hintergrundbild verwendet werden soll, dann das genauso gross
# machen...
try:
background = config.get('globals', 'background')
font_path = os.path.expandvars(os.path.join('$PICCREATE_BACKGROUNDS', background ))
params['background'] = os.path.normpath(font_path)
svgbegin = svgbegin + Template( imagetpl ).substitute(params)
except ConfigParser.NoOptionError:
# dann eben kein Hintergrundbild
pass
svgend = '</svg>' svgend = '</svg>'
return svgbegin, svgend return svgbegin, svgend
@@ -41,13 +56,76 @@ def write_font_line( content, font, params ):
''' erzeugt den SVG Teil des Bildes aus Einzelkomponenten ''' erzeugt den SVG Teil des Bildes aus Einzelkomponenten
''' '''
w = Word(content, font, params) w = Word(content, font, params)
return w.GetSVG() wordsvg = w.GetSVG()
# falls das Wort nun skaliert werden soll
if params.has_key('scale'):
params['xscale'] = params['scale']
params['yscale'] = params['scale']
if not params.has_key('xscale'):
params['xscale'] = 1.0
if not params.has_key('yscale'):
params['yscale'] = 1.0
pic_width = float(params['width'])
pic_height = float(params['height'])
if params.has_key('autoscale'):
wordlength = w.calc_length()
wordheight = w.calc_height()
#print wordlength, wordheight
#print pic_width, pic_height
fw = pic_width / wordlength
fh = pic_height / wordheight
#print fw, fh
if fw < fh: scale_faktor = fw
else: scale_faktor = fh
params['xscale'] = scale_faktor
params['yscale'] = scale_faktor
else:
scale_faktor = 1.0
# berechne immer den richtigen Startpunkt, je nach Bündigkeit
if params.has_key('align'):
xstart = float(params['x'])
if params['align'] == 'left':
x = xstart
elif params['align'] == 'center':
word_length = w.calc_length()
x = xstart * scale_faktor + (pic_width - word_length * scale_faktor)/2.0
else:
word_length = w.calc_length()
x = xstart * scale_faktor + pic_width - word_length * scale_faktor
params['xstart'] = x
else:
params['xstart'] = params['x']
if params.has_key('yalign'):
ystart = float(params['y'])
if params['yalign'] == 'top':
y = 0.0
elif params['yalign'] == 'center':
word_height = w.calc_height()
y = ystart * scale_faktor + (pic_height - word_height * scale_faktor)/2.0
elif params['yalign'] == 'bottom':
y = ystart * scale_faktor + pic_height - word_height * scale_faktor
else:
y = ystart
params['ystart'] = y
else:
params['ystart'] = params['y']
scalebegin = '''<g transform="translate($xstart,$ystart) scale(${xscale},${yscale})">
'''
scaleend = ''' </g>'''
svg = Template( scalebegin ).substitute(params) + wordsvg + scaleend
return svg
def write_random_font_line( config, fontinfos, data ): def write_random_font_line( config, fontinfos, data ):
''' erzeugt den SVG Teil des Bildes aus einem Hintergrundbild und ''' erzeugt den SVG Teil des Bildes aus einem Hintergrundbild und
mehreren in Einzelbereichen zufällig platzierten Einzelbildern ''' mehreren in Einzelbereichen zufällig platzierten Einzelbildern '''
# TODO Bild aus Zufallspositionen von Einzelkomponenten # TODO Bild aus Zufallspositionen von Einzelkomponenten
pass return
class Word: class Word:
"""Berechnet die x/y Daten jedes Buchstabn zu einem Wort bzw. mehreren """Berechnet die x/y Daten jedes Buchstabn zu einem Wort bzw. mehreren
@@ -59,22 +137,23 @@ class Word:
def __repr__(self): def __repr__(self):
return self.line return self.line
def calc_length(self): def calc_length(self):
deltax= 0.0 glyph_space = float(self.params['glyph_space'])
deltax = 0.0
for c in self.line: for c in self.line:
g = self.font.GlyphGet(c) g = self.font.GlyphGet(c)
deltax = g.GetLength() + deltax deltax = g.GetLength() + deltax + glyph_space
return deltax return deltax
def calc_height(self):
max_y = 0.0
for c in self.line:
g = self.font.GlyphGet(c)
new_y = g.GetHeight()
if new_y > max_y:
max_y = new_y
return max_y
def GetSVG(self): def GetSVG(self):
params = self.params params = self.params
# berechne immer den richtigen Startpunkt, je nach Bündigkeit x = float(params['x'])
if params['align'] == 'left':
x = float(params['x'])
elif params['align'] == 'center':
word_length = self.calc_length()
x = float(params['x'] + (params['length'] - word_length)/2.0)
else:
word_length = self.calc_length()
x = float(params['x'] + word_length - params['length'])
y = params['y'] y = params['y']
glyph_space = float(params['glyph_space']) glyph_space = float(params['glyph_space'])
@@ -91,7 +170,7 @@ class Word:
# diese durch den aktuellen Zählerstand ersetzen # diese durch den aktuellen Zählerstand ersetzen
if params['counter_replace']: if params['counter_replace']:
xn = g.GetAttribute('npattern') xn = g.GetAttribute('npattern')
for i in range(1,int(xn)+1): for i in range(1, int(xn)+1):
counter = counter + 1 counter = counter + 1
content['x'+str(i)] = counter content['x'+str(i)] = counter
svgstr = svgstr + g.GetSVG(content) svgstr = svgstr + g.GetSVG(content)
@@ -110,7 +189,7 @@ class Glyph:
def GetLength(self): def GetLength(self):
return float(self.GetAttribute('xstep')) return float(self.GetAttribute('xstep'))
def GetHeight(self): def GetHeight(self):
return float(self.GetAttribute('ystep')) return float(self.GetAttribute('ymax'))
def GetSVG(self, content): def GetSVG(self, content):
t = Template(self.template) t = Template(self.template)
svg = t.substitute(content) svg = t.substitute(content)
@@ -177,8 +256,8 @@ def create_picture(config, fontinfos, data, pic_path):
svgstr = '' svgstr = ''
begin, end = create_picture_frame( config ) picbegin, picend = create_picture_frame( config )
svgstr = svgstr + begin svgstr = svgstr + picbegin
# gehe alle Zeilen die im Bild enthalten sein müssen durch # gehe alle Zeilen die im Bild enthalten sein müssen durch
lines = config.get('globals', 'lines').split(',') lines = config.get('globals', 'lines').split(',')
@@ -201,16 +280,26 @@ def create_picture(config, fontinfos, data, pic_path):
font = fontinfos[fontname] font = fontinfos[fontname]
# hol dir die Eckdaten für die Zeile # hol dir die Eckdaten für die Zeile
# x, y, align, length # x, y, align, width, height
params = dict(config.items(linename)) lineparams = dict(config.items(linename))
picstr = write_font_line( content, font, params ) # falls nix angegeben, dann aus hol defaults aus globalen daten
if not lineparams.has_key('width'):
lineparams['width'] = config.get('globals', 'width')
if not lineparams.has_key('height'):
lineparams['height'] = config.get('globals', 'height')
if not lineparams.has_key('x'):
lineparams['x'] = 0.0
if not lineparams.has_key('y'):
lineparams['y'] = 0.0
picstr = write_font_line( content, font, lineparams )
if picstr: svgstr = svgstr + picstr if picstr: svgstr = svgstr + picstr
randstr = write_random_font_line( content, font, params) randstr = write_random_font_line( content, font, lineparams)
if randstr: svgstr = svgstr + randstr if randstr: svgstr = svgstr + randstr
svgstr = svgstr + end svgstr = svgstr + picend
if options.dry: if options.dry:
print svgstr print svgstr