~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/reportlab/pdfgen/pathobject.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#Copyright ReportLab Europe Ltd. 2000-2004
 
2
#see license.txt for license details
 
3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/pdfgen/pathobject.py
 
4
__version__=''' $Id$ '''
 
5
__doc__="""
 
6
PDFPathObject is an efficient way to draw paths on a Canvas. Do not
 
7
instantiate directly, obtain one from the Canvas instead.
 
8
 
 
9
Progress Reports:
 
10
8.83, 2000-01-13, gmcm:
 
11
    created from pdfgen.py
 
12
"""
 
13
 
 
14
import string
 
15
from reportlab.pdfgen import pdfgeom
 
16
from reportlab.lib.utils import fp_str
 
17
 
 
18
 
 
19
class PDFPathObject:
 
20
    """Represents a graphic path.  There are certain 'modes' to PDF
 
21
    drawing, and making a separate object to expose Path operations
 
22
    ensures they are completed with no run-time overhead.  Ask
 
23
    the Canvas for a PDFPath with getNewPathObject(); moveto/lineto/
 
24
    curveto wherever you want; add whole shapes; and then add it back
 
25
    into the canvas with one of the relevant operators.
 
26
 
 
27
    Path objects are probably not long, so we pack onto one line"""
 
28
 
 
29
    def __init__(self):
 
30
        self._code = []
 
31
        self._code.append('n')   #newpath
 
32
 
 
33
    def getCode(self):
 
34
        "pack onto one line; used internally"
 
35
        return string.join(self._code, ' ')
 
36
 
 
37
    def moveTo(self, x, y):
 
38
        self._code.append('%s m' % fp_str(x,y))
 
39
 
 
40
    def lineTo(self, x, y):
 
41
        self._code.append('%s l' % fp_str(x,y))
 
42
 
 
43
    def curveTo(self, x1, y1, x2, y2, x3, y3):
 
44
        self._code.append('%s c' % fp_str(x1, y1, x2, y2, x3, y3))
 
45
 
 
46
    def arc(self, x1,y1, x2,y2, startAng=0, extent=90):
 
47
        """Contributed to piddlePDF by Robert Kern, 28/7/99.
 
48
        Draw a partial ellipse inscribed within the rectangle x1,y1,x2,y2,
 
49
        starting at startAng degrees and covering extent degrees.   Angles
 
50
        start with 0 to the right (+x) and increase counter-clockwise.
 
51
        These should have x1<x2 and y1<y2.
 
52
 
 
53
        The algorithm is an elliptical generalization of the formulae in
 
54
        Jim Fitzsimmon's TeX tutorial <URL: http://www.tinaja.com/bezarc1.pdf>."""
 
55
 
 
56
        pointList = pdfgeom.bezierArc(x1,y1, x2,y2, startAng, extent)
 
57
        #move to first point
 
58
        self._code.append('%s m' % fp_str(pointList[0][:2]))
 
59
        for curve in pointList:
 
60
            self._code.append('%s c' % fp_str(curve[2:]))
 
61
 
 
62
    def arcTo(self, x1,y1, x2,y2, startAng=0, extent=90):
 
63
        """Like arc, but draws a line from the current point to
 
64
        the start if the start is not the current point."""
 
65
        pointList = pdfgeom.bezierArc(x1,y1, x2,y2, startAng, extent)
 
66
        self._code.append('%s l' % fp_str(pointList[0][:2]))
 
67
        for curve in pointList:
 
68
            self._code.append('%s c' % fp_str(curve[2:]))
 
69
 
 
70
    def rect(self, x, y, width, height):
 
71
        """Adds a rectangle to the path"""
 
72
        self._code.append('%s re' % fp_str((x, y, width, height)))
 
73
 
 
74
    def ellipse(self, x, y, width, height):
 
75
        """adds an ellipse to the path"""
 
76
        pointList = pdfgeom.bezierArc(x, y, x + width,y + height, 0, 360)
 
77
        self._code.append('%s m' % fp_str(pointList[0][:2]))
 
78
        for curve in pointList:
 
79
            self._code.append('%s c' % fp_str(curve[2:]))
 
80
 
 
81
    def circle(self, x_cen, y_cen, r):
 
82
        """adds a circle to the path"""
 
83
        x1 = x_cen - r
 
84
        #x2 = x_cen + r
 
85
        y1 = y_cen - r
 
86
        #y2 = y_cen + r
 
87
        width = height = 2*r
 
88
        #self.ellipse(x_cen - r, y_cen - r, x_cen + r, y_cen + r)
 
89
        self.ellipse(x1, y1, width, height)
 
90
 
 
91
    def close(self):
 
92
        "draws a line back to where it started"
 
93
        self._code.append('h')