From e9832261127c2285157bf1e5b3b488053e4afd06 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 18 Feb 2005 01:10:25 +0000 Subject: [PATCH] * src/docgen/LPRDoc.py (write_at): Correct vertical offset. * src/docgen/PdfDoc.py (write_at,draw_bar): Add functions. * src/docgen/PSDrawDoc.py (write_at): Add function; (draw_bar): Support for filling with color. * src/ReportUtils.py (draw_legend): Correct vertical offset. svn: r4045 --- ChangeLog | 7 +++++++ src/ReportUtils.py | 2 +- src/docgen/LPRDoc.py | 2 +- src/docgen/PSDrawDoc.py | 17 ++++++++++++++++- src/docgen/PdfDoc.py | 29 ++++++++++++++++++++++++++--- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f82de4587..7e0eea66d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-02-17 Alex Roitman + * src/docgen/LPRDoc.py (write_at): Correct vertical offset. + * src/docgen/PdfDoc.py (write_at,draw_bar): Add functions. + * src/docgen/PSDrawDoc.py (write_at): Add function; + (draw_bar): Support for filling with color. + * src/ReportUtils.py (draw_legend): Correct vertical offset. + 2005-02-16 Don Allingham * src/EditSource.py: commit events after deleting sources * src/Marriage.py: disable buttons in readonly mode diff --git a/src/ReportUtils.py b/src/ReportUtils.py index 74a0102ce..90decceac 100644 --- a/src/ReportUtils.py +++ b/src/ReportUtils.py @@ -121,7 +121,7 @@ def draw_legend(doc, start_x, start_y, data): size = pt2cm(doc.get_style(pstyle).get_font().get_size()) doc.draw_bar(format, start_x, start_y, start_x + (2*size), start_y + size) - doc.write_at(pstyle, legend, start_x + (3*size), start_y + (size*0.25)) + doc.write_at(pstyle, legend, start_x + (3*size), start_y - (size*0.25)) start_y += size * 1.3 def draw_vertical_bar_graph(doc, format, start_x, start_y, height, width, data): diff --git a/src/docgen/LPRDoc.py b/src/docgen/LPRDoc.py index c1c6124a3..11048b0b0 100644 --- a/src/docgen/LPRDoc.py +++ b/src/docgen/LPRDoc.py @@ -1071,7 +1071,7 @@ class LPRDoc(BaseDoc.BaseDoc): self.gpc.setfont(find_font_from_fontstyle(fontstyle)) x = self.left_margin + cm2u(x) - y = self.top_margin - cm2u(y) + y = self.top_margin - cm2u(y) - fontstyle.get_size() * _EXTRA_SPACING_FACTOR self.gpc.moveto(x,y) self.gpc.show(text) diff --git a/src/docgen/PSDrawDoc.py b/src/docgen/PSDrawDoc.py index d85b236e6..30a9d0df2 100644 --- a/src/docgen/PSDrawDoc.py +++ b/src/docgen/PSDrawDoc.py @@ -313,6 +313,17 @@ class PSDrawDoc(BaseDoc.BaseDoc): def patch_text(self,text): return text.encode('iso-8859-1') + def write_at(self,style,text,x,y): + para_style = self.style_list[style] + + x = x + self.lmargin + y = y + self.tmargin + + self.f.write('gsave\n') + self.f.write('%f cm %f cm moveto\n' % self.translate(x,y)) + self.f.write(self.fontdef(para_style)) + self.f.write('(%s) show grestore\n' % text) + def draw_bar(self,style,x1,y1,x2,y2): x1 = x1 + self.lmargin x2 = x2 + self.lmargin @@ -320,6 +331,9 @@ class PSDrawDoc(BaseDoc.BaseDoc): y2 = y2 + self.tmargin box_type = self.draw_styles[style] + fill_color = rgb_color(box_type.get_fill_color()) + color = rgb_color(box_type.get_color()) + self.f.write('gsave\n') self.f.write("%f cm %f cm moveto\n" % self.translate(x1,y1)) self.f.write("0 %f cm rlineto\n" % (y2-y1)) @@ -327,7 +341,8 @@ class PSDrawDoc(BaseDoc.BaseDoc): self.f.write("0 %f cm rlineto\n" % (y1-y2)) self.f.write('closepath\n') self.f.write("%.4f setlinewidth\n" % box_type.get_line_width()) - self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % rgb_color(box_type.get_color())) + self.f.write('gsave %.4f %.4f %.4f setrgbcolor fill grestore\n' % fill_color) + self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % color) self.f.write('grestore\n') def draw_box(self,style,text,x,y): diff --git a/src/docgen/PdfDoc.py b/src/docgen/PdfDoc.py index bdde9f94a..6db367115 100644 --- a/src/docgen/PdfDoc.py +++ b/src/docgen/PdfDoc.py @@ -379,7 +379,7 @@ class PdfDoc(BaseDoc.BaseDoc): self.drawing = reportlab.graphics.shapes.Drawing(x,y) def end_page(self): - self.story.append(self.drawing) + self.story.append(self.drawing) def draw_line(self,style,x1,y1,x2,y2): y1 = self.get_usable_height() - y1 @@ -397,8 +397,31 @@ class PdfDoc(BaseDoc.BaseDoc): strokeDashArray=line_array) self.drawing.add(l) - def draw_bar(self,style,x1,y1,x2,y2): - pass + def write_at(self, style, text, x, y): + para_style = self.style_list[style] + font_style = para_style.get_font() + size = font_style.get_size() + y = self.get_usable_height() - y + + if text != "": + lines = text.split('\n') + self.left_print(lines,font_style,x*cm,y*cm - size) + + def draw_bar(self, style, x1, y1, x2, y2): + style = self.draw_styles[style] + fill_color = make_color(style.get_fill_color()) + color = make_color(style.get_color()) + line_width = style.get_line_width() + w = (x2-x1)*cm + h = (y2-y1)*cm + + y1 = self.get_usable_height() - y1 + + r = reportlab.graphics.shapes.Rect((x1)*cm,(y1*cm)-h,w,h, + strokeWidth=line_width, + fillColor=fill_color, + strokeColor=color) + self.drawing.add(r) def draw_path(self,style,path): stype = self.draw_styles[style]