1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLFootnoteSeparatorImport.hxx"
27
28 #ifndef _RTL_USTRING
29 #include <rtl/ustring.hxx>
30 #endif
31 #include <com/sun/star/uno/Reference.h>
32 #include <com/sun/star/xml/sax/XAttributeList.hpp>
33 #include <com/sun/star/text/HorizontalAdjust.hpp>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <xmloff/xmlprmap.hxx>
38 #include "xmloff/xmlnmspe.hxx"
39 #include <xmloff/nmspmap.hxx>
40 #include <xmloff/maptype.hxx>
41
42 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
43 #include <xmloff/PageMasterStyleMap.hxx>
44 #endif
45 #include <tools/debug.hxx>
46 #include <tools/color.hxx>
47
48 #include <vector>
49
50
51 using namespace ::com::sun::star;
52 using namespace ::xmloff::token;
53
54 using ::rtl::OUString;
55 using ::std::vector;
56 using ::com::sun::star::uno::Any;
57 using ::com::sun::star::uno::Reference;
58 using ::com::sun::star::xml::sax::XAttributeList;
59
60
61 TYPEINIT1(XMLFootnoteSeparatorImport, SvXMLImportContext);
62
63
XMLFootnoteSeparatorImport(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,vector<XMLPropertyState> & rProps,const UniReference<XMLPropertySetMapper> & rMapperRef,sal_Int32 nIndex)64 XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
65 SvXMLImport& rImport,
66 sal_uInt16 nPrefix,
67 const OUString& rLocalName,
68 vector<XMLPropertyState> & rProps,
69 const UniReference<XMLPropertySetMapper> & rMapperRef,
70 sal_Int32 nIndex) :
71 SvXMLImportContext(rImport, nPrefix, rLocalName),
72 rProperties(rProps),
73 rMapper(rMapperRef),
74 nPropIndex(nIndex)
75 {
76 }
77
~XMLFootnoteSeparatorImport()78 XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
79 {
80 }
81
StartElement(const Reference<XAttributeList> & xAttrList)82 void XMLFootnoteSeparatorImport::StartElement(
83 const Reference<XAttributeList> & xAttrList)
84 {
85 // get the values from the properties
86 sal_Int16 nLineWeight = 0;
87 sal_Int32 nLineColor = 0;
88 sal_Int8 nLineRelWidth = 0;
89 sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust
90 sal_Int32 nLineTextDistance = 0;
91 sal_Int32 nLineDistance = 0;
92
93 // iterate over xattribute list and fill values
94 sal_Int16 nLength = xAttrList->getLength();
95 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
96 {
97 OUString sLocalName;
98 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
99 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
100 &sLocalName );
101
102 if (XML_NAMESPACE_STYLE == nPrefix)
103 {
104 OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
105 sal_Int32 nTmp;
106 if (IsXMLToken( sLocalName, XML_WIDTH ))
107 {
108 if (GetImport().GetMM100UnitConverter().convertMeasure(
109 nTmp, sAttrValue))
110 {
111 nLineWeight = (sal_Int16)nTmp;
112 }
113 }
114 else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP ))
115 {
116 if (GetImport().GetMM100UnitConverter().convertMeasure(
117 nTmp, sAttrValue))
118 nLineTextDistance = nTmp;
119 }
120 else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP ))
121 {
122 if (GetImport().GetMM100UnitConverter().convertMeasure(
123 nTmp, sAttrValue))
124 nLineDistance = nTmp;
125 }
126 else if (IsXMLToken( sLocalName, XML_ADJUSTMENT ))
127 {
128 sal_uInt16 nTmpU;
129 static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] =
130 {
131 { XML_LEFT, text::HorizontalAdjust_LEFT },
132 { XML_CENTER, text::HorizontalAdjust_CENTER },
133 { XML_RIGHT, text::HorizontalAdjust_RIGHT },
134 { XML_TOKEN_INVALID, 0 }
135 };
136
137 if (SvXMLUnitConverter::convertEnum(
138 nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum))
139 eLineAdjust = (sal_Int16)nTmpU;
140 }
141 else if (IsXMLToken( sLocalName, XML_REL_WIDTH ))
142 {
143 if (SvXMLUnitConverter::convertPercent(nTmp, sAttrValue))
144 nLineRelWidth = (sal_uInt8)nTmp;
145 }
146 else if (IsXMLToken( sLocalName, XML_COLOR ))
147 {
148 Color aColor;
149 if (SvXMLUnitConverter::convertColor(aColor, sAttrValue))
150 nLineColor = (sal_Int32)aColor.GetColor();
151 }
152 }
153 }
154
155 // OK, now we have all values and can fill the XMLPropertyState vector
156 Any aAny;
157 sal_Int32 nIndex;
158
159 aAny <<= eLineAdjust;
160 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
161 XMLPropertyState aLineAdjust( nIndex, aAny);
162 rProperties.push_back(aLineAdjust);
163
164 aAny <<= nLineColor;
165 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
166 XMLPropertyState aLineColor( nIndex, aAny );
167 rProperties.push_back(aLineColor);
168
169 aAny <<= nLineDistance;
170 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
171 XMLPropertyState aLineDistance( nIndex, aAny );
172 rProperties.push_back(aLineDistance);
173
174 aAny <<= nLineRelWidth;
175 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
176 XMLPropertyState aLineRelWidth( nIndex, aAny);
177 rProperties.push_back(aLineRelWidth);
178
179 aAny <<= nLineTextDistance;
180 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
181 XMLPropertyState aLineTextDistance( nIndex, aAny);
182 rProperties.push_back(aLineTextDistance);
183
184 DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGTH) == nPropIndex,
185 "Received wrong property map index!" );
186 aAny <<= nLineWeight;
187 XMLPropertyState aLineWeight( nPropIndex, aAny );
188 rProperties.push_back(aLineWeight);
189 }
190