1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include "XMLFootnoteSeparatorImport.hxx" 31 32 #ifndef _RTL_USTRING 33 #include <rtl/ustring.hxx> 34 #endif 35 #include <com/sun/star/uno/Reference.h> 36 #include <com/sun/star/xml/sax/XAttributeList.hpp> 37 #include <com/sun/star/text/HorizontalAdjust.hpp> 38 #include <xmloff/xmlimp.hxx> 39 #include <xmloff/xmltoken.hxx> 40 #include <xmloff/xmluconv.hxx> 41 #include <xmloff/xmlprmap.hxx> 42 #include "xmloff/xmlnmspe.hxx" 43 #include <xmloff/nmspmap.hxx> 44 #include <xmloff/maptype.hxx> 45 46 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX 47 #include <xmloff/PageMasterStyleMap.hxx> 48 #endif 49 #include <tools/debug.hxx> 50 #include <tools/color.hxx> 51 52 #include <vector> 53 54 55 using namespace ::com::sun::star; 56 using namespace ::xmloff::token; 57 58 using ::rtl::OUString; 59 using ::std::vector; 60 using ::com::sun::star::uno::Any; 61 using ::com::sun::star::uno::Reference; 62 using ::com::sun::star::xml::sax::XAttributeList; 63 64 65 TYPEINIT1(XMLFootnoteSeparatorImport, SvXMLImportContext); 66 67 68 XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport( 69 SvXMLImport& rImport, 70 sal_uInt16 nPrefix, 71 const OUString& rLocalName, 72 vector<XMLPropertyState> & rProps, 73 const UniReference<XMLPropertySetMapper> & rMapperRef, 74 sal_Int32 nIndex) : 75 SvXMLImportContext(rImport, nPrefix, rLocalName), 76 rProperties(rProps), 77 rMapper(rMapperRef), 78 nPropIndex(nIndex) 79 { 80 } 81 82 XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport() 83 { 84 } 85 86 void XMLFootnoteSeparatorImport::StartElement( 87 const Reference<XAttributeList> & xAttrList) 88 { 89 // get the values from the properties 90 sal_Int16 nLineWeight = 0; 91 sal_Int32 nLineColor = 0; 92 sal_Int8 nLineRelWidth = 0; 93 sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust 94 sal_Int32 nLineTextDistance = 0; 95 sal_Int32 nLineDistance = 0; 96 97 // iterate over xattribute list and fill values 98 sal_Int16 nLength = xAttrList->getLength(); 99 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) 100 { 101 OUString sLocalName; 102 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 103 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), 104 &sLocalName ); 105 106 if (XML_NAMESPACE_STYLE == nPrefix) 107 { 108 OUString sAttrValue = xAttrList->getValueByIndex(nAttr); 109 sal_Int32 nTmp; 110 if (IsXMLToken( sLocalName, XML_WIDTH )) 111 { 112 if (GetImport().GetMM100UnitConverter().convertMeasure( 113 nTmp, sAttrValue)) 114 { 115 nLineWeight = (sal_Int16)nTmp; 116 } 117 } 118 else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP )) 119 { 120 if (GetImport().GetMM100UnitConverter().convertMeasure( 121 nTmp, sAttrValue)) 122 nLineTextDistance = nTmp; 123 } 124 else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP )) 125 { 126 if (GetImport().GetMM100UnitConverter().convertMeasure( 127 nTmp, sAttrValue)) 128 nLineDistance = nTmp; 129 } 130 else if (IsXMLToken( sLocalName, XML_ADJUSTMENT )) 131 { 132 sal_uInt16 nTmpU; 133 static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] = 134 { 135 { XML_LEFT, text::HorizontalAdjust_LEFT }, 136 { XML_CENTER, text::HorizontalAdjust_CENTER }, 137 { XML_RIGHT, text::HorizontalAdjust_RIGHT }, 138 { XML_TOKEN_INVALID, 0 } 139 }; 140 141 if (SvXMLUnitConverter::convertEnum( 142 nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum)) 143 eLineAdjust = (sal_Int16)nTmpU; 144 } 145 else if (IsXMLToken( sLocalName, XML_REL_WIDTH )) 146 { 147 if (SvXMLUnitConverter::convertPercent(nTmp, sAttrValue)) 148 nLineRelWidth = (sal_uInt8)nTmp; 149 } 150 else if (IsXMLToken( sLocalName, XML_COLOR )) 151 { 152 Color aColor; 153 if (SvXMLUnitConverter::convertColor(aColor, sAttrValue)) 154 nLineColor = (sal_Int32)aColor.GetColor(); 155 } 156 } 157 } 158 159 // OK, now we have all values and can fill the XMLPropertyState vector 160 Any aAny; 161 sal_Int32 nIndex; 162 163 aAny <<= eLineAdjust; 164 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST); 165 XMLPropertyState aLineAdjust( nIndex, aAny); 166 rProperties.push_back(aLineAdjust); 167 168 aAny <<= nLineColor; 169 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR); 170 XMLPropertyState aLineColor( nIndex, aAny ); 171 rProperties.push_back(aLineColor); 172 173 aAny <<= nLineDistance; 174 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE); 175 XMLPropertyState aLineDistance( nIndex, aAny ); 176 rProperties.push_back(aLineDistance); 177 178 aAny <<= nLineRelWidth; 179 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH); 180 XMLPropertyState aLineRelWidth( nIndex, aAny); 181 rProperties.push_back(aLineRelWidth); 182 183 aAny <<= nLineTextDistance; 184 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE); 185 XMLPropertyState aLineTextDistance( nIndex, aAny); 186 rProperties.push_back(aLineTextDistance); 187 188 DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGTH) == nPropIndex, 189 "Received wrong property map index!" ); 190 aAny <<= nLineWeight; 191 XMLPropertyState aLineWeight( nPropIndex, aAny ); 192 rProperties.push_back(aLineWeight); 193 } 194