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 <rtl/ustring.hxx>
25 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/xml/sax/XAttributeList.hpp>
27 #include <com/sun/star/text/HorizontalAdjust.hpp>
29 #include <tools/debug.hxx>
31 #include <sax/tools/converter.hxx>
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlprmap.hxx>
37 #include <xmloff/xmlnmspe.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/maptype.hxx>
41 #include <xmloff/PageMasterStyleMap.hxx>
46 using namespace ::com::sun::star
;
47 using namespace ::xmloff::token
;
50 using ::com::sun::star::uno::Any
;
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::xml::sax::XAttributeList
;
55 TYPEINIT1(XMLFootnoteSeparatorImport
, SvXMLImportContext
);
58 XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
61 const OUString
& rLocalName
,
62 vector
<XMLPropertyState
> & rProps
,
63 const rtl::Reference
<XMLPropertySetMapper
> & rMapperRef
,
65 SvXMLImportContext(rImport
, nPrefix
, rLocalName
),
72 XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
76 void XMLFootnoteSeparatorImport::StartElement(
77 const Reference
<XAttributeList
> & xAttrList
)
79 // get the values from the properties
80 sal_Int16 nLineWeight
= 0;
81 sal_Int32 nLineColor
= 0;
82 sal_Int8 nLineRelWidth
= 0;
83 sal_Int16 eLineAdjust
= text::HorizontalAdjust_LEFT
; // enum text::HorizontalAdjust
84 sal_Int32 nLineTextDistance
= 0;
85 sal_Int32 nLineDistance
= 0;
86 sal_Int8 nLineStyle
= 0;
88 // iterate over xattribute list and fill values
89 sal_Int16 nLength
= xAttrList
->getLength();
90 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
93 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
94 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
97 if (XML_NAMESPACE_STYLE
== nPrefix
)
99 OUString sAttrValue
= xAttrList
->getValueByIndex(nAttr
);
101 if (IsXMLToken( sLocalName
, XML_WIDTH
))
103 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
106 nLineWeight
= (sal_Int16
)nTmp
;
109 else if (IsXMLToken( sLocalName
, XML_DISTANCE_BEFORE_SEP
))
111 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
113 nLineTextDistance
= nTmp
;
115 else if (IsXMLToken( sLocalName
, XML_DISTANCE_AFTER_SEP
))
117 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
119 nLineDistance
= nTmp
;
121 else if (IsXMLToken( sLocalName
, XML_ADJUSTMENT
))
124 static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum
[] =
126 { XML_LEFT
, text::HorizontalAdjust_LEFT
},
127 { XML_CENTER
, text::HorizontalAdjust_CENTER
},
128 { XML_RIGHT
, text::HorizontalAdjust_RIGHT
},
129 { XML_TOKEN_INVALID
, 0 }
132 if (SvXMLUnitConverter::convertEnum(
133 nTmpU
, sAttrValue
, aXML_HorizontalAdjust_Enum
))
134 eLineAdjust
= (sal_Int16
)nTmpU
;
136 else if (IsXMLToken( sLocalName
, XML_REL_WIDTH
))
138 if (::sax::Converter::convertPercent(nTmp
, sAttrValue
))
139 nLineRelWidth
= (sal_uInt8
)nTmp
;
141 else if (IsXMLToken( sLocalName
, XML_COLOR
))
143 if (::sax::Converter::convertColor(nTmp
, sAttrValue
))
148 else if (IsXMLToken( sLocalName
, XML_LINE_STYLE
))
151 static const SvXMLEnumMapEntry aXML_LineStyle_Enum
[] =
157 { XML_TOKEN_INVALID
, 0 }
160 if (SvXMLUnitConverter::convertEnum(
161 nTmpU
, sAttrValue
, aXML_LineStyle_Enum
))
162 nLineStyle
= (sal_Int8
)nTmpU
;
168 // OK, now we have all values and can fill the XMLPropertyState vector
172 aAny
<<= eLineAdjust
;
173 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST
);
174 XMLPropertyState
aLineAdjust( nIndex
, aAny
);
175 rProperties
.push_back(aLineAdjust
);
178 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_COLOR
);
179 XMLPropertyState
aLineColor( nIndex
, aAny
);
180 rProperties
.push_back(aLineColor
);
183 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_STYLE
);
184 XMLPropertyState
aLineStyle( nIndex
, aAny
);
185 rProperties
.push_back(aLineStyle
);
187 aAny
<<= nLineDistance
;
188 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_DISTANCE
);
189 XMLPropertyState
aLineDistance( nIndex
, aAny
);
190 rProperties
.push_back(aLineDistance
);
192 aAny
<<= nLineRelWidth
;
193 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH
);
194 XMLPropertyState
aLineRelWidth( nIndex
, aAny
);
195 rProperties
.push_back(aLineRelWidth
);
197 aAny
<<= nLineTextDistance
;
198 nIndex
= rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE
);
199 XMLPropertyState
aLineTextDistance( nIndex
, aAny
);
200 rProperties
.push_back(aLineTextDistance
);
202 DBG_ASSERT( rMapper
->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT
) == nPropIndex
,
203 "Received wrong property map index!" );
204 aAny
<<= nLineWeight
;
205 XMLPropertyState
aLineWeight( nPropIndex
, aAny
);
206 rProperties
.push_back(aLineWeight
);
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */