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