bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / style / HatchStyle.cxx
blob2a0bc22597576882765fff28906cae506a856782
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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) }
50 // Import
52 XMLHatchStyleImport::XMLHatchStyleImport( SvXMLImport& rImp )
53 : m_rImport(rImp)
57 void XMLHatchStyleImport::importXML(
58 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
59 uno::Any& rValue,
60 OUString& rStrName )
62 OUString aDisplayName;
64 drawing::Hatch aHatch;
65 aHatch.Style = drawing::HatchStyle_SINGLE;
66 aHatch.Color = 0;
67 aHatch.Distance = 0;
68 aHatch.Angle = 0;
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();
79 break;
80 case XML_ELEMENT(DRAW, XML_DISPLAY_NAME):
81 case XML_ELEMENT(DRAW_OOO, XML_DISPLAY_NAME):
82 aDisplayName = aIter.toString();
83 break;
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 );
87 break;
88 case XML_ELEMENT(DRAW, XML_COLOR):
89 case XML_ELEMENT(DRAW_OOO, XML_COLOR):
90 ::sax::Converter::convertColor(aHatch.Color, aIter.toView());
91 break;
92 case XML_ELEMENT(DRAW, XML_DISTANCE):
93 case XML_ELEMENT(DRAW_OOO, XML_DISTANCE):
94 rUnitConverter.convertMeasureToCore(aHatch.Distance, aIter.toView());
95 break;
96 case XML_ELEMENT(DRAW, XML_ROTATION):
97 case XML_ELEMENT(DRAW_OOO, XML_ROTATION):
99 sal_Int32 nValue;
100 if (::sax::Converter::convertNumber(nValue, aIter.toView(), 0, 3600))
101 aHatch.Angle = sal_Int16(nValue);
102 break;
104 default:
105 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter);
109 rValue <<= aHatch;
111 if( !aDisplayName.isEmpty() )
113 m_rImport.AddStyleDisplayName( XmlStyleFamily::SD_HATCH_ID, rStrName,
114 aDisplayName );
115 rStrName = aDisplayName;
119 // Export
121 XMLHatchStyleExport::XMLHatchStyleExport( SvXMLExport& rExp )
122 : m_rExport(rExp)
126 void XMLHatchStyleExport::exportXML(
127 const OUString& rStrName,
128 const uno::Any& rValue )
130 drawing::Hatch aHatch;
132 if( rStrName.isEmpty() )
133 return;
135 if( !(rValue >>= aHatch) )
136 return;
138 OUString aStrValue;
139 OUStringBuffer aOut;
141 SvXMLUnitConverter& rUnitConverter =
142 m_rExport.GetMM100UnitConverter();
144 // Style
145 if( !SvXMLUnitConverter::convertEnum( aOut, aHatch.Style, pXML_HatchStyle_Enum ) )
146 return;
148 // Name
149 bool bEncoded = false;
150 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
151 m_rExport.EncodeStyleName( rStrName,
152 &bEncoded ) );
153 if( bEncoded )
154 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
155 rStrName );
157 aStrValue = aOut.makeStringAndClear();
158 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue );
160 // Color
161 ::sax::Converter::convertColor(aOut, aHatch.Color);
162 aStrValue = aOut.makeStringAndClear();
163 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_COLOR, aStrValue );
165 // Distance
166 rUnitConverter.convertMeasureToXML( aOut, aHatch.Distance );
167 aStrValue = aOut.makeStringAndClear();
168 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISTANCE, aStrValue );
170 // Angle
171 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ROTATION, OUString::number(aHatch.Angle) );
173 // Do Write
174 SvXMLElementExport rElem( m_rExport, XML_NAMESPACE_DRAW, XML_HATCH,
175 true, false );
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */