예제 #1
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 svg:width="476pt" text:anchor-type="paragraph" svg:height="404pt"><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"/>')
예제 #2
0
    def owriteMath(self, obj): 
        """
        get a MATHML from Latex
        translate element tree to odf.Elements
        """
        #log("math")
        r = writerbase.renderMath(obj.caption, output_mode='mathml', render_engine='blahtexml')        
        if not r:
            log("writerbase.renderMath failed!")
            return
        #print mathml.ET.tostring(r)
        
        def _withETElement(e, parent):
            # translate to odf.Elements
            for c in e.getchildren():
                n = math.Element(qname=(math.MATHNS, str(c.tag)))
                parent.addElement(n)
                if c.text:
                    text = c.text
                    #if not isinstance(text, unicode):  text = text.decode("utf8")
                    n.appendChild(odf.element.Text(text)) # n.addText(c.text)
                    # rffixme: odfpy0.8 errors:"AttributeError: Element instance has no attribute 'elements'" -> this is a lie!
                _withETElement(c, n)

        mathframe = draw.Frame(stylename=style.formula, zindex=0, anchortype="as-char") 
        mathobject = draw.Object() 
        mathframe.addElement(mathobject)
        mroot = math.Math()
        mathobject.addElement(mroot)
        _withETElement(r, mroot)
        return mathframe
예제 #3
0
def drawChart(_document, _values, \
      chartWidth,
      chartHeight,
      chartType):
    # Create the subdocument
    chartdoc = OpenDocumentChart()
    mychart = PieChart(chartWidth, chartHeight, chartType)

    # These represent the data. Six rows in three columns
    mychart.values = _values
    mychart.datasourcehaslabels = "both"
    mychart(chartdoc)

    p = P()
    _document.add(p)

    # Create the frame.
    df = draw.Frame(width=chartWidth,
                    height=chartHeight,
                    anchortype="paragraph")
    p.addElement(df)

    # Here we add the subdocument to the main document. We get back a reference
    # to use in the href.
    objectloc = _document.addAsObject(chartdoc)
    do = draw.Object(href=objectloc)

    # Put the object inside the frame
    df.addElement(do)
예제 #4
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 = 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"'
        ))
예제 #5
0
    mychart = BarChart()
    mychart.title = "SPECTRE"
    mychart.subtitle = "SPecial Executive for Counter-intelligence, Terrorism, Revenge and Extortion"
    mychart.x_axis = "Divisions"
    mychart.y_axis = u"€ (thousand)"
    # These represent the data. Six rows in three columns
    mychart.values = (('', 'Expense', 'Revenue'), ('Counterfeit', 1000, 1500),
                      ('Murder', 1100, 1150), ('Prostitution', 3200, 2350),
                      ('Blackmail', 1100, 1150), ('Larceny', 1000, 1750))
    mychart.datasourcehaslabels = "both"
    mychart(chartdoc)

    # Create the containg document
    textdoc = OpenDocumentText()
    # Create a paragraph to contain the frame. You can put the frame directly
    # as a child og textdoc.text, but both Kword and OOo has problems wiht
    # this approach.
    p = text.P()
    textdoc.text.addElement(p)
    # Create the frame.
    df = draw.Frame(width="476pt", height="404pt", anchortype="paragraph")
    p.addElement(df)

    # Here we add the subdocument to the main document. We get back a reference
    # to use in the href.
    objectloc = textdoc.addObject(chartdoc)
    do = draw.Object(href=objectloc)
    # Put the object inside the frame
    df.addElement(do)
    textdoc.save("spectre-balance", True)