diff --git a/src/plugins/docgen/ODFDoc.py b/src/plugins/docgen/ODFDoc.py
index 9cc25b21a..6a9fac33e 100644
--- a/src/plugins/docgen/ODFDoc.py
+++ b/src/plugins/docgen/ODFDoc.py
@@ -70,7 +70,7 @@ import zipfile
import time
import locale
from cStringIO import StringIO
-from math import pi, cos, sin
+from math import pi, cos, sin, degrees, radians
from xml.sax.saxutils import escape
#-------------------------------------------------------------------------
@@ -114,6 +114,309 @@ _esc_map = {
import re
NewStyle = re.compile('style-name="([a-zA-Z0-9]*)__([#a-zA-Z0-9 ]*)__">')
+#-------------------------------------------------------------------------
+#
+# Constants
+#
+#-------------------------------------------------------------------------
+
+_XMLNS = '''\
+xmlns:office="%(urn)soffice:1.0"
+xmlns:style="%(urn)sstyle:1.0"
+xmlns:text="%(urn)stext:1.0"
+xmlns:table="%(urn)stable:1.0"
+xmlns:draw="%(urn)sdrawing:1.0"
+xmlns:fo="%(urn)sxsl-fo-compatible:1.0"
+xmlns:xlink="http://www.w3.org/1999/xlink"
+xmlns:dc="http://purl.org/dc/elements/1.1/"
+xmlns:meta="%(urn)smeta:1.0"
+xmlns:number="%(urn)sdatastyle:1.0"
+xmlns:svg="%(urn)ssvg-compatible:1.0"
+xmlns:chart="%(urn)schart:1.0"
+xmlns:dr3d="%(urn)sdr3d:1.0"
+xmlns:math="http://www.w3.org/1998/Math/MathML"
+xmlns:form="%(urn)sform:1.0"
+xmlns:script="%(urn)sscript:1.0"
+xmlns:dom="http://www.w3.org/2001/xml-events"
+xmlns:xforms="http://www.w3.org/2002/xforms"
+''' % {"urn": "urn:oasis:names:tc:opendocument:xmlns:"}
+
+_FONTS = '''\
+
+
+
+
+
+'''
+
+_META_XML = '''\
+
+
+
+
+ %(generator)s
+
+
+
+
+
+
+
+
+ %(creator)s
+
+
+ %(date)s
+
+
+ %(creator)s
+
+
+ %(date)s
+
+0-00-00T00:00:00
+
+ %(lang)s
+
+1
+PT0S
+
+ http://gramps-project.org
+
+
+
+
+
+
+'''
+
+_STYLES = '''\
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+'''
+
+_AUTOMATIC_STYLES = '''\
+
+
+
+
+
+
+
+
+
+
+
+'''
+
+_CLEAR_STYLE = '''\
+\n
+
+\n
+'''
+_OTHER_STYLES = '''\
+\n
+ \n
+\n
+
+\n
+ \n
+\n
+
+\n
+
+\n
+
+
+
+\n
+
+
+
+\n
+
+
+
+\n
+
+
+
+\n
+'''
+
+_SHEADER_FOOTER = '''\
+
+
+\n
+
+
+\n
+'''
+
#-------------------------------------------------------------------------
#
# ODFDoc
@@ -158,10 +461,9 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
t = time.localtime(time.time())
self.time = "%04d-%02d-%02dT%02d:%02d:%02d" % t[:6]
- if filename[-4:] != ".odt":
- self.filename = filename + ".odt"
- else:
- self.filename = filename
+ self.filename = filename
+ if not filename.endswith("odt"):
+ self.filename += ".odt"
self.filename = os.path.normpath(os.path.abspath(self.filename))
self._backend = OdfBackend()
@@ -176,404 +478,302 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
assert (not self.init_called)
self.init_called = True
+ wrt = self.cntnt.write
+ wrt1, wrt2 = self.cntnt1.write, self.cntnt2.write
current_locale = locale.getlocale()
self.lang = current_locale[0]
- if self.lang:
- self.lang = self.lang.replace('_', '-')
- else:
- self.lang = "en-US"
+ self.lang = self.lang.replace('_', '-') if self.lang else "en-US"
self.StyleList = [] # styles to create depending on styled notes.
- self.cntnt1.write('\n')
- self.cntnt1.write('\n')
- self.cntnt1.write('office:version="1.0">\n')
- self.cntnt1.write('\n')
- self.cntnt1.write('\n')
- self.cntnt1.write('\n')
- self.cntnt1.write('\n')
- self.cntnt1.write('\n')
- self.cntnt2.write('\n')
- self.cntnt2.write('\n')
- self.cntnt2.write('\n')
- self.cntnt2.write('\n')
- self.cntnt2.write('\n')
- self.cntnt2.write('')
- self.cntnt2.write('')
- self.cntnt2.write('\n')
- self.cntnt2.write('')
- self.cntnt2.write('')
- self.cntnt2.write('\n')
+ wrt1('\n'
+ '\n' +
+ '\n'
+ )
+ wrt1('\n' +
+ _FONTS
+ )
+ wrt2(
+ '\n' +
+ '\n' +
+ _AUTOMATIC_STYLES
+ )
styles = self.get_style_sheet()
for style_name in styles.get_draw_style_names():
style = styles.get_draw_style(style_name)
- self.cntnt.write('\n')
- self.cntnt.write('\n'
+ '\n')
- self.cntnt.write('\n')
+ wrt('svg:fill-color="#%02x%02x%02x" '
+ % style.get_color())
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
+ wrt(
+ 'draw:fill-color="#%02x%02x%02x" '
+ % style.get_fill_color() +
+ 'draw:shadow="hidden" '
+ 'style:run-through="foreground" '
+ 'style:vertical-pos="from-top" '
+ 'style:vertical-rel="paragraph" '
+ 'style:horizontal-pos="from-left" '
+ 'style:horizontal-rel="paragraph" '
+ 'draw:wrap-influence-on-position='
+ '"once-concurrent" '
+ 'style:flow-with-text="false" '
+ '/>\n'
+ '\n'
+ )
+
+ wrt(
+ '\n'
+ '\n'
+ '\n'
+ )
# Graphic style for items with a clear background
- self.cntnt.write('\n')
- self.cntnt.write('')
- self.cntnt.write('\n')
+ wrt(
+ _CLEAR_STYLE
+ )
for style_name in styles.get_paragraph_style_names():
style = styles.get_paragraph_style(style_name)
- self.cntnt.write('\n' % style_name)
- self.cntnt.write('\n')
- self.cntnt.write('\n')
-
- self.cntnt.write('\n')
- self.cntnt.write('\n' % style_name +
+ '\n' +
+ '\n' +
+
+ '\n' +
+ ' 0:
- self.cntnt.write('fo:keep-with-next="auto" ')
+ wrt('fo:keep-with-next="auto" ')
align = style.get_alignment()
if align == PARA_ALIGN_LEFT:
- self.cntnt.write('fo:text-align="start" ')
+ wrt('fo:text-align="start" ')
elif align == PARA_ALIGN_RIGHT:
- self.cntnt.write('fo:text-align="end" ')
+ wrt('fo:text-align="end" ')
elif align == PARA_ALIGN_CENTER:
- self.cntnt.write('fo:text-align="center" ')
- self.cntnt.write('style:justify-single-word="false" ')
+ wrt(
+ 'fo:text-align="center" '
+ 'style:justify-single-word="false" '
+ )
else:
- self.cntnt.write('fo:text-align="justify" ')
- self.cntnt.write('style:justify-single-word="false" ')
+ wrt(
+ 'fo:text-align="justify" '
+ 'style:justify-single-word="false" '
+ )
font = style.get_font()
- if font.get_type_face() == FONT_SANS_SERIF:
- self.cntnt.write('style:font-name="Arial" ')
- else:
- self.cntnt.write('style:font-name="Times New Roman" ')
- self.cntnt.write('fo:font-size="%.2fpt" ' % font.get_size())
- self.cntnt.write('style:font-size-asian="%.2fpt" ' %
- font.get_size())
- color = font.get_color()
- self.cntnt.write('fo:color="#%02x%02x%02x" ' % color)
+ wrt('style:font-name="%s" ' %
+ ("Arial"
+ if font.get_type_face() == FONT_SANS_SERIF else
+ "Times New Roman")
+ )
+
+ wrt(
+ 'fo:font-size="%.2fpt" ' % font.get_size() +
+ 'style:font-size-asian="%.2fpt" ' % font.get_size() +
+ 'fo:color="#%02x%02x%02x" ' % font.get_color()
+ )
+
if font.get_bold():
- self.cntnt.write('fo:font-weight="bold" ')
+ wrt('fo:font-weight="bold" ')
if font.get_italic():
- self.cntnt.write('fo:font-style="italic" ')
+ wrt('fo:font-style="italic" ')
if font.get_underline():
- self.cntnt.write('style:text-underline="single" ')
- self.cntnt.write('style:text-underline-color="font-color" ')
- self.cntnt.write('fo:text-indent="%.2fcm"\n' %
- style.get_first_indent())
- self.cntnt.write('fo:margin-right="%.2fcm"\n' %
- style.get_right_margin())
- self.cntnt.write('fo:margin-left="%.2fcm"\n' %
- style.get_left_margin())
- self.cntnt.write('fo:margin-top="%.2fcm"\n' %
- style.get_top_margin())
- self.cntnt.write('fo:margin-bottom="%.2fcm"\n' %
- style.get_bottom_margin())
- self.cntnt.write('/>\n')
- self.cntnt.write('\n')
+ wrt(
+ 'style:text-underline="single" '
+ 'style:text-underline-color="font-color" '
+ )
+
+ wrt(
+ 'fo:text-indent="%.2fcm"\n' % style.get_first_indent() +
+ 'fo:margin-right="%.2fcm"\n' % style.get_right_margin() +
+ 'fo:margin-left="%.2fcm"\n' % style.get_left_margin() +
+ 'fo:margin-top="%.2fcm"\n' % style.get_top_margin() +
+ 'fo:margin-bottom="%.2fcm"\n' % style.get_bottom_margin() +
+ '/>\n' +
+ '\n'
+ )
+
+ wrt(
+ '\n' +
+ '\n')
- self.cntnt.write(' ' %
- font.get_size())
- self.cntnt.write('\n')
+ wrt('fo:font-style="italic" ')
+
+ wrt(
+ 'fo:font-size="%.2fpt" ' % font.get_size() +
+ 'style:font-size-asian="%.2fpt"/> ' % font.get_size() +
+ '\n'
+ )
for style_name in styles.get_table_style_names():
style = styles.get_table_style(style_name)
- self.cntnt.write('\n')
table_width = float(self.get_usable_width())
table_width_str = "%.2f" % table_width
- self.cntnt.write('\n')
- self.cntnt.write('\n')
+ wrt(
+ '\n'
+ '\n' +
+ '\n'
+ )
+
for col in range(0, style.get_columns()):
- self.cntnt.write('')
- width = table_width * float(style.get_column_width(col)/100.0)
+ width = table_width * float(style.get_column_width(col) / 100.0)
width_str = "%.4f" % width
- self.cntnt.write('' % width_str)
- self.cntnt.write('\n')
+ wrt(
+ '' +
+ '' % width_str +
+ '\n'
+ )
for cell in styles.get_cell_style_names():
cell_style = styles.get_cell_style(cell)
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
+ wrt(
+ '\n' +
+ '\n'
+ '\n'
+ )
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('')
- self.cntnt.write('\n')
+ wrt(
+ _OTHER_STYLES
+ )
- #Begin photo style
- self.cntnt.write('')
- self.cntnt.write('')
- self.cntnt.write('\n')
+ wrt(
+ '\n'
+ '\n'
+ ' \n'
+ ' \n'
+ )
- self.cntnt.write('')
- self.cntnt.write('')
- self.cntnt.write('\n')
-
- self.cntnt.write(' ')
- self.cntnt.write(' ')
- self.cntnt.write('\n')
-
- self.cntnt.write('')
- self.cntnt.write('')
- self.cntnt.write('\n')
-
- #end of Photo style edits
-
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write(' \n')
- self.cntnt.write(' \n')
-
- def uniq(self, List, funct=None):
+ def uniq(self, list_, funct=None):
"""
We want no duplicate in the list
"""
# order preserving
- if funct is None:
- def funct(x):
- """
- function used to compare elements
- """
- return x
- seen = {}
+ funct = funct or (lambda x:x)
+ seen = set()
result = []
- for item in List:
+ for item in list_:
marker = funct(item[0])
if marker in seen:
continue
- seen[marker] = 1
+ seen.add(marker)
result.append(item)
return result
@@ -598,9 +798,11 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
"""
Close the document and create the odt file
"""
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
+ self.cntnt.write(
+ '\n'
+ '\n'
+ '\n'
+ )
self.finish_cntnt_creation()
self._write_styles_file()
self._write_manifest()
@@ -615,53 +817,65 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
Add the new fonts for Styled notes in the font-face-decls section.
"""
# Need to add new font for styled notes here.
+ wrt1 = self.cntnt1.write
for style in self.StyleList:
- if ( style[1] == "FontFace" ):
- self.cntnt1.write('\n')
+ if style[1] == "FontFace":
+ wrt1(
+ '\n'
+ )
def add_styled_notes_styles(self):
"""
Add the new styles for Styled notes in the automatic-styles section.
"""
# Need to add new style for styled notes here.
+ wrt2 = self.cntnt2.write
for style in self.StyleList:
- if ( style[1] == "FontSize" ):
- self.cntnt2.write(' ')
- self.cntnt2.write('' %
- style[2])
- self.cntnt2.write('\n')
- elif ( style[1] == "FontColor" ):
- self.cntnt2.write('')
- self.cntnt2.write(' ' %
- style[2])
- self.cntnt2.write('\n')
- elif ( style[1] == "FontHighlight" ):
- self.cntnt2.write(' ')
- self.cntnt2.write('' % style[2])
- self.cntnt2.write('\n')
- elif ( style[1] == "FontFace" ):
- self.cntnt2.write(' ')
- self.cntnt2.write('')
- self.cntnt2.write('\n')
+ if style[1] == "FontSize":
+ wrt2(
+ ' ' +
+ '' % style[2] +
+ '\n'
+ )
+
+ elif style[1] == "FontColor":
+ wrt2(
+ '' +
+ ' ' % style[2] +
+ '\n'
+ )
+
+ elif style[1] == "FontHighlight":
+ wrt2(
+ ' ' +
+ '' % style[2] +
+ '\n'
+ )
+
+ elif style[1] == "FontFace":
+ wrt2(
+ ' ' +
+ '' +
+ '\n'
+ )
def add_media_object(self, file_name, pos, x_cm, y_cm, alt=''):
"""
@@ -674,13 +888,13 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
if (x, y) == (0, 0):
return
- ratio = float(x_cm)*float(y)/(float(y_cm)*float(x))
+ ratio = float(x_cm) * float(y) / (float(y_cm) * float(x))
if ratio < 1:
act_width = x_cm
- act_height = y_cm*ratio
+ act_height = y_cm * ratio
else:
act_height = y_cm
- act_width = x_cm/ratio
+ act_width = x_cm / ratio
not_extension, extension = os.path.splitext(file_name)
odf_name = md5(file_name).hexdigest() + extension
@@ -694,25 +908,21 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
if self.new_cell:
self.cntnt.write('')
- if pos == "left":
- self.cntnt.write('')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
+ pos = pos.title() if pos in ['left', 'right', 'single'] else 'Row'
+ self.cntnt.write(
+ '' +
+ '\n' +
+ '\n'
+ )
+
if self.new_cell:
self.cntnt.write('\n')
@@ -720,13 +930,19 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
"""
open a table
"""
- self.cntnt.write('\n' % style_name)
+ self.cntnt.write(
+ '\n' % style_name
+ )
+
styles = self.get_style_sheet()
table = styles.get_table_style(style_name)
- for col in range(0, table.get_columns()):
- self.cntnt.write('\n')
+
+ for col in range(table.get_columns()):
+ self.cntnt.write(
+ '\n'
+ % (style_name, str(chr(ord('A')+col)))
+ )
def end_table(self):
"""
@@ -751,9 +967,10 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
open a cell
"""
self.span = span
- self.cntnt.write(' 1:
self.cntnt.write(' table:number-columns-spanned="%s">\n' % span)
else:
@@ -845,302 +1062,242 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
create the styles.xml file
"""
self.sfile = StringIO()
+ wrtf = self.sfile.write
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('')
- self.sfile.write('')
- self.sfile.write(' ')
- self.sfile.write(' ')
- self.sfile.write('')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write(' \n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write(' ')
- self.sfile.write(' ')
- self.sfile.write('\n')
- self.sfile.write(' ')
- self.sfile.write(' ')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
+ wrtf('\n')
+ wrtf('\n'
+ )
+
+ wrtf('\n' +
+ _FONTS +
+ '\n'
+ )
+
+ wrtf('\n' +
+ _STYLES
+ )
styles = self.get_style_sheet()
for style_name in styles.get_paragraph_style_names():
style = styles.get_paragraph_style(style_name)
- self.sfile.write('\n')
- self.sfile.write('\n' +
+ ' 0:
- self.sfile.write('fo:keep-with-next="auto" ')
+ wrtf('fo:keep-with-next="auto" ')
align = style.get_alignment()
if align == PARA_ALIGN_LEFT:
- self.sfile.write('fo:text-align="start" ')
- self.sfile.write('style:justify-single-word="false" ')
+ wrtf(
+ 'fo:text-align="start" '
+ 'style:justify-single-word="false" '
+ )
+
elif align == PARA_ALIGN_RIGHT:
- self.sfile.write('fo:text-align="end" ')
+ wrtf('fo:text-align="end" ')
elif align == PARA_ALIGN_CENTER:
- self.sfile.write('fo:text-align="center" ')
- self.sfile.write('style:justify-single-word="false" ')
+ wrtf(
+ 'fo:text-align="center" '
+ 'style:justify-single-word="false" '
+ )
else:
- self.sfile.write('fo:text-align="justify" ')
- self.sfile.write('style:justify-single-word="false" ')
- self.sfile.write('fo:text-indent="%.2fcm" ' %
- style.get_first_indent())
- self.sfile.write('style:auto-text-indent="false"/> ')
- self.sfile.write(' ' +
+ '\n')
- self.sfile.write('\n')
+ wrtf(
+ 'style:text-underline="single" ' +
+ 'style:text-underline-color="font-color" ' +
+ 'fo:text-indent="%.2fcm" ' % style.get_first_indent() +
+ 'fo:margin-right="%.2fcm" ' % style.get_right_margin() +
+ 'fo:margin-left="%.2fcm" ' % style.get_left_margin() +
+ 'fo:margin-top="%.2fcm" ' % style.get_top_margin() +
+ 'fo:margin-bottom="%.2fcm"\n' % style.get_bottom_margin()
+ )
+ wrtf(
+ '/>\n'
+ '\n'
+ )
# Current no leading number format for headers
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
- #self.sfile.write('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
+ #wrtf('\n')
- self.sfile.write(' ')
- self.sfile.write(' ')
- self.sfile.write(' ')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('')
- self.sfile.write('')
- self.sfile.write('\n')
- self.sfile.write('')
- self.sfile.write('')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
+ wrtf(
+ ' '
+ )
+
+ wrtf(
+ ' '
+ )
+
+ wrtf(
+ ' '
+ )
+
+ wrtf('\n')
+ wrtf(
+ '\n' +
+ _SHEADER_FOOTER +
+ '\n' +
+ '\n' +
+ '\n' +
+ '\n'
+ )
+
# header
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
+ wrtf(
+ '\n'
+ '\n'
+ '\n'
+ )
+
# footer
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- #
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- self.sfile.write('\n')
- # header
- #self.sfile.write('')
- #self.sfile.write('')
- # How to get the document title here ?
- #self.sfile.write(' TITRE : %s' % self.title)
- #self.sfile.write('')
- #self.sfile.write('')
- # footer
- #self.sfile.write('')
- #self.sfile.write('')
- #self.sfile.write('1')
- #self.sfile.write('/')
- #self.sfile.write('1')
- #self.sfile.write('')
- #self.sfile.write('')
- #self.sfile.write('')
- #
- self.sfile.write('')
- self.sfile.write('\n')
- self.sfile.write('\n')
+ wrtf(
+ '\n'
+ '\n'
+ '\n'
+ )
+
+ # End of page layout
+ wrtf(
+ '\n'
+ '\n'
+ )
+
+ # Master Styles
+ wrtf(
+ '\n'
+ '\n'
+ # header
+ #''
+ #''
+ # How to get the document title here ?
+ #' TITRE : %s' % self.title
+ #''
+ #''
+ # footer
+ #''
+ #''
+ #'1'
+ #'/'
+ #'1'
+ #''
+ #''
+ #''
+ #
+ ''
+ '\n'
+ )
+ # End of document styles
+ wrtf('\n')
def page_break(self):
"""
@@ -1175,22 +1332,21 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
if self.level == 0:
self.cntnt.write('' % name)
else:
- self.cntnt.write('')
+ self.cntnt.write(
+ '' % str(self.level)
+ )
if leader is not None:
- self.cntnt.write(leader)
- self.cntnt.write('')
+ self.cntnt.write(leader + '')
self.new_cell = 0
def end_paragraph(self):
"""
close a paragraph
"""
- if self.level == 0:
- self.cntnt.write('\n')
- else:
- self.cntnt.write('\n')
+ self.cntnt.write(
+ '\n' % ('p' if self.level == 0 else 'h')
+ )
self.new_cell = 1
def write_endnotes_ref(self, text, style_name):
@@ -1204,9 +1360,11 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
text = text.replace(' '*n, ' ' % (n-1) )
self.start_paragraph(style_name)
# self.cntnt.write('')
- self.cntnt.write('')
- self.cntnt.write(text)
- self.cntnt.write('')
+ self.cntnt.write(
+ '' +
+ text +
+ ''
+ )
self.end_paragraph()
def write_styled_note(self, styledtext, format, style_name,
@@ -1227,31 +1385,33 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
text = text.replace('<', '\2')
text = text.replace('>', '\3')
markuptext = self._backend.add_markup_from_styled(text, s_tags)
+
# we need to know if we have new styles to add.
# if markuptext contains : FontColor, FontFace, FontSize ...
# we must prepare the new styles for the styles.xml file.
# We are looking for the following format :
# style-name="([a-zA-Z0-9]*)__([a-zA-Z0-9 ])">
# The first element is the StyleType and the second one is the value
+
start = 0
- while 1:
+ while True:
m = NewStyle.search(markuptext, start)
if not m:
break
- self.StyleList.append([m.group(1)+m.group(2),
- m.group(1),
- m.group(2)])
+ self.StyleList.append(
+ [m.group(1) + m.group(2), m.group(1), m.group(2)]
+ )
start = m.end()
- linenb = 1
+
self.start_paragraph(style_name)
markuptext = markuptext.replace('\1', '&') # must be the first
markuptext = markuptext.replace('\2', '<')
markuptext = markuptext.replace('\3', '>')
- for line in markuptext.split('\n'):
- if ( linenb > 1 ):
+
+ for l, line in enumerate(markuptext.split('\n')):
+ if l:
self.cntnt.write('')
self.cntnt.write(line)
- linenb += 1
self.end_paragraph()
def write_text(self, text, mark=None):
@@ -1264,12 +1424,17 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
key = escape(mark.key, _esc_map)
key = key.replace('"', '"')
if mark.type == INDEX_TYPE_ALP:
- self.cntnt.write('' % key)
+ self.cntnt.write(
+ '' % key
+ )
+
elif mark.type == INDEX_TYPE_TOC:
- self.cntnt.write('' % mark.level)
+ self.cntnt.write(
+ '' % mark.level
+ )
self.cntnt.write(escape(text, _esc_map))
def _write_manifest(self):
@@ -1278,27 +1443,38 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
"""
self.mfile = StringIO()
- self.mfile.write('\n')
- self.mfile.write('')
- self.mfile.write('')
+ # Header
+ self.mfile.write(
+ '\n' +
+ '' +
+ ''
+ )
+
+ # Images
for image in self.media_list:
- self.mfile.write('')
- self.mfile.write('')
- self.mfile.write('')
- self.mfile.write('')
- self.mfile.write('')
- self.mfile.write('\n')
+ self.mfile.write(
+ ''
+ )
+
+ # Footer
+ self.mfile.write(
+ ''
+ ''
+ ''
+ ''
+ '\n'
+ )
def _write_mimetype_file(self):
"""
@@ -1312,57 +1488,14 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
create the meta.xml file
"""
self.meta = StringIO()
+ generator = const.PROGRAM_NAME + ' ' + const.VERSION
+ creator = self.get_creator()
+ date = self.time
+ lang = self.lang
- self.meta.write('\n')
- self.meta.write('\n')
- self.meta.write('\n')
- self.meta.write('')
- self.meta.write(const.PROGRAM_NAME + ' ' + const.VERSION)
- self.meta.write('\n')
- self.meta.write('')
- # It should be reasonable to have a true document title. but how ?
- # self.title ?
- #self.meta.write(_("Summary of %s") % self.name)
- self.meta.write('\n')
- self.meta.write('')
- #self.meta.write(_("Summary of %s") % name)
- self.meta.write('\n')
- self.meta.write('')
- self.meta.write('\n')
- self.meta.write('')
- self.meta.write(self.get_creator())
- self.meta.write('\n')
- self.meta.write('')
- self.meta.write(self.time)
- self.meta.write('\n')
- self.meta.write('')
- self.meta.write(self.get_creator())
- self.meta.write('\n')
- self.meta.write('')
- self.meta.write(self.time)
- self.meta.write('\n')
- #self.meta.write('')
- #self.meta.write('\n')
- self.meta.write('0-00-00T00:00:00\n')
- self.meta.write('%s\n' % self.lang)
- self.meta.write('1\n')
- self.meta.write('PT0S\n')
- self.meta.write('')
- self.meta.write('http://gramps-project.org')
- self.meta.write('\n')
- self.meta.write('\n')
- self.meta.write('\n')
- self.meta.write('\n')
- self.meta.write('\n')
- self.meta.write('\n')
+ self.meta.write(
+ _META_XML % locals()
+ )
def rotate_text(self, style, text, x, y, angle):
"""
@@ -1375,31 +1508,32 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
font = p.get_font()
size = font.get_size()
- height = size*(len(text))
+ height = size * (len(text))
width = 0
for line in text:
width = max(width, string_width(font, line))
wcm = ReportUtils.pt2cm(width)
hcm = ReportUtils.pt2cm(height)
- rangle = (pi/180.0) * angle
+ rangle = radians(angle)
+ xloc = x - (wcm / 2.0) * cos(rangle) + (hcm / 2.0) * sin(rangle)
+ yloc = y - (hcm / 2.0) * cos(rangle) - (wcm / 2.0) * sin(rangle)
- self.cntnt.write('\n' % (xloc, yloc))
- self.cntnt.write('\n')
- self.cntnt.write('' % pname)
- self.cntnt.write('' % pname)
- self.cntnt.write(escape('\n'.join(text), _esc_map))
- self.cntnt.write('\n\n')
- self.cntnt.write('\n')
+ self.cntnt.write(
+ '\n' % (xloc, yloc) +
+ '\n' +
+ '' % pname +
+ '' % pname +
+ escape('\n'.join(text), _esc_map) +
+ '\n\n' +
+ '\n')
def draw_path(self, style, path):
"""
@@ -1416,26 +1550,26 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
maxx = max(point[0], maxx)
maxy = max(point[1], maxy)
- self.cntnt.write('\n')
@@ -1443,15 +1577,17 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
"""
Draw a line
"""
- self.cntnt.write('' % y2)
- self.cntnt.write('\n')
- self.cntnt.write('\n')
+ self.cntnt.write(
+ '' % y2 +
+ '\n' +
+ '\n'
+ )
def draw_text(self, style, text, x, y):
"""
@@ -1464,24 +1600,25 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
font = pstyle.get_font()
sw = ReportUtils.pt2cm(string_width(font, text))*1.3
- self.cntnt.write('' % float(y))
- self.cntnt.write(' ' )
- self.cntnt.write('' % para_name)
- self.cntnt.write('' % para_name)
- #self.cntnt.write(' fo:max-height="%.2f">' % font.get_size() )
- self.cntnt.write(escape(text, _esc_map))
- self.cntnt.write('')
- self.cntnt.write('')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
+ self.cntnt.write(
+ '' % float(y) +
+ ' ' +
+ '' % para_name +
+ '' % para_name +
+ #' fo:max-height="%.2f">' % font.get_size() +
+ escape(text, _esc_map) +
+ '' +
+ '' +
+ '\n' +
+ '\n'
+ )
def draw_box(self, style, text, x, y, w, h):
"""
@@ -1493,30 +1630,36 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
shadow_width = box_style.get_shadow_space()
if box_style.get_shadow():
- self.cntnt.write('\n' % (float(y)+shadow_width))
- self.cntnt.write('\n')
+ self.cntnt.write(
+ '\n' % (float(y) + shadow_width) +
+ '\n'
+ )
- self.cntnt.write('\n' % float(y))
- if text != "":
- self.cntnt.write('' % para_name)
- self.cntnt.write('' % para_name)
- self.cntnt.write(escape(text, _esc_map))
- self.cntnt.write('')
- self.cntnt.write('\n')
+ self.cntnt.write(
+ '\n' % float(y)
+ )
+ if text:
+ self.cntnt.write(
+ '' % para_name +
+ '' % para_name +
+ escape(text, _esc_map) +
+ ''
+ '\n'
+ )
self.cntnt.write('\n')
def center_text(self, style, text, x, y):
@@ -1529,23 +1672,26 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
pstyle = style_sheet.get_paragraph_style(para_name)
font = pstyle.get_font()
- size = (string_width(font, text)/72.0) * 2.54
+ size = (string_width(font, text) / 72.0) * 2.54
- self.cntnt.write('\n' % float(y)
+ )
- self.cntnt.write('svg:x="%.2fcm" ' % (x-(size/2.0)))
- self.cntnt.write('svg:y="%.2fcm">\n' % float(y))
-
- if text != "":
- self.cntnt.write('')
- self.cntnt.write('' % para_name)
- self.cntnt.write('' % para_name)
- self.cntnt.write(escape(text, _esc_map))
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('')
+ if text:
+ self.cntnt.write(
+ '' +
+ '' % para_name +
+ '' % para_name +
+ escape(text, _esc_map) +
+ '\n' +
+ '\n' +
+ ''
+ )
self.cntnt.write('\n')
diff --git a/src/plugins/docgen/PSDrawDoc.py b/src/plugins/docgen/PSDrawDoc.py
index 65c4acccb..030d43b8a 100644
--- a/src/plugins/docgen/PSDrawDoc.py
+++ b/src/plugins/docgen/PSDrawDoc.py
@@ -66,32 +66,30 @@ class PSDrawDoc(BaseDoc, DrawDoc):
def fontdef(self, para):
font = para.get_font()
if font.get_type_face() == FONT_SERIF:
+ font_name = "/Times"
if font.get_bold():
+ font_name += "-Bold"
if font.get_italic():
- font_name = "/Times-BoldItalic"
- else:
- font_name = "/Times-Bold"
+ font_name += "Italic"
+ elif font.get_italic():
+ font_name += "-Italic"
else:
- if font.get_italic():
- font_name = "/Times-Italic"
- else:
- font_name = "/Times-Roman"
- else:
+ font_name += "-Roman"
+
+ else: # Use a font without serifs
+ font_name = "/Helvetica"
if font.get_bold():
+ font_name += "-Bold"
if font.get_italic():
- font_name = "/Helvetica-BoldOblique"
- else:
- font_name = "/Helvetica-Bold"
- else:
- if font.get_italic():
- font_name = "/Helvetica-Oblique"
- else:
- font_name = "/Helvetica"
+ font_name += "Oblique"
+ elif font.get_italic():
+ font_name += "-Oblique"
- return "%s find-latin-font %d scalefont setfont\n" % (font_name, font.get_size())
+ return "%s find-latin-font %d scalefont setfont\n" % \
+ (font_name, font.get_size())
def translate(self, x, y):
- return (x, self.paper.get_size().get_height()-y)
+ return (x, self.paper.get_size().get_height() - y)
def open(self, filename):
"""
@@ -99,10 +97,9 @@ class PSDrawDoc(BaseDoc, DrawDoc):
@param filename: path name of the file to create
"""
- if filename[-3:] != ".ps":
- self.filename = filename + ".ps"
- else:
- self.filename = filename
+ self.filename = filename
+ if not filename.endswith(".ps"):
+ self.filename += ".ps"
try:
self.file = open(self.filename,"w")
@@ -112,36 +109,43 @@ class PSDrawDoc(BaseDoc, DrawDoc):
except:
raise Errors.ReportError(_("Could not create %s") % self.filename)
- self.file.write('%!PS-Adobe-3.0\n')
- self.file.write('%%LanguageLevel: 2\n')
- self.file.write('%%Pages: (atend)\n')
- self.file.write('%%PageOrder: Ascend\n')
+ self.file.write(
+ '%!PS-Adobe-3.0\n'
+ '%%LanguageLevel: 2\n'
+ '%%Pages: (atend)\n'
+ '%%PageOrder: Ascend\n'
+ '%%Orientation: '
+ )
if self.paper.get_orientation() != PAPER_PORTRAIT:
- self.file.write('%%Orientation: Landscape\n')
+ self.file.write('Landscape\n')
else:
- self.file.write('%%Orientation: Portrait\n')
- self.file.write('%%EndComments\n')
- self.file.write('/cm { 28.34 mul } def\n')
- self.file.write('% build iso-latin-1 version of a font\n')
- self.file.write('/font-to-iso-latin-1 { % font-to-iso-latin-1 \n')
- self.file.write('%% reencode for iso latin1; from the 2nd edition red book, sec 5.6.1\n')
- self.file.write('dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall\n')
- self.file.write('/Encoding ISOLatin1Encoding def currentdict end\n')
- self.file.write('dup /FontName get 80 string cvs (-ISOLatin1) concatstrings cvn \n')
- self.file.write('exch definefont\n')
- self.file.write('} def\n')
- self.file.write('\n')
- self.file.write('/find-latin-font { % find-latin-font \n')
- self.file.write('findfont font-to-iso-latin-1\n')
- self.file.write('} def\n')
+ self.file.write('Portrait\n')
+ self.file.write(
+ '%%EndComments\n'
+ '/cm { 28.34 mul } def\n'
+ '% build iso-latin-1 version of a font\n'
+ '/font-to-iso-latin-1 { % font-to-iso-latin-1 \n'
+ '%% reencode for iso latin1; from the 2nd edition red book, sec 5.6.1\n'
+ 'dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall\n'
+ '/Encoding ISOLatin1Encoding def currentdict end\n'
+ 'dup /FontName get 80 string cvs (-ISOLatin1) concatstrings cvn \n'
+ 'exch definefont\n'
+ '} def\n'
+ '\n'
+ '/find-latin-font { % find-latin-font \n'
+ 'findfont font-to-iso-latin-1\n'
+ '} def\n'
+ )
self.filename = filename
def close(self):
- self.file.write('%%Trailer\n')
- self.file.write('%%Pages: ')
- self.file.write('%d\n' % self.page)
- self.file.write('%%EOF\n')
+ self.file.write(
+ '%%Trailer\n'
+ '%%Pages: ' +
+ '%d\n' % self.page +
+ '%%EOF\n'
+ )
self.file.close()
if self.open_req:
open_file_with_default_application(self.filename)
@@ -150,23 +154,27 @@ class PSDrawDoc(BaseDoc, DrawDoc):
pass
def start_page(self):
- self.page = self.page + 1
- self.file.write("%%Page:")
- self.file.write("%d %d\n" % (self.page, self.page))
+ self.page += 1
+ self.file.write(
+ "%%Page:" +
+ "%d %d\n" % (self.page, self.page)
+ )
if self.paper.get_orientation() != PAPER_PORTRAIT:
self.file.write('90 rotate %s cm %s cm translate\n' % (
gformat(0),gformat(-1*self.paper.get_size().get_height())))
def end_page(self):
- self.file.write('showpage\n')
- self.file.write('%%PageTrailer\n')
+ self.file.write(
+ 'showpage\n'
+ '%%PageTrailer\n'
+ )
def encode(self, text):
try:
orig = unicode(text)
new_text = orig.encode('iso-8859-1')
except:
- new_text = "?"*len(text)
+ new_text = "?" * len(text)
return new_text
def encode_text(self, p, text):
@@ -181,17 +189,19 @@ class PSDrawDoc(BaseDoc, DrawDoc):
p = style_sheet.get_paragraph_style(pname)
x += self.paper.get_left_margin()
- y = y + self.paper.get_top_margin() + ReportUtils.pt2cm(p.get_font().get_size())
+ y += self.paper.get_top_margin() + ReportUtils.pt2cm(p.get_font().get_size())
(text, fdef) = self.encode_text(p, text)
- self.file.write('gsave\n')
- self.file.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
- self.file.write(fdef)
- self.file.write('(%s) dup stringwidth pop -2 div ' % text)
- self.file.write('%s cm add %s cm moveto ' % coords(self.translate(x, y)))
- self.file.write('show\n')
- self.file.write('grestore\n')
+ self.file.write(
+ 'gsave\n'
+ '%s %s %s setrgbcolor\n' % lrgb(stype.get_color()) +
+ fdef +
+ '(%s) dup stringwidth pop -2 div ' % text +
+ '%s cm add %s cm moveto ' % coords(self.translate(x, y)) +
+ 'show\n'
+ 'grestore\n'
+ )
def draw_text(self, style, text, x1, y1):
style_sheet = self.get_style_sheet()
@@ -199,15 +209,17 @@ class PSDrawDoc(BaseDoc, DrawDoc):
pname = stype.get_paragraph_style()
p = style_sheet.get_paragraph_style(pname)
- x1 = x1 + self.paper.get_left_margin()
- y1 = y1 + self.paper.get_top_margin() + ReportUtils.pt2cm(p.get_font().get_size())
+ x1 += self.paper.get_left_margin()
+ y1 += self.paper.get_top_margin() + ReportUtils.pt2cm(p.get_font().get_size())
(text, fdef) = self.encode_text(p, text)
- self.file.write('gsave\n')
- self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x1, y1)))
- self.file.write(fdef)
- self.file.write('(%s) show grestore\n' % text)
+ self.file.write(
+ 'gsave\n'
+ '%s cm %s cm moveto\n' % coords(self.translate(x1, y1)) +
+ fdef +
+ '(%s) show grestore\n' % text
+ )
def rotate_text(self, style, text, x, y, angle):
@@ -224,22 +236,24 @@ class PSDrawDoc(BaseDoc, DrawDoc):
(new_text, fdef) = self.encode_text(p, text[0])
- self.file.write('gsave\n')
- self.file.write(fdef)
coords = self.translate(x, y)
- self.file.write('%s cm %s cm translate\n' % (
- gformat(coords[0]),gformat(coords[1])))
- self.file.write('%s rotate\n' % gformat(-angle))
+ self.file.write(
+ 'gsave\n' +
+ fdef +
+ '%s cm %s cm translate\n' % (
+ gformat(coords[0]), gformat(coords[1])) +
+ '%s rotate\n' % gformat(-angle) +
+ '%s %s %s setrgbcolor\n' % lrgb(stype.get_color())
+ )
- self.file.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
-
- val = len(text)
- y = ((size * val)/2.0) - size
+ y = ((size * len(text)) / 2.0) - size
for line in text:
- self.file.write('(%s) dup stringwidth pop -2 div '
- % self.encode(line))
- self.file.write("%s moveto show\n" % gformat(y))
+ self.file.write(
+ '(%s) dup stringwidth pop -2 div '
+ % self.encode(line) +
+ "%s moveto show\n" % gformat(y)
+ )
y -= size
self.file.write('grestore\n')
@@ -247,53 +261,65 @@ class PSDrawDoc(BaseDoc, DrawDoc):
def draw_path(self, style, path):
style_sheet = self.get_style_sheet()
stype = style_sheet.get_draw_style(style)
- self.file.write('gsave\n')
- self.file.write('newpath\n')
- self.file.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
+ self.file.write(
+ 'gsave\n'
+ 'newpath\n'
+ '%s setlinewidth\n' % gformat(stype.get_line_width())
+ )
if stype.get_line_style() == SOLID:
self.file.write('[] 0 setdash\n')
else:
self.file.write('[2 4] 0 setdash\n')
point = path[0]
- x1 = point[0]+self.paper.get_left_margin()
- y1 = point[1]+self.paper.get_top_margin()
- self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x1, y1)))
+ x1 = point[0] + self.paper.get_left_margin()
+ y1 = point[1] + self.paper.get_top_margin()
+ self.file.write(
+ '%s cm %s cm moveto\n' % coords(self.translate(x1, y1))
+ )
for point in path[1:]:
- x1 = point[0]+self.paper.get_left_margin()
- y1 = point[1]+self.paper.get_top_margin()
- self.file.write('%s cm %s cm lineto\n' % coords(self.translate(x1, y1)))
+ x1 = point[0] + self.paper.get_left_margin()
+ y1 = point[1] + self.paper.get_top_margin()
+ self.file.write(
+ '%s cm %s cm lineto\n' % coords(self.translate(x1, y1))
+ )
self.file.write('closepath\n')
color = stype.get_fill_color()
- self.file.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(color))
- self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
- self.file.write('grestore\n')
+ self.file.write(
+ 'gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(color) +
+ '%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()) +
+ 'grestore\n'
+ )
def draw_line(self, style, x1, y1, x2, y2):
- x1 = x1 + self.paper.get_left_margin()
- x2 = x2 + self.paper.get_left_margin()
- y1 = y1 + self.paper.get_top_margin()
- y2 = y2 + self.paper.get_top_margin()
+ x1 += self.paper.get_left_margin()
+ x2 += self.paper.get_left_margin()
+ y1 += self.paper.get_top_margin()
+ y2 += self.paper.get_top_margin()
style_sheet = self.get_style_sheet()
stype = style_sheet.get_draw_style(style)
- self.file.write('gsave newpath\n')
- self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x1, y1)))
- self.file.write('%s cm %s cm lineto\n' % coords(self.translate(x2, y2)))
- self.file.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
+ self.file.write(
+ 'gsave newpath\n'
+ '%s cm %s cm moveto\n' % coords(self.translate(x1, y1)) +
+ '%s cm %s cm lineto\n' % coords(self.translate(x2, y2)) +
+ '%s setlinewidth\n' % gformat(stype.get_line_width())
+ )
if stype.get_line_style() == SOLID:
self.file.write('[] 0 setdash\n')
else:
self.file.write('[2 4] 0 setdash\n')
- self.file.write('2 setlinecap\n')
- self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
- self.file.write('grestore\n')
+ self.file.write(
+ '2 setlinecap\n' +
+ '%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()) +
+ 'grestore\n'
+ )
def draw_box(self, style, text, x, y, w, h):
- x = x + self.paper.get_left_margin()
- y = y + self.paper.get_top_margin()
+ x += self.paper.get_left_margin()
+ y += self.paper.get_top_margin()
style_sheet = self.get_style_sheet()
box_style = style_sheet.get_draw_style(style)
@@ -302,36 +328,45 @@ class PSDrawDoc(BaseDoc, DrawDoc):
shadsize = box_style.get_shadow_space()
if box_style.get_shadow():
- self.file.write('newpath\n')
- self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x+shadsize, y+shadsize)))
- self.file.write('0 -%s cm rlineto\n' % gformat(h))
- self.file.write('%s cm 0 rlineto\n' % gformat(w))
- self.file.write('0 %s cm rlineto\n' % gformat(h))
- self.file.write('closepath\n')
- self.file.write('.5 setgray\n')
- self.file.write('fill\n')
- self.file.write('newpath\n')
- self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x, y)))
- self.file.write('0 -%s cm rlineto\n' % gformat(h))
- self.file.write('%s cm 0 rlineto\n' % gformat(w))
- self.file.write('0 %s cm rlineto\n' % gformat(h))
- self.file.write('closepath\n')
+ self.file.write(
+ 'newpath\n'
+ '%s cm %s cm moveto\n'
+ % coords(self.translate(x+shadsize, y+shadsize)) +
+ '0 -%s cm rlineto\n' % gformat(h) +
+ '%s cm 0 rlineto\n' % gformat(w) +
+ '0 %s cm rlineto\n' % gformat(h) +
+ 'closepath\n'
+ '.5 setgray\n'
+ 'fill\n'
+ )
+ self.file.write(
+ 'newpath\n'
+ '%s cm %s cm moveto\n' % coords(self.translate(x, y)) +
+ '0 -%s cm rlineto\n' % gformat(h) +
+ '%s cm 0 rlineto\n' % gformat(w) +
+ '0 %s cm rlineto\n' % gformat(h) +
+ 'closepath\n'
+ )
fill_color = box_style.get_fill_color()
color = box_style.get_color()
- self.file.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(fill_color))
- self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(color))
+ self.file.write(
+ 'gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(fill_color) +
+ '%s %s %s setrgbcolor stroke\n' % lrgb(color)
+ )
self.file.write('newpath\n')
if box_style.get_line_width():
- self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x, y)))
- self.file.write('0 -%s cm rlineto\n' % gformat(h))
- self.file.write('%s cm 0 rlineto\n' % gformat(w))
- self.file.write('0 %s cm rlineto\n' % gformat(h))
- self.file.write('closepath\n')
- self.file.write('%s setlinewidth\n' % gformat(box_style.get_line_width()))
- self.file.write('%s %s %s setrgbcolor stroke\n' % lrgb(box_style.get_color()))
- if text != "":
+ self.file.write(
+ '%s cm %s cm moveto\n' % coords(self.translate(x, y)) +
+ '0 -%s cm rlineto\n' % gformat(h) +
+ '%s cm 0 rlineto\n' % gformat(w) +
+ '0 %s cm rlineto\n' % gformat(h) +
+ 'closepath\n' +
+ '%s setlinewidth\n' % gformat(box_style.get_line_width()) +
+ '%s %s %s setrgbcolor stroke\n' % lrgb(box_style.get_color())
+ )
+ if text:
para_name = box_style.get_paragraph_style()
assert( para_name != '' )
p = style_sheet.get_paragraph_style(para_name)
@@ -339,14 +374,16 @@ class PSDrawDoc(BaseDoc, DrawDoc):
self.file.write(fdef)
lines = text.split('\n')
- nlines = len(lines)
mar = 10/28.35
f_in_cm = p.get_font().get_size()/28.35
fs = f_in_cm * 1.2
center = y + (h + fs)/2.0 + (fs*shadsize)
- ystart = center - (fs/2.0) * nlines
- for i in range(nlines):
+ ystart = center - (fs/2.0) * len(lines)
+ for i, line in enumerate(lines):
ypos = ystart + (i * fs)
- self.file.write('%s cm %s cm moveto\n' % coords(self.translate(x+mar, ypos)))
- self.file.write("(%s) show\n" % lines[i])
+ self.file.write(
+ '%s cm %s cm moveto\n'
+ % coords(self.translate(x+mar, ypos)) +
+ "(%s) show\n" % lines[i]
+ )
self.file.write('grestore\n')
diff --git a/src/plugins/docgen/RTFDoc.py b/src/plugins/docgen/RTFDoc.py
index da9fca489..58a1636c6 100644
--- a/src/plugins/docgen/RTFDoc.py
+++ b/src/plugins/docgen/RTFDoc.py
@@ -87,11 +87,14 @@ class RTFDoc(BaseDoc,TextDoc):
style_sheet = self.get_style_sheet()
- self.f.write('{\\rtf1\\ansi\\ansicpg1252\\deff0\n')
- self.f.write('{\\fonttbl\n')
- self.f.write('{\\f0\\froman\\fcharset0\\fprq0 Times New Roman;}\n')
- self.f.write('{\\f1\\fswiss\\fcharset0\\fprq0 Arial;}}\n')
- self.f.write('{\colortbl\n')
+ self.f.write(
+ '{\\rtf1\\ansi\\ansicpg1252\\deff0\n'
+ '{\\fonttbl\n'
+ '{\\f0\\froman\\fcharset0\\fprq0 Times New Roman;}\n'
+ '{\\f1\\fswiss\\fcharset0\\fprq0 Arial;}}\n'
+ '{\colortbl\n'
+ )
+
self.color_map = {}
index = 1
self.color_map[(0,0,0)] = 0
@@ -109,14 +112,16 @@ class RTFDoc(BaseDoc,TextDoc):
self.color_map[bgcolor] = index
index += 1
self.f.write('}\n')
- self.f.write('\\kerning0\\cf0\\viewkind1')
- self.f.write('\\paperw%d' % twips(self.paper.get_size().get_width()))
- self.f.write('\\paperh%d' % twips(self.paper.get_size().get_height()))
- self.f.write('\\margl%d' % twips(self.paper.get_left_margin()))
- self.f.write('\\margr%d' % twips(self.paper.get_right_margin()))
- self.f.write('\\margt%d' % twips(self.paper.get_top_margin()))
- self.f.write('\\margb%d' % twips(self.paper.get_bottom_margin()))
- self.f.write('\\widowctl\n')
+ self.f.write(
+ '\\kerning0\\cf0\\viewkind1' +
+ '\\paperw%d' % twips(self.paper.get_size().get_width()) +
+ '\\paperh%d' % twips(self.paper.get_size().get_height()) +
+ '\\margl%d' % twips(self.paper.get_left_margin()) +
+ '\\margr%d' % twips(self.paper.get_right_margin()) +
+ '\\margt%d' % twips(self.paper.get_top_margin()) +
+ '\\margb%d' % twips(self.paper.get_bottom_margin()) +
+ '\\widowctl\n'
+ )
self.in_table = 0
self.text = ""
@@ -159,9 +164,11 @@ class RTFDoc(BaseDoc,TextDoc):
bgindex = self.color_map[p.get_background_color()]
fgindex = self.color_map[f.get_color()]
if f.get_type_face() == FONT_SERIF:
- self.font_type = '\\f0\\fs%d\\cf%d\\cb%d' % (size,fgindex,bgindex)
+ self.font_type = '\\f0'
else:
- self.font_type = '\\f1\\fs%d\\cf%d\\cb%d' % (size,fgindex,bgindex)
+ self.font_type = '\\f1'
+ self.font_type += '\\fs%d\\cf%d\\cb%d' % (size,fgindex,bgindex)
+
if f.get_bold():
self.font_type += "\\b"
if f.get_underline():
@@ -177,9 +184,11 @@ class RTFDoc(BaseDoc,TextDoc):
self.f.write('\\qr')
elif p.get_alignment() == PARA_ALIGN_CENTER:
self.f.write('\\qc')
- self.f.write('\\ri%d' % twips(p.get_right_margin()))
- self.f.write('\\li%d' % twips(p.get_left_margin()))
- self.f.write('\\fi%d' % twips(p.get_first_indent()))
+ self.f.write(
+ '\\ri%d' % twips(p.get_right_margin()) +
+ '\\li%d' % twips(p.get_left_margin()) +
+ '\\fi%d' % twips(p.get_first_indent())
+ )
if p.get_alignment() == PARA_ALIGN_JUSTIFY:
self.f.write('\\qj')
if p.get_padding():
diff --git a/src/plugins/docgen/SvgDrawDoc.py b/src/plugins/docgen/SvgDrawDoc.py
index 048f40a75..a4f5812b8 100644
--- a/src/plugins/docgen/SvgDrawDoc.py
+++ b/src/plugins/docgen/SvgDrawDoc.py
@@ -66,7 +66,7 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
pass
def start_page(self):
- self.page = self.page + 1
+ self.page += 1
if self.page != 1:
name = "%s-%d.svg" % (self.root, self.page)
else:
@@ -81,11 +81,15 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
self.t = StringIO.StringIO()
- self.f.write('\n')
- self.f.write('\n')
- self.f.write('