1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "XMLFootnoteSeparatorImport.hxx"
23 #include <sal/log.hxx>
25 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/text/HorizontalAdjust.hpp>
29 #include <sax/tools/converter.hxx>
32 #include <xmloff/xmlimp.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <xmloff/xmlprmap.hxx>
36 #include <xmloff/xmlnamespace.hxx>
37 #include <xmloff/maptype.hxx>
38 #include <xmloff/xmlement.hxx>
40 #include <PageMasterStyleMap.hxx>
43 using namespace ::com::sun::star
;
44 using namespace ::xmloff::token
;
47 using ::com::sun::star::uno::Any
;
48 using ::com::sun::star::uno::Reference
;
51 XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
53 sal_Int32
/*nElement*/,
54 vector
<XMLPropertyState
> & rProps
,
55 rtl::Reference
<XMLPropertySetMapper
> xMapperRef
,
57 SvXMLImportContext(rImport
),
59 rMapper(std::move(xMapperRef
)),
64 XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
68 void XMLFootnoteSeparatorImport::startFastElement(
69 sal_Int32
/*nElement*/,
70 const Reference
<css::xml::sax::XFastAttributeList
> & xAttrList
)
72 // get the values from the properties
73 sal_Int16 nLineWeight
= 0;
74 sal_Int32 nLineColor
= 0;
75 sal_Int8 nLineRelWidth
= 0;
76 text::HorizontalAdjust eLineAdjust
= text::HorizontalAdjust_LEFT
;
77 sal_Int32 nLineTextDistance
= 0;
78 sal_Int32 nLineDistance
= 0;
80 // Default separator line style should be SOLID (used to be default before
81 // the choice selector was available)
82 sal_Int8 nLineStyle
= 1;
84 // iterate over xattribute list and fill values
85 for (auto &aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
88 switch (aIter
.getToken())
90 case XML_ELEMENT(STYLE
, XML_WIDTH
):
92 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
93 nTmp
, aIter
.toView()))
95 nLineWeight
= static_cast<sal_Int16
>(nTmp
);
99 case XML_ELEMENT(STYLE
, XML_DISTANCE_BEFORE_SEP
):
101 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
102 nTmp
, aIter
.toView()))
103 nLineTextDistance
= nTmp
;
106 case XML_ELEMENT(STYLE
, XML_DISTANCE_AFTER_SEP
):
108 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
109 nTmp
, aIter
.toView()))
110 nLineDistance
= nTmp
;
113 case XML_ELEMENT(STYLE
, XML_ADJUSTMENT
):
115 static const SvXMLEnumMapEntry
<text::HorizontalAdjust
> aXML_HorizontalAdjust_Enum
[] =
117 { XML_LEFT
, text::HorizontalAdjust_LEFT
},
118 { XML_CENTER
, text::HorizontalAdjust_CENTER
},
119 { XML_RIGHT
, text::HorizontalAdjust_RIGHT
},
120 { XML_TOKEN_INVALID
, text::HorizontalAdjust(0) }
123 SvXMLUnitConverter::convertEnum(
124 eLineAdjust
, aIter
.toView(), aXML_HorizontalAdjust_Enum
);
127 case XML_ELEMENT(STYLE
, XML_REL_WIDTH
):
129 if (::sax::Converter::convertPercent(nTmp
, aIter
.toView()))
130 nLineRelWidth
= static_cast<sal_uInt8
>(nTmp
);
133 case XML_ELEMENT(STYLE
, XML_COLOR
):
135 if (::sax::Converter::convertColor(nTmp
, aIter
.toView()))
141 case XML_ELEMENT(STYLE
, XML_LINE_STYLE
):
143 static const SvXMLEnumMapEntry
<sal_Int8
> aXML_LineStyle_Enum
[] =
149 { XML_TOKEN_INVALID
, 0 }
152 SvXMLUnitConverter::convertEnum(nLineStyle
, aIter
.toView(), aXML_LineStyle_Enum
);
156 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
160 // OK, now we have all values and can fill the XMLPropertyState vector
163 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST
);
164 XMLPropertyState
aLineAdjust( nIndex
, uno::Any(sal_Int16(eLineAdjust
)) );
165 rProperties
.push_back(aLineAdjust
);
167 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_COLOR
);
168 XMLPropertyState
aLineColor( nIndex
, uno::Any(nLineColor
) );
169 rProperties
.push_back(aLineColor
);
171 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_STYLE
);
172 XMLPropertyState
aLineStyle( nIndex
, uno::Any(nLineStyle
) );
173 rProperties
.push_back(aLineStyle
);
175 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_DISTANCE
);
176 XMLPropertyState
aLineDistance( nIndex
, uno::Any(nLineDistance
) );
177 rProperties
.push_back(aLineDistance
);
179 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH
);
180 XMLPropertyState
aLineRelWidth( nIndex
, uno::Any(nLineRelWidth
));
181 rProperties
.push_back(aLineRelWidth
);
183 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE
);
184 XMLPropertyState
aLineTextDistance( nIndex
, uno::Any(nLineTextDistance
));
185 rProperties
.push_back(aLineTextDistance
);
187 SAL_WARN_IF( rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT
) != nPropIndex
, "xmloff",
188 "Received wrong property map index!" );
189 XMLPropertyState
aLineWeight( nPropIndex
, uno::Any(nLineWeight
) );
190 rProperties
.push_back(aLineWeight
);
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */