CanvasAdapter related changes
authorrgbecker
Wed, 20 Oct 2004 19:27:07 +0000
changeset 2401 cd68d7a84d05
parent 2400 f47d5c6d8fcd
child 2402 da8c6a14c84f
CanvasAdapter related changes
reportlab/graphics/renderPM.py
reportlab/graphics/renderbase.py
reportlab/platypus/tables.py
--- a/reportlab/graphics/renderPM.py	Tue Oct 19 17:52:20 2004 +0000
+++ b/reportlab/graphics/renderPM.py	Wed Oct 20 19:27:07 2004 +0000
@@ -273,45 +273,46 @@
         if fmt is None:
             if type(fn) is not StringType:
                 raise ValueError, "Invalid type '%s' for fn when fmt is None" % type(fn)
+            fmt = os.path.splitext(fn)[1]
+            if fmt.startswith('.'): fmt = fmt[1:]
+        configPIL = self.configPIL or {}
+        fmt = string.upper(fmt)
+        if fmt in ['GIF']:
+            im = _convert2pilp(im)
+        elif fmt in ['PCT','PICT']:
+            return _saveAsPICT(im,fn,fmt,transparent=configPIL.get('transparent',None))
+        elif fmt in ['PNG','TIFF','BMP', 'PPM', 'TIF']:
+            if fmt=='TIF': fmt = 'TIFF'
+            if fmt=='PNG':
+                try:
+                    from PIL import PngImagePlugin
+                except ImportError:
+                    import PngImagePlugin
+            elif fmt=='BMP':
+                try:
+                    from PIL import BmpImagePlugin
+                except ImportError:
+                    import BmpImagePlugin
+        elif fmt in ('JPG','JPEG'):
+            fmt = 'JPEG'
         else:
-            configPIL = self.configPIL or {}
-            fmt = string.upper(fmt)
-            if fmt in ['GIF']:
-                im = _convert2pilp(im)
-            elif fmt in ['PCT','PICT']:
-                return _saveAsPICT(im,fn,fmt,transparent=configPIL.get('transparent',None))
-            elif fmt in ['PNG','TIFF','BMP', 'PPM', 'TIF']:
-                if fmt=='TIF': fmt = 'TIFF'
-                if fmt=='PNG':
-                    try:
-                        from PIL import PngImagePlugin
-                    except ImportError:
-                        import PngImagePlugin
-                elif fmt=='BMP':
-                    try:
-                        from PIL import BmpImagePlugin
-                    except ImportError:
-                        import BmpImagePlugin
-            elif fmt in ('JPG','JPEG'):
-                fmt = 'JPEG'
-            else:
-                raise RenderPMError,"Unknown image kind %s" % fmt
-            if fmt=='TIFF':
-                tc = configPIL.get('transparent',None)
-                if tc:
-                    from PIL import ImageChops, Image
-                    T = 768*[0]
-                    for o, c in zip((0,256,512), tc.bitmap_rgb()):
-                        T[o+c] = 255
-                    #if type(fn) is type(''): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF')
-                    im = Image.merge('RGBA', im.split()+(ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])),))
-                    #if type(fn) is type(''): im.save(fn+'_masked.gif','GIF')
-                for a,d in ('resolution',self._dpi),('resolution unit','inch'):
-                    configPIL[a] = configPIL.get(a,d)
-            apply(im.save,(fn,fmt),configPIL)
-            if not hasattr(fn,'write') and os.name=='mac':
-                from reportlab.lib.utils import markfilename
-                markfilename(fn,ext=fmt)
+            raise RenderPMError,"Unknown image kind %s" % fmt
+        if fmt=='TIFF':
+            tc = configPIL.get('transparent',None)
+            if tc:
+                from PIL import ImageChops, Image
+                T = 768*[0]
+                for o, c in zip((0,256,512), tc.bitmap_rgb()):
+                    T[o+c] = 255
+                #if type(fn) is type(''): ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])).save(fn+'_mask.gif','GIF')
+                im = Image.merge('RGBA', im.split()+(ImageChops.invert(im.point(T).convert('L').point(255*[0]+[255])),))
+                #if type(fn) is type(''): im.save(fn+'_masked.gif','GIF')
+            for a,d in ('resolution',self._dpi),('resolution unit','inch'):
+                configPIL[a] = configPIL.get(a,d)
+        apply(im.save,(fn,fmt),configPIL)
+        if not hasattr(fn,'write') and os.name=='mac':
+            from reportlab.lib.utils import markfilename
+            markfilename(fn,ext=fmt)
 
     def saveToString(self,fmt='GIF'):
         s = getStringIO()
@@ -505,6 +506,12 @@
         '''do nothing for compatibility'''
         pass
 
+    def setFillColor(self,aColor):
+        self.fillColor = Color2Hex(aColor)
+
+    def setStrokeColor(self,aColor):
+        self.strokeColor = Color2Hex(aColor)
+
     restoreState = saveState
 
 def drawToPMCanvas(d, dpi=72, bg=0xffffff, configPIL=None, showBoundary=rl_config._unset_):
--- a/reportlab/graphics/renderbase.py	Tue Oct 19 17:52:20 2004 +0000
+++ b/reportlab/graphics/renderbase.py	Wed Oct 20 19:27:07 2004 +0000
@@ -118,6 +118,13 @@
         "returns the current transformation matrix at this point"""
         return self.__combined[-1]['ctm']
 
+    def __getitem__(self,key):
+        "returns the complete graphics state value of key at this point"
+        return self.__combined[-1][key]
+
+    def __setitem__(self,key,value):
+        "sets the complete graphics state value of key to value"
+        self.__combined[-1][key] = value
 
 def testStateTracker():
     print 'Testing state tracker'
--- a/reportlab/platypus/tables.py	Tue Oct 19 17:52:20 2004 +0000
+++ b/reportlab/platypus/tables.py	Wed Oct 20 19:27:07 2004 +0000
@@ -158,8 +158,10 @@
             raise ValueError, "%s invalid data type" % self.identity()
         self._nrows = nrows = len(data)
         self._cellvalues = []
+        _seqCW = type(colWidths) in _SeqTypes
+        _seqRH = type(rowHeights) in _SeqTypes
         if nrows: self._ncols = ncols = max(map(_rowLen,data))
-        elif colWidths: ncols = len(colWidths)
+        elif colWidths and _seqCW: ncols = len(colWidths)
         else: ncols = 0
         if not emptyTableAction: emptyTableAction = rl_config.emptyTableAction
         if not (nrows and ncols):
@@ -181,10 +183,10 @@
             return
 
         self._cellvalues = data
-        if colWidths is None: colWidths = ncols*[None]
+        if not _seqCW: colWidths = ncols*[colWidths]
         elif len(colWidths) != ncols:
             raise ValueError, "%s data error - %d columns in data but %d in grid" % (self.identity(),ncols, len(colWidths))
-        if rowHeights is None: rowHeights = nrows*[None]
+        if not _seqRH: rowHeights = nrows*[rowHeights]
         elif len(rowHeights) != nrows:
             raise ValueError, "%s data error - %d rows in data but %d in grid" % (self.identity(),nrows, len(rowHeights))
         for i in range(nrows):