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: HatchStyle.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 "HatchStyle.hxx"
34 #include <com/sun/star/drawing/Hatch.hpp>
35 #include <xmloff/nmspmap.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include "xmlnmspe.hxx"
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmlexp.hxx>
40 #include <xmloff/xmlimp.hxx>
41 #include <rtl/ustrbuf.hxx>
42 #include <rtl/ustring.hxx>
43 #include <tools/debug.hxx>
44 #include <xmloff/xmltkmap.hxx>
46 using namespace ::com::sun::star
;
47 using ::rtl::OUString
;
48 using ::rtl::OUStringBuffer
;
50 using namespace ::xmloff::token
;
52 enum SvXMLTokenMapAttrs
55 XML_TOK_HATCH_DISPLAY_NAME
,
58 XML_TOK_HATCH_DISTANCE
,
59 XML_TOK_HATCH_ROTATION
,
60 XML_TOK_TABSTOP_END
=XML_TOK_UNKNOWN
64 SvXMLEnumMapEntry __READONLY_DATA pXML_HatchStyle_Enum
[] =
66 { XML_HATCHSTYLE_SINGLE
, drawing::HatchStyle_SINGLE
},
67 { XML_HATCHSTYLE_DOUBLE
, drawing::HatchStyle_DOUBLE
},
68 { XML_HATCHSTYLE_TRIPLE
, drawing::HatchStyle_TRIPLE
},
69 { XML_TOKEN_INVALID
, 0 }
73 //-------------------------------------------------------------
75 //-------------------------------------------------------------
77 XMLHatchStyleImport::XMLHatchStyleImport( SvXMLImport
& rImp
)
82 XMLHatchStyleImport::~XMLHatchStyleImport()
86 sal_Bool
XMLHatchStyleImport::importXML(
87 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
91 sal_Bool bRet
= sal_False
;
93 sal_Bool bHasName
= sal_False
;
94 sal_Bool bHasStyle
= sal_False
;
95 sal_Bool bHasColor
= sal_False
;
96 sal_Bool bHasDist
= sal_False
;
97 OUString aDisplayName
;
99 drawing::Hatch aHatch
;
100 aHatch
.Style
= drawing::HatchStyle_SINGLE
;
106 static __FAR_DATA SvXMLTokenMapEntry aHatchAttrTokenMap
[] =
108 { XML_NAMESPACE_DRAW
, XML_NAME
, XML_TOK_HATCH_NAME
},
109 { XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
, XML_TOK_HATCH_DISPLAY_NAME
},
110 { XML_NAMESPACE_DRAW
, XML_STYLE
, XML_TOK_HATCH_STYLE
},
111 { XML_NAMESPACE_DRAW
, XML_COLOR
, XML_TOK_HATCH_COLOR
},
112 { XML_NAMESPACE_DRAW
, XML_HATCH_DISTANCE
, XML_TOK_HATCH_DISTANCE
},
113 { XML_NAMESPACE_DRAW
, XML_ROTATION
, XML_TOK_HATCH_ROTATION
},
117 SvXMLTokenMap
aTokenMap( aHatchAttrTokenMap
);
118 SvXMLNamespaceMap rNamespaceMap
= rImport
.GetNamespaceMap();
119 SvXMLUnitConverter
& rUnitConverter
= rImport
.GetMM100UnitConverter();
121 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
122 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
124 const OUString
& rFullAttrName
= xAttrList
->getNameByIndex( i
);
125 OUString aStrAttrName
;
126 sal_uInt16 nPrefix
= rNamespaceMap
.GetKeyByAttrName( rFullAttrName
, &aStrAttrName
);
127 const OUString
& rStrValue
= xAttrList
->getValueByIndex( i
);
129 switch( aTokenMap
.Get( nPrefix
, aStrAttrName
) )
131 case XML_TOK_HATCH_NAME
:
133 rStrName
= rStrValue
;
137 case XML_TOK_HATCH_DISPLAY_NAME
:
138 aDisplayName
= rStrValue
;
140 case XML_TOK_HATCH_STYLE
:
143 bHasStyle
= rUnitConverter
.convertEnum( eValue
, rStrValue
, pXML_HatchStyle_Enum
);
145 aHatch
.Style
= (drawing::HatchStyle
) eValue
;
148 case XML_TOK_HATCH_COLOR
:
151 bHasColor
= rUnitConverter
.convertColor( aColor
, rStrValue
);
153 aHatch
.Color
= (sal_Int32
)( aColor
.GetColor() );
156 case XML_TOK_HATCH_DISTANCE
:
157 bHasDist
= rUnitConverter
.convertMeasure( (sal_Int32
&)aHatch
.Distance
, rStrValue
);
159 case XML_TOK_HATCH_ROTATION
:
162 rUnitConverter
.convertNumber( nValue
, rStrValue
, 0, 360 );
163 aHatch
.Angle
= sal_Int16( nValue
);
168 DBG_WARNING( "Unknown token at import hatch style" )
175 if( aDisplayName
.getLength() )
177 rImport
.AddStyleDisplayName( XML_STYLE_FAMILY_SD_HATCH_ID
, rStrName
,
179 rStrName
= aDisplayName
;
182 bRet
= bHasName
&& bHasStyle
&& bHasColor
&& bHasDist
;
190 //-------------------------------------------------------------
192 //-------------------------------------------------------------
196 XMLHatchStyleExport::XMLHatchStyleExport( SvXMLExport
& rExp
)
201 XMLHatchStyleExport::~XMLHatchStyleExport()
205 sal_Bool
XMLHatchStyleExport::exportXML(
206 const OUString
& rStrName
,
207 const uno::Any
& rValue
)
209 sal_Bool bRet
= sal_False
;
210 drawing::Hatch aHatch
;
212 if( rStrName
.getLength() )
214 if( rValue
>>= aHatch
)
219 SvXMLUnitConverter
& rUnitConverter
=
220 rExport
.GetMM100UnitConverter();
223 if( !rUnitConverter
.convertEnum( aOut
, aHatch
.Style
, pXML_HatchStyle_Enum
) )
230 sal_Bool bEncoded
= sal_False
;
231 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_NAME
,
232 rExport
.EncodeStyleName( rStrName
,
235 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
,
238 aStrValue
= aOut
.makeStringAndClear();
239 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_STYLE
, aStrValue
);
242 rUnitConverter
.convertColor( aOut
, Color( aHatch
.Color
) );
243 aStrValue
= aOut
.makeStringAndClear();
244 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_COLOR
, aStrValue
);
247 rUnitConverter
.convertMeasure( aOut
, aHatch
.Distance
);
248 aStrValue
= aOut
.makeStringAndClear();
249 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_HATCH_DISTANCE
, aStrValue
);
252 rUnitConverter
.convertNumber( aOut
, sal_Int32( aHatch
.Angle
) );
253 aStrValue
= aOut
.makeStringAndClear();
254 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_ROTATION
, aStrValue
);
257 SvXMLElementExport
rElem( rExport
, XML_NAMESPACE_DRAW
, XML_HATCH
,
258 sal_True
, sal_False
);
266 #endif // #ifndef SVX_LIGHT