0003137: Attribute error on EmptyDoc for all graphical reports - only with PostScript and SVG output formats !
removed 'template' parameter from init method. problem was that they still used template parameter, when BaseDoc didn't have a template parameter anymore. also pylint cleanup svn: r12927
This commit is contained in:
parent
c839502568
commit
5ae1a75bc0
@ -21,6 +21,10 @@
|
||||
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
PostScript document generator.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
@ -37,7 +41,6 @@ from gen.plug import PluginManager, DocGenPlugin
|
||||
from gen.plug.docgen import BaseDoc, DrawDoc, FONT_SERIF, PAPER_PORTRAIT, SOLID
|
||||
from gen.plug.utils import gformat
|
||||
import Errors
|
||||
import Utils
|
||||
|
||||
def lrgb(grp):
|
||||
grp = ReportUtils.rgb_color(grp)
|
||||
@ -53,9 +56,9 @@ def coords(grp):
|
||||
#-------------------------------------------------------------------------
|
||||
class PSDrawDoc(BaseDoc, DrawDoc):
|
||||
|
||||
def __init__(self,styles,type,template):
|
||||
BaseDoc.__init__(self,styles,type,template)
|
||||
self.f = None
|
||||
def __init__(self, styles, type):
|
||||
BaseDoc.__init__(self, styles, type)
|
||||
self.file = None
|
||||
self.filename = None
|
||||
self.level = 0
|
||||
self.page = 0
|
||||
@ -91,50 +94,55 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
return (x, self.paper.get_size().get_height()-y)
|
||||
|
||||
def open(self, filename):
|
||||
"""
|
||||
Opens the file so that it can be generated.
|
||||
|
||||
@param filename: path name of the file to create
|
||||
"""
|
||||
if filename[-3:] != ".ps":
|
||||
self.filename = filename + ".ps"
|
||||
else:
|
||||
self.filename = filename
|
||||
|
||||
try:
|
||||
self.f = open(self.filename,"w")
|
||||
self.file = open(self.filename,"w")
|
||||
except IOError,msg:
|
||||
errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg)
|
||||
raise Errors.ReportError(errmsg)
|
||||
except:
|
||||
raise Errors.ReportError(_("Could not create %s") % self.filename)
|
||||
|
||||
self.f.write('%!PS-Adobe-3.0\n')
|
||||
self.f.write('%%LanguageLevel: 2\n')
|
||||
self.f.write('%%Pages: (atend)\n')
|
||||
self.f.write('%%PageOrder: Ascend\n')
|
||||
self.file.write('%!PS-Adobe-3.0\n')
|
||||
self.file.write('%%LanguageLevel: 2\n')
|
||||
self.file.write('%%Pages: (atend)\n')
|
||||
self.file.write('%%PageOrder: Ascend\n')
|
||||
if self.paper.get_orientation() != PAPER_PORTRAIT:
|
||||
self.f.write('%%Orientation: Landscape\n')
|
||||
self.file.write('%%Orientation: Landscape\n')
|
||||
else:
|
||||
self.f.write('%%Orientation: Portrait\n')
|
||||
self.f.write('%%EndComments\n')
|
||||
self.f.write('/cm { 28.34 mul } def\n')
|
||||
self.f.write('% build iso-latin-1 version of a font\n')
|
||||
self.f.write('/font-to-iso-latin-1 { % <font> font-to-iso-latin-1 <font>\n')
|
||||
self.f.write('%% reencode for iso latin1; from the 2nd edition red book, sec 5.6.1\n')
|
||||
self.f.write('dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall\n')
|
||||
self.f.write('/Encoding ISOLatin1Encoding def currentdict end\n')
|
||||
self.f.write('dup /FontName get 80 string cvs (-ISOLatin1) concatstrings cvn \n')
|
||||
self.f.write('exch definefont\n')
|
||||
self.f.write('} def\n')
|
||||
self.f.write('\n')
|
||||
self.f.write('/find-latin-font { % <name> find-latin-font <font>\n')
|
||||
self.f.write('findfont font-to-iso-latin-1\n')
|
||||
self.f.write('} def\n')
|
||||
self.file.write('%%Orientation: Portrait\n')
|
||||
self.file.write('%%EndComments\n')
|
||||
self.file.write('/cm { 28.34 mul } def\n')
|
||||
self.file.write('% build iso-latin-1 version of a font\n')
|
||||
self.file.write('/font-to-iso-latin-1 { % <font> font-to-iso-latin-1 <font>\n')
|
||||
self.file.write('%% reencode for iso latin1; from the 2nd edition red book, sec 5.6.1\n')
|
||||
self.file.write('dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall\n')
|
||||
self.file.write('/Encoding ISOLatin1Encoding def currentdict end\n')
|
||||
self.file.write('dup /FontName get 80 string cvs (-ISOLatin1) concatstrings cvn \n')
|
||||
self.file.write('exch definefont\n')
|
||||
self.file.write('} def\n')
|
||||
self.file.write('\n')
|
||||
self.file.write('/find-latin-font { % <name> find-latin-font <font>\n')
|
||||
self.file.write('findfont font-to-iso-latin-1\n')
|
||||
self.file.write('} def\n')
|
||||
|
||||
self.filename = filename
|
||||
|
||||
def close(self):
|
||||
self.f.write('%%Trailer\n')
|
||||
self.f.write('%%Pages: ')
|
||||
self.f.write('%d\n' % self.page)
|
||||
self.f.write('%%EOF\n')
|
||||
self.f.close()
|
||||
self.file.write('%%Trailer\n')
|
||||
self.file.write('%%Pages: ')
|
||||
self.file.write('%d\n' % self.page)
|
||||
self.file.write('%%EOF\n')
|
||||
self.file.close()
|
||||
if self.open_req:
|
||||
open_file_with_default_application(self.filename)
|
||||
|
||||
@ -143,15 +151,15 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
|
||||
def start_page(self):
|
||||
self.page = self.page + 1
|
||||
self.f.write("%%Page:")
|
||||
self.f.write("%d %d\n" % (self.page,self.page))
|
||||
self.file.write("%%Page:")
|
||||
self.file.write("%d %d\n" % (self.page, self.page))
|
||||
if self.paper.get_orientation() != PAPER_PORTRAIT:
|
||||
self.f.write('90 rotate %s cm %s cm translate\n' % (
|
||||
self.file.write('90 rotate %s cm %s cm translate\n' % (
|
||||
gformat(0),gformat(-1*self.paper.get_size().get_height())))
|
||||
|
||||
def end_page(self):
|
||||
self.f.write('showpage\n')
|
||||
self.f.write('%%PageTrailer\n')
|
||||
self.file.write('showpage\n')
|
||||
self.file.write('%%PageTrailer\n')
|
||||
|
||||
def encode(self, text):
|
||||
try:
|
||||
@ -177,13 +185,13 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
|
||||
(text, fdef) = self.encode_text(p, text)
|
||||
|
||||
self.f.write('gsave\n')
|
||||
self.f.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
|
||||
self.f.write(fdef)
|
||||
self.f.write('(%s) dup stringwidth pop -2 div ' % text)
|
||||
self.f.write('%s cm add %s cm moveto ' % coords(self.translate(x,y)))
|
||||
self.f.write('show\n')
|
||||
self.f.write('grestore\n')
|
||||
self.file.write('gsave\n')
|
||||
self.file.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
|
||||
self.file.write(fdef)
|
||||
self.file.write('(%s) dup stringwidth pop -2 div ' % text)
|
||||
self.file.write('%s cm add %s cm moveto ' % coords(self.translate(x, y)))
|
||||
self.file.write('show\n')
|
||||
self.file.write('grestore\n')
|
||||
|
||||
def draw_text(self, style, text, x1, y1):
|
||||
style_sheet = self.get_style_sheet()
|
||||
@ -196,10 +204,10 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
|
||||
(text, fdef) = self.encode_text(p, text)
|
||||
|
||||
self.f.write('gsave\n')
|
||||
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x1,y1)))
|
||||
self.f.write(fdef)
|
||||
self.f.write('(%s) show grestore\n' % text)
|
||||
self.file.write('gsave\n')
|
||||
self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x1, y1)))
|
||||
self.file.write(fdef)
|
||||
self.file.write('(%s) show grestore\n' % text)
|
||||
|
||||
def rotate_text(self, style, text, x, y, angle):
|
||||
|
||||
@ -216,52 +224,52 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
|
||||
(new_text, fdef) = self.encode_text(p, text[0])
|
||||
|
||||
self.f.write('gsave\n')
|
||||
self.f.write(fdef)
|
||||
self.file.write('gsave\n')
|
||||
self.file.write(fdef)
|
||||
coords = self.translate(x, y)
|
||||
self.f.write('%s cm %s cm translate\n' % (
|
||||
self.file.write('%s cm %s cm translate\n' % (
|
||||
gformat(coords[0]),gformat(coords[1])))
|
||||
self.f.write('%s rotate\n' % gformat(-angle))
|
||||
self.file.write('%s rotate\n' % gformat(-angle))
|
||||
|
||||
self.f.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
|
||||
self.file.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
|
||||
|
||||
val = len(text)
|
||||
y = ((size * val)/2.0) - size
|
||||
|
||||
for line in text:
|
||||
self.f.write('(%s) dup stringwidth pop -2 div '
|
||||
self.file.write('(%s) dup stringwidth pop -2 div '
|
||||
% self.encode(line))
|
||||
self.f.write("%s moveto show\n" % gformat(y))
|
||||
self.file.write("%s moveto show\n" % gformat(y))
|
||||
y -= size
|
||||
|
||||
self.f.write('grestore\n')
|
||||
self.file.write('grestore\n')
|
||||
|
||||
def draw_path(self, style, path):
|
||||
style_sheet = self.get_style_sheet()
|
||||
stype = style_sheet.get_draw_style(style)
|
||||
self.f.write('gsave\n')
|
||||
self.f.write('newpath\n')
|
||||
self.f.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
|
||||
self.file.write('gsave\n')
|
||||
self.file.write('newpath\n')
|
||||
self.file.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
|
||||
if stype.get_line_style() == SOLID:
|
||||
self.f.write('[] 0 setdash\n')
|
||||
self.file.write('[] 0 setdash\n')
|
||||
else:
|
||||
self.f.write('[2 4] 0 setdash\n')
|
||||
self.file.write('[2 4] 0 setdash\n')
|
||||
|
||||
point = path[0]
|
||||
x1 = point[0]+self.paper.get_left_margin()
|
||||
y1 = point[1]+self.paper.get_top_margin()
|
||||
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x1,y1)))
|
||||
self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x1, y1)))
|
||||
|
||||
for point in path[1:]:
|
||||
x1 = point[0]+self.paper.get_left_margin()
|
||||
y1 = point[1]+self.paper.get_top_margin()
|
||||
self.f.write('%s cm %s cm lineto\n' % coords(self.translate(x1,y1)))
|
||||
self.f.write('closepath\n')
|
||||
self.file.write('%s cm %s cm lineto\n' % coords(self.translate(x1, y1)))
|
||||
self.file.write('closepath\n')
|
||||
|
||||
color = stype.get_fill_color()
|
||||
self.f.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(color))
|
||||
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
|
||||
self.f.write('grestore\n')
|
||||
self.file.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(color))
|
||||
self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
|
||||
self.file.write('grestore\n')
|
||||
|
||||
def draw_line(self, style, x1, y1, x2, y2):
|
||||
x1 = x1 + self.paper.get_left_margin()
|
||||
@ -270,18 +278,18 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
y2 = y2 + self.paper.get_top_margin()
|
||||
style_sheet = self.get_style_sheet()
|
||||
stype = style_sheet.get_draw_style(style)
|
||||
self.f.write('gsave newpath\n')
|
||||
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x1,y1)))
|
||||
self.f.write('%s cm %s cm lineto\n' % coords(self.translate(x2,y2)))
|
||||
self.f.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
|
||||
self.file.write('gsave newpath\n')
|
||||
self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x1, y1)))
|
||||
self.file.write('%s cm %s cm lineto\n' % coords(self.translate(x2, y2)))
|
||||
self.file.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
|
||||
if stype.get_line_style() == SOLID:
|
||||
self.f.write('[] 0 setdash\n')
|
||||
self.file.write('[] 0 setdash\n')
|
||||
else:
|
||||
self.f.write('[2 4] 0 setdash\n')
|
||||
self.file.write('[2 4] 0 setdash\n')
|
||||
|
||||
self.f.write('2 setlinecap\n')
|
||||
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
|
||||
self.f.write('grestore\n')
|
||||
self.file.write('2 setlinecap\n')
|
||||
self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
|
||||
self.file.write('grestore\n')
|
||||
|
||||
def draw_box(self, style, text, x, y, w, h):
|
||||
x = x + self.paper.get_left_margin()
|
||||
@ -290,45 +298,45 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
style_sheet = self.get_style_sheet()
|
||||
box_style = style_sheet.get_draw_style(style)
|
||||
|
||||
self.f.write('gsave\n')
|
||||
self.file.write('gsave\n')
|
||||
|
||||
shadsize = box_style.get_shadow_space()
|
||||
if box_style.get_shadow():
|
||||
self.f.write('newpath\n')
|
||||
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x+shadsize,y+shadsize)))
|
||||
self.f.write('0 -%s cm rlineto\n' % gformat(h))
|
||||
self.f.write('%s cm 0 rlineto\n' % gformat(w))
|
||||
self.f.write('0 %s cm rlineto\n' % gformat(h))
|
||||
self.f.write('closepath\n')
|
||||
self.f.write('.5 setgray\n')
|
||||
self.f.write('fill\n')
|
||||
self.f.write('newpath\n')
|
||||
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x,y)))
|
||||
self.f.write('0 -%s cm rlineto\n' % gformat(h))
|
||||
self.f.write('%s cm 0 rlineto\n' % gformat(w))
|
||||
self.f.write('0 %s cm rlineto\n' % gformat(h))
|
||||
self.f.write('closepath\n')
|
||||
self.file.write('newpath\n')
|
||||
self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x+shadsize, y+shadsize)))
|
||||
self.file.write('0 -%s cm rlineto\n' % gformat(h))
|
||||
self.file.write('%s cm 0 rlineto\n' % gformat(w))
|
||||
self.file.write('0 %s cm rlineto\n' % gformat(h))
|
||||
self.file.write('closepath\n')
|
||||
self.file.write('.5 setgray\n')
|
||||
self.file.write('fill\n')
|
||||
self.file.write('newpath\n')
|
||||
self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x, y)))
|
||||
self.file.write('0 -%s cm rlineto\n' % gformat(h))
|
||||
self.file.write('%s cm 0 rlineto\n' % gformat(w))
|
||||
self.file.write('0 %s cm rlineto\n' % gformat(h))
|
||||
self.file.write('closepath\n')
|
||||
|
||||
fill_color = box_style.get_fill_color()
|
||||
color = box_style.get_color()
|
||||
self.f.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(fill_color))
|
||||
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(color))
|
||||
self.file.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(fill_color))
|
||||
self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(color))
|
||||
|
||||
self.f.write('newpath\n')
|
||||
self.file.write('newpath\n')
|
||||
if box_style.get_line_width():
|
||||
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x,y)))
|
||||
self.f.write('0 -%s cm rlineto\n' % gformat(h))
|
||||
self.f.write('%s cm 0 rlineto\n' % gformat(w))
|
||||
self.f.write('0 %s cm rlineto\n' % gformat(h))
|
||||
self.f.write('closepath\n')
|
||||
self.f.write('%s setlinewidth\n' % gformat(box_style.get_line_width()))
|
||||
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(box_style.get_color()))
|
||||
self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x, y)))
|
||||
self.file.write('0 -%s cm rlineto\n' % gformat(h))
|
||||
self.file.write('%s cm 0 rlineto\n' % gformat(w))
|
||||
self.file.write('0 %s cm rlineto\n' % gformat(h))
|
||||
self.file.write('closepath\n')
|
||||
self.file.write('%s setlinewidth\n' % gformat(box_style.get_line_width()))
|
||||
self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(box_style.get_color()))
|
||||
if text != "":
|
||||
para_name = box_style.get_paragraph_style()
|
||||
assert( para_name != '' )
|
||||
p = style_sheet.get_paragraph_style(para_name)
|
||||
(text, fdef) = self.encode_text(p, text)
|
||||
self.f.write(fdef)
|
||||
self.file.write(fdef)
|
||||
lines = text.split('\n')
|
||||
|
||||
nlines = len(lines)
|
||||
@ -339,9 +347,9 @@ class PSDrawDoc(BaseDoc,DrawDoc):
|
||||
ystart = center - (fs/2.0) * nlines
|
||||
for i in range(nlines):
|
||||
ypos = ystart + (i * fs)
|
||||
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x+mar,ypos)))
|
||||
self.f.write("(%s) show\n" % lines[i])
|
||||
self.f.write('grestore\n')
|
||||
self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x+mar, ypos)))
|
||||
self.file.write("(%s) show\n" % lines[i])
|
||||
self.file.write('grestore\n')
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
SVG document generator.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
@ -45,8 +49,8 @@ import Errors
|
||||
#-------------------------------------------------------------------------
|
||||
class SvgDrawDoc(BaseDoc, DrawDoc):
|
||||
|
||||
def __init__(self,styles,type,template):
|
||||
BaseDoc.__init__(self,styles,type,template)
|
||||
def __init__(self, styles, type):
|
||||
BaseDoc.__init__(self, styles, type)
|
||||
self.f = None
|
||||
self.filename = None
|
||||
self.level = 0
|
||||
@ -249,7 +253,6 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
|
||||
para_name = box_style.get_paragraph_style()
|
||||
p = style_sheet.get_paragraph_style(para_name)
|
||||
font = p.get_font()
|
||||
font_size = font.get_size()
|
||||
width = self.string_width(font, text) / 72
|
||||
x = x - width
|
||||
self.draw_text(style, text, x, y)
|
||||
|
Loading…
Reference in New Issue
Block a user