From eb5135310f959b88d30c41e887e36f9d6cbc7136 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Fri, 15 Jun 2007 04:07:41 +0000 Subject: [PATCH] Improve text rendering for SVG reports (#0001072). svn: r8553 --- ChangeLog | 3 ++ src/docgen/SvgDrawDoc.py | 114 ++++++++++++++++++++------------------- 2 files changed, 62 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd5a59ebb..eeca8753e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-06-14 Brian Matherly + * src/docgen/SvgDrawDoc.py: improve text rendering (#0001072) + 2007-06-13 Alex Roitman * src/ViewManager.py: Enable recent files. * src/DisplayState.py (RecentDocsMenu.load): work out directories; diff --git a/src/docgen/SvgDrawDoc.py b/src/docgen/SvgDrawDoc.py index 98b2d7462..db02b62c5 100644 --- a/src/docgen/SvgDrawDoc.py +++ b/src/docgen/SvgDrawDoc.py @@ -27,6 +27,7 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import StringIO #------------------------------------------------------------------------- # @@ -50,7 +51,7 @@ class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc): 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": @@ -62,7 +63,7 @@ class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc): 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: @@ -74,6 +75,8 @@ class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc): 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('') + 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() @@ -193,22 +197,22 @@ class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc): 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.paper.get_left_margin() @@ -222,22 +226,22 @@ class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc): 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): style_sheet = self.get_style_sheet()