commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r6233 - trunk/gnue-common/src/printing/barcodes


From: jcater
Subject: r6233 - trunk/gnue-common/src/printing/barcodes
Date: Mon, 30 Aug 2004 18:06:02 -0500 (CDT)

Author: jcater
Date: 2004-08-30 18:06:01 -0500 (Mon, 30 Aug 2004)
New Revision: 6233

Modified:
   trunk/gnue-common/src/printing/barcodes/Base.py
Log:
use ReportLab's line instead of rect as that's what the old postscript logic 
was written to

Modified: trunk/gnue-common/src/printing/barcodes/Base.py
===================================================================
--- trunk/gnue-common/src/printing/barcodes/Base.py     2004-08-30 18:47:56 UTC 
(rev 6232)
+++ trunk/gnue-common/src/printing/barcodes/Base.py     2004-08-30 23:06:01 UTC 
(rev 6233)
@@ -27,8 +27,8 @@
 #
 import sys, os, string
 import Image, ImageDraw
-from reportlab.lib import colors 
-from reportlab.graphics.shapes import * 
+from reportlab.lib import colors
+from reportlab.graphics.shapes import *
 
 class InvalidBarcode(StandardError):
   pass
@@ -94,44 +94,44 @@
   def generate(self, value, stream=None,
                format='eps', includeText=None, textSize=7, dpi=300):
     """
-    Generates the requested bar code either via a stream or as the 
+    Generates the requested bar code either via a stream or as the
     requested object type.
-  
+
     @param value:   The string to convert to a barcode
     @param stream:  Optional argument of file name as a string, or any
                     open file style object.
     @param format: The format in which the output should be generated
-    
-                  Valid file formats include pdf, eps, svg and 
+
+                  Valid file formats include pdf, eps, svg and
                   will require the stream argument be provided.
-    
+
                   Valid object formats include
                     rldrawing: ReportLab Drawing object will be returned
                                 No stream argument is required.
     @param includeText: Boolean.  If true then human readable text will
                         be printed centered under the barcode.
-  
+
     @param textSize: The point size of the human readable text.
-    @param dpi: The dots per inch at which the bitmap should be generated.  
-  
+    @param dpi: The dots per inch at which the bitmap should be generated.
+
     @return: None or a format dependent object.  Valid return values
             eps : None
             pdf : None
             svg : None
-            rl  : ReportLab Drawing           
+            rl  : ReportLab Drawing
     @rtype: misc
     """
 
-    assert (format in ('rl') or stream is not None)
+    assert (format in ('rl',) or stream is not None)
 
     d = self._generateDrawing(value, includeText, textSize, dpi)
-    
+
     #
     # Process formats that return value instead of write to a file
-    #      
+    #
     if format == 'rl':
       return d
-    
+
     #
     # A stream is required for the remaining formats
     #
@@ -140,12 +140,12 @@
       stream = open(stream,'w')
     else:
       closeFile = False
-                  
+
     if format == 'pdf':
-      from reportlab.graphics import renderPDF 
-      renderPDF.drawToFile(d, stream, 'GNUe')      
-    elif format == 'eps':   
-      from reportlab.graphics import renderPS 
+      from reportlab.graphics import renderPDF
+      renderPDF.drawToFile(d, stream, 'GNUe')
+    elif format == 'eps':
+      from reportlab.graphics import renderPS
       renderPS.drawToFile(d, stream)
     elif format == 'svg':
       from reportlab.graphics import renderSVG
@@ -153,10 +153,10 @@
 
 #
 # This code *should* be replaced with calls to renderPM
-# but that appears broken in the .debs 
+# but that appears broken in the .debs
 #
     ##
-    ## Raster-based output using PIL  
+    ## Raster-based output using PIL
     ##
 #     elif format in ('png','tiff','ppm','xbm'):
 #       lineWidth = int(lineWidth * dpi/72+.5)   # 300dpi
@@ -183,22 +183,22 @@
 
     if closeFile:
       stream.close()
-      
+
   def _generateDrawing(self, value, includeText=None, textSize=7, dpi=300):
     """
-    Generates a ReportLab Drawing object used by the renderers in generate() 
-  
+    Generates a ReportLab Drawing object used by the renderers in generate()
+
     @param value:   The string to convert to a barcode
     @param includeText: Boolean.  If true then human readable text will
                         be printed centered under the barcode.
-  
+
     @param textSize: The point size of the human readable text.
-    @param dpi: The dots per inch at which the bitmap should be generated.  
-  
-    @return: ReportLab Drawing           
+    @param dpi: The dots per inch at which the bitmap should be generated.
+
+    @return: ReportLab Drawing
     @rtype: misc
     """
-    
+
     if includeText is None:
       includeText = self.defaultIncludeText
     code = self._buildBinary(value)
@@ -217,9 +217,9 @@
         width += spaceWidth*xmul
 
     lineHeight = self.calculateLineHeight(width)
-    
+
     d = Drawing(width+1,lineHeight+(includeText and ( textSize+2 ) or 1 ))
-    
+
     if includeText:
       y = textSize + 1
     else:
@@ -236,7 +236,7 @@
         if not x:
           x = dx/2.0
 
-        d.add(Rect(x+dx/2.0, y,dx,dy, fillColor=colors.black,strokeWidth=0)) 
+        d.add(Line(x+dx/2, y, x+dx/2, y+dy, 
strokeColor=colors.black,strokeWidth=dx))
 
         x += dx
       else:
@@ -244,10 +244,10 @@
 
     # Draw the text
     if includeText:
-      d.add(String(x/2.0, textSize/2.0, value, fontSize=textSize, 
fontName="Courier",fillColor=colors.black,textAnchor="middle")) 
+      d.add(String(x/2.0, textSize/2.0, value, fontSize=textSize, 
fontName="Courier",fillColor=colors.black,textAnchor="middle"))
 
-    return d        
-    
+    return d
+
   # Line height is .15 * barcode width, but at least .25"
   # This is used by Code39, Interleaved 2 of 5, etc
   def _calculate15(self, width):





reply via email to

[Prev in Thread] Current Thread [Next in Thread]