コード例 #1
0
ファイル: teststyles.py プロジェクト: abiapp/odfpy
    def testAttributeForeign(self):
        """ Test that you can add foreign attributes """
        textdoc = OpenDocumentText()
        standard = style.Style(name=u"Standard", family=u"paragraph")
        p = style.ParagraphProperties(qattributes={(u'http://foreignuri.com','enable-numbering'):u'true'})
        standard.addElement(p)
        textdoc.styles.addElement(standard)
        s = textdoc.stylesxml()
        s.index(u"""<?xml version='1.0' encoding='UTF-8'?>\n""")
        s.index(u'xmlns:ns41="http://foreignuri.com"')
        s.index(u'<style:paragraph-properties ns41:enable-numbering="true"/>')
        e = ElementParser(s,u'style:style')
#        e = ElementParser('<style:style style:name="Standard" style:display-name="Standard" style:family="paragraph">')
        self.assertEqual(e.element,u'style:style')
        self.assertTrue(e.has_value(u"style:display-name","Standard"))
        self.assertTrue(e.has_value(u"style:name","Standard"))
        self.assertTrue(e.has_value(u"style:family","paragraph"))
コード例 #2
0
ファイル: teststyles.py プロジェクト: bufke/odfpy
    def testAttributeForeign(self):
        """ Test that you can add foreign attributes """
        textdoc = OpenDocumentText()
        standard = style.Style(name="Standard", family="paragraph")
        p = style.ParagraphProperties(qattributes={(u'http://foreignuri.com',u'enable-numbering'):'true'})
        standard.addElement(p)
        textdoc.styles.addElement(standard)
        s = unicode(textdoc.stylesxml(),'UTF-8')
        s.index(u"""<?xml version='1.0' encoding='UTF-8'?>\n""")
        s.index(u'xmlns:ns41="http://foreignuri.com"')
        s.index(u'<style:paragraph-properties ns41:enable-numbering="true"/>')
        e = ElementParser(s,'style:style')
#        e = ElementParser(u'<style:style style:name="Standard" style:display-name="Standard" style:family="paragraph">')
        self.assertEqual(e.element,'style:style')
        self.assertTrue(e.has_value("style:display-name","Standard"))
        self.assertTrue(e.has_value("style:name","Standard"))
        self.assertTrue(e.has_value("style:family","paragraph"))
コード例 #3
0
def main():
    index = FileIndex(r"C:\Users\Dominik\Documents\LStudioProjects\ma_test",
                      ['.sys', '.fbt', '.res'])
    parser = ElementParser(r"D:\LOYTEC\L-STUDIO 3.0\Studio\data\Schemas")
    error_reporter = ValidationErrorReporter()
    parser.attach('validationError', error_reporter)
    parser.attach('element', add_to_element_index)
    iec_elements.initialize(parser)
    for file in index:
        parser.parse(str(file))
    error_reporter.print_error_list()
コード例 #4
0
ファイル: testload.py プロジェクト: bufke/odfpy
    def test_simpletable(self):
        """ Load a document containing tables """
        simpletable_odt = os.path.join(os.path.dirname(__file__), "examples",
                                       "simpletable.odt")
        d = load(simpletable_odt)
        result = unicode(d.contentxml(), 'utf-8')
        e = ElementParser(result, 'text:sequence-decl')
        self.assertTrue(e.has_value("text:name", "Drawing"))  # Last sequence
        self.assertTrue(e.has_value("text:display-outline-level", "0"))

        e = ElementParser(result, 'table:table-column')
        self.assertTrue(e.has_value("table:number-columns-repeated", "2"))
        self.assertTrue(e.has_value("table:style-name", "Tabel1.A"))
コード例 #5
0
ファイル: testsubobjects.py プロジェクト: eea/odfpy
    def test_subobject(self):
        df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
        self.textdoc.text.addElement(df)

        subdoc = OpenDocumentText()
        # Here we add the subdocument to the main document. We get back a reference
        # to use in the href.
        subloc = self.textdoc.addObject(subdoc)
        self.assertEqual(subloc,'./Object 1')
        do = draw.Object(href=subloc)
        df.addElement(do)

        subsubdoc = OpenDocumentText()
        subsubloc = subdoc.addObject(subsubdoc)
        self.assertEqual(subsubloc,'./Object 1/Object 1')

        c = self.textdoc.contentxml() # contentxml() is supposed to yeld a bytes
        c.index(b'<office:body><office:text><draw:frame ')
        e = ElementParser(c.decode("utf-8"), u'draw:frame')
