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 <iostream>
21 : #include <set>
22 : #include <comphelper/servicehelper.hxx>
23 : #include <com/sun/star/drawing/XShapes.hpp>
24 : #include <com/sun/star/xml/sax/FastShapeContextHandler.hpp>
25 : #include <ooxml/QNameToString.hxx>
26 : #include <ooxml/resourceids.hxx>
27 : #include <oox/token/namespaces.hxx>
28 : #include <comphelper/embeddedobjectcontainer.hxx>
29 : #include <tools/globname.hxx>
30 : #include <comphelper/classids.hxx>
31 : #include <sfx2/sfxbasemodel.hxx>
32 : #include "OOXMLFastContextHandler.hxx"
33 : #include "OOXMLFactory.hxx"
34 : #include "Handler.hxx"
35 :
36 : static const sal_Unicode uCR = 0xd;
37 : static const sal_Unicode uFtnEdnRef = 0x2;
38 : static const sal_Unicode uFtnEdnSep = 0x3;
39 : static const sal_Unicode uTab = 0x9;
40 : static const sal_Unicode uPgNum = 0x0;
41 : static const sal_Unicode uNoBreakHyphen = 0x2011;
42 : static const sal_Unicode uSoftHyphen = 0xAD;
43 :
44 : static const sal_uInt8 cFtnEdnCont = 0x4;
45 : static const sal_uInt8 cFieldLock = 0x8;
46 :
47 : namespace writerfilter {
48 : namespace ooxml
49 : {
50 : using namespace ::com::sun::star;
51 : using namespace oox;
52 : using namespace ::std;
53 :
54 24 : set<OOXMLFastContextHandler *> aSetContexts;
55 :
56 : /*
57 : class OOXMLFastContextHandler
58 : */
59 :
60 : sal_uInt32 OOXMLFastContextHandler::mnInstanceCount = 0;
61 :
62 10530 : OOXMLFastContextHandler::OOXMLFastContextHandler
63 : (uno::Reference< uno::XComponentContext > const & context)
64 : : mpParent(nullptr),
65 : mId(0),
66 : mnDefine(0),
67 : mnToken(oox::XML_TOKEN_COUNT),
68 : mpStream(nullptr),
69 : mnTableDepth(0),
70 : mnInstanceNumber(mnInstanceCount),
71 : inPositionV(false),
72 : m_xContext(context),
73 : m_bDiscardChildren(false),
74 10530 : m_bTookChoice(false)
75 : {
76 10530 : mnInstanceCount++;
77 10530 : aSetContexts.insert(this);
78 :
79 10530 : if (mpParserState.get() == nullptr)
80 10530 : mpParserState.reset(new OOXMLParserState());
81 :
82 10530 : mpParserState->incContextCount();
83 10530 : }
84 :
85 2015438 : OOXMLFastContextHandler::OOXMLFastContextHandler(OOXMLFastContextHandler * pContext)
86 : : cppu::WeakImplHelper<xml::sax::XFastContextHandler>(),
87 : mpParent(pContext),
88 : mId(0),
89 : mnDefine(0),
90 : mnToken(oox::XML_TOKEN_COUNT),
91 : mpStream(pContext->mpStream),
92 : mnTableDepth(pContext->mnTableDepth),
93 : mnInstanceNumber(mnInstanceCount),
94 : inPositionV(pContext->inPositionV),
95 : m_xContext(pContext->m_xContext),
96 : m_bDiscardChildren(pContext->m_bDiscardChildren),
97 2015438 : m_bTookChoice(pContext->m_bTookChoice)
98 : {
99 2015438 : mpParserState = pContext->mpParserState;
100 :
101 2015438 : if (mpParserState.get() == nullptr)
102 0 : mpParserState.reset(new OOXMLParserState());
103 :
104 2015438 : mnInstanceCount++;
105 2015438 : aSetContexts.insert(this);
106 2015438 : mpParserState->incContextCount();
107 2015438 : }
108 :
109 4063237 : OOXMLFastContextHandler::~OOXMLFastContextHandler()
110 : {
111 2026225 : aSetContexts.erase(this);
112 2037012 : }
113 :
114 2820 : bool OOXMLFastContextHandler::prepareMceContext(Token_t nElement, const uno::Reference<xml::sax::XFastAttributeList>& rAttribs)
115 : {
116 2820 : switch (oox::getBaseToken(nElement))
117 : {
118 : case XML_AlternateContent:
119 : {
120 : SavedAlternateState aState;
121 940 : aState.m_bDiscardChildren = m_bDiscardChildren;
122 940 : m_bDiscardChildren = false;
123 940 : aState.m_bTookChoice = m_bTookChoice;
124 940 : m_bTookChoice = false;
125 940 : mpParserState->getSavedAlternateStates().push_back(aState);
126 : }
127 940 : break;
128 : case XML_Choice:
129 : {
130 940 : OUString aRequires = rAttribs->getOptionalValue(XML_Requires);
131 : static const char* aFeatures[] = {
132 : "wps",
133 : "wpg",
134 : };
135 1057 : for (size_t i = 0; i < SAL_N_ELEMENTS(aFeatures); ++i)
136 : {
137 1029 : if (aRequires.equalsAscii(aFeatures[i]))
138 : {
139 912 : m_bTookChoice = true;
140 912 : return false;
141 : }
142 : }
143 28 : return true;
144 : }
145 : break;
146 : case XML_Fallback:
147 : // If Choice is already taken, then let's ignore the Fallback.
148 940 : return m_bTookChoice;
149 : break;
150 : default:
151 : SAL_WARN("writerfilter", "OOXMLFastContextHandler::prepareMceContext: unhandled element:" << oox::getBaseToken(nElement));
152 0 : break;
153 : }
154 940 : return false;
155 : }
156 :
157 : // xml::sax::XFastContextHandler:
158 2027591 : void SAL_CALL OOXMLFastContextHandler::startFastElement
159 : (Token_t Element,
160 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
161 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
162 : {
163 2027591 : if (oox::getNamespace(Element) == static_cast<sal_Int32>(NMSP_mce))
164 2820 : m_bDiscardChildren = prepareMceContext(Element, Attribs);
165 :
166 2024771 : else if (!m_bDiscardChildren)
167 : {
168 2024771 : attributes(Attribs);
169 2024771 : lcl_startFastElement(Element, Attribs);
170 : }
171 2027591 : }
172 :
173 257 : void SAL_CALL OOXMLFastContextHandler::startUnknownElement
174 : (const OUString & /*Namespace*/, const OUString & /*Name*/,
175 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
176 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
177 : {
178 257 : }
179 :
180 2027585 : void SAL_CALL OOXMLFastContextHandler::endFastElement(Token_t Element)
181 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
182 : {
183 2027585 : if (Element == (NMSP_mce | XML_Choice) || Element == (NMSP_mce | XML_Fallback))
184 1880 : m_bDiscardChildren = false;
185 2025705 : else if (Element == (NMSP_mce | XML_AlternateContent))
186 : {
187 940 : SavedAlternateState aState(mpParserState->getSavedAlternateStates().back());
188 940 : mpParserState->getSavedAlternateStates().pop_back();
189 940 : m_bDiscardChildren = aState.m_bDiscardChildren;
190 940 : m_bTookChoice = aState.m_bTookChoice;
191 : }
192 2024765 : else if (!m_bDiscardChildren)
193 2024765 : lcl_endFastElement(Element);
194 2027585 : }
195 :
196 1961537 : void OOXMLFastContextHandler::lcl_startFastElement
197 : (Token_t Element,
198 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
199 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
200 : {
201 1961537 : OOXMLFactory::startAction(this, Element);
202 1961537 : if( Element == (NMSP_dmlWordDr|XML_positionV) )
203 936 : inPositionV = true;
204 1960601 : else if( Element == (NMSP_dmlWordDr|XML_positionH) )
205 936 : inPositionV = false;
206 :
207 1961537 : }
208 :
209 150620 : void OOXMLFastContextHandler::lcl_endFastElement
210 : (Token_t Element)
211 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
212 : {
213 150620 : OOXMLFactory::endAction(this, Element);
214 150620 : }
215 :
216 257 : void SAL_CALL OOXMLFastContextHandler::endUnknownElement
217 : (const OUString & , const OUString & )
218 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
219 : {
220 257 : }
221 :
222 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
223 2036751 : OOXMLFastContextHandler::createFastChildContext
224 : (Token_t Element,
225 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
226 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
227 : {
228 2036751 : uno::Reference< xml::sax::XFastContextHandler > xResult;
229 2036751 : if (oox::getNamespace(Element) != NMSP_mce && !m_bDiscardChildren)
230 2032991 : xResult.set(lcl_createFastChildContext(Element, Attribs));
231 3760 : else if (oox::getNamespace(Element) == NMSP_mce)
232 2820 : xResult = this;
233 :
234 2036750 : return xResult;
235 : }
236 :
237 : uno::Reference< xml::sax::XFastContextHandler >
238 1971941 : OOXMLFastContextHandler::lcl_createFastChildContext
239 : (Token_t Element,
240 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
241 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
242 : {
243 1971941 : return OOXMLFactory::createFastChildContext(this, Element);
244 : }
245 :
246 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
247 257 : OOXMLFastContextHandler::createUnknownChildContext
248 : (const OUString &,
249 : const OUString &,
250 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
251 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
252 : {
253 : return uno::Reference< xml::sax::XFastContextHandler >
254 257 : (new OOXMLFastContextHandler(*const_cast<const OOXMLFastContextHandler *>(this)));
255 : }
256 :
257 98859 : void SAL_CALL OOXMLFastContextHandler::characters
258 : (const OUString & aChars)
259 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
260 : {
261 98859 : lcl_characters(aChars);
262 98859 : }
263 :
264 91082 : void OOXMLFastContextHandler::lcl_characters
265 : (const OUString & rString)
266 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
267 : {
268 91082 : if (!m_bDiscardChildren)
269 90978 : OOXMLFactory::characters(this, rString);
270 91082 : }
271 :
272 10530 : void OOXMLFastContextHandler::setStream(Stream * pStream)
273 : {
274 10530 : mpStream = pStream;
275 10530 : }
276 :
277 0 : OOXMLValue::Pointer_t OOXMLFastContextHandler::getValue() const
278 : {
279 0 : return OOXMLValue::Pointer_t();
280 : }
281 :
282 1969607 : void OOXMLFastContextHandler::attributes
283 : (const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
284 : throw (uno::RuntimeException, xml::sax::SAXException)
285 : {
286 1969607 : OOXMLFactory::attributes(this, Attribs);
287 1969607 : }
288 :
289 2743 : void OOXMLFastContextHandler::startAction(Token_t Element)
290 : {
291 2743 : OOXMLFactory::startAction(this, Element);
292 2743 : }
293 :
294 1809735 : void OOXMLFastContextHandler::endAction(Token_t Element)
295 : {
296 1809735 : OOXMLFactory::endAction(this, Element);
297 1809735 : }
298 :
299 2015438 : void OOXMLFastContextHandler::setId(Id rId)
300 : {
301 2015438 : mId = rId;
302 2015438 : }
303 :
304 1028858 : Id OOXMLFastContextHandler::getId() const
305 : {
306 1028858 : return mId;
307 : }
308 :
309 1964475 : void OOXMLFastContextHandler::setDefine(Id nDefine)
310 : {
311 1964475 : mnDefine = nDefine;
312 1964475 : }
313 :
314 :
315 :
316 2015438 : void OOXMLFastContextHandler::setToken(Token_t nToken)
317 : {
318 2015438 : mnToken = nToken;
319 2015438 : }
320 :
321 51515 : Token_t OOXMLFastContextHandler::getToken() const
322 : {
323 51515 : return mnToken;
324 : }
325 :
326 0 : void OOXMLFastContextHandler::setParent
327 : (OOXMLFastContextHandler * pParent)
328 : {
329 0 : mpParent = pParent;
330 0 : }
331 :
332 26661 : void OOXMLFastContextHandler::sendTableDepth() const
333 : {
334 26661 : if (mnTableDepth > 0)
335 : {
336 9043 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
337 : {
338 9043 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth);
339 : OOXMLProperty::Pointer_t pProp
340 18086 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM));
341 18086 : pProps->add(pProp);
342 : }
343 : {
344 9043 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1);
345 : OOXMLProperty::Pointer_t pProp
346 18086 : (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM));
347 18086 : pProps->add(pProp);
348 : }
349 :
350 9043 : mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
351 : }
352 26661 : }
353 :
354 26661 : void OOXMLFastContextHandler::setHandle()
355 : {
356 26661 : mpParserState->setHandle();
357 26661 : mpStream->info(mpParserState->getHandle());
358 26661 : }
359 :
360 71620 : void OOXMLFastContextHandler::startCharacterGroup()
361 : {
362 71620 : if (isForwardEvents())
363 : {
364 68408 : if (mpParserState->isInCharacterGroup())
365 34676 : endCharacterGroup();
366 :
367 68408 : if (! mpParserState->isInParagraphGroup())
368 13 : startParagraphGroup();
369 :
370 68408 : if (! mpParserState->isInCharacterGroup())
371 : {
372 68408 : mpStream->startCharacterGroup();
373 68408 : mpParserState->setInCharacterGroup(true);
374 68408 : mpParserState->resolveCharacterProperties(*mpStream);
375 : }
376 : }
377 71620 : }
378 :
379 68425 : void OOXMLFastContextHandler::endCharacterGroup()
380 : {
381 68425 : if (isForwardEvents() && mpParserState->isInCharacterGroup())
382 : {
383 68406 : mpStream->endCharacterGroup();
384 68406 : mpParserState->setInCharacterGroup(false);
385 : }
386 68425 : }
387 :
388 30032 : void OOXMLFastContextHandler::startParagraphGroup()
389 : {
390 30032 : if (isForwardEvents())
391 : {
392 28411 : if (mpParserState->isInParagraphGroup())
393 13977 : endParagraphGroup();
394 :
395 28411 : if (! mpParserState->isInSectionGroup())
396 88 : startSectionGroup();
397 :
398 28411 : if (! mpParserState->isInParagraphGroup())
399 : {
400 28411 : mpStream->startParagraphGroup();
401 28411 : mpParserState->setInParagraphGroup(true);
402 : }
403 : }
404 30032 : }
405 :
406 28431 : void OOXMLFastContextHandler::endParagraphGroup()
407 : {
408 28431 : if (isForwardEvents())
409 : {
410 28431 : if (mpParserState->isInCharacterGroup())
411 23530 : endCharacterGroup();
412 :
413 28431 : if (mpParserState->isInParagraphGroup())
414 : {
415 28409 : mpStream->endParagraphGroup();
416 28409 : mpParserState->setInParagraphGroup(false);
417 : }
418 : }
419 28431 : }
420 :
421 446 : void OOXMLFastContextHandler::startSdt()
422 : {
423 446 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
424 446 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1);
425 892 : OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtContent, pVal, OOXMLPropertyImpl::ATTRIBUTE));
426 446 : pProps->add(pProp);
427 892 : mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
428 446 : }
429 :
430 446 : void OOXMLFastContextHandler::endSdt()
431 : {
432 446 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
433 446 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1);
434 892 : OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtEndContent, pVal, OOXMLPropertyImpl::ATTRIBUTE));
435 446 : pProps->add(pProp);
436 892 : mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
437 446 : }
438 :
439 1814 : void OOXMLFastContextHandler::startSectionGroup()
440 : {
441 1814 : if (isForwardEvents())
442 : {
443 1814 : if (mpParserState->isInSectionGroup())
444 173 : endSectionGroup();
445 :
446 1814 : if (! mpParserState->isInSectionGroup())
447 : {
448 1814 : mpStream->info(mpParserState->getHandle());
449 1814 : mpStream->startSectionGroup();
450 1814 : mpParserState->setInSectionGroup(true);
451 : }
452 : }
453 1814 : }
454 :
455 2389 : void OOXMLFastContextHandler::endSectionGroup()
456 : {
457 2389 : if (isForwardEvents())
458 : {
459 1901 : if (mpParserState->isInParagraphGroup())
460 291 : endParagraphGroup();
461 :
462 1901 : if (mpParserState->isInSectionGroup())
463 : {
464 1813 : mpStream->endSectionGroup();
465 1813 : mpParserState->setInSectionGroup(false);
466 : }
467 : }
468 2389 : }
469 :
470 1701 : void OOXMLFastContextHandler::setLastParagraphInSection()
471 : {
472 1701 : mpParserState->setLastParagraphInSection(true);
473 1701 : mpStream->markLastParagraphInSection( );
474 1701 : }
475 :
476 1522 : void OOXMLFastContextHandler::setLastSectionGroup()
477 : {
478 1522 : mpStream->markLastSectionGroup( );
479 1522 : }
480 :
481 558678 : void OOXMLFastContextHandler::newProperty
482 : (const Id & /*nId*/, OOXMLValue::Pointer_t /*pVal*/)
483 : {
484 558678 : }
485 :
486 328 : void OOXMLFastContextHandler::setPropertySet
487 : (OOXMLPropertySet::Pointer_t /* pPropertySet */)
488 : {
489 328 : }
490 :
491 58804 : OOXMLPropertySet::Pointer_t OOXMLFastContextHandler::getPropertySet() const
492 : {
493 58804 : return OOXMLPropertySet::Pointer_t();
494 : }
495 :
496 1977 : void OOXMLFastContextHandler::startField()
497 : {
498 1977 : startCharacterGroup();
499 1977 : if (isForwardEvents())
500 1971 : mpStream->text(&cFieldStart, 1);
501 1977 : endCharacterGroup();
502 1977 : }
503 :
504 1852 : void OOXMLFastContextHandler::fieldSeparator()
505 : {
506 1852 : startCharacterGroup();
507 1852 : if (isForwardEvents())
508 1846 : mpStream->text(&cFieldSep, 1);
509 1852 : endCharacterGroup();
510 1852 : }
511 :
512 1977 : void OOXMLFastContextHandler::endField()
513 : {
514 1977 : startCharacterGroup();
515 1977 : if (isForwardEvents())
516 1971 : mpStream->text(&cFieldEnd, 1);
517 1977 : endCharacterGroup();
518 1977 : }
519 :
520 12 : void OOXMLFastContextHandler::lockField()
521 : {
522 12 : startCharacterGroup();
523 12 : if (isForwardEvents())
524 12 : mpStream->text(&cFieldLock, 1);
525 12 : endCharacterGroup();
526 12 : }
527 :
528 244 : void OOXMLFastContextHandler::ftnednref()
529 : {
530 244 : if (isForwardEvents())
531 44 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uFtnEdnRef), 1);
532 244 : }
533 :
534 38 : void OOXMLFastContextHandler::ftnednsep()
535 : {
536 38 : if (isForwardEvents())
537 38 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uFtnEdnSep), 1);
538 38 : }
539 :
540 44 : void OOXMLFastContextHandler::ftnedncont()
541 : {
542 44 : if (isForwardEvents())
543 0 : mpStream->text(&cFtnEdnCont, 1);
544 44 : }
545 :
546 6 : void OOXMLFastContextHandler::pgNum()
547 : {
548 6 : if (isForwardEvents())
549 6 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uPgNum), 1);
550 6 : }
551 :
552 5065 : void OOXMLFastContextHandler::tab()
553 : {
554 5065 : if (isForwardEvents())
555 5059 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uTab), 1);
556 5065 : }
557 :
558 0 : void OOXMLFastContextHandler::cr()
559 : {
560 0 : if (isForwardEvents())
561 0 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uCR), 1);
562 0 : }
563 :
564 3 : void OOXMLFastContextHandler::noBreakHyphen()
565 : {
566 3 : if (isForwardEvents())
567 3 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uNoBreakHyphen), 1);
568 3 : }
569 :
570 30 : void OOXMLFastContextHandler::softHyphen()
571 : {
572 30 : if (isForwardEvents())
573 30 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uSoftHyphen), 1);
574 30 : }
575 :
576 26661 : void OOXMLFastContextHandler::handleLastParagraphInSection()
577 : {
578 26661 : if (mpParserState->isLastParagraphInSection())
579 : {
580 173 : mpParserState->setLastParagraphInSection(false);
581 173 : startSectionGroup();
582 : }
583 26661 : }
584 :
585 27730 : void OOXMLFastContextHandler::endOfParagraph()
586 : {
587 27730 : if (! mpParserState->isInCharacterGroup())
588 7970 : startCharacterGroup();
589 27730 : if (isForwardEvents())
590 26109 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uCR), 1);
591 :
592 27730 : mpParserState->getDocument()->incrementProgress();
593 27730 : }
594 :
595 518 : void OOXMLFastContextHandler::startTxbxContent()
596 : {
597 : /*
598 : This usually means there are recursive <w:p> elements, and the ones
599 : inside and outside of w:txbxContent should not interfere (e.g.
600 : the lastParagraphInSection setting). So save the whole state
601 : and possibly start new groups for the nested content (not section
602 : group though, as that'd cause the txbxContent to be moved onto
603 : another page, I'm not sure how that should work exactly).
604 : */
605 518 : mpParserState->startTxbxContent();
606 518 : startParagraphGroup();
607 518 : }
608 :
609 518 : void OOXMLFastContextHandler::endTxbxContent()
610 : {
611 518 : endParagraphGroup();
612 518 : mpParserState->endTxbxContent();
613 518 : }
614 :
615 41863 : void OOXMLFastContextHandler::text(const OUString & sText)
616 : {
617 41863 : if (isForwardEvents())
618 : mpStream->utext(reinterpret_cast < const sal_uInt8 * >
619 41002 : (sText.getStr()),
620 82004 : sText.getLength());
621 41863 : }
622 :
623 1756 : void OOXMLFastContextHandler::positionOffset(const OUString& rText)
624 : {
625 1756 : if (isForwardEvents())
626 1756 : mpStream->positionOffset(rText, inPositionV);
627 1756 : }
628 :
629 4 : void OOXMLFastContextHandler::ignore()
630 : {
631 4 : }
632 :
633 69 : void OOXMLFastContextHandler::alignH(const OUString& rText)
634 : {
635 69 : if (isForwardEvents())
636 69 : mpStream->align(rText, /*bVertical=*/false);
637 69 : }
638 :
639 47 : void OOXMLFastContextHandler::alignV(const OUString& rText)
640 : {
641 47 : if (isForwardEvents())
642 47 : mpStream->align(rText, /*bVertical=*/true);
643 47 : }
644 :
645 842 : void OOXMLFastContextHandler::positivePercentage(const OUString& rText)
646 : {
647 842 : if (isForwardEvents())
648 842 : mpStream->positivePercentage(rText);
649 842 : }
650 :
651 332 : void OOXMLFastContextHandler::propagateCharacterProperties()
652 : {
653 332 : mpParserState->setCharacterProperties(getPropertySet());
654 332 : }
655 :
656 31 : void OOXMLFastContextHandler::propagateCharacterPropertiesAsSet(const Id & rId)
657 : {
658 31 : OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
659 62 : OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
660 :
661 : OOXMLProperty::Pointer_t pProp
662 62 : (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
663 :
664 31 : pPropertySet->add(pProp);
665 62 : mpParserState->setCharacterProperties(pPropertySet);
666 31 : }
667 :
668 7933 : void OOXMLFastContextHandler::propagateCellProperties()
669 : {
670 7933 : mpParserState->setCellProperties(getPropertySet());
671 7933 : }
672 :
673 2302 : void OOXMLFastContextHandler::propagateRowProperties()
674 : {
675 2302 : mpParserState->setRowProperties(getPropertySet());
676 2302 : }
677 :
678 1075 : void OOXMLFastContextHandler::propagateTableProperties()
679 : {
680 1075 : OOXMLPropertySet::Pointer_t pProps = getPropertySet();
681 :
682 1075 : mpParserState->setTableProperties(pProps);
683 1075 : }
684 :
685 7971 : void OOXMLFastContextHandler::sendCellProperties()
686 : {
687 7971 : mpParserState->resolveCellProperties(*mpStream);
688 7971 : }
689 :
690 2840 : void OOXMLFastContextHandler::sendRowProperties()
691 : {
692 2840 : mpParserState->resolveRowProperties(*mpStream);
693 2840 : }
694 :
695 2840 : void OOXMLFastContextHandler::sendTableProperties()
696 : {
697 2840 : mpParserState->resolveTableProperties(*mpStream);
698 2840 : }
699 :
700 539 : void OOXMLFastContextHandler::clearTableProps()
701 : {
702 : mpParserState->setTableProperties(OOXMLPropertySet::Pointer_t
703 539 : (new OOXMLPropertySetImpl()));
704 539 : }
705 :
706 920 : void OOXMLFastContextHandler::sendPropertiesWithId(const Id & rId)
707 : {
708 920 : OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
709 1840 : OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
710 :
711 : OOXMLProperty::Pointer_t pProp
712 1840 : (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
713 :
714 920 : pPropertySet->add(pProp);
715 1840 : mpStream->props(pPropertySet);
716 920 : }
717 :
718 12261 : void OOXMLFastContextHandler::clearProps()
719 : {
720 12261 : setPropertySet(OOXMLPropertySet::Pointer_t(new OOXMLPropertySetImpl()));
721 12261 : }
722 :
723 0 : void OOXMLFastContextHandler::setDefaultBooleanValue()
724 : {
725 0 : }
726 :
727 0 : void OOXMLFastContextHandler::setDefaultIntegerValue()
728 : {
729 0 : }
730 :
731 0 : void OOXMLFastContextHandler::setDefaultHexValue()
732 : {
733 0 : }
734 :
735 0 : void OOXMLFastContextHandler::setDefaultStringValue()
736 : {
737 0 : }
738 :
739 10530 : void OOXMLFastContextHandler::setDocument(OOXMLDocumentImpl* pDocument)
740 : {
741 10530 : mpParserState->setDocument(pDocument);
742 10530 : }
743 :
744 59906 : OOXMLDocumentImpl* OOXMLFastContextHandler::getDocument()
745 : {
746 59906 : return mpParserState->getDocument();
747 : }
748 :
749 11534 : void OOXMLFastContextHandler::setForwardEvents(bool bForwardEvents)
750 : {
751 11534 : mpParserState->setForwardEvents(bForwardEvents);
752 11534 : }
753 :
754 390410 : bool OOXMLFastContextHandler::isForwardEvents() const
755 : {
756 390410 : return mpParserState->isForwardEvents();
757 : }
758 :
759 10530 : void OOXMLFastContextHandler::setXNoteId(const sal_Int32 nId)
760 : {
761 10530 : mpParserState->setXNoteId(nId);
762 10530 : }
763 :
764 44 : void OOXMLFastContextHandler::setXNoteId(OOXMLValue::Pointer_t pValue)
765 : {
766 44 : mpParserState->setXNoteId(sal_Int32(pValue->getInt()));
767 44 : }
768 :
769 502 : sal_Int32 OOXMLFastContextHandler::getXNoteId() const
770 : {
771 502 : return mpParserState->getXNoteId();
772 : }
773 :
774 35 : void OOXMLFastContextHandler::resolveFootnote
775 : (const sal_Int32 nId)
776 : {
777 35 : mpParserState->getDocument()->resolveFootnote
778 35 : (*mpStream, 0, nId);
779 35 : }
780 :
781 9 : void OOXMLFastContextHandler::resolveEndnote(const sal_Int32 nId)
782 : {
783 9 : mpParserState->getDocument()->resolveEndnote
784 9 : (*mpStream, 0, nId);
785 9 : }
786 :
787 30 : void OOXMLFastContextHandler::resolveComment(const sal_Int32 nId)
788 : {
789 30 : mpParserState->getDocument()->resolveComment(*mpStream, nId);
790 30 : }
791 :
792 0 : void OOXMLFastContextHandler::resolvePicture(const OUString & rId)
793 : {
794 0 : mpParserState->getDocument()->resolvePicture(*mpStream, rId);
795 0 : }
796 :
797 644 : void OOXMLFastContextHandler::resolveHeader
798 : (const sal_Int32 type, const OUString & rId)
799 : {
800 644 : mpParserState->getDocument()->resolveHeader(*mpStream, type, rId);
801 644 : }
802 :
803 668 : void OOXMLFastContextHandler::resolveFooter
804 : (const sal_Int32 type, const OUString & rId)
805 : {
806 668 : mpParserState->getDocument()->resolveFooter(*mpStream, type, rId);
807 668 : }
808 :
809 : // Add the data pointed to by the reference as another property.
810 54 : void OOXMLFastContextHandler::resolveData(const OUString & rId)
811 : {
812 54 : OOXMLDocument * objDocument = getDocument();
813 : SAL_WARN_IF(!objDocument, "writerfilter", "no document to resolveData");
814 54 : if (!objDocument)
815 54 : return;
816 :
817 : uno::Reference<io::XInputStream> xInputStream
818 54 : (objDocument->getInputStreamForId(rId));
819 :
820 108 : OOXMLValue::Pointer_t aValue(new OOXMLInputStreamValue(xInputStream));
821 :
822 108 : newProperty(NS_ooxml::LN_inputstream, aValue);
823 : }
824 :
825 343 : OUString OOXMLFastContextHandler::getTargetForId
826 : (const OUString & rId)
827 : {
828 343 : return mpParserState->getDocument()->getTargetForId(rId);
829 : }
830 :
831 0 : void OOXMLFastContextHandler::resolvePropertySetAttrs()
832 : {
833 0 : }
834 :
835 686529 : void OOXMLFastContextHandler::sendPropertyToParent()
836 : {
837 686529 : if (mpParent != nullptr)
838 : {
839 686529 : OOXMLPropertySet::Pointer_t pProps(mpParent->getPropertySet());
840 :
841 686529 : if (pProps.get() != nullptr)
842 : {
843 : OOXMLProperty::Pointer_t
844 686529 : pProp(new OOXMLPropertyImpl(mId, getValue(),
845 686529 : OOXMLPropertyImpl::SPRM));
846 686529 : pProps->add(pProp);
847 686529 : }
848 : }
849 686529 : }
850 :
851 1034985 : void OOXMLFastContextHandler::sendPropertiesToParent()
852 : {
853 1034985 : if (mpParent != nullptr)
854 : {
855 1034985 : OOXMLPropertySet::Pointer_t pParentProps(mpParent->getPropertySet());
856 :
857 1034985 : if (pParentProps.get() != nullptr)
858 : {
859 976181 : OOXMLPropertySet::Pointer_t pProps(getPropertySet());
860 :
861 976181 : if (pProps.get() != nullptr)
862 : {
863 : OOXMLValue::Pointer_t pValue
864 976181 : (new OOXMLPropertySetValue(getPropertySet()));
865 :
866 : OOXMLProperty::Pointer_t pProp
867 1952362 : (new OOXMLPropertyImpl(getId(), pValue, OOXMLPropertyImpl::SPRM));
868 :
869 :
870 1952362 : pParentProps->add(pProp);
871 :
872 976181 : }
873 1034985 : }
874 : }
875 1034985 : }
876 :
877 :
878 : /*
879 : class OOXMLFastContextHandlerStream
880 : */
881 :
882 139817 : OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream
883 : (OOXMLFastContextHandler * pContext)
884 : : OOXMLFastContextHandler(pContext),
885 139817 : mpPropertySetAttrs(new OOXMLPropertySetImpl())
886 : {
887 139817 : }
888 :
889 279634 : OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream()
890 : {
891 279634 : }
892 :
893 102045 : void OOXMLFastContextHandlerStream::newProperty(const Id & rId,
894 : OOXMLValue::Pointer_t pVal)
895 : {
896 102045 : if (rId != 0x0)
897 : {
898 : OOXMLPropertyImpl::Pointer_t pProperty
899 20464 : (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
900 :
901 20464 : mpPropertySetAttrs->add(pProperty);
902 : }
903 102045 : }
904 :
905 39 : void OOXMLFastContextHandlerStream::sendProperty(Id nId)
906 : {
907 39 : OOXMLPropertySetEntryToString aHandler(nId);
908 39 : getPropertySetAttrs()->resolve(aHandler);
909 39 : const OUString & sText = aHandler.getString();
910 : mpStream->utext(reinterpret_cast < const sal_uInt8 * >
911 39 : (sText.getStr()),
912 78 : sText.getLength());
913 39 : }
914 :
915 :
916 0 : void OOXMLFastContextHandlerStream::resolvePropertySetAttrs()
917 : {
918 0 : mpStream->props(mpPropertySetAttrs);
919 0 : }
920 :
921 328 : OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerStream::getPropertySet()
922 : const
923 : {
924 328 : return getPropertySetAttrs();
925 : }
926 :
927 736 : void OOXMLFastContextHandlerStream::handleHyperlink()
928 : {
929 736 : OOXMLHyperlinkHandler aHyperlinkHandler(this);
930 736 : getPropertySetAttrs()->resolve(aHyperlinkHandler);
931 736 : }
932 :
933 : /*
934 : class OOXMLFastContextHandlerProperties
935 : */
936 1122360 : OOXMLFastContextHandlerProperties::OOXMLFastContextHandlerProperties
937 : (OOXMLFastContextHandler * pContext)
938 0 : : OOXMLFastContextHandler(pContext), mpPropertySet(new OOXMLPropertySetImpl()),
939 1122360 : mbResolve(false)
940 : {
941 1122360 : if (pContext->getResource() == STREAM)
942 87375 : mbResolve = true;
943 1122360 : }
944 :
945 2240514 : OOXMLFastContextHandlerProperties::~OOXMLFastContextHandlerProperties()
946 : {
947 2240514 : }
948 :
949 1120358 : void OOXMLFastContextHandlerProperties::lcl_endFastElement
950 : (Token_t Element)
951 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
952 : {
953 1120358 : endAction(Element);
954 :
955 1120358 : if (mbResolve)
956 : {
957 85373 : if (isForwardEvents())
958 : {
959 82934 : mpStream->props(mpPropertySet);
960 : }
961 : }
962 : else
963 : {
964 1034985 : sendPropertiesToParent();
965 : }
966 1120358 : }
967 :
968 58804 : OOXMLValue::Pointer_t OOXMLFastContextHandlerProperties::getValue() const
969 : {
970 58804 : return OOXMLValue::Pointer_t(new OOXMLPropertySetValue(mpPropertySet));
971 : }
972 :
973 2016361 : void OOXMLFastContextHandlerProperties::newProperty
974 : (const Id & rId, OOXMLValue::Pointer_t pVal)
975 : {
976 2016361 : if (rId != 0x0)
977 : {
978 : OOXMLPropertyImpl::Pointer_t pProperty
979 1990108 : (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
980 :
981 1990108 : mpPropertySet->add(pProperty);
982 : }
983 2016361 : }
984 :
985 44 : void OOXMLFastContextHandlerProperties::handleXNotes()
986 : {
987 44 : switch (mnToken)
988 : {
989 : case W_TOKEN(footnoteReference):
990 : {
991 35 : OOXMLFootnoteHandler aFootnoteHandler(this);
992 35 : mpPropertySet->resolve(aFootnoteHandler);
993 : }
994 35 : break;
995 : case W_TOKEN(endnoteReference):
996 : {
997 9 : OOXMLEndnoteHandler aEndnoteHandler(this);
998 9 : mpPropertySet->resolve(aEndnoteHandler);
999 : }
1000 9 : break;
1001 : default:
1002 0 : break;
1003 : }
1004 44 : }
1005 :
1006 1312 : void OOXMLFastContextHandlerProperties::handleHdrFtr()
1007 : {
1008 1312 : switch (mnToken)
1009 : {
1010 : case W_TOKEN(footerReference):
1011 : {
1012 668 : OOXMLFooterHandler aFooterHandler(this);
1013 668 : mpPropertySet->resolve(aFooterHandler);
1014 668 : aFooterHandler.finalize();
1015 : }
1016 668 : break;
1017 : case W_TOKEN(headerReference):
1018 : {
1019 644 : OOXMLHeaderHandler aHeaderHandler(this);
1020 644 : mpPropertySet->resolve(aHeaderHandler);
1021 644 : aHeaderHandler.finalize();
1022 : }
1023 644 : break;
1024 : default:
1025 0 : break;
1026 : }
1027 1312 : }
1028 :
1029 30 : void OOXMLFastContextHandlerProperties::handleComment()
1030 : {
1031 30 : OOXMLCommentHandler aCommentHandler(this);
1032 30 : getPropertySet()->resolve(aCommentHandler);
1033 30 : }
1034 :
1035 1338 : void OOXMLFastContextHandlerProperties::handlePicture()
1036 : {
1037 1338 : OOXMLPictureHandler aPictureHandler(this);
1038 1338 : getPropertySet()->resolve(aPictureHandler);
1039 1338 : }
1040 :
1041 579 : void OOXMLFastContextHandlerProperties::handleBreak()
1042 : {
1043 579 : OOXMLBreakHandler aBreakHandler(*mpStream);
1044 579 : getPropertySet()->resolve(aBreakHandler);
1045 579 : }
1046 :
1047 54 : void OOXMLFastContextHandlerProperties::handleOLE()
1048 : {
1049 54 : OOXMLOLEHandler aOLEHandler(this);
1050 54 : getPropertySet()->resolve(aOLEHandler);
1051 54 : }
1052 :
1053 0 : void OOXMLFastContextHandlerProperties::handleFontRel()
1054 : {
1055 0 : OOXMLEmbeddedFontHandler handler(this);
1056 0 : getPropertySet()->resolve(handler);
1057 0 : }
1058 :
1059 0 : void OOXMLFastContextHandlerProperties::setParent
1060 : (OOXMLFastContextHandler * pParent)
1061 : {
1062 0 : OOXMLFastContextHandler::setParent(pParent);
1063 :
1064 0 : if (mpParent->getResource() == STREAM)
1065 0 : mbResolve = true;
1066 0 : }
1067 :
1068 11933 : void OOXMLFastContextHandlerProperties::setPropertySet
1069 : (OOXMLPropertySet::Pointer_t pPropertySet)
1070 : {
1071 11933 : if (pPropertySet.get() != nullptr)
1072 11933 : mpPropertySet = pPropertySet;
1073 11933 : }
1074 :
1075 : OOXMLPropertySet::Pointer_t
1076 3634482 : OOXMLFastContextHandlerProperties::getPropertySet() const
1077 : {
1078 3634482 : return mpPropertySet;
1079 : }
1080 :
1081 : /*
1082 : * class OOXMLFasContextHandlerPropertyTable
1083 : */
1084 :
1085 1807 : OOXMLFastContextHandlerPropertyTable::OOXMLFastContextHandlerPropertyTable
1086 : (OOXMLFastContextHandler * pContext)
1087 1807 : : OOXMLFastContextHandlerProperties(pContext)
1088 : {
1089 1807 : }
1090 :
1091 3614 : OOXMLFastContextHandlerPropertyTable::~OOXMLFastContextHandlerPropertyTable()
1092 : {
1093 3614 : }
1094 :
1095 1807 : void OOXMLFastContextHandlerPropertyTable::lcl_endFastElement
1096 : (Token_t Element)
1097 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1098 : {
1099 1807 : OOXMLPropertySet::Pointer_t pPropSet(mpPropertySet->clone());
1100 : OOXMLTableImpl::ValuePointer_t pTmpVal
1101 3614 : (new OOXMLPropertySetValue(pPropSet));
1102 :
1103 1807 : mTable.add(pTmpVal);
1104 :
1105 3614 : writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
1106 :
1107 1807 : mpStream->table(mId, pTable);
1108 :
1109 3614 : endAction(Element);
1110 1807 : }
1111 :
1112 : /*
1113 : class OOXMLFastContextHandlerValue
1114 : */
1115 :
1116 686529 : OOXMLFastContextHandlerValue::OOXMLFastContextHandlerValue
1117 : (OOXMLFastContextHandler * pContext)
1118 686529 : : OOXMLFastContextHandler(pContext)
1119 : {
1120 686529 : }
1121 :
1122 1373058 : OOXMLFastContextHandlerValue::~OOXMLFastContextHandlerValue()
1123 : {
1124 1373058 : }
1125 :
1126 665912 : void OOXMLFastContextHandlerValue::setValue(OOXMLValue::Pointer_t pValue)
1127 : {
1128 665912 : mpValue = pValue;
1129 665912 : }
1130 :
1131 686529 : OOXMLValue::Pointer_t OOXMLFastContextHandlerValue::getValue() const
1132 : {
1133 686529 : return mpValue;
1134 : }
1135 :
1136 686529 : void OOXMLFastContextHandlerValue::lcl_endFastElement
1137 : (Token_t Element)
1138 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1139 : {
1140 686529 : sendPropertyToParent();
1141 :
1142 686529 : endAction(Element);
1143 686529 : }
1144 :
1145 125109 : void OOXMLFastContextHandlerValue::setDefaultBooleanValue()
1146 : {
1147 125109 : if (mpValue.get() == nullptr)
1148 : {
1149 114129 : OOXMLValue::Pointer_t pValue = OOXMLBooleanValue::Create(true);
1150 114129 : setValue(pValue);
1151 : }
1152 125109 : }
1153 :
1154 171323 : void OOXMLFastContextHandlerValue::setDefaultIntegerValue()
1155 : {
1156 171323 : if (mpValue.get() == nullptr)
1157 : {
1158 0 : OOXMLValue::Pointer_t pValue = OOXMLIntegerValue::Create(0);
1159 0 : setValue(pValue);
1160 : }
1161 171323 : }
1162 :
1163 156122 : void OOXMLFastContextHandlerValue::setDefaultHexValue()
1164 : {
1165 156122 : if (mpValue.get() == nullptr)
1166 : {
1167 0 : OOXMLValue::Pointer_t pValue(new OOXMLHexValue(sal_uInt32(0)));
1168 0 : setValue(pValue);
1169 : }
1170 156122 : }
1171 :
1172 120378 : void OOXMLFastContextHandlerValue::setDefaultStringValue()
1173 : {
1174 120378 : if (mpValue.get() == nullptr)
1175 : {
1176 18 : OOXMLValue::Pointer_t pValue(new OOXMLStringValue(OUString()));
1177 18 : setValue(pValue);
1178 : }
1179 120378 : }
1180 : /*
1181 : class OOXMLFastContextHandlerTable
1182 : */
1183 :
1184 4424 : OOXMLFastContextHandlerTable::OOXMLFastContextHandlerTable
1185 : (OOXMLFastContextHandler * pContext)
1186 4424 : : OOXMLFastContextHandler(pContext)
1187 : {
1188 4424 : }
1189 :
1190 8848 : OOXMLFastContextHandlerTable::~OOXMLFastContextHandlerTable()
1191 : {
1192 8848 : }
1193 :
1194 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
1195 61739 : OOXMLFastContextHandlerTable::createFastChildContext
1196 : (Token_t Element,
1197 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1198 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1199 : {
1200 61739 : addCurrentChild();
1201 :
1202 61739 : mCurrentChild.set(OOXMLFastContextHandler::createFastChildContext(Element, Attribs));
1203 :
1204 61739 : return mCurrentChild;
1205 : }
1206 :
1207 4424 : void OOXMLFastContextHandlerTable::lcl_endFastElement
1208 : (Token_t /*Element*/)
1209 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1210 : {
1211 4424 : addCurrentChild();
1212 :
1213 4424 : writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
1214 4424 : if (isForwardEvents() && mId != 0x0)
1215 : {
1216 4424 : mpStream->table(mId, pTable);
1217 4424 : }
1218 4424 : }
1219 :
1220 66163 : void OOXMLFastContextHandlerTable::addCurrentChild()
1221 : {
1222 66163 : OOXMLFastContextHandler * pHandler = dynamic_cast<OOXMLFastContextHandler*>(mCurrentChild.get());
1223 66163 : if (pHandler != nullptr)
1224 : {
1225 58804 : OOXMLValue::Pointer_t pValue(pHandler->getValue());
1226 :
1227 58804 : if (pValue.get() != nullptr)
1228 : {
1229 58804 : OOXMLTableImpl::ValuePointer_t pTmpVal(pValue->clone());
1230 58804 : mTable.add(pTmpVal);
1231 58804 : }
1232 : }
1233 66163 : }
1234 :
1235 : /*
1236 : class OOXMLFastContextHandlerXNote
1237 : */
1238 :
1239 502 : OOXMLFastContextHandlerXNote::OOXMLFastContextHandlerXNote
1240 : (OOXMLFastContextHandler * pContext)
1241 : : OOXMLFastContextHandlerProperties(pContext)
1242 : , mbForwardEventsSaved(false)
1243 : , mnMyXNoteId(0)
1244 502 : , mnMyXNoteType(0)
1245 : {
1246 502 : }
1247 :
1248 1004 : OOXMLFastContextHandlerXNote::~OOXMLFastContextHandlerXNote()
1249 : {
1250 1004 : }
1251 :
1252 502 : void OOXMLFastContextHandlerXNote::lcl_startFastElement
1253 : (Token_t Element,
1254 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
1255 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1256 : {
1257 502 : mbForwardEventsSaved = isForwardEvents();
1258 :
1259 : // If this is the note we're looking for or this is the footnote separator one.
1260 502 : if (mnMyXNoteId == getXNoteId() || static_cast<sal_uInt32>(mnMyXNoteType) == NS_ooxml::LN_Value_doc_ST_FtnEdn_separator)
1261 118 : setForwardEvents(true);
1262 : else
1263 384 : setForwardEvents(false);
1264 :
1265 502 : startAction(Element);
1266 502 : }
1267 :
1268 502 : void OOXMLFastContextHandlerXNote::lcl_endFastElement
1269 : (Token_t Element)
1270 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1271 : {
1272 502 : endAction(Element);
1273 :
1274 502 : OOXMLFastContextHandlerProperties::lcl_endFastElement(Element);
1275 :
1276 502 : setForwardEvents(mbForwardEventsSaved);
1277 502 : }
1278 :
1279 502 : void OOXMLFastContextHandlerXNote::checkId(OOXMLValue::Pointer_t pValue)
1280 : {
1281 502 : mnMyXNoteId = sal_Int32(pValue->getInt());
1282 502 : }
1283 :
1284 88 : void OOXMLFastContextHandlerXNote::checkType(OOXMLValue::Pointer_t pValue)
1285 : {
1286 88 : mnMyXNoteType = pValue->getInt();
1287 88 : }
1288 :
1289 : /*
1290 : class OOXMLFastContextHandlerTextTableCell
1291 : */
1292 :
1293 7959 : OOXMLFastContextHandlerTextTableCell::OOXMLFastContextHandlerTextTableCell
1294 : (OOXMLFastContextHandler * pContext)
1295 7959 : : OOXMLFastContextHandler(pContext)
1296 : {
1297 7959 : }
1298 :
1299 15918 : OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell()
1300 : {
1301 15918 : }
1302 :
1303 7959 : void OOXMLFastContextHandlerTextTableCell::startCell()
1304 : {
1305 7959 : }
1306 :
1307 7959 : void OOXMLFastContextHandlerTextTableCell::endCell()
1308 : {
1309 7959 : if (isForwardEvents())
1310 : {
1311 7959 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
1312 : {
1313 7959 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth);
1314 : OOXMLProperty::Pointer_t pProp
1315 15918 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM));
1316 15918 : pProps->add(pProp);
1317 : }
1318 : {
1319 7959 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1);
1320 : OOXMLProperty::Pointer_t pProp
1321 15918 : (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM));
1322 15918 : pProps->add(pProp);
1323 : }
1324 : {
1325 7959 : OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0);
1326 : OOXMLProperty::Pointer_t pProp
1327 15918 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell, pVal, OOXMLPropertyImpl::SPRM));
1328 15918 : pProps->add(pProp);
1329 : }
1330 :
1331 7959 : mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
1332 : }
1333 7959 : }
1334 :
1335 : /*
1336 : class OOXMLFastContextHandlerTextTableRow
1337 : */
1338 :
1339 2847 : OOXMLFastContextHandlerTextTableRow::OOXMLFastContextHandlerTextTableRow
1340 : (OOXMLFastContextHandler * pContext)
1341 2847 : : OOXMLFastContextHandler(pContext)
1342 : {
1343 2847 : }
1344 :
1345 5694 : OOXMLFastContextHandlerTextTableRow::~OOXMLFastContextHandlerTextTableRow()
1346 : {
1347 5694 : }
1348 :
1349 2840 : void OOXMLFastContextHandlerTextTableRow::startRow()
1350 : {
1351 2840 : }
1352 :
1353 2840 : void OOXMLFastContextHandlerTextTableRow::endRow()
1354 : {
1355 2840 : startParagraphGroup();
1356 :
1357 2840 : if (isForwardEvents())
1358 : {
1359 2840 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
1360 : {
1361 2840 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth);
1362 : OOXMLProperty::Pointer_t pProp
1363 5680 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM));
1364 5680 : pProps->add(pProp);
1365 : }
1366 : {
1367 2840 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1);
1368 : OOXMLProperty::Pointer_t pProp
1369 5680 : (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM));
1370 5680 : pProps->add(pProp);
1371 : }
1372 : {
1373 2840 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1);
1374 : OOXMLProperty::Pointer_t pProp
1375 5680 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblRow, pVal, OOXMLPropertyImpl::SPRM));
1376 5680 : pProps->add(pProp);
1377 : }
1378 :
1379 2840 : mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
1380 : }
1381 :
1382 2840 : startCharacterGroup();
1383 :
1384 2840 : if (isForwardEvents())
1385 2840 : mpStream->utext(reinterpret_cast<const sal_uInt8*>(&uCR), 1);
1386 :
1387 2840 : endCharacterGroup();
1388 2840 : endParagraphGroup();
1389 2840 : }
1390 :
1391 : // Handle w:gridBefore here by faking necessary input that'll fake cells. I'm apparently
1392 : // not insane enough to find out how to add cells in dmapper.
1393 7 : void OOXMLFastContextHandlerTextTableRow::handleGridBefore( OOXMLValue::Pointer_t val )
1394 : {
1395 7 : int count = val->getInt();
1396 19 : for( int i = 0;
1397 : i < count;
1398 : ++i )
1399 : {
1400 12 : endOfParagraph();
1401 :
1402 12 : if (isForwardEvents())
1403 : {
1404 : // This whole part is OOXMLFastContextHandlerTextTableCell::endCell() .
1405 12 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
1406 : {
1407 12 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth);
1408 : OOXMLProperty::Pointer_t pProp
1409 24 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM));
1410 24 : pProps->add(pProp);
1411 : }
1412 : {
1413 12 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1);
1414 : OOXMLProperty::Pointer_t pProp
1415 24 : (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM));
1416 24 : pProps->add(pProp);
1417 : }
1418 : {
1419 12 : OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0);
1420 : OOXMLProperty::Pointer_t pProp
1421 24 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell, pVal, OOXMLPropertyImpl::SPRM));
1422 24 : pProps->add(pProp);
1423 : }
1424 :
1425 12 : mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
1426 :
1427 : // fake <w:tcBorders> with no border
1428 12 : OOXMLPropertySet::Pointer_t pCellProps( new OOXMLPropertySetImpl());
1429 : {
1430 12 : OOXMLPropertySet::Pointer_t pBorderProps( new OOXMLPropertySetImpl());
1431 : static Id borders[] = { NS_ooxml::LN_CT_TcBorders_top, NS_ooxml::LN_CT_TcBorders_bottom,
1432 : NS_ooxml::LN_CT_TcBorders_start, NS_ooxml::LN_CT_TcBorders_end };
1433 60 : for( size_t j = 0; j < SAL_N_ELEMENTS( borders ); ++j )
1434 48 : pBorderProps->add( fakeNoBorder( borders[ j ] ));
1435 24 : OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue( pBorderProps ));
1436 : OOXMLProperty::Pointer_t pProp
1437 24 : (new OOXMLPropertyImpl(NS_ooxml::LN_CT_TcPrBase_tcBorders, pValue, OOXMLPropertyImpl::SPRM));
1438 12 : pCellProps->add(pProp);
1439 24 : mpParserState->setCellProperties(pCellProps);
1440 12 : }
1441 : }
1442 :
1443 12 : sendCellProperties();
1444 12 : endParagraphGroup();
1445 : }
1446 7 : }
1447 :
1448 48 : OOXMLProperty::Pointer_t OOXMLFastContextHandlerTextTableRow::fakeNoBorder( Id id )
1449 : {
1450 48 : OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySetImpl());
1451 96 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(0);
1452 : OOXMLProperty::Pointer_t pPropVal
1453 96 : (new OOXMLPropertyImpl(NS_ooxml::LN_CT_Border_val, pVal, OOXMLPropertyImpl::ATTRIBUTE));
1454 48 : pProps->add(pPropVal);
1455 96 : OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue( pProps ));
1456 : OOXMLProperty::Pointer_t pProp
1457 48 : (new OOXMLPropertyImpl(id, pValue, OOXMLPropertyImpl::SPRM));
1458 96 : return pProp;
1459 : }
1460 :
1461 : /*
1462 : class OOXMLFastContextHandlerTextTable
1463 : */
1464 :
1465 539 : OOXMLFastContextHandlerTextTable::OOXMLFastContextHandlerTextTable
1466 : (OOXMLFastContextHandler * pContext)
1467 539 : : OOXMLFastContextHandler(pContext)
1468 : {
1469 539 : }
1470 :
1471 1617 : OOXMLFastContextHandlerTextTable::~OOXMLFastContextHandlerTextTable()
1472 : {
1473 539 : clearTableProps();
1474 1078 : }
1475 :
1476 539 : void OOXMLFastContextHandlerTextTable::lcl_startFastElement
1477 : (Token_t Element,
1478 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
1479 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1480 : {
1481 539 : mpParserState->startTable();
1482 539 : mnTableDepth++;
1483 :
1484 539 : std::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl );
1485 : {
1486 539 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth);
1487 : OOXMLProperty::Pointer_t pProp
1488 1078 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblStart, pVal, OOXMLPropertyImpl::SPRM));
1489 1078 : pProps->add(pProp);
1490 : }
1491 539 : mpParserState->setCharacterProperties(pProps);
1492 :
1493 539 : startAction(Element);
1494 539 : }
1495 :
1496 539 : void OOXMLFastContextHandlerTextTable::lcl_endFastElement
1497 : (Token_t Element)
1498 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1499 : {
1500 539 : endAction(Element);
1501 :
1502 539 : std::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl );
1503 : {
1504 539 : OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth);
1505 : OOXMLProperty::Pointer_t pProp
1506 1078 : (new OOXMLPropertyImpl(NS_ooxml::LN_tblEnd, pVal, OOXMLPropertyImpl::SPRM));
1507 1078 : pProps->add(pProp);
1508 : }
1509 539 : mpParserState->setCharacterProperties(pProps);
1510 :
1511 539 : mnTableDepth--;
1512 539 : mpParserState->endTable();
1513 539 : }
1514 :
1515 : /*
1516 : class OOXMLFastContextHandlerShape
1517 : */
1518 :
1519 1702 : OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
1520 : (OOXMLFastContextHandler * pContext)
1521 : : OOXMLFastContextHandlerProperties(pContext), m_bShapeSent( false ),
1522 1702 : m_bShapeStarted(false)
1523 : {
1524 1702 : mrShapeContext.set( getDocument( )->getShapeContext( ) );
1525 1702 : if ( !mrShapeContext.is( ) )
1526 : {
1527 : // Define the shape context for the whole document
1528 1598 : mrShapeContext = css::xml::sax::FastShapeContextHandler::create(
1529 799 : getComponentContext());
1530 799 : getDocument()->setShapeContext( mrShapeContext );
1531 : }
1532 :
1533 1702 : mrShapeContext->setModel(getDocument()->getModel());
1534 1702 : uno::Reference<document::XDocumentPropertiesSupplier> xDocSupplier(getDocument()->getModel(), uno::UNO_QUERY_THROW);
1535 1702 : mrShapeContext->setDocumentProperties(xDocSupplier->getDocumentProperties());
1536 1702 : mrShapeContext->setDrawPage(getDocument()->getDrawPage());
1537 1702 : mrShapeContext->setInputStream(getDocument()->getStorageStream());
1538 :
1539 1702 : mrShapeContext->setRelationFragmentPath
1540 1702 : (mpParserState->getTarget());
1541 1702 : }
1542 :
1543 3404 : OOXMLFastContextHandlerShape::~OOXMLFastContextHandlerShape()
1544 : {
1545 3404 : }
1546 :
1547 1702 : void OOXMLFastContextHandlerShape::lcl_startFastElement
1548 : (Token_t Element,
1549 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1550 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1551 : {
1552 1702 : startAction(Element);
1553 :
1554 1702 : if (mrShapeContext.is())
1555 : {
1556 1702 : mrShapeContext->startFastElement(Element, Attribs);
1557 : }
1558 1702 : }
1559 :
1560 0 : void SAL_CALL OOXMLFastContextHandlerShape::startUnknownElement
1561 : (const OUString & Namespace,
1562 : const OUString & Name,
1563 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1564 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1565 : {
1566 0 : if (mrShapeContext.is())
1567 0 : mrShapeContext->startUnknownElement(Namespace, Name, Attribs);
1568 0 : }
1569 :
1570 1702 : void OOXMLFastContextHandlerShape::setToken(Token_t nToken)
1571 : {
1572 1702 : OOXMLFastContextHandler::setToken(nToken);
1573 :
1574 1702 : if (mrShapeContext.is())
1575 1702 : mrShapeContext->setStartToken(nToken);
1576 1702 : }
1577 :
1578 2214 : void OOXMLFastContextHandlerShape::sendShape( Token_t Element )
1579 : {
1580 2214 : if ( mrShapeContext.is() && !m_bShapeSent )
1581 : {
1582 1702 : awt::Point aPosition = mpStream->getPositionOffset();
1583 1702 : mrShapeContext->setPosition(aPosition);
1584 1702 : uno::Reference<drawing::XShape> xShape(mrShapeContext->getShape());
1585 1702 : if (xShape.is())
1586 : {
1587 : OOXMLValue::Pointer_t
1588 1697 : pValue(new OOXMLShapeValue(xShape));
1589 1697 : newProperty(NS_ooxml::LN_shape, pValue);
1590 1697 : m_bShapeSent = true;
1591 :
1592 1697 : bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic );
1593 :
1594 : // Notify the dmapper that the shape is ready to use
1595 1697 : if ( !bIsPicture )
1596 : {
1597 1407 : mpStream->startShape( xShape );
1598 1407 : m_bShapeStarted = true;
1599 1697 : }
1600 1702 : }
1601 : }
1602 2214 : }
1603 :
1604 1702 : void OOXMLFastContextHandlerShape::lcl_endFastElement
1605 : (Token_t Element)
1606 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1607 : {
1608 1702 : if (mrShapeContext.is())
1609 : {
1610 1702 : mrShapeContext->endFastElement(Element);
1611 1702 : sendShape( Element );
1612 : }
1613 :
1614 1702 : OOXMLFastContextHandlerProperties::lcl_endFastElement(Element);
1615 :
1616 : // Ending the shape should be the last thing to do
1617 1702 : bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic );
1618 1702 : if ( !bIsPicture && m_bShapeStarted)
1619 1407 : mpStream->endShape( );
1620 1702 : }
1621 :
1622 0 : void SAL_CALL OOXMLFastContextHandlerShape::endUnknownElement
1623 : (const OUString & Namespace,
1624 : const OUString & Name)
1625 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1626 : {
1627 0 : if (mrShapeContext.is())
1628 0 : mrShapeContext->endUnknownElement(Namespace, Name);
1629 0 : }
1630 :
1631 : uno::Reference< xml::sax::XFastContextHandler >
1632 5375 : OOXMLFastContextHandlerShape::lcl_createFastChildContext
1633 : (Token_t Element,
1634 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1635 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1636 : {
1637 5375 : uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
1638 :
1639 5375 : bool bGroupShape = Element == Token_t(NMSP_vml | XML_group);
1640 : // drawingML version also counts as a group shape.
1641 5375 : bGroupShape |= mrShapeContext->getStartToken() == Token_t(NMSP_wpg | XML_wgp);
1642 :
1643 5375 : switch (oox::getNamespace(Element))
1644 : {
1645 : case NMSP_doc:
1646 : case NMSP_vmlWord:
1647 : case NMSP_vmlOffice:
1648 74 : if (!bGroupShape)
1649 74 : xContextHandler.set(OOXMLFactory::createFastChildContextFromStart(this, Element));
1650 : // no break;
1651 : default:
1652 5375 : if (!xContextHandler.is())
1653 : {
1654 5301 : if (mrShapeContext.is())
1655 : {
1656 : uno::Reference<XFastContextHandler> pChildContext =
1657 5301 : mrShapeContext->createFastChildContext(Element, Attribs);
1658 :
1659 : OOXMLFastContextHandlerWrapper * pWrapper =
1660 5301 : new OOXMLFastContextHandlerWrapper(this, pChildContext);
1661 :
1662 5301 : if (!bGroupShape)
1663 : {
1664 4808 : pWrapper->addNamespace(NMSP_doc);
1665 4808 : pWrapper->addNamespace(NMSP_vmlWord);
1666 4808 : pWrapper->addNamespace(NMSP_vmlOffice);
1667 4808 : pWrapper->addToken( NMSP_vml|XML_textbox );
1668 : }
1669 :
1670 5301 : xContextHandler.set(pWrapper);
1671 : }
1672 : else
1673 0 : xContextHandler.set(this);
1674 : }
1675 5375 : break;
1676 : }
1677 :
1678 : // VML import of shape text is already handled by
1679 : // OOXMLFastContextHandlerWrapper::lcl_createFastChildContext(), here we
1680 : // handle the WPS import of shape text, as there the parent context is a
1681 : // Shape one, so a different situation.
1682 5375 : if (Element == static_cast<sal_Int32>(NMSP_wps | XML_txbx) ||
1683 : Element == static_cast<sal_Int32>(NMSP_wps | XML_linkedTxbx) )
1684 437 : sendShape(Element);
1685 :
1686 5375 : return xContextHandler;
1687 : }
1688 :
1689 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
1690 0 : OOXMLFastContextHandlerShape::createUnknownChildContext
1691 : (const OUString & Namespace,
1692 : const OUString & Name,
1693 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1694 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1695 : {
1696 0 : uno::Reference< xml::sax::XFastContextHandler > xResult;
1697 :
1698 0 : if (mrShapeContext.is())
1699 0 : xResult.set(mrShapeContext->createUnknownChildContext
1700 0 : (Namespace, Name, Attribs));
1701 :
1702 0 : return xResult;
1703 : }
1704 :
1705 618 : void OOXMLFastContextHandlerShape::lcl_characters
1706 : (const OUString & aChars)
1707 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1708 : {
1709 618 : if (mrShapeContext.is())
1710 618 : mrShapeContext->characters(aChars);
1711 618 : }
1712 :
1713 : /*
1714 : class OOXMLFastContextHandlerWrapper
1715 : */
1716 :
1717 50963 : OOXMLFastContextHandlerWrapper::OOXMLFastContextHandlerWrapper
1718 : (OOXMLFastContextHandler * pParent,
1719 : uno::Reference<XFastContextHandler> xContext)
1720 50963 : : OOXMLFastContextHandler(pParent), mxContext(xContext)
1721 : {
1722 50963 : setId(pParent->getId());
1723 50963 : setToken(pParent->getToken());
1724 50963 : setPropertySet(pParent->getPropertySet());
1725 50963 : }
1726 :
1727 101926 : OOXMLFastContextHandlerWrapper::~OOXMLFastContextHandlerWrapper()
1728 : {
1729 101926 : }
1730 :
1731 220 : void SAL_CALL OOXMLFastContextHandlerWrapper::startUnknownElement
1732 : (const OUString & Namespace,
1733 : const OUString & Name,
1734 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1735 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1736 : {
1737 220 : if (mxContext.is())
1738 0 : mxContext->startUnknownElement(Namespace, Name, Attribs);
1739 220 : }
1740 :
1741 220 : void SAL_CALL OOXMLFastContextHandlerWrapper::endUnknownElement
1742 : (const OUString & Namespace,
1743 : const OUString & Name)
1744 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1745 : {
1746 220 : if (mxContext.is())
1747 0 : mxContext->endUnknownElement(Namespace, Name);
1748 220 : }
1749 :
1750 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
1751 326 : OOXMLFastContextHandlerWrapper::createUnknownChildContext
1752 : (const OUString & Namespace,
1753 : const OUString & Name,
1754 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1755 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1756 : {
1757 326 : uno::Reference< xml::sax::XFastContextHandler > xResult;
1758 :
1759 326 : if (mxContext.is())
1760 318 : xResult = mxContext->createUnknownChildContext
1761 212 : (Namespace, Name, Attribs);
1762 : else
1763 220 : xResult.set(this);
1764 :
1765 326 : return xResult;
1766 : }
1767 :
1768 55164 : void OOXMLFastContextHandlerWrapper::attributes
1769 : (const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1770 : throw (uno::RuntimeException, xml::sax::SAXException)
1771 : {
1772 55164 : if (mxContext.is())
1773 : {
1774 39397 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1775 39397 : if (pHandler != nullptr)
1776 0 : pHandler->attributes(Attribs);
1777 : }
1778 55164 : }
1779 :
1780 : OOXMLFastContextHandler::ResourceEnum_t
1781 37 : OOXMLFastContextHandlerWrapper::getResource() const
1782 : {
1783 37 : return UNKNOWN;
1784 : }
1785 :
1786 14424 : void OOXMLFastContextHandlerWrapper::addNamespace(const Id & nId)
1787 : {
1788 14424 : mMyNamespaces.insert(nId);
1789 14424 : }
1790 :
1791 4808 : void OOXMLFastContextHandlerWrapper::addToken( Token_t Token )
1792 : {
1793 4808 : mMyTokens.insert( Token );
1794 4808 : }
1795 :
1796 55164 : void OOXMLFastContextHandlerWrapper::lcl_startFastElement
1797 : (Token_t Element,
1798 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1799 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1800 : {
1801 55164 : if (mxContext.is())
1802 39397 : mxContext->startFastElement(Element, Attribs);
1803 55164 : }
1804 :
1805 55164 : void OOXMLFastContextHandlerWrapper::lcl_endFastElement
1806 : (Token_t Element)
1807 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1808 : {
1809 55164 : if (mxContext.is())
1810 39397 : mxContext->endFastElement(Element);
1811 55164 : }
1812 :
1813 : uno::Reference< xml::sax::XFastContextHandler >
1814 50543 : OOXMLFastContextHandlerWrapper::lcl_createFastChildContext
1815 : (Token_t Element,
1816 : const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
1817 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1818 : {
1819 50543 : uno::Reference< xml::sax::XFastContextHandler > xResult;
1820 :
1821 50543 : bool bInNamespaces = mMyNamespaces.find(oox::getNamespace(Element)) != mMyNamespaces.end();
1822 50543 : bool bInTokens = mMyTokens.find( Element ) != mMyTokens.end( );
1823 :
1824 : // We have methods to _add_ individual tokens or whole namespaces to be
1825 : // processed by writerfilter (instead of oox), but we have no method to
1826 : // filter out a single token. Just hardwire the wrap token here till we
1827 : // need a more generic solution.
1828 50543 : bool bIsWrap = Element == static_cast<sal_Int32>(NMSP_vmlWord | XML_wrap);
1829 50649 : bool bSkipImages = getDocument()->IsSkipImages() && oox::getNamespace(Element) == static_cast<sal_Int32>(NMSP_dml) &&
1830 50649 : !((oox::getBaseToken(Element) == XML_linkedTxbx) || (oox::getBaseToken(Element) == XML_txbx));
1831 :
1832 50543 : if ( bInNamespaces && (!bIsWrap || static_cast<OOXMLFastContextHandlerShape*>(mpParent)->isShapeSent()) )
1833 679 : xResult.set(OOXMLFactory::createFastChildContextFromStart(this, Element));
1834 49864 : else if (mxContext.is() && !bSkipImages)
1835 : {
1836 : OOXMLFastContextHandlerWrapper * pWrapper =
1837 : new OOXMLFastContextHandlerWrapper
1838 45663 : (this, mxContext->createFastChildContext(Element, Attribs));
1839 45662 : pWrapper->mMyNamespaces = mMyNamespaces;
1840 45662 : pWrapper->setPropertySet(getPropertySet());
1841 45662 : xResult.set(pWrapper);
1842 : }
1843 : else
1844 4201 : xResult.set(this);
1845 :
1846 50542 : if ( bInTokens )
1847 75 : static_cast<OOXMLFastContextHandlerShape*>(mpParent)->sendShape( Element );
1848 :
1849 50542 : return xResult;
1850 : }
1851 :
1852 6250 : void OOXMLFastContextHandlerWrapper::lcl_characters
1853 : (const OUString & aChars)
1854 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1855 : {
1856 6250 : if (mxContext.is())
1857 5386 : mxContext->characters(aChars);
1858 6250 : }
1859 :
1860 : OOXMLFastContextHandler *
1861 376083 : OOXMLFastContextHandlerWrapper::getFastContextHandler() const
1862 : {
1863 376083 : if (mxContext.is())
1864 376083 : return dynamic_cast<OOXMLFastContextHandler *>(mxContext.get());
1865 :
1866 0 : return nullptr;
1867 : }
1868 :
1869 0 : void OOXMLFastContextHandlerWrapper::newProperty
1870 : (const Id & rId, OOXMLValue::Pointer_t pVal)
1871 : {
1872 0 : if (mxContext.is())
1873 : {
1874 0 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1875 0 : if (pHandler != nullptr)
1876 0 : pHandler->newProperty(rId, pVal);
1877 : }
1878 0 : }
1879 :
1880 96625 : void OOXMLFastContextHandlerWrapper::setPropertySet
1881 : (OOXMLPropertySet::Pointer_t pPropertySet)
1882 : {
1883 96625 : if (mxContext.is())
1884 : {
1885 75193 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1886 75193 : if (pHandler != nullptr)
1887 0 : pHandler->setPropertySet(pPropertySet);
1888 : }
1889 :
1890 96625 : mpPropertySet = pPropertySet;
1891 96625 : }
1892 :
1893 91481 : OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerWrapper::getPropertySet()
1894 : const
1895 : {
1896 91481 : OOXMLPropertySet::Pointer_t pResult(mpPropertySet);
1897 :
1898 91481 : if (mxContext.is())
1899 : {
1900 91481 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1901 91481 : if (pHandler != nullptr)
1902 0 : pResult = pHandler->getPropertySet();
1903 : }
1904 :
1905 91481 : return pResult;
1906 : }
1907 :
1908 0 : string OOXMLFastContextHandlerWrapper::getType() const
1909 : {
1910 0 : string sResult = "Wrapper(";
1911 :
1912 0 : if (mxContext.is())
1913 : {
1914 0 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1915 0 : if (pHandler != nullptr)
1916 0 : sResult += pHandler->getType();
1917 : }
1918 :
1919 0 : sResult += ")";
1920 :
1921 0 : return sResult;
1922 : }
1923 :
1924 50963 : void OOXMLFastContextHandlerWrapper::setId(Id rId)
1925 : {
1926 50963 : OOXMLFastContextHandler::setId(rId);
1927 :
1928 50963 : if (mxContext.is())
1929 : {
1930 39344 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1931 39344 : if (pHandler != nullptr)
1932 0 : pHandler->setId(rId);
1933 : }
1934 50963 : }
1935 :
1936 45662 : Id OOXMLFastContextHandlerWrapper::getId() const
1937 : {
1938 45662 : Id nResult = OOXMLFastContextHandler::getId();
1939 :
1940 45662 : if (mxContext.is())
1941 : {
1942 45662 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1943 45662 : if (pHandler != nullptr && pHandler->getId() != 0)
1944 0 : nResult = pHandler->getId();
1945 : }
1946 :
1947 45662 : return nResult;
1948 : }
1949 :
1950 50963 : void OOXMLFastContextHandlerWrapper::setToken(Token_t nToken)
1951 : {
1952 50963 : OOXMLFastContextHandler::setToken(nToken);
1953 :
1954 50963 : if (mxContext.is())
1955 : {
1956 39344 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1957 39344 : if (pHandler != nullptr)
1958 0 : pHandler->setToken(nToken);
1959 : }
1960 50963 : }
1961 :
1962 45662 : Token_t OOXMLFastContextHandlerWrapper::getToken() const
1963 : {
1964 45662 : Token_t nResult = OOXMLFastContextHandler::getToken();
1965 :
1966 45662 : if (mxContext.is())
1967 : {
1968 45662 : OOXMLFastContextHandler * pHandler = getFastContextHandler();
1969 45662 : if (pHandler != nullptr)
1970 0 : nResult = pHandler->getToken();
1971 : }
1972 :
1973 45662 : return nResult;
1974 : }
1975 :
1976 :
1977 : /*
1978 : class OOXMLFastContextHandlerLinear
1979 : */
1980 :
1981 195 : OOXMLFastContextHandlerLinear::OOXMLFastContextHandlerLinear(OOXMLFastContextHandler* pContext)
1982 : : OOXMLFastContextHandlerProperties(pContext)
1983 195 : , depthCount( 0 )
1984 : {
1985 195 : }
1986 :
1987 5327 : void OOXMLFastContextHandlerLinear::lcl_startFastElement(Token_t Element,
1988 : const uno::Reference< xml::sax::XFastAttributeList >& Attribs)
1989 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1990 : {
1991 5327 : buffer.appendOpeningTag( Element, Attribs );
1992 5327 : ++depthCount;
1993 5327 : }
1994 :
1995 5324 : void OOXMLFastContextHandlerLinear::lcl_endFastElement(Token_t Element)
1996 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
1997 : {
1998 5324 : buffer.appendClosingTag( Element );
1999 5324 : if( --depthCount == 0 )
2000 194 : process();
2001 5324 : }
2002 :
2003 : uno::Reference< xml::sax::XFastContextHandler >
2004 5132 : OOXMLFastContextHandlerLinear::lcl_createFastChildContext(Token_t,
2005 : const uno::Reference< xml::sax::XFastAttributeList >&)
2006 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
2007 : {
2008 5132 : uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
2009 5132 : xContextHandler.set( this );
2010 5132 : return xContextHandler;
2011 : }
2012 :
2013 909 : void OOXMLFastContextHandlerLinear::lcl_characters(const OUString& aChars)
2014 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
2015 : {
2016 909 : buffer.appendCharacters( aChars );
2017 909 : }
2018 :
2019 : /*
2020 : class OOXMLFastContextHandlerLinear
2021 : */
2022 :
2023 195 : OOXMLFastContextHandlerMath::OOXMLFastContextHandlerMath(OOXMLFastContextHandler* pContext)
2024 195 : : OOXMLFastContextHandlerLinear(pContext)
2025 : {
2026 195 : }
2027 :
2028 194 : void OOXMLFastContextHandlerMath::process()
2029 : {
2030 194 : SvGlobalName name( SO3_SM_CLASSID );
2031 388 : comphelper::EmbeddedObjectContainer container;
2032 388 : OUString aName;
2033 388 : uno::Reference< embed::XEmbeddedObject > ref = container.CreateEmbeddedObject( name.GetByteSequence(), aName );
2034 : assert(ref.is());
2035 194 : if (!ref.is())
2036 194 : return;
2037 388 : uno::Reference< uno::XInterface > component(ref->getComponent(), uno::UNO_QUERY_THROW);
2038 : // gcc4.4 (and 4.3 and possibly older) have a problem with dynamic_cast directly to the target class,
2039 : // so help it with an intermediate cast. I'm not sure what exactly the problem is, seems to be unrelated
2040 : // to RTLD_GLOBAL, so most probably a gcc bug.
2041 194 : oox::FormulaImportBase& import = dynamic_cast<oox::FormulaImportBase&>(dynamic_cast<SfxBaseModel&>(*component.get()));
2042 194 : import.readFormulaOoxml(buffer);
2043 194 : if (isForwardEvents())
2044 : {
2045 194 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
2046 194 : OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref ));
2047 388 : OOXMLProperty::Pointer_t pProp( new OOXMLPropertyImpl( NS_ooxml::LN_starmath, pVal, OOXMLPropertyImpl::ATTRIBUTE ));
2048 194 : pProps->add( pProp );
2049 388 : mpStream->props( writerfilter::Reference< Properties >::Pointer_t( pProps ));
2050 194 : }
2051 : }
2052 :
2053 72 : }}
2054 :
2055 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|