LibreOffice Module xmloff (master) 1
XMLPageExport.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
21#include <o3tl/any.hxx>
22#include <sal/log.hxx>
24#include <xmloff/xmltoken.hxx>
25#include <com/sun/star/frame/XModel.hpp>
26#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
27#include <com/sun/star/style/XStyle.hpp>
28#include <com/sun/star/beans/XPropertySet.hpp>
29#include <com/sun/star/lang/XMultiServiceFactory.hpp>
30#include <xmloff/families.hxx>
31#include <xmloff/xmlexp.hxx>
36
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::style;
40using namespace ::com::sun::star::container;
41using namespace ::com::sun::star::beans;
42using namespace ::xmloff::token;
43
44constexpr OUStringLiteral gsIsPhysical( u"IsPhysical" );
45constexpr OUStringLiteral gsFollowStyle( u"FollowStyle" );
46
47namespace {
48
49bool findPageMasterNameEntry(
50 ::std::vector<XMLPageExportNameEntry> const& aNameVector,
51 const OUString& rStyleName, XMLPageExportNameEntry & o_rEntry)
52{
53 auto pEntry = std::find_if(aNameVector.cbegin(), aNameVector.cend(),
54 [&rStyleName](const XMLPageExportNameEntry& rEntry) { return rEntry.sStyleName == rStyleName; });
55
56 if( pEntry != aNameVector.cend() )
57 {
58 o_rEntry = *pEntry;
59 return true;
60 }
61
62 return false;
63}
64
65} // namespace
66
68 const Reference < XPropertySet > & rPropSet,
70{
71 SAL_WARN_IF( !m_xPageMasterPropSetMapper.is(), "xmloff", "page master family/XMLPageMasterPropSetMapper not found" );
73 {
74 ::std::vector<XMLPropertyState> aPropStates = m_xPageMasterExportPropMapper->Filter(m_rExport, rPropSet);
75 if( !aPropStates.empty())
76 {
77 OUString sParent;
78 rEntry.sPageMasterName = m_rExport.GetAutoStylePool()->Find( XmlStyleFamily::PAGE_MASTER, sParent, aPropStates );
79 if (rEntry.sPageMasterName.isEmpty())
80 {
81 rEntry.sPageMasterName = m_rExport.GetAutoStylePool()->Add(XmlStyleFamily::PAGE_MASTER, sParent, std::move(aPropStates));
82 }
83 }
84 }
86 ::std::vector<XMLPropertyState> aPropStates(
88 if (!aPropStates.empty())
89 {
90 OUString sParent;
92 if (rEntry.sDrawingPageStyleName.isEmpty())
93 {
94 rEntry.sDrawingPageStyleName = m_rExport.GetAutoStylePool()->Add(XmlStyleFamily::SD_DRAWINGPAGE_ID, sParent, std::move(aPropStates));
95 }
96 }
97}
98
100 const Reference < XPropertySet > &,
101 bool /*bAutoStyles*/ )
102{
103
104}
105
107 const Reference< XStyle >& rStyle,
108 bool bAutoStyles )
109{
110 Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
111 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
112
113 // Don't export styles that aren't existing really. This may be the
114 // case for StarOffice Writer's pool styles.
115 if( xPropSetInfo->hasPropertyByName( gsIsPhysical ) )
116 {
117 Any aAny = xPropSet->getPropertyValue( gsIsPhysical );
118 if( !*o3tl::doAccess<bool>(aAny) )
119 return false;
120 }
121
122 if( bAutoStyles )
123 {
125 collectPageMasterAutoStyle(xPropSet, aEntry);
126 aEntry.sStyleName = rStyle->getName();
127 m_aNameVector.push_back( aEntry );
128
129 exportMasterPageContent( xPropSet, true );
130 }
131 else
132 {
133 OUString sName( rStyle->getName() );
134 bool bEncoded = false;
136 GetExport().EncodeStyleName( sName, &bEncoded ) );
137
138 if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
139 {
140 uno::Any aValue = xPropSet->getPropertyValue( "Hidden" );
141 bool bHidden = false;
142 if ((aValue >>= bHidden) && bHidden
143 && GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
144 {
146 GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_HIDDEN, "true"); // FIXME for compatibility
147 }
148 }
149
150 if( bEncoded )
152 sName);
153
155 if (findPageMasterNameEntry(m_aNameVector, sName, entry))
156 {
158 if (!entry.sDrawingPageStyleName.isEmpty())
159 {
161 }
162 }
163
164 Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
165 if ( xInfo.is() && xInfo->hasPropertyByName(gsFollowStyle) )
166 {
167 OUString sNextName;
168 xPropSet->getPropertyValue( gsFollowStyle ) >>= sNextName;
169
170 if( sName != sNextName && !sNextName.isEmpty() )
171 {
173 GetExport().EncodeStyleName( sNextName ) );
174 }
175 }
176
178 XML_MASTER_PAGE, true, true );
179
180 exportMasterPageContent( xPropSet, false );
181 }
182
183 return true;
184}
185
187 : m_rExport(rExp)
188 , m_xPageMasterPropHdlFactory(new XMLPageMasterPropHdlFactory)
189 , m_xPageMasterPropSetMapper(new XMLPageMasterPropSetMapper(
191 m_xPageMasterPropHdlFactory))
192 , m_xPageMasterExportPropMapper(new XMLPageMasterExportPropMapper(
193 m_xPageMasterPropSetMapper, rExp))
194 , m_xPageMasterDrawingPagePropSetMapper(new XMLPageMasterPropSetMapper(
196 m_xPageMasterPropHdlFactory))
197 // use same class but with different map, need its ContextFilter()
198 , m_xPageMasterDrawingPageExportPropMapper(new XMLPageMasterExportPropMapper(
199 m_xPageMasterDrawingPagePropSetMapper, rExp))
200{
205
206 Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
207 UNO_QUERY );
208 SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff",
209 "No XStyleFamiliesSupplier from XModel for export!" );
210 if( !xFamiliesSupp.is() )
211 return;
212
213 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
214 SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff",
215 "getStyleFamilies() from XModel failed for export!" );
216 if( xFamilies.is() )
217 {
218 static constexpr OUStringLiteral aPageStyleName(u"PageStyles");
219
220 if( xFamilies->hasByName( aPageStyleName ) )
221 {
222 m_xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
223
224 SAL_WARN_IF( !m_xPageStyles.is(), "xmloff",
225 "Page Styles not found for export!" );
226 }
227 }
228
229 if (GetExport().GetModelType() != SvtModuleOptions::EFactory::WRITER)
230 return;
231
232 uno::Reference<lang::XMultiServiceFactory> xFac(GetExport().GetModel(), uno::UNO_QUERY);
233 if (!xFac.is())
234 return;
235
236 uno::Reference<beans::XPropertySet> xProps(
237 xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
238 if (!xProps.is())
239 return;
240
241 bool bGutterAtTop{};
242 xProps->getPropertyValue("GutterAtTop") >>= bGutterAtTop;
243 if (bGutterAtTop)
244 {
246 ->SetGutterAtTop(true);
247 }
248}
249
251{
252}
253
254void XMLPageExport::exportStyles( bool bUsed, bool bAutoStyles )
255{
256 if( m_xPageStyles.is() )
257 {
258 const uno::Sequence< OUString> aSeq = m_xPageStyles->getElementNames();
259 for(const auto& rName : aSeq)
260 {
261 Reference< XStyle > xStyle(m_xPageStyles->getByName( rName ),uno::UNO_QUERY);
262 if( !bUsed || xStyle->isInUse() )
263 exportStyle( xStyle, bAutoStyles );
264 }
265 }
266}
267
269{
271 // tdf#103602 this is called by both Writer and Calc but Calc doesn't
272 // have fill properties yet
274}
275
277{
278 Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
279 if (!xFactory.is())
280 return;
281
282 Reference < XPropertySet > xPropSet (xFactory->createInstance ( "com.sun.star.text.Defaults" ), UNO_QUERY);
283 if (!xPropSet.is())
284 return;
285
286 // <style:default-style ...>
288
289 ::std::vector< XMLPropertyState > aPropStates =
290 m_xPageMasterExportPropMapper->FilterDefaults(m_rExport, xPropSet);
291
292 bool bExport = false;
294 for( const auto& rProp : aPropStates )
295 {
296 sal_Int16 nContextId = aPropMapper->GetEntryContextId( rProp.mnIndex );
297 if( nContextId == CTF_PM_STANDARD_MODE )
298 {
299 bExport = true;
300 break;
301 }
302 }
303
304 if( !bExport )
305 return;
306
307 assert(GetExport().getSaneDefaultVersion()
309
310 //<style:default-page-layout>
313 true, true );
314
315 m_xPageMasterExportPropMapper->exportXML( GetExport(), aPropStates,
317}
318
319/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XMLPropertyMapEntry const g_XMLPageMasterDrawingPageStyleMap[]
const XMLPropertyMapEntry aXMLPageMasterStyleMap[]
#define CTF_PM_STANDARD_MODE
constexpr OUStringLiteral gsIsPhysical(u"IsPhysical")
constexpr OUStringLiteral gsFollowStyle(u"FollowStyle")
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
Definition: xmlexp.hxx:573
void CheckAttrList()
Definition: xmlexp.cxx:1012
void collectPageMasterAutoStyle(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, XMLPageExportNameEntry &rEntry)
virtual void exportMasterPageContent(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bAutoStyles)
void exportAutoStyles()
void exportDefaultStyle()
css::uno::Reference< css::container::XNameAccess > m_xPageStyles
rtl::Reference< XMLPropertySetMapper > m_xPageMasterPropSetMapper
::std::vector< XMLPageExportNameEntry > m_aNameVector
virtual ~XMLPageExport() override
rtl::Reference< SvXMLExportPropertyMapper > m_xPageMasterExportPropMapper
SvXMLExport & GetExport()
SvXMLExport & m_rExport
void exportStyles(bool bUsed, bool bAutoStyles)
rtl::Reference< SvXMLExportPropertyMapper > m_xPageMasterDrawingPageExportPropMapper
XMLPageExport(SvXMLExport &rExp)
bool exportStyle(const css::uno::Reference< css::style::XStyle > &rStyle, bool bAutoStyles)
float u
Reference< XSingleServiceFactory > xFactory
constexpr OUStringLiteral XML_STYLE_FAMILY_PAGE_MASTER_PREFIX
Definition: families.hxx:29
constexpr OUStringLiteral XML_STYLE_FAMILY_SD_DRAWINGPAGE_PREFIX
Definition: families.hxx:44
constexpr OUStringLiteral XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME
Definition: families.hxx:43
constexpr OUStringLiteral XML_STYLE_FAMILY_PAGE_MASTER_NAME
These defines determine the unique ids for XML style-families used in the SvXMLAutoStylePoolP.
Definition: families.hxx:28
OUString sName
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
@ XML_DEFAULT_PAGE_LAYOUT
Definition: xmltoken.hxx:2305
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
constexpr sal_uInt16 XML_NAMESPACE_STYLE