bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / ImageStyle.cxx
blobec0a53ef3a3c5df7c0464a51741869af5016ef34
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 void XMLImageStyle::exportXML( const OUString& rStrName, const ::com::sun::star::uno::Any& rValue, SvXMLExport& rExport )
60 ImpExportXML( rStrName, rValue, rExport );
63 void XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport )
65 OUString sImageURL;
67 if( !rStrName.isEmpty() )
69 if( rValue >>= sImageURL )
71 // Name
72 bool bEncoded = false;
73 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
74 rExport.EncodeStyleName( rStrName,
75 &bEncoded ) );
76 if( bEncoded )
77 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
78 rStrName );
80 // uri
81 const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) );
82 if( !aStr.isEmpty() )
84 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr );
85 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
86 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
87 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
90 // Do Write
91 SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, true, true );
93 if( !sImageURL.isEmpty() )
95 // optional office:binary-data
96 rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL );
102 bool XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport )
104 return ImpImportXML( xAttrList, rValue, rStrName, rImport );
107 bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
108 uno::Any& rValue, OUString& rStrName,
109 SvXMLImport& rImport )
111 static const SvXMLTokenMapEntry aHatchAttrTokenMap[] =
113 { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_IMAGE_NAME },
114 { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_IMAGE_DISPLAY_NAME },
115 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
116 { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_IMAGE_TYPE },
117 { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_IMAGE_SHOW },
118 { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_IMAGE_ACTUATE },
119 XML_TOKEN_MAP_END
122 bool bHasHRef = false;
123 bool bHasName = false;
124 OUString aStrURL;
125 OUString aDisplayName;
127 SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
129 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
130 for( sal_Int16 i=0; i < nAttrCount; i++ )
132 const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
133 OUString aStrAttrName;
134 sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName );
135 const OUString& rStrValue = xAttrList->getValueByIndex( i );
137 switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
139 case XML_TOK_IMAGE_NAME:
141 rStrName = rStrValue;
142 bHasName = true;
144 break;
145 case XML_TOK_IMAGE_DISPLAY_NAME:
147 aDisplayName = rStrValue;
149 break;
150 case XML_TOK_IMAGE_URL:
152 aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, false );
153 bHasHRef = true;
155 break;
156 case XML_TOK_IMAGE_TYPE:
157 // ignore
158 break;
159 case XML_TOK_IMAGE_SHOW:
160 // ignore
161 break;
162 case XML_TOK_IMAGE_ACTUATE:
163 // ignore
164 break;
165 default:
166 SAL_INFO("xmloff.style", "Unknown token at import fill bitmap style");
170 rValue <<= aStrURL;
172 if( !aDisplayName.isEmpty() )
174 rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID,
175 rStrName, aDisplayName );
176 rStrName = aDisplayName;
179 bool bRet = bHasName && bHasHRef;
181 return bRet;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */