2633: Characters in Notes don't show in report - 3.0.4 and trunk

1357: Incorrect marriage event description when outputting to PDF 
1328: opened a gedcom, and create a pdf text file 
Correctly escape text for cairo layout before writing


svn: r11892
This commit is contained in:
Benny Malengier 2009-02-07 09:47:25 +00:00
parent 0b1652198e
commit 38c04c0a50

View File

@ -29,6 +29,7 @@
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from math import radians from math import radians
from xml.sax.saxutils import escape
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -1083,16 +1084,16 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self._active_element.add_child(GtkDocPagebreak()) self._active_element.add_child(GtkDocPagebreak())
def start_bold(self): def start_bold(self):
self.write_text('<b>') self.write_text('<b>', True)
def end_bold(self): def end_bold(self):
self.write_text('</b>') self.write_text('</b>', True)
def start_superscript(self): def start_superscript(self):
self.write_text('<small><sup>') self.write_text('<small><sup>', True)
def end_superscript(self): def end_superscript(self):
self.write_text('</sup></small>') self.write_text('</sup></small>', True)
def start_paragraph(self, style_name, leader=None): def start_paragraph(self, style_name, leader=None):
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
@ -1142,6 +1143,14 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self._active_element = self._active_element.get_parent() self._active_element = self._active_element.get_parent()
def write_note(self, text, format, style_name): def write_note(self, text, format, style_name):
"""
Method to write the note objects text on a
Document
"""
# We need to escape the text here for later pango.Layout.set_markup
# calls. This way we save the markup created by the report
# The markup in the note editor is not in the text so is not
# considered. It must be added by pango too
if format == 1: if format == 1:
for line in text.split('\n'): for line in text.split('\n'):
self.start_paragraph(style_name) self.start_paragraph(style_name)
@ -1155,11 +1164,18 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self.write_text(line) self.write_text(line)
self.end_paragraph() self.end_paragraph()
def write_text(self, text, mark=None): def write_text(self, text, markup=False):
text = text.replace('&','&amp;') """Write a normal piece of text according to the
# FIXME this is ugly, do we really need it? present style
text = text.replace('<super>', '<small><sup>') If markup=False, no markup is present, the
text = text.replace('</super>', '</sup></small>') text is escaped in writted
If markup=True, some markup is present, so
caller had to escape the text already
"""
if not markup:
#no pango markup, escape the text as it
#should not have happened yet
text = escape(text)
self._active_element.add_text(text) self._active_element.add_text(text)
def add_media_object(self, name, pos, x_cm, y_cm): def add_media_object(self, name, pos, x_cm, y_cm):