Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <stdio.h>
21 : #include <iostream>
22 : #include "OOXMLParserState.hxx"
23 :
24 : namespace writerfilter {
25 : namespace ooxml
26 : {
27 : /*
28 : class OOXMLParserState
29 : */
30 :
31 19704 : OOXMLParserState::OOXMLParserState() :
32 : mbInSectionGroup(false),
33 : mbInParagraphGroup(false),
34 : mbInCharacterGroup(false),
35 : mbLastParagraphInSection(false),
36 : mbForwardEvents(true),
37 : mnContexts(0),
38 : mnHandle(0),
39 : mpDocument(nullptr),
40 : inTxbxContent(false),
41 : savedInParagraphGroup(false),
42 : savedInCharacterGroup(false),
43 19704 : savedLastParagraphInSection(false)
44 : {
45 19704 : }
46 :
47 39408 : OOXMLParserState::~OOXMLParserState()
48 : {
49 39408 : }
50 :
51 3396 : void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
52 : {
53 3396 : mbLastParagraphInSection = bLastParagraphInSection;
54 3396 : }
55 :
56 :
57 :
58 12072 : void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
59 : {
60 12072 : mbInSectionGroup = bInSectionGroup;
61 12072 : }
62 :
63 :
64 101730 : void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
65 : {
66 101730 : mbInParagraphGroup = bInParagraphGroup;
67 101730 : }
68 :
69 :
70 256470 : void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
71 : {
72 256470 : mbInCharacterGroup = bInCharacterGroup;
73 256470 : }
74 :
75 21132 : void OOXMLParserState::setForwardEvents(bool bForwardEvents)
76 : {
77 21132 : mbForwardEvents = bForwardEvents;
78 21132 : }
79 :
80 :
81 48496 : const std::string OOXMLParserState::getHandle() const
82 : {
83 : char sBuffer[256];
84 :
85 48496 : snprintf(sBuffer, sizeof(sBuffer), "%u", mnHandle);
86 :
87 48496 : return sBuffer;
88 : }
89 :
90 45192 : void OOXMLParserState::setHandle()
91 : {
92 45192 : mnHandle = mnContexts;
93 45192 : }
94 :
95 19704 : void OOXMLParserState::setDocument(OOXMLDocumentImpl* pDocument)
96 : {
97 19704 : mpDocument = pDocument;
98 19704 : }
99 :
100 :
101 19792 : void OOXMLParserState::setXNoteId(const sal_Int32 nId)
102 : {
103 19792 : mpDocument->setXNoteId(nId);
104 19792 : }
105 :
106 714 : sal_Int32 OOXMLParserState::getXNoteId() const
107 : {
108 714 : return mpDocument->getXNoteId();
109 : }
110 :
111 3212 : const OUString & OOXMLParserState::getTarget() const
112 : {
113 3212 : return mpDocument->getTarget();
114 : }
115 :
116 128238 : void OOXMLParserState::resolveCharacterProperties(Stream & rStream)
117 : {
118 128238 : if (mpCharacterProps.get() != nullptr)
119 : {
120 42264 : rStream.props(mpCharacterProps);
121 42264 : mpCharacterProps.reset(new OOXMLPropertySetImpl());
122 : }
123 128238 : }
124 :
125 2576 : void OOXMLParserState::setCharacterProperties(OOXMLPropertySet::Pointer_t pProps)
126 : {
127 2576 : if (mpCharacterProps.get() == nullptr)
128 744 : mpCharacterProps = pProps;
129 : else
130 1832 : mpCharacterProps->add(pProps);
131 2576 : }
132 :
133 14420 : void OOXMLParserState::setCellProperties(OOXMLPropertySet::Pointer_t pProps)
134 : {
135 14420 : if (!mCellProps.empty())
136 : {
137 14420 : OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
138 :
139 14420 : if (rCellProps.get() == nullptr)
140 942 : rCellProps = pProps;
141 : else
142 13478 : rCellProps->add(pProps);
143 : }
144 14420 : }
145 :
146 4146 : void OOXMLParserState::setRowProperties(OOXMLPropertySet::Pointer_t pProps)
147 : {
148 4146 : if (!mRowProps.empty())
149 : {
150 4146 : OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
151 :
152 4146 : if (rRowProps.get() == nullptr)
153 598 : rRowProps = pProps;
154 : else
155 3548 : rRowProps->add(pProps);
156 : }
157 4146 : }
158 :
159 14472 : void OOXMLParserState::resolveCellProperties(Stream & rStream)
160 : {
161 14472 : if (!mCellProps.empty())
162 : {
163 14472 : OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
164 :
165 14472 : if (rCellProps.get() != nullptr)
166 : {
167 14436 : rStream.props(rCellProps);
168 14436 : rCellProps.reset(new OOXMLPropertySetImpl());
169 : }
170 : }
171 14472 : }
172 :
173 5202 : void OOXMLParserState::resolveRowProperties(Stream & rStream)
174 : {
175 5202 : if (!mRowProps.empty())
176 : {
177 5202 : OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
178 :
179 5202 : if (rRowProps.get() != nullptr)
180 : {
181 4232 : rStream.props(rRowProps);
182 4232 : rRowProps.reset(new OOXMLPropertySetImpl());
183 : }
184 : }
185 5202 : }
186 :
187 5202 : void OOXMLParserState::resolveTableProperties(Stream & rStream)
188 : {
189 5202 : if (!mTableProps.empty())
190 : {
191 5202 : OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
192 :
193 5202 : if (rTableProps.get() != nullptr)
194 : {
195 5202 : rStream.props(rTableProps);
196 : // Don't clean the table props to send them again for each row
197 : // This mimics the behaviour from RTF tokenizer.
198 : }
199 : }
200 5202 : }
201 :
202 2832 : void OOXMLParserState::setTableProperties(OOXMLPropertySet::Pointer_t pProps)
203 : {
204 2832 : if (!mTableProps.empty())
205 : {
206 1988 : OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
207 1988 : if (rTableProps.get() == nullptr)
208 946 : rTableProps = pProps;
209 : else
210 1042 : rTableProps->add(pProps);
211 : }
212 2832 : }
213 :
214 946 : void OOXMLParserState::startTable()
215 : {
216 946 : OOXMLPropertySet::Pointer_t pCellProps;
217 1892 : OOXMLPropertySet::Pointer_t pRowProps;
218 1892 : OOXMLPropertySet::Pointer_t pTableProps;
219 :
220 946 : mCellProps.push(pCellProps);
221 946 : mRowProps.push(pRowProps);
222 1892 : mTableProps.push(pTableProps);
223 946 : }
224 :
225 946 : void OOXMLParserState::endTable()
226 : {
227 946 : mCellProps.pop();
228 946 : mRowProps.pop();
229 946 : mTableProps.pop();
230 946 : }
231 :
232 3779710 : void OOXMLParserState::incContextCount()
233 : {
234 3779710 : mnContexts++;
235 3779710 : }
236 :
237 962 : void OOXMLParserState::startTxbxContent()
238 : {
239 : SAL_WARN_IF(inTxbxContent, "writerfilter", "Nested w:txbxContent");
240 :
241 962 : inTxbxContent = true;
242 : // Do not save and reset section group state, it'd cause a new page.
243 : // savedInSectionGroup = mbInSectionGroup;
244 962 : savedInParagraphGroup = mbInParagraphGroup;
245 962 : savedInCharacterGroup = mbInCharacterGroup;
246 962 : savedLastParagraphInSection = mbLastParagraphInSection;
247 : // mbInSectionGroup = false;
248 962 : mbInParagraphGroup = false;
249 962 : mbInCharacterGroup = false;
250 962 : mbLastParagraphInSection = false;
251 962 : }
252 :
253 962 : void OOXMLParserState::endTxbxContent()
254 : {
255 962 : if( !inTxbxContent )
256 : {
257 : SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
258 964 : return;
259 : }
260 : // mbInSectionGroup = savedInSectionGroup;
261 960 : mbInParagraphGroup = savedInParagraphGroup;
262 960 : mbInCharacterGroup = savedInCharacterGroup;
263 960 : mbLastParagraphInSection = savedLastParagraphInSection;
264 960 : inTxbxContent = false;
265 : }
266 :
267 114 : }}
268 :
269 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|