diff --git a/ChangeLog b/ChangeLog index 7d56c75b2..6b4e7de3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-06-14 Brian Matherly + * src/docgen/SvgDrawDoc.py: improve text rendering (#0001072) + 2007-06-01 Alex Roitman * data/grampsxml.rng: Add callname. * data/grampsxml.dtd: Add callname. diff --git a/src/docgen/SvgDrawDoc.py b/src/docgen/SvgDrawDoc.py index 1f4488673..26342c6b3 100644 --- a/src/docgen/SvgDrawDoc.py +++ b/src/docgen/SvgDrawDoc.py @@ -26,6 +26,7 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import StringIO #------------------------------------------------------------------------- # @@ -49,7 +50,7 @@ class SvgDrawDoc(BaseDoc.BaseDoc): self.filename = None self.level = 0 self.time = "0000-00-00T00:00:00" - self.page = 0 + self.page = 0 def open(self,filename): if filename[-4:] != ".svg": @@ -61,7 +62,7 @@ class SvgDrawDoc(BaseDoc.BaseDoc): pass def start_page(self): - self.page = self.page + 1 + self.page = self.page + 1 if self.page != 1: name = "%s-%d.svg" % (self.root,self.page) else: @@ -73,6 +74,8 @@ class SvgDrawDoc(BaseDoc.BaseDoc): raise Errors.ReportError(_("Could not create %s") % name, msg) except: raise Errors.ReportError(_("Could not create %s") % name) + + self.t = StringIO.StringIO() self.f.write('\n') self.f.write('\n') def rotate_text(self,style,text,x,y,angle): - stype = self.draw_styles[style] pname = stype.get_paragraph_style() p = self.style_list[pname] - font = p.get_font() + font = p.get_font() size = font.get_size() width = 0 + height = 0 for line in text: width = max(width,self.string_width(font,line)) + height += size -# rangle = -((pi/180.0) * angle) centerx,centery = units((x+self.lmargin,y+self.tmargin)) + xpos = (centerx - (width/2.0)) + ypos = (centery - (height/2.0)) - yh = 0 + self.t.write('') + for line in text: - xw = self.string_width(font,line) - - xpos = (centerx - (xw/2.0)) - ypos = (centery) - xd = 0 - yd = yh -# xd = yh * sin(-rangle) -# yd = yh * cos(-rangle) - - self.f.write('') - self.f.write(line) - self.f.write('\n') - yh += size + # Center this line relative to the rest of the text + linex = xpos + (width - self.string_width(font,line) ) / 2 + self.t.write('' % (linex,size)) + self.t.write(line) + self.t.write('') + self.t.write('\n') def end_page(self): + # Print the text last for each page so that it is rendered on top of + # other graphic elements. + self.f.write(self.t.getvalue()) + self.t.close() self.f.write('\n') self.f.close() @@ -206,22 +208,22 @@ class SvgDrawDoc(BaseDoc.BaseDoc): ystart = center - (fs/2.0) * nlines for i in range(nlines): ypos = ystart + (i * fs) - self.f.write('') + self.t.write(' font-family:serif;') + self.t.write('">') self.f.write(lines[i]) - self.f.write('\n') + self.t.write('\n') def draw_text(self,style,text,x,y): x = x + self.lmargin @@ -234,22 +236,22 @@ class SvgDrawDoc(BaseDoc.BaseDoc): font = p.get_font() font_size = font.get_size() fs = (font_size/28.35) * 1.2 - self.f.write('') - self.f.write(text) - self.f.write('\n') + self.t.write('font-family:serif;') + self.t.write('">') + self.t.write(text) + self.t.write('\n') def center_text(self, style, text, x, y): box_style = self.draw_styles[style]