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 
20 #include <xmloff/XMLPageExport.hxx>
21 #include <o3tl/any.hxx>
22 #include <sal/log.hxx>
23 #include <xmloff/xmlnamespace.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>
33 #include <PageMasterStyleMap.hxx>
34 #include <PageMasterPropMapper.hxx>
36 
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::style;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::beans;
42 using namespace ::xmloff::token;
43 
44 constexpr OUStringLiteral gsIsPhysical( u"IsPhysical" );
45 constexpr OUStringLiteral gsFollowStyle( u"FollowStyle" );
46 
47 namespace {
48 
49 bool 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,
69  XMLPageExportNameEntry & rEntry)
70 {
71  SAL_WARN_IF( !xPageMasterPropSetMapper.is(), "xmloff", "page master family/XMLPageMasterPropSetMapper not found" );
72  if( xPageMasterPropSetMapper.is() )
73  {
74  ::std::vector<XMLPropertyState> aPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
75  if( !aPropStates.empty())
76  {
77  OUString sParent;
78  rEntry.sPageMasterName = rExport.GetAutoStylePool()->Find( XmlStyleFamily::PAGE_MASTER, sParent, aPropStates );
79  if (rEntry.sPageMasterName.isEmpty())
80  {
81  rEntry.sPageMasterName = rExport.GetAutoStylePool()->Add(XmlStyleFamily::PAGE_MASTER, sParent, aPropStates);
82  }
83  }
84  }
86  ::std::vector<XMLPropertyState> const aPropStates(
88  if (!aPropStates.empty())
89  {
90  OUString sParent;
92  if (rEntry.sDrawingPageStyleName.isEmpty())
93  {
95  }
96  }
97 }
98 
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  {
124  XMLPageExportNameEntry aEntry;
125  collectPageMasterAutoStyle(xPropSet, aEntry);
126  aEntry.sStyleName = rStyle->getName();
127  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(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  : rExport(rExp)
188  , xPageMasterPropHdlFactory(new XMLPageMasterPropHdlFactory)
189  , xPageMasterPropSetMapper(new XMLPageMasterPropSetMapper(
191  xPageMasterPropHdlFactory))
192  , xPageMasterExportPropMapper(new XMLPageMasterExportPropMapper(
193  xPageMasterPropSetMapper, rExp))
194  , m_xPageMasterDrawingPagePropSetMapper(new XMLPageMasterPropSetMapper(
196  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  const OUString aPageStyleName("PageStyles");
219 
220  if( xFamilies->hasByName( aPageStyleName ) )
221  {
222  xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
223 
224  SAL_WARN_IF( !xPageStyles.is(), "xmloff",
225  "Page Styles not found for export!" );
226  }
227  }
228 }
229 
231 {
232 }
233 
234 void XMLPageExport::exportStyles( bool bUsed, bool bAutoStyles )
235 {
236  if( xPageStyles.is() )
237  {
238  const uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
239  for(const auto& rName : aSeq)
240  {
241  Reference< XStyle > xStyle(xPageStyles->getByName( rName ),uno::UNO_QUERY);
242  if( !bUsed || xStyle->isInUse() )
243  exportStyle( xStyle, bAutoStyles );
244  }
245  }
246 }
247 
249 {
251  // tdf#103602 this is called by both Writer and Calc but Calc doesn't
252  // have fill properties yet
254 }
255 
257 {
258  Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
259  if (!xFactory.is())
260  return;
261 
262  Reference < XPropertySet > xPropSet (xFactory->createInstance ( "com.sun.star.text.Defaults" ), UNO_QUERY);
263  if (!xPropSet.is())
264  return;
265 
266  // <style:default-style ...>
268 
269  ::std::vector< XMLPropertyState > aPropStates =
270  xPageMasterExportPropMapper->FilterDefaults( xPropSet );
271 
272  bool bExport = false;
273  rtl::Reference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
274  for( const auto& rProp : aPropStates )
275  {
276  sal_Int16 nContextId = aPropMapper->GetEntryContextId( rProp.mnIndex );
277  if( nContextId == CTF_PM_STANDARD_MODE )
278  {
279  bExport = true;
280  break;
281  }
282  }
283 
284  if( !bExport )
285  return;
286 
287  assert(GetExport().getSaneDefaultVersion()
289 
290  //<style:default-page-layout>
293  true, true );
294 
295  xPageMasterExportPropMapper->exportXML( GetExport(), aPropStates,
297 }
298 
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void collectPageMasterAutoStyle(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, XMLPageExportNameEntry &rEntry)
rtl::Reference< SvXMLExportPropertyMapper > m_xPageMasterDrawingPageExportPropMapper
const XMLPropertyMapEntry aXMLPageMasterStyleMap[]
XMLPageExport(SvXMLExport &rExp)
void CheckAttrList()
Definition: xmlexp.cxx:1030
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:909
bool exportStyle(const css::uno::Reference< css::style::XStyle > &rStyle, bool bAutoStyles)
constexpr sal_uInt16 XML_NAMESPACE_DRAW
const char * sName
virtual ~XMLPageExport() override
constexpr OUStringLiteral gsFollowStyle(u"FollowStyle")
virtual void exportMasterPageContent(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bAutoStyles)
void exportStyles(bool bUsed, bool bAutoStyles)
void exportAutoStyles()
css::uno::Reference< css::container::XNameAccess > xPageStyles
SvXMLExport & GetExport()
XMLPropertyMapEntry const g_XMLPageMasterDrawingPageStyleMap[]
#define XML_STYLE_FAMILY_SD_DRAWINGPAGE_PREFIX
Definition: families.hxx:42
#define XML_STYLE_FAMILY_PAGE_MASTER_PREFIX
Definition: families.hxx:27
#define XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME
Definition: families.hxx:41
void exportDefaultStyle()
constexpr OUStringLiteral gsIsPhysical(u"IsPhysical")
#define SAL_WARN_IF(condition, area, stream)
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
Definition: xmlexp.hxx:576
Handling of tokens in XML:
rtl::Reference< SvXMLExportPropertyMapper > xPageMasterExportPropMapper
SvXMLExport & rExport
rtl::Reference< XMLPropertySetMapper > xPageMasterPropSetMapper
Sequence< sal_Int8 > aSeq
Reference< XSingleServiceFactory > xFactory
#define CTF_PM_STANDARD_MODE
#define XML_STYLE_FAMILY_PAGE_MASTER_NAME
These defines determine the unique ids for XML style-families used in the SvXMLAutoStylePoolP.
Definition: families.hxx:26
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
constexpr sal_uInt16 XML_NAMESPACE_STYLE