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