Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2013-11-26 11:47:43 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2013-11-26 11:52:11 (GMT)
commit81a0b6197fbda041934cceb6f87be27ba7a419b5 (patch)
tree6061eb5181ebc65ad38337e482ceb1211175282b
parentcf3ccfb731b99213ff6555f113cd57bb727f420a (diff)
Improve pdf generation
Now the generation start on box 0, to include the title, and the boxes are scaled to fill the pages. Signed-off-by: Flavio Danesse <fdanesse@gmail.com> Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--historietaactivity.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/historietaactivity.py b/historietaactivity.py
index b367981..16b334f 100644
--- a/historietaactivity.py
+++ b/historietaactivity.py
@@ -266,20 +266,30 @@ class HistorietaActivity(activity.Activity):
_('A image was created in the Journal'))
def _save_as_pdf(self, widget):
- if not len(self.page.boxs) > 1:
- return
file_name = os.path.join(self.get_activity_root(), 'instance',
'tmp-%i.pdf' % time.time())
file_obj = open(file_name, 'w')
- surface = cairo.PDFSurface(file_obj, self.page.boxs[1].width,
- self.page.boxs[1].height)
+ page_width = self.page.boxs[1].width
+ page_height = self.page.boxs[1].height
+
+ surface = cairo.PDFSurface(file_obj, page_width, page_height)
+
context = cairo.Context(surface)
- for box in self.page.boxs[1:]:
+ for box in self.page.boxs[0:]:
+ context.save()
+ if box.width != page_width:
+ # for the first box, scale and center
+ scale = float(page_width) / float(box.width)
+ top_margin = (page_height - box.height) / 2
+ context.translate(0, top_margin)
+ context.scale(scale, scale)
+
box.draw_in_context(context)
context.show_page()
+ context.restore()
surface.finish()
file_obj.close()