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 "hintids.hxx"
21 : #include <com/sun/star/io/XOutputStream.hpp>
22 : #include <editeng/memberids.hrc>
23 :
24 : #include <xmloff/nmspmap.hxx>
25 : #include <xmloff/xmlnmspe.hxx>
26 : #include <xmloff/xmlimp.hxx>
27 : #include <xmloff/xmltkmap.hxx>
28 : #include <xmloff/XMLBase64ImportContext.hxx>
29 : #include <svtools/grfmgr.hxx>
30 : #include <svx/unomid.hxx>
31 : #include <editeng/brushitem.hxx>
32 : #include <xmloff/xmluconv.hxx>
33 :
34 : #include "xmlbrshi.hxx"
35 : #include "xmlbrshe.hxx"
36 : #include "xmlexp.hxx"
37 : #include "xmlimpit.hxx"
38 : #include "xmlexpit.hxx"
39 :
40 : using namespace ::com::sun::star;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::xmloff::token;
43 :
44 : enum SvXMLTokenMapAttrs
45 : {
46 : XML_TOK_BGIMG_HREF,
47 : XML_TOK_BGIMG_TYPE,
48 : XML_TOK_BGIMG_ACTUATE,
49 : XML_TOK_BGIMG_SHOW,
50 : XML_TOK_BGIMG_POSITION,
51 : XML_TOK_BGIMG_REPEAT,
52 : XML_TOK_BGIMG_FILTER,
53 : XML_TOK_NGIMG_END=XML_TOK_UNKNOWN
54 : };
55 :
56 : static SvXMLTokenMapEntry aBGImgAttributesAttrTokenMap[] =
57 : {
58 : { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_BGIMG_HREF },
59 : { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_BGIMG_TYPE },
60 : { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_BGIMG_ACTUATE },
61 : { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_BGIMG_SHOW },
62 : { XML_NAMESPACE_STYLE, XML_POSITION, XML_TOK_BGIMG_POSITION },
63 : { XML_NAMESPACE_STYLE, XML_REPEAT, XML_TOK_BGIMG_REPEAT },
64 : { XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TOK_BGIMG_FILTER },
65 : XML_TOKEN_MAP_END
66 : };
67 :
68 0 : TYPEINIT1( SwXMLBrushItemImportContext, SvXMLImportContext );
69 :
70 0 : void SwXMLBrushItemImportContext::ProcessAttrs(
71 : const uno::Reference< xml::sax::XAttributeList >& xAttrList,
72 : const SvXMLUnitConverter& rUnitConv )
73 : {
74 0 : SvXMLTokenMap aTokenMap( aBGImgAttributesAttrTokenMap );
75 :
76 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
77 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
78 : {
79 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
80 0 : OUString aLocalName;
81 : sal_uInt16 nPrefix =
82 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
83 0 : &aLocalName );
84 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
85 :
86 0 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
87 : {
88 : case XML_TOK_BGIMG_HREF:
89 : SvXMLImportItemMapper::PutXMLValue(
90 0 : *pItem, GetImport().ResolveGraphicObjectURL( rValue, false),
91 0 : MID_GRAPHIC_LINK, rUnitConv );
92 0 : break;
93 : case XML_TOK_BGIMG_TYPE:
94 : case XML_TOK_BGIMG_ACTUATE:
95 : case XML_TOK_BGIMG_SHOW:
96 0 : break;
97 : case XML_TOK_BGIMG_POSITION:
98 : SvXMLImportItemMapper::PutXMLValue(
99 0 : *pItem, rValue, MID_GRAPHIC_POSITION, rUnitConv );
100 0 : break;
101 : case XML_TOK_BGIMG_REPEAT:
102 : SvXMLImportItemMapper::PutXMLValue(
103 0 : *pItem, rValue, MID_GRAPHIC_REPEAT, rUnitConv );
104 0 : break;
105 : case XML_TOK_BGIMG_FILTER:
106 : SvXMLImportItemMapper::PutXMLValue(
107 0 : *pItem, rValue, MID_GRAPHIC_FILTER, rUnitConv );
108 0 : break;
109 : }
110 0 : }
111 :
112 0 : }
113 :
114 0 : SvXMLImportContext *SwXMLBrushItemImportContext::CreateChildContext(
115 : sal_uInt16 nPrefix, const OUString& rLocalName,
116 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
117 : {
118 0 : SvXMLImportContext *pContext = 0;
119 0 : if( xmloff::token::IsXMLToken( rLocalName,
120 : xmloff::token::XML_BINARY_DATA ) )
121 : {
122 0 : if( !xBase64Stream.is() && pItem->GetGraphicLink().isEmpty() )
123 : {
124 0 : const GraphicObject *pGrObj = pItem->GetGraphicObject();
125 0 : if( !pGrObj || GRAPHIC_NONE == pGrObj->GetType() )
126 : {
127 0 : xBase64Stream =
128 0 : GetImport().GetStreamForGraphicObjectURLFromBase64();
129 0 : if( xBase64Stream.is() )
130 0 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
131 : rLocalName, xAttrList,
132 0 : xBase64Stream );
133 : }
134 : }
135 : }
136 0 : if( !pContext )
137 : {
138 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
139 : }
140 :
141 0 : return pContext;
142 : }
143 :
144 0 : void SwXMLBrushItemImportContext::EndElement()
145 : {
146 0 : if( xBase64Stream.is() )
147 : {
148 0 : OUString sURL( GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ) );
149 0 : xBase64Stream = 0;
150 0 : SvXMLImportItemMapper::PutXMLValue( *pItem, sURL, MID_GRAPHIC_LINK, GetImport().GetMM100UnitConverter() );
151 : }
152 :
153 0 : if( pItem->GetGraphicLink().isEmpty() && !(pItem->GetGraphic()) )
154 0 : pItem->SetGraphicPos( GPOS_NONE );
155 0 : else if( GPOS_NONE == pItem->GetGraphicPos() )
156 0 : pItem->SetGraphicPos( GPOS_TILED );
157 0 : }
158 :
159 0 : SwXMLBrushItemImportContext::SwXMLBrushItemImportContext(
160 : SvXMLImport& rImport, sal_uInt16 nPrfx,
161 : const OUString& rLName,
162 : const uno::Reference< xml::sax::XAttributeList >& xAttrList,
163 : const SvXMLUnitConverter& rUnitConv,
164 : const SvxBrushItem& rItem ) :
165 : SvXMLImportContext( rImport, nPrfx, rLName ),
166 0 : pItem( new SvxBrushItem( rItem ) )
167 : {
168 : // delete any grephic that is existing
169 0 : pItem->SetGraphicPos( GPOS_NONE );
170 :
171 0 : ProcessAttrs( xAttrList, rUnitConv );
172 0 : }
173 :
174 0 : SwXMLBrushItemImportContext::SwXMLBrushItemImportContext(
175 : SvXMLImport& rImport, sal_uInt16 nPrfx,
176 : const OUString& rLName,
177 : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
178 : const SvXMLUnitConverter& rUnitConv,
179 : sal_uInt16 nWhich ) :
180 : SvXMLImportContext( rImport, nPrfx, rLName ),
181 0 : pItem( new SvxBrushItem( nWhich ) )
182 : {
183 0 : ProcessAttrs( xAttrList, rUnitConv );
184 0 : }
185 :
186 0 : SwXMLBrushItemImportContext::~SwXMLBrushItemImportContext()
187 : {
188 0 : delete pItem;
189 0 : }
190 :
191 0 : SwXMLBrushItemExport::SwXMLBrushItemExport( SwXMLExport& rExp ) :
192 0 : rExport( rExp )
193 : {
194 0 : }
195 :
196 0 : SwXMLBrushItemExport::~SwXMLBrushItemExport()
197 : {
198 0 : }
199 :
200 0 : void SwXMLBrushItemExport::exportXML( const SvxBrushItem& rItem )
201 : {
202 0 : GetExport().CheckAttrList();
203 :
204 0 : OUString sValue, sURL;
205 0 : const SvXMLUnitConverter& rUnitConv = GetExport().GetTwipUnitConverter();
206 0 : if( SvXMLExportItemMapper::QueryXMLValue(
207 0 : rItem, sURL, MID_GRAPHIC_LINK, rUnitConv ) )
208 : {
209 0 : sValue = GetExport().AddEmbeddedGraphicObject( sURL );
210 0 : if( !sValue.isEmpty() )
211 : {
212 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sValue );
213 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
214 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
215 : }
216 :
217 0 : if( SvXMLExportItemMapper::QueryXMLValue(
218 0 : rItem, sValue, MID_GRAPHIC_POSITION, rUnitConv ) )
219 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_POSITION, sValue );
220 :
221 0 : if( SvXMLExportItemMapper::QueryXMLValue(
222 0 : rItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv ) )
223 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT, sValue );
224 :
225 0 : if( SvXMLExportItemMapper::QueryXMLValue(
226 0 : rItem, sValue, MID_GRAPHIC_FILTER, rUnitConv ) )
227 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME, sValue );
228 : }
229 :
230 : {
231 0 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_BACKGROUND_IMAGE,
232 0 : true, true );
233 0 : if( !sURL.isEmpty() )
234 : {
235 : // optional office:binary-data
236 0 : GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );
237 0 : }
238 0 : }
239 0 : }
240 :
241 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|