40
|
1 |
#!/bin/env python
|
494
|
2 |
#copyright ReportLab Inc. 2000
|
|
3 |
#see license.txt for license details
|
|
4 |
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/lib/corp.py?cvsroot=reportlab
|
|
5 |
#$Header: /tmp/reportlab/reportlab/lib/corp.py,v 1.2 2000/10/25 08:57:45 rgbecker Exp $
|
40
|
6 |
|
|
7 |
""" This module includes some reusable routines for ReportLab's
|
|
8 |
'Corporate Image' - the logo, standard page backdrops and
|
|
9 |
so on - you are advised to do the same for your own company!"""
|
494
|
10 |
__version__=''' $Id: corp.py,v 1.2 2000/10/25 08:57:45 rgbecker Exp $ '''
|
40
|
11 |
|
|
12 |
from reportlab.lib.units import inch
|
|
13 |
|
|
14 |
class ReportLabLogo:
|
|
15 |
"""vector reportlab logo centered in a 250x by 150y rectangle"""
|
|
16 |
|
|
17 |
def __init__(self, atx=0, aty=0, width=2.5*inch, height=1.5*inch, powered_by=0):
|
|
18 |
self.origin = (atx, aty)
|
|
19 |
self.dimensions = (width, height)
|
|
20 |
self.powered_by = powered_by
|
|
21 |
|
|
22 |
dogrid = 0
|
|
23 |
xticks = 25
|
|
24 |
yticks = 15
|
|
25 |
def draw(self, canvas):
|
|
26 |
canvas.saveState()
|
|
27 |
(atx,aty) = self.origin
|
|
28 |
canvas.translate(atx, aty)
|
|
29 |
(width, height) = self.dimensions
|
|
30 |
canvas.scale(width/250.0, height/150.0)
|
|
31 |
# do a skew
|
|
32 |
canvas.skew(0,20)
|
|
33 |
self.setup(canvas)
|
|
34 |
if self.powered_by:
|
|
35 |
canvas.setFont("Helvetica-Bold", 18)
|
|
36 |
canvas.drawString(-15, 135, "powered by")
|
|
37 |
# do a stretched "ReportLab"
|
|
38 |
canvas.saveState()
|
|
39 |
canvas.setFont("Helvetica-Bold", 30)
|
|
40 |
canvas.scale(1.65,1)
|
|
41 |
canvas.drawString(0,60,"ReportLab")
|
|
42 |
canvas.restoreState()
|
|
43 |
# draw the "page" as a bunch of rectangles
|
|
44 |
rects = [
|
|
45 |
# x y h, w
|
|
46 |
[65,10,40,8], # below p
|
|
47 |
[65,53,22.5,8], # over p
|
|
48 |
[65,78,50,8], # above p
|
|
49 |
[65,123,7,75], # across top
|
|
50 |
[161,86,29,9], # above L
|
|
51 |
[161,60.5,21,9], # over L
|
|
52 |
[161,10,47,9], # below L
|
|
53 |
[65,10,7,102], # across bottom
|
|
54 |
[140,110,20,10], # notch vertical
|
|
55 |
[140,110,7,29.5],# notch horizontal
|
|
56 |
]
|
|
57 |
fill = 1
|
|
58 |
for [x,y,h,w] in rects:
|
|
59 |
canvas.rect(x,y,w,h, stroke=1, fill=fill)
|
|
60 |
#break
|
|
61 |
path = canvas.beginPath()
|
|
62 |
path.moveTo(150,130)
|
|
63 |
for (x,y) in ((170,115), (167,112), (147,127)):
|
|
64 |
path.lineTo(x,y)
|
|
65 |
#path.close()
|
|
66 |
canvas.drawPath(path, stroke=1, fill=fill)
|
|
67 |
canvas.restoreState()
|
|
68 |
|
|
69 |
def setup(self, canvas):
|
|
70 |
xticks, yticks = self.xticks, self.yticks
|
|
71 |
if self.dogrid:
|
|
72 |
canvas.saveState()
|
|
73 |
for y in range(yticks):
|
|
74 |
if y%5==0:
|
|
75 |
canvas.setStrokeColorRGB(1,0,0)
|
|
76 |
canvas.line(0,y*10,xticks*10,y*10)
|
|
77 |
if y%5==0:
|
|
78 |
canvas.setStrokeColorRGB(0,1,0)
|
|
79 |
for x in range(xticks):
|
|
80 |
if x%5==0:
|
|
81 |
canvas.setStrokeColorRGB(1,0,0)
|
|
82 |
canvas.line(x*10,yticks*10,x*10,0)
|
|
83 |
if x%5==0:
|
|
84 |
canvas.setStrokeColorRGB(0,1,0)
|
|
85 |
canvas.restoreState()
|
|
86 |
|
|
87 |
def main(filename, logomaker):
|
|
88 |
from reportlab.pdfgen import canvas
|
|
89 |
c = canvas.Canvas(filename)
|
|
90 |
#c.translate(inch,inch)
|
|
91 |
# scale each point to a quarter inch/10
|
|
92 |
#tqinch = inch/40.0
|
|
93 |
#c.scale(tqinch, tqinch)
|
|
94 |
logomaker.draw(c)
|
|
95 |
c.save()
|
|
96 |
|
|
97 |
if __name__=="__main__":
|
|
98 |
logomaker = ReportLabLogo(inch, 8*inch, powered_by=1)
|
|
99 |
main("logo.pdf", logomaker)
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|