2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-11 06:42:06 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2002-10-20 19:55:16 +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.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-12-13 11:29:35 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
2003-01-06 10:44:49 +05:30
|
|
|
import zipfile
|
|
|
|
import time
|
2004-10-26 08:50:38 +05:30
|
|
|
from cStringIO import StringIO
|
2003-09-14 10:20:44 +05:30
|
|
|
from math import pi, cos, sin, fabs
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-03-11 06:42:06 +05:30
|
|
|
from xml.sax.saxutils import escape
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-08-24 02:40:21 +05:30
|
|
|
import BaseDoc
|
2002-10-20 19:55:16 +05:30
|
|
|
import const
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import ReportUtils, \
|
|
|
|
register_text_doc, register_draw_doc, register_book_doc
|
|
|
|
pt2cm = ReportUtils.pt2cm
|
2002-10-20 19:55:16 +05:30
|
|
|
import ImgManip
|
2003-08-25 08:43:52 +05:30
|
|
|
import FontScale
|
2006-03-03 05:53:04 +05:30
|
|
|
import Mime
|
2005-12-13 07:37:16 +05:30
|
|
|
import Utils
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2006-03-11 06:42:06 +05:30
|
|
|
# constants
|
2003-01-06 10:44:49 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-01-13 10:35:39 +05:30
|
|
|
_apptype = 'application/vnd.sun.xml.writer'
|
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
_esc_map = {
|
|
|
|
'\x1a' : '',
|
|
|
|
'\x0c' : '',
|
|
|
|
'\n' : '<text:line-break/>',
|
|
|
|
'<super>' : '<text:span text:style-name="GSuper">',
|
|
|
|
'</super>' : '</text:span>',
|
|
|
|
}
|
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# OpenOfficeDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-08-24 02:40:21 +05:30
|
|
|
class OpenOfficeDoc(BaseDoc.BaseDoc):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
def __init__(self,styles,type,template,orientation=BaseDoc.PAPER_PORTRAIT):
|
|
|
|
BaseDoc.BaseDoc.__init__(self,styles,type,template,orientation)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt = None
|
2002-10-20 19:55:16 +05:30
|
|
|
self.filename = None
|
|
|
|
self.level = 0
|
|
|
|
self.time = "0000-00-00T00:00:00"
|
|
|
|
self.new_page = 0
|
2003-06-13 09:37:13 +05:30
|
|
|
self.new_cell = 0
|
2003-08-24 02:40:21 +05:30
|
|
|
self.page = 0
|
|
|
|
self.first_page = 1
|
|
|
|
|
|
|
|
def set_mode(self, mode):
|
|
|
|
self.mode = mode
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def open(self,filename):
|
|
|
|
t = time.localtime(time.time())
|
|
|
|
self.time = "%04d-%02d-%02dT%02d:%02d:%02d" % \
|
|
|
|
(t[0],t[1],t[2],t[3],t[4],t[5])
|
|
|
|
|
|
|
|
if filename[-4:] != ".sxw":
|
|
|
|
self.filename = filename + ".sxw"
|
|
|
|
else:
|
|
|
|
self.filename = filename
|
2003-01-29 10:13:12 +05:30
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.filename = os.path.normpath(os.path.abspath(self.filename))
|
|
|
|
self.cntnt = StringIO()
|
2003-09-13 10:26:04 +05:30
|
|
|
|
|
|
|
def init(self):
|
2004-10-14 09:39:38 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
assert (not self.init_called)
|
2005-01-20 09:41:13 +05:30
|
|
|
self.init_called = True
|
|
|
|
|
2005-12-13 07:37:16 +05:30
|
|
|
self.lang = Utils.xml_lang()
|
2004-10-14 09:39:38 +05:30
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.cntnt.write('<office:document-content ')
|
|
|
|
self.cntnt.write('xmlns:office="http://openoffice.org/2000/office" ')
|
|
|
|
self.cntnt.write('xmlns:style="http://openoffice.org/2000/style" ')
|
|
|
|
self.cntnt.write('xmlns:text="http://openoffice.org/2000/text" ')
|
|
|
|
self.cntnt.write('xmlns:table="http://openoffice.org/2000/table" ')
|
|
|
|
self.cntnt.write('xmlns:draw="http://openoffice.org/2000/drawing" ')
|
|
|
|
self.cntnt.write('xmlns:fo="http://www.w3.org/1999/XSL/Format" ')
|
|
|
|
self.cntnt.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
|
|
|
|
self.cntnt.write('xmlns:number="http://openoffice.org/2000/datastyle" ')
|
|
|
|
self.cntnt.write('xmlns:svg="http://www.w3.org/2000/svg" ')
|
|
|
|
self.cntnt.write('xmlns:chart="http://openoffice.org/2000/chart" ')
|
|
|
|
self.cntnt.write('xmlns:dr3d="http://openoffice.org/2000/dr3d" ')
|
|
|
|
self.cntnt.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
|
|
|
|
self.cntnt.write('xmlns:form="http://openoffice.org/2000/form" ')
|
|
|
|
self.cntnt.write('xmlns:script="http://openoffice.org/2000/script" ')
|
|
|
|
self.cntnt.write('office:class="text" office:version="0.9">\n')
|
|
|
|
self.cntnt.write('<office:script/>\n')
|
|
|
|
self.cntnt.write('<office:font-decls>\n')
|
|
|
|
self.cntnt.write('<style:font-decl style:name="Courier" fo:font-family="Courier" ')
|
|
|
|
self.cntnt.write('style:font-family-generic="modern" style:font-pitch="fixed"/>\n')
|
|
|
|
self.cntnt.write('<style:font-decl style:name="Times New Roman" ')
|
|
|
|
self.cntnt.write('fo: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-decl style:name="Arial" ')
|
|
|
|
self.cntnt.write('fo:font-family="Arial" ')
|
|
|
|
self.cntnt.write('style:font-family-generic="swiss" ')
|
|
|
|
self.cntnt.write('style:font-pitch="variable"/>\n')
|
|
|
|
self.cntnt.write('</office:font-decls>\n')
|
|
|
|
self.cntnt.write('<office:automatic-styles>\n')
|
|
|
|
self.cntnt.write('<style:style style:name="docgen_page_break" style:family="paragraph">\n')
|
|
|
|
self.cntnt.write('<style: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: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:properties style:font-name="Courier"/>')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2003-06-14 07:48:55 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
for style_name in self.draw_styles.keys():
|
2003-08-24 02:40:21 +05:30
|
|
|
style = self.draw_styles[style_name]
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style:style style:name="%s"' % style_name)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write(' style:family="graphics">\n')
|
|
|
|
self.cntnt.write('<style:properties ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('draw:fill="solid" ')
|
|
|
|
self.cntnt.write('draw:fill-color="#%02x%02x%02x" ' % style.get_fill_color())
|
2003-09-13 10:26:04 +05:30
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
if style.get_line_style() == BaseDoc.DASHED:
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write('svg:stroke-color="#cccccc" ')
|
2003-08-24 02:40:21 +05:30
|
|
|
else:
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write('svg:stroke-color="#%02x%02x%02x" ' % style.get_color())
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
if style.get_line_width():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('draw:stroke="solid" ')
|
2003-08-24 02:40:21 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('draw:stroke="none" ')
|
|
|
|
self.cntnt.write('draw:shadow="hidden" ')
|
|
|
|
self.cntnt.write('style:run-through="background" ')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2004-10-26 08:50:38 +05:30
|
|
|
|
|
|
|
self.cntnt.write('<style:style style:name="%s_shadow"' % style_name)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write(' style:family="graphics">\n')
|
|
|
|
self.cntnt.write('<style:properties ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('draw:fill="solid" ')
|
|
|
|
self.cntnt.write('draw:fill-color="#cccccc" ')
|
|
|
|
self.cntnt.write('draw:stroke="none" ')
|
|
|
|
self.cntnt.write('style:run-through="background" ')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
for style_name in self.style_list.keys():
|
2005-01-31 11:01:30 +05:30
|
|
|
style = self.style_list[style_name]
|
2004-10-26 08:50:38 +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: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('style:parent-style-name="Standard" ')
|
|
|
|
self.cntnt.write('style:class="text">\n')
|
|
|
|
self.cntnt.write('<style:properties ')
|
2003-09-13 10:26:04 +05:30
|
|
|
|
|
|
|
if style.get_padding() != 0.0:
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('fo:padding="%.3fcm" ' % style.get_padding())
|
2003-09-13 10:26:04 +05:30
|
|
|
if style.get_header_level() > 0:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:keep-with-next="true" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
|
|
|
|
align = style.get_alignment()
|
2005-01-31 11:01:30 +05:30
|
|
|
if align == BaseDoc.PARA_ALIGN_LEFT:
|
|
|
|
self.cntnt.write('fo:text-align="start" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_RIGHT:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:text-align="end" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_CENTER:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:text-align="center" ')
|
|
|
|
self.cntnt.write('style:justify-single-word="false" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:text-align="justify" ')
|
|
|
|
self.cntnt.write('style:justify-single-word="false" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
font = style.get_font()
|
|
|
|
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('style:font-name="Arial" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('style:font-name="Times New Roman" ')
|
2005-12-06 12:08:09 +05:30
|
|
|
self.cntnt.write('fo:font-size="%.3fpt" ' % font.get_size())
|
|
|
|
self.cntnt.write('style:font-size-asian="%.3fpt" '
|
|
|
|
% font.get_size())
|
2003-09-13 10:26:04 +05:30
|
|
|
color = font.get_color()
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('fo:color="#%02x%02x%02x" ' % color)
|
2003-09-13 10:26:04 +05:30
|
|
|
if font.get_bold():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:font-weight="bold" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
if font.get_italic():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:font-style="italic" ')
|
2005-01-31 11:01:30 +05:30
|
|
|
if font.get_underline():
|
|
|
|
self.cntnt.write('style:text-underline="single" ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('style:text-underline-color="font-color" ')
|
2005-12-06 12:08:09 +05:30
|
|
|
self.cntnt.write('fo:text-indent="%.2fcm" '
|
|
|
|
% style.get_first_indent())
|
|
|
|
self.cntnt.write('fo:margin-right="%.2fcm" '
|
|
|
|
% style.get_right_margin())
|
|
|
|
self.cntnt.write('fo:margin-left="%.2fcm" '
|
|
|
|
% style.get_left_margin())
|
|
|
|
self.cntnt.write('fo:margin-top="%.2fcm" '
|
|
|
|
% style.get_top_margin())
|
|
|
|
self.cntnt.write('fo:margin-bottom="%.2fcm"'
|
|
|
|
% style.get_bottom_margin())
|
2004-10-26 08:50:38 +05:30
|
|
|
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:properties ')
|
2003-09-13 10:26:04 +05:30
|
|
|
align = style.get_alignment()
|
2005-01-31 11:01:30 +05:30
|
|
|
if align == BaseDoc.PARA_ALIGN_LEFT:
|
|
|
|
self.cntnt.write('fo:text-align="start" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_RIGHT:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:text-align="end" ')
|
2003-09-13 10:26:04 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_CENTER:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:text-align="center" ')
|
2003-08-25 08:43:52 +05:30
|
|
|
font = style.get_font()
|
|
|
|
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('style:font-name="Arial" ')
|
2003-08-25 08:43:52 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('style:font-name="Times New Roman" ')
|
2003-09-02 08:58:27 +05:30
|
|
|
color = font.get_color()
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('fo:color="#%02x%02x%02x" ' % color)
|
2003-09-02 08:58:27 +05:30
|
|
|
if font.get_bold():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:font-weight="bold" ')
|
2003-09-02 08:58:27 +05:30
|
|
|
if font.get_italic():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('fo:font-style="italic" ')
|
2005-12-06 12:08:09 +05:30
|
|
|
self.cntnt.write('fo:font-size="%.3fpt" ' % font.get_size())
|
|
|
|
self.cntnt.write('style:font-size-asian="%.3fpt"/> ' % font.get_size())
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</style:style>\n')
|
2003-09-13 10:26:04 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
for style_name in self.table_styles.keys():
|
|
|
|
style = self.table_styles[style_name]
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style:style style:name="%s" ' % style_name)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('style:family="table">\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
table_width = float(self.get_usable_width())
|
|
|
|
table_width_str = "%.4f" % table_width
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('<style:properties style:width="%scm" '%table_width_str)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2005-01-31 11:01:30 +05:30
|
|
|
for col in range(0,style.get_columns()):
|
|
|
|
self.cntnt.write('<style:style style:name="')
|
|
|
|
self.cntnt.write(style_name + '.' + str(chr(ord('A')+col)) +'" ')
|
|
|
|
self.cntnt.write('style:family="table-column">')
|
2002-10-20 19:55:16 +05:30
|
|
|
width = table_width * float(style.get_column_width(col)/100.0)
|
|
|
|
width_str = "%.4f" % width
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('<style:properties ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('style:column-width="%scm"/>' % width_str)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('</style:style>\n')
|
2003-08-25 08:43:52 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
for cell in self.cell_styles.keys():
|
|
|
|
cell_style = self.cell_styles[cell]
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style:style style:name="%s" ' % cell)
|
|
|
|
self.cntnt.write('style:family="table-cell">\n')
|
|
|
|
self.cntnt.write('<style:properties')
|
|
|
|
self.cntnt.write(' fo:padding="%.3fcm"' % cell_style.get_padding())
|
2002-10-20 19:55:16 +05:30
|
|
|
if cell_style.get_top_border():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-top="0.002cm solid #000000"')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-top="none"')
|
2002-10-20 19:55:16 +05:30
|
|
|
if cell_style.get_bottom_border():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-bottom="0.002cm solid #000000"')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-bottom="none"')
|
2002-10-20 19:55:16 +05:30
|
|
|
if cell_style.get_left_border():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-left="0.002cm solid #000000"')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-left="none"')
|
2002-10-20 19:55:16 +05:30
|
|
|
if cell_style.get_right_border():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-right="0.002cm solid #000000"')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' fo:border-right="none"')
|
|
|
|
self.cntnt.write('/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-05-28 20:40:47 +05:30
|
|
|
self.cntnt.write('<style:style style:name="wraprow" style:family="table-row">\n')
|
|
|
|
self.cntnt.write('<style:properties style:keep-together="true" />\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style:style style:name="Tbold" style:family="text">\n')
|
|
|
|
self.cntnt.write('<style:properties fo:font-weight="bold"/>\n')
|
|
|
|
self.cntnt.write('</style:style>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#Begin photo style
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style:style style:name="Left" style:family="graphics"')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write(' style:parent-style-name="photo">')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style:properties style:run-through="foreground"')
|
2006-05-02 02:41:26 +05:30
|
|
|
self.cntnt.write(' style:wrap="dynamic"')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write(' style:number-wrapped-paragraphs="no-limit"')
|
2004-10-26 08:50:38 +05:30
|
|
|
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="graphics"')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write(' style:parent-style-name="photo">')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style:properties style:run-through="foreground"')
|
2006-04-10 09:59:29 +05:30
|
|
|
self.cntnt.write(' style:wrap="dynamic"')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write(' style:number-wrapped-paragraphs="no-limit"')
|
2004-10-26 08:50:38 +05:30
|
|
|
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="graphics"')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write(' style:parent-style-name="Graphics">')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style: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="graphics"')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write(' style:parent-style-name="Graphics">')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<style: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')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#end of Photo style edits
|
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</office:automatic-styles>\n')
|
|
|
|
self.cntnt.write('<office:body>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def close(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</office:body>\n')
|
|
|
|
self.cntnt.write('</office:document-content>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
self._write_styles_file()
|
|
|
|
self._write_manifest()
|
|
|
|
self._write_meta_file()
|
|
|
|
self._write_zip()
|
2003-08-05 22:31:47 +05:30
|
|
|
if self.print_req:
|
2006-03-03 05:53:04 +05:30
|
|
|
app = Mime.get_application(_apptype)
|
2003-08-05 22:31:47 +05:30
|
|
|
os.environ["FILE"] = self.filename
|
2004-04-04 10:09:52 +05:30
|
|
|
os.system ('%s "$FILE" &' % app[0])
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def add_media_object(self,name,pos,x_cm,y_cm):
|
2003-10-27 09:18:13 +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)
|
|
|
|
try:
|
|
|
|
image = ImgManip.ImgManip(name)
|
|
|
|
(x,y) = image.size()
|
|
|
|
ratio = float(x_cm)*float(y)/(float(y_cm)*float(x))
|
|
|
|
except:
|
|
|
|
return
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if ratio < 1:
|
|
|
|
act_width = x_cm
|
|
|
|
act_height = y_cm*ratio
|
|
|
|
else:
|
|
|
|
act_height = y_cm
|
|
|
|
act_width = x_cm/ratio
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
media_list_item = (name,act_width,act_height)
|
|
|
|
if not media_list_item in self.media_list:
|
|
|
|
self.media_list.append(media_list_item)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
base = os.path.basename(name)
|
2004-10-14 09:39:38 +05:30
|
|
|
tag = base.replace('.','_')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-06-13 09:37:13 +05:30
|
|
|
if self.new_cell:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<text:p>')
|
2002-10-20 19:55:16 +05:30
|
|
|
if pos == "left":
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<draw:image draw:style-name="Left" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
elif pos == "right":
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<draw:image draw:style-name="Right" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
elif pos == "single":
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<draw:image draw:style-name="Single" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<draw:image draw:style-name="Row" ')
|
|
|
|
|
|
|
|
self.cntnt.write('draw:name="%s" ' % tag)
|
|
|
|
self.cntnt.write('text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('svg:width="%.3fcm" ' % act_width)
|
|
|
|
self.cntnt.write('svg:height="%.3fcm" ' % act_height)
|
|
|
|
self.cntnt.write('draw:z-index="0" ')
|
|
|
|
self.cntnt.write('xlink:href="#Pictures/')
|
|
|
|
self.cntnt.write(base)
|
|
|
|
self.cntnt.write('" xlink:type="simple" xlink:show="embed" ')
|
|
|
|
self.cntnt.write('xlink:actuate="onLoad"/>\n')
|
2003-06-13 09:37:13 +05:30
|
|
|
if self.new_cell:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:p>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def start_table(self,name,style_name):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<table:table table:name="%s" ' % name)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('table:style-name="%s">\n' % style_name)
|
|
|
|
table = self.table_styles[style_name]
|
|
|
|
for col in range(0,table.get_columns()):
|
|
|
|
self.cntnt.write('<table:table-column table:style-name="')
|
|
|
|
self.cntnt.write(style_name + '.' + str(chr(ord('A')+col)) +'"/>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def end_table(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</table:table>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def start_row(self):
|
2006-05-28 20:40:47 +05:30
|
|
|
self.cntnt.write('<table:table-row table:style-name="wraprow">\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def end_row(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</table:table-row>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def start_cell(self,style_name,span=1):
|
2005-01-31 11:01:30 +05:30
|
|
|
self.span = span
|
|
|
|
self.cntnt.write('<table:table-cell table:style-name="%s" ' % style_name)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('table:value-type="string"')
|
2002-10-20 19:55:16 +05:30
|
|
|
if span > 1:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' table:number-columns-spanned="%s">\n' % span)
|
2005-01-31 11:01:30 +05:30
|
|
|
else:
|
|
|
|
self.cntnt.write('>\n')
|
2003-06-13 09:37:13 +05:30
|
|
|
self.new_cell = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def end_cell(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</table:table-cell>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
for col in range(1,self.span):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<table:covered-table-cell/>\n')
|
2003-06-13 09:37:13 +05:30
|
|
|
self.new_cell = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def start_bold(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<text:span text:style-name="Tbold">')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def end_bold(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:span>')
|
|
|
|
|
|
|
|
def _add_zip(self,zfile,name,data,t):
|
|
|
|
zipinfo = zipfile.ZipInfo(name.encode('latin-1'))
|
|
|
|
zipinfo.date_time = t
|
|
|
|
zipinfo.compress_type = zipfile.ZIP_DEFLATED
|
|
|
|
zfile.writestr(zipinfo,data)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def _write_zip(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
zfile = zipfile.ZipFile(self.filename,"w",zipfile.ZIP_DEFLATED)
|
|
|
|
|
|
|
|
t = time.localtime(time.time())[:6]
|
|
|
|
|
|
|
|
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.mfile.close()
|
|
|
|
self.cntnt.close()
|
|
|
|
self.meta.close()
|
|
|
|
self.sfile.close()
|
2003-01-06 10:44:49 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
for image in self.media_list:
|
2004-10-26 08:50:38 +05:30
|
|
|
try:
|
2006-04-05 10:11:56 +05:30
|
|
|
ifile = open(image[0],mode='rb')
|
2004-10-26 08:50:38 +05:30
|
|
|
base = os.path.basename(image[0])
|
|
|
|
self._add_zip(zfile,"Pictures/%s" % base, ifile.read(),t)
|
|
|
|
ifile.close()
|
|
|
|
except:
|
|
|
|
print "Could not open %s" % image[0]
|
|
|
|
zfile.close()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def _write_styles_file(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile = StringIO()
|
2003-05-21 04:50:47 +05:30
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.sfile.write('<office:document-styles ')
|
|
|
|
self.sfile.write('xmlns:office="http://openoffice.org/2000/office" ')
|
|
|
|
self.sfile.write('xmlns:style="http://openoffice.org/2000/style" ')
|
|
|
|
self.sfile.write('xmlns:text="http://openoffice.org/2000/text" ')
|
|
|
|
self.sfile.write('xmlns:table="http://openoffice.org/2000/table" ')
|
|
|
|
self.sfile.write('xmlns:draw="http://openoffice.org/2000/drawing" ')
|
|
|
|
self.sfile.write('xmlns:fo="http://www.w3.org/1999/XSL/Format" ')
|
|
|
|
self.sfile.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
|
|
|
|
self.sfile.write('xmlns:number="http://openoffice.org/2000/datastyle" ')
|
|
|
|
self.sfile.write('xmlns:svg="http://www.w3.org/2000/svg" ')
|
|
|
|
self.sfile.write('xmlns:chart="http://openoffice.org/2000/chart" ')
|
|
|
|
self.sfile.write('xmlns:dr3d="http://openoffice.org/2000/dr3d" ')
|
|
|
|
self.sfile.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
|
|
|
|
self.sfile.write('xmlns:form="http://openoffice.org/2000/form" ')
|
|
|
|
self.sfile.write('xmlns:script="http://openoffice.org/2000/script" ')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.sfile.write('office:version="0.9">\n')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('<office:font-decls>\n')
|
|
|
|
self.sfile.write('<style:font-decl style:name="Times New Roman" ')
|
|
|
|
self.sfile.write('fo:font-family="'Times New Roman'" ')
|
|
|
|
self.sfile.write('style:font-family-generic="roman" ')
|
|
|
|
self.sfile.write('style:font-pitch="variable"/>\n')
|
|
|
|
self.sfile.write('<style:font-decl style:name="Arial" ')
|
|
|
|
self.sfile.write('fo:font-family="Arial" ')
|
|
|
|
self.sfile.write('style:font-family-generic="swiss" ')
|
|
|
|
self.sfile.write('style:font-pitch="variable"/>\n')
|
|
|
|
self.sfile.write('</office:font-decls>\n')
|
|
|
|
self.sfile.write('<office:styles>\n')
|
|
|
|
self.sfile.write('<style:default-style style:family="paragraph">\n')
|
|
|
|
self.sfile.write('<style:properties style:font-name="Times New Roman" ')
|
|
|
|
self.sfile.write('style:font-pitch-asian="fixed" ')
|
|
|
|
self.sfile.write('style:font-pitch-complex="fixed" ')
|
|
|
|
self.sfile.write('style:tab-stop-distance="2.205cm"/>\n')
|
|
|
|
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="graphics">\n')
|
|
|
|
self.sfile.write('<style: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')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
for key in self.style_list.keys():
|
|
|
|
style = self.style_list[key]
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('<style:style style:name="%s" ' % key)
|
|
|
|
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:properties ')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if style.get_padding() != 0.0:
|
2005-01-31 11:01:30 +05:30
|
|
|
self.sfile.write('fo:padding="%.3fcm" ' % style.get_padding())
|
2005-12-06 12:08:09 +05:30
|
|
|
if style.get_top_border():
|
|
|
|
self.sfile.write('fo:border-top="0.002cm solid #000000" ')
|
|
|
|
if style.get_bottom_border():
|
|
|
|
self.sfile.write('fo:border-bottom="0.002cm solid #000000" ')
|
|
|
|
if style.get_right_border():
|
|
|
|
self.sfile.write('fo:border-right="0.002cm solid #000000" ')
|
|
|
|
if style.get_left_border():
|
|
|
|
self.sfile.write('fo:border-left="0.002cm solid #000000" ')
|
2003-07-21 08:58:14 +05:30
|
|
|
if style.get_header_level() > 0:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('fo:keep-with-next="true" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
align = style.get_alignment()
|
2005-01-31 11:01:30 +05:30
|
|
|
if align == BaseDoc.PARA_ALIGN_LEFT:
|
|
|
|
self.sfile.write('fo:text-align="start" ')
|
2003-08-24 02:40:21 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_RIGHT:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('fo:text-align="end" ')
|
2003-08-24 02:40:21 +05:30
|
|
|
elif align == BaseDoc.PARA_ALIGN_CENTER:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('fo:text-align="center" ')
|
|
|
|
self.sfile.write('style:justify-single-word="false" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('fo:text-align="justify" ')
|
|
|
|
self.sfile.write('style:justify-single-word="false" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
font = style.get_font()
|
2003-08-24 02:40:21 +05:30
|
|
|
if font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('style:font-name="Arial" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('style:font-name="Times New Roman" ')
|
2005-12-06 12:08:09 +05:30
|
|
|
self.sfile.write('fo:font-size="%.3fpt" ' % font.get_size())
|
2002-10-20 19:55:16 +05:30
|
|
|
color = font.get_color()
|
2005-01-31 11:01:30 +05:30
|
|
|
self.sfile.write('fo:color="#%02x%02x%02x" ' % color)
|
2002-10-20 19:55:16 +05:30
|
|
|
if font.get_bold():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('fo:font-weight="bold" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
if font.get_italic():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('fo:font-style="italic" ')
|
2005-01-31 11:01:30 +05:30
|
|
|
if font.get_underline():
|
|
|
|
self.sfile.write('style:text-underline="single" ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('style:text-underline-color="font-color" ')
|
2005-12-06 12:08:09 +05:30
|
|
|
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())
|
|
|
|
self.sfile.write('fo:margin-top="%.2fcm" '
|
|
|
|
% style.get_top_margin())
|
|
|
|
self.sfile.write('fo:margin-bottom="%.2fcm"'
|
|
|
|
% style.get_bottom_margin())
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('/>\n')
|
|
|
|
self.sfile.write('</style:style>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
# Current no leading number format for headers
|
|
|
|
|
|
|
|
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')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('</office:styles>\n')
|
|
|
|
self.sfile.write('<office:automatic-styles>\n')
|
|
|
|
self.sfile.write('<style:page-master style:name="pm1">\n')
|
|
|
|
self.sfile.write('<style:properties fo:page-width="%.3fcm" ' % self.width)
|
|
|
|
self.sfile.write('fo:page-height="%.3fcm" ' % self.height)
|
|
|
|
self.sfile.write('style:num-format="1" ')
|
2003-08-24 02:40:21 +05:30
|
|
|
if self.orientation == BaseDoc.PAPER_PORTRAIT:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('style:print-orientation="portrait" ')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('style:print-orientation="landscape" ')
|
|
|
|
self.sfile.write('fo:margin-top="%.2fcm" ' % self.tmargin)
|
|
|
|
self.sfile.write('fo:margin-bottom="%.2fcm" ' % self.bmargin)
|
|
|
|
self.sfile.write('fo:margin-left="%.2fcm" ' % self.lmargin)
|
|
|
|
self.sfile.write('fo:margin-right="%.2fcm" ' % self.rmargin)
|
|
|
|
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:properties>\n')
|
|
|
|
self.sfile.write('<style:header-style/>\n')
|
|
|
|
self.sfile.write('<style:footer-style/>\n')
|
|
|
|
self.sfile.write('</style:page-master>\n')
|
|
|
|
self.sfile.write('</office:automatic-styles>\n')
|
|
|
|
self.sfile.write('<office:master-styles>\n')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.sfile.write('<draw:layer-set>\n')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.sfile.write('<draw:layer draw:name="layout"/>\n')
|
|
|
|
self.sfile.write('<draw:layer draw:name="background"/>\n')
|
|
|
|
self.sfile.write('<draw:layer draw:name="backgroundobjects"/>\n')
|
|
|
|
self.sfile.write('<draw:layer draw:name="controls"/>\n')
|
|
|
|
self.sfile.write('<draw:layer draw:name="measurelines"/>\n')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.sfile.write('</draw:layer-set>\n')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.sfile.write('<style:master-page style:name="Standard" ')
|
|
|
|
self.sfile.write('style:page-master-name="pm1"/>\n')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.sfile.write('</office:master-styles>\n')
|
|
|
|
self.sfile.write('</office:document-styles>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-08-25 08:43:52 +05:30
|
|
|
def page_break(self):
|
|
|
|
self.new_page = 1
|
|
|
|
|
|
|
|
def start_page(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<text:p text:style-name="docgen_page_break">\n')
|
2003-08-25 08:43:52 +05:30
|
|
|
|
|
|
|
def end_page(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:p>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def start_paragraph(self,style_name,leader=None):
|
2005-01-31 11:01:30 +05:30
|
|
|
style = self.style_list[style_name]
|
|
|
|
self.level = style.get_header_level()
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.new_page == 1:
|
2003-08-24 02:40:21 +05:30
|
|
|
self.new_page = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
name = "NL%s" % style_name
|
|
|
|
else:
|
|
|
|
name = style_name
|
2005-01-31 11:01:30 +05:30
|
|
|
if self.level == 0:
|
|
|
|
self.cntnt.write('<text:p text:style-name="%s">' % name)
|
|
|
|
else:
|
|
|
|
self.cntnt.write('<text:h text:style-name="')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(name)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.cntnt.write('" text:level="%d">' % self.level)
|
2002-10-20 19:55:16 +05:30
|
|
|
if leader != None:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(leader)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.cntnt.write('<text:tab-stop/>')
|
2003-06-13 09:37:13 +05:30
|
|
|
self.new_cell = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def end_paragraph(self):
|
|
|
|
if self.level == 0:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:p>\n')
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:h>\n')
|
2003-06-13 09:37:13 +05:30
|
|
|
self.new_cell = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-12-13 11:29:35 +05:30
|
|
|
def write_note(self,text,format,style_name):
|
|
|
|
if format == 1:
|
|
|
|
text = text.replace('&','&') # Must be first
|
|
|
|
text = text.replace('<','<')
|
|
|
|
text = text.replace('>','>')
|
|
|
|
# Replace multiple spaces: have to go from the largest number down
|
|
|
|
for n in range(text.count(' '),1,-1):
|
|
|
|
text = text.replace(' '*n, ' <text:s text:c="%d"/>' % (n-1) )
|
|
|
|
text = text.replace('\n','<text:line-break/>')
|
|
|
|
text = text.replace('\t','<text:tab-stop/>')
|
2004-10-14 09:39:38 +05:30
|
|
|
text = text.replace('<super>',
|
|
|
|
'<text:span text:style-name="GSuper">')
|
2003-12-13 11:29:35 +05:30
|
|
|
text = text.replace('</super>','</text:span>')
|
|
|
|
|
|
|
|
self.start_paragraph(style_name)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<text:span text:style-name="GRAMPS-preformat">')
|
|
|
|
self.cntnt.write(text)
|
|
|
|
self.cntnt.write('</text:span>')
|
2003-12-13 11:29:35 +05:30
|
|
|
self.end_paragraph()
|
|
|
|
elif format == 0:
|
|
|
|
for line in text.split('\n\n'):
|
|
|
|
self.start_paragraph(style_name)
|
|
|
|
line = line.replace('\n',' ')
|
2005-01-19 10:17:36 +05:30
|
|
|
line = ' '.join(line.split())
|
2003-12-13 11:29:35 +05:30
|
|
|
self.write_text(line)
|
|
|
|
self.end_paragraph()
|
|
|
|
|
2006-05-29 08:22:14 +05:30
|
|
|
def write_text(self,text,key=""):
|
2005-08-18 11:28:28 +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-05-29 08:22:14 +05:30
|
|
|
|
|
|
|
if key != "":
|
|
|
|
key = escape(key,_esc_map)
|
|
|
|
key = key.replace('"','"')
|
|
|
|
self.cntnt.write('<text:alphabetical-index-mark ')
|
|
|
|
self.cntnt.write('text:string-value="%s" />' % key)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write(escape(text,_esc_map))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def _write_manifest(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.mfile = StringIO()
|
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.mfile.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.mfile.write('<manifest:manifest ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.mfile.write('xmlns:manifest="http://openoffice.org/2001/manifest">')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.mfile.write('<manifest:file-entry ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.mfile.write('manifest:media-type="application/vnd.sun.xml.writer" ')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.mfile.write('manifest:full-path="/"/>')
|
2004-02-21 11:41:59 +05:30
|
|
|
for image in self.media_list:
|
2002-10-20 19:55:16 +05:30
|
|
|
i = image[0]
|
|
|
|
base = os.path.basename(i)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.mfile.write('<manifest:file-entry manifest:media-type="" ')
|
|
|
|
self.mfile.write('manifest:full-path="Pictures/')
|
|
|
|
self.mfile.write(base)
|
|
|
|
self.mfile.write('"/>')
|
|
|
|
self.mfile.write('<manifest:file-entry manifest:media-type="" ')
|
2005-01-31 11:01:30 +05:30
|
|
|
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')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def _write_meta_file(self):
|
2004-10-26 08:50:38 +05:30
|
|
|
self.meta = StringIO()
|
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.meta.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
self.meta.write('<office:document-meta ')
|
|
|
|
self.meta.write('xmlns:office="http://openoffice.org/2000/office" ')
|
|
|
|
self.meta.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
|
|
|
|
self.meta.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
|
|
|
|
self.meta.write('xmlns:meta="http://openoffice.org/2000/meta" ')
|
2005-08-18 11:28:28 +05:30
|
|
|
self.meta.write('office:version="0.9">\n');
|
2005-01-31 11:01:30 +05:30
|
|
|
self.meta.write('<office:meta>\n')
|
|
|
|
self.meta.write('<meta:generator>')
|
2006-03-29 10:21:19 +05:30
|
|
|
self.meta.write(const.program_name + ' ' + const.version)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.meta.write('</meta:generator>\n')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.meta.write('<meta:initial-creator>')
|
|
|
|
self.meta.write(self.name)
|
|
|
|
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>')
|
|
|
|
self.meta.write(self.name)
|
|
|
|
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('<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')
|
|
|
|
self.meta.write('<meta:user-defined meta:name="Info 0"/>\n')
|
|
|
|
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')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
def rotate_text(self,style,text,x,y,angle):
|
|
|
|
|
|
|
|
stype = self.draw_styles[style]
|
|
|
|
pname = stype.get_paragraph_style()
|
|
|
|
p = self.style_list[pname]
|
2005-01-31 11:01:30 +05:30
|
|
|
font = p.get_font()
|
2003-08-24 02:40:21 +05:30
|
|
|
size = font.get_size()
|
|
|
|
|
|
|
|
height = size*(len(text))
|
2003-09-13 10:26:04 +05:30
|
|
|
oneline = (size/72.0)*2.54
|
2003-08-24 02:40:21 +05:30
|
|
|
width = 0
|
|
|
|
for line in text:
|
|
|
|
width = max(width,FontScale.string_width(font,line))
|
|
|
|
wcm = (width/72.0)*2.54
|
|
|
|
hcm = (height/72.0)*2.54
|
|
|
|
|
|
|
|
rangle = -((pi/180.0) * angle)
|
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<draw:text-box draw:style-name="%s" ' % style)
|
|
|
|
self.cntnt.write('draw:layer="layout" svg:width="%.3fcm" ' % wcm)
|
|
|
|
self.cntnt.write('svg:height="%.3fpt" ' % hcm)
|
|
|
|
self.cntnt.write('draw:transform="')
|
|
|
|
self.cntnt.write('rotate (%.8f) ' % rangle)
|
2003-08-25 08:43:52 +05:30
|
|
|
xloc = x-((wcm/2.0)*cos(-rangle))
|
2003-09-14 10:20:44 +05:30
|
|
|
yloc = y-((hcm)*sin(-rangle))-oneline
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('translate (%.3fcm %.3fcm)"' % (xloc,yloc))
|
|
|
|
self.cntnt.write('>')
|
|
|
|
self.cntnt.write('<text:p text:style-name="X%s">' % pname)
|
2003-09-13 10:26:04 +05:30
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<text:span text:style-name="F%s">\n' % pname)
|
2005-01-19 10:17:36 +05:30
|
|
|
self.write_text('\n'.join(text))
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:span>\n</text:p>\n</draw:text-box>\n')
|
2003-09-14 10:20:44 +05:30
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
def draw_path(self,style,path):
|
|
|
|
minx = 9e12
|
|
|
|
miny = 9e12
|
|
|
|
maxx = 0
|
|
|
|
maxy = 0
|
|
|
|
|
|
|
|
for point in path:
|
|
|
|
minx = min(point[0],minx)
|
|
|
|
miny = min(point[1],miny)
|
|
|
|
maxx = max(point[0],maxx)
|
|
|
|
maxy = max(point[1],maxy)
|
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<draw:polygon draw:style-name="%s" draw:layer="layout" ' % style)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('draw:z-index="1" ')
|
2003-08-25 08:43:52 +05:30
|
|
|
x = int((minx)*1000)
|
|
|
|
y = int((miny)*1000)
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:x="%d" svg:y="%d" ' % (x,y))
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write('svg:viewBox="0 0 %d %d" ' % (int((maxx-minx)*1000),int((maxy-miny)*1000)))
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:width="%.4fcm" ' % (maxx-minx))
|
|
|
|
self.cntnt.write('svg:height="%.4fcm" ' % (maxy-miny))
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
point = path[0]
|
|
|
|
x1 = int((point[0]-minx)*1000)
|
|
|
|
y1 = int((point[1]-miny)*1000)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('draw:points="%d,%d' % (x1,y1))
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
for point in path[1:]:
|
|
|
|
x1 = int((point[0]-minx)*1000)
|
|
|
|
y1 = int((point[1]-miny)*1000)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write(' %d,%d' % (x1,y1))
|
|
|
|
self.cntnt.write('"/>\n')
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def draw_line(self,style,x1,y1,x2,y2):
|
2005-08-18 11:28:28 +05:30
|
|
|
self.cntnt.write('<draw:line draw:style-name="%s" '% style)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:x1="%.3fcm" ' % x1)
|
|
|
|
self.cntnt.write('svg:y1="%.3fcm" ' % y1)
|
|
|
|
self.cntnt.write('svg:x2="%.3fcm" ' % x2)
|
|
|
|
self.cntnt.write('svg:y2="%.3fcm" ' % y2)
|
|
|
|
self.cntnt.write('/>\n')
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def draw_text(self,style,text,x,y):
|
2005-01-31 11:01:30 +05:30
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
para_name = box_style.get_paragraph_style()
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
pstyle = self.style_list[para_name]
|
|
|
|
font = pstyle.get_font()
|
2004-01-10 23:34:32 +05:30
|
|
|
if box_style.get_width():
|
|
|
|
sw = box_style.get_width()
|
|
|
|
else:
|
2004-08-21 02:56:51 +05:30
|
|
|
sw = pt2cm(FontScale.string_width(font,text))*1.3
|
2004-01-10 23:34:32 +05:30
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('<draw:text-box draw:style-name="%s" ' % style)
|
|
|
|
self.cntnt.write('draw:layer="layout" ')
|
2003-08-24 02:40:21 +05:30
|
|
|
# fix this
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('draw:z-index="0" ')
|
|
|
|
self.cntnt.write('svg:width="%.3fcm" ' % sw)
|
|
|
|
self.cntnt.write('svg:height="%.4fpt" ' % (font.get_size()*1.4))
|
2004-10-26 08:50:38 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('svg:x="%.3fcm" ' % float(x))
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:y="%.3fcm">' % float(y))
|
|
|
|
self.cntnt.write('<text:p text:style-name="X%s">' % para_name)
|
|
|
|
self.cntnt.write('<text:span text:style-name="F%s">' % para_name)
|
|
|
|
self.cntnt.write(text)
|
|
|
|
self.cntnt.write('</text:span></text:p>')
|
|
|
|
self.cntnt.write('</draw:text-box>\n')
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def draw_bar(self,style,x,y,x2,y2):
|
2005-01-31 11:01:30 +05:30
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
|
|
|
|
self.cntnt.write('<draw:rect text:anchor-type="paragraph" draw:style-name="')
|
|
|
|
self.cntnt.write(style)
|
|
|
|
self.cntnt.write('" draw:z-index="0" ')
|
|
|
|
self.cntnt.write('svg:width="%.3fcm" ' % float(x2-x))
|
|
|
|
self.cntnt.write('svg:height="%.3fcm" ' % float(y2-y))
|
|
|
|
self.cntnt.write('svg:x="%.3fcm" ' % float(x))
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:y="%.3fcm">' % float(y))
|
|
|
|
self.cntnt.write('</draw:rect>\n')
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def draw_box(self,style,text,x,y):
|
2005-01-31 11:01:30 +05:30
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
para_name = box_style.get_paragraph_style()
|
2004-01-09 08:46:48 +05:30
|
|
|
shadow_width = box_style.get_shadow_space()
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2004-01-10 08:07:07 +05:30
|
|
|
if box_style.get_shadow():
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<draw:rect text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:style-name="%s_shadow" ' % style)
|
|
|
|
self.cntnt.write('draw:text-style-name="%s" ' % para_name)
|
|
|
|
self.cntnt.write('draw:z-index="0" ')
|
|
|
|
self.cntnt.write('svg:width="%.3fcm" ' % box_style.get_width())
|
|
|
|
self.cntnt.write('svg:height="%.3fcm" ' % box_style.get_height())
|
|
|
|
self.cntnt.write('svg:x="%.3fcm" ' % (float(x)+shadow_width))
|
|
|
|
self.cntnt.write('svg:y="%.3fcm">\n' % (float(y)+shadow_width))
|
|
|
|
self.cntnt.write('</draw:rect>\n')
|
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('<draw:rect text:anchor-type="paragraph" ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('draw:style-name="%s" ' % style)
|
|
|
|
self.cntnt.write('draw:text-style-name="%s" ' % para_name)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('draw:z-index="1" ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:width="%.3fcm" ' % box_style.get_width())
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('svg:height="%.3fcm" ' % box_style.get_height())
|
|
|
|
self.cntnt.write('svg:x="%.3fcm" ' % float(x))
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:y="%.3fcm">\n' % float(y))
|
2005-01-31 11:01:30 +05:30
|
|
|
if text != "":
|
|
|
|
self.cntnt.write('<text:p text:style-name="%s">' % para_name)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('<text:span text:style-name="F%s">' % para_name)
|
2004-10-14 09:39:38 +05:30
|
|
|
text = text.replace('\t','<text:tab-stop/>')
|
|
|
|
text = text.replace('\n','<text:line-break/>')
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write(text)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:span>')
|
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
self.cntnt.write('</draw:rect>\n')
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2003-09-13 10:26:04 +05:30
|
|
|
def center_text(self,style,text,x,y):
|
2005-01-31 11:01:30 +05:30
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
para_name = box_style.get_paragraph_style()
|
2003-09-13 10:26:04 +05:30
|
|
|
pstyle = self.style_list[para_name]
|
|
|
|
font = pstyle.get_font()
|
|
|
|
|
2004-01-10 23:34:32 +05:30
|
|
|
size = 1.1*(FontScale.string_width(font,text)/72.0) * 2.54
|
2003-09-13 10:26:04 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('<draw:text-box text:anchor-type="paragraph" ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('draw:style-name="%s" ' % style)
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('draw:z-index="0" ')
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:width="%.3fcm" ' % size)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.cntnt.write('svg:height="%.3fpt" ' % (font.get_size()*1.1))
|
2003-09-13 10:26:04 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('svg:x="%.3fcm" ' % (x-(size/2.0)))
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('svg:y="%.3fcm">\n' % float(y))
|
2003-09-13 10:26:04 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
if text != "":
|
|
|
|
self.cntnt.write('<text:p text:style-name="X%s">' % para_name)
|
|
|
|
self.cntnt.write(text)
|
2004-10-26 08:50:38 +05:30
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
self.cntnt.write('</draw:text-box>\n')
|
2003-09-13 10:26:04 +05:30
|
|
|
|
2005-01-18 08:45:40 +05:30
|
|
|
def write_at(self,style,text,x,y):
|
2005-01-31 11:01:30 +05:30
|
|
|
pstyle = self.style_list[style]
|
2005-01-18 08:45:40 +05:30
|
|
|
font = pstyle.get_font()
|
|
|
|
|
|
|
|
size = 1.1*(FontScale.string_width(font,text)/72.0) * 2.54
|
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('<draw:text-box text:anchor-type="paragraph" ')
|
|
|
|
self.cntnt.write('draw:z-index="0" ')
|
2005-01-18 08:45:40 +05:30
|
|
|
self.cntnt.write('svg:width="%.3fcm" ' % size)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.cntnt.write('svg:height="%.3fpt" ' % font.get_size())
|
2005-01-18 08:45:40 +05:30
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
self.cntnt.write('svg:x="%.3fcm" ' % x)
|
2005-01-18 08:45:40 +05:30
|
|
|
self.cntnt.write('svg:y="%.3fcm">\n' % float(y))
|
|
|
|
|
2005-01-31 11:01:30 +05:30
|
|
|
if text != "":
|
|
|
|
self.cntnt.write('<text:p text:style-name="X%s">' % style)
|
|
|
|
self.cntnt.write(text)
|
2005-01-18 08:45:40 +05:30
|
|
|
self.cntnt.write('</text:p>\n')
|
|
|
|
self.cntnt.write('</draw:text-box>\n')
|
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
#--------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register plugins
|
|
|
|
#
|
|
|
|
#--------------------------------------------------------------------------
|
2004-08-23 23:00:47 +05:30
|
|
|
print_label = None
|
2004-01-01 23:47:47 +05:30
|
|
|
try:
|
|
|
|
|
2006-03-03 05:53:04 +05:30
|
|
|
mprog = Mime.get_application(_apptype)
|
|
|
|
mtype = Mime.get_description(_apptype)
|
2004-01-01 23:47:47 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
if Utils.search_for(mprog[0]):
|
2004-01-01 23:47:47 +05:30
|
|
|
print_label = _("Open in OpenOffice.org")
|
2004-04-04 10:09:52 +05:30
|
|
|
else:
|
|
|
|
print_label = None
|
|
|
|
|
2006-03-11 06:42:06 +05:30
|
|
|
register_text_doc(mtype,OpenOfficeDoc,1,1,1,".sxw",print_label)
|
|
|
|
register_book_doc(mtype,OpenOfficeDoc,1,1,1,".sxw")
|
|
|
|
register_draw_doc(mtype,OpenOfficeDoc,1,1, ".sxw",print_label);
|
2004-01-01 23:47:47 +05:30
|
|
|
except:
|
2006-03-11 06:42:06 +05:30
|
|
|
register_text_doc(_('OpenOffice.org Writer'),
|
|
|
|
OpenOfficeDoc,1,1,1,".sxw", None)
|
|
|
|
register_book_doc(_("OpenOffice.org Writer"), OpenOfficeDoc,1,1,1,".sxw")
|
|
|
|
register_draw_doc(_("OpenOffice.org Writer"),
|
|
|
|
OpenOfficeDoc,1,1,".sxw",None);
|