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
This commit is contained in:
Tim G L Lyons 2012-01-25 23:28:42 +00:00
parent 520287dacc
commit 8eaa83a5e8

View File

@ -30,6 +30,8 @@
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.ggettext import gettext as _ 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. # there is no newline between the description and the note.
if not self.in_table: if not self.in_table:
self.f.write(self.text) 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: if self.opened:
self.f.write('}') self.f.write('}')
self.opened = 0 self.opened = 0
@ -264,9 +269,12 @@ class RTFDoc(BaseDoc,TextDoc):
# #
#-------------------------------------------------------------------- #--------------------------------------------------------------------
def start_bold(self): 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: if self.opened:
self.f.write('}') self.text += '}'
self.f.write('{%s\\b ' % self.font_type) self.text += '{%s\\b ' % self.font_type
self.opened = 1 self.opened = 1
#-------------------------------------------------------------------- #--------------------------------------------------------------------
@ -275,10 +283,14 @@ class RTFDoc(BaseDoc,TextDoc):
# #
#-------------------------------------------------------------------- #--------------------------------------------------------------------
def end_bold(self): 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.opened = 0
self.f.write(self.text) self.text += '}'
self.text = ""
self.f.write('}')
def start_superscript(self): def start_superscript(self):
self.text += '{{\*\updnprop5801}\up10 ' 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. # Convert to unicode, just in case it's not. Fix of bug 2449.
text = unicode(text) text = unicode(text)
text = text.replace('\n','\n\\par ') text = text.replace('\n','\n\\par ')
LOG.debug("write_text: opened: %d input text: %s" %
(self.opened,
text))
if self.opened == 0: if self.opened == 0:
self.opened = 1 self.opened = 1
self.text += '{%s ' % self.font_type self.text += '{%s ' % self.font_type
@ -483,6 +498,9 @@ class RTFDoc(BaseDoc,TextDoc):
if links == True: if links == True:
import re import re
self.text = re.sub(URL_PATTERN, _CLICKABLE, self.text) 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): def process_spaces(line, format):
""" """