File indexing completed on 2024-05-12 04:43:22
0001 /* This file is part of the KDE project 0002 Copyright (C) 2011, 2012 by Dag Andersen (danders@get2net.dk) 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoOdtFrameReportPicture.h" 0021 #include "KReportRenderObjects.h" 0022 0023 #include <KoXmlWriter.h> 0024 #include <KoOdfGraphicStyles.h> 0025 #include <KoGenStyle.h> 0026 #include <KoGenStyles.h> 0027 #include <KReportUnit.h> 0028 #include <KoStore.h> 0029 #include <KoStoreDevice.h> 0030 0031 #include <QPainter> 0032 #include "kreport_debug.h" 0033 #include <QMimeDatabase> 0034 #include <QMimeType> 0035 0036 KoOdtFrameReportPicture::KoOdtFrameReportPicture(OROPrimitive *primitive) 0037 : KoOdtFrameReportPrimitive(primitive) 0038 { 0039 } 0040 0041 KoOdtFrameReportPicture::~KoOdtFrameReportPicture() 0042 { 0043 } 0044 0045 OROPicture *KoOdtFrameReportPicture::picture() const 0046 { 0047 return dynamic_cast<OROPicture*>(m_primitive); 0048 } 0049 0050 void KoOdtFrameReportPicture::createBody(KoXmlWriter *bodyWriter) const 0051 { 0052 bodyWriter->startElement("draw:frame"); 0053 bodyWriter->addAttribute("draw:id", itemName()); 0054 bodyWriter->addAttribute("xml:id", itemName()); 0055 bodyWriter->addAttribute("draw:name", itemName()); 0056 bodyWriter->addAttribute("text:anchor-type", "page"); 0057 bodyWriter->addAttribute("text:anchor-page-number", pageNumber()); 0058 bodyWriter->addAttribute("draw:style-name", m_frameStyleName); 0059 0060 commonAttributes(bodyWriter); 0061 0062 bodyWriter->startElement("draw:image"); 0063 bodyWriter->addAttribute("xlink:href", "Pictures/" + pictureName()); 0064 bodyWriter->addAttribute("xlink:type", "simple"); 0065 bodyWriter->addAttribute("xlink:show", "embed"); 0066 bodyWriter->addAttribute("xlink:actuate", "onLoad"); 0067 bodyWriter->endElement(); 0068 0069 bodyWriter->endElement(); // draw:frame 0070 } 0071 0072 bool KoOdtFrameReportPicture::saveData(KoStore* store, KoXmlWriter* manifestWriter) const 0073 { 0074 QString name = "Pictures/" + pictureName(); 0075 if (!store->open(name)) { 0076 return false; 0077 } 0078 KoStoreDevice device(store); 0079 QImage image(m_primitive->size().toSize(), QImage::Format_ARGB32); 0080 image.fill(0); 0081 QPainter painter; 0082 painter.begin(&image); 0083 painter.setRenderHint(QPainter::Antialiasing); 0084 painter.drawPicture(0, 0, *(picture()->picture())); 0085 painter.end(); 0086 //kreportDebug()<<image.format(); 0087 bool ok = image.save(&device, "PNG"); 0088 if (ok) { 0089 QMimeDatabase db; 0090 const QString mimetype(db.mimeTypeForFile(name, QMimeDatabase::MatchExtension).name()); 0091 manifestWriter->addManifestEntry(name, mimetype); 0092 } 0093 ok = store->close() && ok; 0094 return ok; 0095 }