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 .
23 * This file implements XMLTextParagraphExport methods to export
26 * - footnote configuration elements
27 * - endnote configuration elements
30 #include <sal/config.h>
31 #include <sal/log.hxx>
33 #include <o3tl/any.hxx>
34 #include <rtl/ustrbuf.hxx>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/frame/XModel.hpp>
38 #include <com/sun/star/text/XText.hpp>
39 #include <com/sun/star/text/XFootnote.hpp>
40 #include <com/sun/star/text/XFootnotesSupplier.hpp>
41 #include <com/sun/star/text/XEndnotesSupplier.hpp>
42 #include <com/sun/star/text/FootnoteNumbering.hpp>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/xmlnamespace.hxx>
45 #include <xmloff/xmluconv.hxx>
46 #include <xmloff/xmlexp.hxx>
47 #include <xmloff/families.hxx>
48 #include "XMLTextCharStyleNamesElementExport.hxx"
49 #include <xmloff/txtparae.hxx>
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::uno
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::beans
;
56 using namespace ::com::sun::star::text
;
57 using namespace ::xmloff::token
;
60 void XMLTextParagraphExport::exportTextFootnote(
61 const Reference
<XPropertySet
> & rPropSet
,
62 const OUString
& rText
,
63 bool bAutoStyles
, bool bIsProgress
)
65 // get footnote and associated text
66 Any aAny
= rPropSet
->getPropertyValue(gsFootnote
);
67 Reference
<XFootnote
> xFootnote
;
69 Reference
<XText
> xText(xFootnote
, UNO_QUERY
);
72 Reference
<XServiceInfo
> xServiceInfo( xFootnote
, UNO_QUERY
);
73 bool bIsEndnote
= xServiceInfo
->supportsService(gsTextEndnoteService
);
77 // handle formatting of citation mark
78 Add( XmlStyleFamily::TEXT_TEXT
, rPropSet
);
80 // handle formatting within footnote
81 exportTextFootnoteHelper(xFootnote
, xText
, rText
,
82 bAutoStyles
, bIsEndnote
, bIsProgress
);
86 // create span (for citation mark) if necessary; footnote content
87 // will be handled via exportTextFootnoteHelper, exportText
88 bool bIsUICharStyle
= false;
89 bool bHasAutoStyle
= false;
91 OUString sStyle
= FindTextStyle( rPropSet
, bIsUICharStyle
, bHasAutoStyle
);
94 XMLTextCharStyleNamesElementExport
aCharStylesExport(
95 GetExport(), bIsUICharStyle
&&
96 m_aCharStyleNamesPropInfoCache
.hasProperty(
97 rPropSet
), bHasAutoStyle
,
98 rPropSet
, gsCharStyleNames
);
99 if( !sStyle
.isEmpty() )
101 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_STYLE_NAME
,
102 GetExport().EncodeStyleName( sStyle
) );
103 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_TEXT
,
104 XML_SPAN
, false, false );
105 exportTextFootnoteHelper(xFootnote
, xText
, rText
,
106 bAutoStyles
, bIsEndnote
, bIsProgress
);
110 exportTextFootnoteHelper(xFootnote
, xText
, rText
,
111 bAutoStyles
, bIsEndnote
, bIsProgress
);
118 void XMLTextParagraphExport::exportTextFootnoteHelper(
119 const Reference
<XFootnote
> & rFootnote
,
120 const Reference
<XText
> & rText
,
121 const OUString
& rTextString
,
128 exportText(rText
, bAutoStyles
, bIsProgress
, true );
132 // export reference Id (for reference fields)
133 Reference
<XPropertySet
> xPropSet(rFootnote
, UNO_QUERY
);
134 Any aAny
= xPropSet
->getPropertyValue(gsReferenceId
);
135 sal_Int32 nNumber
= 0;
137 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_ID
,
138 "ftn" + OUString::number(nNumber
));
139 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_NOTE_CLASS
,
140 GetXMLToken( bIsEndnote
? XML_ENDNOTE
143 SvXMLElementExport
aNote(GetExport(), XML_NAMESPACE_TEXT
,
144 XML_NOTE
, false, false);
146 // handle label vs. automatic numbering
147 OUString sLabel
= rFootnote
->getLabel();
148 if (!sLabel
.isEmpty())
150 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_LABEL
,
153 // else: automatic numbering -> no attribute
155 SvXMLElementExport
aCite(GetExport(), XML_NAMESPACE_TEXT
,
156 XML_NOTE_CITATION
, false, false);
157 GetExport().Characters(rTextString
);
161 SvXMLElementExport
aBody(GetExport(), XML_NAMESPACE_TEXT
,
162 XML_NOTE_BODY
, false, false);
163 exportText(rText
, bAutoStyles
, bIsProgress
, true );
169 void XMLTextParagraphExport::exportTextFootnoteConfiguration()
172 Reference
<XFootnotesSupplier
> aFootnotesSupplier(GetExport().GetModel(),
174 Reference
<XPropertySet
> aFootnoteConfiguration(
175 aFootnotesSupplier
->getFootnoteSettings());
176 exportTextFootnoteConfigurationHelper(aFootnoteConfiguration
, false);
179 Reference
<XEndnotesSupplier
> aEndnotesSupplier(GetExport().GetModel(),
181 Reference
<XPropertySet
> aEndnoteConfiguration(
182 aEndnotesSupplier
->getEndnoteSettings());
183 exportTextFootnoteConfigurationHelper(aEndnoteConfiguration
, true);
187 static void lcl_exportString(
188 SvXMLExport
& rExport
,
189 const Reference
<XPropertySet
> & rPropSet
,
190 const OUString
& sProperty
,
192 enum XMLTokenEnum eElement
,
195 SAL_WARN_IF( eElement
== XML_TOKEN_INVALID
, "xmloff", "need element token");
197 Any aAny
= rPropSet
->getPropertyValue(sProperty
);
203 sTmp
= rExport
.EncodeStyleName( sTmp
);
204 rExport
.AddAttribute(nPrefix
, eElement
, sTmp
);
208 void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
209 const Reference
<XPropertySet
> & rFootnoteConfig
,
212 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_NOTE_CLASS
,
213 GetXMLToken( bIsEndnote
? XML_ENDNOTE
215 // default/paragraph style
216 lcl_exportString( GetExport(), rFootnoteConfig
,
218 XML_NAMESPACE_TEXT
, XML_DEFAULT_STYLE_NAME
,
222 lcl_exportString( GetExport(), rFootnoteConfig
,
224 XML_NAMESPACE_TEXT
, XML_CITATION_STYLE_NAME
,
227 // citation body style
228 lcl_exportString( GetExport(), rFootnoteConfig
,
229 gsAnchorCharStyleName
,
230 XML_NAMESPACE_TEXT
, XML_CITATION_BODY_STYLE_NAME
,
234 lcl_exportString( GetExport(), rFootnoteConfig
,
236 XML_NAMESPACE_TEXT
, XML_MASTER_PAGE_NAME
,
240 lcl_exportString( GetExport(), rFootnoteConfig
, gsPrefix
,
241 XML_NAMESPACE_STYLE
, XML_NUM_PREFIX
, false);
244 lcl_exportString( GetExport(), rFootnoteConfig
, gsSuffix
,
245 XML_NAMESPACE_STYLE
, XML_NUM_SUFFIX
, false);
251 OUStringBuffer sBuffer
;
252 aAny
= rFootnoteConfig
->getPropertyValue(gsNumberingType
);
253 sal_Int16 nNumbering
= 0;
255 GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer
, nNumbering
);
256 GetExport().AddAttribute(XML_NAMESPACE_STYLE
, XML_NUM_FORMAT
,
257 sBuffer
.makeStringAndClear() );
258 SvXMLUnitConverter::convertNumLetterSync( sBuffer
, nNumbering
);
259 if (!sBuffer
.isEmpty() )
261 GetExport().AddAttribute(XML_NAMESPACE_STYLE
, XML_NUM_LETTER_SYNC
,
262 sBuffer
.makeStringAndClear());
265 // StartAt / start-value
266 aAny
= rFootnoteConfig
->getPropertyValue(gsStartAt
);
267 sal_Int16 nOffset
= 0;
269 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_START_VALUE
,
270 OUString::number(nOffset
));
272 // some properties are for footnotes only
275 // footnotes position
276 aAny
= rFootnoteConfig
->getPropertyValue(
278 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_FOOTNOTES_POSITION
,
279 ( (*o3tl::doAccess
<bool>(aAny
)) ?
280 XML_DOCUMENT
: XML_PAGE
) );
282 aAny
= rFootnoteConfig
->getPropertyValue(gsFootnoteCounting
);
285 enum XMLTokenEnum eElement
;
288 case FootnoteNumbering::PER_PAGE
:
291 case FootnoteNumbering::PER_CHAPTER
:
292 eElement
= XML_CHAPTER
;
294 case FootnoteNumbering::PER_DOCUMENT
:
296 eElement
= XML_DOCUMENT
;
299 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
300 XML_START_NUMBERING_AT
, eElement
);
304 SvXMLElementExport
aFootnoteConfigElement(
305 GetExport(), XML_NAMESPACE_TEXT
,
306 XML_NOTES_CONFIGURATION
,
309 // two element for footnote content
315 // end notice / quo vadis
316 aAny
= rFootnoteConfig
->getPropertyValue(gsEndNotice
);
321 SvXMLElementExport
aElem(GetExport(), XML_NAMESPACE_TEXT
,
322 XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
,
324 GetExport().Characters(sTmp
);
327 // begin notice / ergo sum
328 aAny
= rFootnoteConfig
->getPropertyValue(gsBeginNotice
);
333 SvXMLElementExport
aElem(GetExport(), XML_NAMESPACE_TEXT
,
334 XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
,
336 GetExport().Characters(sTmp
);
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */