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