Warning, file /office/calligra/filters/libmsooxml/MsooXmlCommonReader.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * This file is part of Office 2007 Filters for Calligra
0003  *
0004  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
0005  *
0006  * Contact: Suresh Chande suresh.chande@nokia.com
0007  *
0008  * This library is free software; you can redistribute it and/or
0009  * modify it under the terms of the GNU Lesser General Public License
0010  * version 2.1 as published by the Free Software Foundation.
0011  *
0012  * This library is distributed in the hope that it will be useful, but
0013  * WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020  * 02110-1301 USA
0021  *
0022  */
0023 
0024 #include "MsooXmlCommonReader.h"
0025 #include <KoXmlWriter.h>
0026 #include <KoGenStyles.h>
0027 
0028 #include <QMap>
0029 
0030 using namespace MSOOXML;
0031 
0032 MsooXmlCommonReader::MsooXmlCommonReader(KoOdfWriters *writers)
0033         : MsooXmlReader(writers)
0034 {
0035     init();
0036 }
0037 
0038 MsooXmlCommonReader::MsooXmlCommonReader(QIODevice* io, KoOdfWriters *writers)
0039         : MsooXmlReader(io, writers)
0040 {
0041     init();
0042 }
0043 
0044 MsooXmlCommonReader::~MsooXmlCommonReader()
0045 {
0046     delete m_currentTextStyleProperties;
0047     m_currentTextStyleProperties = nullptr;
0048 }
0049 
0050 void MsooXmlCommonReader::init()
0051 {
0052     m_currentTextStyleProperties = 0;
0053     m_read_p_args = 0;
0054     m_pPr_lvl = 0;
0055     m_addManifestEntryForPicturesDirExecuted = false;
0056     m_moveToStylesXml = false;
0057 }
0058 
0059 //! CASE #420
0060 bool MsooXmlCommonReader::isDefaultTocStyle(const QString& name) const
0061 {
0062     if (name == QLatin1String("TOCHeading"))
0063         return true;
0064     if (name.startsWith(QLatin1String("TOC"))) {
0065         const QString num(name.mid(3));
0066         if (num.length() == 1 && num[0].isDigit() && num[0] != '0')
0067             return true;
0068     }
0069     return false;
0070 }
0071 
0072 void MsooXmlCommonReader::setupParagraphStyle()
0073 {
0074     if (m_moveToStylesXml) {
0075         m_currentParagraphStyle.setAutoStyleInStylesDotXml(true);
0076     }
0077 
0078     QString currentParagraphStyleName(mainStyles->insert(m_currentParagraphStyle));
0079     if (currentParagraphStyleName.isEmpty()) {
0080         currentParagraphStyleName = QLatin1String("Standard");
0081     }
0082     body->addAttribute("text:style-name", currentParagraphStyleName);
0083     m_paragraphStyleNameWritten = true;
0084 //debugMsooXml << "currentParagraphStyleName:" << currentParagraphStyleName;
0085 }
0086 
0087 class MediaTypeMap : public QMap<QByteArray, QByteArray>
0088 {
0089 public:
0090     MediaTypeMap() {
0091         insert("bmp", "image/x-bmp");
0092         insert("gif", "image/gif");
0093         insert("jpg", "image/jpeg");
0094         insert("jpeg", "image/jpeg");
0095         insert("jpe", "image/jpeg");
0096         insert("jfif", "image/jpeg");
0097         insert("tif", "image/tiff");
0098         insert("tiff", "image/tiff");
0099         insert("png", "image/png");
0100         insert("emf", "application/x-openoffice-wmf;windows_formatname=\"Image EMF\"");
0101         insert("wmf", "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"");
0102         insert("bin", "application/vnd.sun.star.oleobject");
0103         insert("xls", "application/vnd.sun.star.oleobject");
0104         insert("doc", "application/vnd.sun.star.oleobject");
0105         insert("ppt", "application/vnd.sun.star.oleobject");
0106         insert("", "application/vnd.sun.star.oleobject");
0107     }
0108 };
0109 
0110 void MsooXmlCommonReader::pushCurrentDrawStyle(KoGenStyle *newStyle)
0111 {
0112     m_drawStyleStack.append(m_currentDrawStyle);
0113 
0114     // This step also takes ownership, so we have to delete it when popping.
0115     m_currentDrawStyle = newStyle;
0116 }
0117 
0118 void MsooXmlCommonReader::popCurrentDrawStyle()
0119 {
0120     Q_ASSERT(!m_drawStyleStack.isEmpty());
0121 
0122     delete m_currentDrawStyle;
0123     m_currentDrawStyle = m_drawStyleStack.last();
0124     m_drawStyleStack.removeLast();
0125 }
0126 
0127 Q_GLOBAL_STATIC(MediaTypeMap, g_mediaTypes)
0128 
0129 void MsooXmlCommonReader::addManifestEntryForFile(const QString& path)
0130 {
0131     if (path.isEmpty())
0132         return;
0133 
0134     if (path.endsWith('/')) { // dir
0135         manifest->addManifestEntry(path, QString());
0136         return;
0137     }
0138     const int lastDot = path.lastIndexOf(QLatin1Char('.'));
0139     const QByteArray ext(path.mid(lastDot + 1).toLatin1().toLower());
0140     manifest->addManifestEntry(path, g_mediaTypes->value(ext));
0141 }
0142 
0143 //! Adds manifest entry for "Pictures/"
0144 void MsooXmlCommonReader::addManifestEntryForPicturesDir()
0145 {
0146     if (m_addManifestEntryForPicturesDirExecuted)
0147         return;
0148     m_addManifestEntryForPicturesDirExecuted = true;
0149     manifest->addManifestEntry("Pictures/", QString());
0150 }