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_XMLOFF_TXTPARAE_HXX
21 #define INCLUDED_XMLOFF_TXTPARAE_HXX
23 #include <sal/config.h>
24 #include <rtl/ref.hxx>
25 #include <xmloff/dllapi.h>
26 #include <rtl/ustring.hxx>
27 #include <com/sun/star/uno/Reference.h>
28 #include <xmloff/maptype.hxx>
29 #include <xmloff/styleexp.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/SinglePropertySetInfoCache.hxx>
32 #include <xmloff/XMLTextListAutoStylePool.hxx>
33 #include <o3tl/sorted_vector.hxx>
34 #include <o3tl/span.hxx>
38 class XMLTextListsHelper
;
40 class SvXMLAutoStylePoolP
;
41 class XMLTextFieldExport
;
42 class XMLTextNumRuleInfo
;
43 class XMLSectionExport
;
44 class XMLIndexMarkExport
;
45 class XMLRedlineExport
;
46 class MultiPropertySetHelper
;
47 enum class XMLShapeExportFlags
;
48 class SvXMLExportPropertyMapper
;
50 namespace com::sun::star
52 namespace beans
{ class XPropertySet
; class XPropertyState
;
53 class XPropertySetInfo
; }
54 namespace container
{ class XEnumeration
; class XIndexAccess
; class XNameReplace
; }
55 namespace drawing
{ class XShape
; }
56 namespace text
{ class XTextContent
; class XTextRange
; class XText
;
57 class XFootnote
; class XTextFrame
; class XTextSection
;
63 class OFormLayerXMLExport
;
79 class XMLOFF_DLLPUBLIC XMLTextParagraphExport
: public XMLStyleExport
82 std::unique_ptr
<Impl
> m_xImpl
;
84 // SvXMLExport& rExport;
85 SvXMLAutoStylePoolP
& m_rAutoStylePool
;
86 rtl::Reference
< SvXMLExportPropertyMapper
> m_xParaPropMapper
;
87 rtl::Reference
< SvXMLExportPropertyMapper
> m_xTextPropMapper
;
88 rtl::Reference
< SvXMLExportPropertyMapper
> m_xFramePropMapper
;
89 rtl::Reference
< SvXMLExportPropertyMapper
> m_xAutoFramePropMapper
;
90 rtl::Reference
< SvXMLExportPropertyMapper
> m_xSectionPropMapper
;
91 rtl::Reference
< SvXMLExportPropertyMapper
> m_xRubyPropMapper
;
93 const ::std::unique_ptr
< ::xmloff::BoundFrameSets
> m_pBoundFrameSets
;
94 std::unique_ptr
<XMLTextFieldExport
> m_pFieldExport
;
95 std::vector
<OUString
> maListElements
;
96 XMLTextListAutoStylePool maListAutoPool
;
97 std::unique_ptr
<XMLSectionExport
> m_pSectionExport
;
98 std::unique_ptr
<XMLIndexMarkExport
> m_pIndexMarkExport
;
100 /// may be NULL (if no redlines should be exported; e.g. in block mode)
101 std::unique_ptr
<XMLRedlineExport
> m_pRedlineExport
;
107 // keep track of open rubies
108 OUString m_sOpenRubyText
;
109 OUString m_sOpenRubyCharStyle
;
112 XMLTextListsHelper
* mpTextListsHelper
;
113 ::std::vector
< std::unique_ptr
<XMLTextListsHelper
> > maTextListsHelperStack
;
115 struct DocumentListNodes
;
116 std::unique_ptr
<DocumentListNodes
> mpDocumentListNodes
;
118 o3tl::sorted_vector
<css::uno::Reference
<css::text::XTextFrame
>> maFrameRecurseGuard
;
119 o3tl::sorted_vector
<css::uno::Reference
<css::drawing::XShape
>> maShapeRecurseGuard
;
123 enum class FrameType
{ Text
, Graphic
, Embedded
, Shape
};
126 enum FieldmarkType
{ NONE
, TEXT
, CHECK
}; // Used for simulating fieldmarks in OpenDocument 1.n Strict (for n <= 2). CHECK currently ignored.
129 void exportTextRangeSpan(
130 const css::uno::Reference
< css::text::XTextRange
> & rTextRange
,
131 css::uno::Reference
< css::beans::XPropertySet
> const & xPropSet
,
132 css::uno::Reference
< css::beans::XPropertySetInfo
> & xPropSetInfo
,
133 const bool bIsUICharStyle
,
134 const bool bHasAutoStyle
,
135 const OUString
& sStyle
,
136 bool& rPrevCharIsSpace
,
137 FieldmarkType
& openFieldMark
);
141 // Implement Title/Description Elements UI (#i73249#)
142 static constexpr OUStringLiteral gsAnchorCharStyleName
= u
"AnchorCharStyleName";
143 static constexpr OUStringLiteral gsBeginNotice
= u
"BeginNotice";
144 static constexpr OUStringLiteral gsCategory
= u
"Category";
145 static constexpr OUStringLiteral gsCharStyleName
= u
"CharStyleName";
146 static constexpr OUStringLiteral gsCharStyleNames
= u
"CharStyleNames";
147 static constexpr OUStringLiteral gsEndNotice
= u
"EndNotice";
148 static constexpr OUStringLiteral gsFootnote
= u
"Footnote";
149 static constexpr OUStringLiteral gsFootnoteCounting
= u
"FootnoteCounting";
150 static constexpr OUStringLiteral gsNumberingType
= u
"NumberingType";
151 static constexpr OUStringLiteral gsPageDescName
= u
"PageDescName";
152 static constexpr OUStringLiteral gsPageStyleName
= u
"PageStyleName";
153 static constexpr OUStringLiteral gsParaStyleName
= u
"ParaStyleName";
154 static constexpr OUStringLiteral gsPositionEndOfDoc
= u
"PositionEndOfDoc";
155 static constexpr OUStringLiteral gsPrefix
= u
"Prefix";
156 static constexpr OUStringLiteral gsReferenceId
= u
"ReferenceId";
157 static constexpr OUStringLiteral gsStartAt
= u
"StartAt";
158 static constexpr OUStringLiteral gsSuffix
= u
"Suffix";
159 static constexpr OUStringLiteral gsTextEndnoteService
= u
"com.sun.star.text.Endnote";
160 static constexpr OUStringLiteral gsTextSection
= u
"TextSection";
163 static constexpr OUStringLiteral gsFrameStyleName
= u
"FrameStyleName";
164 SinglePropertySetInfoCache m_aCharStyleNamesPropInfoCache
;
166 SvXMLAutoStylePoolP
& GetAutoStylePool() { return m_rAutoStylePool
; }
167 const SvXMLAutoStylePoolP
& GetAutoStylePool() const { return m_rAutoStylePool
; }
170 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetParaPropMapper() const
172 return m_xParaPropMapper
;
175 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetTextPropMapper() const
177 return m_xTextPropMapper
;
180 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetAutoFramePropMapper() const
182 return m_xAutoFramePropMapper
;
184 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetSectionPropMapper() const
186 return m_xSectionPropMapper
;
188 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetRubyPropMapper() const
190 return m_xRubyPropMapper
;
193 OUString
FindTextStyle(
194 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
195 bool& rbHasCharStyle
,
196 bool& rbHasAutoStyle
,
197 const XMLPropertyState
** pAddState
= nullptr) const;
199 void exportTextRangeEnumeration(
200 const css::uno::Reference
< css::container::XEnumeration
> & rRangeEnum
,
201 bool bAutoStyles
, bool bProgress
, bool & rPrevCharIsSpace
);
205 XMLShapeExportFlags
addTextFrameAttributes(
206 const css::uno::Reference
< css::beans::XPropertySet
>& rPropSet
,
208 basegfx::B2DPoint
* pCenter
= nullptr,
209 OUString
*pMinHeightValue
= nullptr,
210 OUString
*pMinWidthValue
= nullptr );
212 virtual void exportStyleAttributes(
213 const css::uno::Reference
< css::style::XStyle
> & rStyle
) override
;
215 void exportPageFrames( bool bProgress
);
216 void exportFrameFrames( bool bAutoStyles
, bool bProgress
,
217 const css::uno::Reference
< css::text::XTextFrame
>& rParentTxtFrame
);
219 void exportNumStyles( bool bUsed
);
222 const css::uno::Reference
<
223 css::text::XText
> & rText
,
224 bool bAutoStyles
, bool bProgress
, bool bExportParagraph
, TextPNS eExtensionNS
= TextPNS::ODF
);
227 const css::uno::Reference
< css::text::XText
> & rText
,
228 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
229 bool bAutoStyles
, bool bProgress
, bool bExportParagraph
);
231 void exportTextContentEnumeration(
232 const css::uno::Reference
< css::container::XEnumeration
> & rContentEnum
,
234 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
236 bool bExportParagraph
= true,
237 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr,
238 TextPNS eExtensionNS
= TextPNS::ODF
);
239 void exportParagraph(
240 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
241 bool bAutoStyles
, bool bProgress
,
242 bool bExportParagraph
,
243 MultiPropertySetHelper
& rPropSetHelper
,
244 TextPNS eExtensionNS
);
246 virtual void exportTable(
247 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
248 bool bAutoStyles
, bool bProgress
);
250 void exportTextField(
251 const css::uno::Reference
< css::text::XTextRange
> & rTextRange
,
252 bool bAutoStyles
, bool bProgress
, bool * pPrevCharIsSpace
);
254 void exportTextField(
255 const css::uno::Reference
< css::text::XTextField
> & xTextField
,
256 const bool bAutoStyles
, const bool bProgress
,
257 const bool bRecursive
, bool * pPrevCharIsSpace
);
259 void exportAnyTextFrame(
260 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
262 bool bAutoStyles
, bool bProgress
, bool bExportContent
,
263 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
);
264 void _exportTextFrame(
265 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
266 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
,
268 inline void exportTextFrame(
269 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
270 bool bAutoStyles
, bool bProgress
, bool bExportContent
,
271 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
272 inline void exportShape(
273 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
275 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
278 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
279 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
280 void _exportTextGraphic(
281 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
282 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
283 inline void exportTextGraphic(
284 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
286 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
288 virtual void _collectTextEmbeddedAutoStyles(
289 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
);
290 virtual void _exportTextEmbedded(
291 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
292 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
293 inline void exportTextEmbedded(
294 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
296 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
298 /// export a footnote and styles
299 void exportTextFootnote(
300 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
301 const OUString
& sString
,
302 bool bAutoStyles
, bool bProgress
);
304 /// helper for exportTextFootnote
305 void exportTextFootnoteHelper(
306 const css::uno::Reference
< css::text::XFootnote
> & rPropSet
,
307 const css::uno::Reference
< css::text::XText
> & rText
,
308 const OUString
& sString
,
310 bool bIsEndnote
, bool bProgress
);
312 /// export footnote and endnote configuration elements
313 void exportTextFootnoteConfiguration();
315 void exportTextFootnoteConfigurationHelper(
316 const css::uno::Reference
< css::beans::XPropertySet
> & rFootnoteSupplier
,
320 const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
,
321 const OUString
& rProperty
,
322 const enum ::xmloff::token::XMLTokenEnum pElements
[],
325 void exportSoftPageBreak();
327 void exportTextLineBreak(const css::uno::Reference
<css::beans::XPropertySet
>& xPropSet
);
329 void exportTextRange(
330 const css::uno::Reference
< css::text::XTextRange
> & rTextRange
,
332 bool& rPrevCharWasSpace
,
333 FieldmarkType
& openFieldmarkType
);
335 void exportListChange( const XMLTextNumRuleInfo
& rPrvInfo
,
336 const XMLTextNumRuleInfo
& rNextInfo
);
338 /// check if current section or current list has changed;
339 /// calls exportListChange as appropriate
340 void exportListAndSectionChange(
341 css::uno::Reference
< css::text::XTextSection
> & rOldSection
,
342 const css::uno::Reference
< css::text::XTextSection
> & rNewSection
,
343 const XMLTextNumRuleInfo
& rOldList
,
344 const XMLTextNumRuleInfo
& rNewList
,
347 /// overload for exportListAndSectionChange;
348 /// takes new content rather than new section.
349 void exportListAndSectionChange(
350 css::uno::Reference
< css::text::XTextSection
> & rOldSection
,
351 const css::uno::Reference
< css::text::XTextContent
> & rNewContent
,
352 const XMLTextNumRuleInfo
& rOldList
,
353 const XMLTextNumRuleInfo
& rNewList
,
355 void exportListAndSectionChange(
356 css::uno::Reference
< css::text::XTextSection
> & rOldSection
,
357 MultiPropertySetHelper
& rPropSetHelper
,
358 sal_Int16 nTextSectionId
,
359 const css::uno::Reference
< css::text::XTextContent
> & rNewContent
,
360 const XMLTextNumRuleInfo
& rOldList
,
361 const XMLTextNumRuleInfo
& rNewList
,
366 const css::uno::Reference
< css::beans::XPropertySet
> & rPortionPropSet
,
369 /// export a text:meta
371 const css::uno::Reference
< css::beans::XPropertySet
> & i_xPortion
,
372 bool i_bAutoStyles
, bool i_isProgress
, bool & rPrevCharIsSpace
);
374 /// Exports a <loext:content-control> element.
375 void ExportContentControl(const css::uno::Reference
<css::beans::XPropertySet
>& xPortion
,
376 bool bAutoStyles
, bool isProgress
, bool& rPrevCharIsSpace
);
378 bool isAutoStylesCollected() const { return mbCollected
; }
380 virtual void exportTableAutoStyles();
384 XMLTextParagraphExport(
386 SvXMLAutoStylePoolP
& rASP
388 virtual ~XMLTextParagraphExport() override
;
390 /// add autostyle for specified family
392 XmlStyleFamily nFamily
,
393 MultiPropertySetHelper
& rPropSetHelper
,
394 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
);
396 XmlStyleFamily nFamily
,
397 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
398 o3tl::span
<const XMLPropertyState
> aAddStates
= {}, bool bDontSeek
= false );
400 /// find style name for specified family and parent
402 XmlStyleFamily nFamily
,
403 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
404 const OUString
& rParent
,
405 const o3tl::span
<const XMLPropertyState
> aAddStates
= {} ) const;
407 static SvXMLExportPropertyMapper
*CreateShapeExtPropMapper(
408 SvXMLExport
& rExport
);
409 static SvXMLExportPropertyMapper
*CreateCharExtPropMapper(
410 SvXMLExport
& rExport
);
411 static SvXMLExportPropertyMapper
*CreateParaExtPropMapper(
412 SvXMLExport
& rExport
);
413 static SvXMLExportPropertyMapper
*CreateParaDefaultExtPropMapper(
414 SvXMLExport
& rExport
);
416 // This methods exports all (or all used) styles
417 void exportTextStyles( bool bUsed
, bool bProg
);
419 /// This method exports (text field) declarations etc.
420 void exportTextDeclarations();
422 /// export the (text field) declarations for a particular XText
423 void exportTextDeclarations(
424 const css::uno::Reference
< css::text::XText
> & rText
);
426 /// export all declarations
427 void exportUsedDeclarations();
429 /// Export the list of change information (enclosed by <tracked-changes>)
430 /// (or the necessary automatic styles)
431 void exportTrackedChanges(bool bAutoStyle
);
433 /// Export the list of change information (enclosed by <tracked-changes>)
434 /// (or the necessary automatic styles)
435 void exportTrackedChanges(const css::uno::Reference
< css::text::XText
> & rText
,
438 /// Record tracked changes for this particular XText
439 /// (empty reference stop recording)
440 /// This should be used if tracked changes for e.g. footers are to
441 /// be exported separately via the exportTrackedChanges(bool,
442 /// Reference<XText>) method.
443 void recordTrackedChangesForXText(
444 const css::uno::Reference
< css::text::XText
> & rText
);
447 /// Stop recording tracked changes.
448 /// This is the same as calling recordTrackedChanges(...) with an
450 void recordTrackedChangesNoXText();
453 // This method exports the given OUString
454 void exportCharacterData(
455 const OUString
& rText
,
456 bool& rPrevCharWasSpace
);
458 // This method collects all automatic styles for the given XText
459 void collectTextAutoStyles(
460 const css::uno::Reference
< css::text::XText
> & rText
,
461 bool bIsProgress
= false,
462 bool bExportParagraph
= true )
464 exportText( rText
, true, bIsProgress
, bExportParagraph
);
467 void collectTextAutoStyles(
468 const css::uno::Reference
< css::text::XText
> & rText
,
469 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
472 exportText( rText
, rBaseSection
, true, bIsProgress
, true/*bExportParagraph*/ );
475 // It the model implements the xAutoStylesSupplier interface, the automatic
476 // styles can exported without iterating over the text portions
477 void collectTextAutoStylesOptimized( bool bIsProgress
);
479 // This method exports all automatic styles that have been collected.
480 void exportTextAutoStyles();
482 void exportEvents( const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
);
484 // Implement Title/Description Elements UI (#i73249#)
485 void exportTitleAndDescription( const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
486 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
488 // This method exports the given XText
490 const css::uno::Reference
< css::text::XText
> & rText
,
491 bool bIsProgress
= false,
492 bool bExportParagraph
= true, TextPNS eExtensionNS
= TextPNS::ODF
)
494 exportText( rText
, false, bIsProgress
, bExportParagraph
, eExtensionNS
);
498 const css::uno::Reference
< css::text::XText
> & rText
,
499 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
502 exportText( rText
, rBaseSection
, false, bIsProgress
, true/*bExportParagraph*/ );
505 void exportFramesBoundToPage( bool bIsProgress
)
507 exportPageFrames( bIsProgress
);
509 inline const XMLTextListAutoStylePool
& GetListAutoStylePool() const;
511 void SetBlockMode( bool bSet
) { m_bBlock
= bSet
; }
512 bool IsBlockMode() const { return m_bBlock
; }
515 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetParagraphPropertyMapper() const
517 return m_xParaPropMapper
;
521 /** exclude form controls which are in mute sections.
523 * This method is necessary to prevent the form layer export from exporting
524 * control models whose controls are not represented in the document. To
525 * achieve this, this method iterates over all shapes, checks to see if
526 * they are control shapes, and if so, whether they should be exported or
527 * not. If not, the form layer export will be notified accordingly.
529 * The reason this method is located here is that it needs to access the
530 * XMLSectionExport, which is only available here.
532 void PreventExportOfControlsInMuteSections(
533 const css::uno::Reference
< css::container::XIndexAccess
> & rShapes
,
534 const rtl::Reference
<xmloff::OFormLayerXMLExport
>& xFormExport
);
536 SinglePropertySetInfoCache
& GetCharStyleNamesPropInfoCache() { return m_aCharStyleNamesPropInfoCache
; }
538 void PushNewTextListsHelper();
540 void PopTextListsHelper();
543 bool ShouldSkipListId(const css::uno::Reference
<css::text::XTextContent
>& xTextContent
);
544 bool ExportListId() const;
546 XMLTextParagraphExport(XMLTextParagraphExport
const &) = delete;
550 inline const XMLTextListAutoStylePool
&
551 XMLTextParagraphExport::GetListAutoStylePool() const
553 return maListAutoPool
;
556 inline void XMLTextParagraphExport::exportTextFrame(
557 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
558 bool bAutoStyles
, bool bIsProgress
, bool bExportContent
,
559 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
561 exportAnyTextFrame( rTextContent
, FrameType::Text
, bAutoStyles
, bIsProgress
,
562 bExportContent
, pRangePropSet
);
565 inline void XMLTextParagraphExport::exportTextGraphic(
566 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
568 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
570 exportAnyTextFrame( rTextContent
, FrameType::Graphic
, bAutoStyles
, false,
571 true, pRangePropSet
);
574 inline void XMLTextParagraphExport::exportTextEmbedded(
575 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
577 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
579 exportAnyTextFrame( rTextContent
, FrameType::Embedded
, bAutoStyles
, false,
580 true, pRangePropSet
);
583 inline void XMLTextParagraphExport::exportShape(
584 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
586 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
588 exportAnyTextFrame( rTextContent
, FrameType::Shape
, bAutoStyles
, false,
589 true, pRangePropSet
);
594 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */