Update git submodules
[LibreOffice.git] / xmloff / source / text / txtftne.cxx
blob9646fa2e2ad74bb9c3dc0c99cf1c2fc88ad55a2b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 /** @#file
23 * This file implements XMLTextParagraphExport methods to export
24 * - footnotes
25 * - endnotes
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;
68 aAny >>= xFootnote;
69 Reference<XText> xText(xFootnote, UNO_QUERY);
71 // are we an endnote?
72 Reference<XServiceInfo> xServiceInfo( xFootnote, UNO_QUERY );
73 bool bIsEndnote = xServiceInfo->supportsService(gsTextEndnoteService);
75 if (bAutoStyles)
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 );
84 else
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 );
108 else
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,
122 bool bAutoStyles,
123 bool bIsEndnote,
124 bool bIsProgress )
126 if (bAutoStyles)
128 exportText(rText, bAutoStyles, bIsProgress, true );
130 else
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;
136 aAny >>= nNumber;
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
141 : XML_FOOTNOTE ) );
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,
151 sLabel);
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()
171 // footnote settings
172 Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(),
173 UNO_QUERY);
174 Reference<XPropertySet> aFootnoteConfiguration(
175 aFootnotesSupplier->getFootnoteSettings());
176 exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, false);
178 // endnote settings
179 Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(),
180 UNO_QUERY);
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,
191 sal_uInt16 nPrefix,
192 enum XMLTokenEnum eElement,
193 bool bEncodeName)
195 SAL_WARN_IF( eElement == XML_TOKEN_INVALID, "xmloff", "need element token");
197 Any aAny = rPropSet->getPropertyValue(sProperty);
198 OUString sTmp;
199 aAny >>= sTmp;
200 if (!sTmp.isEmpty())
202 if( bEncodeName )
203 sTmp = rExport.EncodeStyleName( sTmp );
204 rExport.AddAttribute(nPrefix, eElement, sTmp);
208 void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
209 const Reference<XPropertySet> & rFootnoteConfig,
210 bool bIsEndnote)
212 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
213 GetXMLToken( bIsEndnote ? XML_ENDNOTE
214 : XML_FOOTNOTE ) );
215 // default/paragraph style
216 lcl_exportString( GetExport(), rFootnoteConfig,
217 gsParaStyleName,
218 XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME,
219 true);
221 // citation style
222 lcl_exportString( GetExport(), rFootnoteConfig,
223 gsCharStyleName,
224 XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME,
225 true);
227 // citation body style
228 lcl_exportString( GetExport(), rFootnoteConfig,
229 gsAnchorCharStyleName,
230 XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME,
231 true);
233 // page style
234 lcl_exportString( GetExport(), rFootnoteConfig,
235 gsPageStyleName,
236 XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME,
237 true );
239 // prefix
240 lcl_exportString( GetExport(), rFootnoteConfig, gsPrefix,
241 XML_NAMESPACE_STYLE, XML_NUM_PREFIX, false);
243 // suffix
244 lcl_exportString( GetExport(), rFootnoteConfig, gsSuffix,
245 XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, false);
248 Any aAny;
250 // numbering style
251 OUStringBuffer sBuffer;
252 aAny = rFootnoteConfig->getPropertyValue(gsNumberingType);
253 sal_Int16 nNumbering = 0;
254 aAny >>= nNumbering;
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;
268 aAny >>= nOffset;
269 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
270 OUString::number(nOffset));
272 // some properties are for footnotes only
273 if (!bIsEndnote)
275 // footnotes position
276 aAny = rFootnoteConfig->getPropertyValue(
277 gsPositionEndOfDoc);
278 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION,
279 ( (*o3tl::doAccess<bool>(aAny)) ?
280 XML_DOCUMENT : XML_PAGE ) );
282 aAny = rFootnoteConfig->getPropertyValue(gsFootnoteCounting);
283 sal_Int16 nTmp = 0;
284 aAny >>= nTmp;
285 enum XMLTokenEnum eElement;
286 switch (nTmp)
288 case FootnoteNumbering::PER_PAGE:
289 eElement = XML_PAGE;
290 break;
291 case FootnoteNumbering::PER_CHAPTER:
292 eElement = XML_CHAPTER;
293 break;
294 case FootnoteNumbering::PER_DOCUMENT:
295 default:
296 eElement = XML_DOCUMENT;
297 break;
299 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
300 XML_START_NUMBERING_AT, eElement);
303 // element
304 SvXMLElementExport aFootnoteConfigElement(
305 GetExport(), XML_NAMESPACE_TEXT,
306 XML_NOTES_CONFIGURATION,
307 true, true);
309 // two element for footnote content
310 if (bIsEndnote)
311 return;
313 OUString sTmp;
315 // end notice / quo vadis
316 aAny = rFootnoteConfig->getPropertyValue(gsEndNotice);
317 aAny >>= sTmp;
319 if (!sTmp.isEmpty())
321 SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
322 XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD,
323 true, false);
324 GetExport().Characters(sTmp);
327 // begin notice / ergo sum
328 aAny = rFootnoteConfig->getPropertyValue(gsBeginNotice);
329 aAny >>= sTmp;
331 if (!sTmp.isEmpty())
333 SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
334 XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD,
335 true, false);
336 GetExport().Characters(sTmp);
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */