1 /*
2  * This file is part of Office 2007 Filters for Calligra
3  *
4  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Suresh Chande suresh.chande@nokia.com
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
24 #ifndef MSOOXMLCOMMONREADER_H
25 #define MSOOXMLCOMMONREADER_H
26 
27 #include <KoGenStyle.h>
28 #include <styles/KoCharacterStyle.h>
29 #include <styles/KoListLevelProperties.h>
30 
31 #include "MsooXmlReader.h"
32 #include "MsooXmlUtils.h"
33 
34 namespace MSOOXML
35 {
36 
37 //! A class reading generic parts of MSOOXML main document's markup.
38 class KOMSOOXML_EXPORT MsooXmlCommonReader : public MsooXmlReader
39 {
40 protected:
41     explicit MsooXmlCommonReader(KoOdfWriters *writers);
42 
43     MsooXmlCommonReader(QIODevice* io, KoOdfWriters *writers);
44 
45     ~MsooXmlCommonReader() override;
46 
47     // -- for read_p()
48     enum read_p_arg {
49         read_p_Skip
50     };
51     Q_DECLARE_FLAGS(read_p_args, read_p_arg)
52     read_p_args m_read_p_args;
53 
54     KoGenStyle* m_currentDrawStyle; //! used by all classes that need a graphics style.
55     QList<KoGenStyle*>  m_drawStyleStack;
56     KoGenStyle m_currentGradientStyle;
57     void pushCurrentDrawStyle(KoGenStyle *newStyle);
58     void popCurrentDrawStyle();
59 
60     //! Used for creating style in w:pPr (style:style/\@style:name attr)
61     KoGenStyle m_currentParagraphStyle;
62 
63     void setupParagraphStyle();
64 
65     KoGenStyle m_currentTextStyle;
66     KoCharacterStyle* m_currentTextStyleProperties;
67 
68     KoGenStyle m_currentListStyle;
69     MSOOXML::Utils::ParagraphBulletProperties m_currentBulletProperties;
70     // Properties for potentially all 9 lvls which are possible
71     QMap<int, MSOOXML::Utils::ParagraphBulletProperties> m_currentCombinedBulletProperties;
72     QMap<int, KoGenStyle> m_currentCombinedParagraphStyles;
73     QMap<int, KoGenStyle> m_currentCombinedTextStyles;
74 
75     //! Style (from styles.xml) to apply to the current paragraph or similar element, set by read_pStyle()
76     QString m_currentStyleName;
77 
78     bool isDefaultTocStyle(const QString& name) const;
79 
80     //! Adds reference to a file in the ODF document to manifest.xml
81     //! The media-type attribute is based on the extension of @p path.
82     void addManifestEntryForFile(const QString& path);
83 
84     //! Adds manifest entry for "Pictures/"
85     void addManifestEntryForPicturesDir();
86 
87     //! value of recent pPr_lvl attribute; set by read_pPr()
88     uint m_pPr_lvl;
89 
90     bool m_paragraphStyleNameWritten; //!< set by setupParagraphStyle()
91 
92     bool m_addManifestEntryForPicturesDirExecuted;
93 
94     bool m_moveToStylesXml;
95 
96     QSize m_imageSize;
97 
98     QSet<QString> m_copiedFiles; //!< collects source names to avoid multiple copying of media files
99 
100 //    //! Used for creating style names (style:style/@style:name attr)
101 //    //! To achieve this, in XSLT it generate-id(.) for w:p is used.
102 //    ////! Starts with 1. Updated in read_p();
103 //    uint m_currentParagraphStyleNumber;
104 //    QString currentParagraphStyleName() const;
105 private:
106     Q_DISABLE_COPY(MsooXmlCommonReader)
107 
108     void init();
109 };
110 
111 }
112 
113 #endif
114