LibreOffice Module xmloff (master) 1
HatchStyle.cxx
Go to the documentation of this file.
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 <xmloff/HatchStyle.hxx>
21
22#include <com/sun/star/drawing/Hatch.hpp>
23
25
27#include <xmloff/xmluconv.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>
37
38using namespace ::com::sun::star;
39
40using namespace ::xmloff::token;
41
43{
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) }
48};
49
50// Import
51
53 : m_rImport(rImp)
54{
55}
56
58 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
59 uno::Any& rValue,
60 OUString& rStrName )
61{
62 OUString aDisplayName;
63
64 drawing::Hatch aHatch;
65 aHatch.Style = drawing::HatchStyle_SINGLE;
66 aHatch.Color = 0;
67 aHatch.Distance = 0;
68 aHatch.Angle = 0;
69
70 SvXMLUnitConverter& rUnitConverter = m_rImport.GetMM100UnitConverter();
71
72 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
73 {
74 switch( aIter.getToken() )
75 {
77 case XML_ELEMENT(DRAW_OOO, XML_NAME):
78 rStrName = aIter.toString();
79 break;
81 case XML_ELEMENT(DRAW_OOO, XML_DISPLAY_NAME):
82 aDisplayName = aIter.toString();
83 break;
85 case XML_ELEMENT(DRAW_OOO, XML_STYLE):
86 SvXMLUnitConverter::convertEnum( aHatch.Style, aIter.toView(), pXML_HatchStyle_Enum );
87 break;
89 case XML_ELEMENT(DRAW_OOO, XML_COLOR):
90 ::sax::Converter::convertColor(aHatch.Color, aIter.toView());
91 break;
93 case XML_ELEMENT(DRAW_OOO, XML_DISTANCE):
94 rUnitConverter.convertMeasureToCore(aHatch.Distance, aIter.toView());
95 break;
97 case XML_ELEMENT(DRAW_OOO, XML_ROTATION):
98 {
99 sal_Int32 nValue;
100 if (::sax::Converter::convertNumber(nValue, aIter.toView(), 0, 3600))
101 aHatch.Angle = sal_Int16(nValue);
102 break;
103 }
104 default:
105 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter);
106 }
107 }
108
109 rValue <<= aHatch;
110
111 if( !aDisplayName.isEmpty() )
112 {
113 m_rImport.AddStyleDisplayName( XmlStyleFamily::SD_HATCH_ID, rStrName,
114 aDisplayName );
115 rStrName = aDisplayName;
116 }
117}
118
119// Export
120
122 : m_rExport(rExp)
123{
124}
125
127 const OUString& rStrName,
128 const uno::Any& rValue )
129{
130 drawing::Hatch aHatch;
131
132 if( rStrName.isEmpty() )
133 return;
134
135 if( !(rValue >>= aHatch) )
136 return;
137
138 OUString aStrValue;
139 OUStringBuffer aOut;
140
141 SvXMLUnitConverter& rUnitConverter =
143
144 // Style
145 if( !SvXMLUnitConverter::convertEnum( aOut, aHatch.Style, pXML_HatchStyle_Enum ) )
146 return;
147
148 // Name
149 bool bEncoded = false;
151 m_rExport.EncodeStyleName( rStrName,
152 &bEncoded ) );
153 if( bEncoded )
155 rStrName );
156
157 aStrValue = aOut.makeStringAndClear();
159
160 // Color
161 ::sax::Converter::convertColor(aOut, aHatch.Color);
162 aStrValue = aOut.makeStringAndClear();
164
165 // Distance
166 rUnitConverter.convertMeasureToXML( aOut, aHatch.Distance );
167 aStrValue = aOut.makeStringAndClear();
169
170 // Angle
171 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ROTATION, OUString::number(aHatch.Angle) );
172
173 // Do Write
175 true, false );
176}
177
178/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLEnumMapEntry< drawing::HatchStyle > const pXML_HatchStyle_Enum[]
Definition: HatchStyle.cxx:42
const SvXMLImport & m_rImport
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmlexp.cxx:1934
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:391
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:145
bool convertMeasureToCore(sal_Int32 &rValue, std::u16string_view rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
convert string to measure with meCoreMeasureUnit, using optional min and max values
Definition: xmluconv.cxx:188
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:208
void exportXML(const OUString &rStrName, const css::uno::Any &rValue)
Definition: HatchStyle.cxx:126
XMLHatchStyleExport(SvXMLExport &rExport)
Definition: HatchStyle.cxx:121
SvXMLExport & m_rExport
Definition: HatchStyle.hxx:51
XMLHatchStyleImport(SvXMLImport &rImport)
Definition: HatchStyle.cxx:52
SvXMLImport & m_rImport
Definition: HatchStyle.hxx:38
void importXML(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Any &rValue, OUString &rStrName)
Definition: HatchStyle.cxx:57
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
DRAW
sal_Int16 nValue
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
constexpr sal_uInt16 XML_NAMESPACE_DRAW