Fix of issue 2848.

svn: r14064
This commit is contained in:
Peter Landgren 2010-01-13 18:40:55 +00:00
parent 5d1ac53678
commit 27dd026a97
5 changed files with 92 additions and 41 deletions

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
# Copyright (C) 2010 Peter Landgren
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -123,6 +124,10 @@ def reformat_para(para='',left=0,right=72,just=LEFT,right_pad=0,first=0):
#------------------------------------------------------------------------
class AsciiDoc(BaseDoc,TextDoc):
def __init__(self, styles, type):
BaseDoc.__init__(self, styles, type)
self.__note_format = False
#--------------------------------------------------------------------
#
# Opens the file, resets the text buffer.
@ -239,8 +244,13 @@ class AsciiDoc(BaseDoc,TextDoc):
# line indent, as specified by style.
this_text = reformat_para(self.text,regular_indent,right,fmt,
right_pad,first_indent)
this_text += '\n' + the_pad + '\n'
if self.__note_format:
# don't add an extra LF before the_pad if preformatted notes.
if this_text != '\n':
# don't add LF if there is this_text is a LF
this_text += the_pad + '\n'
else:
this_text += '\n' + the_pad + '\n'
if self.in_cell:
self.cellpars[self.cellnum] = self.cellpars[self.cellnum] + \
@ -343,12 +353,20 @@ class AsciiDoc(BaseDoc,TextDoc):
else:
self.f.write(this_text)
def write_note(self,text,format,style_name):
def write_styled_note(self,styledtext,format,style_name):
text = str(styledtext)
if format == 1:
# Preformatted note
self.__note_format = True
for line in text.split('\n'):
self.start_paragraph(style_name)
self.write_text(line)
self.end_paragraph()
# Add an extra LF after all lines in each preformatted note
self.__note_format = False
self.start_paragraph(style_name)
self.write_text('\n')
self.end_paragraph()
elif format == 0:
for line in text.split('\n\n'):
self.start_paragraph(style_name)
@ -357,6 +375,21 @@ class AsciiDoc(BaseDoc,TextDoc):
self.write_text(line)
self.end_paragraph()
def write_endnotes_ref(self, text, style_name):
"""
Overwrite base method for lines of endnotes references
"""
self.__note_format = True
for line in text.split('\n'):
self.start_paragraph(style_name)
self.write_text(line)
self.end_paragraph()
# Add an extra LF after all lines in each preformatted note
self.__note_format = False
self.start_paragraph(style_name)
self.write_text('\n')
self.end_paragraph()
#--------------------------------------------------------------------
#
# Writes text.

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
# Copyright (C) 2010 Peter Landgren
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -450,28 +451,19 @@ class HtmlDoc(BaseDoc, TextDoc):
"""
self.__reduce_list()
def write_note(self, text, format, style_name):
def write_endnotes_ref(self, text, style_name):
"""
Overwrite base method
Overwrite base method for lines of endnotes references
"""
self.htmllist += [Html('div', id='grampsstylednote')]
if format == 1:
#preformatted, retain whitespace.
# User should use write_styled_note for correct behavior, in this
# more basic method we convert all to a monospace character
for line in text.split('\n'):
# more basic method we convert all to a monospace character
self.htmllist += [Html('pre', class_=style_name,
style = 'font-family: courier, monospace',
indent=None, inline=True)]
self.write_text(text)
style = 'font-family: courier, monospace',
indent=None, inline=True)]
self.write_text(line)
#end pre element
self.__reduce_list()
elif format == 0:
for line in text.split('\n\n'):
self.start_paragraph(style_name)
self.write_text(line)
self.end_paragraph()
else:
raise NotImplementedError
#end div element
self.__reduce_list()

View File

@ -7,6 +7,7 @@
# 2002-2003 Donald A. Peterson
# 2003 Alex Roitman
# 2009 Benny Malengier
# 2010 Peter Landgren
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -647,12 +648,17 @@ class LaTeXDoc(BaseDoc, TextDoc):
#preformatted finished, go back to normal escape function
self._backend.setescape(False)
def write_note(self,text,format,style_name):
"""Write the note's text to the file, respecting the format"""
self.start_paragraph(style_name)
if format == 1:
self._backend.write('\\begin{verbatim}')
self.write_text(text)
if format == 1:
self._backend.write('\\end{verbatim}')
self.end_paragraph()
def write_endnotes_ref(self, text, style_name):
"""
Overwrite base method for lines of endnotes references
"""
self._backend.write("\\begin{minipage}{{0.8\\linewidth}}\n")
for line in text.split('\n'):
self.start_paragraph(style_name)
if format == 0:
self._backend.write('\\begin{verbatim}')
self.write_text(line)
if format == 0:
self._backend.write('\\end{verbatim}')
self.end_paragraph()
self._backend.write("\n\\vspace*{0.5cm} \n\end{minipage}\n\n")

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2005-2009 Serge Noiraud
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2010 Peter Landgren
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -1185,27 +1186,21 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
self.cntnt.write('</text:h>\n')
self.new_cell = 1
def write_note(self, text, format, style_name):
def write_endnotes_ref(self, text, style_name):
"""
write a note
Overwrite base method for lines of endnotes references
"""
if format == 1:
text = escape(text, _esc_map)
for line in text.split('\n'):
text = escape(line, _esc_map)
# Replace multiple spaces: have to go from the largest number down
for n in range(text.count(' '), 1, -1):
text = text.replace(' '*n, ' <text:s text:c="%d"/>' % (n-1) )
self.start_paragraph(style_name)
self.cntnt.write('<text:span text:style-name="GRAMPS-preformat">')
# self.cntnt.write('<text:span text:style-name="GRAMPS-preformat">')
self.cntnt.write('<text:span text:style-name="Standard">')
self.cntnt.write(text)
self.cntnt.write('</text:span>')
self.end_paragraph()
elif format == 0:
for line in text.split('\n\n'):
self.start_paragraph(style_name)
line = line.replace('\n', ' ')
line = ' '.join(line.split())
self.write_text(line)
self.end_paragraph()
def write_styled_note(self, styledtext, format, style_name):
"""

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Gary Burton
# Copyright (C) 2010 Peter Landgren
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -395,11 +396,16 @@ class RTFDoc(BaseDoc,TextDoc):
index = index+1
self.f.write('}}\\par\n')
def write_note(self,text,format,style_name):
def write_styled_note(self,styledtext,format,style_name):
text = str(styledtext)
if format == 1:
# Preformatted note
for line in text.split('\n'):
self.start_paragraph(style_name)
self.write_text(line)
if self.in_table:
# Add LF when in table as in indiv_complete report
self.write_text('\n')
self.end_paragraph()
elif format == 0:
for line in text.split('\n\n'):
@ -408,6 +414,25 @@ class RTFDoc(BaseDoc,TextDoc):
line = ' '.join(line.split())
self.write_text(line)
self.end_paragraph()
self.start_paragraph(style_name)
self.write_text('\n')
self.end_paragraph()
def write_endnotes_ref(self,text,style_name):
"""
Overwrite base method for lines of endnotes references
"""
for line in text.split('\n'):
self.start_paragraph(style_name)
self.write_text(line)
if self.in_table:
# Add LF when in table as in indiv_complete report
self.write_text('\n')
self.end_paragraph()
# Write NL after all ref lines for each source
self.start_paragraph(style_name)
self.write_text('\n')
self.end_paragraph()
#--------------------------------------------------------------------
#