1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_WW8_DOCUMENT_IMPL_HXX
21 #define INCLUDED_WW8_DOCUMENT_IMPL_HXX
24 #include <WW8PieceTable.hxx>
25 #include <WW8BinTable.hxx>
26 #include <doctok/resources.hxx>
27 #include <resourcemodel/WW8ResourceModel.hxx>
29 #include <WW8Sttbf.hxx>
30 #include <XNoteHelper.hxx>
32 namespace writerfilter
{
36 class WW8DocumentImpl
;
41 class Bookmark
: public writerfilter::Reference
<Properties
>
43 /// bookmark first descriptor
44 writerfilter::Reference
<Properties
>::Pointer_t mpBKF
;
50 Bookmark(writerfilter::Reference
<Properties
>::Pointer_t pBKF
,
53 virtual ~Bookmark() {}
56 Resolve bookmark to handler.
58 @param rHandler handler to send events to
60 virtual void resolve(Properties
& rHandler
);
62 virtual string
getType() const;
66 A helper for bookmarks.
70 /// PLCF containing Cps and BKFs for the bookmarks
71 PLCF
<WW8BKF
>::Pointer_t mpStartCps
;
73 /// Cps of the ends of bookmarks
74 WW8StructBase::Pointer_t mpEndCps
;
76 /// STTBF containing the names of bookmarks
77 WW8Sttbf::Pointer_t mpNames
;
79 /// piece table for converting CPs to FCs
80 WW8PieceTable::Pointer_t mpPieceTable
;
82 /// document to insert CpAndFcs to
83 WW8DocumentImpl
* mpDoc
;
86 Return start CpAndFc for a bookmark.
88 @param nPos index of the bookmark
90 CpAndFc
getStartCpAndFc(sal_uInt32 nPos
);
93 Return end CpAndFc for a bookmark.
95 @param nPos index of the bookmark
97 CpAndFc
getEndCpAndFc(sal_uInt32 nPos
);
100 Return the name of a bookmark.
102 @param nPos index of the bookmark
104 OUString
getName(sal_uInt32 nPos
);
107 Return index of a bookmark.
109 @param rCpAndFc CpAndFc of the bookmark
111 sal_uInt32
getIndex(const CpAndFc
& rCpAndFc
);
114 typedef boost::shared_ptr
<BookmarkHelper
> Pointer_t
;
116 BookmarkHelper(PLCF
<WW8BKF
>::Pointer_t pStartCps
,
117 WW8StructBase::Pointer_t pEndCps
,
118 WW8Sttbf::Pointer_t pNames
,
119 WW8PieceTable::Pointer_t pPieceTable
,
120 WW8DocumentImpl
* pDoc
)
121 : mpStartCps(pStartCps
), mpEndCps(pEndCps
), mpNames(pNames
),
122 mpPieceTable(pPieceTable
), mpDoc(pDoc
)
129 Inserts CpAndFcs for the bookmark starts and ends into the
135 Return BKF of a bookmark.
137 @param rCpAndFc CpAndFc of the bookmark
139 writerfilter::Reference
<Properties
>::Pointer_t getBKF
140 (const CpAndFc
& rCpAndFc
);
143 Return the name of a bookmark.
145 @param rCpAndFc CpAndFc of the bookmark
147 OUString
getName(const CpAndFc
& rCp
);
151 @param rCpAndFc CpAndFc of the bookmark
153 writerfilter::Reference
<Properties
>::Pointer_t
154 getBookmark(const CpAndFc
& rCpAndFc
);
163 typedef boost::unordered_map
<CpAndFc
, WW8FSPA::Pointer_t
, CpAndFcHash
> Map_t
;
166 WW8DocumentImpl
* mpDoc
;
170 typedef boost::shared_ptr
<ShapeHelper
> Pointer_t
;
171 ShapeHelper(PLCF
<WW8FSPA
>::Pointer_t pPlcspaMom
,
172 PLCF
<WW8FSPA
>::Pointer_t pPlcspaHdr
,
173 WW8DocumentImpl
* pDoc
);
177 writerfilter::Reference
<Properties
>::Pointer_t
178 getShape(const CpAndFc
& rCpAndFc
);
188 typedef boost::unordered_map
<CpAndFc
, WW8FLD::Pointer_t
,
192 WW8DocumentImpl
* mpDoc
;
196 typedef boost::shared_ptr
<FieldHelper
> Pointer_t
;
197 FieldHelper(PLCF
<WW8FLD
>::Pointer_t pPlcffldMom
,
198 WW8DocumentImpl
* pDoc
);
202 writerfilter::Reference
<Properties
>::Pointer_t
203 getField(const CpAndFc
& rCpAndFc
);
205 WW8FLD::Pointer_t
getWW8FLD(const CpAndFc
& rCpAndFc
);
214 typedef boost::unordered_map
<CpAndFc
, WW8BKD::Pointer_t
,
217 WW8DocumentImpl
* mpDoc
;
220 typedef boost::shared_ptr
<BreakHelper
> Pointer_t
;
221 BreakHelper(PLCF
<WW8BKD
>::Pointer_t pPlcfbkdMom
,
222 WW8DocumentImpl
* pDoc
);
226 writerfilter::Reference
<Properties
>::Pointer_t
227 getBreak(const CpAndFc
& rCpAndFc
);
231 Implementation class for document.
233 class WW8DocumentImpl
: public WW8Document
235 /// true if the document is contained in another document
239 sal_uInt32 mfcPicLoc
;
241 /// true if FFDATA structure is found at offset mfcPicLoc in data stream
244 /// current field descriptor
245 WW8FLD::Pointer_t mpFLD
;
247 /// CpAndFcs in the document where properties change
250 /// CpAndFc pointing to the start of the document
251 CpAndFc mCpAndFcStart
;
253 /// CpAndFc pointing to the end of the document
256 /// pointer to the cache of FKPs containing character properties
257 WW8FKPCache::Pointer_t mpCHPFKPCache
;
259 /// pointer to the cache of FPKs containing paragraph properties
260 WW8FKPCache::Pointer_t mpPAPFKPCache
;
262 /// pointer to the stream containing the whole document
263 WW8Stream::Pointer_t mpStream
;
265 /// pointer to the substream of the document containing table like
267 WW8Stream::Pointer_t mpTableStream
;
269 /// pointer to the substream of the document containing the
270 /// document contents and formatting information
271 WW8Stream::Pointer_t mpDocStream
;
273 /// pointer to the data stream of the document
274 WW8Stream::Pointer_t mpDataStream
;
276 /// pointer to the compound object stream of the document
277 WW8Stream::Pointer_t mpCompObjStream
;
279 /// pointer to the summayry information stream of the document
280 WW8Stream::Pointer_t mpSummaryInformationStream
;
282 /// pointer to the piece table
283 WW8PieceTable::Pointer_t mpPieceTable
;
285 /// pointer to the bin table for paragraph properties
286 WW8BinTable::Pointer_t mpBinTablePAPX
;
288 /// pointer to the bin table for character properties
289 WW8BinTable::Pointer_t mpBinTableCHPX
;
291 /// PLCF containing the section descriptions
292 PLCF
<WW8SED
>::Pointer_t mpSEDs
;
294 /// pointer to the file information block
295 WW8Fib::Pointer_t mpFib
;
297 /// pointer to the file information block for post 2000 documents
298 WW8FibRgFcLcb2000::Pointer_t mpFibRgFcLcb2000
;
300 /// pointer to the offsets of headers/footers
301 WW8StructBase::Pointer_t mpHeaderOffsets
;
303 /// pointer to the helper for footnotes
304 XNoteHelper
<WW8FRD
>::Pointer_t mpFootnoteHelper
;
306 /// pointer to the helper for endnotes
307 XNoteHelper
<WW8FRD
>::Pointer_t mpEndnoteHelper
;
309 /// pointer to the helper for annotations
310 XNoteHelper
<WW8ATRD
>::Pointer_t mpAnnotationHelper
;
312 /// pointer to the helper for bookmarks
313 BookmarkHelper::Pointer_t mpBookmarkHelper
;
315 /// pointer to the helper for fields
316 FieldHelper::Pointer_t mpFieldHelper
;
318 /// pointer to the helper for shapes
319 ShapeHelper::Pointer_t mpShapeHelper
;
321 /// pointer to the helper for breaks
322 BreakHelper::Pointer_t mpBreakHelper
;
325 /// cache for the Cp where main text flow end
326 CpAndFc mDocumentEndCpAndFc
;
328 /// cache for the Cp where footnotes section ends
329 CpAndFc mFootnoteEndCpAndFc
;
331 /// cache for the Cp where header section ends
332 CpAndFc mHeaderEndCpAndFc
;
334 /// cache for the Cp where annotation section ends
335 CpAndFc mAnnotationEndCpAndFc
;
337 /// cache for the Cp where endnote section ends
338 CpAndFc mEndnoteEndCpAndFc
;
340 /// cache for the Cp where textbox section ends
341 CpAndFc mTextboxEndCpAndFc
;
343 /// cache for the Cp where textbox in header section ends
344 CpAndFc mTextboxHeaderEndCpAndFc
;
346 /// DffBlock of document
347 DffBlock::Pointer_t mpDffBlock
;
350 PLCF
<WW8FTXBXS
>::Pointer_t mpTextBoxStories
;
353 bool mbInParagraphGroup
;
354 bool mbInCharacterGroup
;
356 bool isSpecial(sal_uInt32 nChar
);
358 WW8Stream::Pointer_t
getSubStream(const OUString
& sId
) const;
361 Parse bin table and create CpAndFcs for all points in the
362 document where properties of the given type change.
364 @param rTable bin table to parse
365 @param eType_ type of CpAndFcs to create
367 void parseBinTableCpAndFcs(WW8BinTable
& rTable
, PropertyType eType_
);
369 void startCharacterGroup(Stream
& rStream
);
370 void endCharacterGroup(Stream
& rStream
);
371 void startParagraphGroup(Stream
& rStream
);
372 void endParagraphGroup(Stream
& rStream
);
373 void startSectionGroup(Stream
& rStream
);
374 void endSectionGroup(Stream
& rStream
);
375 void text(Stream
& rStream
, const sal_uInt8
* data
, size_t len
);
376 void utext(Stream
& rStream
, const sal_uInt8
* data
, size_t len
);
379 WW8DocumentImpl(WW8Stream::Pointer_t rpStream
);
380 WW8DocumentImpl(const WW8DocumentImpl
& rSrc
,
381 const CpAndFc
& rStart
, const CpAndFc
& rEnd
);
382 virtual ~WW8DocumentImpl();
384 virtual WW8DocumentImpl
& Assign(const WW8DocumentImpl
& rSrc
);
386 virtual string
getType() const;
388 virtual WW8Document::Pointer_t
getSubDocument(SubDocumentId nId
);
389 virtual WW8DocumentIterator::Pointer_t getIterator
390 (const CpAndFc
& rCpAndFc
);
391 virtual WW8DocumentIterator::Pointer_t
begin();
392 virtual WW8DocumentIterator::Pointer_t
end();
394 virtual WW8Stream::Sequence
getText(const CpAndFc
& rStart
);
397 Returns the document stream.
400 WW8Stream::Pointer_t
getDocStream() const;
403 Returns the data stream.
405 WW8Stream::Pointer_t
getDataStream() const;
408 Returns distance in bytes to next CpAndFc.
410 @param rCpAndFc CpAndFc to start at
412 sal_uInt32
getByteLength(const CpAndFc
& rCpAndFc
) const;
415 Returns first character position in document.
417 const CpAndFc
& getFirstCp() const;
420 Returns last character position in document.
422 const CpAndFc
& getLastCp() const;
425 Returns next character position with change in properties.
427 @param rCpAndFc position to start at
429 CpAndFc
getNextCp(const CpAndFc
& rCpAndFc
) const;
432 Returns previous character position with change in properties.
434 @param rCpAndFc position to start at
436 CpAndFc
getPrevCp(const CpAndFc
& rCpAndFc
) const;
439 Returns character position where main text flow ends.
441 CpAndFc
getDocumentEndCp() const;
444 Returns character position where footnotes end.
446 CpAndFc
getFootnodeEndCp() const;
449 Returns character position where headers end.
451 CpAndFc
getHeaderEndCp() const;
454 Returns character position where annatations end.
456 CpAndFc
getAnnotationEndCp() const;
459 Returns character position where endnotes end.
461 CpAndFc
getEndnoteEndCp() const;
464 Returns character position where textboxes end.
466 CpAndFc
getTextboxEndCp() const;
469 Returns character positoion where textboxes in headers end.
471 CpAndFc
getTextboxHeaderEndCp() const;
474 Insert CpAndFc to set of CpAndFcs.
476 @param rCpAndFc CpAndFc to insert
478 void insertCpAndFc(const CpAndFc
& rCpAndFc
);
481 Return FKP for certain CpAndFc.
483 @param rCpAndFc CpAndFc for which the FKP is looked for
485 WW8FKP::Pointer_t
getFKP(const CpAndFc
& rCpAndFc
);
488 Return FKP containing character properties.
490 @param nIndex index of FKP to return
491 @param bComplex true if FKP contains complex FCs
493 WW8FKP::Pointer_t
getFKPCHPX(sal_uInt32 nIndex
, bool bComplex
);
496 Return FKP containing paragraph properties.
498 @param nIndex index of FKP to return
499 @param bComplex true if FKP contains complex FCs
501 WW8FKP::Pointer_t
getFKPPAPX(sal_uInt32 nIndex
, bool bComplex
);
504 Return property set valid at a certain CpAndFc.
506 @param rCpAndFc CpAndFc to look at
508 writerfilter::Reference
<Properties
>::Pointer_t
509 getProperties(const CpAndFc
& rCpAndFc
);
512 Return subdocument referenced at a certain point in document.
514 @param rCpAndFc CpAndFc where subdocument is referenced
516 writerfilter::Reference
<Stream
>::Pointer_t
517 getSubDocument(const CpAndFc
& rCpAndFc
);
520 Return section description at a certain CpAndFc.
522 @param rCpAndFc CpAndFc to look at
524 WW8SED
* getSED(const CpAndFc
& rCpAndFc
) const;
527 Return reference to list plcs.
529 writerfilter::Reference
<Table
>::Pointer_t
getListTplcs() const;
532 Return reference to list table.
534 writerfilter::Reference
<Table
>::Pointer_t
getListTable() const;
537 Return reference to table of list level overrides.
539 writerfilter::Reference
<Table
>::Pointer_t
getLFOTable() const;
542 Return reference to font table.
544 writerfilter::Reference
<Table
>::Pointer_t
getFontTable() const;
547 Return reference to style sheet.
549 writerfilter::Reference
<Table
>::Pointer_t
getStyleSheet() const;
552 Return reference to associated data.
554 writerfilter::Reference
<Table
>::Pointer_t
getAssocTable() const;
557 Return count of headers/footers.
559 sal_uInt32
getHeaderCount() const;
562 Return CpAndFc for a header or footer.
564 @param nPos index in the list of headers and footers
566 CpAndFc
getHeaderCpAndFc(sal_uInt32 nPos
);
569 Return subdocument for header/footer.
571 @param nPos index in the list of headers and footers
573 writerfilter::Reference
<Stream
>::Pointer_t
getHeader(sal_uInt32 nPos
);
576 Return count of footnotes.
578 sal_uInt32
getFootnoteCount() const;
581 Return subdocument for footnote.
583 @param nPos index of the footnote
585 writerfilter::Reference
<Stream
>::Pointer_t
getFootnote(sal_uInt32 nPos
);
588 Return subdocument for footnote at a certain position in document.
590 @param rCpAndFc position in document
592 writerfilter::Reference
<Stream
>::Pointer_t getFootnote
593 (const CpAndFc
& rCpAndFc
);
596 Return count of endnotes.
598 sal_uInt32
getEndnoteCount() const;
601 Return subdocument for an endnote.
603 @param nPos index of the endnote
605 writerfilter::Reference
<Stream
>::Pointer_t
getEndnote(sal_uInt32 nPos
);
608 Return subdocument for an endnote.
610 @param rCpAndFc CpAndFc where endnote is referenced
612 writerfilter::Reference
<Stream
>::Pointer_t getEndnote
613 (const CpAndFc
& rCpAndFc
);
616 Return count of annotations.
618 sal_uInt32
getAnnotationCount() const;
621 Return subdocument for an annotation.
623 @param nPos index of the annotation
625 writerfilter::Reference
<Stream
>::Pointer_t
getAnnotation(sal_uInt32 nPos
);
628 Return subdocument for an annotation.
630 @param rCpAndFc CpAndFc where annotation is referenced
632 writerfilter::Reference
<Stream
>::Pointer_t getAnnotation
633 (const CpAndFc
& rCpAndFc
);
638 @param rCpAndFc CpAndFc where bookmark begins or ends
640 writerfilter::Reference
<Properties
>::Pointer_t
641 getBookmark(const CpAndFc
& rCpAndFc
) const;
646 @param rCpAndFc CpAndFc of the shape
648 writerfilter::Reference
<Properties
>::Pointer_t
649 getShape(const CpAndFc
& rCpAndFc
) const;
651 writerfilter::Reference
<Properties
>::Pointer_t
652 getShape(sal_uInt32 nSpid
);
657 @param nBlib number of the blip to return
659 writerfilter::Reference
<Properties
>::Pointer_t
660 getBlip(sal_uInt32 nBlib
);
663 Return break descriptor.
665 @param rCpAndFc CpAndFc of the break
667 writerfilter::Reference
<Properties
>::Pointer_t
668 getBreak(const CpAndFc
& rCpAndFc
) const;
674 @param rCpAndFc CpAndFc of the field
676 writerfilter::Reference
<Properties
>::Pointer_t
677 getField(const CpAndFc
& rCpAndFc
) const;
680 Return document properties.
683 writerfilter::Reference
<Properties
>::Pointer_t
684 getDocumentProperties() const;
687 Return current field descriptor.
689 WW8FLD::Pointer_t
getCurrentFLD() const;
692 Return stream of text box.
694 @param nShpId shape id of text box
696 writerfilter::Reference
<Stream
>::Pointer_t
697 getTextboxText(sal_uInt32 nShpId
) const;
700 Return file character position according to a character
703 @param cp the character position
705 Fc
cp2fc(const Cp
& cp
) const;
708 Return CpAndFc related to character position.
710 @param cp the character position
712 CpAndFc
getCpAndFc(const Cp
& cp
, PropertyType type
= PROP_DOC
) const;
715 Return CpAndFc related to file character position.
717 @param fc the file character position
719 CpAndFc
getCpAndFc(const Fc
& fc
, PropertyType type
= PROP_DOC
) const;
721 sal_uInt32
getPicLocation() const;
722 void setPicLocation(sal_uInt32 fcPicLoc
);
725 void setPicIsData(bool bPicIsData
);
728 Create events for the document.
730 @param rHandler handler to send the events to
732 void resolve(Stream
& rHandler
);
737 The text of the given iterator is split at special
738 characters. Each run of non-special characters is send as one
739 event. Each run of special characters is send as one event.
741 @param pIt iterator whose text is to be resolved
742 @param rStream handler for the events
744 void resolveText(WW8DocumentIterator::Pointer_t pIt
, Stream
& rStream
);
747 Resolve the picture at mfcPicLoc.
751 void resolvePicture(Stream
& rStream
);
754 Resolve special char.
756 @param nChar the special char
757 @param rStream the stream handler to resolve the special char to
759 void resolveSpecialChar(sal_uInt32 nChar
, Stream
& rStream
);
763 Implentation class for an iterator in a document.
765 class WW8DocumentIteratorImpl
: public WW8DocumentIterator
767 /// pointer to the document
768 WW8DocumentImpl
* mpDocument
;
770 /// CpAndFc the iterator is pointing to
774 WW8DocumentIteratorImpl(WW8DocumentImpl
* pDocument
,
775 const CpAndFc
& rCpAndFc
)
776 : mpDocument(pDocument
), mCpAndFc(rCpAndFc
)
780 virtual ~WW8DocumentIteratorImpl();
783 Increase the iterator to the next character position.
785 WW8DocumentIterator
& operator++();
788 Decrease the iterator to the previous character position.
790 WW8DocumentIterator
& operator--();
792 virtual writerfilter::Reference
<Properties
>::Pointer_t
getProperties()
794 //void setAttributes(const IAttributeSet & aAttributeSet);
796 virtual writerfilter::Reference
<Stream
>::Pointer_t
getSubDocument() const;
798 /** Return if the text the iterator points to is complex.
800 @attention The definition of a complex run of text in Word is
801 counter-intuitive: Complex runs use 8-bit encoding for characters,
802 non-complex ones use 16 bits.
804 bool isComplex() const;
805 virtual PropertyType
getPropertyType() const;
807 virtual WW8Stream::Sequence
getText();
808 virtual bool equal(const WW8DocumentIterator
& rIt
) const;
810 virtual string
toString() const;
811 virtual void dump(ostream
& o
) const;
814 Return pointer to the shape at character position the iterator
817 virtual writerfilter::Reference
<Properties
>::Pointer_t
getShape() const;
820 Return pointer to section description at character position the
823 WW8SED
* getSED() const;
827 Return string for property type.
829 string
propertyTypeToString(PropertyType nType
);
832 #endif // INCLUDED_WW8_DOCUMENT_IMPL_HXX
834 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */