1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8DocumentImpl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <resourcemodel/exceptions.hxx>
32 #include <resourcemodel/QNameToString.hxx>
33 #include <WW8DocumentImpl.hxx>
34 #include <WW8FKPImpl.hxx>
35 #include <WW8PieceTableImpl.hxx>
36 #include <WW8BinTableImpl.hxx>
37 #include <WW8StreamImpl.hxx>
38 #include <WW8Sttbf.hxx>
41 #include <XNoteHelperImpl.hxx>
42 #include <rtl/ustring.hxx>
43 #include <rtl/ustrbuf.hxx>
44 #include <doctokLoggers.hxx>
46 namespace writerfilter
{
50 using namespace ::std
;
55 static void processPLCFCpAndFcs(WW8DocumentImpl
& rDoc
,
56 WW8PieceTable::Pointer_t pPieceTable
,
57 typename PLCF
<T
>::Pointer_t pPLCF
,
61 sal_uInt32 nCount
= pPLCF
->getEntryCount();
62 for (sal_uInt32 n
= 0; n
< nCount
; ++n
)
64 Cp
aCp(pPLCF
->getFc(n
) + nOffset
);
65 CpAndFc aCpAndFc
= pPieceTable
->createCpAndFc(aCp
, eType
);
67 rDoc
.insertCpAndFc(aCpAndFc
);
72 // WW8DocumentIteratorImpl
73 bool operator == (const WW8DocumentIterator
& rA
,
74 const WW8DocumentIterator
& rB
)
79 WW8DocumentIterator::~WW8DocumentIterator()
83 WW8DocumentIteratorImpl::~WW8DocumentIteratorImpl()
87 WW8DocumentIterator
& WW8DocumentIteratorImpl::operator++()
89 mCpAndFc
= mpDocument
->getNextCp(mCpAndFc
);
94 WW8DocumentIterator
& WW8DocumentIteratorImpl::operator--()
96 mCpAndFc
= mpDocument
->getPrevCp(mCpAndFc
);
101 bool WW8DocumentIteratorImpl::equal(const WW8DocumentIterator
& rIt_
) const
103 const WW8DocumentIteratorImpl
& rIt
=
104 dynamic_cast<const WW8DocumentIteratorImpl
&>(rIt_
);
106 return mCpAndFc
== rIt
.mCpAndFc
&& mpDocument
== rIt
.mpDocument
;
109 writerfilter::Reference
<Properties
>::Pointer_t
110 WW8DocumentIteratorImpl::getProperties() const
112 return mpDocument
->getProperties(mCpAndFc
);
115 writerfilter::Reference
<Stream
>::Pointer_t
116 WW8DocumentIteratorImpl::getSubDocument() const
118 return mpDocument
->getSubDocument(mCpAndFc
);
121 WW8SED
* WW8DocumentIteratorImpl::getSED() const
123 return mpDocument
->getSED(mCpAndFc
);
126 WW8Stream::Sequence
WW8DocumentIteratorImpl::getText()
128 return mpDocument
->getText(mCpAndFc
);
131 writerfilter::Reference
<Properties
>::Pointer_t
132 WW8DocumentIteratorImpl::getShape() const
134 return mpDocument
->getShape(mCpAndFc
);
137 PropertyType
WW8DocumentIteratorImpl::getPropertyType() const
139 return mCpAndFc
.getType();
142 bool WW8DocumentIteratorImpl::isComplex() const
144 return mCpAndFc
.isComplex();
147 void WW8DocumentIteratorImpl::dump(ostream
& o
) const
152 string
WW8DocumentIteratorImpl::toString() const
154 return mCpAndFc
.toString();
159 WW8Document::~WW8Document()
163 class WW8IdToString
: public IdToString
166 WW8IdToString() : IdToString() {}
167 virtual ~WW8IdToString() {}
169 virtual string
toString(const Id
& rId
) const
171 string
s((*SprmIdToString::Instance())(rId
));
174 s
= (*QNameToString::Instance())(rId
);
180 WW8DocumentImpl::~WW8DocumentImpl()
184 WW8DocumentImpl::WW8DocumentImpl(WW8Stream::Pointer_t rpStream
)
185 : bSubDocument(false), mfcPicLoc(0), mbPicIsData(false), mpStream(rpStream
),
186 mbInSection(false), mbInParagraphGroup(false), mbInCharacterGroup(false)
188 mpDocStream
= getSubStream(::rtl::OUString::createFromAscii
193 mpDataStream
= getSubStream(::rtl::OUString::createFromAscii
196 catch (ExceptionNotFound e
)
202 mpCompObjStream
= getSubStream(::rtl::OUString::createFromAscii
205 catch (ExceptionNotFound e
)
210 WW8FKPCache::Pointer_t(new WW8CHPFKPCacheImpl(mpDocStream
, 5));
212 WW8FKPCache::Pointer_t(new WW8PAPFKPCacheImpl(mpDocStream
, 5));
214 mpFib
= WW8Fib::Pointer_t(new WW8Fib(*mpDocStream
));
216 switch (mpFib
->get_fWhichTblStm())
219 mpTableStream
= getSubStream(::rtl::OUString::createFromAscii
225 mpTableStream
= getSubStream(::rtl::OUString::createFromAscii
234 if (mpTableStream
.get() == NULL
)
235 throw ExceptionNotFound("Table stream not found.");
238 WW8PieceTable::Pointer_t
239 (new WW8PieceTableImpl(*mpTableStream
, mpFib
->get_fcClx(),
240 mpFib
->get_lcbClx()));
243 Cp
aCp(mpPieceTable
->getLastCp());
244 Fc
aFc(mpPieceTable
->getLastFc());
245 CpAndFc
aCpAndFc(aCp
, aFc
, PROP_DOC
);
246 mCpAndFcs
.insert(aCpAndFc
);
250 Cp
aCp(mpFib
->get_ccpText());
252 mDocumentEndCpAndFc
= CpAndFc(aCp
, mpPieceTable
->cp2fc(aCp
),
254 mCpAndFcs
.insert(mDocumentEndCpAndFc
);
256 aCp
+= mpFib
->get_ccpFtn();
257 mFootnoteEndCpAndFc
= CpAndFc(aCp
, mpPieceTable
->cp2fc(aCp
),
259 mCpAndFcs
.insert(mFootnoteEndCpAndFc
);
261 aCp
+= mpFib
->get_ccpHdd();
262 mHeaderEndCpAndFc
= CpAndFc(aCp
, mpPieceTable
->cp2fc(aCp
),
264 mCpAndFcs
.insert(mHeaderEndCpAndFc
);
266 aCp
+= mpFib
->get_ccpAtn();
267 mAnnotationEndCpAndFc
= CpAndFc(aCp
, mpPieceTable
->cp2fc(aCp
),
269 mCpAndFcs
.insert(mAnnotationEndCpAndFc
);
271 aCp
+= mpFib
->get_ccpEdn();
272 mEndnoteEndCpAndFc
= CpAndFc(aCp
, mpPieceTable
->cp2fc(aCp
),
274 mCpAndFcs
.insert(mEndnoteEndCpAndFc
);
276 aCp
+= mpFib
->get_ccpTxbx();
277 mTextboxEndCpAndFc
= CpAndFc(aCp
, mpPieceTable
->cp2fc(aCp
),
279 mCpAndFcs
.insert(mTextboxEndCpAndFc
);
281 aCp
+= mpFib
->get_ccpHdrTxbx();
282 mTextboxHeaderEndCpAndFc
= CpAndFc(aCp
, mpPieceTable
->cp2fc(aCp
),
284 mCpAndFcs
.insert(mTextboxHeaderEndCpAndFc
);
288 WW8BinTable::Pointer_t(new WW8BinTableImpl
290 mpFib
->get_fcPlcfbtePapx(),
291 mpFib
->get_lcbPlcfbtePapx()));
293 //clog << "BinTable(PAP):" << mpBinTablePAPX->toString();
295 parseBinTableCpAndFcs(*mpBinTablePAPX
, PROP_PAP
);
298 WW8BinTable::Pointer_t(new WW8BinTableImpl
300 mpFib
->get_fcPlcfbteChpx(),
301 mpFib
->get_lcbPlcfbteChpx()));
303 //clog << "BinTable(CHP):" << mpBinTableCHPX->toString();
305 parseBinTableCpAndFcs(*mpBinTableCHPX
, PROP_CHP
);
307 mpSEDs
= PLCF
<WW8SED
>::Pointer_t(new PLCF
<WW8SED
>
309 mpFib
->get_fcPlcfsed(),
310 mpFib
->get_lcbPlcfsed()));
312 //mpSEDs->dump(clog);
315 PLCFHelper
<WW8SED
>::processPLCFCpAndFcs
316 (*this, mpPieceTable
, mpSEDs
, PROP_SEC
, 0);
319 sal_uInt32 nHeaders
= getHeaderCount();
323 mpHeaderOffsets
= WW8StructBase::Pointer_t
324 (new WW8StructBase(*mpTableStream
,
325 mpFib
->get_fcPlcfhdd(),
326 mpFib
->get_lcbPlcfhdd()));
329 for (sal_uInt32 n
= 0; n
<= nHeaders
; ++n
)
331 CpAndFc
aCpAndFc(getHeaderCpAndFc(n
));
333 mCpAndFcs
.insert(aCpAndFc
);
338 if (mpFib
->get_lcbPlcffndTxt() > 0)
340 WW8StructBase::Pointer_t pCps
341 (new WW8StructBase(*mpTableStream
,
342 mpFib
->get_fcPlcffndTxt(),
343 mpFib
->get_lcbPlcffndTxt()));
345 PLCF
<WW8FRD
>::Pointer_t pRefs
346 (new PLCF
<WW8FRD
>(*mpTableStream
,
347 mpFib
->get_fcPlcffndRef(),
348 mpFib
->get_lcbPlcffndRef()));
350 mpFootnoteHelper
= XNoteHelper
<WW8FRD
>::Pointer_t
351 (new XNoteHelper
<WW8FRD
>(pCps
, pRefs
, mpPieceTable
, this,
352 PROP_FOOTNOTE
, getDocumentEndCp()));
354 mpFootnoteHelper
->init();
357 if (mpFib
->get_lcbPlcfendTxt() > 0)
359 WW8StructBase::Pointer_t pCps
360 (new WW8StructBase(*mpTableStream
,
361 mpFib
->get_fcPlcfendTxt(),
362 mpFib
->get_lcbPlcfendTxt()));
364 PLCF
<WW8FRD
>::Pointer_t pRefs
365 (new PLCF
<WW8FRD
>(*mpTableStream
,
366 mpFib
->get_fcPlcfendRef(),
367 mpFib
->get_lcbPlcfendRef()));
369 mpEndnoteHelper
= XNoteHelper
<WW8FRD
>::Pointer_t
370 (new XNoteHelper
<WW8FRD
>(pCps
, pRefs
, mpPieceTable
, this,
371 PROP_ENDNOTE
, getAnnotationEndCp()));
373 mpEndnoteHelper
->init();
376 if (mpFib
->get_lcbPlcfandTxt() > 0)
378 WW8StructBase::Pointer_t pCps
379 (new WW8StructBase(*mpTableStream
,
380 mpFib
->get_fcPlcfandTxt(),
381 mpFib
->get_lcbPlcfandTxt()));
383 PLCF
<WW8ATRD
>::Pointer_t pRefs
384 (new PLCF
<WW8ATRD
>(*mpTableStream
,
385 mpFib
->get_fcPlcfandRef(),
386 mpFib
->get_lcbPlcfandRef()));
388 mpAnnotationHelper
= XNoteHelper
<WW8ATRD
>::Pointer_t
389 (new XNoteHelper
<WW8ATRD
>(pCps
, pRefs
, mpPieceTable
, this,
390 PROP_ANNOTATION
, getHeaderEndCp()));
392 mpAnnotationHelper
->init();
395 if (mpFib
->get_lcbSttbfbkmk() > 0)
397 PLCF
<WW8BKF
>::Pointer_t pStartCps
398 (new PLCF
<WW8BKF
>(*mpTableStream
, mpFib
->get_fcPlcfbkf(),
399 mpFib
->get_lcbPlcfbkf()));
401 WW8StructBase::Pointer_t pEndCps
402 (new WW8StructBase(*mpTableStream
, mpFib
->get_fcPlcfbkl(),
403 mpFib
->get_lcbPlcfbkl()));
405 WW8Sttbf::Pointer_t pNames
406 (new WW8Sttbf(*mpTableStream
, mpFib
->get_fcSttbfbkmk(),
407 mpFib
->get_lcbSttbfbkmk()));
409 mpBookmarkHelper
= BookmarkHelper::Pointer_t
410 (new BookmarkHelper(pStartCps
, pEndCps
, pNames
, mpPieceTable
, this));
412 mpBookmarkHelper
->init();
416 PLCF
<WW8FLD
>::Pointer_t pPlcffldMom
;
418 if (mpFib
->get_lcbPlcffldMom() > 0)
420 pPlcffldMom
= PLCF
<WW8FLD
>::Pointer_t
421 (new PLCF
<WW8FLD
>(*mpTableStream
,
422 mpFib
->get_fcPlcffldMom(),
423 mpFib
->get_lcbPlcffldMom()));
425 mpFieldHelper
= FieldHelper::Pointer_t
426 (new FieldHelper(pPlcffldMom
,
429 mpFieldHelper
->init();
433 PLCF
<WW8FSPA
>::Pointer_t pPlcspaMom
;
434 if (mpFib
->get_lcbPlcspaMom() > 0)
436 pPlcspaMom
= PLCF
<WW8FSPA
>::Pointer_t
438 (*mpTableStream
, mpFib
->get_fcPlcspaMom(),
439 mpFib
->get_lcbPlcspaMom()));
442 PLCF
<WW8FSPA
>::Pointer_t pPlcspaHdr
;
443 if (mpFib
->get_lcbPlcspaHdr() > 0)
445 pPlcspaHdr
= PLCF
<WW8FSPA
>::Pointer_t
447 (*mpTableStream
, mpFib
->get_fcPlcspaHdr(),
448 mpFib
->get_lcbPlcspaHdr()));
451 mpShapeHelper
= ShapeHelper::Pointer_t
452 (new ShapeHelper(pPlcspaMom
, pPlcspaHdr
, this));
454 mpShapeHelper
->init();
456 PLCF
<WW8BKD
>::Pointer_t pPlcbkdMother
;
457 if (mpFib
->get_fcBkdMother() > 0 && mpFib
->get_lcbBkdMother() > 0)
459 pPlcbkdMother
= PLCF
<WW8BKD
>::Pointer_t
461 (*mpTableStream
, mpFib
->get_fcBkdMother(),
462 mpFib
->get_lcbBkdMother()));
465 mpBreakHelper
= BreakHelper::Pointer_t
466 (new BreakHelper(pPlcbkdMother
, this));
468 mpBreakHelper
->init();
470 if (mpFib
->get_fcDggInfo() != 0 && mpFib
->get_lcbDggInfo() > 0)
472 mpDffBlock
= DffBlock::Pointer_t
473 (new DffBlock(*mpTableStream
, mpFib
->get_fcDggInfo(),
474 mpFib
->get_lcbDggInfo(), 1));
476 mpDffBlock
->setDocument(this);
479 if (mpFib
->get_lcbPlcftxbxTxt() > 0)
481 mpTextBoxStories
= PLCF
<WW8FTXBXS
>::Pointer_t
482 (new PLCF
<WW8FTXBXS
>(*mpTableStream
,
483 mpFib
->get_fcPlcftxbxTxt(),
484 mpFib
->get_lcbPlcftxbxTxt()));
486 PLCFHelper
<WW8FTXBXS
>::processPLCFCpAndFcs
487 (*this, mpPieceTable
, mpTextBoxStories
, PROP_DOC
,
488 mEndnoteEndCpAndFc
.getCp().get());
491 if (mCpAndFcs
.size() > 0)
493 mCpAndFcStart
= *mCpAndFcs
.begin();
494 mCpAndFcEnd
= getDocumentEndCp();
498 bool WW8DocumentImpl::isSpecial(sal_uInt32 nChar
)
500 bool bResult
= false;
504 else if (nChar
>= 10)
508 else if (nChar
<= 16)
510 else if (nChar
>= 22)
514 else if (nChar
>= 33)
518 else if (nChar
== 41)
527 WW8DocumentImpl::WW8DocumentImpl(const WW8DocumentImpl
& rSrc
,
528 const CpAndFc
& rStart
, const CpAndFc
& rEnd
)
529 : bSubDocument(true), mfcPicLoc(0), mbPicIsData(false)
533 mCpAndFcStart
= rStart
;
537 WW8DocumentImpl
& WW8DocumentImpl::Assign(const WW8DocumentImpl
& rSrc
)
539 mCpAndFcs
= rSrc
.mCpAndFcs
;
541 mpCHPFKPCache
= rSrc
.mpCHPFKPCache
;
542 mpPAPFKPCache
= rSrc
.mpPAPFKPCache
;
544 mpStream
= rSrc
.mpStream
;
545 mpTableStream
= rSrc
.mpTableStream
;
546 mpDataStream
= rSrc
.mpDataStream
;
547 mpDocStream
= rSrc
.mpDocStream
;
548 mpCompObjStream
= rSrc
.mpCompObjStream
;
550 mpPieceTable
= rSrc
.mpPieceTable
;
552 mpBinTableCHPX
= rSrc
.mpBinTableCHPX
;
553 mpBinTablePAPX
= rSrc
.mpBinTablePAPX
;
555 mpSEDs
= rSrc
.mpSEDs
;
559 mpHeaderOffsets
= rSrc
.mpHeaderOffsets
;
560 mpFootnoteHelper
= rSrc
.mpFootnoteHelper
;
561 mpEndnoteHelper
= rSrc
.mpEndnoteHelper
;
562 mpAnnotationHelper
= rSrc
.mpAnnotationHelper
;
563 mpShapeHelper
= rSrc
.mpShapeHelper
;
564 mpBreakHelper
= rSrc
.mpBreakHelper
;
566 mpBookmarkHelper
= rSrc
.mpBookmarkHelper
;
568 mpDffBlock
= rSrc
.mpDffBlock
;
569 mpTextBoxStories
= rSrc
.mpTextBoxStories
;
571 mDocumentEndCpAndFc
= rSrc
.mDocumentEndCpAndFc
;
572 mFootnoteEndCpAndFc
= rSrc
.mFootnoteEndCpAndFc
;
577 string
WW8DocumentImpl::getType() const
579 return "WW8DocumentImpl";
582 void WW8DocumentImpl::parseBinTableCpAndFcs(WW8BinTable
& rTable
,
585 //clog << "<bintable type=\"" << propertyTypeToString(eType_) << "\">" << endl;
586 for (sal_uInt32 i
= 0; i
< rTable
.getEntryCount(); i
++)
590 snprintf(sBuffer
, 255, "%ld", i
);
591 char sBufferPageNum
[255];
592 snprintf(sBufferPageNum
, 255, "%ld", rTable
.getPageNumber(i
));
594 Fc
aFcFromTable(rTable
.getFc(i
));
596 if (aFcFromTable
< mpPieceTable
->getFirstFc())
597 aFcFromTable
= mpPieceTable
->getFirstFc();
599 bool bComplex
= mpPieceTable
->isComplex(aFcFromTable
);
600 aFcFromTable
.setComplex(bComplex
);
602 //clog << "<entry fc=\"" << aFcFromTable.toString() << "\">" << endl;
606 Cp
aCpFromTable(mpPieceTable
->fc2cp(aFcFromTable
));
607 CpAndFc
aCpAndFcFromTable(aCpFromTable
, aFcFromTable
, eType_
);
609 mCpAndFcs
.insert(aCpAndFcFromTable
);
611 WW8FKP::Pointer_t pFKP
;
616 pFKP
= getFKPCHPX(rTable
.getPageNumber(i
),
617 aCpAndFcFromTable
.isComplex());
622 pFKP
= getFKPPAPX(rTable
.getPageNumber(i
),
623 aCpAndFcFromTable
.isComplex());
630 for (sal_uInt32 n
= 0; n
< pFKP
->getEntryCount(); n
++)
632 Fc aFc
= pFKP
->getFc(n
);
634 if (aFc
< mpPieceTable
->getFirstFc())
635 aFc
= mpPieceTable
->getFirstFc();
637 bool bComplexFKP
= mpPieceTable
->isComplex(aFc
);
638 aFc
.setComplex(bComplexFKP
);
640 //clog << "<fkpentry fc=\"" << aFc.toString() << "\"/>" << endl;
644 Cp aCp
= mpPieceTable
->fc2cp(aFc
);
646 CpAndFc
aCpAndFc(aCp
, aFc
, eType_
);
648 mCpAndFcs
.insert(aCpAndFc
);
650 //clog << aCpAndFc << endl;
652 catch (ExceptionNotFound e
)
654 clog
<< e
.getText() << endl
;
658 catch (ExceptionNotFound e
)
660 clog
<< e
.getText() << endl
;
663 //clog << "</entry>" << endl;
666 //clog << "</bintable>" << endl;
669 WW8Stream::Pointer_t
WW8DocumentImpl::getSubStream
670 (const ::rtl::OUString
& sId
) const
672 return mpStream
->getSubStream(sId
);
675 WW8Document::Pointer_t
WW8DocumentImpl::getSubDocument(SubDocumentId
/*nId*/)
677 return WW8Document::Pointer_t(new WW8DocumentImpl(*this));
680 WW8DocumentIterator::Pointer_t
681 WW8DocumentImpl::getIterator(const CpAndFc
& rCpAndFc
)
683 return WW8DocumentIterator::Pointer_t
684 (new WW8DocumentIteratorImpl(this, rCpAndFc
));
687 WW8DocumentIterator::Pointer_t
WW8DocumentImpl::begin()
689 return getIterator(getFirstCp());
692 WW8DocumentIterator::Pointer_t
WW8DocumentImpl::end()
694 return getIterator(getLastCp());
697 WW8Stream::Pointer_t
WW8DocumentImpl::getDocStream() const
702 WW8Stream::Pointer_t
WW8DocumentImpl::getDataStream() const
707 sal_uInt32
WW8DocumentImpl::getByteLength(const CpAndFc
& rCpAndFc
) const
709 CpAndFc aEnd
= getNextCp(rCpAndFc
);
711 sal_uInt32 nResult
= 3;
714 nResult
= (aEnd
- rCpAndFc
) *
715 (mpPieceTable
->isComplex(rCpAndFc
.getCp()) ? 1 : 2);
721 WW8DocumentImpl::getText(const CpAndFc
& rStart
)
723 return mpDocStream
->get(rStart
.getFc().get(), getByteLength(rStart
));
726 const CpAndFc
& WW8DocumentImpl::getFirstCp() const
728 return mCpAndFcStart
;
731 const CpAndFc
& WW8DocumentImpl::getLastCp() const
736 CpAndFc
WW8DocumentImpl::getDocumentEndCp() const
738 return mDocumentEndCpAndFc
;
741 CpAndFc
WW8DocumentImpl::getFootnodeEndCp() const
743 return mFootnoteEndCpAndFc
;
746 CpAndFc
WW8DocumentImpl::getHeaderEndCp() const
748 return mHeaderEndCpAndFc
;
751 CpAndFc
WW8DocumentImpl::getAnnotationEndCp() const
753 return mAnnotationEndCpAndFc
;
756 CpAndFc
WW8DocumentImpl::getEndnoteEndCp() const
758 return mEndnoteEndCpAndFc
;
761 CpAndFc
WW8DocumentImpl::getTextboxEndCp() const
763 return mTextboxEndCpAndFc
;
766 CpAndFc
WW8DocumentImpl::getTextboxHeaderEndCp() const
768 return mTextboxHeaderEndCpAndFc
;
771 CpAndFc
WW8DocumentImpl::getNextCp(const CpAndFc
& rCpAndFc
) const
773 CpAndFc aResult
= mCpAndFcEnd
;
774 CpAndFcs::const_iterator aIt
= mCpAndFcs
.find(rCpAndFc
);
776 if (aIt
!= mCpAndFcs
.end())
780 if (aIt
!= mCpAndFcs
.end())
784 throw ExceptionNotFound("getNextCp: " + rCpAndFc
.toString());
789 CpAndFc
WW8DocumentImpl::getPrevCp(const CpAndFc
& rCpAndFc
) const
791 CpAndFc aResult
= mCpAndFcStart
;
793 CpAndFcs::const_iterator aIt
= mCpAndFcs
.find(CpAndFc(rCpAndFc
));
795 if (aIt
!= mCpAndFcs
.end() && aIt
!= mCpAndFcs
.begin())
802 throw ExceptionNotFound("getPrevCp: " + rCpAndFc
.toString());
807 WW8FKP::Pointer_t
WW8DocumentImpl::getFKP(const CpAndFc
& rCpAndFc
)
809 WW8FKP::Pointer_t pResult
;
811 sal_uInt32 nPageNumber
= 0;
813 switch (rCpAndFc
.getType())
818 mpBinTablePAPX
->getPageNumber(rCpAndFc
.getFc());
820 pResult
= getFKPPAPX(nPageNumber
, rCpAndFc
.isComplex());
826 mpBinTableCHPX
->getPageNumber(rCpAndFc
.getFc());
828 pResult
= getFKPCHPX(nPageNumber
, rCpAndFc
.isComplex());
835 if (pResult
.get() != NULL
)
836 pResult
->setDocument(this);
841 WW8FKP::Pointer_t
WW8DocumentImpl::getFKPCHPX(sal_uInt32 nIndex
,
844 return mpCHPFKPCache
->get(nIndex
, bComplex
);
847 WW8FKP::Pointer_t
WW8DocumentImpl::getFKPPAPX(sal_uInt32 nIndex
,
850 return mpPAPFKPCache
->get(nIndex
, bComplex
);
853 writerfilter::Reference
<Properties
>::Pointer_t
WW8DocumentImpl::getProperties
854 (const CpAndFc
& rCpAndFc
)
856 writerfilter::Reference
<Properties
>::Pointer_t pResult
;
858 switch (rCpAndFc
.getType())
865 WW8FKP::Pointer_t pFKP
= getFKP(rCpAndFc
);
867 pResult
= pFKP
->getProperties(rCpAndFc
.getFc());
869 catch (ExceptionOutOfBounds e
)
878 pResult
= writerfilter::Reference
<Properties
>::Pointer_t
886 pResult
= writerfilter::Reference
<Properties
>::Pointer_t
887 (mpFootnoteHelper
->getRef(rCpAndFc
));
893 pResult
= writerfilter::Reference
<Properties
>::Pointer_t
894 (mpEndnoteHelper
->getRef(rCpAndFc
));
898 case PROP_ANNOTATION
:
900 pResult
= writerfilter::Reference
<Properties
>::Pointer_t
901 (mpAnnotationHelper
->getRef(rCpAndFc
));
905 case PROP_BOOKMARKSTART
:
906 case PROP_BOOKMARKEND
:
908 pResult
= getBookmark(rCpAndFc
);
914 pResult
= getField(rCpAndFc
);
916 mpFLD
= mpFieldHelper
->getWW8FLD(rCpAndFc
);
922 pResult
= getShape(rCpAndFc
);
927 pResult
= getBreak(rCpAndFc
);
937 writerfilter::Reference
<Stream
>::Pointer_t
938 WW8DocumentImpl::getSubDocument(const CpAndFc
& rCpAndFc
)
940 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
942 switch (rCpAndFc
.getType())
945 pResult
= getFootnote(rCpAndFc
);
949 pResult
= getEndnote(rCpAndFc
);
952 case PROP_ANNOTATION
:
953 pResult
= getAnnotation(rCpAndFc
);
963 WW8SED
* WW8DocumentImpl::getSED(const CpAndFc
& rCpAndFc
) const
965 WW8SED
* pResult
= mpSEDs
->getEntryByFc(rCpAndFc
.getCp().get());
967 pResult
->setDoc(const_cast<const WW8DocumentImpl
*>(this));
972 writerfilter::Reference
<Table
>::Pointer_t
WW8DocumentImpl::getListTable() const
974 writerfilter::Reference
<Table
>::Pointer_t pResult
;
976 if (mpFib
->get_fcPlcfLst() != 0 && mpFib
->get_lcbPlcfLst() > 0)
978 WW8ListTable
* pList
= new WW8ListTable(*mpTableStream
,
979 mpFib
->get_fcPlcfLst(),
980 mpFib
->get_fcPlfLfo() -
981 mpFib
->get_fcPlcfLst());
983 pList
->setPayloadOffset(mpFib
->get_lcbPlcfLst());
984 pList
->initPayload();
986 pResult
= writerfilter::Reference
<Table
>::Pointer_t(pList
);
992 writerfilter::Reference
<Table
>::Pointer_t
WW8DocumentImpl::getLFOTable() const
994 writerfilter::Reference
<Table
>::Pointer_t pResult
;
996 if (mpFib
->get_fcPlfLfo() != 0 && mpFib
->get_lcbPlfLfo() > 0)
1000 WW8LFOTable
* pLFOs
= new WW8LFOTable(*mpTableStream
,
1001 mpFib
->get_fcPlfLfo(),
1002 mpFib
->get_lcbPlfLfo());
1004 pLFOs
->setPayloadOffset(mpFib
->get_lcbPlcfLst());
1005 pLFOs
->initPayload();
1007 pResult
= writerfilter::Reference
<Table
>::Pointer_t(pLFOs
);
1011 clog
<< e
.getText() << endl
;
1018 writerfilter::Reference
<Table
>::Pointer_t
WW8DocumentImpl::getFontTable() const
1020 writerfilter::Reference
<Table
>::Pointer_t pResult
;
1022 if (mpFib
->get_fcSttbfffn() != 0 && mpFib
->get_lcbSttbfffn() > 0)
1024 WW8FontTable
* pFonts
= new WW8FontTable(*mpTableStream
,
1025 mpFib
->get_fcSttbfffn(),
1026 mpFib
->get_lcbSttbfffn());
1028 pFonts
->initPayload();
1030 pResult
= writerfilter::Reference
<Table
>::Pointer_t(pFonts
);
1036 writerfilter::Reference
<Table
>::Pointer_t
WW8DocumentImpl::getStyleSheet() const
1038 writerfilter::Reference
<Table
>::Pointer_t pResult
;
1040 if (mpFib
->get_lcbStshf() > 0)
1042 WW8StyleSheet
* pStyles
= new WW8StyleSheet(*mpTableStream
,
1043 mpFib
->get_fcStshf(),
1044 mpFib
->get_lcbStshf());
1046 pStyles
->initPayload();
1048 pResult
= writerfilter::Reference
<Table
>::Pointer_t(pStyles
);
1054 sal_uInt32
WW8DocumentImpl::getHeaderCount() const
1056 sal_uInt32 nResult
= 0;
1057 sal_uInt32 nLcbPlcfhdd
= mpFib
->get_lcbPlcfhdd();
1059 if (nLcbPlcfhdd
> 4)
1060 nResult
= (nLcbPlcfhdd
/ 4) - 1;
1065 CpAndFc
WW8DocumentImpl::getHeaderCpAndFc(sal_uInt32 nPos
)
1067 sal_uInt32 nCount
= getHeaderCount();
1069 // There are getHeaderCount() + 1 entries in mpHeaderOffsets => greater
1071 throw ExceptionNotFound("getHeaderCpAndFc");
1074 return mHeaderEndCpAndFc
;
1077 Cp
aCp(getFootnodeEndCp().getCp() + mpHeaderOffsets
->getU32(nPos
* 4));
1078 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
1079 CpAndFc
aCpAndFc(aCp
, aFc
, PROP_DOC
);
1086 writerfilter::Reference
<Stream
>::Pointer_t
WW8DocumentImpl::getHeader(sal_uInt32 nPos
)
1088 // There are getHeaderCount() headers => greater or equal
1089 if (nPos
>= getHeaderCount())
1090 throw ExceptionNotFound("getHeader");
1092 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1094 CpAndFc
aCpAndFcStart(getHeaderCpAndFc(nPos
));
1095 CpAndFc
aCpAndFcEnd(getHeaderCpAndFc(nPos
+ 1));
1098 sal_uInt32 nEquals
= 1;
1099 while (aCpAndFcEnd
== aCpAndFcStart
&& nPos
+ nEquals
< getHeaderCount())
1103 aCpAndFcEnd
= getHeaderCpAndFc(nPos
+ nEquals
);
1107 if (aCpAndFcStart
< aCpAndFcEnd
)
1108 pResult
= writerfilter::Reference
<Stream
>::Pointer_t
1109 (new WW8DocumentImpl(*this, aCpAndFcStart
, aCpAndFcEnd
));
1114 sal_uInt32
WW8DocumentImpl::getFootnoteCount() const
1116 return (mpFootnoteHelper
.get() != NULL
) ? mpFootnoteHelper
->getCount() : 0;
1119 writerfilter::Reference
<Stream
>::Pointer_t
1120 WW8DocumentImpl::getFootnote(sal_uInt32 nPos
)
1122 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1125 pResult
= mpFootnoteHelper
->get(nPos
);
1130 writerfilter::Reference
<Stream
>::Pointer_t
1131 WW8DocumentImpl::getFootnote(const CpAndFc
& rCpAndFc
)
1133 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1136 pResult
= mpFootnoteHelper
->get(rCpAndFc
);
1141 sal_uInt32
WW8DocumentImpl::getEndnoteCount() const
1143 return mpEndnoteHelper
.get() != NULL
? mpEndnoteHelper
->getCount() : 0;
1146 writerfilter::Reference
<Stream
>::Pointer_t
1147 WW8DocumentImpl::getEndnote(sal_uInt32 nPos
)
1149 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1152 pResult
= mpEndnoteHelper
->get(nPos
);
1157 writerfilter::Reference
<Stream
>::Pointer_t
1158 WW8DocumentImpl::getEndnote(const CpAndFc
& rCpAndFc
)
1160 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1163 pResult
= mpEndnoteHelper
->get(rCpAndFc
);
1168 sal_uInt32
WW8DocumentImpl::getAnnotationCount() const
1170 return mpAnnotationHelper
.get() != NULL
?
1171 mpAnnotationHelper
->getCount() : 0;
1174 writerfilter::Reference
<Stream
>::Pointer_t
1175 WW8DocumentImpl::getAnnotation(sal_uInt32 nPos
)
1177 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1180 pResult
= mpAnnotationHelper
->get(nPos
);
1185 writerfilter::Reference
<Stream
>::Pointer_t
1186 WW8DocumentImpl::getAnnotation(const CpAndFc
& rCpAndFc
)
1188 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1191 pResult
= mpAnnotationHelper
->get(rCpAndFc
);
1196 writerfilter::Reference
<Properties
>::Pointer_t
1197 WW8DocumentImpl::getBookmark(const CpAndFc
& rCpAndFc
) const
1199 return mpBookmarkHelper
->getBookmark(rCpAndFc
);
1202 writerfilter::Reference
<Properties
>::Pointer_t
1203 WW8DocumentImpl::getShape(const CpAndFc
& rCpAndFc
) const
1205 return mpShapeHelper
->getShape(rCpAndFc
);
1208 writerfilter::Reference
<Properties
>::Pointer_t
1209 WW8DocumentImpl::getShape(sal_uInt32 nSpid
)
1211 writerfilter::Reference
<Properties
>::Pointer_t pResult
;
1212 DffRecord::Pointer_t pShape
= mpDffBlock
->getShape(nSpid
);
1214 if (pShape
.get() != NULL
)
1216 DffSpContainer
* pTmp
= new DffSpContainer(*pShape
);
1217 pTmp
->setDocument(this);
1219 pResult
= writerfilter::Reference
<Properties
>::Pointer_t(pTmp
);
1225 writerfilter::Reference
<Properties
>::Pointer_t
1226 WW8DocumentImpl::getBreak(const CpAndFc
& rCpAndFc
) const
1228 return mpBreakHelper
->getBreak(rCpAndFc
);
1231 writerfilter::Reference
<Properties
>::Pointer_t
1232 WW8DocumentImpl::getBlip(sal_uInt32 nBid
)
1234 writerfilter::Reference
<Properties
>::Pointer_t pResult
;
1236 if (mpDffBlock
!= NULL
)
1238 DffRecord::Pointer_t
pDffRecord(mpDffBlock
->getBlip(nBid
));
1240 if (pDffRecord
.get() != NULL
)
1242 DffBSE
* pBlip
= new DffBSE(*pDffRecord
);
1245 pResult
= writerfilter::Reference
<Properties
>::Pointer_t(pBlip
);
1252 writerfilter::Reference
<Properties
>::Pointer_t
1253 WW8DocumentImpl::getField(const CpAndFc
& rCpAndFc
) const
1255 return mpFieldHelper
->getField(rCpAndFc
);
1258 WW8FLD::Pointer_t
WW8DocumentImpl::getCurrentFLD() const
1263 sal_uInt32
WW8DocumentImpl::getPicLocation() const
1268 void WW8DocumentImpl::setPicLocation(sal_uInt32 fcPicLoc
)
1270 mfcPicLoc
= fcPicLoc
;
1273 bool WW8DocumentImpl::isPicData()
1278 void WW8DocumentImpl::setPicIsData(bool bPicIsData
)
1280 mbPicIsData
= bPicIsData
;
1283 writerfilter::Reference
<Stream
>::Pointer_t
1284 WW8DocumentImpl::getTextboxText(sal_uInt32 nShpId
) const
1286 writerfilter::Reference
<Stream
>::Pointer_t pResult
;
1288 if (mpTextBoxStories
.get() != NULL
)
1290 sal_uInt32 nCount
= mpTextBoxStories
->getEntryCount();
1295 WW8FTXBXS
* pTextboxStory
= mpTextBoxStories
->getEntryPointer(n
);
1297 if (pTextboxStory
->get_lid() == nShpId
)
1305 Cp
aCpStart(mpTextBoxStories
->getFc(n
));
1306 aCpStart
+= getEndnoteEndCp().getCp().get();
1307 CpAndFc aCpAndFcStart
=
1308 mpPieceTable
->createCpAndFc(aCpStart
, PROP_DOC
);
1309 Cp
aCpEnd(mpTextBoxStories
->getFc(n
+ 1));
1310 aCpEnd
+= getEndnoteEndCp().getCp().get();
1311 CpAndFc aCpAndFcEnd
= mpPieceTable
->createCpAndFc(aCpEnd
, PROP_DOC
);
1313 pResult
= writerfilter::Reference
<Stream
>::Pointer_t
1314 (new WW8DocumentImpl(*this, aCpAndFcStart
, aCpAndFcEnd
));
1321 Id
lcl_headerQName(sal_uInt32 nIndex
)
1323 Id qName
= NS_rtf::LN_header
;
1327 switch ((nIndex
- 6) % 6)
1330 qName
= NS_rtf::LN_headerl
;
1334 qName
= NS_rtf::LN_headerr
;
1338 qName
= NS_rtf::LN_footerl
;
1342 qName
= NS_rtf::LN_footerr
;
1346 qName
= NS_rtf::LN_headerf
;
1350 qName
= NS_rtf::LN_footerf
;
1359 Fc
WW8DocumentImpl::cp2fc(const Cp
& cp
) const
1361 return mpPieceTable
->cp2fc(cp
);
1364 Cp
WW8DocumentImpl::fc2cp(const Fc
& fc
) const
1366 return mpPieceTable
->fc2cp(fc
);
1369 CpAndFc
WW8DocumentImpl::getCpAndFc(const Cp
& cp
, PropertyType type
) const
1373 return CpAndFc(cp
, aFc
, type
);
1376 CpAndFc
WW8DocumentImpl::getCpAndFc(const Fc
& fc
, PropertyType type
) const
1380 return CpAndFc(aCp
, fc
, type
);
1383 void WW8DocumentImpl::resolvePicture(Stream
& rStream
)
1385 WW8Stream::Pointer_t pStream
= getDataStream();
1387 if (pStream
.get() != NULL
)
1389 WW8StructBase
aStruct(*pStream
, mfcPicLoc
, 4);
1390 sal_uInt32 nCount
= aStruct
.getU32(0);
1393 WW8PICF
* pPicf
= new WW8PICF(*pStream
, mfcPicLoc
, nCount
);
1394 pPicf
->setDocument(this);
1396 writerfilter::Reference
<Properties
>::Pointer_t
pProps(pPicf
);
1398 rStream
.props(pProps
);
1403 void WW8DocumentImpl::resolveSpecialChar(sal_uInt32 nChar
, Stream
& rStream
)
1408 resolvePicture(rStream
);
1415 void WW8DocumentImpl::text(Stream
& rStream
, const sal_uInt8
* data
, size_t len
)
1417 #ifdef DEBUG_ELEMENT
1418 ::rtl::OUString
sText( (const sal_Char
*) data
, len
, RTL_TEXTENCODING_MS_1252
);
1419 debug_logger
->startElement("text");
1420 debug_logger
->chars(OUStringToOString(sText
, RTL_TEXTENCODING_ASCII_US
).getStr());
1421 debug_logger
->endElement("text");
1423 rStream
.text(data
, len
);
1426 void WW8DocumentImpl::utext(Stream
& rStream
, const sal_uInt8
* data
, size_t len
)
1428 #ifdef DEBUG_ELEMENT
1429 debug_logger
->startElement("utext");
1431 ::rtl::OUString sText
;
1432 ::rtl::OUStringBuffer aBuffer
= ::rtl:: OUStringBuffer(len
);
1433 aBuffer
.append( (const sal_Unicode
*) data
, len
);
1434 sText
= aBuffer
.makeStringAndClear();
1436 debug_logger
->chars(OUStringToOString(sText
, RTL_TEXTENCODING_ASCII_US
).getStr());
1437 debug_logger
->endElement("utext");
1439 rStream
.text(data
, len
);
1443 void WW8DocumentImpl::resolveText(WW8DocumentIterator::Pointer_t pIt
,
1446 WW8Stream::Sequence aSeq
= pIt
->getText();
1448 sal_uInt32 nCount
= aSeq
.getCount();
1449 bool bComplex
= pIt
->isComplex();
1452 Assumption: Special characters are always at the beginning or end of a
1462 sal_uInt32 nStartIndex
= 0;
1463 sal_uInt32 nEndIndex
= nCount
- 1;
1465 sal_uInt32 nCharFirst
= aSeq
[0];
1466 sal_uInt32 nCharLast
= aSeq
[nEndIndex
];
1468 if (isSpecial(nCharFirst
))
1471 resolveSpecialChar(nCharFirst
, rStream
);
1472 text(rStream
, &aSeq
[0], 1);
1475 if (!isSpecial(nCharLast
))
1478 if (nStartIndex
< nEndIndex
)
1480 sal_uInt32 nChars
= nEndIndex
- nStartIndex
;
1481 text(rStream
, &aSeq
[nStartIndex
], nChars
);
1483 if (isSpecial(nCharLast
))
1485 resolveSpecialChar(nCharLast
, rStream
);
1486 text(rStream
, &aSeq
[nEndIndex
], 1);
1492 sal_uInt32 nStartIndex
= 0;
1493 sal_uInt32 nEndIndex
= nCount
- 2;
1495 sal_uInt32 nCharFirst
= aSeq
[0] + (aSeq
[1] << 8);
1496 sal_uInt32 nCharLast
= aSeq
[nEndIndex
] + (aSeq
[nEndIndex
+ 1]);
1498 if (isSpecial(nCharFirst
))
1501 resolveSpecialChar(nCharFirst
, rStream
);
1502 utext(rStream
, &aSeq
[0], 1);
1505 if (!isSpecial(nCharLast
))
1508 if (nStartIndex
< nEndIndex
)
1510 sal_uInt32 nChars
= (nEndIndex
- nStartIndex
) / 2;
1511 utext(rStream
, &aSeq
[nStartIndex
], nChars
);
1513 if (isSpecial(nCharLast
))
1515 resolveSpecialChar(nCharLast
, rStream
);
1516 utext(rStream
, &aSeq
[nEndIndex
], 1);
1523 void WW8DocumentImpl::startCharacterGroup(Stream
& rStream
)
1525 if (mbInCharacterGroup
)
1526 endCharacterGroup(rStream
);
1528 #ifdef DEBUG_ELEMENT
1529 debug_logger
->startElement("charactergroup");
1532 rStream
.startCharacterGroup();
1533 mbInCharacterGroup
= true;
1536 void WW8DocumentImpl::endCharacterGroup(Stream
& rStream
)
1538 #ifdef DEBUG_ELEMENT
1539 debug_logger
->endElement("charactergroup");
1542 rStream
.endCharacterGroup();
1543 mbInCharacterGroup
= false;
1546 void WW8DocumentImpl::startParagraphGroup(Stream
& rStream
)
1548 if (mbInParagraphGroup
)
1549 endParagraphGroup(rStream
);
1551 #ifdef DEBUG_ELEMENT
1552 debug_logger
->startElement("paragraphgroup");
1555 rStream
.startParagraphGroup();
1556 mbInParagraphGroup
= true;
1559 void WW8DocumentImpl::endParagraphGroup(Stream
& rStream
)
1561 if (mbInCharacterGroup
)
1562 endCharacterGroup(rStream
);
1564 #ifdef DEBUG_ELEMENT
1565 debug_logger
->endElement("paragraphgroup");
1567 rStream
.endParagraphGroup();
1568 mbInParagraphGroup
= false;
1571 void WW8DocumentImpl::startSectionGroup(Stream
& rStream
)
1574 endSectionGroup(rStream
);
1576 #ifdef DEBUG_ELEMENT
1577 debug_logger
->startElement("sectiongroup");
1580 rStream
.startSectionGroup();
1584 void WW8DocumentImpl::endSectionGroup(Stream
& rStream
)
1586 if (mbInParagraphGroup
)
1587 endParagraphGroup(rStream
);
1589 #ifdef DEBUG_ELEMENT
1590 debug_logger
->endElement("sectiongroup");
1592 rStream
.endSectionGroup();
1593 mbInSection
= false;
1596 void WW8DocumentImpl::resolve(Stream
& rStream
)
1601 //mpPieceTable->dump(clog);
1603 //copy(mCpAndFcs.begin(), mCpAndFcs.end(), ostream_iterator<CpAndFc>(clog, ", "));
1605 //mpDocStream->dump(output);
1607 //output.addItem(mTextboxHeaderEndCpAndFc.toString());
1610 output
.addItem("<substream-names>");
1611 output
.addItem(mpStream
->getSubStreamNames());
1612 output
.addItem("</substream-names>");
1614 if (mpDocStream
.get() != NULL
)
1616 mpDocStream
->dump(output
);
1620 writerfilter::Reference
<Properties
>::Pointer_t pFib
1621 (new WW8Fib(*mpFib
));
1622 rStream
.props(pFib
);
1625 if (mpTextBoxStories
.get() != NULL
)
1627 output
.addItem("<textbox.boxes>");
1628 mpTextBoxStories
->dump(output
);
1629 output
.addItem("</textbox.boxes>");
1632 if (mpFib
->get_lcbPlcftxbxBkd() > 0)
1634 PLCF
<WW8BKD
> aPLCF(*mpTableStream
,
1635 mpFib
->get_fcPlcftxbxBkd(),
1636 mpFib
->get_lcbPlcftxbxBkd());
1638 output
.addItem("<textbox.breaks>");
1640 output
.addItem("</textbox.breaks>");
1644 if (mpDffBlock
.get() != NULL
)
1646 DffBlock
* pTmp
= new DffBlock(*mpDffBlock
);
1648 writerfilter::Reference
<Properties
>::Pointer_t pDffBlock
=
1649 writerfilter::Reference
<Properties
>::Pointer_t(pTmp
);
1651 rStream
.props(pDffBlock
);
1655 rStream
.info("headers");
1656 sal_uInt32 nHeaderCount
= getHeaderCount();
1657 for (sal_uInt32 n
= 0; n
< nHeaderCount
; ++n
)
1659 rStream
.info(getHeaderCpAndFc(n
).toString());
1661 rStream
.info("/headers");
1666 sal_uInt32 nFootnoteCount
= getFootnoteCount();
1667 for (sal_uInt32 n
= 0; n
< nFootnoteCount
; ++n
)
1669 //clog << "<footnote num=\"" << n << "\"/>" << endl;
1671 writerfilter::Reference
<Stream
>::Pointer_t
pFootnote(getFootnote(n
));
1673 if (pFootnote
.get() != NULL
)
1674 rStream
.substream(NS_rtf::LN_footnote
, pFootnote
);
1678 sal_uInt32 nEndnoteCount
= getEndnoteCount();
1679 for (sal_uInt32 n
= 0; n
< nEndnoteCount
; ++n
)
1681 //clog << "<endnote num=\"" << n << "\"/>" << endl;
1683 writerfilter::Reference
<Stream
>::Pointer_t
pEndnote(getEndnote(n
));
1685 if (pEndnote
.get() != NULL
)
1686 rStream
.substream(NS_rtf::LN_endnote
, pEndnote
);
1691 writerfilter::Reference
<Table
>::Pointer_t pFontTable
= getFontTable();
1693 if (pFontTable
.get() != NULL
)
1694 rStream
.table(NS_rtf::LN_FONTTABLE
, pFontTable
);
1698 writerfilter::Reference
<Table
>::Pointer_t pStyleSheet
= getStyleSheet();
1700 if (pStyleSheet
.get() != NULL
)
1701 rStream
.table(NS_rtf::LN_STYLESHEET
, pStyleSheet
);
1705 clog
<< e
.getText() << endl
;
1708 writerfilter::Reference
<Table
>::Pointer_t pListTable
= getListTable();
1710 if (pListTable
.get() != NULL
)
1711 rStream
.table(NS_rtf::LN_LISTTABLE
, pListTable
);
1713 writerfilter::Reference
<Table
>::Pointer_t pLFOTable
= getLFOTable();
1715 if (pLFOTable
.get() != NULL
)
1716 rStream
.table(NS_rtf::LN_LFOTABLE
, pLFOTable
);
1719 WW8DocumentIterator::Pointer_t pIt
= begin();
1720 WW8DocumentIterator::Pointer_t pItEnd
= end();
1722 mbInParagraphGroup
= false;
1723 mbInCharacterGroup
= false;
1724 mbInSection
= false;
1726 sal_uInt32 nSectionIndex
= 0;
1728 rStream
.info(pIt
->toString());
1729 rStream
.info(pItEnd
->toString());
1731 while (! pIt
->equal(*pItEnd
))
1733 writerfilter::Reference
<Properties
>::Pointer_t
1734 pProperties(pIt
->getProperties());
1736 switch (pIt
->getPropertyType())
1740 rStream
.info(pIt
->toString());
1741 writerfilter::Reference
<Stream
>::Pointer_t
1742 pFootnote(pIt
->getSubDocument());
1744 if (pFootnote
.get() != NULL
)
1746 #ifdef DEBUG_ELEMENT
1747 debug_logger
->startElement("substream");
1749 rStream
.substream(NS_rtf::LN_footnote
, pFootnote
);
1750 #ifdef DEBUG_ELEMENT
1751 debug_logger
->endElement("substream");
1758 rStream
.info(pIt
->toString());
1759 writerfilter::Reference
<Stream
>::Pointer_t
1760 pEndnote(pIt
->getSubDocument());
1762 if (pEndnote
.get() != NULL
)
1764 #ifdef DEBUG_ELEMENT
1765 debug_logger
->startElement("substream");
1767 rStream
.substream(NS_rtf::LN_endnote
, pEndnote
);
1768 #ifdef DEBUG_ELEMENT
1769 debug_logger
->endElement("substream");
1774 case PROP_ANNOTATION
:
1776 rStream
.info(pIt
->toString());
1777 writerfilter::Reference
<Stream
>::Pointer_t
1778 pAnnotation(pIt
->getSubDocument());
1780 if (pAnnotation
.get() != NULL
)
1782 #ifdef DEBUG_ELEMENT
1783 debug_logger
->startElement("substream");
1785 rStream
.substream(NS_rtf::LN_annotation
, pAnnotation
);
1786 #ifdef DEBUG_ELEMENT
1787 debug_logger
->endElement("substream");
1794 startCharacterGroup(rStream
);
1800 startParagraphGroup(rStream
);
1801 rStream
.info(pIt
->toString());
1807 startSectionGroup(rStream
);
1808 rStream
.info(pIt
->toString());
1810 sal_uInt32 nHeaderStartIndex
= 6 + nSectionIndex
* 6;
1811 sal_uInt32 nHeaderEndIndex
= nHeaderStartIndex
+ 6;
1813 if (nHeaderStartIndex
>= getHeaderCount())
1814 nHeaderStartIndex
= getHeaderCount();
1816 if (nHeaderEndIndex
>= getHeaderCount())
1817 nHeaderEndIndex
= getHeaderCount();
1819 for (sal_uInt32 n
= nHeaderStartIndex
; n
< nHeaderEndIndex
; ++n
)
1821 writerfilter::Reference
<Stream
>::Pointer_t
1822 pHeader(getHeader(n
));
1824 Id qName
= lcl_headerQName(n
);
1826 if (pHeader
.get() != NULL
)
1827 rStream
.substream(qName
, pHeader
);
1835 rStream
.info(pIt
->toString());
1838 if (pProperties
.get() != NULL
)
1840 #ifdef DEBUG_PROPERTIES
1841 PropertySetToTagHandler
aHandler(IdToString::Pointer_t(new WW8IdToString()));
1842 pProperties
->resolve(aHandler
);
1843 debug_logger
->addTag(aHandler
.getTag());
1846 rStream
.props(pProperties
);
1849 if (pIt
->getPropertyType() == PROP_PAP
)
1851 startCharacterGroup(rStream
);
1854 resolveText(pIt
, rStream
);
1859 if (mbInCharacterGroup
)
1860 endCharacterGroup(rStream
);
1862 if (mbInParagraphGroup
)
1863 endParagraphGroup(rStream
);
1866 endSectionGroup(rStream
);
1870 WW8Stream::Pointer_t
1871 WW8DocumentFactory::createStream(uno::Reference
<uno::XComponentContext
> rContext
,
1872 uno::Reference
<io::XInputStream
> rStream
)
1874 return WW8Stream::Pointer_t(new WW8StreamImpl(rContext
, rStream
));
1878 WW8DocumentFactory::createDocument(WW8Stream::Pointer_t rpStream
)
1880 return new WW8DocumentImpl(rpStream
);
1883 writerfilter::Reference
<Properties
>::Pointer_t
1886 writerfilter::Reference
<Properties
>::Pointer_t pResult
;
1888 if (get_fcSepx() != 0xffffffff)
1890 WW8StructBase
aTmp(*mpDoc
->getDocStream(), get_fcSepx(), 2);
1891 pResult
= writerfilter::Reference
<Properties
>::Pointer_t
1892 (new WW8PropertySetImpl
1893 (*mpDoc
->getDocStream(), get_fcSepx() + 2,
1894 (sal_uInt32
) aTmp
.getU16(0), false));
1900 void WW8DocumentImpl::insertCpAndFc(const CpAndFc
& rCpAndFc
)
1902 mCpAndFcs
.insert(rCpAndFc
);
1905 string
propertyTypeToString(PropertyType nType
)
1919 case PROP_BOOKMARKSTART
:
1920 result
= "BOOKMARKSTART";
1923 case PROP_BOOKMARKEND
:
1924 result
= "BOOKMARKEND";
1932 result
= "FOOTNOTE";
1935 case PROP_ANNOTATION
:
1936 result
= "ANNOTATION";
1965 string
CpAndFc::toString() const
1970 result
+= getCp().toString();
1972 result
+= getFc().toString();
1975 result
+= propertyTypeToString(getType());
1985 Bookmark::Bookmark(writerfilter::Reference
<Properties
>::Pointer_t pBKF
,
1986 rtl::OUString
& rName
)
1987 : mpBKF(pBKF
), mName(rName
)
1991 void Bookmark::resolve(Properties
& rHandler
)
1993 mpBKF
->resolve(rHandler
);
1995 WW8Value::Pointer_t pValue
= createValue(mName
);
1996 rHandler
.attribute(NS_rtf::LN_BOOKMARKNAME
, *pValue
);
1999 string
Bookmark::getType() const
2006 CpAndFc
BookmarkHelper::getStartCpAndFc(sal_uInt32 nPos
)
2008 Cp
aCp(mpStartCps
->getFc(nPos
));
2009 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
2010 CpAndFc
aCpAndFc(aCp
, aFc
, PROP_BOOKMARKSTART
);
2015 CpAndFc
BookmarkHelper::getEndCpAndFc(sal_uInt32 nPos
)
2017 Cp
aCp(mpEndCps
->getU32(nPos
* 4));
2018 Fc
aFc(mpPieceTable
->cp2fc(aCp
));
2019 CpAndFc
aCpAndFc(aCp
, aFc
, PROP_BOOKMARKEND
);
2024 rtl::OUString
BookmarkHelper::getName(sal_uInt32 nPos
)
2026 return mpNames
->getEntry(nPos
);
2029 sal_uInt32
BookmarkHelper::getIndex(const CpAndFc
& rCpAndFc
)
2031 sal_uInt32 nResult
= mpStartCps
->getEntryCount();
2033 sal_uInt32 nCp
= rCpAndFc
.getCp().get();
2036 switch (rCpAndFc
.getType())
2038 case PROP_BOOKMARKSTART
:
2040 sal_uInt32 nStartsCount
= mpStartCps
->getEntryCount();
2042 for (n
= 0; n
< nStartsCount
; ++n
)
2044 if (nCp
== mpStartCps
->getFc(n
))
2052 if (n
== nStartsCount
)
2053 throw ExceptionNotFound("BookmarkHelper::getIndex");
2058 case PROP_BOOKMARKEND
:
2060 sal_uInt32 nEndsCount
= mpEndCps
->getCount() / 4;
2061 sal_uInt32 nIndex
= nEndsCount
;
2063 for (n
= 0; n
< nEndsCount
; ++n
)
2065 if (nCp
== mpEndCps
->getU16(n
* 4))
2073 if (n
== nEndsCount
)
2074 throw ExceptionNotFound("BookmarkHelper::getIndex");
2078 sal_uInt32 nStartsCount
= mpStartCps
->getEntryCount();
2079 for (n
= 0; n
< nStartsCount
; ++n
)
2081 WW8BKF::Pointer_t
pBKF(mpStartCps
->getEntry(n
));
2083 if (pBKF
->get_ibkl() ==
2084 sal::static_int_cast
<sal_Int32
>(nIndex
))
2092 if (n
== nStartsCount
)
2093 throw ExceptionNotFound("BookmarkHelper::getIndex");
2106 void BookmarkHelper::init()
2109 sal_uInt32 nStartsCount
= mpStartCps
->getEntryCount();
2111 for (sal_uInt32 n
= 0; n
< nStartsCount
; ++n
)
2112 mpDoc
->insertCpAndFc(getStartCpAndFc(n
));
2116 sal_uInt32 nEndsCount
= mpEndCps
->getCount() / 4;
2118 for (sal_uInt32 n
= 0; n
< nEndsCount
; ++n
)
2119 mpDoc
->insertCpAndFc(getEndCpAndFc(n
));
2123 writerfilter::Reference
<Properties
>::Pointer_t
2124 BookmarkHelper::getBKF(const CpAndFc
& rCpAndFc
)
2126 sal_uInt32 nIndex
= getIndex(rCpAndFc
);
2128 return writerfilter::Reference
<Properties
>::Pointer_t
2129 (mpStartCps
->getEntryPointer(nIndex
));
2132 writerfilter::Reference
<Properties
>::Pointer_t
2133 BookmarkHelper::getBookmark(const CpAndFc
& rCpAndFc
)
2135 writerfilter::Reference
<Properties
>::Pointer_t pResult
;
2139 rtl::OUString aName
= getName(rCpAndFc
);
2141 pResult
= writerfilter::Reference
<Properties
>::Pointer_t
2142 (new Bookmark(getBKF(rCpAndFc
), aName
));
2144 catch (ExceptionNotFound e
)
2146 clog
<< e
.getText() << endl
;
2152 rtl::OUString
BookmarkHelper::getName(const CpAndFc
& rCpAndFc
)
2154 rtl::OUString sResult
;
2156 sal_uInt32 nIndex
= getIndex(rCpAndFc
);
2158 sResult
= getName(nIndex
);
2163 template <class T
, class Helper
>
2164 struct ProcessPLCF2Map
2166 void process(typename PLCF
<T
>::Pointer_t pPlcf
,
2167 typename
Helper::Map_t
& rMap
,
2169 WW8DocumentImpl
* pDoc
)
2171 if (pPlcf
.get() != NULL
)
2173 sal_uInt32 nCount
= pPlcf
->getEntryCount();
2175 for (sal_uInt32 n
= 0; n
< nCount
; n
++)
2177 Cp
aCp(pPlcf
->getFc(n
));
2178 CpAndFc
aCpAndFc(pDoc
->getCpAndFc(aCp
, type
));
2179 typename
T::Pointer_t pT
= pPlcf
->getEntry(n
);
2181 rMap
[aCpAndFc
] = pT
;
2187 FieldHelper::FieldHelper(PLCF
<WW8FLD
>::Pointer_t pPlcffldMom
,
2188 WW8DocumentImpl
* pDoc
)
2191 ProcessPLCF2Map
<WW8FLD
, FieldHelper
> process
;
2192 process
.process(pPlcffldMom
, mMap
, PROP_FLD
, pDoc
);
2195 void FieldHelper::init()
2197 Map_t::iterator aIt
;
2199 for (aIt
= mMap
.begin(); aIt
!= mMap
.end(); aIt
++)
2201 mpDoc
->insertCpAndFc(aIt
->first
);
2205 WW8FLD::Pointer_t
FieldHelper::getWW8FLD(const CpAndFc
& rCpAndFc
)
2207 WW8FLD::Pointer_t pFld
= mMap
[rCpAndFc
];
2212 writerfilter::Reference
<Properties
>::Pointer_t
2213 FieldHelper::getField(const CpAndFc
& rCpAndFc
)
2215 WW8FLD::Pointer_t pFLD
= getWW8FLD(rCpAndFc
);
2217 return writerfilter::Reference
<Properties
>::Pointer_t
2218 (new WW8FLD(*pFLD
));
2221 ShapeHelper::ShapeHelper(PLCF
<WW8FSPA
>::Pointer_t pPlcspaMom
,
2222 PLCF
<WW8FSPA
>::Pointer_t pPlcspaHdr
,
2223 WW8DocumentImpl
* pDoc
)
2226 ProcessPLCF2Map
<WW8FSPA
, ShapeHelper
> process
;
2227 process
.process(pPlcspaMom
, mMap
, PROP_SHP
, pDoc
);
2228 process
.process(pPlcspaHdr
, mMap
, PROP_SHP
, pDoc
);
2231 void ShapeHelper::init()
2233 Map_t::iterator aIt
;
2235 for (aIt
= mMap
.begin(); aIt
!= mMap
.end(); aIt
++)
2237 mpDoc
->insertCpAndFc(aIt
->first
);
2238 aIt
->second
->setDocument(mpDoc
);
2242 writerfilter::Reference
<Properties
>::Pointer_t
2243 ShapeHelper::getShape(const CpAndFc
& rCpAndFc
)
2245 WW8FSPA::Pointer_t pFSPA
= mMap
[rCpAndFc
];
2247 return writerfilter::Reference
<Properties
>::Pointer_t
2248 (new WW8FSPA(*pFSPA
));
2251 BreakHelper::BreakHelper(PLCF
<WW8BKD
>::Pointer_t pPlcfbkdMom
,
2252 WW8DocumentImpl
* pDoc
)
2255 ProcessPLCF2Map
<WW8BKD
, BreakHelper
> process
;
2256 process
.process(pPlcfbkdMom
, mMap
, PROP_BRK
, pDoc
);
2259 void BreakHelper::init()
2261 Map_t::iterator aIt
;
2263 for (aIt
= mMap
.begin(); aIt
!= mMap
.end(); aIt
++)
2265 mpDoc
->insertCpAndFc(aIt
->first
);
2269 writerfilter::Reference
<Properties
>::Pointer_t
2270 BreakHelper::getBreak(const CpAndFc
& rCpAndFc
)
2272 WW8BKD::Pointer_t pBKD
= mMap
[rCpAndFc
];
2274 return writerfilter::Reference
<Properties
>::Pointer_t
2275 (new WW8BKD(*pBKD
));