File indexing completed on 2025-01-19 13:27:36
0001 /* 0002 * This file is part of Office 2007 Filters for Calligra 0003 * 0004 * Copyright (C) 2010 Sebastian Sauer <sebsauer@kdab.com> 0005 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 0006 * 0007 * Contact: Suresh Chande suresh.chande@nokia.com 0008 * 0009 * This library is free software; you can redistribute it and/or 0010 * modify it under the terms of the GNU Lesser General Public License 0011 * version 2.1 as published by the Free Software Foundation. 0012 * 0013 * This library is distributed in the hope that it will be useful, but 0014 * WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Lesser General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Lesser General Public 0019 * License along with this library; if not, write to the Free Software 0020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 0021 * 02110-1301 USA 0022 * 0023 */ 0024 0025 #ifndef XLSXXMLDRAWINGREADER_H 0026 #define XLSXXMLDRAWINGREADER_H 0027 0028 #include <MsooXmlTheme.h> 0029 #include <MsooXmlCommonReader.h> 0030 0031 #include <KoXmlWriter.h> 0032 #include <KoBorder.h> // Needed in DrawingMLMethods.h 0033 0034 0035 class XlsxImport; 0036 class XlsxXmlWorksheetReaderContext; 0037 class XlsxXmlChartReaderContext; 0038 class XlsxXmlEmbeddedPicture; 0039 class Sheet; 0040 0041 namespace MSOOXML 0042 { 0043 class MsooXmlDiagramReaderContext; 0044 } 0045 0046 0047 class XlsxShape { 0048 }; 0049 0050 class XlsxDrawingObject { 0051 public: 0052 Sheet* m_sheet; 0053 enum Type { 0054 Unknown, 0055 Chart, 0056 Diagram, 0057 Picture, 0058 Shape 0059 }; 0060 Type m_type; 0061 union { 0062 XlsxXmlChartReaderContext* m_chart; 0063 MSOOXML::MsooXmlDiagramReaderContext* m_diagram; 0064 XlsxXmlEmbeddedPicture* m_picture; 0065 XlsxShape* m_shape; 0066 }; 0067 enum AnchorType { 0068 NoAnchor, 0069 FromAnchor, 0070 ToAnchor 0071 }; 0072 struct Position { 0073 int m_row, m_col, m_rowOff, m_colOff; 0074 Position() : m_row(0), m_col(0), m_rowOff(0), m_colOff(0) {} 0075 }; 0076 QMap<AnchorType, Position> m_positions; 0077 explicit XlsxDrawingObject(Sheet* sheet) : m_sheet(sheet), m_type(Unknown), m_shapeBody(0) {} 0078 ~XlsxDrawingObject() { delete m_shapeBody; } 0079 void setPicture(XlsxXmlEmbeddedPicture* picture) { m_type = Picture; m_picture = picture; } 0080 void setChart(XlsxXmlChartReaderContext* chart) { m_type = Chart; m_chart = chart; } 0081 void setDiagram(MSOOXML::MsooXmlDiagramReaderContext* diagram) { m_type = Diagram; m_diagram = diagram; } 0082 KoXmlWriter* setShape(XlsxShape* shape); 0083 void save(KoXmlWriter* xmlWriter); 0084 0085 KoXmlWriter * pictureWriter(); 0086 0087 0088 /** 0089 * @return true if drawing object is anchored to cell 0090 * Presence of FromAnchor position is tested 0091 */ 0092 bool isAnchoredToCell() const; 0093 0094 /** 0095 * @return From anchor cell address 0096 * @see toCellAddress() 0097 */ 0098 0099 QString fromCellAddress() const; 0100 /** 0101 * @return End anchor cell address, in format like Sheetname.A5, 0102 * empty string if no ToAnchor position is available 0103 * 0104 */ 0105 QString toCellAddress() const; 0106 0107 private: 0108 QRect positionRect() const; 0109 /** 0110 * Computes the cell address name in xlsx documents 0111 * 0112 * @return For sheetname "Sheet" and row 0, column 0 returns "Sheet.A1", 0113 * for row 0, column 1 "Sheet.B1" etc. 0114 * for row 1, column 0 "Sheet.A2" etc. 0115 */ 0116 QString cellAddress(const QString &sheetname, int row, int column) const; 0117 0118 KoXmlWriter* m_shapeBody; 0119 }; 0120 0121 class XlsxXmlDrawingReaderContext : public MSOOXML::MsooXmlReaderContext 0122 { 0123 public: 0124 XlsxXmlDrawingReaderContext(XlsxXmlWorksheetReaderContext* _worksheetReaderContext, Sheet* _sheet, const QString& _path, const QString& _file); 0125 ~XlsxXmlDrawingReaderContext() override; 0126 0127 XlsxImport* import; 0128 QString path; // contains the path to the file which is being processed (i.e. 'xl/drawings') 0129 QString file; // contains the name of the file which is being processed (i.e. 'drawing1.xml') 0130 const MSOOXML::DrawingMLTheme* themes; 0131 0132 XlsxXmlWorksheetReaderContext* worksheetReaderContext; 0133 Sheet* sheet; 0134 quint32 m_groupDepthCounter; // How deep we currently are 0135 }; 0136 0137 class XlsxXmlDrawingReader : public MSOOXML::MsooXmlCommonReader 0138 { 0139 public: 0140 explicit XlsxXmlDrawingReader(KoOdfWriters *writers); 0141 ~XlsxXmlDrawingReader() override; 0142 KoFilter::ConversionStatus read(MSOOXML::MsooXmlReaderContext* context = 0) override; 0143 0144 protected: 0145 KoFilter::ConversionStatus read_oneCellAnchor(); 0146 KoFilter::ConversionStatus read_twoCellAnchor(); 0147 KoFilter::ConversionStatus read_absoluteAnchor(); 0148 KoFilter::ConversionStatus read_anchor(const QString& reference); 0149 KoFilter::ConversionStatus read_from(); 0150 KoFilter::ConversionStatus read_to(); 0151 KoFilter::ConversionStatus read_col(); 0152 KoFilter::ConversionStatus read_row(); 0153 KoFilter::ConversionStatus read_colOff(); 0154 KoFilter::ConversionStatus read_rowOff(); 0155 KoFilter::ConversionStatus read_graphicFrame(); 0156 KoFilter::ConversionStatus read_graphic2(); 0157 KoFilter::ConversionStatus read_graphicData2(); 0158 KoFilter::ConversionStatus read_chart2(); 0159 KoFilter::ConversionStatus read_diagram(); 0160 private: 0161 XlsxXmlDrawingReaderContext *m_context; 0162 XlsxDrawingObject *m_currentDrawingObject; 0163 XlsxDrawingObject::AnchorType m_anchorType; 0164 int m_chartNumber; 0165 0166 #include <MsooXmlCommonReaderMethods.h> 0167 #include <MsooXmlCommonReaderDrawingMLMethods.h> 0168 // #include <MsooXmlDrawingReaderTableMethods.h> 0169 0170 Q_DISABLE_COPY(XlsxXmlDrawingReader) 0171 }; 0172 0173 // This class is used for storing information about embedded pictures. 0174 // It's saving service is used in XlsxXmlDrawingReader.cpp, it's created in MsooXmlCommonReaderDrawingMLImpl.h 0175 class XlsxXmlEmbeddedPicture 0176 { 0177 public: 0178 XlsxXmlEmbeddedPicture(); 0179 ~XlsxXmlEmbeddedPicture(); 0180 0181 /** 0182 * Use this pointer for KoXmlWriter for writing odf representing 0183 * the image anchored/embedded to element like cell. 0184 * The ownership of this pointer belong to XlsxXmlEmbeddedPicture class. 0185 * */ 0186 KoXmlWriter * pictureWriter(); 0187 0188 /** 0189 * Save the .xml part of the picture (the picture itself isn't stored here) 0190 * @return true if saving was successful 0191 * */ 0192 bool saveXml(KoXmlWriter *xmlWriter); 0193 0194 private: 0195 KoXmlWriter * m_pictureWriter; 0196 QBuffer m_pictureBuffer; 0197 }; 0198 0199 #endif