Remove the write_at function. Use draw_text instead. Add center_text to SVGDoc
svn: r8101
This commit is contained in:
parent
5230306111
commit
9a179f7ec3
@ -1,4 +1,16 @@
|
||||
2007-02-10 Brian Matherly <brian@gramps-project.org>
|
||||
2007-02-12 Brian Matherly <brian@gramps-project.org>
|
||||
* 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 <brian@gramps-project.org>
|
||||
* src/BaseDoc.py: remove unused functions
|
||||
* src/docgen/KwordDoc.py: remove unused functions
|
||||
* src/docgen/OpenOfficeDoc.py: remove unused functions
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -1145,31 +1145,6 @@ class ODFDoc(BaseDoc.BaseDoc):
|
||||
self.cntnt.write('</draw:text-box>')
|
||||
self.cntnt.write('</draw:frame>\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('<draw:frame text:anchor-type="paragraph" ')
|
||||
self.cntnt.write('draw:z-index="0" ')
|
||||
self.cntnt.write('draw:style-name="F%s" ' % style)
|
||||
self.cntnt.write('svg:width="%.2fcm" ' % size)
|
||||
self.cntnt.write('svg:height="%.2fpt" ' % font.get_size())
|
||||
|
||||
self.cntnt.write('svg:x="%.2fcm" ' % x)
|
||||
self.cntnt.write('svg:y="%.2fcm">\n' % float(y))
|
||||
|
||||
if text != "":
|
||||
self.cntnt.write('<draw:text-box>')
|
||||
self.cntnt.write('<text:p text:style-name="%s">' % style)
|
||||
self.cntnt.write('<text:span text:style-name="X%s">' % style)
|
||||
self.cntnt.write(text)
|
||||
self.cntnt.write('</text:span>\n')
|
||||
self.cntnt.write('</text:p>\n')
|
||||
self.cntnt.write('</draw:text-box>')
|
||||
self.cntnt.write('</draw:frame>\n')
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Register plugins
|
||||
|
@ -986,26 +986,6 @@ class OpenOfficeDoc(BaseDoc.BaseDoc):
|
||||
self.cntnt.write('</text:p>\n')
|
||||
self.cntnt.write('</draw:text-box>\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('<draw:text-box text:anchor-type="paragraph" ')
|
||||
self.cntnt.write('draw:z-index="0" ')
|
||||
self.cntnt.write('svg:width="%.3fcm" ' % size)
|
||||
self.cntnt.write('svg:height="%.3fpt" ' % font.get_size())
|
||||
|
||||
self.cntnt.write('svg:x="%.3fcm" ' % x)
|
||||
self.cntnt.write('svg:y="%.3fcm">\n' % float(y))
|
||||
|
||||
if text != "":
|
||||
self.cntnt.write('<text:p text:style-name="X%s">' % style)
|
||||
self.cntnt.write(text)
|
||||
self.cntnt.write('</text:p>\n')
|
||||
self.cntnt.write('</draw:text-box>\n')
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
#
|
||||
# Register plugins
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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('</text>\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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user