* 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 727cbff2da
commit f6d06b1220

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,
strokeWidth=stype.get_line_width(), x2*cm,y2*cm,
strokeDashArray=line_array)) strokeWidth=stype.get_line_width(),
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())
strokeDashArray=line_array, p = reportlab.graphics.shapes.Path(strokeWidth=stype.get_line_width(),
fillColor=color, strokeDashArray=line_array,
strokeColor=make_color(stype.get_color())) fillColor=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,
fillColor=col, (y-0.2)*cm-h,
strokeColor=col) w,h,
fillColor=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,13 +399,17 @@ 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())
str(text), fc = make_color(font.get_color())
strokeColor=make_color(font.get_color()), fnt = self.pdf_set_font(font),
fillColor=make_color(font.get_color()), s = reportlab.graphics.shape.String(x*cm,
fontName=self.pdf_set_font(font), y,
fontSize=size) str(text),
strokeColor=sc,
fillColor=fc,
fontName=fnt,
fontSize=size)
self.drawing.add(s) self.drawing.add(s)
def pdf_set_font(self,font): def pdf_set_font(self,font):
@ -417,14 +433,17 @@ 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,14 +458,17 @@ 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)
yt, sc = make_color(font.get_color())
str(text), fc = make_color(font.get_color())
fontName=self.pdf_set_font(font), s = reportlab.graphics.shapes.String(x*cm,
fontSize=font.get_size(), yt,
strokeColor=make_color(font.get_color()), str(text),
fillColor=make_color(font.get_color()), fontName=fnt,
textAnchor='middle') fontSize=font.get_size(),
strokeColor=sc,
fillColor=fc,
textAnchor='middle')
self.drawing.add(s) self.drawing.add(s)
def center_print(self,lines,font,x,y,w,h): def center_print(self,lines,font,x,y,w,h):
@ -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