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