reportlab: changes to accomodate barcodes pre-utf8-merge-trunk
authorrgbecker
Wed, 15 Mar 2006 16:47:27 +0000
changeset 2574 d81949596070
parent 2573 273f77e79536
child 2575 0cba68b93555
reportlab: changes to accomodate barcodes
reportlab/graphics/renderPM.py
reportlab/graphics/renderPS.py
reportlab/graphics/renderSVG.py
reportlab/pdfbase/pdfmetrics.py
reportlab/platypus/tables.py
--- a/reportlab/graphics/renderPM.py	Wed Mar 15 12:22:10 2006 +0000
+++ b/reportlab/graphics/renderPM.py	Wed Mar 15 16:47:27 2006 +0000
@@ -416,9 +416,9 @@
         if self.fillColor is not None:
             textLen = stringWidth(text, self.fontName,self.fontSize)
             if text_anchor=='end':
-                x = x-textLen
+                x -= textLen
             elif text_anchor=='middle':
-                x = x - textLen/2
+                x -= textLen/2.
             self.drawString(x,y,text)
 
     def drawRightString(self, text, x, y):
--- a/reportlab/graphics/renderPS.py	Wed Mar 15 12:22:10 2006 +0000
+++ b/reportlab/graphics/renderPS.py	Wed Mar 15 16:47:27 2006 +0000
@@ -241,9 +241,9 @@
         if self._fillColor is not None:
             textLen = stringWidth(text, self._font,self._fontSize)
             if text_anchor=='end':
-                x = x-textLen
+                x -= textLen
             elif text_anchor=='middle':
-                x = x - textLen/2
+                x -= textLen/2.
             self.drawString(x,y,text)
 
     def drawRightString(self, text, x, y):
--- a/reportlab/graphics/renderSVG.py	Wed Mar 15 12:22:10 2006 +0000
+++ b/reportlab/graphics/renderSVG.py	Wed Mar 15 16:47:27 2006 +0000
@@ -386,6 +386,22 @@
 
             self.currGroup.appendChild(text)
 
+    def drawCentredString(self, s, x, y, angle=0,text_anchor='middle'):
+        if self.verbose: print "+++ SVGCanvas.drawCentredString"
+
+        if self._fillColor != None:
+            if not text_anchor in ['start', 'inherited']:
+                textLen = stringWidth(s,self._font,self._fontSize)
+                if text_anchor=='end':
+                    x -= textLen
+                elif text_anchor=='middle':
+                    x -= textLen/2.
+                else:
+                    raise ValueError, 'bad value for text_anchor ' + str(text_anchor)
+        self.drawString(x,y,text,angle=angle)
+
+    def drawRightString(self, text, x, y, angle=0):
+        self.drawCentredString(text,x,y,angle=angle,text_anchor='end')
 
     def comment(self, data):
         "Add a comment."
--- a/reportlab/pdfbase/pdfmetrics.py	Wed Mar 15 12:22:10 2006 +0000
+++ b/reportlab/pdfbase/pdfmetrics.py	Wed Mar 15 16:47:27 2006 +0000
@@ -654,6 +654,19 @@
         registerFont(font)
         return font
 
+def getAscentDescent(fontName):
+    font = getFont(fontName)
+    try:
+        return font.ascent,font.descent
+    except:
+        return font.face.ascent,font.face.descent
+
+def getAscent(fontName):
+    return getAscentDescent(fontName)[0]
+
+def getDescent(fontName):
+    return getAscentDescent(fontName)[1]
+
 def getRegisteredFontNames():
     "Returns what's in there"
     reg = _fonts.keys()
--- a/reportlab/platypus/tables.py	Wed Mar 15 12:22:10 2006 +0000
+++ b/reportlab/platypus/tables.py	Wed Mar 15 16:47:27 2006 +0000
@@ -79,6 +79,9 @@
             # copy the parents list at construction time
             commands = commands + parent.getCommands()
             self._opts = parent._opts
+            for a in ('spaceBefore','spaceAfter'):
+                if hasattr(parent,a):
+                    setattr(self,a,getattr(parent,a))
         if cmds:
             commands = commands + list(cmds)
         self._cmds = commands
@@ -780,6 +783,9 @@
             self._addCommand(cmd)
         for k,v in tblstyle._opts.items():
             setattr(self,k,v)
+        for a in ('spaceBefore','spaceAfter'):
+            if not hasattr(self,a) and hasattr(tblstyle,a):
+                setattr(self,a,getattr(tblstyle,a))
 
     def _addCommand(self,cmd):
         if cmd[0] in ('BACKGROUND','ROWBACKGROUNDS','COLBACKGROUNDS'):