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/styleexp.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/SinglePropertySetInfoCache.hxx>
31 #include <xmloff/XMLTextListAutoStylePool.hxx>
32 #include <o3tl/span.hxx>
36 class XMLTextListsHelper
;
38 class SvXMLAutoStylePoolP
;
39 class XMLTextFieldExport
;
40 class XMLTextNumRuleInfo
;
41 class XMLSectionExport
;
42 class XMLIndexMarkExport
;
43 class XMLRedlineExport
;
44 struct XMLPropertyState
;
45 class MultiPropertySetHelper
;
46 enum class XMLShapeExportFlags
;
47 class SvXMLExportPropertyMapper
;
49 namespace com::sun::star
51 namespace beans
{ class XPropertySet
; class XPropertyState
;
52 class XPropertySetInfo
; }
53 namespace container
{ class XEnumeration
; class XIndexAccess
; }
54 namespace text
{ class XTextContent
; class XTextRange
; class XText
;
55 class XFootnote
; class XTextFrame
; class XTextSection
;
61 class OFormLayerXMLExport
;
77 class XMLOFF_DLLPUBLIC XMLTextParagraphExport
: public XMLStyleExport
80 std::unique_ptr
<Impl
> m_xImpl
;
82 // SvXMLExport& rExport;
83 SvXMLAutoStylePoolP
& rAutoStylePool
;
84 rtl::Reference
< SvXMLExportPropertyMapper
> xParaPropMapper
;
85 rtl::Reference
< SvXMLExportPropertyMapper
> xTextPropMapper
;
86 rtl::Reference
< SvXMLExportPropertyMapper
> xFramePropMapper
;
87 rtl::Reference
< SvXMLExportPropertyMapper
> xAutoFramePropMapper
;
88 rtl::Reference
< SvXMLExportPropertyMapper
> xSectionPropMapper
;
89 rtl::Reference
< SvXMLExportPropertyMapper
> xRubyPropMapper
;
91 const ::std::unique_ptr
< ::xmloff::BoundFrameSets
> pBoundFrameSets
;
92 std::unique_ptr
<XMLTextFieldExport
> pFieldExport
;
93 std::vector
<OUString
> maListElements
;
94 XMLTextListAutoStylePool maListAutoPool
;
95 std::unique_ptr
<XMLSectionExport
> pSectionExport
;
96 std::unique_ptr
<XMLIndexMarkExport
> pIndexMarkExport
;
98 /// may be NULL (if no redlines should be exported; e.g. in block mode)
99 std::unique_ptr
<XMLRedlineExport
> pRedlineExport
;
105 // keep track of open rubies
106 OUString sOpenRubyText
;
107 OUString sOpenRubyCharStyle
;
110 XMLTextListsHelper
* mpTextListsHelper
;
111 ::std::vector
< std::unique_ptr
<XMLTextListsHelper
> > maTextListsHelperStack
;
115 enum class FrameType
{ Text
, Graphic
, Embedded
, Shape
};
118 enum FieldmarkType
{ NONE
, TEXT
, CHECK
}; // Used for simulating fieldmarks in OpenDocument 1.n Strict (for n <= 2). CHECK currently ignored.
121 void exportTextRangeSpan(
122 const css::uno::Reference
< css::text::XTextRange
> & rTextRange
,
123 css::uno::Reference
< css::beans::XPropertySet
> const & xPropSet
,
124 css::uno::Reference
< css::beans::XPropertySetInfo
> & xPropSetInfo
,
125 const bool bIsUICharStyle
,
126 const bool bHasAutoStyle
,
127 const OUString
& sStyle
,
128 bool& rPrevCharIsSpace
,
129 FieldmarkType
& openFieldMark
);
133 // Implement Title/Description Elements UI (#i73249#)
134 static constexpr OUStringLiteral gsAnchorCharStyleName
= u
"AnchorCharStyleName";
135 static constexpr OUStringLiteral gsBeginNotice
= u
"BeginNotice";
136 static constexpr OUStringLiteral gsCategory
= u
"Category";
137 static constexpr OUStringLiteral gsCharStyleName
= u
"CharStyleName";
138 static constexpr OUStringLiteral gsCharStyleNames
= u
"CharStyleNames";
139 static constexpr OUStringLiteral gsEndNotice
= u
"EndNotice";
140 static constexpr OUStringLiteral gsFootnote
= u
"Footnote";
141 static constexpr OUStringLiteral gsFootnoteCounting
= u
"FootnoteCounting";
142 static constexpr OUStringLiteral gsNumberingType
= u
"NumberingType";
143 static constexpr OUStringLiteral gsPageDescName
= u
"PageDescName";
144 static constexpr OUStringLiteral gsPageStyleName
= u
"PageStyleName";
145 static constexpr OUStringLiteral gsParaStyleName
= u
"ParaStyleName";
146 static constexpr OUStringLiteral gsPositionEndOfDoc
= u
"PositionEndOfDoc";
147 static constexpr OUStringLiteral gsPrefix
= u
"Prefix";
148 static constexpr OUStringLiteral gsReferenceId
= u
"ReferenceId";
149 static constexpr OUStringLiteral gsStartAt
= u
"StartAt";
150 static constexpr OUStringLiteral gsSuffix
= u
"Suffix";
151 static constexpr OUStringLiteral gsTextEndnoteService
= u
"com.sun.star.text.Endnote";
152 static constexpr OUStringLiteral gsTextSection
= u
"TextSection";
155 static constexpr OUStringLiteral gsFrameStyleName
= u
"FrameStyleName";
156 SinglePropertySetInfoCache aCharStyleNamesPropInfoCache
;
158 SvXMLAutoStylePoolP
& GetAutoStylePool() { return rAutoStylePool
; }
159 const SvXMLAutoStylePoolP
& GetAutoStylePool() const { return rAutoStylePool
; }
162 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetParaPropMapper() const
164 return xParaPropMapper
;
167 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetTextPropMapper() const
169 return xTextPropMapper
;
172 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetAutoFramePropMapper() const
174 return xAutoFramePropMapper
;
176 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetSectionPropMapper() const
178 return xSectionPropMapper
;
180 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetRubyPropMapper() const
182 return xRubyPropMapper
;
185 OUString
FindTextStyleAndHyperlink(
186 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
188 bool& rbHasCharStyle
,
189 bool& rbHasAutoStyle
,
190 const XMLPropertyState
** pAddState
= nullptr) const;
191 bool addHyperlinkAttributes(
192 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
193 const css::uno::Reference
< css::beans::XPropertyState
> & rPropState
,
194 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
196 void exportTextRangeEnumeration(
197 const css::uno::Reference
< css::container::XEnumeration
> & rRangeEnum
,
198 bool bAutoStyles
, bool bProgress
, bool & rPrevCharIsSpace
);
202 XMLShapeExportFlags
addTextFrameAttributes(
203 const css::uno::Reference
< css::beans::XPropertySet
>& rPropSet
,
205 basegfx::B2DPoint
* pCenter
= nullptr,
206 OUString
*pMinHeightValue
= nullptr,
207 OUString
*pMinWidthValue
= nullptr );
209 virtual void exportStyleAttributes(
210 const css::uno::Reference
< css::style::XStyle
> & rStyle
) override
;
212 void exportPageFrames( bool bProgress
);
213 void exportFrameFrames( bool bAutoStyles
, bool bProgress
,
214 const css::uno::Reference
< css::text::XTextFrame
> *pParentTxtFrame
);
216 void exportNumStyles( bool bUsed
);
219 const css::uno::Reference
<
220 css::text::XText
> & rText
,
221 bool bAutoStyles
, bool bProgress
, bool bExportParagraph
, TextPNS eExtensionNS
= TextPNS::ODF
);
224 const css::uno::Reference
< css::text::XText
> & rText
,
225 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
226 bool bAutoStyles
, bool bProgress
, bool bExportParagraph
);
228 void exportTextContentEnumeration(
229 const css::uno::Reference
< css::container::XEnumeration
> & rContentEnum
,
231 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
233 bool bExportParagraph
= true,
234 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr,
235 TextPNS eExtensionNS
= TextPNS::ODF
);
236 void exportParagraph(
237 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
238 bool bAutoStyles
, bool bProgress
,
239 bool bExportParagraph
,
240 MultiPropertySetHelper
& rPropSetHelper
,
241 TextPNS eExtensionNS
);
243 virtual void exportTable(
244 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
245 bool bAutoStyles
, bool bProgress
);
247 void exportTextField(
248 const css::uno::Reference
< css::text::XTextRange
> & rTextRange
,
249 bool bAutoStyles
, bool bProgress
, bool * pPrevCharIsSpace
);
251 void exportTextField(
252 const css::uno::Reference
< css::text::XTextField
> & xTextField
,
253 const bool bAutoStyles
, const bool bProgress
,
254 const bool bRecursive
, bool * pPrevCharIsSpace
);
256 void exportAnyTextFrame(
257 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
259 bool bAutoStyles
, bool bProgress
, bool bExportContent
,
260 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
);
261 void _exportTextFrame(
262 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
263 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
,
265 inline void exportTextFrame(
266 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
267 bool bAutoStyles
, bool bProgress
, bool bExportContent
,
268 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
269 inline void exportShape(
270 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
272 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
275 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
276 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
277 void _exportTextGraphic(
278 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
279 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
280 inline void exportTextGraphic(
281 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
283 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
285 virtual void _collectTextEmbeddedAutoStyles(
286 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
);
287 virtual void _exportTextEmbedded(
288 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
289 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
290 inline void exportTextEmbedded(
291 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
293 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
= nullptr );
295 /// export a footnote and styles
296 void exportTextFootnote(
297 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
298 const OUString
& sString
,
299 bool bAutoStyles
, bool bProgress
);
301 /// helper for exportTextFootnote
302 void exportTextFootnoteHelper(
303 const css::uno::Reference
< css::text::XFootnote
> & rPropSet
,
304 const css::uno::Reference
< css::text::XText
> & rText
,
305 const OUString
& sString
,
307 bool bIsEndnote
, bool bProgress
);
309 /// export footnote and endnote configuration elements
310 void exportTextFootnoteConfiguration();
312 void exportTextFootnoteConfigurationHelper(
313 const css::uno::Reference
< css::beans::XPropertySet
> & rFootnoteSupplier
,
317 const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
,
318 const OUString
& rProperty
,
319 const enum ::xmloff::token::XMLTokenEnum pElements
[],
322 void exportSoftPageBreak();
324 void exportTextRange(
325 const css::uno::Reference
< css::text::XTextRange
> & rTextRange
,
327 bool& rPrevCharWasSpace
,
328 FieldmarkType
& openFieldmarkType
);
330 void exportListChange( const XMLTextNumRuleInfo
& rPrvInfo
,
331 const XMLTextNumRuleInfo
& rNextInfo
);
333 /// check if current section or current list has changed;
334 /// calls exportListChange as appropriate
335 void exportListAndSectionChange(
336 css::uno::Reference
< css::text::XTextSection
> & rOldSection
,
337 const css::uno::Reference
< css::text::XTextSection
> & rNewSection
,
338 const XMLTextNumRuleInfo
& rOldList
,
339 const XMLTextNumRuleInfo
& rNewList
,
342 /// overload for exportListAndSectionChange;
343 /// takes new content rather than new section.
344 void exportListAndSectionChange(
345 css::uno::Reference
< css::text::XTextSection
> & rOldSection
,
346 const css::uno::Reference
< css::text::XTextContent
> & rNewContent
,
347 const XMLTextNumRuleInfo
& rOldList
,
348 const XMLTextNumRuleInfo
& rNewList
,
350 void exportListAndSectionChange(
351 css::uno::Reference
< css::text::XTextSection
> & rOldSection
,
352 MultiPropertySetHelper
& rPropSetHelper
,
353 sal_Int16 nTextSectionId
,
354 const css::uno::Reference
< css::text::XTextContent
> & rNewContent
,
355 const XMLTextNumRuleInfo
& rOldList
,
356 const XMLTextNumRuleInfo
& rNewList
,
361 const css::uno::Reference
< css::beans::XPropertySet
> & rPortionPropSet
,
364 /// export a text:meta
366 const css::uno::Reference
< css::beans::XPropertySet
> & i_xPortion
,
367 bool i_bAutoStyles
, bool i_isProgress
, bool & rPrevCharIsSpace
);
369 bool isAutoStylesCollected() const { return mbCollected
; }
371 virtual void exportTableAutoStyles();
375 XMLTextParagraphExport(
377 SvXMLAutoStylePoolP
& rASP
379 virtual ~XMLTextParagraphExport() override
;
381 /// add autostyle for specified family
383 XmlStyleFamily nFamily
,
384 MultiPropertySetHelper
& rPropSetHelper
,
385 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
);
387 XmlStyleFamily nFamily
,
388 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
389 const o3tl::span
<XMLPropertyState
> aAddStates
= {}, bool bDontSeek
= false );
391 /// find style name for specified family and parent
393 XmlStyleFamily nFamily
,
394 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
395 const OUString
& rParent
,
396 const o3tl::span
<XMLPropertyState
> aAddStates
= {} ) const;
398 static SvXMLExportPropertyMapper
*CreateShapeExtPropMapper(
399 SvXMLExport
& rExport
);
400 static SvXMLExportPropertyMapper
*CreateCharExtPropMapper(
401 SvXMLExport
& rExport
);
402 static SvXMLExportPropertyMapper
*CreateParaExtPropMapper(
403 SvXMLExport
& rExport
);
404 static SvXMLExportPropertyMapper
*CreateParaDefaultExtPropMapper(
405 SvXMLExport
& rExport
);
407 // This methods exports all (or all used) styles
408 void exportTextStyles( bool bUsed
, bool bProg
);
410 /// This method exports (text field) declarations etc.
411 void exportTextDeclarations();
413 /// export the (text field) declarations for a particular XText
414 void exportTextDeclarations(
415 const css::uno::Reference
< css::text::XText
> & rText
);
417 /// export all declarations
418 void exportUsedDeclarations();
420 /// Export the list of change information (enclosed by <tracked-changes>)
421 /// (or the necessary automatic styles)
422 void exportTrackedChanges(bool bAutoStyle
);
424 /// Export the list of change information (enclosed by <tracked-changes>)
425 /// (or the necessary automatic styles)
426 void exportTrackedChanges(const css::uno::Reference
< css::text::XText
> & rText
,
429 /// Record tracked changes for this particular XText
430 /// (empty reference stop recording)
431 /// This should be used if tracked changes for e.g. footers are to
432 /// be exported separately via the exportTrackedChanges(bool,
433 /// Reference<XText>) method.
434 void recordTrackedChangesForXText(
435 const css::uno::Reference
< css::text::XText
> & rText
);
438 /// Stop recording tracked changes.
439 /// This is the same as calling recordTrackedChanges(...) with an
441 void recordTrackedChangesNoXText();
444 // This method exports the given OUString
445 void exportCharacterData(
446 const OUString
& rText
,
447 bool& rPrevCharWasSpace
);
449 // This method collects all automatic styles for the given XText
450 void collectTextAutoStyles(
451 const css::uno::Reference
< css::text::XText
> & rText
,
452 bool bIsProgress
= false,
453 bool bExportParagraph
= true )
455 exportText( rText
, true, bIsProgress
, bExportParagraph
);
458 void collectTextAutoStyles(
459 const css::uno::Reference
< css::text::XText
> & rText
,
460 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
463 exportText( rText
, rBaseSection
, true, bIsProgress
, true/*bExportParagraph*/ );
466 // It the model implements the xAutoStylesSupplier interface, the automatic
467 // styles can exported without iterating over the text portions
468 void collectTextAutoStylesOptimized( bool bIsProgress
);
470 // This method exports all automatic styles that have been collected.
471 void exportTextAutoStyles();
473 void exportEvents( const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
);
475 // Implement Title/Description Elements UI (#i73249#)
476 void exportTitleAndDescription( const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
477 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropSetInfo
);
479 // This method exports the given XText
481 const css::uno::Reference
< css::text::XText
> & rText
,
482 bool bIsProgress
= false,
483 bool bExportParagraph
= true, TextPNS eExtensionNS
= TextPNS::ODF
)
485 exportText( rText
, false, bIsProgress
, bExportParagraph
, eExtensionNS
);
489 const css::uno::Reference
< css::text::XText
> & rText
,
490 const css::uno::Reference
< css::text::XTextSection
> & rBaseSection
,
493 exportText( rText
, rBaseSection
, false, bIsProgress
, true/*bExportParagraph*/ );
496 void exportFramesBoundToPage( bool bIsProgress
)
498 exportPageFrames( bIsProgress
);
500 inline const XMLTextListAutoStylePool
& GetListAutoStylePool() const;
502 void SetBlockMode( bool bSet
) { bBlock
= bSet
; }
503 bool IsBlockMode() const { return bBlock
; }
506 const rtl::Reference
< SvXMLExportPropertyMapper
>& GetParagraphPropertyMapper() const
508 return xParaPropMapper
;
512 /** exclude form controls which are in mute sections.
514 * This method is necessary to prevent the form layer export from exporting
515 * control models whose controls are not represented in the document. To
516 * achieve this, this method iterates over all shapes, checks to see if
517 * they are control shapes, and if so, whether they should be exported or
518 * not. If not, the form layer export will be notified accordingly.
520 * The reason this method is located here is that it needs to access the
521 * XMLSectionExport, which is only available here.
523 void PreventExportOfControlsInMuteSections(
524 const css::uno::Reference
< css::container::XIndexAccess
> & rShapes
,
525 const rtl::Reference
<xmloff::OFormLayerXMLExport
>& xFormExport
);
527 SinglePropertySetInfoCache
& GetCharStyleNamesPropInfoCache() { return aCharStyleNamesPropInfoCache
; }
529 void PushNewTextListsHelper();
531 void PopTextListsHelper();
534 XMLTextParagraphExport(XMLTextParagraphExport
const &) = delete;
537 inline const XMLTextListAutoStylePool
&
538 XMLTextParagraphExport::GetListAutoStylePool() const
540 return maListAutoPool
;
543 inline void XMLTextParagraphExport::exportTextFrame(
544 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
545 bool bAutoStyles
, bool bIsProgress
, bool bExportContent
,
546 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
548 exportAnyTextFrame( rTextContent
, FrameType::Text
, bAutoStyles
, bIsProgress
,
549 bExportContent
, pRangePropSet
);
552 inline void XMLTextParagraphExport::exportTextGraphic(
553 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
555 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
557 exportAnyTextFrame( rTextContent
, FrameType::Graphic
, bAutoStyles
, false,
558 true, pRangePropSet
);
561 inline void XMLTextParagraphExport::exportTextEmbedded(
562 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
564 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
566 exportAnyTextFrame( rTextContent
, FrameType::Embedded
, bAutoStyles
, false,
567 true, pRangePropSet
);
570 inline void XMLTextParagraphExport::exportShape(
571 const css::uno::Reference
< css::text::XTextContent
> & rTextContent
,
573 const css::uno::Reference
< css::beans::XPropertySet
> *pRangePropSet
)
575 exportAnyTextFrame( rTextContent
, FrameType::Shape
, bAutoStyles
, false,
576 true, pRangePropSet
);
581 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */