[Python-modules-commits] [python-odf] 75/118: Make draw_:custom-shape work and switched to absolute positioning

Wolfgang Borgert debacle at moszumanska.debian.org
Fri Oct 3 21:27:25 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to reference refs/remotes/upstream/master
in repository python-odf.

commit 1e136f0770f9864568a0e0b30acd518ede0f67d7
Author: Søren Roug <soren.roug at eea.europa.eu>
Date:   Sat Mar 20 16:48:39 2010 +0000

    Make draw_:custom-shape work and switched to absolute positioning
---
 odf/odf2xhtml.py        |  47 ++++++++++++++++++++++++++++++++++++++++++-----
 tests/examples/cols.odp | Bin 0 -> 18037 bytes
 tests/testxhtml.py      |  11 +++++++++++
 3 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/odf/odf2xhtml.py b/odf/odf2xhtml.py
index 6aaf165..9ae4453 100644
--- a/odf/odf2xhtml.py
+++ b/odf/odf2xhtml.py
@@ -341,6 +341,7 @@ class ODF2XHTML(handler.ContentHandler):
         (DCNS, 'creator'): (self.s_processcont, self.e_dc_metatag),
         (DCNS, 'description'): (self.s_processcont, self.e_dc_metatag),
         (DCNS, 'date'): (self.s_processcont, self.e_dc_metatag),
+        (DRAWNS, 'custom-shape'): (self.s_custom_shape, self.e_custom_shape),
         (DRAWNS, 'frame'): (self.s_draw_frame, self.e_draw_frame),
         (DRAWNS, 'image'): (self.s_draw_image, None),
         (DRAWNS, 'fill-image'): (self.s_draw_fill_image, None),
@@ -381,8 +382,8 @@ class ODF2XHTML(handler.ContentHandler):
 #       (STYLENS, "header-style"):(self.s_style_header_style, None),
         (STYLENS, "master-page"):(self.s_style_master_page, None),
         (STYLENS, "page-layout-properties"):(self.s_style_handle_properties, None),
-#       (STYLENS, "page-layout"):(self.s_style_page_layout, self.e_style_page_layout),
-        (STYLENS, "page-layout"):(self.s_ignorexml, None),
+        (STYLENS, "page-layout"):(self.s_style_page_layout, self.e_style_page_layout),
+#       (STYLENS, "page-layout"):(self.s_ignorexml, None),
         (STYLENS, "paragraph-properties"):(self.s_style_handle_properties, None),
         (STYLENS, "style"):(self.s_style_style, self.e_style_style),
         (STYLENS, "table-cell-properties"):(self.s_style_handle_properties, None),
@@ -550,10 +551,46 @@ class ODF2XHTML(handler.ContentHandler):
         self.metatags.append('<meta http-equiv="content-language" content="%s"/>\n' % ''.join(self.data))
         self.data = []
 
+    def s_custom_shape(self, tag, attrs):
+        """ A <draw:custom-shape> is made into a <div> in HTML which is then styled
+        """
+        anchor_type = attrs.get((TEXTNS,'anchor-type'),'notfound')
+        htmltag = 'div'
+        name = "G-" + attrs.get( (DRAWNS,'style-name'), "")
+        if name == 'G-':
+            name = "PR-" + attrs.get( (PRESENTATIONNS,'style-name'), "")
+        name = name.replace(".","_")
+        if anchor_type == "paragraph":
+            style = 'position:absolute;'
+        elif anchor_type == 'char':
+            style = "position:absolute;"
+        elif anchor_type == 'as-char':
+            htmltag = 'div'
+            style = ''
+        else:
+            style = "position: absolute;"
+        if attrs.has_key( (SVGNS,"width") ):
+            style = style + "width:" + attrs[(SVGNS,"width")] + ";"
+        if attrs.has_key( (SVGNS,"height") ):
+            style = style + "height:" +  attrs[(SVGNS,"height")] + ";"
+        if attrs.has_key( (SVGNS,"x") ):
+            style = style + "left:" +  attrs[(SVGNS,"x")] + ";"
+        if attrs.has_key( (SVGNS,"y") ):
+            style = style + "top:" +  attrs[(SVGNS,"y")] + ";"
+        if self.generate_css:
+            self.opentag(htmltag, {'class': name, 'style': style})
+        else:
+            self.opentag(htmltag)
+
+    def e_custom_shape(self, tag, attrs):
+        """ End the <draw:frame>
+        """
+        self.closetag('div')
+
     def s_draw_frame(self, tag, attrs):
         """ A <draw:frame> is made into a <div> in HTML which is then styled
         """
-        anchor_type = attrs.get((TEXTNS,'anchor-type'),'char')
+        anchor_type = attrs.get((TEXTNS,'anchor-type'),'notfound')
         htmltag = 'div'
         name = "G-" + attrs.get( (DRAWNS,'style-name'), "")
         if name == 'G-':
@@ -567,7 +604,7 @@ class ODF2XHTML(handler.ContentHandler):
             htmltag = 'div'
             style = ''
         else:
-            style = "position: absolute;"
+            style = "position:absolute;"
         if attrs.has_key( (SVGNS,"width") ):
             style = style + "width:" + attrs[(SVGNS,"width")] + ";"
         if attrs.has_key( (SVGNS,"height") ):
@@ -839,7 +876,7 @@ class ODF2XHTML(handler.ContentHandler):
         """
         name = attrs[(STYLENS,'name')]
         name = name.replace(".","_")
-        self.currentstyle = "@page " + name
+        self.currentstyle = ".PL-" + name
         self.stylestack.append(self.currentstyle)
         self.styledict[self.currentstyle] = {}
 
diff --git a/tests/examples/cols.odp b/tests/examples/cols.odp
new file mode 100644
index 0000000..8c03690
Binary files /dev/null and b/tests/examples/cols.odp differ
diff --git a/tests/testxhtml.py b/tests/testxhtml.py
index a48b192..532e414 100644
--- a/tests/testxhtml.py
+++ b/tests/testxhtml.py
@@ -165,8 +165,10 @@ class TestExampleDocs(unittest.TestCase):
         assert has_rules(result,".L3_1","list-style-type: disc;")
         assert has_rules(result,".L3_2","list-style-type: decimal;")
         assert has_rules(result,".L3_3","list-style-type: square;")
+        assert has_rules(result,".MP-Default","height: 19.05cm; width: 25.4cm; position: relative;")
         self.assertNotEqual(-1, result.find(u"""<ol class="L2_1">"""))
         self.assertNotEqual(-1, result.find(u"""<ol class="L3_2">"""))
+        self.assertNotEqual(-1, result.find(u"""position:absolute;width:22.86cm;height:3.176cm;left:1.27cm;top:0.762cm;"""))
 
     def test_simpletable(self):
         """ Check CSS has table styles """
@@ -216,5 +218,14 @@ class TestExampleDocs(unittest.TestCase):
         assert has_rules(result,".G-fr7","margin-right: auto;margin-left: auto;")
         assert has_rules(result,".P-Illustration","font-size: 10pt;")
 
+    def test_positioned_shapes(self):
+        """ Test positioned custom-shapes """
+        odt = os.path.join(os.path.dirname(__file__), "examples", "cols.odp")
+        odhandler = ODF2XHTML()
+        result = odhandler.odf2xhtml(odt)
+        self.assertNotEqual(-1, result.find(u'''<div style="position: absolute;width:5.503cm;height:1.905cm;left:2.117cm;top:3.175cm;" class="G-gr1">'''))
+        assert has_rules(result,".MP-Default","height: 19.05cm; width: 25.4cm; position: relative;")
+
+
 if __name__ == '__main__':
     unittest.main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-odf.git



More information about the Python-modules-commits mailing list