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 : #ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPER_IMPL_HXX
20 : #define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPER_IMPL_HXX
21 :
22 : #include <com/sun/star/text/XParagraphCursor.hpp>
23 : #include <com/sun/star/text/XTextDocument.hpp>
24 : #include <com/sun/star/text/XTextCursor.hpp>
25 : #include <com/sun/star/text/XTextAppend.hpp>
26 : #include <com/sun/star/text/XTextAppendAndConvert.hpp>
27 : #include <com/sun/star/text/XTextFrame.hpp>
28 : #include <com/sun/star/style/TabStop.hpp>
29 : #include <com/sun/star/container/XNameContainer.hpp>
30 : #include <vector>
31 : #include <stack>
32 : #include <queue>
33 : #include <boost/optional.hpp>
34 : #include <boost/tuple/tuple.hpp>
35 : #include <unordered_map>
36 :
37 : #include <ooxml/resourceids.hxx>
38 :
39 : #include <DomainMapper.hxx>
40 : #include "DomainMapperTableManager.hxx"
41 : #include "PropertyMap.hxx"
42 : #include "FontTable.hxx"
43 : #include "NumberingManager.hxx"
44 : #include "StyleSheetTable.hxx"
45 : #include "SettingsTable.hxx"
46 : #include "ThemeTable.hxx"
47 : #include "GraphicImport.hxx"
48 : #include "OLEHandler.hxx"
49 : #include "FFDataHandler.hxx"
50 : #include "FormControlHelper.hxx"
51 : #include <map>
52 :
53 : #include <string.h>
54 :
55 : namespace com{ namespace sun{ namespace star{
56 : namespace awt{
57 : struct Size;
58 : }
59 : namespace lang{
60 : class XMultiServiceFactory;
61 : struct Locale;
62 : }
63 : namespace text
64 : {
65 : class XTextField;
66 : class XFormField;
67 : }
68 : namespace beans{ class XPropertySet;}
69 : }}}
70 :
71 : namespace writerfilter {
72 : namespace dmapper {
73 :
74 : class SdtHelper;
75 :
76 : struct _PageMar
77 : {
78 : sal_Int32 top;
79 : sal_Int32 right;
80 : sal_Int32 bottom;
81 : sal_Int32 left;
82 : sal_Int32 header;
83 : sal_Int32 footer;
84 : sal_Int32 gutter;
85 : public:
86 : _PageMar();
87 : };
88 : enum PageMarElement
89 : {
90 : PAGE_MAR_TOP,
91 : PAGE_MAR_RIGHT,
92 : PAGE_MAR_BOTTOM,
93 : PAGE_MAR_LEFT,
94 : PAGE_MAR_HEADER,
95 : PAGE_MAR_FOOTER,
96 : PAGE_MAR_GUTTER
97 : };
98 :
99 : /*-------------------------------------------------------------------------
100 : property stack element
101 : -----------------------------------------------------------------------*/
102 : enum ContextType
103 : {
104 : CONTEXT_SECTION,
105 : CONTEXT_PARAGRAPH,
106 : CONTEXT_CHARACTER,
107 : CONTEXT_STYLESHEET,
108 : CONTEXT_LIST
109 : };
110 : enum { NUMBER_OF_CONTEXTS = CONTEXT_LIST + 1 };
111 :
112 : enum BreakType
113 : {
114 : PAGE_BREAK,
115 : COLUMN_BREAK
116 : };
117 :
118 : /**
119 : * Storage for state that is relevant outside a header/footer, but not inside it.
120 : *
121 : * In case some state of DomainMapper_Impl should be reset before handling the
122 : * header/footer and should be restored once handling of header/footer is done,
123 : * then you can use this class to do so.
124 : */
125 : class HeaderFooterContext
126 : {
127 : bool m_bTextInserted;
128 : public:
129 : HeaderFooterContext(bool bTextInserted);
130 : bool getTextInserted();
131 : };
132 :
133 : /*--------------------------------------------------
134 : field stack element
135 : * --------------------------------------------------*/
136 : class FieldContext
137 : {
138 : bool m_bFieldCommandCompleted;
139 : css::uno::Reference<css::text::XTextRange> m_xStartRange;
140 :
141 : OUString m_sCommand;
142 : OUString m_sResult;
143 : bool m_bFieldLocked;
144 :
145 : css::uno::Reference<css::text::XTextField> m_xTextField;
146 : css::uno::Reference<css::text::XFormField> m_xFormField;
147 : css::uno::Reference<css::beans::XPropertySet> m_xTOC;
148 : css::uno::Reference<css::beans::XPropertySet> m_xTC; // TOX entry
149 : css::uno::Reference<css::beans::XPropertySet> m_xCustomField;
150 : OUString m_sHyperlinkURL;
151 : FFDataHandler::Pointer_t m_pFFDataHandler;
152 : FormControlHelper::Pointer_t m_pFormControlHelper;
153 : /// (Character) properties of the field itself.
154 : PropertyMapPtr m_pProperties;
155 :
156 : public:
157 : FieldContext(css::uno::Reference<css::text::XTextRange> const& xStart);
158 : ~FieldContext();
159 :
160 2067 : css::uno::Reference<css::text::XTextRange> GetStartRange() const { return m_xStartRange; }
161 :
162 : void AppendCommand(const OUString& rPart);
163 7048 : const OUString& GetCommand() const {return m_sCommand; }
164 :
165 373 : void AppendResult(OUString const& rResult) { m_sResult += rResult; }
166 2311 : const OUString& GetResult() const { return m_sResult; }
167 :
168 1974 : void SetCommandCompleted() { m_bFieldCommandCompleted = true; }
169 7489 : bool IsCommandCompleted() const { return m_bFieldCommandCompleted; }
170 :
171 12 : void SetFieldLocked() { m_bFieldLocked = true; }
172 11 : bool IsFieldLocked() { return m_bFieldLocked; }
173 :
174 336 : css::uno::Reference<css::beans::XPropertySet> GetCustomField() const { return m_xCustomField; }
175 2 : void SetCustomField(css::uno::Reference<css::beans::XPropertySet> const& xCustomField) { m_xCustomField = xCustomField; }
176 4602 : css::uno::Reference<css::text::XTextField> GetTextField() const { return m_xTextField;}
177 1972 : void SetTextField(css::uno::Reference<css::text::XTextField> const& xTextField) { m_xTextField = xTextField;}
178 32 : css::uno::Reference<css::text::XFormField> GetFormField() const { return m_xFormField;}
179 126 : void SetFormField(css::uno::Reference<css::text::XFormField> const& xFormField) { m_xFormField = xFormField;}
180 :
181 92 : void SetTOC(css::uno::Reference<css::beans::XPropertySet> const& xTOC) { m_xTOC = xTOC; }
182 1992 : css::uno::Reference<css::beans::XPropertySet> GetTOC() { return m_xTOC; }
183 :
184 1 : void SetTC(css::uno::Reference<css::beans::XPropertySet> const& xTC) { m_xTC = xTC; }
185 1881 : css::uno::Reference<css::beans::XPropertySet> GetTC() { return m_xTC; }
186 :
187 775 : void SetHyperlinkURL( const OUString& rURL ) { m_sHyperlinkURL = rURL; }
188 2280 : const OUString& GetHyperlinkURL() { return m_sHyperlinkURL; }
189 :
190 63 : void setFFDataHandler(FFDataHandler::Pointer_t pFFDataHandler) { m_pFFDataHandler = pFFDataHandler; }
191 32 : FFDataHandler::Pointer_t getFFDataHandler() const { return m_pFFDataHandler; }
192 :
193 32 : void setFormControlHelper(FormControlHelper::Pointer_t pFormControlHelper) { m_pFormControlHelper = pFormControlHelper; }
194 1537 : FormControlHelper::Pointer_t getFormControlHelper() const { return m_pFormControlHelper; }
195 393 : PropertyMapPtr getProperties() { return m_pProperties; }
196 :
197 : ::std::vector<OUString> GetCommandParts() const;
198 : };
199 :
200 14142 : struct TextAppendContext
201 : {
202 : css::uno::Reference<css::text::XTextAppend> xTextAppend;
203 : css::uno::Reference<css::text::XTextRange> xInsertPosition;
204 : css::uno::Reference<css::text::XParagraphCursor> xCursor;
205 : ParagraphPropertiesPtr pLastParagraphProperties;
206 :
207 4714 : TextAppendContext(const css::uno::Reference<css::text::XTextAppend>& xAppend, const css::uno::Reference<css::text::XTextCursor>& xCur)
208 4714 : : xTextAppend(xAppend)
209 : {
210 4714 : xCursor.set(xCur, css::uno::UNO_QUERY);
211 4714 : xInsertPosition.set(xCursor, css::uno::UNO_QUERY);
212 4714 : }
213 : };
214 :
215 4230 : struct AnchoredContext
216 : {
217 : css::uno::Reference<css::text::XTextContent> xTextContent;
218 : bool bToRemove;
219 :
220 1410 : AnchoredContext(const css::uno::Reference<css::text::XTextContent>& xContent)
221 1410 : : xTextContent(xContent), bToRemove(false)
222 : {
223 1410 : }
224 : };
225 :
226 : typedef std::shared_ptr<FieldContext> FieldContextPtr;
227 :
228 : typedef std::stack<ContextType> ContextStack;
229 : typedef std::stack<PropertyMapPtr> PropertyStack;
230 : typedef std::stack< TextAppendContext > TextAppendStack;
231 : typedef std::stack<HeaderFooterContext> HeaderFooterStack;
232 : typedef std::stack<FieldContextPtr> FieldStack;
233 : typedef std::stack< AnchoredContext > TextContentStack;
234 :
235 : /*-------------------------------------------------------------------------
236 : extended tab stop struct
237 : -----------------------------------------------------------------------*/
238 : struct DeletableTabStop : public css::style::TabStop
239 : {
240 : bool bDeleted;
241 9885 : DeletableTabStop()
242 9885 : : bDeleted(false)
243 : {
244 : // same defaults as SvxXMLTabStopContext_Impl
245 9885 : FillChar = ' ';
246 9885 : DecimalChar = ',';
247 9885 : }
248 331 : DeletableTabStop(const css::style::TabStop& rTabStop)
249 : : TabStop(rTabStop),
250 331 : bDeleted(false)
251 : {
252 331 : }
253 : };
254 : /*-------------------------------------------------------------------------
255 : /// helper to remember bookmark start position
256 : -----------------------------------------------------------------------*/
257 14545 : struct BookmarkInsertPosition
258 : {
259 : bool m_bIsStartOfText;
260 : OUString m_sBookmarkName;
261 : css::uno::Reference<css::text::XTextRange> m_xTextRange;
262 2909 : BookmarkInsertPosition(bool bIsStartOfText, const OUString& rName, css::uno::Reference<css::text::XTextRange> const& xTextRange):
263 : m_bIsStartOfText( bIsStartOfText ),
264 : m_sBookmarkName( rName ),
265 2909 : m_xTextRange( xTextRange )
266 2909 : {}
267 : };
268 :
269 : /// Stores the start/end positions of an annotation before its insertion.
270 112 : struct AnnotationPosition
271 : {
272 : css::uno::Reference<css::text::XTextRange> m_xStart;
273 : css::uno::Reference<css::text::XTextRange> m_xEnd;
274 : };
275 : typedef std::unordered_map< sal_Int32, AnnotationPosition > AnnotationPositions_t;
276 :
277 : struct LineNumberSettings
278 : {
279 : bool bIsOn;
280 : sal_Int32 nDistance;
281 : sal_Int32 nInterval;
282 : bool bRestartAtEachPage;
283 : sal_Int32 nStartValue;
284 1985 : LineNumberSettings() :
285 : bIsOn(false)
286 : ,nDistance(0)
287 : ,nInterval(0)
288 : ,bRestartAtEachPage(true)
289 1985 : ,nStartValue(1)
290 1985 : {}
291 :
292 : };
293 :
294 : /// Contains information about a table that will be potentially converted to a floating one at the section end.
295 117 : struct FloatingTableInfo
296 : {
297 : css::uno::Reference<css::text::XTextRange> m_xStart;
298 : css::uno::Reference<css::text::XTextRange> m_xEnd;
299 : css::uno::Sequence<css::beans::PropertyValue> m_aFrameProperties;
300 : sal_Int32 m_nTableWidth;
301 :
302 37 : FloatingTableInfo(css::uno::Reference<css::text::XTextRange> const& xStart,
303 : css::uno::Reference<css::text::XTextRange> const& xEnd,
304 : const css::uno::Sequence<css::beans::PropertyValue>& aFrameProperties,
305 : sal_Int32 nTableWidth)
306 : : m_xStart(xStart),
307 : m_xEnd(xEnd),
308 : m_aFrameProperties(aFrameProperties),
309 37 : m_nTableWidth(nTableWidth)
310 : {
311 37 : }
312 : css::uno::Any getPropertyValue(const OUString &propertyName);
313 : };
314 :
315 : class DomainMapper;
316 : class DomainMapper_Impl
317 : {
318 : public:
319 : typedef std::map < OUString, BookmarkInsertPosition > BookmarkMap_t;
320 :
321 : private:
322 : SourceDocumentType m_eDocumentType;
323 : DomainMapper& m_rDMapper;
324 : css::uno::Reference<css::text::XTextDocument> m_xTextDocument;
325 : css::uno::Reference<css::beans::XPropertySet> m_xDocumentSettings;
326 : css::uno::Reference<css::lang::XMultiServiceFactory> m_xTextFactory;
327 : css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
328 : css::uno::Reference<css::container::XNameContainer> m_xPageStyles;
329 : css::uno::Reference<css::text::XText> m_xBodyText;
330 : css::uno::Reference<css::text::XTextContent> m_xEmbedded;
331 :
332 : TextAppendStack m_aTextAppendStack;
333 :
334 : TextContentStack m_aAnchoredStack;
335 :
336 : HeaderFooterStack m_aHeaderFooterStack;
337 : FieldStack m_aFieldStack;
338 : bool m_bSetUserFieldContent;
339 : bool m_bSetCitation;
340 : bool m_bSetDateValue;
341 : bool m_bIsFirstSection;
342 : bool m_bIsColumnBreakDeferred;
343 : bool m_bIsPageBreakDeferred;
344 : /// If we want to set "sdt end" on the next character context.
345 : bool m_bSdtEndDeferred;
346 : /// If we want to set "paragraph sdt end" on the next paragraph context.
347 : bool m_bParaSdtEndDeferred;
348 : bool m_bStartTOC;
349 : bool m_bStartTOCHeaderFooter;
350 : /// If we got any text that is the pre-rendered result of the TOC field.
351 : bool m_bStartedTOC;
352 : bool m_bStartIndex;
353 : bool m_bStartBibliography;
354 : bool m_bTOCPageRef;
355 : bool m_bStartGenericField;
356 : bool m_bTextInserted;
357 : LineNumberSettings m_aLineNumberSettings;
358 :
359 : BookmarkMap_t m_aBookmarkMap;
360 : OUString m_sCurrentBkmkId;
361 : OUString m_sCurrentBkmkName;
362 :
363 : _PageMar m_aPageMargins;
364 : sal_Int32 m_nSymboldata;
365 :
366 :
367 : // TableManagers are stacked: one for each stream to avoid any confusion
368 : std::stack< std::shared_ptr< DomainMapperTableManager > > m_aTableManagers;
369 : TableDataHandler::Pointer_t m_pTableHandler;
370 :
371 : //each context needs a stack of currently used attributes
372 : PropertyStack m_aPropertyStacks[NUMBER_OF_CONTEXTS];
373 : ContextStack m_aContextStack;
374 : FontTablePtr m_pFontTable;
375 : ListsManager::Pointer m_pListTable;
376 : std::deque< css::uno::Reference<css::drawing::XShape> > m_aPendingShapes;
377 : StyleSheetTablePtr m_pStyleSheetTable;
378 : ThemeTablePtr m_pThemeTable;
379 : SettingsTablePtr m_pSettingsTable;
380 : GraphicImportPtr m_pGraphicImport;
381 :
382 :
383 : PropertyMapPtr m_pTopContext;
384 : PropertyMapPtr m_pLastSectionContext;
385 : PropertyMapPtr m_pLastCharacterContext;
386 :
387 : ::std::vector<DeletableTabStop> m_aCurrentTabStops;
388 : sal_uInt32 m_nCurrentTabStopIndex;
389 : OUString m_sCurrentParaStyleId;
390 : bool m_bInStyleSheetImport; //in import of fonts, styles, lists or lfos
391 : bool m_bInAnyTableImport; //in import of fonts, styles, lists or lfos
392 : bool m_bInHeaderFooterImport;
393 : bool m_bDiscardHeaderFooter;
394 : bool m_bInFootOrEndnote;
395 :
396 : bool m_bLineNumberingSet;
397 : bool m_bIsInFootnoteProperties;
398 : bool m_bIsCustomFtnMark;
399 :
400 : //registered frame properties
401 : std::vector<css::beans::PropertyValue> m_aFrameProperties;
402 : css::uno::Reference<css::text::XTextRange> m_xFrameStartRange;
403 : css::uno::Reference<css::text::XTextRange> m_xFrameEndRange;
404 :
405 : // Redline stack
406 : std::stack< std::vector< RedlineParamsPtr > > m_aRedlines;
407 : // The redline currently read, may be also stored by a context instead of m_aRedlines.
408 : RedlineParamsPtr m_currentRedline;
409 : RedlineParamsPtr m_pParaMarkerRedline;
410 : bool m_bIsParaMarkerChange;
411 :
412 : /// If the current paragraph has any runs.
413 : bool m_bParaChanged;
414 : bool m_bIsFirstParaInSection;
415 : bool m_bDummyParaAddedForTableInSection;
416 : bool m_bTextFrameInserted;
417 : bool m_bIsLastParaInSection;
418 : bool m_bIsLastSectionGroup;
419 : bool m_bIsInComments;
420 : /// If the current paragraph contains section property definitions.
421 : bool m_bParaSectpr;
422 : bool m_bUsingEnhancedFields;
423 : /// If the current paragraph is inside a structured document element.
424 : bool m_bSdt;
425 : bool m_bIsFirstRun;
426 : bool m_bIsOutsideAParagraph;
427 :
428 : css::uno::Reference< css::text::XTextCursor > xTOCMarkerCursor;
429 : css::uno::Reference< css::text::XTextCursor > mxTOCTextCursor;
430 :
431 : //annotation import
432 : css::uno::Reference< css::beans::XPropertySet > m_xAnnotationField;
433 : sal_Int32 m_nAnnotationId;
434 : AnnotationPositions_t m_aAnnotationPositions;
435 :
436 : void GetCurrentLocale(css::lang::Locale& rLocale);
437 : void SetNumberFormat(const OUString& rCommand, css::uno::Reference<css::beans::XPropertySet> const& xPropertySet, bool bDetectFormat = false);
438 : css::uno::Reference<css::beans::XPropertySet> FindOrCreateFieldMaster(const sal_Char* pFieldMasterService, const OUString& rFieldMasterName) throw(css::uno::Exception);
439 : css::uno::Reference<css::beans::XPropertySet> GetDocumentSettings();
440 :
441 : std::map<sal_Int32, css::uno::Any> deferredCharacterProperties;
442 :
443 : public:
444 : css::uno::Reference<css::text::XTextRange> m_xInsertTextRange;
445 : private:
446 : bool m_bIsNewDoc;
447 : public:
448 : DomainMapper_Impl(
449 : DomainMapper& rDMapper,
450 : css::uno::Reference < css::uno::XComponentContext > const& xContext,
451 : css::uno::Reference< css::lang::XComponent > const& xModel,
452 : SourceDocumentType eDocumentType,
453 : css::uno::Reference< css::text::XTextRange > const& xInsertTextRange,
454 : bool bIsNewDoc );
455 : virtual ~DomainMapper_Impl();
456 :
457 3084 : SectionPropertyMap* GetLastSectionContext( )
458 : {
459 3084 : return dynamic_cast< SectionPropertyMap* >( m_pLastSectionContext.get( ) );
460 : }
461 :
462 : css::uno::Reference<css::container::XNameContainer> GetPageStyles();
463 : css::uno::Reference<css::text::XText> GetBodyText();
464 6634 : css::uno::Reference<css::lang::XMultiServiceFactory> GetTextFactory() const
465 : {
466 6634 : return m_xTextFactory;
467 : }
468 : css::uno::Reference<css::uno::XComponentContext> GetComponentContext() const
469 : {
470 : return m_xComponentContext;
471 : }
472 20501 : css::uno::Reference<css::text::XTextDocument> GetTextDocument() const
473 : {
474 20501 : return m_xTextDocument;
475 : }
476 : void SetDocumentSettingsProperty( const OUString& rPropName, const css::uno::Any& rValue );
477 :
478 : static void CreateRedline(css::uno::Reference<css::text::XTextRange> const& xRange, RedlineParamsPtr pRedline);
479 :
480 : void CheckParaMarkerRedline(css::uno::Reference<css::text::XTextRange> const& xRange);
481 :
482 : void CheckRedline(css::uno::Reference<css::text::XTextRange> const& xRange);
483 :
484 : void StartParaMarkerChange( );
485 : void EndParaMarkerChange( );
486 : void ChainTextFrames();
487 :
488 : void RemoveDummyParaForTableInSection();
489 : void AddDummyParaForTableInSection();
490 : void RemoveLastParagraph( );
491 : void SetIsLastParagraphInSection( bool bIsLast );
492 1784 : bool GetIsLastParagraphInSection() { return m_bIsLastParaInSection;}
493 : void SetIsLastSectionGroup( bool bIsLast );
494 45 : bool GetIsLastSectionGroup() { return m_bIsLastSectionGroup;}
495 : void SetIsFirstParagraphInSection( bool bIsFirst );
496 32237 : bool GetIsFirstParagraphInSection() { return m_bIsFirstParaInSection;}
497 : void SetIsDummyParaAddedForTableInSection( bool bIsAdded );
498 8311 : bool GetIsDummyParaAddedForTableInSection() { return m_bDummyParaAddedForTableInSection;}
499 : void SetIsTextFrameInserted( bool bIsInserted );
500 193 : bool GetIsTextFrameInserted() { return m_bTextFrameInserted;}
501 : void SetParaSectpr(bool bParaSectpr);
502 13686 : bool GetParaSectpr() { return m_bParaSectpr;}
503 :
504 : void SetSymbolData( sal_Int32 nSymbolData );
505 10 : sal_Int32 GetSymbolData() { return m_nSymboldata;}
506 : /// Setter method for m_bSdt.
507 : void SetSdt(bool bSdt);
508 : /// Getter method for m_bSdt.
509 515 : bool GetSdt() { return m_bSdt;}
510 28861 : bool GetParaChanged() { return m_bParaChanged;}
511 :
512 : void deferBreak( BreakType deferredBreakType );
513 : bool isBreakDeferred( BreakType deferredBreakType );
514 : void clearDeferredBreaks();
515 : void clearDeferredBreak(BreakType deferredBreakType);
516 :
517 : void setSdtEndDeferred(bool bSdtEndDeferred);
518 : bool isSdtEndDeferred();
519 : void setParaSdtEndDeferred(bool bParaSdtEndDeferred);
520 : bool isParaSdtEndDeferred();
521 :
522 : void finishParagraph( PropertyMapPtr pPropertyMap );
523 : void appendTextPortion( const OUString& rString, PropertyMapPtr pPropertyMap );
524 : void appendTextContent(const css::uno::Reference<css::text::XTextContent>&, const css::uno::Sequence<css::beans::PropertyValue>&);
525 : void appendOLE( const OUString& rStreamName, OLEHandlerPtr pOleHandler );
526 : void appendStarMath( const Value& v );
527 : css::uno::Reference<css::beans::XPropertySet> appendTextSectionAfter(css::uno::Reference<css::text::XTextRange>& xBefore);
528 :
529 : // push the new properties onto the stack and make it the 'current' property map
530 : void PushProperties(ContextType eId);
531 : void PushStyleProperties(PropertyMapPtr pStyleProperties);
532 : void PushListProperties(PropertyMapPtr pListProperties);
533 : void PopProperties(ContextType eId);
534 :
535 77745 : ContextType GetTopContextType() const { return m_aContextStack.top(); }
536 1091220 : PropertyMapPtr GetTopContext()
537 : {
538 1091220 : return m_pTopContext;
539 : }
540 : PropertyMapPtr GetTopContextOfType(ContextType eId);
541 :
542 : css::uno::Reference<css::text::XTextAppend> GetTopTextAppend();
543 : FieldContextPtr GetTopFieldContext();
544 :
545 3467 : FontTablePtr GetFontTable()
546 : {
547 3467 : if(!m_pFontTable)
548 1747 : m_pFontTable.reset(new FontTable());
549 3467 : return m_pFontTable;
550 : }
551 70478 : StyleSheetTablePtr GetStyleSheetTable()
552 : {
553 70478 : if(!m_pStyleSheetTable)
554 1971 : m_pStyleSheetTable.reset(new StyleSheetTable( m_rDMapper, m_xTextDocument, m_bIsNewDoc ));
555 70478 : return m_pStyleSheetTable;
556 : }
557 : ListsManager::Pointer GetListTable();
558 17803 : ThemeTablePtr GetThemeTable()
559 : {
560 17803 : if(!m_pThemeTable)
561 1381 : m_pThemeTable.reset( new ThemeTable );
562 17803 : return m_pThemeTable;
563 : }
564 :
565 46538 : SettingsTablePtr GetSettingsTable()
566 : {
567 46538 : if( !m_pSettingsTable )
568 1984 : m_pSettingsTable.reset( new SettingsTable( m_rDMapper, m_xTextFactory ) );
569 46538 : return m_pSettingsTable;
570 : }
571 :
572 : GraphicImportPtr GetGraphicImport( GraphicImportType eGraphicImportType );
573 : void ResetGraphicImport();
574 : // this method deletes the current m_pGraphicImport after import
575 : void ImportGraphic(writerfilter::Reference< Properties>::Pointer_t, GraphicImportType eGraphicImportType );
576 :
577 : void InitTabStopFromStyle(const css::uno::Sequence<css::style::TabStop>& rInitTabStops);
578 : void IncorporateTabStop( const DeletableTabStop &aTabStop );
579 : css::uno::Sequence<css::style::TabStop> GetCurrentTabStopAndClear();
580 : void NextTabStop() {++m_nCurrentTabStopIndex;}
581 :
582 44899 : void SetCurrentParaStyleId(const OUString& sStringValue) {m_sCurrentParaStyleId = sStringValue;}
583 74932 : OUString GetCurrentParaStyleId() const {return m_sCurrentParaStyleId;}
584 :
585 : css::uno::Any GetPropertyFromStyleSheet(PropertyIds eId);
586 3390 : void SetStyleSheetImport( bool bSet ) { m_bInStyleSheetImport = bSet;}
587 94094 : bool IsStyleSheetImport()const { return m_bInStyleSheetImport;}
588 14318 : void SetAnyTableImport( bool bSet ) { m_bInAnyTableImport = bSet;}
589 814680 : bool IsAnyTableImport()const { return m_bInAnyTableImport;}
590 32761 : bool IsInShape()const { return m_aAnchoredStack.size() > 0;}
591 :
592 : void PushShapeContext(const css::uno::Reference<css::drawing::XShape>& xShape);
593 : void PopShapeContext();
594 : void UpdateEmbeddedShapeProps(const css::uno::Reference<css::drawing::XShape>& xShape);
595 : /// Add a pending shape: it's currently inserted into the document, but it should be removed before the import finishes.
596 : void PushPendingShape(const css::uno::Reference<css::drawing::XShape>& xShape);
597 : /// Get the first pending shape, if there are any.
598 : css::uno::Reference<css::drawing::XShape> PopPendingShape();
599 :
600 : void PushPageHeader(SectionPropertyMap::PageType eType);
601 : void PushPageFooter(SectionPropertyMap::PageType eType);
602 :
603 : void PopPageHeaderFooter();
604 1408 : bool IsInHeaderFooter() const { return m_bInHeaderFooterImport; }
605 :
606 : void PushFootOrEndnote( bool bIsFootnote );
607 : void PopFootOrEndnote();
608 91 : bool IsInFootOrEndnote() const { return m_bInFootOrEndnote; }
609 :
610 : void PushAnnotation();
611 : void PopAnnotation();
612 :
613 : /// A field context starts with a cFieldStart.
614 : void PushFieldContext();
615 : //the current field context waits for the completion of the command
616 : bool IsOpenFieldCommand() const;
617 : bool IsOpenField() const;
618 : //mark field in current context as locked (fixed)
619 : void SetFieldLocked();
620 : //collect the pieces of the command
621 : void AppendFieldCommand(OUString& rPartOfCommand);
622 : void handleFieldAsk
623 : (FieldContextPtr pContext,
624 : PropertyNameSupplier& rPropNameSupplier,
625 : css::uno::Reference< css::uno::XInterface > & xFieldInterface,
626 : css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties);
627 : void handleAutoNum
628 : (FieldContextPtr pContext,
629 : PropertyNameSupplier& rPropNameSupplier,
630 : css::uno::Reference< css::uno::XInterface > & xFieldInterface,
631 : css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties);
632 : static void handleAuthor
633 : (OUString const& rFirstParam,
634 : PropertyNameSupplier& rPropNameSupplier,
635 : css::uno::Reference< css::uno::XInterface > & xFieldInterface,
636 : css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties,
637 : FieldId eFieldId);
638 : void handleDocProperty
639 : (FieldContextPtr pContext,
640 : OUString const& rFirstParam,
641 : PropertyNameSupplier& rPropNameSupplier,
642 : css::uno::Reference< css::uno::XInterface > & xFieldInterface,
643 : css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties);
644 : void handleToc
645 : (FieldContextPtr pContext,
646 : PropertyNameSupplier& rPropNameSupplier,
647 : css::uno::Reference< css::uno::XInterface > & xFieldInterface,
648 : css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties,
649 : const OUString & sTOCServiceName);
650 : void handleIndex
651 : (FieldContextPtr pContext,
652 : PropertyNameSupplier& rPropNameSupplier,
653 : css::uno::Reference< css::uno::XInterface > & xFieldInterface,
654 : css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties,
655 : const OUString & sTOCServiceName);
656 :
657 : void handleBibliography
658 : (FieldContextPtr pContext,
659 : PropertyNameSupplier& rPropNameSupplier,
660 : const OUString & sTOCServiceName);
661 : /// The field command has to be closed (cFieldSep appeared).
662 : void CloseFieldCommand();
663 : //the _current_ fields require a string type result while TOCs accept richt results
664 : bool IsFieldResultAsString();
665 : void AppendFieldResult(OUString const& rResult);
666 : //apply the result text to the related field
667 : void SetFieldResult(OUString const& rResult);
668 : // set FFData of top field context
669 : void SetFieldFFData( FFDataHandler::Pointer_t pFFDataHandler );
670 : /// The end of field is reached (cFieldEnd appeared) - the command might still be open.
671 : void PopFieldContext();
672 :
673 : void SetBookmarkName( const OUString& rBookmarkName );
674 : void StartOrEndBookmark( const OUString& rId );
675 :
676 : void AddAnnotationPosition(
677 : const bool bStart,
678 : const sal_Int32 nAnnotationId );
679 :
680 1203140 : DomainMapperTableManager& getTableManager()
681 : {
682 1203140 : std::shared_ptr< DomainMapperTableManager > pMngr = m_aTableManagers.top();
683 1203140 : return *pMngr.get( );
684 : }
685 :
686 4834 : void appendTableManager( )
687 : {
688 4834 : std::shared_ptr<DomainMapperTableManager> pMngr(new DomainMapperTableManager());
689 4834 : m_aTableManagers.push( pMngr );
690 4834 : }
691 :
692 2849 : void appendTableHandler( )
693 : {
694 2849 : if (m_pTableHandler.get())
695 2849 : m_aTableManagers.top()->setHandler(m_pTableHandler);
696 2849 : }
697 :
698 4833 : void popTableManager( )
699 : {
700 4833 : if ( m_aTableManagers.size( ) > 0 )
701 4833 : m_aTableManagers.pop( );
702 4833 : }
703 :
704 : void SetLineNumbering( sal_Int32 nLnnMod, sal_uInt32 nLnc, sal_Int32 ndxaLnn );
705 27 : bool IsLineNumberingSet() const {return m_bLineNumberingSet;}
706 :
707 : DeletableTabStop m_aCurrentTabStop;
708 :
709 52929 : bool IsOOXMLImport() const { return m_eDocumentType == SourceDocumentType::OOXML; }
710 :
711 2486 : bool IsRTFImport() const { return m_eDocumentType == SourceDocumentType::RTF; }
712 :
713 1892 : void InitPageMargins() { m_aPageMargins = _PageMar(); }
714 : void SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue );
715 1892 : const _PageMar& GetPageMargins() const {return m_aPageMargins;}
716 :
717 104 : const LineNumberSettings& GetLineNumberSettings() const { return m_aLineNumberSettings;}
718 104 : void SetLineNumberSettings(const LineNumberSettings& rSet) { m_aLineNumberSettings = rSet;}
719 :
720 1240 : void SetInFootnoteProperties(bool bSet) { m_bIsInFootnoteProperties = bSet;}
721 3027 : bool IsInFootnoteProperties() const { return m_bIsInFootnoteProperties;}
722 :
723 0 : void SetCustomFtnMark(bool bSet) { m_bIsCustomFtnMark = bSet; }
724 0 : bool IsCustomFtnMark() const { return m_bIsCustomFtnMark; }
725 :
726 1075 : bool IsInComments() const { return m_bIsInComments; };
727 :
728 : void CheckUnregisteredFrameConversion( );
729 :
730 : void RegisterFrameConversion(css::uno::Reference<css::text::XTextRange> const& xFrameStartRange,
731 : css::uno::Reference<css::text::XTextRange> const& xFrameEndRange,
732 : const std::vector<css::beans::PropertyValue>& aFrameProperties);
733 : bool ExecuteFrameConversion();
734 :
735 : void AddNewRedline( sal_uInt32 sprmId );
736 :
737 : sal_Int32 GetCurrentRedlineToken( );
738 : void SetCurrentRedlineAuthor( const OUString& sAuthor );
739 : void SetCurrentRedlineDate( const OUString& sDate );
740 : void SetCurrentRedlineId( sal_Int32 nId );
741 : void SetCurrentRedlineToken( sal_Int32 nToken );
742 : void SetCurrentRedlineRevertProperties( const css::uno::Sequence<css::beans::PropertyValue>& aProperties );
743 : void SetCurrentRedlineIsRead();
744 : void RemoveTopRedline( );
745 : void ResetParaMarkerRedline( );
746 : void SetCurrentRedlineInitials( const OUString& sInitials );
747 181 : bool IsFirstRun() { return m_bIsFirstRun;}
748 112140 : void SetIsFirstRun(bool bval) { m_bIsFirstRun = bval;}
749 3679 : bool IsOutsideAParagraph() { return m_bIsOutsideAParagraph;}
750 97633 : void SetIsOutsideAParagraph(bool bval) { m_bIsOutsideAParagraph = bval;}
751 :
752 : void ApplySettingsTable();
753 : SectionPropertyMap * GetSectionContext();
754 : /// If the current paragraph has a numbering style associated, this method returns its character style (part of the numbering rules)
755 : css::uno::Reference<css::beans::XPropertySet> GetCurrentNumberingCharStyle();
756 : /// If the current paragraph has a numbering style associated, this method returns its numbering rules
757 : css::uno::Reference<css::container::XIndexAccess> GetCurrentNumberingRules(sal_Int32* pListLevel = nullptr);
758 :
759 : /**
760 : Used for attributes/sprms which cannot be evaluated immediatelly (e.g. they depend
761 : on another one that comes in the same CONTEXT_CHARACTER). The property will be processed
762 : again in DomainMapper::processDeferredCharacterProperties().
763 : */
764 : void deferCharacterProperty(sal_Int32 id, const css::uno::Any& value);
765 : /**
766 : Processes properties deferred using deferCharacterProperty(). To be called whenever the top
767 : CONTEXT_CHARACTER is going to be used (e.g. by appendText()).
768 : */
769 : void processDeferredCharacterProperties();
770 :
771 : /// Get a property of the current numbering style's current level.
772 : sal_Int32 getCurrentNumberingProperty(const OUString& aProp);
773 :
774 : /// If we're importing into a new document, or just pasting to an existing one.
775 4478 : bool IsNewDoc() { return m_bIsNewDoc;}
776 :
777 : /// If we're inside <w:rPr>, inside <w:style w:type="table">
778 : bool m_bInTableStyleRunProps;
779 :
780 : std::shared_ptr<SdtHelper> m_pSdtHelper;
781 :
782 : /// Document background color, applied to every page style.
783 : boost::optional<sal_Int32> m_oBackgroundColor;
784 :
785 : /**
786 : * This contains the raw table depth. m_nTableDepth > 0 is the same as
787 : * getTableManager().isInTable(), unless we're in the first paragraph of a
788 : * table, or first paragraph after a table, as the table manager is only
789 : * updated once we ended the paragraph (and know if the para has the
790 : * inTbl SPRM or not).
791 : */
792 : sal_Int32 m_nTableDepth;
793 :
794 : /// If the document has a footnote separator.
795 : bool m_bHasFtnSep;
796 :
797 : /// If the next newline should be ignored, used by the special footnote separator paragraph.
798 : bool m_bIgnoreNextPara;
799 : /// If the next tab should be ignored, used for footnotes.
800 : bool m_bIgnoreNextTab;
801 : bool m_bFrameBtLr; ///< Bottom to top, left to right text frame direction is requested for the current text frame.
802 : /// Pending floating tables: they may be converted to text frames at the section end.
803 : std::vector<FloatingTableInfo> m_aPendingFloatingTables;
804 :
805 : /// Append a property to a sub-grabbag if necessary (e.g. 'lineRule', 'auto')
806 : void appendGrabBag(std::vector<css::beans::PropertyValue>& rInteropGrabBag, const OUString& aKey, const OUString& aValue);
807 : void appendGrabBag(std::vector<css::beans::PropertyValue>& rInteropGrabBag, const OUString& aKey, std::vector<css::beans::PropertyValue>& rValue);
808 :
809 : /// Enable, disable an check status of grabbags
810 : void enableInteropGrabBag(const OUString& aName);
811 : void disableInteropGrabBag();
812 : bool isInteropGrabBagEnabled();
813 :
814 : /// Name of m_aInteropGrabBag.
815 : OUString m_aInteropGrabBagName;
816 :
817 : /// A toplevel dmapper grabbag, like 'pPr'.
818 : std::vector<css::beans::PropertyValue> m_aInteropGrabBag;
819 :
820 : /// A sub-grabbag of m_aInteropGrabBag, like 'spacing'.
821 : std::vector<css::beans::PropertyValue> m_aSubInteropGrabBag;
822 :
823 : /// ST_PositionOffset values we received
824 : std::pair<OUString, OUString> m_aPositionOffsets;
825 : /// ST_AlignH/V values we received
826 : std::pair<OUString, OUString> m_aAligns;
827 : /// ST_PositivePercentage values we received
828 : std::queue<OUString> m_aPositivePercentages;
829 5642 : bool isInIndexContext() { return m_bStartIndex;}
830 4517 : bool isInBibliographyContext() { return m_bStartBibliography;}
831 :
832 : void substream(Id rName, ::writerfilter::Reference<Stream>::Pointer_t const& ref);
833 :
834 : /// If the document needs to split paragraph.
835 : bool m_bIsSplitPara;
836 :
837 : /// Check if "SdtEndBefore" property is set
838 : bool IsSdtEndBefore();
839 :
840 : bool IsDiscardHeaderFooter();
841 :
842 : private:
843 : void PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType);
844 : std::vector<css::uno::Reference< css::drawing::XShape > > m_vTextFramesForChaining ;
845 : /// Current paragraph had at least one field in it.
846 : bool m_bParaHadField;
847 : };
848 :
849 : // export just for test
850 : SAL_DLLPUBLIC_EXPORT boost::tuple<OUString, std::vector<OUString>, std::vector<OUString> >
851 : lcl_SplitFieldCommand(const OUString& rCommand);
852 :
853 : } //namespace dmapper
854 : } //namespace writerfilter
855 : #endif
856 :
857 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|