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