20#include "KoOdtFrameReportDocument.h"
21#include "KoOdtFrameReportPrimitive.h"
22#include "KReportRenderObjects.h"
24#include <KoOdfWriteStore.h>
25#include <KoXmlWriter.h>
27#include <KoOdfGraphicStyles.h>
28#include <KoGenStyles.h>
29#include <KoGenStyle.h>
30#include <KReportDpi.h>
32#include <QVarLengthArray>
33#include "kreport_debug.h"
35KoOdtFrameReportDocument::KoOdtFrameReportDocument()
40KoOdtFrameReportDocument::~KoOdtFrameReportDocument()
43 foreach(KoOdtFrameReportPrimitive *p, lst) {
49void KoOdtFrameReportDocument::setPageOptions(
const ReportPageOptions &pageOptions)
51 m_pageOptions = pageOptions;
54void KoOdtFrameReportDocument::startTable(
OROSection* section)
59void KoOdtFrameReportDocument::addPrimitive(KoOdtFrameReportPrimitive *data)
61 m_pagemap[data->pageNumber()].append( data);
67 KoStore *store = KoStore::createStore(path, KoStore::Write,
68 "application/vnd.oasis.opendocument.text", KoStore::Zip);
70 kreportWarning() <<
"Couldn't open the requested file.";
74 KoOdfWriteStore oasisStore(store);
75 manifestWriter = oasisStore.manifestWriter(
"application/vnd.oasis.opendocument.text");
76 if (!manifestWriter) {
81 foreach(KoOdtFrameReportPrimitive *p, lst) {
82 p->saveData(store, manifestWriter);
88 bool ok = createContent(&oasisStore, coll);
91 ok = coll.saveOdfStylesDotXml(store, manifestWriter);
93 ok = oasisStore.closeManifestWriter() &&
ok;
94 delete oasisStore.store();
99void KoOdtFrameReportDocument::createStyles(KoGenStyles *coll)
102 qreal pw = m_pageOptions.widthPx() / KReportPrivate::dpiX();
103 qreal ph = m_pageOptions.heightPx() / KReportPrivate::dpiY();
104 qreal topMargin = m_pageOptions.getMarginTop() / KReportPrivate::dpiY();
105 qreal bottomMargin = m_pageOptions.getMarginBottom() / KReportPrivate::dpiY();
106 qreal leftMargin = m_pageOptions.getMarginLeft() / KReportPrivate::dpiX();
107 qreal rightMargin = m_pageOptions.getMarginRight() / KReportPrivate::dpiX();
108 QString orientation = m_pageOptions.isPortrait() ?
"portrait" :
"landscape";
112 KoGenStyle page(KoGenStyle::PageLayoutStyle,
"page-layout");
113 page.addProperty(
"style:num-format",
"1");
114 page.addProperty(
"style:print-orientation", orientation);
115 page.addProperty(
"style:writing-mode",
"lr-tb");
116 page.addProperty(
"style:footnote-max-height",
"0cm");
118 page.addProperty(
"fo:page-width",
QString(
"%1in").arg(pw));
119 page.addProperty(
"fo:page-height",
QString(
"%1in").arg(ph));
120 page.addProperty(
"fo:margin-top",
QString(
"%1in").arg(topMargin));
121 page.addProperty(
"fo:margin-bottom",
QString(
"%1in").arg(bottomMargin));
122 page.addProperty(
"fo:margin-left",
QString(
"%1in").arg(leftMargin));
123 page.addProperty(
"fo:margin-right",
QString(
"%1in").arg(rightMargin));
124 page.setAutoStyleInStylesDotXml(
true);
127 KoGenStyle master(KoGenStyle::MasterPageStyle,
"master-page");
128 master.addAttribute(
"style:page-layout-name", pagename);
129 coll->insert(master,
"Standard", KoGenStyles::DontAddNumberToName);
131 KoGenStyle fs(KoGenStyle::GraphicStyle,
"graphic");
132 fs.addProperty(
"vertical-pos",
"from-top");
133 fs.addProperty(
"vertical-rel",
"page");
134 fs.addProperty(
"horizontal-pos",
"from-left");
135 fs.addProperty(
"horizontal-rel",
"page");
136 coll->insert(fs,
"Frame", KoGenStyles::DontAddNumberToName);
138 KoGenStyle ps(KoGenStyle::ParagraphStyle,
"paragraph");
139 ps.addAttribute(
"style:parent-style-name",
"Standard");
140 coll->insert(ps,
"P1", KoGenStyles::DontAddNumberToName);
143bool KoOdtFrameReportDocument::createContent(KoOdfWriteStore* store, KoGenStyles *coll)
145 KoXmlWriter* bodyWriter = store->bodyWriter();
146 KoXmlWriter* contentWriter = store->contentWriter();
148 if (!bodyWriter || !contentWriter || !manifestWriter) {
149 kreportWarning()<<
"Failed to created odt writer";
154 manifestWriter->addManifestEntry(
"content.xml",
"text/xml");
157 contentWriter->startElement(
"office:automatic-styles");
160 contentWriter->startElement(
"style:style");
161 contentWriter->addAttribute(
"style:name",
"NewPage");
162 contentWriter->addAttribute(
"style:master-page-name",
"Standard");
163 contentWriter->addAttribute(
"style:family",
"paragraph");
164 contentWriter->startElement(
"style:paragraph-properties");
165 contentWriter->addAttribute(
"fo:font-family",
"Arial");
166 contentWriter->addAttribute(
"fo:break-before",
"page");
167 contentWriter->endElement();
168 contentWriter->endElement();
170 contentWriter->startElement(
"text:sequence-decls");
171 contentWriter->startElement(
"text:sequence-decl");
172 contentWriter->addAttribute(
"text:display-outline-level",
"0");
173 contentWriter->addAttribute(
"text:name",
"Illustration");
174 contentWriter->endElement();
175 contentWriter->startElement(
"text:sequence-decl");
176 contentWriter->addAttribute(
"text:display-outline-level",
"0");
177 contentWriter->addAttribute(
"text:name",
"Table");
178 contentWriter->endElement();
179 contentWriter->startElement(
"text:sequence-decl");
180 contentWriter->addAttribute(
"text:display-outline-level",
"0");
181 contentWriter->addAttribute(
"text:name",
"Text");
182 contentWriter->endElement();
183 contentWriter->startElement(
"text:sequence-decl");
184 contentWriter->addAttribute(
"text:display-outline-level",
"0");
185 contentWriter->addAttribute(
"text:name",
"Drawing");
186 contentWriter->endElement();
187 contentWriter->endElement();
188 contentWriter->endElement();
191 bodyWriter->startElement(
"office:body");
192 bodyWriter->startElement(
"office:text");
194 createPages(bodyWriter, coll);
196 bodyWriter->endElement();
197 bodyWriter->endElement();
199 return store->closeContentWriter();
202void KoOdtFrameReportDocument::createPages(KoXmlWriter* bodyWriter, KoGenStyles *coll)
206 bodyWriter->startElement(
"text:p");
207 bodyWriter->addAttribute(
"text:style-name",
"NewPage");
209 foreach (KoOdtFrameReportPrimitive *data, it.
value()) {
210 data->createStyle(coll);
211 data->createBody(bodyWriter);
213 bodyWriter->endElement();
217 bodyWriter->startElement(
"text:p");
218 bodyWriter->addAttribute(
"text:style-name",
"P1");
219 bodyWriter->endElement();
Represents a single a single row in a document and may contain zero or more OROPrimitives.
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
T value(const Key &key, const T &defaultValue) const const
QString & insert(qsizetype position, QChar ch)