1 /*
2 * This file is part of Office 2007 Filters for Calligra
3 *
4 * Copyright (C) 2009-2010 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_IMPL_H
25 #define MSOOXMLCOMMONREADER_IMPL_H
26
27 #include <KoXmlWriter.h>
28
initInternal()29 void MSOOXML_CURRENT_CLASS::initInternal()
30 {
31 m_insideHdr = false;
32 m_insideFtr = false;
33 m_hasPosOffsetH = false;
34 m_hasPosOffsetV = false;
35 m_posOffsetH = 0;
36 m_posOffsetV = 0;
37 m_currentTextStyleProperties = 0;
38 m_read_t_args = false;
39 }
40
doneInternal()41 void MSOOXML_CURRENT_CLASS::doneInternal()
42 {
43 delete m_currentTextStyleProperties;
44 m_currentTextStyleProperties = nullptr;
45 }
46
47 #undef CURRENT_EL
48 #define CURRENT_EL t
49 //! t (Text)
50 //! ECMA-376, 17.3.3.31, p.379. (WordprocessingML)
51 //! ECMA-376, 21.1.2.3.11, p.3632 (DrawingML)
52 //! ECMA-376, 22.1.2.116, p.4226 (MathML)
53 /*! This element specifies the actual text for this text run. This is
54 the text that is formatted using all specified body, paragraph and
55 run properties. This element shall be present within a run of text.
56
57 Parent elements:
58 ----------------
59 WordprocessingML:
60 - r (§22.1.2.87)
61 - [done] r (§17.3.2.25)
62
63 DrawingML:
64 - [done] fld (§21.1.2.2.4)
65 - [done] r (§21.1.2.3.8)
66
67 No child elements.
68 */
69 //! @todo support all elements
read_t()70 KoFilter::ConversionStatus MSOOXML_CURRENT_CLASS::read_t()
71 {
72 if (m_read_t_args) {
73 READ_PROLOGUE_IF_NS(a)
74 } else {
75 READ_PROLOGUE
76 }
77
78 while (!atEnd()) {
79 readNext();
80 //debugMsooXml << *this;
81 if (isCharacters()) {
82 body->addTextSpan(text().toString());
83 #ifdef PPTXXMLSLIDEREADER_CPP
84 d->textBoxHasContent = true;
85 #endif
86 }
87 if (m_read_t_args) {
88 BREAK_IF_END_OF_WITH_NS(a, CURRENT_EL)
89 } else {
90 BREAK_IF_END_OF(CURRENT_EL)
91 }
92 }
93 //debugMsooXml << "{1}";
94
95 if (m_read_t_args) {
96 m_read_t_args = false;
97 READ_EPILOGUE_IF_NS(a)
98 } else {
99 READ_EPILOGUE
100 }
101 }
102
103
104
105 // ================================================================
106 // Namespace: mc
107 // ================================================================
108 // ARRRRRGH!
109
110 // The way that READ_PROLOGUE is defined via QUALIFIED_NAME makes it
111 // impossible to use it in files that handle tags both with and
112 // without namespaces. This means that we cannot use READ_PROLOGUE in
113 // the functions below, and most likely also not the READ_IF variants.
114 // The above is only true when called from XmlWorksheetReader. For Docx,
115 // there are always namespaces, so it doesn't apply.
116 // Same is true for READ_EPILOGUE.
117
118
119 #undef MSOOXML_CURRENT_NS
120 #define MSOOXML_CURRENT_NS "mc"
121
122 #undef CURRENT_EL
123 #define CURRENT_EL AlternateContent
124 //! Alternate content handler
read_AlternateContent()125 KoFilter::ConversionStatus MSOOXML_CURRENT_CLASS::read_AlternateContent()
126 {
127 m_choiceAccepted = false;
128
129 while (!atEnd()) {
130 readNext();
131 if (isEndElement() && name() == "AlternateContent") {
132 break;
133 }
134
135 if (isStartElement()) {
136 if (name() == "Choice") {
137 TRY_READ(Choice)
138 }
139 else if (!m_choiceAccepted && qualifiedName() == "mc:Fallback") {
140 TRY_READ(Fallback)
141 }
142 else {
143 skipCurrentElement();
144 }
145 }
146 }
147
148 return KoFilter::OK;
149 }
150
151 #undef CURRENT_EL
152 #define CURRENT_EL Choice
153 //! Choice handler
read_Choice()154 KoFilter::ConversionStatus MSOOXML_CURRENT_CLASS::read_Choice()
155 {
156
157 const QXmlStreamAttributes attrs(attributes());
158
159 TRY_READ_ATTR_WITHOUT_NS(Requires)
160
161 // 'Requires="v"' means that the contents of the Choice part
162 // is VML, which we support (or something else we do support,
163 // Lassi is not sure). For all other alternatives we
164 // don't dare try to interpret it, but instead we use the
165 // AlternateContent which is what MSO 2007 would have given us.
166 if (Requires != "v") {
167 skipCurrentElement();
168 return KoFilter::OK;
169 }
170
171 m_choiceAccepted = true;
172 while (!atEnd()) {
173 readNext();
174 if (isEndElement() && name() == "Choice") {
175 break;
176 }
177 if (isStartElement()) {
178 #ifdef PPTXXMLSLIDEREADER_CPP
179 TRY_READ_IF_NS(p, oleObj)
180 #endif
181 }
182 }
183 return KoFilter::OK;
184 }
185
186 #undef CURRENT_EL
187 #define CURRENT_EL Fallback
188 //! Fallback handler
read_Fallback()189 KoFilter::ConversionStatus MSOOXML_CURRENT_CLASS::read_Fallback()
190 {
191
192 while (!atEnd()) {
193 readNext();
194 if (isEndElement() && name() == "Fallback") {
195 break;
196 }
197
198 if (isStartElement()) {
199 #ifdef PPTXXMLSLIDEREADER_CPP
200 TRY_READ_IF_NS(p, sp)
201 #endif
202 #ifdef DOCXXMLDOCUMENTREADER_H
203 TRY_READ_IF_NS(w, pict)
204 #endif
205 #ifdef XLSXXMLWORKSHEETREADER_CPP
206 // FIXME: This Choice/Content/Fallback structure needs a more general treatment.
207 if (name() == "oleObject") {
208 TRY_READ(oleObject)
209 }
210 #endif
211 }
212 }
213 return KoFilter::OK;
214 }
215
216 #endif
217