split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
authorrobin <robin@reportlab.com>
Thu, 31 May 2018 12:07:34 +0100
changeset 4405 c985bd7093ad
parent 4404 b055f51699ca
child 4406 88b91bcf5fc1
split out DocTemplate _makeCanvas suggested by Chris Jerdonek cjerdonek @ bitbucket; version --> 3.4.41
src/reportlab/__init__.py
src/reportlab/platypus/doctemplate.py
--- a/src/reportlab/__init__.py	Thu May 24 11:50:23 2018 +0100
+++ b/src/reportlab/__init__.py	Thu May 31 12:07:34 2018 +0100
@@ -1,9 +1,9 @@
 #Copyright ReportLab Europe Ltd. 2000-2017
 #see license.txt for license details
 __doc__="""The Reportlab PDF generation library."""
-Version = "3.4.40"
+Version = "3.4.41"
 __version__=Version
-__date__='20180524'
+__date__='20180531'
 
 import sys, os
 
--- a/src/reportlab/platypus/doctemplate.py	Thu May 24 11:50:23 2018 +0100
+++ b/src/reportlab/platypus/doctemplate.py	Thu May 31 12:07:34 2018 +0100
@@ -939,41 +939,52 @@
     _handle_currentFrame = handle_currentFrame
     _handle_nextFrame = handle_nextFrame
 
+    def _makeCanvas(self, filename=None, canvasmaker=canvas.Canvas):
+        '''make and return a sample canvas. As suggested by 
+        Chris Jerdonek cjerdonek @ bitbucket this allows testing of stringWidths
+        etc.
+
+        *NB* only the canvases created in self._startBuild will actually be used
+        in the build process.
+        '''
+        canv = canvasmaker(filename or self.filename,
+                            pagesize=self.pagesize,
+                            invariant=self.invariant,
+                            pageCompression=self.pageCompression,
+                            enforceColorSpace=self.enforceColorSpace,
+                            initialFontName = self.initialFontName,
+                            initialFontSize = self.initialFontSize,
+                            initialLeading = self.initialLeading,
+                            cropBox = self.cropBox,
+                            artBox = self.artBox,
+                            trimBox = self.trimBox,
+                            bleedBox = self.bleedBox,
+                            )
+
+        getattr(canv,'setEncrypt',lambda x: None)(self.encrypt)
+
+        canv._cropMarks = self.cropMarks
+        canv.setAuthor(self.author)
+        canv.setTitle(self.title)
+        canv.setSubject(self.subject)
+        canv.setCreator(self.creator)
+        canv.setKeywords(self.keywords)
+        if self.displayDocTitle is not None:
+            canv.setViewerPreference('DisplayDocTitle',['false','true'][self.displayDocTitle])
+        if self.lang:
+            canv.setCatalogEntry('Lang',self.lang)
+
+        if self._onPage:
+            canv.setPageCallBack(self._onPage)
+        return canv
+
     def _startBuild(self, filename=None, canvasmaker=canvas.Canvas):
         self._calc()
 
         #each distinct pass gets a sequencer
-        self.seq = reportlab.lib.sequencer.Sequencer()
-
-        self.canv = canvasmaker(filename or self.filename,
-                                pagesize=self.pagesize,
-                                invariant=self.invariant,
-                                pageCompression=self.pageCompression,
-                                enforceColorSpace=self.enforceColorSpace,
-                                initialFontName = self.initialFontName,
-                                initialFontSize = self.initialFontSize,
-                                initialLeading = self.initialLeading,
-                                cropBox = self.cropBox,
-                                artBox = self.artBox,
-                                trimBox = self.trimBox,
-                                bleedBox = self.bleedBox,
-                                )
+        #self.seq = reportlab.lib.sequencer.Sequencer()
 
-        getattr(self.canv,'setEncrypt',lambda x: None)(self.encrypt)
-
-        self.canv._cropMarks = self.cropMarks
-        self.canv.setAuthor(self.author)
-        self.canv.setTitle(self.title)
-        self.canv.setSubject(self.subject)
-        self.canv.setCreator(self.creator)
-        self.canv.setKeywords(self.keywords)
-        if self.displayDocTitle is not None:
-            self.canv.setViewerPreference('DisplayDocTitle',['false','true'][self.displayDocTitle])
-        if self.lang:
-            self.canv.setCatalogEntry('Lang',self.lang)
-
-        if self._onPage:
-            self.canv.setPageCallBack(self._onPage)
+        self.canv = self._makeCanvas(filename=filename,canvasmaker=canvasmaker)
         self.handle_documentBegin()
 
     def _endBuild(self):