From 7721bc58fa5caa16b75760f44d55f74312f90417 Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Wed, 27 Oct 2010 22:17:55 -0200 Subject: [PATCH 1/2] FIX: Table sometimes expands out of page - Fixes: http://github.com/holtwick/xhtml2pdf/issues/issue/2 --- sx/pisa3/pisa_tables.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/sx/pisa3/pisa_tables.py b/sx/pisa3/pisa_tables.py index cb707d37..e168dd78 100644 --- a/sx/pisa3/pisa_tables.py +++ b/sx/pisa3/pisa_tables.py @@ -37,6 +37,14 @@ def _width(value=None): return value return getSize(value) +def _heigth(value=None): + if value is None: + return None + value = str(value) + if value.endswith("%"): + return value + return getSize(value) + class TableData: def __init__(self): @@ -202,10 +210,17 @@ def end(self, c): for i, row in enumerate(data): data[i] += [''] * (maxcols - len(row)) + + cols_with_no_width = len(filter(lambda col: col is None, tdata.colw)) + if cols_with_no_width: # any col width not defined + bad_cols = filter(lambda tup: tup[1] is None, enumerate(tdata.colw)) + fair_division = str(100/float(cols_with_no_width))+'%' # get fair % + for i,col in bad_cols: + tdata.colw[i] = fair_division # fix empty with fair % try: if tdata.data: - # log.debug("Table sryles %r", tdata.styles) + # log.debug("Table styles %r", tdata.styles) t = PmlTable( data, colWidths=tdata.colw, @@ -317,7 +332,7 @@ def start(self, c): if not rspan: height = None #self._getStyle(None, attrs, "height", "height", mode) if height is not None: - tdata.rowh[row] = _width(height) + tdata.rowh[row] = _heigth(height) tdata.add_style(('FONTSIZE', begin, end, 1.0)) tdata.add_style(('LEADING', begin, end, 1.0)) @@ -400,4 +415,4 @@ def end_keepinframe(self): self.next_para() self.keepinframe["content"] = self.story.pop() self.add_story(KeepInFrame(**self.keepinframe)) -''' \ No newline at end of file +''' From e278001df8c31c103726d1f1f8b114d4f4c1bf0d Mon Sep 17 00:00:00 2001 From: Alan Justino Date: Mon, 4 Mar 2013 17:22:28 -0300 Subject: [PATCH 2/2] [FIX] AttributeError: HTTPResponse instance has no attribute 'tell' Python gzip cannot handle streams. So bad... Solution from: http://rationalpie.wordpress.com/2010/06/02/python-streaming-gzip-decompression/ --- sx/pisa3/pisa_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx/pisa3/pisa_util.py b/sx/pisa3/pisa_util.py index 4502e45b..6db23075 100644 --- a/sx/pisa3/pisa_util.py +++ b/sx/pisa3/pisa_util.py @@ -514,7 +514,7 @@ def __init__(self, uri, basepath=None): if r1.getheader("content-encoding") == "gzip": # zbuf = cStringIO.StringIO(data) import gzip - self.file = gzip.GzipFile(mode="rb", fileobj=r1) + self.file = gzip.GzipFile(mode="rb", fileobj=StringIO.StringIO(r1.read())) #data = zfile.read() #zfile.close() else: