Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added keywords center and cursor

  • Loading branch information...
commit ee0b115c85c832325f52ae239e1a251d965bfacf 1 parent a5c7f12
@badzong authored
Showing with 43 additions and 7 deletions.
  1. +29 −2 pypdfml/pypdfml.py
  2. +14 −5 pypdfml/templates/example.xml
View
31 pypdfml/pypdfml.py
@@ -221,7 +221,7 @@ def draw(self):
self.canvas.drawText(self.text)
if self.move_cursor:
- return page_cursor
+ return page_cursor - self.lineheight
else:
return 0
@@ -380,8 +380,35 @@ def pop_value(self, d, name):
return None
def do_math(self, attrs):
+
+ keywords = {
+ 'x': {},
+ 'y': {},
+ }
+ try:
+ keywords['x'].update({
+ 'center': self.width / 2,
+ 'cursor': self.cursor.x,
+ })
+ keywords['y'].update({
+ 'center': self.height / 2,
+ 'cursor': self.cursor.y,
+ })
+ except TypeError:
+ pass
+
# Cast arguments and multiply by unit
for k in attrs.keys():
+ kw = attrs[k]
+ try:
+ attrs[k] = keywords[k][kw]
+ except KeyError:
+ pass
+ else:
+ if kw == 'cursor':
+ attrs['move_cursor'] = False
+ continue
+
if k in math_attributes:
attrs[k] = float(attrs[k]) * self.unit
@@ -621,7 +648,7 @@ def text_cdata(self, cdata):
def text_end(self):
text = self.text_stack.pop()
- self.cursor.move(y = text.draw() - text.lineheight)
+ self.cursor.move(y = text.draw())
def image_start(self, **args):
src = args.pop('src')
View
19 pypdfml/templates/example.xml
@@ -1,7 +1,7 @@
<pdf filename="example.pdf" pagesize="A4" unit="cm" margin="1.5,1">
<font name="asongforjennifer" ttf="a song for jennifer.ttf"/>
<page>
- <rect height="1" width="1" x="0" y="-1" fill="blue"/>
+ <rect height="1.5" width="1" x="0" y="-1.5" fill="black" stroke="0"/>
<text fontsize="18">Available Fonts (on my computer at generation time)</text>
<line/>
<text/>
@@ -14,6 +14,15 @@
<line/>
<text/>
<text font="asongforjennifer" fontsize="16">A Song For Jennifer (http://www.1001freefonts.com)</text>
+ <text/>
+ <text/>
+ <text fontsize="18">Loaded TTF Font</text>
+ <line/>
+ <text/>
+ <text y="2" move_cursor="1">Text</text>
+ <text y="cursor" x="3">on</text>
+ <text y="cursor" x="5">a</text>
+ <text y="cursor" x="7">Line</text>
</page>
<page>
<text fontsize="18">Available Barcodes</text>
@@ -85,10 +94,10 @@ Lorem Ipsum</text>
<text y="-10" fontsize="18" move_cursor="1">Spirograph</text>
<line/>
{% for deg in range(0, 360, 15) %}
- <rect rotate="{{ deg }}" x="10" y="10" height="8" width="1" stroke="1,0,0"/>
- <rect rotate="{{ deg }}" x="10" y="10" height="5" width="2" stroke="0,1,1"/>
- <rect rotate="{{ deg }}" x="10" y="10" height="2" width="4" stroke="1,0,1"/>
- <rect rotate="{{ deg }}" x="10" y="10" height="2" width="3" stroke="0,0,1"/>
+ <rect rotate="{{ deg }}" x="center" y="10" height="8" width="1" stroke="1,0,0"/>
+ <rect rotate="{{ deg }}" x="center" y="10" height="5" width="2" stroke="0,1,1"/>
+ <rect rotate="{{ deg }}" x="center" y="10" height="2" width="4" stroke="1,0,1"/>
+ <rect rotate="{{ deg }}" x="center" y="10" height="2" width="3" stroke="0,0,1"/>
{% endfor %}
</page>
<page>

0 comments on commit ee0b115

Please sign in to comment.
Something went wrong with that request. Please try again.