From 8eaa83a5e8507a723600cf9c7d2322df2469e2cd Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Wed, 25 Jan 2012 23:28:42 +0000 Subject: [PATCH] 0005533: RTFDoc produces invalid RTF when bold and normal are mixed in a paragraph. start_bold and end_bold changed to store data in the self.text buffer svn: r18770 --- src/plugins/docgen/RTFDoc.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/plugins/docgen/RTFDoc.py b/src/plugins/docgen/RTFDoc.py index 6e1d87114..cb8d07bbf 100644 --- a/src/plugins/docgen/RTFDoc.py +++ b/src/plugins/docgen/RTFDoc.py @@ -30,6 +30,8 @@ # #------------------------------------------------------------------------ from gen.ggettext import gettext as _ +import logging +LOG = logging.getLogger(".rtfdoc") #------------------------------------------------------------------------ # @@ -240,6 +242,9 @@ class RTFDoc(BaseDoc,TextDoc): # there is no newline between the description and the note. if not self.in_table: self.f.write(self.text) + LOG.debug("end_paragraph: opened: %d write: %s" % + (self.opened, + self.text + '}' if self.opened else "" + "newline")) if self.opened: self.f.write('}') self.opened = 0 @@ -264,9 +269,12 @@ class RTFDoc(BaseDoc,TextDoc): # #-------------------------------------------------------------------- def start_bold(self): + LOG.debug("start_bold: opened: %d saved text: %s" % + (self.opened, + '}' if self.opened else "" + '{%s\\b ' % self.font_type)) if self.opened: - self.f.write('}') - self.f.write('{%s\\b ' % self.font_type) + self.text += '}' + self.text += '{%s\\b ' % self.font_type self.opened = 1 #-------------------------------------------------------------------- @@ -275,10 +283,14 @@ class RTFDoc(BaseDoc,TextDoc): # #-------------------------------------------------------------------- def end_bold(self): + LOG.debug("end_bold: opened: %d saved text: %s" % + (self.opened, + self.text + '}')) + if not self.opened == 1: + print self.opened + raise RuntimeError self.opened = 0 - self.f.write(self.text) - self.text = "" - self.f.write('}') + self.text += '}' def start_superscript(self): self.text += '{{\*\updnprop5801}\up10 ' @@ -463,6 +475,9 @@ class RTFDoc(BaseDoc,TextDoc): # Convert to unicode, just in case it's not. Fix of bug 2449. text = unicode(text) text = text.replace('\n','\n\\par ') + LOG.debug("write_text: opened: %d input text: %s" % + (self.opened, + text)) if self.opened == 0: self.opened = 1 self.text += '{%s ' % self.font_type @@ -483,6 +498,9 @@ class RTFDoc(BaseDoc,TextDoc): if links == True: import re self.text = re.sub(URL_PATTERN, _CLICKABLE, self.text) + LOG.debug("write_text, exit: opened: %d saved text: %s" % + (self.opened, + self.text)) def process_spaces(line, format): """