Line data Source code
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 : #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>
33 :
34 : using namespace ::com::sun::star;
35 :
36 : using namespace ::xmloff::token;
37 :
38 : enum SvXMLTokenMapAttrs
39 : {
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
47 : };
48 :
49 :
50 125 : XMLImageStyle::XMLImageStyle()
51 : {
52 125 : }
53 :
54 125 : XMLImageStyle::~XMLImageStyle()
55 : {
56 125 : }
57 :
58 0 : sal_Bool XMLImageStyle::exportXML( const OUString& rStrName, const ::com::sun::star::uno::Any& rValue, SvXMLExport& rExport )
59 : {
60 0 : return ImpExportXML( rStrName, rValue, rExport );
61 : }
62 :
63 0 : sal_Bool XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport )
64 : {
65 0 : sal_Bool bRet = sal_False;
66 :
67 0 : OUString sImageURL;
68 :
69 0 : if( !rStrName.isEmpty() )
70 : {
71 0 : if( rValue >>= sImageURL )
72 : {
73 : // Name
74 0 : sal_Bool bEncoded = sal_False;
75 : rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
76 : rExport.EncodeStyleName( rStrName,
77 0 : &bEncoded ) );
78 0 : if( bEncoded )
79 : rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
80 0 : rStrName );
81 :
82 : // uri
83 0 : const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) );
84 0 : if( !aStr.isEmpty() )
85 : {
86 0 : rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr );
87 0 : rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
88 0 : rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
89 0 : rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
90 : }
91 :
92 : // Do Write
93 0 : SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, sal_True, sal_True );
94 :
95 0 : if( !sImageURL.isEmpty() )
96 : {
97 : // optional office:binary-data
98 0 : rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL );
99 0 : }
100 : }
101 : }
102 :
103 0 : return bRet;
104 : }
105 :
106 90 : sal_Bool XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport )
107 : {
108 90 : return ImpImportXML( xAttrList, rValue, rStrName, rImport );
109 : }
110 :
111 90 : sal_Bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
112 : uno::Any& rValue, OUString& rStrName,
113 : SvXMLImport& rImport )
114 : {
115 90 : sal_Bool bRet = sal_False;
116 90 : sal_Bool bHasHRef = sal_False;
117 90 : sal_Bool bHasName = sal_False;
118 90 : OUString aStrURL;
119 180 : OUString aDisplayName;
120 :
121 : {
122 : static SvXMLTokenMapEntry aHatchAttrTokenMap[] =
123 : {
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
131 : };
132 :
133 90 : SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
134 :
135 90 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
136 540 : for( sal_Int16 i=0; i < nAttrCount; i++ )
137 : {
138 450 : const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
139 900 : OUString aStrAttrName;
140 450 : sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName );
141 900 : const OUString& rStrValue = xAttrList->getValueByIndex( i );
142 :
143 450 : switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
144 : {
145 : case XML_TOK_IMAGE_NAME:
146 : {
147 90 : rStrName = rStrValue;
148 90 : bHasName = sal_True;
149 : }
150 90 : break;
151 : case XML_TOK_IMAGE_DISPLAY_NAME:
152 : {
153 0 : aDisplayName = rStrValue;
154 : }
155 0 : break;
156 : case XML_TOK_IMAGE_URL:
157 : {
158 90 : aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, sal_False );
159 90 : bHasHRef = sal_True;
160 : }
161 90 : break;
162 : case XML_TOK_IMAGE_TYPE:
163 : // ignore
164 90 : break;
165 : case XML_TOK_IMAGE_SHOW:
166 : // ignore
167 90 : break;
168 : case XML_TOK_IMAGE_ACTUATE:
169 : // ignore
170 90 : break;
171 : default:
172 : DBG_WARNING( "Unknown token at import fill bitmap style" )
173 : ;
174 : }
175 450 : }
176 :
177 90 : rValue <<= aStrURL;
178 :
179 90 : if( !aDisplayName.isEmpty() )
180 : {
181 : rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID,
182 0 : rStrName, aDisplayName );
183 0 : rStrName = aDisplayName;
184 : }
185 :
186 90 : bRet = bHasName && bHasHRef;
187 :
188 : }
189 :
190 180 : return bRet;
191 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|