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 <com/sun/star/style/DropCapFormat.hpp> 31 #include "txtdropi.hxx" 32 #include <xmloff/xmltkmap.hxx> 33 #include <xmloff/xmluconv.hxx> 34 #include <xmloff/nmspmap.hxx> 35 #include "xmloff/xmlnmspe.hxx" 36 #include <xmloff/xmlimp.hxx> 37 #include <xmloff/xmltoken.hxx> 38 39 using ::rtl::OUString; 40 using ::rtl::OUStringBuffer; 41 42 using namespace ::com::sun::star; 43 using namespace ::com::sun::star::uno; 44 using namespace ::com::sun::star::style; 45 using namespace ::xmloff::token; 46 47 48 enum SvXMLTokenMapDropAttrs 49 { 50 XML_TOK_DROP_LINES, 51 XML_TOK_DROP_LENGTH, 52 XML_TOK_DROP_DISTANCE, 53 XML_TOK_DROP_STYLE, 54 XML_TOK_DROP_END=XML_TOK_UNKNOWN 55 }; 56 57 static __FAR_DATA SvXMLTokenMapEntry aDropAttrTokenMap[] = 58 { 59 { XML_NAMESPACE_STYLE, XML_LINES, XML_TOK_DROP_LINES }, 60 { XML_NAMESPACE_STYLE, XML_LENGTH, XML_TOK_DROP_LENGTH }, 61 { XML_NAMESPACE_STYLE, XML_DISTANCE, XML_TOK_DROP_DISTANCE }, 62 { XML_NAMESPACE_STYLE, XML_STYLE_NAME, XML_TOK_DROP_STYLE }, 63 XML_TOKEN_MAP_END 64 }; 65 66 TYPEINIT1( XMLTextDropCapImportContext, XMLElementPropertyContext ); 67 void XMLTextDropCapImportContext::ProcessAttrs( 68 const Reference< xml::sax::XAttributeList >& xAttrList ) 69 { 70 SvXMLTokenMap aTokenMap( aDropAttrTokenMap ); 71 72 DropCapFormat aFormat; 73 sal_Bool bWholeWord = sal_False; 74 75 sal_Int32 nTmp; 76 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 77 for( sal_Int16 i=0; i < nAttrCount; i++ ) 78 { 79 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 80 OUString aLocalName; 81 sal_uInt16 nPrefix = 82 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, 83 &aLocalName ); 84 const OUString& rValue = xAttrList->getValueByIndex( i ); 85 86 switch( aTokenMap.Get( nPrefix, aLocalName ) ) 87 { 88 case XML_TOK_DROP_LINES: 89 if( GetImport().GetMM100UnitConverter().convertNumber( nTmp, rValue, 0, 255 ) ) 90 { 91 aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp; 92 } 93 break; 94 95 case XML_TOK_DROP_LENGTH: 96 if( IsXMLToken( rValue, XML_WORD ) ) 97 { 98 bWholeWord = sal_True; 99 } 100 else if( GetImport().GetMM100UnitConverter().convertNumber( nTmp, rValue, 1, 255 ) ) 101 { 102 bWholeWord = sal_False; 103 aFormat.Count = (sal_Int8)nTmp; 104 } 105 break; 106 107 case XML_TOK_DROP_DISTANCE: 108 if( GetImport().GetMM100UnitConverter().convertMeasure( nTmp, rValue, 0 ) ) 109 { 110 aFormat.Distance = (sal_uInt16)nTmp; 111 } 112 break; 113 114 case XML_TOK_DROP_STYLE: 115 sStyleName = rValue; 116 break; 117 } 118 } 119 120 if( aFormat.Lines > 1 && aFormat.Count < 1 ) 121 aFormat.Count = 1; 122 123 aProp.maValue <<= aFormat; 124 125 aWholeWordProp.maValue.setValue( &bWholeWord, ::getBooleanCppuType() ); 126 } 127 128 XMLTextDropCapImportContext::XMLTextDropCapImportContext( 129 SvXMLImport& rImport, sal_uInt16 nPrfx, 130 const OUString& rLName, 131 const Reference< xml::sax::XAttributeList > & xAttrList, 132 const XMLPropertyState& rProp, 133 sal_Int32 nWholeWordIdx, 134 ::std::vector< XMLPropertyState > &rProps ) : 135 XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ), 136 aWholeWordProp( nWholeWordIdx ) 137 { 138 ProcessAttrs( xAttrList ); 139 } 140 141 XMLTextDropCapImportContext::~XMLTextDropCapImportContext() 142 { 143 } 144 145 void XMLTextDropCapImportContext::EndElement() 146 { 147 SetInsert( sal_True ); 148 XMLElementPropertyContext::EndElement(); 149 150 if( -1 != aWholeWordProp.mnIndex ) 151 rProperties.push_back( aWholeWordProp ); 152 } 153 154 155