LibreOffice Module xmloff (master)  1
layerexp.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 
21 #include <com/sun/star/drawing/XLayerSupplier.hpp>
22 #include <com/sun/star/container/XIndexAccess.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnmspe.hxx>
27 #include <xmloff/xmlexp.hxx>
28 #include "layerexp.hxx"
29 #include <osl/diagnose.h>
30 
31 using ::com::sun::star::uno::Reference;
32 
33 using namespace ::cppu;
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::drawing;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::container;
40 using namespace ::xmloff::token;
41 
43 {
44  Reference< XLayerSupplier > xLayerSupplier( rExport.GetModel(), UNO_QUERY );
45  if( !xLayerSupplier.is() )
46  return;
47 
48  Reference< XIndexAccess > xLayerManager( xLayerSupplier->getLayerManager(), UNO_QUERY );
49  if( !xLayerManager.is() )
50  return;
51 
52  const sal_Int32 nCount = xLayerManager->getCount();
53  if( nCount == 0 )
54  return;
55 
56  const OUString strName( "Name" );
57  const OUString strTitle( "Title" );
58  const OUString strDescription( "Description" );
59  const OUString strIsVisible( "IsVisible");
60  const OUString strIsPrintable( "IsPrintable");
61  const OUString strIsLocked( "IsLocked" );
62 
63  OUString sTmp;
64 
65 
66  SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_LAYER_SET, true, true );
67 
68  for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
69  {
70  try
71  {
72  Reference< XPropertySet> xLayer( xLayerManager->getByIndex( nIndex ), UNO_QUERY_THROW );
73  xLayer->getPropertyValue( strName ) >>= sTmp;
74  if(!sTmp.isEmpty())
75  rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, sTmp );
76 
77  bool bTmpVisible( true );
78  bool bTmpPrintable( true );
79  xLayer->getPropertyValue( strIsVisible) >>= bTmpVisible;
80  xLayer->getPropertyValue( strIsPrintable) >>= bTmpPrintable;
81  // only write non-default values, default is "always"
82  if ( bTmpVisible )
83  {
84  if ( !bTmpPrintable )
85  rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY, OUString("screen") );
86  }
87  else
88  {
89  if ( bTmpPrintable)
90  rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY, OUString("printer") );
91  else
92  rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY, OUString("none") );
93  }
94 
95  bool bTmpLocked( false );
96  xLayer->getPropertyValue( strIsLocked ) >>= bTmpLocked;
97  // only write non-default value, default is "false"
98  if ( bTmpLocked )
99  {
100  rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_PROTECTED, OUString("true") );
101  }
102 
103  SvXMLElementExport aEle( rExport, XML_NAMESPACE_DRAW, XML_LAYER, true, true );
104 
105  // title property (as <svg:title> element)
106  xLayer->getPropertyValue(strTitle) >>= sTmp;
107  if(!sTmp.isEmpty())
108  {
109  SvXMLElementExport aEventElemt(rExport, XML_NAMESPACE_SVG, XML_TITLE, true, false);
110  rExport.Characters(sTmp);
111  }
112 
113  // description property (as <svg:desc> element)
114  xLayer->getPropertyValue(strDescription) >>= sTmp;
115  if(!sTmp.isEmpty())
116  {
117  SvXMLElementExport aDesc(rExport, XML_NAMESPACE_SVG, XML_DESC, true, false);
118  rExport.Characters(sTmp);
119  }
120  }
121  catch( Exception& )
122  {
123  OSL_FAIL("SdXMLayerExporter::exportLayer(), exception caught during export of one layer!");
124  }
125  }
126 }
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlexp.hxx:415
int nCount
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:926
constexpr sal_uInt16 XML_NAMESPACE_DRAW
Definition: xmlnmspe.hxx:33
static void exportLayer(SvXMLExport &rExport)
Definition: layerexp.cxx:42
Handling of tokens in XML:
void Characters(const OUString &rChars)
Definition: xmlexp.cxx:2163
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
constexpr sal_uInt16 XML_NAMESPACE_SVG
Definition: xmlnmspe.hxx:40