* src/docgen/PdfDoc.py: handle multiple image classes defined

by reportlab


svn: r2104
This commit is contained in:
Don Allingham 2003-09-08 04:20:01 +00:00
parent 3795edd1d4
commit a115be7739

View File

@ -46,7 +46,7 @@ try:
from reportlab.lib.units import cm from reportlab.lib.units import cm
from reportlab.lib.colors import Color from reportlab.lib.colors import Color
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
from reportlab.graphics.shapes import * import reportlab.graphics.shapes
import reportlab.lib.styles import reportlab.lib.styles
except ImportError: except ImportError:
raise Errors.PluginError( _("The ReportLab modules are not installed")) raise Errors.PluginError( _("The ReportLab modules are not installed"))
@ -292,6 +292,7 @@ class PdfDoc(BaseDoc.BaseDoc):
act_width = x_cm/ratio act_width = x_cm/ratio
self.story.append(Spacer(1,0.5*cm)) self.story.append(Spacer(1,0.5*cm))
print Image
self.story.append(Image(name,act_width*cm,act_height*cm)) self.story.append(Image(name,act_width*cm,act_height*cm))
self.story.append(Spacer(1,0.5*cm)) self.story.append(Spacer(1,0.5*cm))
self.image = 1 self.image = 1
@ -308,7 +309,9 @@ class PdfDoc(BaseDoc.BaseDoc):
return run_print_dialog (self.filename) return run_print_dialog (self.filename)
def start_page(self,orientation=None): def start_page(self,orientation=None):
self.drawing = Drawing(self.get_usable_width()*cm, self.get_usable_height()*cm) x = self.get_usable_width()*cm
y = self.get_usable_height()*cm
self.drawing = reportlab.graphics.shapes.Drawing(x,y)
def end_page(self): def end_page(self):
self.story.append(self.drawing) self.story.append(self.drawing)
@ -323,9 +326,11 @@ class PdfDoc(BaseDoc.BaseDoc):
else: else:
line_array = [2,4] line_array = [2,4]
self.drawing.add(Line(x1*cm,y1*cm,x2*cm,y2*cm, l = reportlab.graphics.shapes.Line(x1*cm,y1*cm,
x2*cm,y2*cm,
strokeWidth=stype.get_line_width(), strokeWidth=stype.get_line_width(),
strokeDashArray=line_array)) strokeDashArray=line_array)
self.drawing.add(l)
def draw_bar(self,style,x1,y1,x2,y2): def draw_bar(self,style,x1,y1,x2,y2):
pass pass
@ -340,10 +345,11 @@ class PdfDoc(BaseDoc.BaseDoc):
else: else:
line_array = [2,4] line_array = [2,4]
p = Path(strokeWidth=stype.get_line_width(), scol = make_color(stype.get_color())
p = reportlab.graphics.shapes.Path(strokeWidth=stype.get_line_width(),
strokeDashArray=line_array, strokeDashArray=line_array,
fillColor=color, fillColor=color,
strokeColor=make_color(stype.get_color())) strokeColor=scol)
point = path[0] point = path[0]
p.moveTo(point[0]*cm,y-point[1]*cm) p.moveTo(point[0]*cm,y-point[1]*cm)
@ -364,15 +370,21 @@ class PdfDoc(BaseDoc.BaseDoc):
if box_style.get_shadow(): if box_style.get_shadow():
col = make_color((0xc0,0xc0,0xc0)) col = make_color((0xc0,0xc0,0xc0))
r = Rect((x+0.2)*cm,(y-0.2)*cm-h,w,h, r = reportlab.graphics.shapes.Rect((x+0.2)*cm,
(y-0.2)*cm-h,
w,h,
fillColor=col, fillColor=col,
strokeColor=col) strokeColor=col)
self.drawing.add(r) self.drawing.add(r)
self.drawing.add(Rect((x)*cm,(y*cm)-h,w,h, sw = box_style.get_line_width()
strokeWidth=box_style.get_line_width(), fc = box_style.get_fill_color()
fillColor=box_style.get_fill_color(), sc = box_style.get_color()
strokeColor=box_style.get_color())) r = reportlab.graphics.shapes.Rect((x)*cm,(y*cm)-h,w,h,
strokeWidth=sw,
fillColor=fc,
strokeColor=sc)
self.drawing.add(r)
size = p.get_font().get_size() size = p.get_font().get_size()
@ -387,12 +399,16 @@ class PdfDoc(BaseDoc.BaseDoc):
p = self.style_list[pname] p = self.style_list[pname]
font = p.get_font() font = p.get_font()
size = font.get_size() size = font.get_size()
s = String(x*cm, y = (self.get_usable_height()*cm)-(y*cm)
(self.get_usable_height()*cm)-(y*cm), sc = make_color(font.get_color())
fc = make_color(font.get_color())
fnt = self.pdf_set_font(font),
s = reportlab.graphics.shape.String(x*cm,
y,
str(text), str(text),
strokeColor=make_color(font.get_color()), strokeColor=sc,
fillColor=make_color(font.get_color()), fillColor=fc,
fontName=self.pdf_set_font(font), fontName=fnt,
fontSize=size) fontSize=size)
self.drawing.add(s) self.drawing.add(s)
@ -417,13 +433,16 @@ class PdfDoc(BaseDoc.BaseDoc):
yt = (self.get_usable_height()*cm) - (y*cm) yt = (self.get_usable_height()*cm) - (y*cm)
yval = 0 yval = 0
g = Group() g = reportlab.graphics.shapes.Group()
fnt = self.pdf_set_font(font)
sc = make_color(font.get_color())
fc = make_color(font.get_color())
for line in text: for line in text:
s = String(0,yval,str(line), s = reportlab.graphics.shapes.String(0,yval,str(line),
fontName=self.pdf_set_font(font), fontName=fnt,
fontSize=size, fontSize=size,
strokeColor=make_color(font.get_color()), strokeColor=sc,
fillColor=make_color(font.get_color()), fillColor=fc,
textAnchor='middle') textAnchor='middle')
yval -= size yval -= size
g.add(s) g.add(s)
@ -439,13 +458,16 @@ class PdfDoc(BaseDoc.BaseDoc):
font = p.get_font() font = p.get_font()
yt = (self.get_usable_height()*cm) - (y*cm) yt = (self.get_usable_height()*cm) - (y*cm)
s = String(x*cm, fnt = self.pdf_set_font(font)
sc = make_color(font.get_color())
fc = make_color(font.get_color())
s = reportlab.graphics.shapes.String(x*cm,
yt, yt,
str(text), str(text),
fontName=self.pdf_set_font(font), fontName=fnt,
fontSize=font.get_size(), fontSize=font.get_size(),
strokeColor=make_color(font.get_color()), strokeColor=sc,
fillColor=make_color(font.get_color()), fillColor=fc,
textAnchor='middle') textAnchor='middle')
self.drawing.add(s) self.drawing.add(s)
@ -456,16 +478,19 @@ class PdfDoc(BaseDoc.BaseDoc):
start_y = (y + h/2.0 + l/2.0 + l) - ((l*size) + ((l-1)*0.2))/2.0 start_y = (y + h/2.0 + l/2.0 + l) - ((l*size) + ((l-1)*0.2))/2.0
start_x = (x + w/2.0) start_x = (x + w/2.0)
fnt = self.pdf_set_font(font)
size = font.get_size()
sc = make_color(font.get_color())
fc = make_color(font.get_color())
for text in lines: for text in lines:
s = String(start_x*cm, s = reportlab.graphics.shapes.String(start_x*cm,
start_y*cm, start_y*cm,
str(line), str(line),
fontName=self.pdf_set_font(font), fontName=fnt,
fontSize=font.get_size(), fontSize=size,
strokeColor=make_color(font.get_color()), strokeColor=sc,
fillColor=make_color(font.get_color()), fillColor=fc)
) self.drawing.add(s)
self.drawing.add(String(start_x,start_y,str(text)))
start_y = start_y - size*1.2 start_y = start_y - size*1.2
def left_print(self,lines,font,x,y): def left_print(self,lines,font,x,y):
@ -474,14 +499,17 @@ class PdfDoc(BaseDoc.BaseDoc):
start_y = y start_y = y
start_x = x start_x = x
fnt = self.pdf_set_font(font)
sc = make_color(font.get_color())
fc = make_color(font.get_color())
for text in lines: for text in lines:
s = String(start_x, s = reportlab.graphics.shapes.String(start_x,
start_y, start_y,
str(text), str(text),
fontSize=size, fontSize=size,
strokeColor=make_color(font.get_color()), strokeColor=sc,
fillColor=make_color(font.get_color()), fillColor=fc,
fontName=self.pdf_set_font(font)) fontName=fnt)
self.drawing.add(s) self.drawing.add(s)
start_y = start_y - size*1.2 start_y = start_y - size*1.2