1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <xmloff/HatchStyle.hxx>
22 #include <com/sun/star/drawing/Hatch.hpp>
24 #include <sax/tools/converter.hxx>
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlexp.hxx>
31 #include <xmloff/xmlimp.hxx>
32 #include <rtl/ustrbuf.hxx>
33 #include <rtl/ustring.hxx>
34 #include <sal/log.hxx>
35 #include <xmloff/xmltkmap.hxx>
36 #include <xmloff/xmlement.hxx>
38 using namespace ::com::sun::star
;
40 using namespace ::xmloff::token
;
42 SvXMLEnumMapEntry
<drawing::HatchStyle
> const pXML_HatchStyle_Enum
[] =
44 { XML_SINGLE
, drawing::HatchStyle_SINGLE
},
45 { XML_DOUBLE
, drawing::HatchStyle_DOUBLE
},
46 { XML_HATCHSTYLE_TRIPLE
, drawing::HatchStyle_TRIPLE
},
47 { XML_TOKEN_INVALID
, drawing::HatchStyle(0) }
52 XMLHatchStyleImport::XMLHatchStyleImport( SvXMLImport
& rImp
)
57 void XMLHatchStyleImport::importXML(
58 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
,
62 OUString aDisplayName
;
64 drawing::Hatch aHatch
;
65 aHatch
.Style
= drawing::HatchStyle_SINGLE
;
70 SvXMLUnitConverter
& rUnitConverter
= m_rImport
.GetMM100UnitConverter();
72 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
74 switch( aIter
.getToken() )
76 case XML_ELEMENT(DRAW
, XML_NAME
):
77 case XML_ELEMENT(DRAW_OOO
, XML_NAME
):
78 rStrName
= aIter
.toString();
80 case XML_ELEMENT(DRAW
, XML_DISPLAY_NAME
):
81 case XML_ELEMENT(DRAW_OOO
, XML_DISPLAY_NAME
):
82 aDisplayName
= aIter
.toString();
84 case XML_ELEMENT(DRAW
, XML_STYLE
):
85 case XML_ELEMENT(DRAW_OOO
, XML_STYLE
):
86 SvXMLUnitConverter::convertEnum( aHatch
.Style
, aIter
.toView(), pXML_HatchStyle_Enum
);
88 case XML_ELEMENT(DRAW
, XML_COLOR
):
89 case XML_ELEMENT(DRAW_OOO
, XML_COLOR
):
90 ::sax::Converter::convertColor(aHatch
.Color
, aIter
.toView());
92 case XML_ELEMENT(DRAW
, XML_DISTANCE
):
93 case XML_ELEMENT(DRAW_OOO
, XML_DISTANCE
):
94 rUnitConverter
.convertMeasureToCore(aHatch
.Distance
, aIter
.toView());
96 case XML_ELEMENT(DRAW
, XML_ROTATION
):
97 case XML_ELEMENT(DRAW_OOO
, XML_ROTATION
):
100 if (::sax::Converter::convertNumber(nValue
, aIter
.toView(), 0, 3600))
101 aHatch
.Angle
= sal_Int16(nValue
);
105 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter
);
111 if( !aDisplayName
.isEmpty() )
113 m_rImport
.AddStyleDisplayName( XmlStyleFamily::SD_HATCH_ID
, rStrName
,
115 rStrName
= aDisplayName
;
121 XMLHatchStyleExport::XMLHatchStyleExport( SvXMLExport
& rExp
)
126 void XMLHatchStyleExport::exportXML(
127 const OUString
& rStrName
,
128 const uno::Any
& rValue
)
130 drawing::Hatch aHatch
;
132 if( rStrName
.isEmpty() )
135 if( !(rValue
>>= aHatch
) )
141 SvXMLUnitConverter
& rUnitConverter
=
142 m_rExport
.GetMM100UnitConverter();
145 if( !SvXMLUnitConverter::convertEnum( aOut
, aHatch
.Style
, pXML_HatchStyle_Enum
) )
149 bool bEncoded
= false;
150 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_NAME
,
151 m_rExport
.EncodeStyleName( rStrName
,
154 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
,
157 aStrValue
= aOut
.makeStringAndClear();
158 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_STYLE
, aStrValue
);
161 ::sax::Converter::convertColor(aOut
, aHatch
.Color
);
162 aStrValue
= aOut
.makeStringAndClear();
163 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_COLOR
, aStrValue
);
166 rUnitConverter
.convertMeasureToXML( aOut
, aHatch
.Distance
);
167 aStrValue
= aOut
.makeStringAndClear();
168 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISTANCE
, aStrValue
);
171 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_ROTATION
, OUString::number(aHatch
.Angle
) );
174 SvXMLElementExport
rElem( m_rExport
, XML_NAMESPACE_DRAW
, XML_HATCH
,
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */