diff --git a/src/plugins/docgen/ODFDoc.py b/src/plugins/docgen/ODFDoc.py
index c4b4db9ed..2df130f74 100644
--- a/src/plugins/docgen/ODFDoc.py
+++ b/src/plugins/docgen/ODFDoc.py
@@ -38,6 +38,7 @@ import locale
from cStringIO import StringIO
from math import pi, cos, sin
from xml.sax.saxutils import escape
+import operator
#-------------------------------------------------------------------------
#
@@ -51,6 +52,7 @@ from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc,
INDEX_TYPE_TOC, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,
INDEX_TYPE_ALP, PARA_ALIGN_RIGHT)
from gen.plug.docgen.fontscale import string_width
+from libodfbackend import OdfBackend
import const
from ReportBase import ReportUtils
import ImgManip
@@ -73,6 +75,14 @@ _esc_map = {
'\t' : '',
}
+#-------------------------------------------------------------------------
+#
+# regexp for Styled Notes ...
+#
+#-------------------------------------------------------------------------
+import re
+NewStyle = re.compile('style-name="([a-zA-Z0-9]*)__([#a-zA-Z0-9 ]*)__">')
+
#-------------------------------------------------------------------------
#
# ODFDoc
@@ -84,6 +94,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
BaseDoc.__init__(self, styles, type)
self.media_list = []
self.cntnt = None
+ self._backend = None
self.filename = None
self.level = 0
self.time = "0000-00-00T00:00:00"
@@ -91,6 +102,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
self.new_cell = 0
self.page = 0
self.first_page = 1
+ self.StyleList = [] # styles to create depending on styled notes.
def open(self, filename):
t = time.localtime(time.time())
@@ -102,7 +114,10 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
self.filename = filename
self.filename = os.path.normpath(os.path.abspath(self.filename))
+ self._backend = OdfBackend()
self.cntnt = StringIO()
+ self.cntnt1 = StringIO()
+ self.cntnt2 = StringIO()
def init(self):
@@ -116,51 +131,52 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
else:
self.lang = "en-US"
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('\n')
- self.cntnt.write('')
- self.cntnt.write('')
- self.cntnt.write('\n')
- self.cntnt.write('')
- self.cntnt.write('')
- self.cntnt.write('\n')
+ self.StyleList = [] # styles to create depending on styled notes.
+ self.cntnt1.write('\n')
+ self.cntnt1.write('\n')
+ self.cntnt1.write('\n')
+ self.cntnt1.write('\n')
+ self.cntnt1.write('\n')
+ self.cntnt1.write('\n')
+ self.cntnt1.write('\n')
+ self.cntnt2.write('\n')
+ self.cntnt2.write('\n')
+ self.cntnt2.write('\n')
+ self.cntnt2.write('\n')
+ self.cntnt2.write('\n')
+ self.cntnt2.write('')
+ self.cntnt2.write('')
+ self.cntnt2.write('\n')
+ self.cntnt2.write('')
+ self.cntnt2.write('')
+ self.cntnt2.write('\n')
styles = self.get_style_sheet()
@@ -359,6 +375,16 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
self.cntnt.write('\n')
self.cntnt.write('\n')
self.cntnt.write('\n')
+ self.cntnt.write('\n')
+ self.cntnt.write('\n')
+ self.cntnt.write('\n')
+ self.cntnt.write('\n')
+ self.cntnt.write('')
+ self.cntnt.write('\n')
#Begin photo style
self.cntnt.write('\n')
+ def finish_cntnt_creation(self):
+ self.cntntx = StringIO()
+ self.add_styled_notes_fonts()
+ self.add_styled_notes_styles()
+ self.cntntx.write(self.cntnt1.getvalue())
+ self.cntntx.write(self.cntnt2.getvalue())
+ self.cntntx.write(self.cntnt.getvalue())
+ self.cntnt1.close()
+ self.cntnt2.close()
+ self.cntnt.close()
+
def close(self):
self.cntnt.write('\n')
self.cntnt.write('\n')
self.cntnt.write('\n')
+ self.finish_cntnt_creation()
self._write_styles_file()
self._write_manifest()
self._write_meta_file()
@@ -437,6 +475,41 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
if self.open_req:
open_file_with_default_application(self.filename)
+ def add_styled_notes_fonts(self):
+ # Need to add new font for styled notes here.
+ for style in self.StyleList:
+ if ( style[0] == "FontFace" ):
+ self.cntnt1.write('\n')
+
+ def add_styled_notes_styles(self):
+ # Need to add new style for styled notes here.
+ for style in self.StyleList:
+ if ( style[0] == "FontSize" ):
+ self.cntnt2.write('')
+ self.cntnt2.write(' ' % style[1])
+ self.cntnt2.write('\n')
+ elif ( style[0] == "FontColor" ):
+ self.cntnt2.write('')
+ self.cntnt2.write(' ' % style[1])
+ self.cntnt2.write('\n')
+ elif ( style[0] == "FontHighlight" ):
+ self.cntnt2.write('')
+ self.cntnt2.write(' ' % style[1])
+ self.cntnt2.write('\n')
+ elif ( style[0] == "FontFace" ):
+ self.cntnt2.write('')
+ self.cntnt2.write(' ')
+ self.cntnt2.write('\n')
+
def add_media_object(self, file_name, pos, x_cm, y_cm, alt=''):
# try to open the image. If the open fails, it probably wasn't
@@ -552,7 +625,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
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, "content.xml", self.cntntx.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)
@@ -881,6 +954,34 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
self.write_text(line)
self.end_paragraph()
+ def write_styled_note(self, styledtext, format, style_name):
+ """
+ Convenience function to write a styledtext to the latex doc.
+ styledtext : assumed a StyledText object to write
+ format : = 0 : Flowed, = 1 : Preformatted
+ style_name : name of the style to use for default presentation
+ """
+ text = str(styledtext)
+ s_tags = styledtext.get_tags()
+ markuptext = self._backend.add_markup_from_styled(text, s_tags)
+ # we need to know if we have new styles to add.
+ # if markuptext contains : FontColor, FontFace, FontSize or FontHighlight
+ # we must prepare the new styles for the styles.xml file.
+ # We are looking for the following format :
+ # style-name="([a-zA-Z0-9]*)__([a-zA-Z0-9 ])">
+ # The first element is the StyleType and the second one is the value
+ start = 0
+ while 1:
+ m = NewStyle.search(markuptext, start)
+ if not m:
+ break
+ self.StyleList.append([m.group(1), m.group(2)])
+ print [m.group(1), m.group(2)]
+ start = m.end()
+ self.cntnt.write('')
+ self.cntnt.write(markuptext)
+ self.cntnt.write('')
+
def write_text(self, text, mark=None):
"""
Uses the xml.sax.saxutils.escape function to convert XML