xref: /aoo42x/main/xmloff/source/style/ImageStyle.cxx (revision 63bba73c)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "xmloff/ImageStyle.hxx"
27cdf0e10cSrcweir #include <com/sun/star/awt/XBitmap.hpp>
28cdf0e10cSrcweir #include <xmloff/attrlist.hxx>
29cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
30cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
31cdf0e10cSrcweir #include"xmloff/xmlnmspe.hxx"
32cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
33cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
34cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
35cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
36cdf0e10cSrcweir #include <rtl/ustring.hxx>
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir using ::rtl::OUStringBuffer;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace ::xmloff::token;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir enum SvXMLTokenMapAttrs
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	XML_TOK_IMAGE_NAME,
49cdf0e10cSrcweir 	XML_TOK_IMAGE_DISPLAY_NAME,
50cdf0e10cSrcweir 	XML_TOK_IMAGE_URL,
51cdf0e10cSrcweir 	XML_TOK_IMAGE_TYPE,
52cdf0e10cSrcweir 	XML_TOK_IMAGE_SHOW,
53cdf0e10cSrcweir 	XML_TOK_IMAGE_ACTUATE,
54cdf0e10cSrcweir 	/* XML_TOK_IMAGE_SIZEW,
55cdf0e10cSrcweir 	   XML_TOK_IMAGE_SIZEH,*/
56cdf0e10cSrcweir 	XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
XMLImageStyle()60cdf0e10cSrcweir XMLImageStyle::XMLImageStyle()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
~XMLImageStyle()64cdf0e10cSrcweir XMLImageStyle::~XMLImageStyle()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #ifndef SVX_LIGHT
69cdf0e10cSrcweir 
exportXML(const OUString & rStrName,const::com::sun::star::uno::Any & rValue,SvXMLExport & rExport)70cdf0e10cSrcweir sal_Bool XMLImageStyle::exportXML( const OUString& rStrName, const ::com::sun::star::uno::Any& rValue, SvXMLExport& rExport )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	return ImpExportXML( rStrName, rValue, rExport );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
ImpExportXML(const OUString & rStrName,const uno::Any & rValue,SvXMLExport & rExport)75cdf0e10cSrcweir sal_Bool XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	OUString sImageURL;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	if( rStrName.getLength() )
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		if( rValue >>= sImageURL )
84cdf0e10cSrcweir 		{
85cdf0e10cSrcweir 			OUString aStrValue;
86cdf0e10cSrcweir 			OUStringBuffer aOut;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 			// Name
89cdf0e10cSrcweir 			sal_Bool bEncoded = sal_False;
90cdf0e10cSrcweir 			rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
91cdf0e10cSrcweir 								  rExport.EncodeStyleName( rStrName,
92cdf0e10cSrcweir 														   &bEncoded ) );
93cdf0e10cSrcweir 			if( bEncoded )
94cdf0e10cSrcweir 				rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
95cdf0e10cSrcweir 									  rStrName );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 			// uri
98cdf0e10cSrcweir 			const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) );
99cdf0e10cSrcweir 			if( aStr.getLength() )
100cdf0e10cSrcweir 			{
101cdf0e10cSrcweir 				rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr );
102cdf0e10cSrcweir 				rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
103cdf0e10cSrcweir 				rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
104cdf0e10cSrcweir 				rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
105cdf0e10cSrcweir 			}
106cdf0e10cSrcweir /*
107cdf0e10cSrcweir 			// size
108cdf0e10cSrcweir 			awt::Size aSize = xBitmap->getSize();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 			rUnitConverter.convertNumber( aOut, aSize.Width );
111cdf0e10cSrcweir 			aStrValue = aOut.makeStringAndClear();
112cdf0e10cSrcweir 			AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH, aStrValue );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 			rUnitConverter.convertNumber( aOut, aSize.Height );
115cdf0e10cSrcweir 			aStrValue = aOut.makeStringAndClear();
116cdf0e10cSrcweir 			AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT, aStrValue );
117cdf0e10cSrcweir */
118cdf0e10cSrcweir 			// Do Write
119cdf0e10cSrcweir 			SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, sal_True, sal_True );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 			if( sImageURL.getLength() )
122cdf0e10cSrcweir 			{
123cdf0e10cSrcweir 				// optional office:binary-data
124cdf0e10cSrcweir 				rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL );
125cdf0e10cSrcweir 			}
126cdf0e10cSrcweir 		}
127cdf0e10cSrcweir 	}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	return bRet;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir #endif // #ifndef SVX_LIGHT
133cdf0e10cSrcweir 
importXML(const uno::Reference<xml::sax::XAttributeList> & xAttrList,uno::Any & rValue,OUString & rStrName,SvXMLImport & rImport)134cdf0e10cSrcweir sal_Bool XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	return ImpImportXML( xAttrList, rValue, rStrName, rImport );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
ImpImportXML(const uno::Reference<xml::sax::XAttributeList> & xAttrList,uno::Any & rValue,OUString & rStrName,SvXMLImport & rImport)139cdf0e10cSrcweir sal_Bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
140cdf0e10cSrcweir 									  uno::Any& rValue, OUString& rStrName,
141cdf0e10cSrcweir 									  SvXMLImport& rImport )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	sal_Bool bRet     = sal_False;
144cdf0e10cSrcweir 	sal_Bool bHasHRef = sal_False;
145cdf0e10cSrcweir 	sal_Bool bHasName = sal_False;
146cdf0e10cSrcweir 	OUString aStrURL;
147cdf0e10cSrcweir 	OUString aDisplayName;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aHatchAttrTokenMap[] =
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	{ XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_IMAGE_NAME },
153cdf0e10cSrcweir 	{ XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_IMAGE_DISPLAY_NAME },
154cdf0e10cSrcweir 	{ XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
155cdf0e10cSrcweir 	{ XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_IMAGE_TYPE },
156cdf0e10cSrcweir 	{ XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_IMAGE_SHOW },
157cdf0e10cSrcweir 	{ XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_IMAGE_ACTUATE },
158cdf0e10cSrcweir 	/*{ XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
159cdf0e10cSrcweir 	{ XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },*/
160cdf0e10cSrcweir 	XML_TOKEN_MAP_END
161cdf0e10cSrcweir };
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
166cdf0e10cSrcweir 	for( sal_Int16 i=0; i < nAttrCount; i++ )
167cdf0e10cSrcweir 	{
168cdf0e10cSrcweir 		const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
169cdf0e10cSrcweir 		OUString aStrAttrName;
170cdf0e10cSrcweir 		sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName );
171cdf0e10cSrcweir 		const OUString& rStrValue = xAttrList->getValueByIndex( i );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
174cdf0e10cSrcweir 		{
175cdf0e10cSrcweir 			case XML_TOK_IMAGE_NAME:
176cdf0e10cSrcweir 				{
177cdf0e10cSrcweir 					rStrName = rStrValue;
178cdf0e10cSrcweir 					bHasName = sal_True;
179cdf0e10cSrcweir 				}
180cdf0e10cSrcweir 				break;
181cdf0e10cSrcweir 			case XML_TOK_IMAGE_DISPLAY_NAME:
182cdf0e10cSrcweir 				{
183cdf0e10cSrcweir 					aDisplayName = rStrValue;
184cdf0e10cSrcweir 				}
185cdf0e10cSrcweir 				break;
186cdf0e10cSrcweir 			case XML_TOK_IMAGE_URL:
187cdf0e10cSrcweir 				{
188cdf0e10cSrcweir 					aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, sal_False );
189cdf0e10cSrcweir 					bHasHRef = sal_True;
190cdf0e10cSrcweir 				}
191cdf0e10cSrcweir 				break;
192cdf0e10cSrcweir 			case XML_TOK_IMAGE_TYPE:
193cdf0e10cSrcweir 				// ignore
194cdf0e10cSrcweir 				break;
195cdf0e10cSrcweir 			case XML_TOK_IMAGE_SHOW:
196cdf0e10cSrcweir 				// ignore
197cdf0e10cSrcweir 				break;
198cdf0e10cSrcweir 			case XML_TOK_IMAGE_ACTUATE:
199cdf0e10cSrcweir 				// ignore
200cdf0e10cSrcweir 				break;
201cdf0e10cSrcweir 			default:
202cdf0e10cSrcweir 				DBG_WARNING( "Unknown token at import fill bitmap style" )
203cdf0e10cSrcweir 				;
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 	}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	rValue <<= aStrURL;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	if( aDisplayName.getLength() )
210cdf0e10cSrcweir 	{
211cdf0e10cSrcweir 		rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID,
212cdf0e10cSrcweir 									 rStrName, aDisplayName );
213cdf0e10cSrcweir 		rStrName = aDisplayName;
214cdf0e10cSrcweir 	}
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	bRet = bHasName && bHasHRef;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	return bRet;
221cdf0e10cSrcweir }
222