From: <dku...@us...> - 2012-08-19 21:46:17
|
Revision: 7499 http://docutils.svn.sourceforge.net/docutils/?rev=7499&view=rev Author: dkuhlman Date: 2012-08-19 21:46:11 +0000 (Sun, 19 Aug 2012) Log Message: ----------- Fix to attach the default page style in the body of the document Modified Paths: -------------- trunk/docutils/docutils/writers/odf_odt/__init__.py trunk/docutils/test/functional/expected/odt_basic.odt trunk/docutils/test/functional/expected/odt_custom_headfoot.odt trunk/docutils/test/functional/expected/odt_tables1.odt Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py =================================================================== --- trunk/docutils/docutils/writers/odf_odt/__init__.py 2012-08-19 04:56:42 UTC (rev 7498) +++ trunk/docutils/docutils/writers/odf_odt/__init__.py 2012-08-19 21:46:11 UTC (rev 7499) @@ -73,6 +73,8 @@ PIL.Image = Image except ImportError: PIL = None +if PIL is not None: + import PIL.Image ## import warnings ## warnings.warn('importing IPShellEmbed', UserWarning) @@ -946,7 +948,46 @@ }) el.text = text self.body_text_element.insert(0, el) + el = self.find_first_text_p(self.body_text_element) + if el is not None: + self.attach_page_style(el) + def find_first_text_p(self, el): + """Search the generated doc and return the first <text:p> element. + """ + if ( + el.tag == 'text:p' or + el.tag == 'text:h' + ): + return el + elif el.getchildren(): + for child in el.getchildren(): + el1 = self.find_first_text_p(child) + if el1 is not None: + return el1 + return None + else: + return None + + def attach_page_style(self, el): + """Attach the default page style. + + Create an automatic-style that refers to the current style + of this element and that refers to the default page style. + """ + current_style = el.get('text:style-name') + style_name = 'P1003' + el1 = SubElement( + self.automatic_styles, 'style:style', attrib={ + 'style:name': style_name, + 'style:master-page-name': "rststyle-pagedefault", + 'style:family': "paragraph", + }, nsdict=SNSD) + if current_style: + el1.set('style:parent-style-name', current_style) + el.set('text:style-name', style_name) + + def rststyle(self, name, parameters=( )): """ Returns the style name to use for the given style. Modified: trunk/docutils/test/functional/expected/odt_basic.odt =================================================================== (Binary files differ) Modified: trunk/docutils/test/functional/expected/odt_custom_headfoot.odt =================================================================== (Binary files differ) Modified: trunk/docutils/test/functional/expected/odt_tables1.odt =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |