bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / ImageStyle.cxx
blobde3bfc8f3e8f30b6991fde261f7b731eeb986cb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmloff/ImageStyle.hxx"
21 #include <com/sun/star/awt/XBitmap.hpp>
22 #include <xmloff/attrlist.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmluconv.hxx>
25 #include"xmloff/xmlnmspe.hxx"
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <rtl/ustring.hxx>
31 #include <tools/debug.hxx>
32 #include <xmloff/xmltkmap.hxx>
34 using namespace ::com::sun::star;
36 using namespace ::xmloff::token;
38 enum SvXMLTokenMapAttrs
40 XML_TOK_IMAGE_NAME,
41 XML_TOK_IMAGE_DISPLAY_NAME,
42 XML_TOK_IMAGE_URL,
43 XML_TOK_IMAGE_TYPE,
44 XML_TOK_IMAGE_SHOW,
45 XML_TOK_IMAGE_ACTUATE,
46 XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
50 XMLImageStyle::XMLImageStyle()
54 XMLImageStyle::~XMLImageStyle()
58 sal_Bool XMLImageStyle::exportXML( const OUString& rStrName, const ::com::sun::star::uno::Any& rValue, SvXMLExport& rExport )
60 return ImpExportXML( rStrName, rValue, rExport );
63 sal_Bool XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport )
65 sal_Bool bRet = sal_False;
67 OUString sImageURL;
69 if( !rStrName.isEmpty() )
71 if( rValue >>= sImageURL )
73 // Name
74 sal_Bool bEncoded = sal_False;
75 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
76 rExport.EncodeStyleName( rStrName,
77 &bEncoded ) );
78 if( bEncoded )
79 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
80 rStrName );
82 // uri
83 const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) );
84 if( !aStr.isEmpty() )
86 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr );
87 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
88 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
89 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
92 // Do Write
93 SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, sal_True, sal_True );
95 if( !sImageURL.isEmpty() )
97 // optional office:binary-data
98 rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL );
103 return bRet;
106 sal_Bool XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport )
108 return ImpImportXML( xAttrList, rValue, rStrName, rImport );
111 sal_Bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
112 uno::Any& rValue, OUString& rStrName,
113 SvXMLImport& rImport )
115 sal_Bool bRet = sal_False;
116 sal_Bool bHasHRef = sal_False;
117 sal_Bool bHasName = sal_False;
118 OUString aStrURL;
119 OUString aDisplayName;
122 static SvXMLTokenMapEntry aHatchAttrTokenMap[] =
124 { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_IMAGE_NAME },
125 { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_IMAGE_DISPLAY_NAME },
126 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
127 { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_IMAGE_TYPE },
128 { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_IMAGE_SHOW },
129 { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_IMAGE_ACTUATE },
130 XML_TOKEN_MAP_END
133 SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
135 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
136 for( sal_Int16 i=0; i < nAttrCount; i++ )
138 const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
139 OUString aStrAttrName;
140 sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName );
141 const OUString& rStrValue = xAttrList->getValueByIndex( i );
143 switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
145 case XML_TOK_IMAGE_NAME:
147 rStrName = rStrValue;
148 bHasName = sal_True;
150 break;
151 case XML_TOK_IMAGE_DISPLAY_NAME:
153 aDisplayName = rStrValue;
155 break;
156 case XML_TOK_IMAGE_URL:
158 aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, sal_False );
159 bHasHRef = sal_True;
161 break;
162 case XML_TOK_IMAGE_TYPE:
163 // ignore
164 break;
165 case XML_TOK_IMAGE_SHOW:
166 // ignore
167 break;
168 case XML_TOK_IMAGE_ACTUATE:
169 // ignore
170 break;
171 default:
172 DBG_WARNING( "Unknown token at import fill bitmap style" )
177 rValue <<= aStrURL;
179 if( !aDisplayName.isEmpty() )
181 rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID,
182 rStrName, aDisplayName );
183 rStrName = aDisplayName;
186 bRet = bHasName && bHasHRef;
190 return bRet;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */