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