android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / source / ooxml / OOXMLParserState.cxx
blobb8cc55377b5be597c8464d9b2af0ea8b97fa3498
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "OOXMLParserState.hxx"
21 #include "Handler.hxx"
23 #include <sal/log.hxx>
25 namespace writerfilter::ooxml
28 class OOXMLParserState
31 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 m_inTxbxContent(false),
41 m_savedInParagraphGroup(false),
42 m_savedInCharacterGroup(false),
43 m_savedLastParagraphInSection(false),
44 mbStartFootnote(false)
48 OOXMLParserState::~OOXMLParserState()
52 void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
54 mbLastParagraphInSection = bLastParagraphInSection;
58 void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
60 mbInSectionGroup = bInSectionGroup;
64 void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
66 mbInParagraphGroup = bInParagraphGroup;
70 void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
72 mbInCharacterGroup = bInCharacterGroup;
75 void OOXMLParserState::setForwardEvents(bool bForwardEvents)
77 mbForwardEvents = bForwardEvents;
81 std::string OOXMLParserState::getHandle() const
83 return std::to_string(mnHandle);
86 void OOXMLParserState::setHandle()
88 mnHandle = mnContexts;
91 void OOXMLParserState::setDocument(OOXMLDocumentImpl* pDocument)
93 mpDocument = pDocument;
97 void OOXMLParserState::setXNoteId(const sal_Int32 nId)
99 mpDocument->setXNoteId(nId);
102 sal_Int32 OOXMLParserState::getXNoteId() const
104 return mpDocument->getXNoteId();
107 const OUString & OOXMLParserState::getTarget() const
109 return mpDocument->getTarget();
112 void OOXMLParserState::resolveCharacterProperties(Stream & rStream)
114 if (mpCharacterProps)
116 rStream.props(mpCharacterProps.get());
117 mpCharacterProps = new OOXMLPropertySet;
121 void OOXMLParserState::setCharacterProperties(const OOXMLPropertySet::Pointer_t& pProps)
123 if (!mpCharacterProps)
124 mpCharacterProps = pProps;
125 else
126 mpCharacterProps->add(pProps);
129 void OOXMLParserState::setCellProperties(const OOXMLPropertySet::Pointer_t& pProps)
131 if (!mCellProps.empty())
133 OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
135 if (!rCellProps)
136 rCellProps = pProps;
137 else
138 rCellProps->add(pProps);
142 void OOXMLParserState::setRowProperties(const OOXMLPropertySet::Pointer_t& pProps)
144 if (!mRowProps.empty())
146 OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
148 if (!rRowProps)
149 rRowProps = pProps;
150 else
151 rRowProps->add(pProps);
155 void OOXMLParserState::resolveCellProperties(Stream & rStream)
157 if (!mCellProps.empty())
159 OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
161 if (rCellProps)
163 rStream.props(rCellProps.get());
164 rCellProps = new OOXMLPropertySet;
169 void OOXMLParserState::resolveRowProperties(Stream & rStream)
171 if (!mRowProps.empty())
173 OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
175 if (rRowProps)
177 rStream.props(rRowProps.get());
178 rRowProps = new OOXMLPropertySet;
183 void OOXMLParserState::resolveTableProperties(Stream & rStream)
185 if (!mTableProps.empty())
187 OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
189 if (rTableProps)
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.
198 void OOXMLParserState::setTableProperties(const OOXMLPropertySet::Pointer_t& pProps)
200 if (!mTableProps.empty())
202 OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
203 if (!rTableProps)
204 rTableProps = pProps;
205 else
206 rTableProps->add(pProps);
210 OOXMLPropertySet::Pointer_t OOXMLParserState::GetTableProperties() const
212 if (mTableProps.empty())
214 return nullptr;
217 return mTableProps.top();
220 // tdf#108714
221 void OOXMLParserState::resolvePostponedBreak(Stream & rStream)
223 for (const auto & rBreak: mvPostponedBreaks)
225 OOXMLBreakHandler aBreakHandler(nullptr, rStream);
226 rBreak->resolve(aBreakHandler);
228 mvPostponedBreaks.clear();
231 void OOXMLParserState::setPostponedBreak(const OOXMLPropertySet::Pointer_t & pProps)
233 mvPostponedBreaks.push_back(pProps);
236 void OOXMLParserState::startTable()
238 OOXMLPropertySet::Pointer_t pCellProps;
239 OOXMLPropertySet::Pointer_t pRowProps;
240 OOXMLPropertySet::Pointer_t pTableProps;
242 mCellProps.push(pCellProps);
243 mRowProps.push(pRowProps);
244 mTableProps.push(pTableProps);
247 void OOXMLParserState::endTable()
249 mCellProps.pop();
250 mRowProps.pop();
251 mTableProps.pop();
254 void OOXMLParserState::incContextCount()
256 mnContexts++;
259 void OOXMLParserState::startTxbxContent()
261 SAL_WARN_IF(m_inTxbxContent, "writerfilter", "Nested w:txbxContent");
263 m_inTxbxContent = true;
264 // Do not save and reset section group state, it'd cause a new page.
265 // savedInSectionGroup = mbInSectionGroup;
266 m_savedInParagraphGroup = mbInParagraphGroup;
267 m_savedInCharacterGroup = mbInCharacterGroup;
268 m_savedLastParagraphInSection = mbLastParagraphInSection;
269 // mbInSectionGroup = false;
270 mbInParagraphGroup = false;
271 mbInCharacterGroup = false;
272 mbLastParagraphInSection = false;
275 void OOXMLParserState::endTxbxContent()
277 if( !m_inTxbxContent )
279 SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
280 return;
282 // mbInSectionGroup = savedInSectionGroup;
283 mbInParagraphGroup = m_savedInParagraphGroup;
284 mbInCharacterGroup = m_savedInCharacterGroup;
285 mbLastParagraphInSection = m_savedLastParagraphInSection;
286 m_inTxbxContent = false;
289 void OOXMLParserState::setStartFootnote(bool bStartFootnote)
291 mbStartFootnote = bStartFootnote;
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */