src/reportlab/graphics/renderPDF.py
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3975 4a3599863c11
equal deleted inserted replaced
3722:29c11b905751 3723:99aa837b6703
    16 """
    16 """
    17 
    17 
    18 from reportlab.graphics.shapes import *
    18 from reportlab.graphics.shapes import *
    19 from reportlab.pdfgen.canvas import Canvas
    19 from reportlab.pdfgen.canvas import Canvas
    20 from reportlab.pdfbase.pdfmetrics import stringWidth
    20 from reportlab.pdfbase.pdfmetrics import stringWidth
    21 from reportlab.lib.utils import getStringIO
    21 from reportlab.lib.utils import getBytesIO
    22 from reportlab import rl_config
    22 from reportlab import rl_config
    23 from .renderbase import Renderer, StateTracker, getStateDelta, renderScaledDrawing
    23 from .renderbase import Renderer, StateTracker, getStateDelta, renderScaledDrawing
    24 
    24 
    25 # the main entry point for users...
    25 # the main entry point for users...
    26 def draw(drawing, canvas, x, y, showBoundary=rl_config._unset_):
    26 def draw(drawing, canvas, x, y, showBoundary=rl_config._unset_):
   193         self._canvas.setFillColor(c)
   193         self._canvas.setFillColor(c)
   194 
   194 
   195     def applyStateChanges(self, delta, newState):
   195     def applyStateChanges(self, delta, newState):
   196         """This takes a set of states, and outputs the PDF operators
   196         """This takes a set of states, and outputs the PDF operators
   197         needed to set those properties"""
   197         needed to set those properties"""
   198         for key, value in list(delta.items()):
   198         for key, value in delta.items():
   199             if key == 'transform':
   199             if key == 'transform':
   200                 self._canvas.transform(value[0], value[1], value[2],
   200                 self._canvas.transform(value[0], value[1], value[2],
   201                                  value[3], value[4], value[5])
   201                                  value[3], value[4], value[5])
   202             elif key == 'strokeColor':
   202             elif key == 'strokeColor':
   203                 #this has different semantics in PDF to SVG;
   203                 #this has different semantics in PDF to SVG;
   301         except:
   301         except:
   302             pass
   302             pass
   303 
   303 
   304 def drawToString(d, msg="", showBoundary=rl_config._unset_,autoSize=1):
   304 def drawToString(d, msg="", showBoundary=rl_config._unset_,autoSize=1):
   305     "Returns a PDF as a string in memory, without touching the disk"
   305     "Returns a PDF as a string in memory, without touching the disk"
   306     s = getStringIO()
   306     s = getBytesIO()
   307     drawToFile(d, s, msg=msg, showBoundary=showBoundary,autoSize=autoSize)
   307     drawToFile(d, s, msg=msg, showBoundary=showBoundary,autoSize=autoSize)
   308     return s.getvalue()
   308     return s.getvalue()
   309 
   309 
   310 #########################################################
   310 #########################################################
   311 #
   311 #