2006-03-01 01:24:35 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
|
|
|
# Copyright (C) 2005-2006 Serge Noiraud
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2006-03-01 01:24:35 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2007-09-12 20:32:03 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2006-03-01 01:24:35 +05:30
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2008-12-05 03:14:12 +05:30
|
|
|
try:
|
|
|
|
from hashlib import md5
|
|
|
|
except ImportError:
|
|
|
|
from md5 import md5
|
2006-03-01 01:24:35 +05:30
|
|
|
import zipfile
|
|
|
|
import time
|
|
|
|
import locale
|
|
|
|
from cStringIO import StringIO
|
2006-07-05 05:08:51 +05:30
|
|
|
from math import pi, cos, sin
|
2007-04-18 07:42:40 +05:30
|
|
|
from xml.sax.saxutils import escape
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import BaseDoc
|
|
|
|
import const
|
2008-10-02 09:32:10 +05:30
|
|
|
from gen.plug import PluginManager
|
2006-05-31 09:18:32 +05:30
|
|
|
from ReportBase import ReportUtils
|
2006-03-01 01:24:35 +05:30
|
|
|
import ImgManip
|
|
|
|
import FontScale
|
2006-03-03 05:53:04 +05:30
|
|
|
import Mime
|
2006-06-19 02:28:25 +05:30
|
|
|
import Utils
|
2006-06-24 22:52:34 +05:30
|
|
|
import Errors
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# internationalization
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
_apptype = 'application/vnd.oasis.opendocument.text'
|
|
|
|
|
|
|
|
_esc_map = {
|
2007-09-12 20:32:03 +05:30
|
|
|
'\x1a' : '',
|
|
|
|
'\x0c' : '',
|
|
|
|
'\n' : '<text:line-break/>',
|
|
|
|
'\t' : '<text:tab />',
|
|
|
|
'<super>' : '<text:span text:style-name="GSuper">',
|
|
|
|
'</super>' : '</text:span>',
|
2006-03-01 01:24:35 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ODFDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-09-12 20:32:03 +05:30
|
|
|
class ODFDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def __init__(self, styles, type, template):
|
|
|
|
BaseDoc.BaseDoc.__init__(self, styles, type, template)
|
2007-04-01 09:51:44 +05:30
|
|
|
self.media_list = []
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt = None
|
|
|
|
self.filename = None
|
|
|
|
self.level = 0
|
|
|
|
self.time = "0000-00-00T00:00:00"
|
|
|
|
self.new_page = 0
|
|
|
|
self.new_cell = 0
|
|
|
|
self.page = 0
|
|
|
|
self.first_page = 1
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def open(self, filename):
|
2006-03-01 01:24:35 +05:30
|
|
|
t = time.localtime(time.time())
|
|
|
|
self.time = "%04d-%02d-%02dT%02d:%02d:%02d" % \
|
2007-09-12 20:32:03 +05:30
|
|
|
(t[0], t[1], t[2], t[3], t[4], t[5])
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
if filename[-4:] != ".odt":
|
|
|
|
self.filename = filename + ".odt"
|
|
|
|
else:
|
|
|
|
self.filename = filename
|
|
|
|
|
|
|
|
self.filename = os.path.normpath(os.path.abspath(self.filename))
|
|
|
|
self.cntnt = StringIO()
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
assert (not self.init_called)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.init_called = True
|
|
|
|
|
|
|
|
current_locale = locale.getlocale()
|
|
|
|
self.lang = current_locale[0]
|
|
|
|
if self.lang:
|
2007-09-12 20:32:03 +05:30
|
|
|
self.lang = self.lang.replace('_', '-')
|
2006-03-01 01:24:35 +05:30
|
|
|
else:
|
|
|
|
self.lang = "en-US"
|
|
|
|
|
|
|
|
self.cntnt.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.cntnt.write('<office:document-content ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
|
|
|
|
self.cntnt.write('xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" ')
|
|
|
|
self.cntnt.write('xmlns:dom="http://www.w3.org/2001/xml-events" ')
|
|
|
|
self.cntnt.write('xmlns:xforms="http://www.w3.org/2002/xforms" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('office:class="text" office:version="1.0">\n')
|
|
|
|
self.cntnt.write('<office:scripts/>\n')
|
|
|
|
self.cntnt.write('<office:font-face-decls>\n')
|
|
|
|
self.cntnt.write('<style:font-face style:name="Courier" svg:font-family="Courier" ')
|
|
|
|
self.cntnt.write('style:font-family-generic="modern" style:font-pitch="fixed"/>\n')
|
|
|
|
self.cntnt.write('<style:font-face style:name="Times New Roman" ')
|
|
|
|
self.cntnt.write('svg:font-family="'Times New Roman'" ')
|
|
|
|
self.cntnt.write('style:font-family-generic="roman" ')
|
|
|
|
self.cntnt.write('style:font-pitch="variable"/>\n')
|
|
|
|
self.cntnt.write('<style:font-face style:name="Arial" ')
|
|
|
|
self.cntnt.write('svg:font-family="Arial" ')
|
|
|
|
self.cntnt.write('style:font-family-generic="swiss" ')
|
|
|
|
self.cntnt.write('style:font-pitch="variable"/>\n')
|
|
|
|
self.cntnt.write('</office:font-face-decls>\n')
|
|
|
|
self.cntnt.write('<office:automatic-styles>\n')
|
|
|
|
self.cntnt.write('<style:style style:name="docgen_page_break" style:family="paragraph" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('style:parent-style-name="Standard">\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<style:paragraph-properties fo:break-before="page"/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
self.cntnt.write('<style:style style:name="GSuper" style:family="text">')
|
|
|
|
self.cntnt.write('<style:text-properties style:text-position="super 58%"/>')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
self.cntnt.write('<style:style style:name="GRAMPS-preformat" style:family="text">')
|
|
|
|
self.cntnt.write('<style:text-properties style:font-name="Courier"/>')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
styles = self.get_style_sheet()
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
for style_name in styles.get_draw_style_names():
|
|
|
|
style = styles.get_draw_style(style_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<style:style style:name="%s"' % style_name)
|
|
|
|
self.cntnt.write(' style:family="graphic"')
|
|
|
|
self.cntnt.write(' >\n')
|
|
|
|
self.cntnt.write('<style:graphic-properties ')
|
|
|
|
|
|
|
|
if style.get_line_width():
|
|
|
|
self.cntnt.write('svg:stroke-width="%.2f" ' % (style.get_line_width()*10))
|
|
|
|
self.cntnt.write('draw:marker-start="" ')
|
|
|
|
self.cntnt.write('draw:marker-start-width="0.0" ')
|
|
|
|
self.cntnt.write('draw:marker-end-width="0.0" ')
|
|
|
|
self.cntnt.write('draw:stroke="solid" ')
|
|
|
|
self.cntnt.write('draw:textarea-horizontal-align="center" ')
|
|
|
|
self.cntnt.write('draw:textarea-vertical-align="middle" ')
|
|
|
|
else:
|
|
|
|
self.cntnt.write('draw:stroke="none" ')
|
|
|
|
self.cntnt.write('draw:stroke-color="#000000" ')
|
|
|
|
|
|
|
|
if style.get_line_style() == BaseDoc.DASHED:
|
|
|
|
self.cntnt.write('svg:fill-color="#cccccc" ')
|
|
|
|
else:
|
|
|
|
self.cntnt.write('svg:fill-color="#%02x%02x%02x" ' % style.get_color())
|
|
|
|
self.cntnt.write('draw:fill-color="#%02x%02x%02x" ' % style.get_fill_color())
|
|
|
|
self.cntnt.write('draw:shadow="hidden" ')
|
|
|
|
self.cntnt.write('style:run-through="background" ')
|
|
|
|
self.cntnt.write('style:vertical-pos="from-top" ')
|
|
|
|
self.cntnt.write('style:vertical-rel="paragraph" ')
|
|
|
|
self.cntnt.write('style:horizontal-pos="from-left" ')
|
|
|
|
self.cntnt.write('style:horizontal-rel="paragraph" ')
|
|
|
|
self.cntnt.write('draw:wrap-influence-on-position="once-concurrent" ')
|
|
|
|
self.cntnt.write('style:flow-with-text="false" ')
|
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="%s_shadow"' % style_name)
|
|
|
|
self.cntnt.write(' style:family="graphic">\n')
|
|
|
|
self.cntnt.write('<style:graphic-properties ')
|
|
|
|
self.cntnt.write('draw:stroke="none" ')
|
|
|
|
self.cntnt.write('draw:fill="solid" ')
|
|
|
|
self.cntnt.write('draw:fill-color="#cccccc" ')
|
|
|
|
self.cntnt.write('draw:textarea-horizontal-align="center" ')
|
|
|
|
self.cntnt.write('draw:textarea-vertical-align="middle" ')
|
|
|
|
self.cntnt.write('draw:shadow="hidden" ')
|
|
|
|
self.cntnt.write('style:run-through="background" ')
|
|
|
|
self.cntnt.write('style:vertical-pos="from-top" ')
|
|
|
|
self.cntnt.write('style:vertical-rel="paragraph" ')
|
|
|
|
self.cntnt.write('style:horizontal-pos="from-left" ')
|
|
|
|
self.cntnt.write('style:horizontal-rel="paragraph" ')
|
|
|
|
self.cntnt.write('draw:wrap-influence-on-position="once-concurrent" ')
|
|
|
|
self.cntnt.write('style:flow-with-text="false" ')
|
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
2007-06-25 02:30:25 +05:30
|
|
|
# Graphic style for items with a clear background
|
|
|
|
self.cntnt.write('<style:style style:name="clear" ')
|
|
|
|
self.cntnt.write('style:family="graphic">\n')
|
|
|
|
self.cntnt.write('\t<style:graphic-properties draw:stroke="none" ')
|
|
|
|
self.cntnt.write('draw:fill="none" draw:shadow="hidden" ')
|
|
|
|
self.cntnt.write('style:run-through="background" ')
|
|
|
|
self.cntnt.write('style:vertical-pos="from-top" ')
|
|
|
|
self.cntnt.write('style:vertical-rel="paragraph" ')
|
|
|
|
self.cntnt.write('style:horizontal-pos="from-left" ')
|
|
|
|
self.cntnt.write('style:horizontal-rel="paragraph" ')
|
|
|
|
self.cntnt.write('draw:wrap-influence-on-position="once-concurrent" ')
|
|
|
|
self.cntnt.write('style:flow-with-text="false"/>')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
for style_name in styles.get_paragraph_style_names():
|
|
|
|
style = styles.get_paragraph_style(style_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="NL%s" ' % style_name)
|
|
|
|
self.cntnt.write('style:family="paragraph" ')
|
|
|
|
self.cntnt.write('style:parent-style-name="%s">\n' % style_name)
|
|
|
|
self.cntnt.write('<style:paragraph-properties fo:break-before="page"/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="X%s" ' % style_name)
|
|
|
|
self.cntnt.write('style:family="paragraph"')
|
|
|
|
self.cntnt.write('>\n')
|
|
|
|
self.cntnt.write('<style:paragraph-properties ')
|
|
|
|
|
|
|
|
if style.get_padding() != 0.0:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:padding="%.2fcm" ' % style.get_padding())
|
2006-03-01 01:24:35 +05:30
|
|
|
if style.get_header_level() > 0:
|
|
|
|
self.cntnt.write('fo:keep-with-next="true" ')
|
|
|
|
|
|
|
|
align = style.get_alignment()
|
|
|
|
if align == BaseDoc.PARA_ALIGN_LEFT:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:text-align="start" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_RIGHT:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:text-align="end" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_CENTER:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:text-align="center" ')
|
|
|
|
self.cntnt.write('style:justify-single-word="false" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
else:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:text-align="justify" ')
|
|
|
|
self.cntnt.write('style:justify-single-word="false" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
font = style.get_font()
|
|
|
|
if font.get_type_face() == BaseDoc.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)
|
|
|
|
if font.get_bold():
|
|
|
|
self.cntnt.write('fo:font-weight="bold" ')
|
|
|
|
if font.get_italic():
|
|
|
|
self.cntnt.write('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="0.00cm"\n')
|
|
|
|
self.cntnt.write('fo:margin-bottom="0.212cm" ')
|
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="F%s" ' % style_name)
|
|
|
|
self.cntnt.write('style:family="text">\n')
|
|
|
|
self.cntnt.write('<style:text-properties ')
|
|
|
|
align = style.get_alignment()
|
|
|
|
if align == BaseDoc.PARA_ALIGN_LEFT:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:text-align="start" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_RIGHT:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:text-align="end" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_CENTER:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.cntnt.write('fo:text-align="center" ')
|
|
|
|
self.cntnt.write('style:justify-single-word="false" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
font = style.get_font()
|
|
|
|
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
|
|
|
self.cntnt.write('style:font-name="Arial" ')
|
|
|
|
else:
|
|
|
|
self.cntnt.write('style:font-name="Times New Roman" ')
|
|
|
|
color = font.get_color()
|
|
|
|
self.cntnt.write('fo:color="#%02x%02x%02x" ' % color)
|
|
|
|
if font.get_bold():
|
|
|
|
self.cntnt.write('fo:font-weight="bold" ')
|
|
|
|
if font.get_italic():
|
|
|
|
self.cntnt.write('fo:font-style="italic" ')
|
|
|
|
self.cntnt.write('fo:font-size="%.2fpt" ' % font.get_size())
|
|
|
|
self.cntnt.write('style:font-size-asian="%.2fpt"/> ' % font.get_size())
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
for style_name in styles.get_table_style_names():
|
|
|
|
style = styles.get_table_style(style_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<style:style style:name="%s" ' % style_name)
|
|
|
|
self.cntnt.write('style:family="table-properties">\n')
|
|
|
|
table_width = float(self.get_usable_width())
|
|
|
|
table_width_str = "%.2f" % table_width
|
|
|
|
self.cntnt.write('<style:table-properties-properties style:width="%scm" '%table_width_str)
|
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2007-09-12 20:32:03 +05:30
|
|
|
for col in range(0, style.get_columns()):
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<style:style style:name="')
|
|
|
|
self.cntnt.write(style_name + '.' + str(chr(ord('A')+col)) +'" ')
|
|
|
|
self.cntnt.write('style:family="table-column">')
|
|
|
|
width = table_width * float(style.get_column_width(col)/100.0)
|
|
|
|
width_str = "%.4f" % width
|
|
|
|
self.cntnt.write('<style:table-column-properties ')
|
|
|
|
self.cntnt.write('style:column-width="%scm"/>' % width_str)
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
for cell in styles.get_cell_style_names():
|
|
|
|
cell_style = styles.get_cell_style(cell)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<style:style style:name="%s" ' % cell)
|
|
|
|
self.cntnt.write('style:family="table-cell">\n')
|
|
|
|
self.cntnt.write('<style:table-cell-properties')
|
|
|
|
self.cntnt.write(' fo:padding="%.2fcm"' % cell_style.get_padding())
|
|
|
|
if cell_style.get_top_border():
|
|
|
|
self.cntnt.write(' fo:border-top="0.002cm solid #000000"')
|
|
|
|
else:
|
|
|
|
self.cntnt.write(' fo:border-top="none"')
|
|
|
|
if cell_style.get_bottom_border():
|
|
|
|
self.cntnt.write(' fo:border-bottom="0.002cm solid #000000"')
|
|
|
|
else:
|
|
|
|
self.cntnt.write(' fo:border-bottom="none"')
|
|
|
|
if cell_style.get_left_border():
|
|
|
|
self.cntnt.write(' fo:border-left="0.002cm solid #000000"')
|
|
|
|
else:
|
|
|
|
self.cntnt.write(' fo:border-left="none"')
|
|
|
|
if cell_style.get_right_border():
|
|
|
|
self.cntnt.write(' fo:border-right="0.002cm solid #000000"')
|
|
|
|
else:
|
|
|
|
self.cntnt.write(' fo:border-right="none"')
|
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="Tbold" style:family="text">\n')
|
|
|
|
self.cntnt.write('<style:text-properties fo:font-weight="bold"/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
#Begin photo style
|
|
|
|
self.cntnt.write('<style:style style:name="Left" style:family="graphic"')
|
|
|
|
self.cntnt.write(' style:parent-style-name="photo">')
|
|
|
|
self.cntnt.write('<style:graphic-properties style:run-through="foreground"')
|
2006-05-02 02:41:26 +05:30
|
|
|
self.cntnt.write(' style:wrap="dynamic"')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write(' style:number-wrapped-paragraphs="no-limit"')
|
|
|
|
self.cntnt.write(' style:wrap-contour="false" style:vertical-pos="from-top"')
|
|
|
|
self.cntnt.write(' style:vertical-rel="paragraph-content"')
|
|
|
|
self.cntnt.write(' style:horizontal-pos="left"')
|
|
|
|
self.cntnt.write(' style:horizontal-rel="paragraph-content"')
|
|
|
|
self.cntnt.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
|
|
|
|
self.cntnt.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
|
|
|
|
self.cntnt.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
|
|
|
|
self.cntnt.write(' draw:color-inversion="false" draw:transparency="-100%"')
|
|
|
|
self.cntnt.write(' draw:color-mode="standard"/>')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="Right" style:family="graphic"')
|
|
|
|
self.cntnt.write(' style:parent-style-name="photo">')
|
|
|
|
self.cntnt.write('<style:graphic-properties style:run-through="foreground"')
|
2006-04-10 09:59:29 +05:30
|
|
|
self.cntnt.write(' style:wrap="dynamic"')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write(' style:number-wrapped-paragraphs="no-limit"')
|
|
|
|
self.cntnt.write(' style:wrap-contour="false" style:vertical-pos="from-top"')
|
|
|
|
self.cntnt.write(' style:vertical-rel="paragraph-content"')
|
|
|
|
self.cntnt.write(' style:horizontal-pos="right"')
|
|
|
|
self.cntnt.write(' style:horizontal-rel="paragraph-content"')
|
|
|
|
self.cntnt.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
|
|
|
|
self.cntnt.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
|
|
|
|
self.cntnt.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
|
|
|
|
self.cntnt.write(' draw:color-inversion="false" draw:transparency="-100%"')
|
|
|
|
self.cntnt.write(' draw:color-mode="standard"/>')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="Single" style:family="graphic"')
|
|
|
|
self.cntnt.write(' style:parent-style-name="Graphics"> ')
|
|
|
|
self.cntnt.write('<style:graphic-properties style:vertical-pos="from-top"')
|
|
|
|
self.cntnt.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
|
|
|
|
self.cntnt.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
|
|
|
|
self.cntnt.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
|
|
|
|
self.cntnt.write(' draw:color-inversion="false" draw:transparency="-100%"')
|
|
|
|
self.cntnt.write(' draw:color-mode="standard"/> ')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="Row" style:family="graphic"')
|
|
|
|
self.cntnt.write(' style:parent-style-name="Graphics">')
|
|
|
|
self.cntnt.write('<style:graphic-properties style:vertical-pos="from-top"')
|
|
|
|
self.cntnt.write(' style:vertical-rel="paragraph"')
|
|
|
|
self.cntnt.write(' style:horizontal-pos="from-left"')
|
|
|
|
self.cntnt.write(' style:horizontal-rel="paragraph"')
|
|
|
|
self.cntnt.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
|
|
|
|
self.cntnt.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
|
|
|
|
self.cntnt.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
|
|
|
|
self.cntnt.write(' draw:color-inversion="false" draw:transparency="-100%"')
|
|
|
|
self.cntnt.write(' draw:color-mode="standard"/>')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
|
|
|
|
|
|
|
#end of Photo style edits
|
|
|
|
|
|
|
|
self.cntnt.write('</office:automatic-styles>\n')
|
|
|
|
self.cntnt.write('<office:body>\n')
|
|
|
|
self.cntnt.write(' <office:text>\n')
|
|
|
|
self.cntnt.write(' <office:forms ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('form:automatic-focus="false" ')
|
|
|
|
self.cntnt.write('form:apply-design-mode="false"/>\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
def close(self):
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('</office:text>\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('</office:body>\n')
|
|
|
|
self.cntnt.write('</office:document-content>\n')
|
|
|
|
self._write_styles_file()
|
|
|
|
self._write_manifest()
|
|
|
|
self._write_meta_file()
|
|
|
|
self._write_mimetype_file()
|
|
|
|
self._write_zip()
|
|
|
|
if self.print_req:
|
2006-03-03 05:53:04 +05:30
|
|
|
app = Mime.get_application(_apptype)
|
2007-09-12 20:32:03 +05:30
|
|
|
Utils.launch(app[0], self.filename)
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2008-04-06 09:11:22 +05:30
|
|
|
def add_media_object(self, file_name, pos, x_cm, y_cm):
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
# try to open the image. If the open fails, it probably wasn't
|
|
|
|
# a valid image (could be a PDF, or a non-image)
|
2008-04-06 09:11:22 +05:30
|
|
|
(x, y) = ImgManip.image_size(file_name)
|
2007-09-12 20:32:03 +05:30
|
|
|
if (x, y) == (0, 0):
|
2006-03-01 01:24:35 +05:30
|
|
|
return
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
ratio = float(x_cm)*float(y)/(float(y_cm)*float(x))
|
2006-03-01 01:24:35 +05:30
|
|
|
if ratio < 1:
|
|
|
|
act_width = x_cm
|
|
|
|
act_height = y_cm*ratio
|
|
|
|
else:
|
|
|
|
act_height = y_cm
|
|
|
|
act_width = x_cm/ratio
|
2008-04-06 09:11:22 +05:30
|
|
|
|
|
|
|
not_extension, extension = os.path.splitext(file_name)
|
2008-12-05 03:14:12 +05:30
|
|
|
odf_name = md5(file_name).hexdigest() + extension
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2008-04-06 09:11:22 +05:30
|
|
|
media_list_item = (file_name, odf_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
if not media_list_item in self.media_list:
|
|
|
|
self.media_list.append(media_list_item)
|
|
|
|
|
2008-04-06 09:11:22 +05:30
|
|
|
base = escape(os.path.basename(file_name))
|
2007-09-12 20:32:03 +05:30
|
|
|
tag = base.replace('.', '_')
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
if self.new_cell:
|
|
|
|
self.cntnt.write('<text:p>')
|
|
|
|
if pos == "left":
|
2006-04-05 10:11:56 +05:30
|
|
|
self.cntnt.write('<draw:frame draw:style-name="Left" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif pos == "right":
|
2006-04-05 10:11:56 +05:30
|
|
|
self.cntnt.write('<draw:frame draw:style-name="Right" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif pos == "single":
|
2006-04-05 10:11:56 +05:30
|
|
|
self.cntnt.write('<draw:frame draw:style-name="Single" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
else:
|
2006-04-05 10:11:56 +05:30
|
|
|
self.cntnt.write('<draw:frame draw:style-name="Row" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.cntnt.write('draw:name="%s" ' % tag)
|
|
|
|
self.cntnt.write('text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('svg:width="%.2fcm" ' % act_width)
|
|
|
|
self.cntnt.write('svg:height="%.2fcm" ' % act_height)
|
2006-05-02 02:41:26 +05:30
|
|
|
self.cntnt.write('draw:z-index="1" >')
|
2006-04-05 10:11:56 +05:30
|
|
|
self.cntnt.write('<draw:image xlink:href="Pictures/')
|
2008-04-06 09:11:22 +05:30
|
|
|
self.cntnt.write(odf_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('" xlink:type="simple" xlink:show="embed" ')
|
|
|
|
self.cntnt.write('xlink:actuate="onLoad"/>\n')
|
2006-04-05 10:11:56 +05:30
|
|
|
self.cntnt.write('</draw:frame>\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
if self.new_cell:
|
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def start_table(self, name, style_name):
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<table:table table:name="%s" ' % name)
|
|
|
|
self.cntnt.write('table:style-name="%s">\n' % style_name)
|
2007-04-23 17:16:26 +05:30
|
|
|
styles = self.get_style_sheet()
|
|
|
|
table = styles.get_table_style(style_name)
|
2007-09-12 20:32:03 +05:30
|
|
|
for col in range(0, table.get_columns()):
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<table:table-column table:style-name="')
|
|
|
|
self.cntnt.write(style_name + '.' + str(chr(ord('A')+col)) +'"/>\n')
|
|
|
|
|
|
|
|
def end_table(self):
|
|
|
|
self.cntnt.write('</table:table>\n')
|
|
|
|
|
|
|
|
def start_row(self):
|
|
|
|
self.cntnt.write('<table:table-row>\n')
|
|
|
|
|
|
|
|
def end_row(self):
|
|
|
|
self.cntnt.write('</table:table-row>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def start_cell(self, style_name, span=1):
|
2006-03-01 01:24:35 +05:30
|
|
|
self.span = span
|
|
|
|
self.cntnt.write('<table:table-cell table:style-name="%s" ' % style_name)
|
|
|
|
self.cntnt.write('table:value-type="string"')
|
|
|
|
if span > 1:
|
|
|
|
self.cntnt.write(' table:number-columns-spanned="%s">\n' % span)
|
|
|
|
else:
|
|
|
|
self.cntnt.write('>\n')
|
|
|
|
self.new_cell = 1
|
|
|
|
|
|
|
|
def end_cell(self):
|
|
|
|
self.cntnt.write('</table:table-cell>\n')
|
2007-09-12 20:32:03 +05:30
|
|
|
#for col in range(1, self.span):
|
2006-03-01 01:24:35 +05:30
|
|
|
# self.cntnt.write('<table:covered-table-cell/>\n')
|
|
|
|
self.new_cell = 0
|
|
|
|
|
|
|
|
def start_bold(self):
|
|
|
|
self.cntnt.write('<text:span text:style-name="Tbold">')
|
|
|
|
|
|
|
|
def end_bold(self):
|
|
|
|
self.cntnt.write('</text:span>')
|
2007-01-31 08:43:31 +05:30
|
|
|
|
|
|
|
def start_superscript(self):
|
|
|
|
self.cntnt.write('<text:span text:style-name="GSuper">')
|
|
|
|
|
|
|
|
def end_superscript(self):
|
|
|
|
self.cntnt.write('</text:span>')
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def _add_zip(self, zfile, name, data, t):
|
2006-03-01 01:24:35 +05:30
|
|
|
zipinfo = zipfile.ZipInfo(name.encode('latin-1'))
|
|
|
|
zipinfo.date_time = t
|
|
|
|
zipinfo.compress_type = zipfile.ZIP_DEFLATED
|
2007-09-12 20:32:03 +05:30
|
|
|
zfile.writestr(zipinfo, data)
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
def _write_zip(self):
|
2006-06-24 22:52:34 +05:30
|
|
|
try:
|
2007-09-12 20:32:03 +05:30
|
|
|
zfile = zipfile.ZipFile(self.filename, "w", zipfile.ZIP_DEFLATED)
|
|
|
|
except IOError, msg:
|
2006-06-24 22:52:34 +05:30
|
|
|
errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg)
|
|
|
|
raise Errors.ReportError(errmsg)
|
|
|
|
except:
|
|
|
|
raise Errors.ReportError(_("Could not create %s") % self.filename)
|
|
|
|
|
2006-03-01 01:24:35 +05:30
|
|
|
t = time.localtime(time.time())[:6]
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
self._add_zip(zfile, "META-INF/manifest.xml", self.mfile.getvalue(), t)
|
|
|
|
self._add_zip(zfile, "content.xml", self.cntnt.getvalue(), t)
|
|
|
|
self._add_zip(zfile, "meta.xml", self.meta.getvalue(), t)
|
|
|
|
self._add_zip(zfile, "styles.xml", self.sfile.getvalue(), t)
|
|
|
|
self._add_zip(zfile, "mimetype", self.mimetype.getvalue(), t)
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.mfile.close()
|
|
|
|
self.cntnt.close()
|
|
|
|
self.meta.close()
|
|
|
|
self.sfile.close()
|
|
|
|
self.mimetype.close()
|
|
|
|
|
|
|
|
for image in self.media_list:
|
|
|
|
try:
|
2007-09-12 20:32:03 +05:30
|
|
|
ifile = open(image[0], mode='rb')
|
2008-04-06 09:11:22 +05:30
|
|
|
self._add_zip(zfile, "Pictures/%s" % image[1], ifile.read(), t)
|
2006-03-01 01:24:35 +05:30
|
|
|
ifile.close()
|
|
|
|
except:
|
|
|
|
print "Could not open %s" % image[0]
|
|
|
|
zfile.close()
|
|
|
|
|
|
|
|
def _write_styles_file(self):
|
|
|
|
self.sfile = StringIO()
|
|
|
|
|
|
|
|
self.sfile.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.sfile.write('<office:document-styles ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ')
|
|
|
|
self.sfile.write('xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ')
|
|
|
|
self.sfile.write('xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ')
|
|
|
|
self.sfile.write('xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ')
|
|
|
|
self.sfile.write('xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ')
|
|
|
|
self.sfile.write('xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
|
|
|
|
self.sfile.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ')
|
|
|
|
self.sfile.write('xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" ')
|
|
|
|
self.sfile.write('xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" ')
|
|
|
|
self.sfile.write('xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" ')
|
|
|
|
self.sfile.write('xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" ')
|
|
|
|
self.sfile.write('xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('office:version="1.0">\n')
|
|
|
|
self.sfile.write('<office:font-face-decls>\n')
|
|
|
|
self.sfile.write('<style:font-face style:name="Times New Roman"')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write(' svg:font-family="'Times New Roman'"')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write(' style:font-family-generic="roman"')
|
|
|
|
self.sfile.write(' style:font-pitch="variable"/>\n')
|
|
|
|
self.sfile.write('<style:font-face style:name="Arial"')
|
|
|
|
self.sfile.write(' svg:font-family="Arial"')
|
|
|
|
self.sfile.write(' style:font-family-generic="swiss"')
|
|
|
|
self.sfile.write(' style:font-pitch="variable"/>\n')
|
|
|
|
self.sfile.write('</office:font-face-decls>\n')
|
|
|
|
self.sfile.write('<office:styles>\n')
|
|
|
|
self.sfile.write('<style:default-style ')
|
|
|
|
self.sfile.write(' style:family="graphic">\n')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('<style:graphic-properties ')
|
|
|
|
self.sfile.write(' draw:shadow-offset-x="0.3cm"')
|
|
|
|
self.sfile.write(' draw:shadow-offset-y="0.3cm" ')
|
|
|
|
self.sfile.write(' draw:start-line-spacing-horizontal="0.283cm" ')
|
|
|
|
self.sfile.write(' draw:start-line-spacing-vertical="0.283cm" ')
|
|
|
|
self.sfile.write(' draw:end-line-spacing-horizontal="0.283cm" ')
|
|
|
|
self.sfile.write(' draw:end-line-spacing-vertical="0.283cm" ')
|
|
|
|
self.sfile.write(' style:flow-with-text="true"/>')
|
|
|
|
self.sfile.write('<style:paragraph-properties ')
|
|
|
|
self.sfile.write(' style:text-autospace="ideograph-alpha" ')
|
|
|
|
self.sfile.write(' style:line-break="strict" ')
|
|
|
|
self.sfile.write(' style:writing-mode="lr-tb" ')
|
|
|
|
self.sfile.write(' style:font-independent-line-spacing="false">')
|
|
|
|
self.sfile.write(' <style:tab-stops/>')
|
|
|
|
self.sfile.write(' </style:paragraph-properties>')
|
|
|
|
self.sfile.write('<style:text-properties ')
|
|
|
|
self.sfile.write(' style:use-window-font-color="true" ')
|
|
|
|
self.sfile.write(' fo:font-size="12pt" ')
|
|
|
|
self.sfile.write(' style:font-size-asian="12pt" ')
|
|
|
|
self.sfile.write(' style:language-asian="none" ')
|
|
|
|
self.sfile.write(' style:country-asian="none" ')
|
|
|
|
self.sfile.write(' style:font-size-complex="12pt" ')
|
|
|
|
self.sfile.write(' style:language-complex="none" ')
|
|
|
|
self.sfile.write(' style:country-complex="none"/>')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('</style:default-style>\n')
|
|
|
|
self.sfile.write('<style:default-style ')
|
|
|
|
self.sfile.write(' style:family="paragraph">\n')
|
|
|
|
self.sfile.write(' <style:paragraph-properties\n')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write(' style:text-autospace="ideograph-alpha"\n')
|
|
|
|
self.sfile.write(' style:punctuation-wrap="hanging"\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write(' style:line-break="strict"\n')
|
|
|
|
self.sfile.write(' style:tab-stop-distance="2.205cm"\n')
|
|
|
|
self.sfile.write(' style:writing-mode="page"/>\n')
|
|
|
|
self.sfile.write('<style:text-properties \n')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('style:font-name="Times New Roman" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('fo:font-size="12pt" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('style:font-name-asian="Times New Roman" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('style:font-size-asian="12pt" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('style:font-name-complex="Times New Roman" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('style:font-size-complex="12pt" ')
|
|
|
|
self.sfile.write('style:tab-stop-distance="2.205cm"/>\n')
|
|
|
|
self.sfile.write('</style:default-style>\n')
|
|
|
|
self.sfile.write('<style:default-style ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write(' style:family="table"> ')
|
|
|
|
self.sfile.write(' <style:table-properties ')
|
|
|
|
self.sfile.write(' table:border-model="separating"/> ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('</style:default-style>\n')
|
|
|
|
self.sfile.write('<style:default-style ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write(' style:family="table-row"> ')
|
|
|
|
self.sfile.write(' <style:table-row-properties ')
|
|
|
|
self.sfile.write(' fo:keep-together="auto"/> ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('</style:default-style>\n')
|
|
|
|
self.sfile.write('<style:style style:name="Standard" ')
|
|
|
|
self.sfile.write('style:family="paragraph" style:class="text"/>\n')
|
|
|
|
self.sfile.write('<style:style style:name="photo" style:family="graphic">\n')
|
|
|
|
self.sfile.write('<style:graphic-properties text:anchor-type="paragraph" ')
|
|
|
|
self.sfile.write('svg:x="0cm" svg:y="0cm" style:wrap="none" ')
|
|
|
|
self.sfile.write('style:vertical-pos="top" ')
|
|
|
|
self.sfile.write('style:vertical-rel="paragraph-content" ')
|
|
|
|
self.sfile.write('style:horizontal-pos="center" ')
|
|
|
|
self.sfile.write('style:horizontal-rel="paragraph-content"/>\n')
|
|
|
|
self.sfile.write('</style:style>\n')
|
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
styles = self.get_style_sheet()
|
|
|
|
|
|
|
|
for style_name in styles.get_paragraph_style_names():
|
|
|
|
style = styles.get_paragraph_style(style_name)
|
|
|
|
self.sfile.write('<style:style style:name="%s" ' % style_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('style:family="paragraph" ')
|
|
|
|
self.sfile.write('style:parent-style-name="Standard" ')
|
|
|
|
self.sfile.write('style:class="text">\n')
|
|
|
|
self.sfile.write('<style:paragraph-properties\n')
|
|
|
|
self.sfile.write('fo:margin-left="%.2fcm"\n' % style.get_left_margin())
|
|
|
|
self.sfile.write('fo:margin-right="%.2fcm"\n' % style.get_right_margin())
|
|
|
|
self.sfile.write('fo:margin-top="0.00cm"\n')
|
|
|
|
self.sfile.write('fo:margin-bottom="0.212cm"\n')
|
|
|
|
|
|
|
|
if style.get_padding() != 0.0:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.sfile.write('fo:padding="%.2fcm" ' % style.get_padding())
|
2006-03-01 01:24:35 +05:30
|
|
|
if style.get_header_level() > 0:
|
|
|
|
self.sfile.write('fo:keep-with-next="always" ')
|
|
|
|
|
|
|
|
align = style.get_alignment()
|
|
|
|
if align == BaseDoc.PARA_ALIGN_LEFT:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.sfile.write('fo:text-align="start" ')
|
|
|
|
self.sfile.write('style:justify-single-word="false" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_RIGHT:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.sfile.write('fo:text-align="end" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_CENTER:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.sfile.write('fo:text-align="center" ')
|
|
|
|
self.sfile.write('style:justify-single-word="false" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
else:
|
2008-01-06 01:40:26 +05:30
|
|
|
self.sfile.write('fo:text-align="justify" ')
|
|
|
|
self.sfile.write('style:justify-single-word="false" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('fo:text-indent="%.2fcm" ' % style.get_first_indent())
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('style:auto-text-indent="false"/> ')
|
|
|
|
self.sfile.write('<style:text-properties ')
|
2006-03-01 01:24:35 +05:30
|
|
|
font = style.get_font()
|
|
|
|
color = font.get_color()
|
|
|
|
self.sfile.write('fo:color="#%02x%02x%02x" ' % color)
|
|
|
|
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
|
|
|
self.sfile.write('style:font-name="Arial" ')
|
|
|
|
else:
|
|
|
|
self.sfile.write('style:font-name="Times New Roman" ')
|
|
|
|
self.sfile.write('fo:font-size="%.0fpt" ' % font.get_size())
|
|
|
|
if font.get_italic():
|
|
|
|
self.sfile.write('fo:font-style="italic" ')
|
|
|
|
if font.get_bold():
|
|
|
|
self.sfile.write('fo:font-weight="bold" ')
|
|
|
|
if font.get_underline():
|
|
|
|
self.sfile.write('style:text-underline="single" ')
|
|
|
|
self.sfile.write('style:text-underline-color="font-color" ')
|
|
|
|
self.sfile.write('fo:text-indent="%.2fcm" ' % style.get_first_indent())
|
|
|
|
self.sfile.write('fo:margin-right="%.2fcm" ' % style.get_right_margin())
|
|
|
|
self.sfile.write('fo:margin-left="%.2fcm" ' % style.get_left_margin())
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('fo:margin-top="0cm" ')
|
|
|
|
self.sfile.write('fo:margin-bottom="0.212cm"')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('/>\n')
|
|
|
|
self.sfile.write('</style:style>\n')
|
|
|
|
|
|
|
|
# Current no leading number format for headers
|
|
|
|
|
2006-06-20 02:18:28 +05:30
|
|
|
#self.sfile.write('<text:outline-style>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="1" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="2" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="3" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="4" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="5" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="6" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="7" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="8" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="9" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('<text:outline-level-style text:level="10" style:num-format=""/>\n')
|
|
|
|
#self.sfile.write('</text:outline-style>\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('<text:notes-configuration ')
|
|
|
|
self.sfile.write('text:note-class="footnote" ')
|
|
|
|
self.sfile.write('style:num-format="1" ')
|
|
|
|
self.sfile.write('text:start-value="0" ')
|
|
|
|
self.sfile.write('text:footnotes-position="page" ')
|
|
|
|
self.sfile.write('text:start-numbering-at="document"/> ')
|
|
|
|
self.sfile.write('<text:notes-configuration ')
|
|
|
|
self.sfile.write('text:note-class="endnote" ')
|
|
|
|
self.sfile.write('style:num-format="i" ')
|
|
|
|
self.sfile.write('text:start-value="0"/> ')
|
|
|
|
self.sfile.write('<text:linenumbering-configuration ')
|
|
|
|
self.sfile.write('text:number-lines="false" ')
|
|
|
|
self.sfile.write('text:offset="0.499cm" ')
|
|
|
|
self.sfile.write('style:num-format="1" ')
|
|
|
|
self.sfile.write('text:number-position="left" ')
|
|
|
|
self.sfile.write('text:increment="5"/> ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('</office:styles>\n')
|
|
|
|
self.sfile.write('<office:automatic-styles>\n')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('<style:style style:name="S-Header" style:family="paragraph" ')
|
|
|
|
self.sfile.write('style:parent-style-name="Standard">')
|
|
|
|
self.sfile.write('<style:paragraph-properties fo:text-align="center" ')
|
|
|
|
self.sfile.write('style:justify-single-word="false"/>')
|
|
|
|
self.sfile.write('</style:style>\n')
|
|
|
|
self.sfile.write('<style:style style:name="S-Footer" style:family="paragraph" ')
|
|
|
|
self.sfile.write('style:parent-style-name="Header">')
|
|
|
|
self.sfile.write('<style:paragraph-properties fo:text-align="center" ')
|
|
|
|
self.sfile.write('style:justify-single-word="false"/>')
|
|
|
|
self.sfile.write('</style:style>\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('<style:page-layout style:name="pm1">\n')
|
2007-02-25 02:45:21 +05:30
|
|
|
self.sfile.write('<style:page-layout-properties fo:page-width="%.2fcm" ' % self.paper.get_size().get_width())
|
|
|
|
self.sfile.write('fo:page-height="%.2fcm" ' % self.paper.get_size().get_height())
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('style:num-format="1" ')
|
2007-02-25 02:45:21 +05:30
|
|
|
if self.paper.get_orientation() == BaseDoc.PAPER_PORTRAIT:
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('style:print-orientation="portrait" ')
|
|
|
|
else:
|
|
|
|
self.sfile.write('style:print-orientation="landscape" ')
|
2007-02-25 02:45:21 +05:30
|
|
|
self.sfile.write('fo:margin-top="%.2fcm" ' % self.paper.get_top_margin())
|
|
|
|
self.sfile.write('fo:margin-bottom="%.2fcm" ' % self.paper.get_bottom_margin())
|
|
|
|
self.sfile.write('fo:margin-left="%.2fcm" ' % self.paper.get_left_margin())
|
|
|
|
self.sfile.write('fo:margin-right="%.2fcm" ' % self.paper.get_right_margin())
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('style:writing-mode="lr-tb" ')
|
|
|
|
self.sfile.write('style:footnote-max-height="0cm">\n')
|
|
|
|
self.sfile.write('<style:footnote-sep style:width="0.018cm" ')
|
|
|
|
self.sfile.write('style:distance-before-sep="0.101cm" ')
|
|
|
|
self.sfile.write('style:distance-after-sep="0.101cm" ')
|
|
|
|
self.sfile.write('style:adjustment="left" style:rel-width="25%" ')
|
|
|
|
self.sfile.write('style:color="#000000"/>\n')
|
|
|
|
self.sfile.write('</style:page-layout-properties>\n')
|
2006-06-20 02:18:28 +05:30
|
|
|
# header
|
|
|
|
self.sfile.write('<style:header-style>\n')
|
|
|
|
self.sfile.write('<style:header-footer-properties ')
|
|
|
|
self.sfile.write('fo:min-height="0cm" fo:margin-bottom="0.499cm"/>\n')
|
|
|
|
self.sfile.write('</style:header-style>\n')
|
|
|
|
# footer
|
|
|
|
self.sfile.write('<style:footer-style>\n')
|
|
|
|
self.sfile.write('<style:header-footer-properties ')
|
|
|
|
self.sfile.write('fo:min-height="0cm" fo:margin-bottom="0.499cm"/>\n')
|
|
|
|
self.sfile.write('</style:footer-style>\n')
|
|
|
|
#
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('</style:page-layout>\n')
|
|
|
|
self.sfile.write('</office:automatic-styles>\n')
|
|
|
|
self.sfile.write('<office:master-styles>\n')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.sfile.write('<style:master-page style:name="Standard" ')
|
|
|
|
self.sfile.write('style:page-layout-name="pm1">\n')
|
|
|
|
# header
|
|
|
|
#self.sfile.write('<style:header>')
|
|
|
|
#self.sfile.write('<text:p text:style-name="S-Header">')
|
|
|
|
#self.sfile.write(' TITRE : %s' % self.title) # How to get the document title here ?
|
|
|
|
#self.sfile.write('</text:p>')
|
|
|
|
#self.sfile.write('</style:header>')
|
|
|
|
# footer
|
|
|
|
#self.sfile.write('<style:footer>')
|
|
|
|
#self.sfile.write('<text:p text:style-name="S-Footer">')
|
|
|
|
#self.sfile.write('<text:page-number text:select-page="current">1')
|
|
|
|
#self.sfile.write('</text:page-number>/')
|
|
|
|
#self.sfile.write('<text:page-count>1')
|
|
|
|
#self.sfile.write('</text:page-count>')
|
|
|
|
#self.sfile.write('</text:p>')
|
|
|
|
#self.sfile.write('</style:footer>')
|
|
|
|
#
|
|
|
|
self.sfile.write('</style:master-page>')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.sfile.write('</office:master-styles>\n')
|
|
|
|
self.sfile.write('</office:document-styles>\n')
|
|
|
|
|
|
|
|
def page_break(self):
|
|
|
|
self.new_page = 1
|
|
|
|
|
|
|
|
def start_page(self):
|
|
|
|
self.cntnt.write('<text:p text:style-name="docgen_page_break">\n')
|
|
|
|
|
|
|
|
def end_page(self):
|
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def start_paragraph(self, style_name, leader=None):
|
2007-04-23 17:16:26 +05:30
|
|
|
style_sheet = self.get_style_sheet()
|
|
|
|
style = style_sheet.get_paragraph_style(style_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.level = style.get_header_level()
|
|
|
|
if self.new_page == 1:
|
|
|
|
self.new_page = 0
|
|
|
|
name = "NL%s" % style_name
|
|
|
|
else:
|
|
|
|
name = style_name
|
|
|
|
if self.level == 0:
|
|
|
|
self.cntnt.write('<text:p text:style-name="%s">' % name)
|
|
|
|
else:
|
|
|
|
self.cntnt.write('<text:h text:style-name="')
|
|
|
|
self.cntnt.write(name)
|
2006-04-21 04:31:35 +05:30
|
|
|
self.cntnt.write('" text:outline-level="' + str(self.level) + '">')
|
2008-06-16 20:31:46 +05:30
|
|
|
if leader is not None:
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write(leader)
|
2006-04-21 04:31:35 +05:30
|
|
|
self.cntnt.write('<text:tab/>')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.new_cell = 0
|
|
|
|
|
|
|
|
def end_paragraph(self):
|
|
|
|
if self.level == 0:
|
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
else:
|
|
|
|
self.cntnt.write('</text:h>\n')
|
|
|
|
self.new_cell = 1
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def write_note(self, text, format, style_name):
|
2006-03-01 01:24:35 +05:30
|
|
|
if format == 1:
|
2007-09-12 20:32:03 +05:30
|
|
|
text = escape(text, _esc_map)
|
2006-03-01 01:24:35 +05:30
|
|
|
# Replace multiple spaces: have to go from the largest number down
|
2007-09-12 20:32:03 +05:30
|
|
|
for n in range(text.count(' '), 1, -1):
|
2006-03-01 01:24:35 +05:30
|
|
|
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">')
|
2007-07-09 03:47:45 +05:30
|
|
|
self.cntnt.write(text)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('</text:span>')
|
|
|
|
self.end_paragraph()
|
|
|
|
elif format == 0:
|
|
|
|
for line in text.split('\n\n'):
|
|
|
|
self.start_paragraph(style_name)
|
2007-09-12 20:32:03 +05:30
|
|
|
line = line.replace('\n', ' ')
|
2006-03-01 01:24:35 +05:30
|
|
|
line = ' '.join(line.split())
|
|
|
|
self.write_text(line)
|
|
|
|
self.end_paragraph()
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def write_text(self, text, mark=None):
|
2006-03-01 01:24:35 +05:30
|
|
|
"""
|
|
|
|
Uses the xml.sax.saxutils.escape function to convert XML
|
|
|
|
entities. The _esc_map dictionary allows us to add our own
|
|
|
|
mappings.
|
|
|
|
"""
|
2006-06-03 09:02:26 +05:30
|
|
|
if mark:
|
2007-09-12 20:32:03 +05:30
|
|
|
key = escape(mark.key, _esc_map)
|
|
|
|
key = key.replace('"', '"')
|
2006-06-03 09:02:26 +05:30
|
|
|
if mark.type == BaseDoc.INDEX_TYPE_ALP:
|
|
|
|
self.cntnt.write('<text:alphabetical-index-mark ')
|
2006-06-04 09:56:28 +05:30
|
|
|
self.cntnt.write('text:string-value="%s" />' % key)
|
2006-06-03 09:02:26 +05:30
|
|
|
elif mark.type == BaseDoc.INDEX_TYPE_TOC:
|
|
|
|
self.cntnt.write('<text:toc-mark ')
|
2006-06-04 09:56:28 +05:30
|
|
|
self.cntnt.write('text:string-value="%s" ' % key)
|
|
|
|
self.cntnt.write('text:outline-level="%d" />' % mark.level)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write(escape(text, _esc_map))
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
def _write_manifest(self):
|
|
|
|
self.mfile = StringIO()
|
|
|
|
|
|
|
|
self.mfile.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.mfile.write('<manifest:manifest ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.mfile.write('xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.mfile.write('<manifest:file-entry ')
|
|
|
|
self.mfile.write('manifest:media-type="%s" ' % _apptype)
|
|
|
|
self.mfile.write('manifest:full-path="/"/>')
|
|
|
|
for image in self.media_list:
|
|
|
|
self.mfile.write('<manifest:file-entry manifest:media-type="" ')
|
|
|
|
self.mfile.write('manifest:full-path="Pictures/')
|
2008-04-06 09:11:22 +05:30
|
|
|
self.mfile.write(image[1])
|
2006-03-01 01:24:35 +05:30
|
|
|
self.mfile.write('"/>')
|
|
|
|
self.mfile.write('<manifest:file-entry manifest:media-type="" ')
|
|
|
|
self.mfile.write('manifest:full-path="Pictures/"/>')
|
|
|
|
self.mfile.write('<manifest:file-entry manifest:media-type="text/xml" ')
|
|
|
|
self.mfile.write('manifest:full-path="content.xml"/>')
|
|
|
|
self.mfile.write('<manifest:file-entry manifest:media-type="text/xml" ')
|
|
|
|
self.mfile.write('manifest:full-path="styles.xml"/>')
|
|
|
|
self.mfile.write('<manifest:file-entry manifest:media-type="text/xml" ')
|
|
|
|
self.mfile.write('manifest:full-path="meta.xml"/>')
|
|
|
|
self.mfile.write('</manifest:manifest>\n')
|
|
|
|
|
|
|
|
def _write_mimetype_file(self):
|
|
|
|
self.mimetype = StringIO()
|
|
|
|
self.mimetype.write('application/vnd.oasis.opendocument.text')
|
|
|
|
|
|
|
|
def _write_meta_file(self):
|
|
|
|
self.meta = StringIO()
|
|
|
|
|
|
|
|
self.meta.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.meta.write('<office:document-meta ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.meta.write('xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
|
|
|
|
self.meta.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.meta.write('xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('office:version="1.0">\n');
|
|
|
|
self.meta.write('<office:meta>\n')
|
|
|
|
self.meta.write('<meta:generator>')
|
2007-09-08 11:24:02 +05:30
|
|
|
self.meta.write(const.PROGRAM_NAME + ' ' + const.VERSION)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('</meta:generator>\n')
|
|
|
|
self.meta.write('<dc:title>')
|
2006-06-20 02:18:28 +05:30
|
|
|
# It should be reasonable to have a true document title. but how ?
|
|
|
|
# self.title ?
|
|
|
|
#self.meta.write(_("Summary of %s") % self.name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('</dc:title>\n')
|
|
|
|
self.meta.write('<dc:subject>')
|
2006-06-20 02:18:28 +05:30
|
|
|
#self.meta.write(_("Summary of %s") % name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('</dc:subject>\n')
|
|
|
|
self.meta.write('<dc:description>')
|
|
|
|
self.meta.write('</dc:description>\n')
|
|
|
|
self.meta.write('<meta:initial-creator>')
|
2007-04-30 07:26:34 +05:30
|
|
|
self.meta.write(self.get_creator())
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('</meta:initial-creator>\n')
|
|
|
|
self.meta.write('<meta:creation-date>')
|
|
|
|
self.meta.write(self.time)
|
|
|
|
self.meta.write('</meta:creation-date>\n')
|
|
|
|
self.meta.write('<dc:creator>')
|
2007-04-30 07:26:34 +05:30
|
|
|
self.meta.write(self.get_creator())
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('</dc:creator>\n')
|
|
|
|
self.meta.write('<dc:date>')
|
|
|
|
self.meta.write(self.time)
|
|
|
|
self.meta.write('</dc:date>\n')
|
|
|
|
self.meta.write('<dc:keyword>')
|
|
|
|
self.meta.write('</dc:keyword>\n')
|
|
|
|
self.meta.write('<meta:print-date>0-00-00T00:00:00</meta:print-date>\n')
|
|
|
|
self.meta.write('<dc:language>%s</dc:language>\n' % self.lang)
|
|
|
|
self.meta.write('<meta:editing-cycles>1</meta:editing-cycles>\n')
|
|
|
|
self.meta.write('<meta:editing-duration>PT0S</meta:editing-duration>\n')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.meta.write('<meta:user-defined meta:name="Genealogical Research and Analysis Management Programming System">http://gramps-project.org')
|
|
|
|
self.meta.write('</meta:user-defined>\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.meta.write('<meta:user-defined meta:name="Info 1"/>\n')
|
|
|
|
self.meta.write('<meta:user-defined meta:name="Info 2"/>\n')
|
|
|
|
self.meta.write('<meta:user-defined meta:name="Info 3"/>\n')
|
|
|
|
self.meta.write('</office:meta>\n')
|
|
|
|
self.meta.write('</office:document-meta>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def rotate_text(self, style, text, x, y, angle):
|
2007-04-23 17:16:26 +05:30
|
|
|
style_sheet = self.get_style_sheet()
|
|
|
|
stype = style_sheet.get_draw_style(style)
|
2006-03-01 01:24:35 +05:30
|
|
|
pname = stype.get_paragraph_style()
|
2007-04-23 17:16:26 +05:30
|
|
|
p = style_sheet.get_paragraph_style(pname)
|
2006-03-01 01:24:35 +05:30
|
|
|
font = p.get_font()
|
|
|
|
size = font.get_size()
|
|
|
|
|
|
|
|
height = size*(len(text))
|
|
|
|
width = 0
|
|
|
|
for line in text:
|
2007-09-12 20:32:03 +05:30
|
|
|
width = max(width, FontScale.string_width(font, line))
|
2007-06-25 02:30:25 +05:30
|
|
|
wcm = ReportUtils.pt2cm(width)
|
|
|
|
hcm = ReportUtils.pt2cm(height)
|
2006-03-01 01:24:35 +05:30
|
|
|
|
2007-06-25 02:30:25 +05:30
|
|
|
rangle = (pi/180.0) * angle
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.cntnt.write('<draw:frame text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:z-index="2" ')
|
2007-06-25 02:30:25 +05:30
|
|
|
self.cntnt.write('draw:style-name="clear" ')
|
|
|
|
self.cntnt.write('svg:height="%.2fcm" ' % hcm)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('svg:width="%.2fcm" ' % wcm)
|
|
|
|
self.cntnt.write('draw:transform="')
|
2007-06-25 02:30:25 +05:30
|
|
|
self.cntnt.write('rotate (%.8f) ' % -rangle)
|
|
|
|
xloc = x-((wcm/2.0)*cos(rangle))+((hcm/2.0)*sin(rangle))
|
|
|
|
yloc = y-((hcm/2.0)*cos(rangle))-((wcm/2.0)*sin(rangle))
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write('translate (%.3fcm %.3fcm)">\n' % (xloc, yloc))
|
2007-04-23 17:16:26 +05:30
|
|
|
self.cntnt.write('<draw:text-box>\n')
|
|
|
|
self.cntnt.write('<text:p text:style-name="X%s">' % pname)
|
|
|
|
self.cntnt.write('<text:span text:style-name="F%s">' % pname)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write(escape('\n'.join(text), _esc_map))
|
2007-04-23 17:16:26 +05:30
|
|
|
self.cntnt.write('</text:span></text:p>\n</draw:text-box>\n')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('</draw:frame>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def draw_path(self, style, path):
|
2006-03-01 01:24:35 +05:30
|
|
|
minx = 9e12
|
|
|
|
miny = 9e12
|
|
|
|
maxx = 0
|
|
|
|
maxy = 0
|
|
|
|
|
|
|
|
for point in path:
|
2007-09-12 20:32:03 +05:30
|
|
|
minx = min(point[0], minx)
|
|
|
|
miny = min(point[1], miny)
|
|
|
|
maxx = max(point[0], maxx)
|
|
|
|
maxy = max(point[1], maxy)
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.cntnt.write('<draw:polygon draw:style-name="%s" draw:layer="layout" ' % style)
|
|
|
|
self.cntnt.write('draw:z-index="1" ')
|
|
|
|
x = int((minx)*1000)
|
|
|
|
y = int((miny)*1000)
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write('svg:x="%d" svg:y="%d" ' % (x, y))
|
|
|
|
self.cntnt.write('svg:viewBox="0 0 %d %d" ' % (int((maxx-minx)*1000), int((maxy-miny)*1000)))
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('svg:width="%.4fcm" ' % (maxx-minx))
|
|
|
|
self.cntnt.write('svg:height="%.4fcm" ' % (maxy-miny))
|
|
|
|
|
|
|
|
point = path[0]
|
|
|
|
x1 = int((point[0]-minx)*1000)
|
|
|
|
y1 = int((point[1]-miny)*1000)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write('draw:points="%d, %d' % (x1, y1))
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
for point in path[1:]:
|
|
|
|
x1 = int((point[0]-minx)*1000)
|
|
|
|
y1 = int((point[1]-miny)*1000)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write(' %d, %d' % (x1, y1))
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('"/>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def draw_line(self, style, x1, y1, x2, y2):
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<draw:line text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:z-index="3" ')
|
|
|
|
self.cntnt.write('draw:text-style-name="%s" ' % style )
|
|
|
|
self.cntnt.write('svg:x1="%.2fcm" ' % x1)
|
|
|
|
self.cntnt.write('svg:y1="%.2fcm" ' % y1)
|
|
|
|
self.cntnt.write('svg:x2="%.2fcm" ' % x2)
|
|
|
|
self.cntnt.write('svg:y2="%.2fcm">' % y2)
|
|
|
|
self.cntnt.write('<text:p/>\n')
|
|
|
|
self.cntnt.write('</draw:line>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def draw_text(self, style, text, x, y):
|
2007-04-23 17:16:26 +05:30
|
|
|
style_sheet = self.get_style_sheet()
|
|
|
|
box_style = style_sheet.get_draw_style(style)
|
2006-03-01 01:24:35 +05:30
|
|
|
para_name = box_style.get_paragraph_style()
|
2007-04-23 17:16:26 +05:30
|
|
|
pstyle = style_sheet.get_paragraph_style(para_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
font = pstyle.get_font()
|
2007-09-12 20:32:03 +05:30
|
|
|
sw = ReportUtils.pt2cm(FontScale.string_width(font, text))*1.3
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.cntnt.write('<draw:frame text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:z-index="2" ')
|
|
|
|
self.cntnt.write('draw:style-name="%s" ' % style)
|
|
|
|
self.cntnt.write('svg:width="%.2fcm" ' % sw)
|
2006-06-04 23:57:50 +05:30
|
|
|
self.cntnt.write('svg:height="%.2fcm" ' %
|
|
|
|
(ReportUtils.pt2cm(font.get_size()*1.4)))
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.cntnt.write('svg:x="%.2fcm" ' % float(x))
|
|
|
|
self.cntnt.write('svg:y="%.2fcm">' % float(y))
|
|
|
|
self.cntnt.write('<draw:text-box> ' )
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('<text:p text:style-name="F%s">' % para_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<text:span text:style-name="F%s"' % para_name)
|
|
|
|
self.cntnt.write(' fo:max-height="%.2f">' % font.get_size() )
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write(escape(text, _esc_map))
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('</text:span></text:p>')
|
|
|
|
self.cntnt.write('</draw:text-box>\n')
|
|
|
|
self.cntnt.write('</draw:frame>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def draw_box(self, style, text, x, y, w, h):
|
2007-04-23 17:16:26 +05:30
|
|
|
style_sheet = self.get_style_sheet()
|
|
|
|
box_style = style_sheet.get_draw_style(style)
|
2006-03-01 01:24:35 +05:30
|
|
|
para_name = box_style.get_paragraph_style()
|
|
|
|
shadow_width = box_style.get_shadow_space()
|
|
|
|
|
|
|
|
if box_style.get_shadow():
|
|
|
|
self.cntnt.write('<draw:rect text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:style-name="%s_shadow" ' % style)
|
|
|
|
self.cntnt.write('draw:z-index="0" ')
|
|
|
|
self.cntnt.write('draw:text-style-name="%s" ' % para_name)
|
2007-02-26 03:23:38 +05:30
|
|
|
self.cntnt.write('svg:width="%.2fcm" ' % w)
|
|
|
|
self.cntnt.write('svg:height="%.2fcm" ' % h)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('svg:x="%.2fcm" ' % (float(x)+shadow_width))
|
|
|
|
self.cntnt.write('svg:y="%.2fcm">\n' % (float(y)+shadow_width))
|
|
|
|
self.cntnt.write('</draw:rect>\n')
|
|
|
|
|
|
|
|
self.cntnt.write('<draw:rect text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:style-name="%s" ' % style)
|
|
|
|
self.cntnt.write('draw:text-style-name="%s" ' % para_name)
|
|
|
|
self.cntnt.write('draw:z-index="1" ')
|
2007-02-26 03:23:38 +05:30
|
|
|
self.cntnt.write('svg:width="%.2fcm" ' % w)
|
|
|
|
self.cntnt.write('svg:height="%.2fcm" ' % h)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('svg:x="%.2fcm" ' % float(x))
|
|
|
|
self.cntnt.write('svg:y="%.2fcm">\n' % float(y))
|
|
|
|
if text != "":
|
|
|
|
self.cntnt.write('<text:p text:style-name="%s">' % para_name)
|
|
|
|
self.cntnt.write('<text:span text:style-name="F%s">' % para_name)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write(escape(text, _esc_map))
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('</text:span>')
|
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
self.cntnt.write('</draw:rect>\n')
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
def center_text(self, style, text, x, y):
|
2007-04-23 17:16:26 +05:30
|
|
|
style_sheet = self.get_style_sheet()
|
|
|
|
box_style = style_sheet.get_draw_style(style)
|
2006-03-01 01:24:35 +05:30
|
|
|
para_name = box_style.get_paragraph_style()
|
2007-04-23 17:16:26 +05:30
|
|
|
pstyle = style_sheet.get_paragraph_style(para_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
font = pstyle.get_font()
|
|
|
|
|
2007-09-12 20:32:03 +05:30
|
|
|
size = (FontScale.string_width(font, text)/72.0) * 2.54
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
self.cntnt.write('<draw:frame text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:style-name="%s" ' % style)
|
2007-02-27 09:40:43 +05:30
|
|
|
self.cntnt.write('draw:z-index="2" ')
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('svg:width="%.2fcm" ' % size)
|
|
|
|
self.cntnt.write('svg:height="%.2fpt" ' % font.get_size())
|
|
|
|
|
|
|
|
self.cntnt.write('svg:x="%.2fcm" ' % (x-(size/2.0)))
|
|
|
|
self.cntnt.write('svg:y="%.2fcm">\n' % float(y))
|
|
|
|
|
|
|
|
if text != "":
|
|
|
|
self.cntnt.write('<draw:text-box>')
|
2006-06-20 02:18:28 +05:30
|
|
|
self.cntnt.write('<text:p text:style-name="X%s">' % para_name)
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('<text:span text:style-name="F%s">' % para_name)
|
2007-09-12 20:32:03 +05:30
|
|
|
self.cntnt.write(escape(text, _esc_map))
|
2006-03-01 01:24:35 +05:30
|
|
|
self.cntnt.write('</text:span>\n')
|
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
self.cntnt.write('</draw:text-box>')
|
|
|
|
self.cntnt.write('</draw:frame>\n')
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register plugins
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------------
|
|
|
|
print_label = None
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
2006-03-01 01:24:35 +05:30
|
|
|
try:
|
2006-03-03 05:53:04 +05:30
|
|
|
mprog = Mime.get_application(_apptype)
|
2006-03-01 01:24:35 +05:30
|
|
|
|
|
|
|
if Utils.search_for(mprog[0]):
|
|
|
|
print_label = _("Open in %(program_name)s") % { 'program_name':
|
|
|
|
mprog[1]}
|
|
|
|
else:
|
|
|
|
print_label = None
|
|
|
|
except:
|
2006-11-26 01:46:55 +05:30
|
|
|
print_label = None
|
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr.register_text_doc(_('Open Document Text'),
|
2008-05-20 08:49:58 +05:30
|
|
|
ODFDoc, 1, 1, ".odt", print_label)
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr.register_book_doc(_("Open Document Text"),
|
2008-05-20 08:49:58 +05:30
|
|
|
ODFDoc, 1, 1, ".odt", print_label)
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr.register_draw_doc(_("Open Document Text"),
|
|
|
|
ODFDoc, 1, 1, ".odt", print_label);
|