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/HatchStyle.hxx"
27cdf0e10cSrcweir #include <com/sun/star/drawing/Hatch.hpp>
28cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
29cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
30cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
31cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
32cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
33cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
34cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
35cdf0e10cSrcweir #include <rtl/ustring.hxx>
36cdf0e10cSrcweir #include <tools/debug.hxx>
37cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir using ::rtl::OUStringBuffer;
42cdf0e10cSrcweir
43cdf0e10cSrcweir using namespace ::xmloff::token;
44cdf0e10cSrcweir
45cdf0e10cSrcweir enum SvXMLTokenMapAttrs
46cdf0e10cSrcweir {
47cdf0e10cSrcweir XML_TOK_HATCH_NAME,
48cdf0e10cSrcweir XML_TOK_HATCH_DISPLAY_NAME,
49cdf0e10cSrcweir XML_TOK_HATCH_STYLE,
50cdf0e10cSrcweir XML_TOK_HATCH_COLOR,
51cdf0e10cSrcweir XML_TOK_HATCH_DISTANCE,
52cdf0e10cSrcweir XML_TOK_HATCH_ROTATION,
53cdf0e10cSrcweir XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
54cdf0e10cSrcweir };
55cdf0e10cSrcweir
56cdf0e10cSrcweir
57cdf0e10cSrcweir SvXMLEnumMapEntry __READONLY_DATA pXML_HatchStyle_Enum[] =
58cdf0e10cSrcweir {
59cdf0e10cSrcweir { XML_HATCHSTYLE_SINGLE, drawing::HatchStyle_SINGLE },
60cdf0e10cSrcweir { XML_HATCHSTYLE_DOUBLE, drawing::HatchStyle_DOUBLE },
61cdf0e10cSrcweir { XML_HATCHSTYLE_TRIPLE, drawing::HatchStyle_TRIPLE },
62cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
63cdf0e10cSrcweir };
64cdf0e10cSrcweir
65cdf0e10cSrcweir
66cdf0e10cSrcweir //-------------------------------------------------------------
67cdf0e10cSrcweir // Import
68cdf0e10cSrcweir //-------------------------------------------------------------
69cdf0e10cSrcweir
XMLHatchStyleImport(SvXMLImport & rImp)70cdf0e10cSrcweir XMLHatchStyleImport::XMLHatchStyleImport( SvXMLImport& rImp )
71cdf0e10cSrcweir : rImport(rImp)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
~XMLHatchStyleImport()75cdf0e10cSrcweir XMLHatchStyleImport::~XMLHatchStyleImport()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir
importXML(const uno::Reference<xml::sax::XAttributeList> & xAttrList,uno::Any & rValue,OUString & rStrName)79cdf0e10cSrcweir sal_Bool XMLHatchStyleImport::importXML(
80cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList >& xAttrList,
81cdf0e10cSrcweir uno::Any& rValue,
82cdf0e10cSrcweir OUString& rStrName )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir sal_Bool bRet = sal_False;
85cdf0e10cSrcweir
86cdf0e10cSrcweir sal_Bool bHasName = sal_False;
87cdf0e10cSrcweir sal_Bool bHasStyle = sal_False;
88cdf0e10cSrcweir sal_Bool bHasColor = sal_False;
89cdf0e10cSrcweir sal_Bool bHasDist = sal_False;
90cdf0e10cSrcweir OUString aDisplayName;
91cdf0e10cSrcweir
92cdf0e10cSrcweir drawing::Hatch aHatch;
93cdf0e10cSrcweir aHatch.Style = drawing::HatchStyle_SINGLE;
94cdf0e10cSrcweir aHatch.Color = 0;
95cdf0e10cSrcweir aHatch.Distance = 0;
96cdf0e10cSrcweir aHatch.Angle = 0;
97cdf0e10cSrcweir
98cdf0e10cSrcweir {
99cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aHatchAttrTokenMap[] =
100cdf0e10cSrcweir {
101cdf0e10cSrcweir { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_HATCH_NAME },
102cdf0e10cSrcweir { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_HATCH_DISPLAY_NAME },
103cdf0e10cSrcweir { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_HATCH_STYLE },
104cdf0e10cSrcweir { XML_NAMESPACE_DRAW, XML_COLOR, XML_TOK_HATCH_COLOR },
105cdf0e10cSrcweir { XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, XML_TOK_HATCH_DISTANCE },
106cdf0e10cSrcweir { XML_NAMESPACE_DRAW, XML_ROTATION, XML_TOK_HATCH_ROTATION },
107cdf0e10cSrcweir XML_TOKEN_MAP_END
108cdf0e10cSrcweir };
109cdf0e10cSrcweir
110cdf0e10cSrcweir SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
111cdf0e10cSrcweir SvXMLNamespaceMap rNamespaceMap = rImport.GetNamespaceMap();
112cdf0e10cSrcweir SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter();
113cdf0e10cSrcweir
114cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
115cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
118cdf0e10cSrcweir OUString aStrAttrName;
119cdf0e10cSrcweir sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName );
120cdf0e10cSrcweir const OUString& rStrValue = xAttrList->getValueByIndex( i );
121cdf0e10cSrcweir
122cdf0e10cSrcweir switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir case XML_TOK_HATCH_NAME:
125cdf0e10cSrcweir {
126cdf0e10cSrcweir rStrName = rStrValue;
127cdf0e10cSrcweir bHasName = sal_True;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir break;
130cdf0e10cSrcweir case XML_TOK_HATCH_DISPLAY_NAME:
131cdf0e10cSrcweir aDisplayName = rStrValue;
132cdf0e10cSrcweir break;
133cdf0e10cSrcweir case XML_TOK_HATCH_STYLE:
134cdf0e10cSrcweir {
135cdf0e10cSrcweir sal_uInt16 eValue;
136cdf0e10cSrcweir bHasStyle = rUnitConverter.convertEnum( eValue, rStrValue, pXML_HatchStyle_Enum );
137cdf0e10cSrcweir if( bHasStyle )
138cdf0e10cSrcweir aHatch.Style = (drawing::HatchStyle) eValue;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir break;
141cdf0e10cSrcweir case XML_TOK_HATCH_COLOR:
142cdf0e10cSrcweir {
143cdf0e10cSrcweir Color aColor;
144cdf0e10cSrcweir bHasColor = rUnitConverter.convertColor( aColor, rStrValue );
145cdf0e10cSrcweir if( bHasColor )
146cdf0e10cSrcweir aHatch.Color = (sal_Int32)( aColor.GetColor() );
147cdf0e10cSrcweir }
148cdf0e10cSrcweir break;
149cdf0e10cSrcweir case XML_TOK_HATCH_DISTANCE:
150cdf0e10cSrcweir bHasDist = rUnitConverter.convertMeasure( (sal_Int32&)aHatch.Distance, rStrValue );
151cdf0e10cSrcweir break;
152cdf0e10cSrcweir case XML_TOK_HATCH_ROTATION:
153cdf0e10cSrcweir {
154cdf0e10cSrcweir sal_Int32 nValue;
155cdf0e10cSrcweir rUnitConverter.convertNumber( nValue, rStrValue, 0, 3600 );
156cdf0e10cSrcweir aHatch.Angle = sal_Int16( nValue );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir break;
159cdf0e10cSrcweir
160cdf0e10cSrcweir default:
161cdf0e10cSrcweir DBG_WARNING( "Unknown token at import hatch style" )
162cdf0e10cSrcweir ;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir rValue <<= aHatch;
167cdf0e10cSrcweir
168cdf0e10cSrcweir if( aDisplayName.getLength() )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_HATCH_ID, rStrName,
171cdf0e10cSrcweir aDisplayName );
172cdf0e10cSrcweir rStrName = aDisplayName;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
175cdf0e10cSrcweir bRet = bHasName && bHasStyle && bHasColor && bHasDist;
176cdf0e10cSrcweir
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir return bRet;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir
183cdf0e10cSrcweir //-------------------------------------------------------------
184cdf0e10cSrcweir // Export
185cdf0e10cSrcweir //-------------------------------------------------------------
186cdf0e10cSrcweir
187cdf0e10cSrcweir #ifndef SVX_LIGHT
188cdf0e10cSrcweir
XMLHatchStyleExport(SvXMLExport & rExp)189cdf0e10cSrcweir XMLHatchStyleExport::XMLHatchStyleExport( SvXMLExport& rExp )
190cdf0e10cSrcweir : rExport(rExp)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
~XMLHatchStyleExport()194cdf0e10cSrcweir XMLHatchStyleExport::~XMLHatchStyleExport()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
exportXML(const OUString & rStrName,const uno::Any & rValue)198cdf0e10cSrcweir sal_Bool XMLHatchStyleExport::exportXML(
199cdf0e10cSrcweir const OUString& rStrName,
200cdf0e10cSrcweir const uno::Any& rValue )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir sal_Bool bRet = sal_False;
203cdf0e10cSrcweir drawing::Hatch aHatch;
204cdf0e10cSrcweir
205cdf0e10cSrcweir if( rStrName.getLength() )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir if( rValue >>= aHatch )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir OUString aStrValue;
210cdf0e10cSrcweir OUStringBuffer aOut;
211cdf0e10cSrcweir
212cdf0e10cSrcweir SvXMLUnitConverter& rUnitConverter =
213cdf0e10cSrcweir rExport.GetMM100UnitConverter();
214cdf0e10cSrcweir
215cdf0e10cSrcweir // Style
216cdf0e10cSrcweir if( !rUnitConverter.convertEnum( aOut, aHatch.Style, pXML_HatchStyle_Enum ) )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir bRet = sal_False;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir else
221cdf0e10cSrcweir {
222cdf0e10cSrcweir // Name
223cdf0e10cSrcweir sal_Bool bEncoded = sal_False;
224cdf0e10cSrcweir rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
225cdf0e10cSrcweir rExport.EncodeStyleName( rStrName,
226cdf0e10cSrcweir &bEncoded ) );
227cdf0e10cSrcweir if( bEncoded )
228cdf0e10cSrcweir rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
229cdf0e10cSrcweir rStrName );
230cdf0e10cSrcweir
231cdf0e10cSrcweir aStrValue = aOut.makeStringAndClear();
232cdf0e10cSrcweir rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue );
233cdf0e10cSrcweir
234cdf0e10cSrcweir // Color
235cdf0e10cSrcweir rUnitConverter.convertColor( aOut, Color( aHatch.Color ) );
236cdf0e10cSrcweir aStrValue = aOut.makeStringAndClear();
237cdf0e10cSrcweir rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_COLOR, aStrValue );
238cdf0e10cSrcweir
239cdf0e10cSrcweir // Distance
240cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aHatch.Distance );
241cdf0e10cSrcweir aStrValue = aOut.makeStringAndClear();
242cdf0e10cSrcweir rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, aStrValue );
243cdf0e10cSrcweir
244cdf0e10cSrcweir // Angle
245cdf0e10cSrcweir rUnitConverter.convertNumber( aOut, sal_Int32( aHatch.Angle ) );
246cdf0e10cSrcweir aStrValue = aOut.makeStringAndClear();
247cdf0e10cSrcweir rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ROTATION, aStrValue );
248cdf0e10cSrcweir
249cdf0e10cSrcweir // Do Write
250cdf0e10cSrcweir SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_HATCH,
251cdf0e10cSrcweir sal_True, sal_False );
252cdf0e10cSrcweir }
253cdf0e10cSrcweir }
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir return bRet;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir #endif // #ifndef SVX_LIGHT
260