From 9a179f7ec356816af637f716e36ed194158c2c2f Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Tue, 13 Feb 2007 04:46:29 +0000 Subject: [PATCH] Remove the write_at function. Use draw_text instead. Add center_text to SVGDoc svn: r8101 --- gramps2/ChangeLog | 14 +++++++++++++- gramps2/src/BaseDoc.py | 3 --- gramps2/src/ReportBase/_ReportUtils.py | 15 +++++++++------ gramps2/src/docgen/GtkPrint.py | 3 --- gramps2/src/docgen/LPRDoc.py | 11 ----------- gramps2/src/docgen/ODFDoc.py | 25 ------------------------- gramps2/src/docgen/OpenOfficeDoc.py | 20 -------------------- gramps2/src/docgen/PSDrawDoc.py | 13 ------------- gramps2/src/docgen/PdfDoc.py | 10 ---------- gramps2/src/docgen/SvgDrawDoc.py | 12 +++++++++++- gramps2/src/plugins/StatisticsChart.py | 11 +++++++++-- 11 files changed, 42 insertions(+), 95 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index b1ed237b5..6bfcbe608 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,16 @@ -2007-02-10 Brian Matherly +2007-02-12 Brian Matherly + * src/BaseDoc.py: remove write_at + * src/docgen/PSDrawDoc.py: remove write_at + * src/docgen/SvgDrawDoc.py: remove write_at, add center_text + * src/docgen/OpenOfficeDoc.py: remove write_at + * src/docgen/PdfDoc.py: remove write_at + * src/docgen/GtkPrint.py: remove write_at + * src/plugins/StatisticsChart.py: pass draw style to legend + * src/docgen/LPRDoc.py: remove write_at + * src/docgen/ODFDoc.py: remove write_at + * src/ReportBase/_ReportUtils.py + +2007-02-12 Brian Matherly * src/BaseDoc.py: remove unused functions * src/docgen/KwordDoc.py: remove unused functions * src/docgen/OpenOfficeDoc.py: remove unused functions diff --git a/gramps2/src/BaseDoc.py b/gramps2/src/BaseDoc.py index a09b928e1..ea3c7aa6c 100644 --- a/gramps2/src/BaseDoc.py +++ b/gramps2/src/BaseDoc.py @@ -1430,9 +1430,6 @@ class BaseDoc: def draw_box(self, style, text, x, y): pass - def write_at(self, style, text, x, y): - pass - def draw_bar(self, style, x1, y1, x2, y2): pass diff --git a/gramps2/src/ReportBase/_ReportUtils.py b/gramps2/src/ReportBase/_ReportUtils.py index 315b192db..025a7d8a8 100644 --- a/gramps2/src/ReportBase/_ReportUtils.py +++ b/gramps2/src/ReportBase/_ReportUtils.py @@ -903,7 +903,7 @@ def draw_pie_chart(doc, center_x, center_y, radius, data, start=0): doc.draw_wedge(item[0], center_x, center_y, radius, start, start + incr) start += incr -def draw_legend(doc, start_x, start_y, data, title=None): +def draw_legend(doc, start_x, start_y, data, title, label_style): """ Draws a legend for a graph in the specified document. The data passed is used to define the legend. First item style is used for the optional @@ -923,16 +923,19 @@ def draw_legend(doc, start_x, start_y, data, title=None): legend_description). @type data: list """ + if title: + gstyle = doc.get_draw_style(label_style) + pstyle = gstyle.get_paragraph_style() + size = pt2cm(doc.get_style(pstyle).get_font().get_size()) + doc.draw_text(label_style, title, start_x + (3*size), start_y - (size*0.25)) + start_y += size * 1.3 + for (format, size, legend) in data: gstyle = doc.get_draw_style(format) pstyle = gstyle.get_paragraph_style() size = pt2cm(doc.get_style(pstyle).get_font().get_size()) - if title: - doc.write_at(pstyle, title, start_x + (3*size), start_y - (size*0.25)) - start_y += size * 1.3 - title = None 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.draw_text(label_style, 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/gramps2/src/docgen/GtkPrint.py b/gramps2/src/docgen/GtkPrint.py index d13e9f51c..43304eec8 100644 --- a/gramps2/src/docgen/GtkPrint.py +++ b/gramps2/src/docgen/GtkPrint.py @@ -412,9 +412,6 @@ class GtkDoc(BaseDoc.BaseDoc): def draw_line(self,style,x1,y1,x2,y2): pass - def write_at(self, style, text, x, y): - pass - def draw_bar(self, style, x1, y1, x2, y2): pass diff --git a/gramps2/src/docgen/LPRDoc.py b/gramps2/src/docgen/LPRDoc.py index 3ff81dfe5..ee92f38c0 100644 --- a/gramps2/src/docgen/LPRDoc.py +++ b/gramps2/src/docgen/LPRDoc.py @@ -1101,17 +1101,6 @@ class LPRDoc(BaseDoc.BaseDoc): self.gpc.show(line) start_y -= fontstyle.get_size() * _EXTRA_SPACING_FACTOR - def write_at (self, style, text, x, y): - self.brand_new_page = 0 - para_style = self.style_list[style] - fontstyle = para_style.get_font() - - self.gpc.setfont(find_font_from_fontstyle(fontstyle)) - x = self.left_margin + cm2u(x) - y = self.top_margin - cm2u(y) - fontstyle.get_size() * _EXTRA_SPACING_FACTOR - self.gpc.moveto(x,y) - self.gpc.show(text) - def draw_bar(self, style, x1, y1, x2, y2): self.brand_new_page = 0 diff --git a/gramps2/src/docgen/ODFDoc.py b/gramps2/src/docgen/ODFDoc.py index a02a530f0..565605ce7 100644 --- a/gramps2/src/docgen/ODFDoc.py +++ b/gramps2/src/docgen/ODFDoc.py @@ -1145,31 +1145,6 @@ class ODFDoc(BaseDoc.BaseDoc): self.cntnt.write('') self.cntnt.write('\n') - def write_at(self,style,text,x,y): - pstyle = self.style_list[style] - font = pstyle.get_font() - - size = 1.2*(FontScale.string_width(font,text)/72.0) * 2.54 - - self.cntnt.write('\n' % float(y)) - - if text != "": - self.cntnt.write('') - self.cntnt.write('' % style) - self.cntnt.write('' % style) - self.cntnt.write(text) - self.cntnt.write('\n') - self.cntnt.write('\n') - self.cntnt.write('') - self.cntnt.write('\n') - #-------------------------------------------------------------------------- # # Register plugins diff --git a/gramps2/src/docgen/OpenOfficeDoc.py b/gramps2/src/docgen/OpenOfficeDoc.py index ed4dcec8d..d5f9ae6e9 100644 --- a/gramps2/src/docgen/OpenOfficeDoc.py +++ b/gramps2/src/docgen/OpenOfficeDoc.py @@ -986,26 +986,6 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): self.cntnt.write('\n') self.cntnt.write('\n') - def write_at(self,style,text,x,y): - pstyle = self.style_list[style] - font = pstyle.get_font() - - size = 1.1*(FontScale.string_width(font,text)/72.0) * 2.54 - - self.cntnt.write('\n' % float(y)) - - if text != "": - self.cntnt.write('' % style) - self.cntnt.write(text) - self.cntnt.write('\n') - self.cntnt.write('\n') - #-------------------------------------------------------------------------- # # Register plugins diff --git a/gramps2/src/docgen/PSDrawDoc.py b/gramps2/src/docgen/PSDrawDoc.py index cfb75ae9e..259675526 100644 --- a/gramps2/src/docgen/PSDrawDoc.py +++ b/gramps2/src/docgen/PSDrawDoc.py @@ -354,19 +354,6 @@ class PSDrawDoc(BaseDoc.BaseDoc): self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color())) self.f.write('grestore\n') - def write_at(self,style,text,x,y): - para_style = self.style_list[style] - - x = x + self.lmargin - y = y + self.tmargin - - (text,fdef) = self.encode_text(para_style,text) - - self.f.write('gsave\n') - self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x,y))) - self.f.write(fdef) - 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 diff --git a/gramps2/src/docgen/PdfDoc.py b/gramps2/src/docgen/PdfDoc.py index 653d1bc69..c13055454 100644 --- a/gramps2/src/docgen/PdfDoc.py +++ b/gramps2/src/docgen/PdfDoc.py @@ -431,16 +431,6 @@ class PdfDoc(BaseDoc.BaseDoc): strokeDashArray=line_array) self.drawing.add(l) - 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()) diff --git a/gramps2/src/docgen/SvgDrawDoc.py b/gramps2/src/docgen/SvgDrawDoc.py index 7f46f3a0d..d5d7b4be3 100644 --- a/gramps2/src/docgen/SvgDrawDoc.py +++ b/gramps2/src/docgen/SvgDrawDoc.py @@ -166,7 +166,7 @@ class SvgDrawDoc(BaseDoc.BaseDoc): self.f.write('y="%4.2fcm" ' % y1) self.f.write('width="%4.2fcm" ' % (x2-x1)) self.f.write('height="%4.2fcm" ' % (y2-y1)) - self.f.write('style="fill:##%02x%02x%02x; ' % s.get_fill_color()) + self.f.write('style="fill:#%02x%02x%02x; ' % s.get_fill_color()) self.f.write('stroke:#%02x%02x%02x; ' % s.get_color()) self.f.write('stroke-width:%.2f;"/>\n' % s.get_line_width()) @@ -251,6 +251,16 @@ class SvgDrawDoc(BaseDoc.BaseDoc): self.f.write(text) self.f.write('\n') + def center_text(self, style, text, x, y): + box_style = self.draw_styles[style] + para_name = box_style.get_paragraph_style() + p = self.style_list[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) + def units(val): return (val[0]*35.433, val[1]*35.433) diff --git a/gramps2/src/plugins/StatisticsChart.py b/gramps2/src/plugins/StatisticsChart.py index 4d7287499..da677505e 100644 --- a/gramps2/src/plugins/StatisticsChart.py +++ b/gramps2/src/plugins/StatisticsChart.py @@ -640,6 +640,13 @@ class StatisticsChart(Report): g.set_line_width(width) self.doc.add_draw_style("SC-bar",g) + # legend + g = BaseDoc.GraphicsStyle() + g.set_paragraph_style('SC-Text') + g.set_color((0,0,0)) + g.set_fill_color((255,255,255)) + g.set_line_width(0) + self.doc.add_draw_style("SC-legend",g) def write_report(self): "output the selected statistics..." @@ -685,7 +692,7 @@ class StatisticsChart(Report): yoffset = yoffset + radius + margin text = _("%s (persons):") % typename - ReportUtils.draw_legend(self.doc, legendx, yoffset, chart_data, text) + ReportUtils.draw_legend(self.doc, legendx, yoffset, chart_data, text,'SC-legend') def output_barchart(self, title, typename, data, lookup): @@ -809,7 +816,7 @@ class StatisticsChartOptions(ReportOptions): f.set_type_face(BaseDoc.FONT_SERIF) p = BaseDoc.ParagraphStyle() p.set_font(f) - p.set_alignment(BaseDoc.PARA_ALIGN_RIGHT) + p.set_alignment(BaseDoc.PARA_ALIGN_LEFT) p.set_description(_("The style used for the items and values.")) default_style.add_style("SC-Text",p)