diff --git a/src/plugins/docgen/ODFDoc.py b/src/plugins/docgen/ODFDoc.py index d5c773b62..93a2fda61 100644 --- a/src/plugins/docgen/ODFDoc.py +++ b/src/plugins/docgen/ODFDoc.py @@ -112,7 +112,8 @@ _esc_map = { # #------------------------------------------------------------------------- import re -NewStyle = re.compile('style-name="([a-zA-Z0-9]*)__([#a-zA-Z0-9 ]*)__">') +# Hyphen is added because it is used to replace spaces in the font name +NewStyle = re.compile('style-name="([a-zA-Z0-9]*)__([#a-zA-Z0-9 -]*)__">') #------------------------------------------------------------------------- # @@ -156,6 +157,7 @@ _FONTS = '''\ svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/> + ''' _META_XML = '''\ @@ -298,6 +300,7 @@ _AUTOMATIC_STYLES = '''\ + ''' _CLEAR_STYLE = '''\ @@ -444,6 +447,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): self.mimetype = None self.meta = None self.mfile = None + self.stfile = None self.filename = None self.lang = None self._backend = None @@ -810,6 +814,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): self.finish_cntnt_creation() self._write_styles_file() self._write_manifest() + self._write_settings() self._write_meta_file() self._write_mimetype_file() self._write_zip() @@ -822,11 +827,14 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): wrt1 = self.cntnt1.write for style in self.StyleList_notes: if style[1] == "FontFace": + # Restore any spaced that were replaced by hyphens in + # libodfbackend wrt1( '\n' + ' style:name="%s"\n' % style[2].replace("-", " ") + + ' svg:font-family="'%s'"\n' % + style[2].replace("-", " ") + + ' style:font-pitch="fixed"/>\n\n' ) def add_styled_notes_styles(self): @@ -839,44 +847,49 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): if style[1] == "FontSize": wrt2( ' ' + - '' % style[2] + - '\n' + 'style:name="FontSize__%s__"\n' % style[2] + + ' style:family="text">\n' + + ' \n' % style[2] + + '\n\n' ) elif style[1] == "FontColor": + # Restore the hash at the start that was removed by + # libodfbackend wrt2( '' + - ' ' % style[2] + - '\n' + 'style:name="FontColor__%s__"\n' % style[2] + + ' style:family="text">\n' + + ' \n' % style[2] + + '\n\n' ) elif style[1] == "FontHighlight": wrt2( ' ' + - '' % style[2] + - '\n' + 'style:name="FontHighlight__%s__"\n' % style[2] + + ' style:family="text">\n' + + ' \n' % style[2] + + '\n\n' ) elif style[1] == "FontFace": + # Restore any spaced that were replaced by hyphens in + # libodfbackend wrt2( ' ' + - '' + - '\n' + 'style:name="FontFace__%s__"\n' % style[2] + + ' style:family="text">\n' + + ' \n' + + '\n\n' ) def add_styled_photo_styles(self): @@ -1184,12 +1197,14 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): self._add_zip(zfile, "META-INF/manifest.xml", self.mfile.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, "settings.xml", self.stfile.getvalue(), t) self._add_zip(zfile, "styles.xml", self.sfile.getvalue(), t) self._add_zip(zfile, "mimetype", self.mimetype.getvalue(), t) self.mfile.close() self.cntnt.close() self.meta.close() + self.stfile.close() self.sfile.close() self.mimetype.close() @@ -1617,11 +1632,30 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): 'manifest:full-path="content.xml"/>' '' + '' '' '\n' ) + def _write_settings(self): + """ + create the settings.xml file + """ + self.stfile = StringIO() + # This minimal settings file has been taken from + # http://mashupguide.net/1.0/html/ch17s03.xhtml (Creative commons + # licence): http://mashupguide.net/1.0/html/apas02.xhtml + self.stfile.write( + '\n' + + '' + ) + def _write_mimetype_file(self): """ create the mimetype.xml file diff --git a/src/plugins/lib/libodfbackend.py b/src/plugins/lib/libodfbackend.py index 5b23e0a91..61567a2e6 100644 --- a/src/plugins/lib/libodfbackend.py +++ b/src/plugins/lib/libodfbackend.py @@ -121,18 +121,25 @@ class OdfBackend(DocBackend): """ if tagtype not in self.SUPPORTED_MARKUP: return None + # The ODF validator does not like spaces or hash in style-names. the + # font name needs to have the spaces restored, we just hope that the + # name did not have a hyphen in it originally. The colour is represented + # without the leading hash, this can be replaced when used in the text- + # property font colour if ( tagtype == DocBackend.FONTCOLOR ): - return ('' % value, + return ('' % + value.replace("#", ""), '') elif ( tagtype == DocBackend.FONTFACE ): return ('' % - self.ESCAPE_FUNC()(value), + self.ESCAPE_FUNC()(value).replace(" ", "-"), '') elif ( tagtype == DocBackend.FONTSIZE ): return ('' % value, '') else: #elif ( tagtype == DocBackend.HIGHLIGHT ): - return ('' % value, + return ('' % + value.replace("#", ""), '') def format_link(self, value):