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 
24 #include <sax/tools/converter.hxx>
25 
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>
37 
38 using namespace ::com::sun::star;
39 
40 using 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  : rImport(rImp)
54 {
55 }
56 
58 {
59 }
60 
62  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
63  uno::Any& rValue,
64  OUString& rStrName )
65 {
66  OUString aDisplayName;
67 
68  drawing::Hatch aHatch;
69  aHatch.Style = drawing::HatchStyle_SINGLE;
70  aHatch.Color = 0;
71  aHatch.Distance = 0;
72  aHatch.Angle = 0;
73 
75 
76  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
77  {
78  switch( aIter.getToken() )
79  {
80  case XML_ELEMENT(DRAW, XML_NAME):
81  case XML_ELEMENT(DRAW_OOO, XML_NAME):
82  rStrName = aIter.toString();
83  break;
85  case XML_ELEMENT(DRAW_OOO, XML_DISPLAY_NAME):
86  aDisplayName = aIter.toString();
87  break;
88  case XML_ELEMENT(DRAW, XML_STYLE):
89  case XML_ELEMENT(DRAW_OOO, XML_STYLE):
90  SvXMLUnitConverter::convertEnum( aHatch.Style, aIter.toView(), pXML_HatchStyle_Enum );
91  break;
92  case XML_ELEMENT(DRAW, XML_COLOR):
93  case XML_ELEMENT(DRAW_OOO, XML_COLOR):
94  ::sax::Converter::convertColor(aHatch.Color, aIter.toString());
95  break;
97  case XML_ELEMENT(DRAW_OOO, XML_DISTANCE):
98  rUnitConverter.convertMeasureToCore(aHatch.Distance, aIter.toView());
99  break;
101  case XML_ELEMENT(DRAW_OOO, XML_ROTATION):
102  {
103  sal_Int32 nValue;
104  if (::sax::Converter::convertNumber(nValue, aIter.toView(), 0, 3600))
105  aHatch.Angle = sal_Int16(nValue);
106  break;
107  }
108  default:
109  XMLOFF_WARN_UNKNOWN("xmloff.style", aIter);
110  }
111  }
112 
113  rValue <<= aHatch;
114 
115  if( !aDisplayName.isEmpty() )
116  {
118  aDisplayName );
119  rStrName = aDisplayName;
120  }
121 }
122 
123 // Export
124 
126  : rExport(rExp)
127 {
128 }
129 
131 {
132 }
133 
135  const OUString& rStrName,
136  const uno::Any& rValue )
137 {
138  drawing::Hatch aHatch;
139 
140  if( rStrName.isEmpty() )
141  return;
142 
143  if( !(rValue >>= aHatch) )
144  return;
145 
146  OUString aStrValue;
147  OUStringBuffer aOut;
148 
149  SvXMLUnitConverter& rUnitConverter =
151 
152  // Style
153  if( !SvXMLUnitConverter::convertEnum( aOut, aHatch.Style, pXML_HatchStyle_Enum ) )
154  return;
155 
156  // Name
157  bool bEncoded = false;
159  rExport.EncodeStyleName( rStrName,
160  &bEncoded ) );
161  if( bEncoded )
163  rStrName );
164 
165  aStrValue = aOut.makeStringAndClear();
167 
168  // Color
169  ::sax::Converter::convertColor(aOut, aHatch.Color);
170  aStrValue = aOut.makeStringAndClear();
172 
173  // Distance
174  rUnitConverter.convertMeasureToXML( aOut, aHatch.Distance );
175  aStrValue = aOut.makeStringAndClear();
177 
178  // Angle
179  rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ROTATION, OUString::number(aHatch.Angle) );
180 
181  // Do Write
183  true, false );
184 }
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:186
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:82
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:400
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
DRAW
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
XMLHatchStyleImport(SvXMLImport &rImport)
Definition: HatchStyle.cxx:52
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:938
constexpr sal_uInt16 XML_NAMESPACE_DRAW
XMLHatchStyleExport(SvXMLExport &rExport)
Definition: HatchStyle.cxx:125
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
SvXMLExport & rExport
Definition: HatchStyle.hxx:53
void importXML(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Any &rValue, OUString &rStrName)
Definition: HatchStyle.cxx:61
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmlexp.cxx:1981
void exportXML(const OUString &rStrName, const css::uno::Any &rValue)
Definition: HatchStyle.cxx:134
SvXMLEnumMapEntry< drawing::HatchStyle > const pXML_HatchStyle_Enum[]
Definition: HatchStyle.cxx:42
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:39
Handling of tokens in XML:
SvXMLImport & rImport
Definition: HatchStyle.hxx:39
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
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
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:400
void AddStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName, const OUString &rDisplayName)
Definition: xmlimp.cxx:1375
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:206
sal_Int16 nValue
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)