Line data Source code
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 :
21 : #include "XMLFootnoteSeparatorImport.hxx"
22 :
23 : #include <rtl/ustring.hxx>
24 :
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>
28 :
29 : #include <tools/debug.hxx>
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/xmlnmspe.hxx>
38 : #include <xmloff/nmspmap.hxx>
39 : #include <xmloff/maptype.hxx>
40 :
41 : #include <xmloff/PageMasterStyleMap.hxx>
42 :
43 : #include <vector>
44 :
45 :
46 : using namespace ::com::sun::star;
47 : using namespace ::xmloff::token;
48 :
49 : using ::std::vector;
50 : using ::com::sun::star::uno::Any;
51 : using ::com::sun::star::uno::Reference;
52 : using ::com::sun::star::xml::sax::XAttributeList;
53 :
54 :
55 0 : TYPEINIT1(XMLFootnoteSeparatorImport, SvXMLImportContext);
56 :
57 :
58 0 : XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
59 : SvXMLImport& rImport,
60 : sal_uInt16 nPrefix,
61 : const OUString& rLocalName,
62 : vector<XMLPropertyState> & rProps,
63 : const UniReference<XMLPropertySetMapper> & rMapperRef,
64 : sal_Int32 nIndex) :
65 : SvXMLImportContext(rImport, nPrefix, rLocalName),
66 : rProperties(rProps),
67 : rMapper(rMapperRef),
68 0 : nPropIndex(nIndex)
69 : {
70 0 : }
71 :
72 0 : XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
73 : {
74 0 : }
75 :
76 0 : void XMLFootnoteSeparatorImport::StartElement(
77 : const Reference<XAttributeList> & xAttrList)
78 : {
79 : // get the values from the properties
80 0 : sal_Int16 nLineWeight = 0;
81 0 : sal_Int32 nLineColor = 0;
82 0 : sal_Int8 nLineRelWidth = 0;
83 0 : sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust
84 0 : sal_Int32 nLineTextDistance = 0;
85 0 : sal_Int32 nLineDistance = 0;
86 0 : sal_Int8 nLineStyle = 0;
87 :
88 : // iterate over xattribute list and fill values
89 0 : sal_Int16 nLength = xAttrList->getLength();
90 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
91 : {
92 0 : OUString sLocalName;
93 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
94 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
95 0 : &sLocalName );
96 :
97 0 : if (XML_NAMESPACE_STYLE == nPrefix)
98 : {
99 0 : OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
100 : sal_Int32 nTmp;
101 0 : if (IsXMLToken( sLocalName, XML_WIDTH ))
102 : {
103 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
104 : nTmp, sAttrValue))
105 : {
106 0 : nLineWeight = (sal_Int16)nTmp;
107 : }
108 : }
109 0 : else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP ))
110 : {
111 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
112 : nTmp, sAttrValue))
113 0 : nLineTextDistance = nTmp;
114 : }
115 0 : else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP ))
116 : {
117 0 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
118 : nTmp, sAttrValue))
119 0 : nLineDistance = nTmp;
120 : }
121 0 : else if (IsXMLToken( sLocalName, XML_ADJUSTMENT ))
122 : {
123 : sal_uInt16 nTmpU;
124 : static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] =
125 : {
126 : { XML_LEFT, text::HorizontalAdjust_LEFT },
127 : { XML_CENTER, text::HorizontalAdjust_CENTER },
128 : { XML_RIGHT, text::HorizontalAdjust_RIGHT },
129 : { XML_TOKEN_INVALID, 0 }
130 : };
131 :
132 0 : if (SvXMLUnitConverter::convertEnum(
133 : nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum))
134 0 : eLineAdjust = (sal_Int16)nTmpU;
135 : }
136 0 : else if (IsXMLToken( sLocalName, XML_REL_WIDTH ))
137 : {
138 0 : if (::sax::Converter::convertPercent(nTmp, sAttrValue))
139 0 : nLineRelWidth = (sal_uInt8)nTmp;
140 : }
141 0 : else if (IsXMLToken( sLocalName, XML_COLOR ))
142 : {
143 0 : if (::sax::Converter::convertColor(nTmp, sAttrValue))
144 : {
145 0 : nLineColor = nTmp;
146 : }
147 : }
148 0 : else if (IsXMLToken( sLocalName, XML_LINE_STYLE ))
149 : {
150 : sal_uInt16 nTmpU;
151 : static const SvXMLEnumMapEntry aXML_LineStyle_Enum[] =
152 : {
153 : { XML_NONE, 0 },
154 : { XML_SOLID, 1 },
155 : { XML_DOTTED, 2 },
156 : { XML_DASH, 3 },
157 : { XML_TOKEN_INVALID, 0 }
158 : };
159 :
160 0 : if (SvXMLUnitConverter::convertEnum(
161 : nTmpU, sAttrValue, aXML_LineStyle_Enum))
162 0 : nLineStyle = (sal_Int8)nTmpU;
163 :
164 0 : }
165 : }
166 0 : }
167 :
168 : // OK, now we have all values and can fill the XMLPropertyState vector
169 0 : Any aAny;
170 : sal_Int32 nIndex;
171 :
172 0 : aAny <<= eLineAdjust;
173 0 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
174 0 : XMLPropertyState aLineAdjust( nIndex, aAny);
175 0 : rProperties.push_back(aLineAdjust);
176 :
177 0 : aAny <<= nLineColor;
178 0 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
179 0 : XMLPropertyState aLineColor( nIndex, aAny );
180 0 : rProperties.push_back(aLineColor);
181 :
182 0 : aAny <<= nLineStyle;
183 0 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_STYLE);
184 0 : XMLPropertyState aLineStyle( nIndex, aAny );
185 0 : rProperties.push_back(aLineStyle);
186 :
187 0 : aAny <<= nLineDistance;
188 0 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
189 0 : XMLPropertyState aLineDistance( nIndex, aAny );
190 0 : rProperties.push_back(aLineDistance);
191 :
192 0 : aAny <<= nLineRelWidth;
193 0 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
194 0 : XMLPropertyState aLineRelWidth( nIndex, aAny);
195 0 : rProperties.push_back(aLineRelWidth);
196 :
197 0 : aAny <<= nLineTextDistance;
198 0 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
199 0 : XMLPropertyState aLineTextDistance( nIndex, aAny);
200 0 : rProperties.push_back(aLineTextDistance);
201 :
202 : DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT) == nPropIndex,
203 : "Received wrong property map index!" );
204 0 : aAny <<= nLineWeight;
205 0 : XMLPropertyState aLineWeight( nPropIndex, aAny );
206 0 : rProperties.push_back(aLineWeight);
207 0 : }
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|