LibreOffice Module xmloff (master)  1
XMLFootnoteSeparatorImport.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 
22 
23 #include <rtl/ustring.hxx>
24 #include <sal/log.hxx>
25 
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 #include <com/sun/star/text/HorizontalAdjust.hpp>
29 
30 
31 #include <sax/tools/converter.hxx>
32 
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlprmap.hxx>
37 #include <xmloff/xmlnamespace.hxx>
38 #include <xmloff/namespacemap.hxx>
39 #include <xmloff/maptype.hxx>
40 #include <xmloff/xmlement.hxx>
41 
42 #include <PageMasterStyleMap.hxx>
43 
44 #include <vector>
45 
46 
47 using namespace ::com::sun::star;
48 using namespace ::xmloff::token;
49 
50 using ::std::vector;
51 using ::com::sun::star::uno::Any;
52 using ::com::sun::star::uno::Reference;
53 using ::com::sun::star::xml::sax::XAttributeList;
54 
55 
57  SvXMLImport& rImport,
58  sal_Int32 /*nElement*/,
59  vector<XMLPropertyState> & rProps,
60  const rtl::Reference<XMLPropertySetMapper> & rMapperRef,
61  sal_Int32 nIndex) :
62  SvXMLImportContext(rImport),
63  rProperties(rProps),
64  rMapper(rMapperRef),
65  nPropIndex(nIndex)
66 {
67 }
68 
70 {
71 }
72 
74  sal_Int32 /*nElement*/,
75  const Reference<css::xml::sax::XFastAttributeList> & xAttrList)
76 {
77  // get the values from the properties
78  sal_Int16 nLineWeight = 0;
79  sal_Int32 nLineColor = 0;
80  sal_Int8 nLineRelWidth = 0;
81  text::HorizontalAdjust eLineAdjust = text::HorizontalAdjust_LEFT;
82  sal_Int32 nLineTextDistance = 0;
83  sal_Int32 nLineDistance = 0;
84 
85  // Default separator line style should be SOLID (used to be default before
86  // the choice selector was available)
87  sal_Int8 nLineStyle = 1;
88 
89  // iterate over xattribute list and fill values
90  for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
91  {
92  sal_Int32 nTmp;
93  switch (aIter.getToken())
94  {
96  {
97  if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
98  nTmp, aIter.toView()))
99  {
100  nLineWeight = static_cast<sal_Int16>(nTmp);
101  }
102  break;
103  }
105  {
106  if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
107  nTmp, aIter.toView()))
108  nLineTextDistance = nTmp;
109  break;
110  }
112  {
113  if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
114  nTmp, aIter.toView()))
115  nLineDistance = nTmp;
116  break;
117  }
119  {
121  {
122  { XML_LEFT, text::HorizontalAdjust_LEFT },
123  { XML_CENTER, text::HorizontalAdjust_CENTER },
124  { XML_RIGHT, text::HorizontalAdjust_RIGHT },
125  { XML_TOKEN_INVALID, text::HorizontalAdjust(0) }
126  };
127 
129  eLineAdjust, aIter.toView(), aXML_HorizontalAdjust_Enum);
130  break;
131  }
133  {
134  if (::sax::Converter::convertPercent(nTmp, aIter.toView()))
135  nLineRelWidth = static_cast<sal_uInt8>(nTmp);
136  break;
137  }
138  case XML_ELEMENT(STYLE, XML_COLOR):
139  {
140  if (::sax::Converter::convertColor(nTmp, aIter.toView()))
141  {
142  nLineColor = nTmp;
143  }
144  break;
145  }
147  {
148  static const SvXMLEnumMapEntry<sal_Int8> aXML_LineStyle_Enum[] =
149  {
150  { XML_NONE, 0 },
151  { XML_SOLID, 1 },
152  { XML_DOTTED, 2 },
153  { XML_DASH, 3 },
154  { XML_TOKEN_INVALID, 0 }
155  };
156 
157  SvXMLUnitConverter::convertEnum(nLineStyle, aIter.toView(), aXML_LineStyle_Enum);
158  break;
159  }
160  default:
161  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
162  }
163  }
164 
165  // OK, now we have all values and can fill the XMLPropertyState vector
166  sal_Int32 nIndex;
167 
168  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
169  XMLPropertyState aLineAdjust( nIndex, uno::Any(sal_Int16(eLineAdjust)) );
170  rProperties.push_back(aLineAdjust);
171 
172  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
173  XMLPropertyState aLineColor( nIndex, uno::Any(nLineColor) );
174  rProperties.push_back(aLineColor);
175 
176  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_STYLE);
177  XMLPropertyState aLineStyle( nIndex, uno::Any(nLineStyle) );
178  rProperties.push_back(aLineStyle);
179 
180  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
181  XMLPropertyState aLineDistance( nIndex, uno::Any(nLineDistance) );
182  rProperties.push_back(aLineDistance);
183 
184  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
185  XMLPropertyState aLineRelWidth( nIndex, uno::Any(nLineRelWidth));
186  rProperties.push_back(aLineRelWidth);
187 
188  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
189  XMLPropertyState aLineTextDistance( nIndex, uno::Any(nLineTextDistance));
190  rProperties.push_back(aLineTextDistance);
191 
192  SAL_WARN_IF( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT) != nPropIndex, "xmloff",
193  "Received wrong property map index!" );
194  XMLPropertyState aLineWeight( nPropIndex, uno::Any(nLineWeight) );
195  rProperties.push_back(aLineWeight);
196 }
197 
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &) override
XMLFootnoteSeparatorImport(SvXMLImport &rImport, sal_Int32 nElement,::std::vector< XMLPropertyState > &rProperties, const rtl::Reference< XMLPropertySetMapper > &rMapperRef, sal_Int32 nIndex)
#define CTF_PM_FTN_LINE_ADJUST
signed char sal_Int8
#define CTF_PM_FTN_LINE_WEIGHT
#define CTF_PM_FTN_LINE_COLOR
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
#define CTF_PM_FTN_LINE_WIDTH
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
#define CTF_PM_FTN_LINE_STYLE
#define CTF_PM_FTN_DISTANCE
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
rtl::Reference< XMLPropertySetMapper > rMapper
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:39
#define SAL_WARN_IF(condition, area, stream)
unsigned char sal_uInt8
#define CTF_PM_FTN_LINE_DISTANCE
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:122
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
SvXMLEnumMapEntry< text::HorizontalAdjust > const aXML_HorizontalAdjust_Enum[]
Definition: prhdlfac.cxx:74
::std::vector< XMLPropertyState > & rProperties