LibreOffice Module writerfilter (master) 1
OOXMLParserState.cxx
Go to the documentation of this file.
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 "OOXMLParserState.hxx"
21#include "Handler.hxx"
22
23#include <sal/log.hxx>
24
25namespace writerfilter::ooxml
26{
27/*
28 class OOXMLParserState
29*/
30
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 m_inTxbxContent(false),
41 m_savedInParagraphGroup(false),
42 m_savedInCharacterGroup(false),
43 m_savedLastParagraphInSection(false),
44 mbStartFootnote(false)
45{
46}
47
49{
50}
51
52void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
53{
54 mbLastParagraphInSection = bLastParagraphInSection;
55}
56
57
58void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
59{
60 mbInSectionGroup = bInSectionGroup;
61}
62
63
64void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
65{
66 mbInParagraphGroup = bInParagraphGroup;
67}
68
69
70void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
71{
72 mbInCharacterGroup = bInCharacterGroup;
73}
74
75void OOXMLParserState::setForwardEvents(bool bForwardEvents)
76{
77 mbForwardEvents = bForwardEvents;
78}
79
80
81std::string OOXMLParserState::getHandle() const
82{
83 return std::to_string(mnHandle);
84}
85
87{
89}
90
92{
93 mpDocument = pDocument;
94}
95
96
97void OOXMLParserState::setXNoteId(const sal_Int32 nId)
98{
100}
101
103{
104 return mpDocument->getXNoteId();
105}
106
107const OUString & OOXMLParserState::getTarget() const
108{
109 return mpDocument->getTarget();
110}
111
113{
115 {
116 rStream.props(mpCharacterProps.get());
118 }
119}
120
122{
123 if (!mpCharacterProps)
124 mpCharacterProps = pProps;
125 else
126 mpCharacterProps->add(pProps);
127}
128
130{
131 if (!mCellProps.empty())
132 {
133 OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
134
135 if (!rCellProps)
136 rCellProps = pProps;
137 else
138 rCellProps->add(pProps);
139 }
140}
141
143{
144 if (!mRowProps.empty())
145 {
146 OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
147
148 if (!rRowProps)
149 rRowProps = pProps;
150 else
151 rRowProps->add(pProps);
152 }
153}
154
156{
157 if (!mCellProps.empty())
158 {
159 OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
160
161 if (rCellProps)
162 {
163 rStream.props(rCellProps.get());
164 rCellProps = new OOXMLPropertySet;
165 }
166 }
167}
168
170{
171 if (!mRowProps.empty())
172 {
173 OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
174
175 if (rRowProps)
176 {
177 rStream.props(rRowProps.get());
178 rRowProps = new OOXMLPropertySet;
179 }
180 }
181}
182
184{
185 if (!mTableProps.empty())
186 {
187 OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
188
189 if (rTableProps)
190 {
191 rStream.props(rTableProps.get());
192 // Don't clean the table props to send them again for each row
193 // This mimics the behaviour from RTF tokenizer.
194 }
195 }
196}
197
199{
200 if (!mTableProps.empty())
201 {
202 OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
203 if (!rTableProps)
204 rTableProps = pProps;
205 else
206 rTableProps->add(pProps);
207 }
208}
209
211{
212 if (mTableProps.empty())
213 {
214 return nullptr;
215 }
216
217 return mTableProps.top();
218}
219
220// tdf#108714
222{
223 for (const auto & rBreak: mvPostponedBreaks)
224 {
225 OOXMLBreakHandler aBreakHandler(nullptr, rStream);
226 rBreak->resolve(aBreakHandler);
227 }
228 mvPostponedBreaks.clear();
229}
230
232{
233 mvPostponedBreaks.push_back(pProps);
234}
235
237{
240 OOXMLPropertySet::Pointer_t pTableProps;
241
242 mCellProps.push(pCellProps);
243 mRowProps.push(pRowProps);
244 mTableProps.push(pTableProps);
245}
246
248{
249 mCellProps.pop();
250 mRowProps.pop();
251 mTableProps.pop();
252}
253
255{
256 mnContexts++;
257}
258
260{
261 SAL_WARN_IF(m_inTxbxContent, "writerfilter", "Nested w:txbxContent");
262
263 m_inTxbxContent = true;
264 // Do not save and reset section group state, it'd cause a new page.
265// savedInSectionGroup = mbInSectionGroup;
269// mbInSectionGroup = false;
270 mbInParagraphGroup = false;
271 mbInCharacterGroup = false;
273}
274
276{
277 if( !m_inTxbxContent )
278 {
279 SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
280 return;
281 }
282// mbInSectionGroup = savedInSectionGroup;
286 m_inTxbxContent = false;
287}
288
289void OOXMLParserState::setStartFootnote(bool bStartFootnote)
290{
291 mbStartFootnote = bStartFootnote;
292}
293
294}
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
T * get() const
Handler for a stream.
virtual void props(writerfilter::Reference< Properties >::Pointer_t ref)=0
Receives properties of the current run of text.
virtual sal_Int32 getXNoteId() const override
virtual void setXNoteId(const sal_Int32 nId) override
virtual const OUString & getTarget() const override
void setPostponedBreak(const OOXMLPropertySet::Pointer_t &pProps)
std::stack< OOXMLPropertySet::Pointer_t > mTableProps
void setXNoteId(const sal_Int32 rId)
void setInSectionGroup(bool bInSectionGroup)
OOXMLPropertySet::Pointer_t mpCharacterProps
void resolveCharacterProperties(Stream &rStream)
void setForwardEvents(bool bForwardEvents)
void setLastParagraphInSection(bool bLastParagraphInSection)
void setRowProperties(const OOXMLPropertySet::Pointer_t &pProps)
OOXMLPropertySet::Pointer_t GetTableProperties() const
void setInCharacterGroup(bool bInCharacterGroup)
std::stack< OOXMLPropertySet::Pointer_t > mCellProps
void setDocument(OOXMLDocumentImpl *pDocument)
void setInParagraphGroup(bool bInParagraphGroup)
std::vector< OOXMLPropertySet::Pointer_t > mvPostponedBreaks
std::stack< OOXMLPropertySet::Pointer_t > mRowProps
void setCellProperties(const OOXMLPropertySet::Pointer_t &pProps)
void setTableProperties(const OOXMLPropertySet::Pointer_t &pProps)
void setStartFootnote(bool bStartFootnote)
void setCharacterProperties(const OOXMLPropertySet::Pointer_t &pProps)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
sal_Int16 nId