1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ImageStyle.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "ImageStyle.hxx"
34 #include <com/sun/star/awt/XBitmap.hpp>
35 #include <xmloff/attrlist.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include"xmlnmspe.hxx"
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmlexp.hxx>
41 #include <xmloff/xmlimp.hxx>
42 #include <rtl/ustrbuf.hxx>
43 #include <rtl/ustring.hxx>
44 #include <tools/debug.hxx>
45 #include <xmloff/xmltkmap.hxx>
47 using namespace ::com::sun::star
;
48 using ::rtl::OUString
;
49 using ::rtl::OUStringBuffer
;
51 using namespace ::xmloff::token
;
53 enum SvXMLTokenMapAttrs
56 XML_TOK_IMAGE_DISPLAY_NAME
,
60 XML_TOK_IMAGE_ACTUATE
,
61 /* XML_TOK_IMAGE_SIZEW,
62 XML_TOK_IMAGE_SIZEH,*/
63 XML_TOK_TABSTOP_END
=XML_TOK_UNKNOWN
67 XMLImageStyle::XMLImageStyle()
71 XMLImageStyle::~XMLImageStyle()
77 sal_Bool
XMLImageStyle::exportXML( const OUString
& rStrName
, const ::com::sun::star::uno::Any
& rValue
, SvXMLExport
& rExport
)
79 return ImpExportXML( rStrName
, rValue
, rExport
);
82 sal_Bool
XMLImageStyle::ImpExportXML( const OUString
& rStrName
, const uno::Any
& rValue
, SvXMLExport
& rExport
)
84 sal_Bool bRet
= sal_False
;
88 if( rStrName
.getLength() )
90 if( rValue
>>= sImageURL
)
96 sal_Bool bEncoded
= sal_False
;
97 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_NAME
,
98 rExport
.EncodeStyleName( rStrName
,
101 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
,
105 const OUString
aStr( rExport
.AddEmbeddedGraphicObject( sImageURL
) );
106 if( aStr
.getLength() )
108 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_HREF
, aStr
);
109 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_TYPE
, XML_SIMPLE
);
110 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_SHOW
, XML_EMBED
);
111 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_ACTUATE
, XML_ONLOAD
);
115 awt::Size aSize = xBitmap->getSize();
117 rUnitConverter.convertNumber( aOut, aSize.Width );
118 aStrValue = aOut.makeStringAndClear();
119 AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH, aStrValue );
121 rUnitConverter.convertNumber( aOut, aSize.Height );
122 aStrValue = aOut.makeStringAndClear();
123 AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT, aStrValue );
126 SvXMLElementExport
aElem( rExport
, XML_NAMESPACE_DRAW
, XML_FILL_IMAGE
, sal_True
, sal_True
);
128 if( sImageURL
.getLength() )
130 // optional office:binary-data
131 rExport
.AddEmbeddedGraphicObjectAsBase64( sImageURL
);
139 #endif // #ifndef SVX_LIGHT
141 sal_Bool
XMLImageStyle::importXML( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
, uno::Any
& rValue
, OUString
& rStrName
, SvXMLImport
& rImport
)
143 return ImpImportXML( xAttrList
, rValue
, rStrName
, rImport
);
146 sal_Bool
XMLImageStyle::ImpImportXML( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
147 uno::Any
& rValue
, OUString
& rStrName
,
148 SvXMLImport
& rImport
)
150 sal_Bool bRet
= sal_False
;
151 sal_Bool bHasHRef
= sal_False
;
152 sal_Bool bHasName
= sal_False
;
154 OUString aDisplayName
;
157 static __FAR_DATA SvXMLTokenMapEntry aHatchAttrTokenMap
[] =
159 { XML_NAMESPACE_DRAW
, XML_NAME
, XML_TOK_IMAGE_NAME
},
160 { XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
, XML_TOK_IMAGE_DISPLAY_NAME
},
161 { XML_NAMESPACE_XLINK
, XML_HREF
, XML_TOK_IMAGE_URL
},
162 { XML_NAMESPACE_XLINK
, XML_TYPE
, XML_TOK_IMAGE_TYPE
},
163 { XML_NAMESPACE_XLINK
, XML_SHOW
, XML_TOK_IMAGE_SHOW
},
164 { XML_NAMESPACE_XLINK
, XML_ACTUATE
, XML_TOK_IMAGE_ACTUATE
},
165 /*{ XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
166 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },*/
170 SvXMLTokenMap
aTokenMap( aHatchAttrTokenMap
);
172 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
173 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
175 const OUString
& rFullAttrName
= xAttrList
->getNameByIndex( i
);
176 OUString aStrAttrName
;
177 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName( rFullAttrName
, &aStrAttrName
);
178 const OUString
& rStrValue
= xAttrList
->getValueByIndex( i
);
180 switch( aTokenMap
.Get( nPrefix
, aStrAttrName
) )
182 case XML_TOK_IMAGE_NAME
:
184 rStrName
= rStrValue
;
188 case XML_TOK_IMAGE_DISPLAY_NAME
:
190 aDisplayName
= rStrValue
;
193 case XML_TOK_IMAGE_URL
:
195 aStrURL
= rImport
.ResolveGraphicObjectURL( rStrValue
, sal_False
);
199 case XML_TOK_IMAGE_TYPE
:
202 case XML_TOK_IMAGE_SHOW
:
205 case XML_TOK_IMAGE_ACTUATE
:
209 DBG_WARNING( "Unknown token at import fill bitmap style" )
216 if( aDisplayName
.getLength() )
218 rImport
.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
,
219 rStrName
, aDisplayName
);
220 rStrName
= aDisplayName
;
223 bRet
= bHasName
&& bHasHRef
;