#       e = ElementParser('<draw:frame svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt">')
        self.assertTrue(e.has_value(u'svg:width',"476pt"))
        self.assertTrue(e.has_value(u'svg:height',"404pt"))
        self.assertTrue(e.has_value(u'text:anchor-type',"paragraph"))
        self.assertFalse(e.has_value(u'svg:height',"476pt"))
        c.index(b'<draw:object xlink:href="./Object 1"/></draw:frame></office:text></office:body>')
        c.index(b'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
        self.textdoc.save(u"TEST.odt")
        self.saved = True
        m = _getxmlpart(u"TEST.odt", u"META-INF/manifest.xml").decode('utf-8')
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="content.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="meta.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/styles.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/content.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/Object 1/"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/styles.xml"'))
        assert(element_has_attributes(m, u'manifest:file-entry', u'manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/content.xml"'))
コード例 #6
0
ファイル: testload.py プロジェクト: abiapp/odfpy
    def test_simpletable(self):
        """ Load a document containing tables """
        simpletable_odt = os.path.join(
            os.path.dirname(__file__), "examples", "simpletable.odt")
        d = load(simpletable_odt)
        result = unicode(d.contentxml(),'utf-8')
        e = ElementParser(result,'text:sequence-decl')
        self.assertTrue(e.has_value("text:name","Drawing")) # Last sequence
        self.assertTrue(e.has_value("text:display-outline-level","0"))

        e = ElementParser(result,'table:table-column')
        self.assertTrue(e.has_value("table:number-columns-repeated","2"))
        self.assertTrue(e.has_value("table:style-name","Tabel1.A"))
コード例 #7
0
    def testStyle(self):
        """ Create a presentation with a page layout called MyLayout
            Add a presentation style for the title
            Check that MyLayout is listed in styles.xml
        """
        presdoc = OpenDocumentPresentation()
        # We must describe the dimensions of the page
        pagelayout = style.PageLayout(name="MyLayout")
        presdoc.automaticstyles.addElement(pagelayout)
        pagelayout.addElement(
            style.PageLayoutProperties(margin="0cm",
                                       pagewidth="28cm",
                                       pageheight="21cm",
                                       printorientation="landscape"))

        # Every drawing page must have a master page assigned to it.
        masterpage = style.MasterPage(name="MyMaster",
                                      pagelayoutname=pagelayout)
        presdoc.masterstyles.addElement(masterpage)

        # Style for the title frame of the page
        # We set a centered 34pt font with yellowish background
        titlestyle = style.Style(name="MyMaster-title", family="presentation")
        titlestyle.addElement(style.ParagraphProperties(textalign="center"))
        titlestyle.addElement(style.TextProperties(fontsize="34pt"))
        titlestyle.addElement(style.GraphicProperties(fillcolor="#ffff99"))
        presdoc.styles.addElement(titlestyle)

        s = presdoc.stylesxml()
        self.assertContains(
            s,
            '<style:page-layout style:name="MyLayout"><style:page-layout-properties '
        )
        e = ElementParser(s, 'style:page-layout-properties')
        self.assertEqual(e.element, 'style:page-layout-properties')
        self.assertTrue(e.has_value("fo:margin", "0cm"))
        self.assertTrue(e.has_value("fo:page-width", "28cm"))
        self.assertTrue(e.has_value("fo:page-height", "21cm"))
        self.assertTrue(e.has_value("style:print-orientation", "landscape"))

        e = ElementParser(s, 'style:style')
        self.assertTrue(e.has_value("style:name", "MyMaster-title"))
        self.assertTrue(e.has_value("style:display-name", "MyMaster-title"))
        self.assertTrue(e.has_value("style:family", "presentation"))

        self.assertContains(
            s,
            '<style:paragraph-properties fo:text-align="center"/><style:text-properties fo:font-size="34pt"/><style:graphic-properties draw:fill-color="#ffff99"/></style:style></office:styles>'
        )
        e = ElementParser(s, 'style:master-page')
        self.assertTrue(e.has_value("style:name", "MyMaster"))
        self.assertTrue(e.has_value("style:display-name", "MyMaster"))
        self.assertTrue(e.has_value("style:page-layout-name", "MyLayout"))
コード例 #8
0
    def test_subobject(self):
        df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
        self.textdoc.text.addElement(df)

        subdoc = OpenDocumentText()
        # Here we add the subdocument to the main document. We get back a reference
        # to use in the href.
        subloc = self.textdoc.addObject(subdoc)
        self.assertEqual(subloc, './Object 1')
        do = draw.Object(href=subloc)
        df.addElement(do)

        subsubdoc = OpenDocumentText()
        subsubloc = subdoc.addObject(subsubdoc)
        self.assertEqual(subsubloc, './Object 1/Object 1')

        c = unicode(self.textdoc.contentxml(), 'UTF-8')
        c.index(u'<office:body><office:text><draw:frame ')
        e = ElementParser(c, 'draw:frame')
        #       e = ElementParser('<draw:frame svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt">')
        self.assertTrue(e.has_value('svg:width', "476pt"))
        self.assertTrue(e.has_value('svg:height', "404pt"))
        self.assertTrue(e.has_value('text:anchor-type', "paragraph"))
        self.assertFalse(e.has_value('svg:height', "476pt"))
        c.index(
            u'<draw:object xlink:href="./Object 1"/></draw:frame></office:text></office:body>'
        )
        c.index(u'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"')
        self.textdoc.save("TEST.odt")
        self.saved = True
        m = _getxmlpart("TEST.odt", "META-INF/manifest.xml")
        m.index(
            '<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/styles.xml"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/content.xml"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="Object 1/Object 1/"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/styles.xml"/>'
        )
        m.index(
            '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="Object 1/Object 1/content.xml"/>'
        )
コード例 #9
0
ファイル: testmasterstyles.py プロジェクト: BrickXu/odfpy
    def testStyle(self):
        """ Create a presentation with a page layout called MyLayout
            Add a presentation style for the title
            Check that MyLayout is listed in styles.xml
        """
        presdoc = OpenDocumentPresentation()
        # We must describe the dimensions of the page
        pagelayout = style.PageLayout(name="MyLayout")
        presdoc.automaticstyles.addElement(pagelayout)
        pagelayout.addElement(style.PageLayoutProperties(margin="0cm", pagewidth="28cm", pageheight="21cm", printorientation="landscape"))

        # Every drawing page must have a master page assigned to it.
        masterpage = style.MasterPage(name="MyMaster", pagelayoutname=pagelayout)
        presdoc.masterstyles.addElement(masterpage)

        # Style for the title frame of the page
        # We set a centered 34pt font with yellowish background
        titlestyle = style.Style(name="MyMaster-title", family="presentation")
        titlestyle.addElement(style.ParagraphProperties(textalign="center"))
        titlestyle.addElement(style.TextProperties(fontsize="34pt"))
        titlestyle.addElement(style.GraphicProperties(fillcolor="#ffff99"))
        presdoc.styles.addElement(titlestyle)

        s = unicode(presdoc.stylesxml(),'UTF-8')
        self.assertContains(s, u'<style:page-layout style:name="MyLayout"><style:page-layout-properties ')
        e = ElementParser(s,'style:page-layout-properties')
        self.assertEqual(e.element,'style:page-layout-properties')
        self.assertTrue(e.has_value("fo:margin","0cm"))
        self.assertTrue(e.has_value("fo:page-width","28cm"))
        self.assertTrue(e.has_value("fo:page-height","21cm"))
        self.assertTrue(e.has_value("style:print-orientation","landscape"))

        e = ElementParser(s,'style:style')
        self.assertTrue(e.has_value("style:name","MyMaster-title"))
        self.assertTrue(e.has_value("style:display-name","MyMaster-title"))
        self.assertTrue(e.has_value("style:family","presentation"))

        self.assertContains(s, u'<style:paragraph-properties fo:text-align="center"/><style:text-properties fo:font-size="34pt"/><style:graphic-properties draw:fill-color="#ffff99"/></style:style></office:styles>')
        e = ElementParser(s,'style:master-page')
        self.assertTrue(e.has_value("style:name","MyMaster"))
        self.assertTrue(e.has_value("style:display-name","MyMaster"))
        self.assertTrue(e.has_value("style:page-layout-name","MyLayout"))