LibreOffice Module xmloff (master) 1
txtftne.cxx
Go to the documentation of this file.
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
20
30#include <sal/config.h>
31#include <sal/log.hxx>
32
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/beans/XPropertyState.hpp>
38#include <com/sun/star/text/XTextDocument.hpp>
39#include <com/sun/star/text/XText.hpp>
40#include <com/sun/star/text/XFootnote.hpp>
41#include <com/sun/star/text/XFootnotesSupplier.hpp>
42#include <com/sun/star/text/XEndnotesSupplier.hpp>
43#include <com/sun/star/text/FootnoteNumbering.hpp>
44#include <com/sun/star/container/XNameReplace.hpp>
45#include <xmloff/xmltoken.hxx>
47#include <xmloff/xmluconv.hxx>
48#include <xmloff/xmlexp.hxx>
49#include <xmloff/families.hxx>
52#include <xmloff/txtparae.hxx>
53
54
55using namespace ::com::sun::star;
56using namespace ::com::sun::star::uno;
57using namespace ::com::sun::star::lang;
58using namespace ::com::sun::star::beans;
59using namespace ::com::sun::star::text;
60using namespace ::com::sun::star::container;
61using namespace ::xmloff::token;
62
63
65 const Reference<XPropertySet> & rPropSet,
66 const OUString& rText,
67 bool bAutoStyles, bool bIsProgress )
68{
69 // get footnote and associated text
70 Any aAny = rPropSet->getPropertyValue(gsFootnote);
71 Reference<XFootnote> xFootnote;
72 aAny >>= xFootnote;
73 Reference<XText> xText(xFootnote, UNO_QUERY);
74
75 // are we an endnote?
76 Reference<XServiceInfo> xServiceInfo( xFootnote, UNO_QUERY );
77 bool bIsEndnote = xServiceInfo->supportsService(gsTextEndnoteService);
78
79 if (bAutoStyles)
80 {
81 // handle formatting of citation mark
82 Add( XmlStyleFamily::TEXT_TEXT, rPropSet );
83
84 // handle formatting within footnote
85 exportTextFootnoteHelper(xFootnote, xText, rText,
86 bAutoStyles, bIsEndnote, bIsProgress );
87 }
88 else
89 {
90 // create span (for citation mark) if necessary; footnote content
91 // will be handled via exportTextFootnoteHelper, exportText
92 bool bIsUICharStyle = false;
93 bool bHasAutoStyle = false;
94
95 OUString sStyle = FindTextStyle( rPropSet, bIsUICharStyle, bHasAutoStyle );
96
97 {
98 XMLTextCharStyleNamesElementExport aCharStylesExport(
99 GetExport(), bIsUICharStyle &&
101 rPropSet ), bHasAutoStyle,
102 rPropSet, gsCharStyleNames );
103 if( !sStyle.isEmpty() )
104 {
106 GetExport().EncodeStyleName( sStyle ) );
108 XML_SPAN, false, false );
109 exportTextFootnoteHelper(xFootnote, xText, rText,
110 bAutoStyles, bIsEndnote, bIsProgress );
111 }
112 else
113 {
114 exportTextFootnoteHelper(xFootnote, xText, rText,
115 bAutoStyles, bIsEndnote, bIsProgress );
116 }
117 }
118 }
119}
120
121
123 const Reference<XFootnote> & rFootnote,
124 const Reference<XText> & rText,
125 const OUString& rTextString,
126 bool bAutoStyles,
127 bool bIsEndnote,
128 bool bIsProgress )
129{
130 if (bAutoStyles)
131 {
132 exportText(rText, bAutoStyles, bIsProgress, true );
133 }
134 else
135 {
136 // export reference Id (for reference fields)
137 Reference<XPropertySet> xPropSet(rFootnote, UNO_QUERY);
138 Any aAny = xPropSet->getPropertyValue(gsReferenceId);
139 sal_Int32 nNumber = 0;
140 aAny >>= nNumber;
142 "ftn" + OUString::number(nNumber));
144 GetXMLToken( bIsEndnote ? XML_ENDNOTE
145 : XML_FOOTNOTE ) );
146
148 XML_NOTE, false, false);
149 {
150 // handle label vs. automatic numbering
151 OUString sLabel = rFootnote->getLabel();
152 if (!sLabel.isEmpty())
153 {
155 sLabel);
156 }
157 // else: automatic numbering -> no attribute
158
160 XML_NOTE_CITATION, false, false);
161 GetExport().Characters(rTextString);
162 }
163
164 {
166 XML_NOTE_BODY, false, false);
167 exportText(rText, bAutoStyles, bIsProgress, true );
168 }
169 }
170}
171
172
174{
175 // footnote settings
176 Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(),
177 UNO_QUERY);
178 Reference<XPropertySet> aFootnoteConfiguration(
179 aFootnotesSupplier->getFootnoteSettings());
180 exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, false);
181
182 // endnote settings
183 Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(),
184 UNO_QUERY);
185 Reference<XPropertySet> aEndnoteConfiguration(
186 aEndnotesSupplier->getEndnoteSettings());
187 exportTextFootnoteConfigurationHelper(aEndnoteConfiguration, true);
188}
189
190
192 SvXMLExport& rExport,
193 const Reference<XPropertySet> & rPropSet,
194 const OUString& sProperty,
195 sal_uInt16 nPrefix,
196 enum XMLTokenEnum eElement,
197 bool bEncodeName)
198{
199 SAL_WARN_IF( eElement == XML_TOKEN_INVALID, "xmloff", "need element token");
200
201 Any aAny = rPropSet->getPropertyValue(sProperty);
202 OUString sTmp;
203 aAny >>= sTmp;
204 if (!sTmp.isEmpty())
205 {
206 if( bEncodeName )
207 sTmp = rExport.EncodeStyleName( sTmp );
208 rExport.AddAttribute(nPrefix, eElement, sTmp);
209 }
210}
211
213 const Reference<XPropertySet> & rFootnoteConfig,
214 bool bIsEndnote)
215{
217 GetXMLToken( bIsEndnote ? XML_ENDNOTE
218 : XML_FOOTNOTE ) );
219 // default/paragraph style
220 lcl_exportString( GetExport(), rFootnoteConfig,
223 true);
224
225 // citation style
226 lcl_exportString( GetExport(), rFootnoteConfig,
229 true);
230
231 // citation body style
232 lcl_exportString( GetExport(), rFootnoteConfig,
235 true);
236
237 // page style
238 lcl_exportString( GetExport(), rFootnoteConfig,
241 true );
242
243 // prefix
244 lcl_exportString( GetExport(), rFootnoteConfig, gsPrefix,
246
247 // suffix
248 lcl_exportString( GetExport(), rFootnoteConfig, gsSuffix,
250
251
252 Any aAny;
253
254 // numbering style
255 OUStringBuffer sBuffer;
256 aAny = rFootnoteConfig->getPropertyValue(gsNumberingType);
257 sal_Int16 nNumbering = 0;
258 aAny >>= nNumbering;
259 GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer, nNumbering);
261 sBuffer.makeStringAndClear() );
262 SvXMLUnitConverter::convertNumLetterSync( sBuffer, nNumbering);
263 if (!sBuffer.isEmpty() )
264 {
266 sBuffer.makeStringAndClear());
267 }
268
269 // StartAt / start-value
270 aAny = rFootnoteConfig->getPropertyValue(gsStartAt);
271 sal_Int16 nOffset = 0;
272 aAny >>= nOffset;
274 OUString::number(nOffset));
275
276 // some properties are for footnotes only
277 if (!bIsEndnote)
278 {
279 // footnotes position
280 aAny = rFootnoteConfig->getPropertyValue(
283 ( (*o3tl::doAccess<bool>(aAny)) ?
285
286 aAny = rFootnoteConfig->getPropertyValue(gsFootnoteCounting);
287 sal_Int16 nTmp = 0;
288 aAny >>= nTmp;
289 enum XMLTokenEnum eElement;
290 switch (nTmp)
291 {
292 case FootnoteNumbering::PER_PAGE:
293 eElement = XML_PAGE;
294 break;
295 case FootnoteNumbering::PER_CHAPTER:
296 eElement = XML_CHAPTER;
297 break;
298 case FootnoteNumbering::PER_DOCUMENT:
299 default:
300 eElement = XML_DOCUMENT;
301 break;
302 }
304 XML_START_NUMBERING_AT, eElement);
305 }
306
307 // element
308 SvXMLElementExport aFootnoteConfigElement(
311 true, true);
312
313 // two element for footnote content
314 if (bIsEndnote)
315 return;
316
317 OUString sTmp;
318
319 // end notice / quo vadis
320 aAny = rFootnoteConfig->getPropertyValue(gsEndNotice);
321 aAny >>= sTmp;
322
323 if (!sTmp.isEmpty())
324 {
327 true, false);
328 GetExport().Characters(sTmp);
329 }
330
331 // begin notice / ergo sum
332 aAny = rFootnoteConfig->getPropertyValue(gsBeginNotice);
333 aAny >>= sTmp;
334
335 if (!sTmp.isEmpty())
336 {
339 true, false);
340 GetExport().Characters(sTmp);
341 }
342}
343
344/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool hasProperty(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, css::uno::Reference< css::beans::XPropertySetInfo > &rPropSetInfo)
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:911
void Characters(const OUString &rChars)
Definition: xmlexp.cxx:2133
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmlexp.cxx:1938
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:396
bool convertNumFormat(sal_Int16 &rType, const OUString &rNumFormat, std::u16string_view rNumLetterSync, bool bNumberNone=false) const
convert num-format and num-letter-sync values to NumberingType
Definition: xmluconv.cxx:654
static void convertNumLetterSync(OUStringBuffer &rBuffer, sal_Int16 nType)
Definition: xmluconv.cxx:751
SvXMLExport & GetExport()
Definition: styleexp.hxx:59
static constexpr OUStringLiteral gsParaStyleName
Definition: txtparae.hxx:145
SinglePropertySetInfoCache aCharStyleNamesPropInfoCache
Definition: txtparae.hxx:156
static constexpr OUStringLiteral gsCharStyleNames
Definition: txtparae.hxx:138
static constexpr OUStringLiteral gsPrefix
Definition: txtparae.hxx:147
void exportTextFootnoteConfiguration()
export footnote and endnote configuration elements
Definition: txtftne.cxx:173
static constexpr OUStringLiteral gsReferenceId
Definition: txtparae.hxx:148
static constexpr OUStringLiteral gsSuffix
Definition: txtparae.hxx:150
static constexpr OUStringLiteral gsStartAt
Definition: txtparae.hxx:149
static constexpr OUStringLiteral gsBeginNotice
Definition: txtparae.hxx:135
static constexpr OUStringLiteral gsNumberingType
Definition: txtparae.hxx:142
static constexpr OUStringLiteral gsPageStyleName
Definition: txtparae.hxx:144
static constexpr OUStringLiteral gsFootnote
Definition: txtparae.hxx:140
static constexpr OUStringLiteral gsPositionEndOfDoc
Definition: txtparae.hxx:146
static constexpr OUStringLiteral gsFootnoteCounting
Definition: txtparae.hxx:141
OUString FindTextStyle(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool &rbHasCharStyle, bool &rbHasAutoStyle, const XMLPropertyState **pAddState=nullptr) const
Definition: txtparae.cxx:914
static constexpr OUStringLiteral gsCharStyleName
Definition: txtparae.hxx:137
void exportTextFootnoteConfigurationHelper(const css::uno::Reference< css::beans::XPropertySet > &rFootnoteSupplier, bool bIsEndnote)
Definition: txtftne.cxx:212
void exportTextFootnote(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, const OUString &sString, bool bAutoStyles, bool bProgress)
export a footnote and styles
Definition: txtftne.cxx:64
static constexpr OUStringLiteral gsEndNotice
Definition: txtparae.hxx:139
static constexpr OUStringLiteral gsTextEndnoteService
Definition: txtparae.hxx:151
static constexpr OUStringLiteral gsAnchorCharStyleName
Definition: txtparae.hxx:134
void Add(XmlStyleFamily nFamily, MultiPropertySetHelper &rPropSetHelper, const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
add autostyle for specified family
void exportTextFootnoteHelper(const css::uno::Reference< css::text::XFootnote > &rPropSet, const css::uno::Reference< css::text::XText > &rText, const OUString &sString, bool bAutoStyles, bool bIsEndnote, bool bProgress)
helper for exportTextFootnote
Definition: txtftne.cxx:122
void exportText(const css::uno::Reference< css::text::XText > &rText, bool bAutoStyles, bool bProgress, bool bExportParagraph, TextPNS eExtensionNS=TextPNS::ODF)
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
@ XML_DEFAULT_STYLE_NAME
Definition: xmltoken.hxx:652
@ XML_CITATION_BODY_STYLE_NAME
Definition: xmltoken.hxx:438
@ XML_START_NUMBERING_AT
Definition: xmltoken.hxx:1836
@ XML_NOTES_CONFIGURATION
Definition: xmltoken.hxx:2617
@ XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
Definition: xmltoken.hxx:918
@ XML_FOOTNOTES_POSITION
Definition: xmltoken.hxx:923
@ XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
Definition: xmltoken.hxx:917
@ XML_CITATION_STYLE_NAME
Definition: xmltoken.hxx:439
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3527
static void lcl_exportString(SvXMLExport &rExport, const Reference< XPropertySet > &rPropSet, const OUString &sProperty, sal_uInt16 nPrefix, enum XMLTokenEnum eElement, bool bEncodeName)
Definition: txtftne.cxx:191
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_STYLE