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 900 : XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
59 : SvXMLImport& rImport,
60 : sal_uInt16 nPrefix,
61 : const OUString& rLocalName,
62 : vector<XMLPropertyState> & rProps,
63 : const rtl::Reference<XMLPropertySetMapper> & rMapperRef,
64 : sal_Int32 nIndex) :
65 : SvXMLImportContext(rImport, nPrefix, rLocalName),
66 : rProperties(rProps),
67 : rMapper(rMapperRef),
68 900 : nPropIndex(nIndex)
69 : {
70 900 : }
71 :
72 1800 : XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
73 : {
74 1800 : }
75 :
76 900 : void XMLFootnoteSeparatorImport::StartElement(
77 : const Reference<XAttributeList> & xAttrList)
78 : {
79 : // get the values from the properties
80 900 : sal_Int16 nLineWeight = 0;
81 900 : sal_Int32 nLineColor = 0;
82 900 : sal_Int8 nLineRelWidth = 0;
83 900 : sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust
84 900 : sal_Int32 nLineTextDistance = 0;
85 900 : sal_Int32 nLineDistance = 0;
86 900 : sal_Int8 nLineStyle = 0;
87 :
88 : // iterate over xattribute list and fill values
89 900 : sal_Int16 nLength = xAttrList->getLength();
90 6152 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
91 : {
92 5252 : OUString sLocalName;
93 5252 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
94 5252 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
95 10504 : &sLocalName );
96 :
97 5252 : if (XML_NAMESPACE_STYLE == nPrefix)
98 : {
99 5252 : OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
100 : sal_Int32 nTmp;
101 5252 : if (IsXMLToken( sLocalName, XML_WIDTH ))
102 : {
103 728 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
104 : nTmp, sAttrValue))
105 : {
106 728 : nLineWeight = (sal_Int16)nTmp;
107 : }
108 : }
109 4524 : else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP ))
110 : {
111 728 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
112 : nTmp, sAttrValue))
113 728 : nLineTextDistance = nTmp;
114 : }
115 3796 : else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP ))
116 : {
117 728 : if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
118 : nTmp, sAttrValue))
119 728 : nLineDistance = nTmp;
120 : }
121 3068 : 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 900 : if (SvXMLUnitConverter::convertEnum(
133 : nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum))
134 900 : eLineAdjust = (sal_Int16)nTmpU;
135 : }
136 2168 : else if (IsXMLToken( sLocalName, XML_REL_WIDTH ))
137 : {
138 900 : if (::sax::Converter::convertPercent(nTmp, sAttrValue))
139 900 : nLineRelWidth = (sal_uInt8)nTmp;
140 : }
141 1268 : else if (IsXMLToken( sLocalName, XML_COLOR ))
142 : {
143 900 : if (::sax::Converter::convertColor(nTmp, sAttrValue))
144 : {
145 900 : nLineColor = nTmp;
146 : }
147 : }
148 368 : 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 368 : if (SvXMLUnitConverter::convertEnum(
161 : nTmpU, sAttrValue, aXML_LineStyle_Enum))
162 368 : nLineStyle = (sal_Int8)nTmpU;
163 :
164 5252 : }
165 : }
166 5252 : }
167 :
168 : // OK, now we have all values and can fill the XMLPropertyState vector
169 900 : Any aAny;
170 : sal_Int32 nIndex;
171 :
172 900 : aAny <<= eLineAdjust;
173 900 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
174 1800 : XMLPropertyState aLineAdjust( nIndex, aAny);
175 900 : rProperties.push_back(aLineAdjust);
176 :
177 900 : aAny <<= nLineColor;
178 900 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
179 1800 : XMLPropertyState aLineColor( nIndex, aAny );
180 900 : rProperties.push_back(aLineColor);
181 :
182 900 : aAny <<= nLineStyle;
183 900 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_STYLE);
184 1800 : XMLPropertyState aLineStyle( nIndex, aAny );
185 900 : rProperties.push_back(aLineStyle);
186 :
187 900 : aAny <<= nLineDistance;
188 900 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
189 1800 : XMLPropertyState aLineDistance( nIndex, aAny );
190 900 : rProperties.push_back(aLineDistance);
191 :
192 900 : aAny <<= nLineRelWidth;
193 900 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
194 1800 : XMLPropertyState aLineRelWidth( nIndex, aAny);
195 900 : rProperties.push_back(aLineRelWidth);
196 :
197 900 : aAny <<= nLineTextDistance;
198 900 : nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
199 1800 : XMLPropertyState aLineTextDistance( nIndex, aAny);
200 900 : rProperties.push_back(aLineTextDistance);
201 :
202 : DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT) == nPropIndex,
203 : "Received wrong property map index!" );
204 900 : aAny <<= nLineWeight;
205 1800 : XMLPropertyState aLineWeight( nPropIndex, aAny );
206 1800 : rProperties.push_back(aLineWeight);
207 900 : }
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|