def setUp(self): d = OpenDocumentText() # Styles h1style = style.Style(name=u"Heading 1", family=u"paragraph") h1style.addElement( style.TextProperties(attributes={ 'fontsize': u"24pt", 'fontweight': u"bold" })) d.styles.addElement(h1style) boldstyle = style.Style(name=u"Bold", family=u"text") boldstyle.addElement( style.TextProperties(attributes={'fontweight': u"bold"})) d.automaticstyles.addElement(boldstyle) # Text h = H(outlinelevel=1, stylename=h1style, text=u"Simple test document") d.text.addElement(h) p = P( text= u"The earth's climate has not changed many times in the course of its long history. " ) d.text.addElement(p) boldpart = Span(stylename=boldstyle, text=u"This part is bold. ") p.addElement(boldpart) p.addText(u"This is after bold.") d.save(u"TEST.odt")
def testTable(self): """ Create a presentation with a page layout called MyLayout """ 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) # Style for the photo frame mainstyle = style.Style(name="MyMaster-main", family="presentation") presdoc.styles.addElement(mainstyle) # Create style for drawing page dpstyle = style.Style(name="dp1", family="drawing-page") presdoc.automaticstyles.addElement(dpstyle) page = draw.Page(stylename=dpstyle, masterpagename=masterpage) presdoc.presentation.addElement(page) titleframe = draw.Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt") page.addElement(titleframe) textbox = draw.TextBox() titleframe.addElement(textbox) textbox.addElement(text.P(text="Presentation")) mainframe = draw.Frame(stylename=mainstyle, width="720pt", height="500pt", x="0pt", y="56pt") page.addElement(mainframe) mainframe.addElement(table.Table())
def _make_layout(self, doc, layout, firstpage): # set paper dimensions pageLayout = style.PageLayout(name=u"pl1") doc.automaticstyles.addElement(pageLayout) plProp = style.PageLayoutProperties(pageheight=str(layout.height), pagewidth=str(layout.width), marginleft=str(layout.left), marginright=str(layout.right), margintop=str(layout.top), marginbottom=str(layout.bottom)) pageLayout.addElement(plProp) # add page numbers to the footers footer = style.Footer() foostyle = style.Style(name="Footer", family="paragraph") foostyle.addElement(style.ParagraphProperties(textalign='center')) foostyle.addElement(style.TextProperties(fontsize='10pt')) doc.automaticstyles.addElement(foostyle) p = text.P(stylename=foostyle) p.addElement( text.PageNumber(selectpage="current", pageadjust=str(firstpage - 1))) footer.addElement(p) masterpage = style.MasterPage(name=u"Standard", pagelayoutname=pageLayout) masterpage.addElement(footer) doc.masterstyles.addElement(masterpage)
def test_style(self): """ Get a common style with getStyleByName """ textdoc = OpenDocumentText() tablecontents = style.Style(name="Table Contents", family="paragraph") tablecontents.addElement(style.ParagraphProperties(numberlines="false", linenumber="0")) textdoc.styles.addElement(tablecontents) s = textdoc.getStyleByName('Table Contents') self.assertEquals((u'urn:oasis:names:tc:opendocument:xmlns:style:1.0', 'style'), s.qname)
def testAutomaticStyles(self): """ Create a text document with a page layout called "pagelayout" Add a master page Add an automatic style for the heading Check that pagelayout is listed in styles.xml under automatic-styles Check that the heading style is NOT listed in styles.xml Check that the pagelayout is NOT listed in content.xml """ textdoc = OpenDocumentText() parastyle = style.Style(name="Para", family="paragraph") parastyle.addElement( style.ParagraphProperties(numberlines="false", linenumber="0")) parastyle.addElement( style.TextProperties(fontsize="24pt", fontweight="bold")) textdoc.automaticstyles.addElement(parastyle) hpstyle = style.Style(name="HeaderPara", family="paragraph") hpstyle.addElement(style.ParagraphProperties(linenumber="0")) hpstyle.addElement( style.TextProperties(fontsize="18pt", fontstyle="italic")) textdoc.automaticstyles.addElement(hpstyle) pl = style.PageLayout(name="pagelayout") textdoc.automaticstyles.addElement(pl) mp = style.MasterPage(name="Standard", pagelayoutname=pl) textdoc.masterstyles.addElement(mp) h = style.Header() hp = text.P(text="header content", stylename=hpstyle) h.addElement(hp) mp.addElement(h) textdoc.text.addElement(text.P(text="Paragraph 1", stylename=parastyle)) # Check styles.xml s = textdoc.stylesxml() self.assertContains(s, u'<style:page-layout style:name="pagelayout"/>') self.assertContains(s, u'style:name="HeaderPara"') self.assertNotContains(s, u'style:name="Para" ') # Check content.xml s = textdoc.contentxml() # contentxml is supposed to yed a byts self.assertNotContains( s, b'<style:page-layout style:name="pagelayout"/>') self.assertContains(s, b'style:name="Para"')
def test_style(self): """ Get an automatic style with getStyleByName """ textdoc = OpenDocumentText() boldstyle = style.Style(name='Bold', family="text") boldstyle.addElement(style.TextProperties(fontweight="bold")) textdoc.automaticstyles.addElement(boldstyle) s = textdoc.getStyleByName('Bold') self.assertEquals((u'urn:oasis:names:tc:opendocument:xmlns:style:1.0', 'style'), s.qname)
def test_xstyle(self): self.assertRaises(UnicodeDecodeError, style.Style, name="X✗", family="paragraph") xstyle = style.Style(name=u"X✗", family=u"paragraph") pp = style.ParagraphProperties(padding=u"0.2cm") pp.setAttribute(u"backgroundcolor", u"rød") xstyle.addElement(pp) self.textdoc.styles.addElement(xstyle) self.textdoc.save(u"TEST.odt") self.saved = True
def textBold(self) -> style.Style: """ Return text bold property. @return Style Property. """ bold_style = style.Style(name="Bold", family="text") bold_style.addElement(style.TextProperties(fontweight="bold")) return bold_style
def textUnderline(self) -> style.Style: """ Return text bold property. @return Style Property. """ bold_style = style.Style(name="Underline", family="text") bold_style.addElement(style.TextProperties(fontstyle="underline")) return bold_style
def textItalic(self) -> style.Style: """ Return italic text. @return Style Property. """ italic_style = style.Style(name="Italic", family="text") italic_style.addElement(style.TextProperties(fontstyle="italic")) return italic_style
def testBadChild(self): """ Test that you can't add an illegal child """ tablecontents = style.Style(name=u"Table Contents", family=u"paragraph") p = text.P(text=u"x") with self.assertRaises(Exception) as cm: tablecontents.addElement(p) # FIXME: This doesn't work on Python 3. if sys.version_info[0] == 2: self.assertTrue(isinstance(cm.exception, IllegalChild))
def testBadChild(self): """ Test that you can't add an illegal child """ tablecontents = style.Style(name=u"Table Contents", family=u"paragraph") p = text.P(text=u"x") # something to fix here if sys.version_info.major == 3: print( "There is some bug to fix: the exception 'IllegalChild' is correctly raised, but the call of 'assertRaises' fails, only with Python3! See line 61 in `teststyles.py`." ) self.assertRaises(IllegalChild, tablecontents.addElement, p)
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"))
def _write_journal(self, journal): path = os.path.join( options.REPORTS_DIR, 'Журнал {} {} {}.odt'.format( self.year, self.months[self.month], self.doctor[1], )) doc = opendocument.OpenDocumentText() table_style = style.Style(name='tableStyle', family='table', masterpagename='masterQ') page_layout = style.PageLayout(name='pageStyle') page_layout.addElement( style.PageLayoutProperties( printorientation='landscape', margin='0cm', pagewidth='290cm', pageheight='21cm', )) master_q = style.MasterPage(name='masterQ', pagelayoutname=page_layout) doc.automaticstyles.addElement(table_style) doc.automaticstyles.addElement(page_layout) doc.masterstyles.addElement(master_q) journal = ([['Дата', 'ФИО', 'Дата Рождения', 'Адрес', 'Заключение']] + journal) _table = table.Table(name='journal') _table.addElement( table.TableColumn(numbercolumnsrepeated=len(journal[0]))) for data in journal: row = table.TableRow() _table.addElement(row) for col in data: cell = table.TableCell(valuetype='string') cell.addElement(text.P(text=str(col or ''))) row.addElement(cell) doc.text.addElement(_table) try: doc.save(path) except PermissionError: self.main_window.create_alert( 'Файл журнала используется.\nЗакройте его и создайте снова.') return self._open(path)
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"))
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:ns30="http://foreignuri.com"') s.index(u'<style:paragraph-properties ns30:enable-numbering="true"/>') s.index( u'<office:styles><style:style style:name="Standard" style:display-name="Standard" style:family="paragraph">' )
def testCalls(self): """ Simple calls """ for family in ("graphic", "presentation"): boldstyle = style.Style(name='Bold', family=family) dr3d.Cube(stylename=boldstyle) dr3d.Extrude(stylename=boldstyle, d="x", viewbox="0 0 1000 1000") dr3d.Rotate(stylename=boldstyle, d="x", viewbox="0 0 1000 1000") dr3d.Scene(stylename=boldstyle) dr3d.Sphere(stylename=boldstyle) draw.Caption(stylename=boldstyle) draw.Circle(stylename=boldstyle) draw.Connector(stylename=boldstyle) draw.Control(stylename=boldstyle, control="x") draw.CustomShape(stylename=boldstyle) draw.Ellipse(stylename=boldstyle) draw.Frame(stylename=boldstyle) draw.G(stylename=boldstyle) draw.Line(stylename=boldstyle, x1="0%", y1="0%", x2="100%", y2="100%") draw.Measure(stylename=boldstyle, x1="0cm", y1="0cm", x2="100%", y2="100%") draw.PageThumbnail(stylename=boldstyle) draw.Path(stylename=boldstyle, d="x", viewbox="0 0 1000 1000") draw.Polygon(stylename=boldstyle, points=((0, 0), (1, 1)), viewbox="0 0 1000 1000") draw.Polygon(stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000") draw.Polyline(stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000") draw.Rect(stylename=boldstyle) draw.RegularPolygon(stylename=boldstyle, corners="x") office.Annotation(stylename=boldstyle)
def __newCell__(self) -> Tuple[table.TableCell, style.Style]: """ Return new cell This is created by assigning the value to the previous one. @return Tuple(TableCell, Style) """ style_cell = style.Style( name="stylecell_%s_%s" % (len(self.cells_list_), self.sheet_.rowsCount()), family="table-cell", ) if self.row_color_: # Guardo color si hay style_cell.addElement( style.TableCellProperties(backgroundcolor="#%s" % self.row_color_) ) for prop in self.property_cell_: # Guardo prop cell si hay style_cell.addElement(prop) self.property_cell_ = [] return table.TableCell(valuetype="string", stylename=style_cell), style_cell
# -*- coding: utf-8 -*- """ Tablib - ODF Support. """ from io import BytesIO from odf import opendocument, style, table, text from tablib.compat import unicode title = 'ods' extensions = ('ods', ) bold = style.Style(name="bold", family="paragraph") bold.addElement( style.TextProperties(fontweight="bold", fontweightasian="bold", fontweightcomplex="bold")) def export_set(dataset): """Returns ODF representation of Dataset.""" wb = opendocument.OpenDocumentSpreadsheet() wb.automaticstyles.addElement(bold) ws = table.Table(name=dataset.title if dataset.title else 'Tablib Dataset') wb.spreadsheet.addElement(ws) dset_sheet(dataset, ws) stream = BytesIO() wb.save(stream) return stream.getvalue()
def __call__(self, doc): chartstyle = style.Style(name="chartstyle", family="chart") chartstyle.addElement( style.GraphicProperties(stroke="none", fillcolor="#ffffff")) doc.automaticstyles.addElement(chartstyle) mychart = chart.Chart( width="576pt", height="504pt", stylename=chartstyle, attributes={'class':self.charttype}) doc.chart.addElement(mychart) # Title if self.title: titlestyle = style.Style(name="titlestyle", family="chart") titlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) titlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="13pt")) doc.automaticstyles.addElement(titlestyle) mytitle = chart.Title(x="385pt", y="27pt", stylename=titlestyle) mytitle.addElement( text.P(text=self.title)) mychart.addElement(mytitle) # Subtitle if self.subtitle: subtitlestyle = style.Style(name="subtitlestyle", family="chart") subtitlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) subtitlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="10pt")) doc.automaticstyles.addElement(subtitlestyle) subtitle = chart.Subtitle(x="0pt", y="123pt", stylename=subtitlestyle) subtitle.addElement( text.P(text= self.subtitle)) mychart.addElement(subtitle) # Legend legendstyle = style.Style(name="legendstyle", family="chart") legendstyle.addElement( style.GraphicProperties(fill="none")) legendstyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="6pt")) doc.automaticstyles.addElement(legendstyle) mylegend = chart.Legend(legendposition="end", legendalign="center", stylename=legendstyle) mychart.addElement(mylegend) # Plot area plotstyle = style.Style(name="plotstyle", family="chart") if self.subtype == "stacked": percentage="false"; stacked="true" elif self.subtype == "percentage": percentage="true"; stacked="false" else: percentage="false"; stacked="false" plotstyle.addElement( style.ChartProperties(seriessource="columns", percentage=percentage, stacked=stacked, threedimensional=self.threedimensional)) doc.automaticstyles.addElement(plotstyle) plotarea = chart.PlotArea(datasourcehaslabels=self.datasourcehaslabels, stylename=plotstyle) mychart.addElement(plotarea) # Style for the X,Y axes axisstyle = style.Style(name="axisstyle", family="chart") axisstyle.addElement( style.ChartProperties(displaylabel="true")) doc.automaticstyles.addElement(axisstyle) # Title for the X axis xaxis = chart.Axis(dimension="x", name="primary-x", stylename=axisstyle) plotarea.addElement(xaxis) xt = chart.Title() xaxis.addElement(xt) xt.addElement(text.P(text=self.x_axis)) # Title for the Y axis yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle) plotarea.addElement(yaxis) yt = chart.Title() yaxis.addElement(yt) yt.addElement(text.P(text=self.y_axis)) # Data area datatable = DataTable( self.values ) datatable.datasourcehaslabels = self.datasourcehaslabels mychart.addElement(datatable())
def _make_styles(self, doc, layout): """Generate set of styles for the document. Parameters ---------- doc : `OpenDocumentText` ODT document object. layout : `PageLayout` ODT page layout. """ styles = {} # heading styles, occupies whole page, centered h1font = '22pt' h1topmrg = (layout.height - layout.top - layout.bottom) * 0.5 h1topmrg -= Size(h1font) h1style = style.Style(name="Heading 1", family="paragraph") h1style.addElement( style.ParagraphProperties(textalign='center', breakbefore='page', margintop=str(h1topmrg))) h1style.addElement( style.TextProperties(fontsize=h1font, fontweight='bold')) doc.styles.addElement(h1style) styles['h1'] = h1style brstyle = style.Style(name="Break", family="paragraph") brstyle.addElement( style.ParagraphProperties(textalign='center', breakafter='page')) doc.automaticstyles.addElement(brstyle) styles['br'] = brstyle h2namestyle = style.Style(name="Heading 2 (Name)", family="paragraph") h2namestyle.addElement( style.ParagraphProperties(textalign='center', breakbefore='page', marginbottom="14pt")) h2namestyle.addElement( style.TextProperties(fontsize='14pt', fontweight='bold')) doc.styles.addElement(h2namestyle) styles['h2br'] = h2namestyle h2style = style.Style(name="Heading 2", family="paragraph") h2style.addElement( style.ParagraphProperties(textalign='center', margintop="12pt")) h2style.addElement( style.TextProperties(fontsize='14pt', fontweight='bold')) doc.styles.addElement(h2style) styles['h2'] = h2style h3style = style.Style(name="Heading 3", family="paragraph") # h3style.addElement(style.ParagraphProperties(textalign='center', # margintop="12pt", borderbottom="0.06pt solid #000000")) h3style.addElement( style.ParagraphProperties(textalign='center', margintop="12pt")) h3style.addElement(style.TextProperties(fontweight='bold')) doc.styles.addElement(h3style) styles['h3'] = h3style # style for image imgstyle = style.Style(name="ImgStyle", family="graphic", parentstylename="Graphics") imgstyle.addElement( style.GraphicProperties(verticalpos='top', verticalrel='paragraph-content', horizontalpos='right', horizontalrel='page-content', marginleft="0.1in", marginbottom="0.1in")) doc.automaticstyles.addElement(imgstyle) styles['img'] = imgstyle # centered paragraph centered = style.Style(name="centered", family="paragraph") centered.addElement(style.ParagraphProperties(textalign='center')) doc.styles.addElement(centered) styles['center'] = centered # centered frame frame_center = style.Style(name="frame-center", family="graphic", parentstylename="Graphics") frame_center.addElement( style.GraphicProperties(horizontalpos="center", horizontalrel="paragraph")) doc.automaticstyles.addElement(frame_center) styles['frame_center'] = frame_center # style for tree table treetablestyle = style.Style(name="TreeTableStyle", family="table") treetablestyle.addElement(style.TableProperties(align='center')) doc.automaticstyles.addElement(treetablestyle) styles['treetable'] = treetablestyle treecellstyle = style.Style(name="TreeTableCellStyle", family="table-cell") treecellstyle.addElement( style.TableCellProperties(verticalalign='middle', padding='0.03in')) doc.automaticstyles.addElement(treecellstyle) styles['treecell'] = treecellstyle treeparastyle = style.Style(name="TreeTableParaStyle", family="paragraph") treeparastyle.addElement( style.ParagraphProperties(textalign='center', verticalalign='middle', border="0.06pt solid #000000", padding='0.01in')) treeparastyle.addElement(style.TextProperties(fontsize='10pt')) doc.automaticstyles.addElement(treeparastyle) styles['treepara'] = treeparastyle return styles
# Font Styles # see http://books.evc-cit.info/odbook/ch03.html#char-para-styling-section for a fast introdution # dejaVuSerif = style.FontFace( name="DejaVuSerif", fontfamily="'DejaVu Serif'", fontfamilygeneric="roman", fontpitch="variable") dejaVuSans = style.FontFace( name="DejaVuSans", fontfamily="'DejaVu Sans'", fontfamilygeneric="swiss", fontpitch="variable") dejaVuMono = style.FontFace( name="DejaVumono", fontfamily="'DejaVu mono'", fontfamilygeneric="modern", fontpitch="fixed") dejaVuSansMono = style.FontFace( name="DejaVuSansMono", fontfamily="'DejaVu Sans Mono'", fontfamilygeneric="swiss", fontpitch="fixed") # # Section styles # sect = style.Style(name="Sect1", family="section") sectTable = style.Style(name="SectTable", family="section") # # Paragraph styles # # textbody is the default for text textbody = style.Style(name="TextBody", family="paragraph") textbody.addElement( style.ParagraphProperties( marginbottom="0.05in", margintop="0.04in", textalign="left", punctuationwrap="hanging", linebreak="strict", orphans="3", keeptogether="always",
def testAttribute(self): """ Test that you can add a normal attributes using 'qattributes' """ standard = style.Style(name=u"Standard", family=u"paragraph") p = style.ParagraphProperties( qattributes={(TEXTNS, u'enable-numbering'): 'true'}) standard.addElement(p)
def testTextStyleName(self): """ Test that you can use the name of the style in references """ boldstyle = style.Style(name=u"Bold", family=u"text") boldstyle.addElement( style.TextProperties(attributes={u'fontweight': u"bold"})) text.Span(stylename=u"Bold", text=u"This part is bold. ")
def testBadFamily(self): """ Family must be graphic or presentation """ boldstyle = style.Style(name='Bold', family="paragraph") self.assertRaises(ValueError, dr3d.Cube, stylename=boldstyle) self.assertRaises(ValueError, dr3d.Cube, stylename=boldstyle) self.assertRaises(ValueError, dr3d.Extrude, stylename=boldstyle, d="x", viewbox="0 0 1000 1000") self.assertRaises(ValueError, dr3d.Rotate, stylename=boldstyle, d="x", viewbox="0 0 1000 1000") self.assertRaises(ValueError, dr3d.Scene, stylename=boldstyle) self.assertRaises(ValueError, dr3d.Sphere, stylename=boldstyle) self.assertRaises(ValueError, draw.Caption, stylename=boldstyle) self.assertRaises(ValueError, draw.Circle, stylename=boldstyle) self.assertRaises(ValueError, draw.Connector, stylename=boldstyle) self.assertRaises(ValueError, draw.Control, stylename=boldstyle, control="x") self.assertRaises(ValueError, draw.CustomShape, stylename=boldstyle) self.assertRaises(ValueError, draw.Ellipse, stylename=boldstyle) self.assertRaises(ValueError, draw.Frame, stylename=boldstyle) self.assertRaises(ValueError, draw.G, stylename=boldstyle) self.assertRaises(ValueError, draw.Line, stylename=boldstyle, x1="0", y1="0", x2="1", y2="1") self.assertRaises(ValueError, draw.Measure, stylename=boldstyle, x1="0", y1="0", x2="1", y2="1") self.assertRaises(ValueError, draw.PageThumbnail, stylename=boldstyle) self.assertRaises(ValueError, draw.Path, stylename=boldstyle, d="x", viewbox="0 0 1000 1000") self.assertRaises(ValueError, draw.Polygon, stylename=boldstyle, points=((0, 0), (1, 1)), viewbox="0 0 1000 1000") self.assertRaises(ValueError, draw.Polygon, stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000") self.assertRaises(ValueError, draw.Polyline, stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000") self.assertRaises(ValueError, draw.Rect, stylename=boldstyle) self.assertRaises(ValueError, draw.RegularPolygon, stylename=boldstyle, corners="x") self.assertRaises(ValueError, office.Annotation, stylename=boldstyle)
if language is not None: doc.meta.addElement(dc.Language(text=language)) if publisher is not None: # doc.meta.addElement(dc.Publisher(text=publisher)) doc.meta.addElement(meta.UserDefined(name="Publisher", text=publisher)) if copyrights is not None: # doc.meta.addElement(dc.Rights(text=copyrights)) doc.meta.addElement(meta.UserDefined(name="Rights", text=copyrights)) if ebooknum is not None: doc.meta.addElement(meta.UserDefined(name="EText", text=ebooknum)) arial = style.FontFace(name="Arial", fontfamily="Arial", fontfamilygeneric="swiss", fontpitch="variable") doc.fontfacedecls.addElement(arial) # Paragraph styles standardstyle = style.Style(name="Standard", family="paragraph") standardstyle.addElement(style.ParagraphProperties(marginbottom="0cm", margintop="0cm" )) doc.styles.addElement(standardstyle) h1style = style.Style(name="Heading 1", family="paragraph", defaultoutlinelevel="1") h1style.addElement(style.TextProperties(attributes={'fontsize':"20pt", 'fontweight':"bold"})) doc.styles.addElement(h1style) textbodystyle = style.Style(name="Text body", family="paragraph", parentstylename=standardstyle) textbodystyle.addElement(style.ParagraphProperties(attributes={'marginbottom':"0.212cm", 'margintop':"0cm", 'textalign':"justify", 'justifysingleword':"false"})) doc.styles.addElement(textbodystyle) subtitlestyle = style.Style(name="Subtitle", family="paragraph", nextstylename=textbodystyle) subtitlestyle.addElement(style.ParagraphProperties(textalign="center") ) subtitlestyle.addElement(style.TextProperties(fontsize="14pt", fontstyle="italic", fontname="Arial"))
def __call__(self, doc): chartstyle = style.Style(name="chartstyle", family="chart") chartstyle.addElement( style.GraphicProperties(stroke="none", fillcolor="#ffffff")) doc.automaticstyles.addElement(chartstyle) mychart = chart.Chart(width=self.width, height=self.height, stylename=chartstyle, attributes={'class': self.charttype}) doc.chart.addElement(mychart) # Title if self.title: titlestyle = style.Style(name="titlestyle", family="chart") titlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) titlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="13pt")) doc.automaticstyles.addElement(titlestyle) mytitle = chart.Title(x="185pt", y="27pt", stylename=titlestyle) mytitle.addElement(text.P(text=self.title)) mychart.addElement(mytitle) # Subtitle if self.subtitle: subtitlestyle = style.Style(name="subtitlestyle", family="chart") subtitlestyle.addElement( style.GraphicProperties(stroke="none", fill="none")) subtitlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="10pt")) doc.automaticstyles.addElement(subtitlestyle) subtitle = chart.Subtitle(x="50pt", y="50pt", stylename=subtitlestyle) subtitle.addElement(text.P(text=self.subtitle)) mychart.addElement(subtitle) # Legend legendstyle = style.Style(name="legendstyle", family="chart") legendstyle.addElement(style.GraphicProperties(fill="none")) legendstyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="8pt")) doc.automaticstyles.addElement(legendstyle) mylegend = chart.Legend(legendposition="end", legendalign="center", stylename=legendstyle) mychart.addElement(mylegend) # Plot area plotstyle = style.Style(name="plotstyle", family="chart") if self.subtype == "stacked": percentage = "false" stacked = "true" elif self.subtype == "percentage": percentage = "true" stacked = "false" else: percentage = "false" stacked = "false" plotstyle.addElement( style.ChartProperties(seriessource="columns", percentage=percentage, stacked=stacked, threedimensional=self.threedimensional)) doc.automaticstyles.addElement(plotstyle) plotarea = chart.PlotArea(datasourcehaslabels=self.datasourcehaslabels, stylename=plotstyle) mychart.addElement(plotarea) # Style for the X,Y axes axisstyle = style.Style(name="axisstyle", family="chart") axisstyle.addElement(style.ChartProperties(displaylabel="true")) axisstyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'", fontfamilygeneric="swiss", fontpitch="variable", fontsize="8pt")) doc.automaticstyles.addElement(axisstyle) # Title for the X axis xaxis = chart.Axis(dimension="x", name="primary-x", stylename=axisstyle) plotarea.addElement(xaxis) xt = chart.Title() xaxis.addElement(xt) xt.addElement(text.P(text=self.x_axis)) # Title for the Y axis yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle) plotarea.addElement(yaxis) yt = chart.Title() yaxis.addElement(yt) yt.addElement(text.P(text=self.y_axis)) # chart colors piestyle = style.Style(name="series", family="chart") piestyle.addElement(style.GraphicProperties(fillcolor="#000000")) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.critical", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskCritical)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.high", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskHigh)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.medium", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskMedium)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.low", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskLow)) doc.automaticstyles.addElement(piestyle) piestyle = style.Style(name="piestyle.none", family="chart") piestyle.addElement(style.ChartProperties(solidtype="cuboid")) piestyle.addElement(style.GraphicProperties(fillcolor=riskNone)) doc.automaticstyles.addElement(piestyle) # Set up the data series. OOo doesn't show correctly without them. s = chart.Series(valuescellrangeaddress="local-table.$B$2:.$B$6", labelcelladdress="local-table.$B$1", attributes={'class': self.charttype}, stylename="series") s.addElement(chart.DataPoint(stylename="piestyle.critical")) s.addElement(chart.DataPoint(stylename="piestyle.high")) s.addElement(chart.DataPoint(stylename="piestyle.medium")) s.addElement(chart.DataPoint(stylename="piestyle.low")) s.addElement(chart.DataPoint(stylename="piestyle.none")) plotarea.addElement(s) # The data are placed in a table inside the chart object - but could also be a # table in the main document datatable = DataTable(self.values) datatable.datasourcehaslabels = self.datasourcehaslabels mychart.addElement(datatable())
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Contributor(s): # from xliff_parser import HandleXliffParsing import sys from odf.opendocument import OpenDocumentText from odf import style, table from odf.text import P, UserFieldDecls, UserFieldDecl, UserFieldInput from odf.namespaces import TABLENS textdoc = OpenDocumentText() # Create a style for the table content. One we can modify # later in the word processor. tablecontents = style.Style(name="Table Contents", family="paragraph") tablecontents.addElement(style.ParagraphProperties(numberlines="false", linenumber="0")) textdoc.styles.addElement(tablecontents) #tablestyle = style.Style(name="Table style", family="table") #tablestyle.addElement(style.TableProperties(protected="true")) #textdoc.automaticstyles.addElement(tablestyle) # Create automatic styles for the column widths. widthwide = style.Style(name="Wwide", family="table-column") widthwide.addElement(style.TableColumnProperties(columnwidth="8cm")) textdoc.automaticstyles.addElement(widthwide) tcstyle = style.Style(name="Table Cell", family="table-cell") tcstyle.addElement(style.TableCellProperties(cellprotect="protected")) textdoc.automaticstyles.addElement(tcstyle)
def create_cell_styles(doc): warning = style.Style(family="table-cell", name="warning", parentstylename="Default") warning.addElement(style.TableCellProperties(backgroundcolor="#d85c41")) doc.styles.addElement(warning)
def testBadChild(self): """ Test that you can't add an illegal child """ tablecontents = style.Style(name="Table Contents", family="paragraph") p = text.P(text="x") self.assertRaises(IllegalChild, tablecontents.addElement,p)