bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / txtdropi.cxx
blob53edb1bc0dd811efb5557216bef998a82a1b42d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "txtdropi.hxx"
23 #include <com/sun/star/style/DropCapFormat.hpp>
25 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmltkmap.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/xmlimp.hxx>
32 #include <xmloff/xmltoken.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::style;
38 using namespace ::xmloff::token;
41 enum SvXMLTokenMapDropAttrs
43 XML_TOK_DROP_LINES,
44 XML_TOK_DROP_LENGTH,
45 XML_TOK_DROP_DISTANCE,
46 XML_TOK_DROP_STYLE,
47 XML_TOK_DROP_END=XML_TOK_UNKNOWN
50 static const SvXMLTokenMapEntry aDropAttrTokenMap[] =
52 { XML_NAMESPACE_STYLE, XML_LINES, XML_TOK_DROP_LINES },
53 { XML_NAMESPACE_STYLE, XML_LENGTH, XML_TOK_DROP_LENGTH },
54 { XML_NAMESPACE_STYLE, XML_DISTANCE, XML_TOK_DROP_DISTANCE },
55 { XML_NAMESPACE_STYLE, XML_STYLE_NAME, XML_TOK_DROP_STYLE },
56 XML_TOKEN_MAP_END
59 TYPEINIT1( XMLTextDropCapImportContext, XMLElementPropertyContext );
60 void XMLTextDropCapImportContext::ProcessAttrs(
61 const Reference< xml::sax::XAttributeList >& xAttrList )
63 SvXMLTokenMap aTokenMap( aDropAttrTokenMap );
65 DropCapFormat aFormat;
66 sal_Bool bWholeWord = sal_False;
68 sal_Int32 nTmp;
69 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
70 for( sal_Int16 i=0; i < nAttrCount; i++ )
72 const OUString& rAttrName = xAttrList->getNameByIndex( i );
73 OUString aLocalName;
74 sal_uInt16 nPrefix =
75 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
76 &aLocalName );
77 const OUString& rValue = xAttrList->getValueByIndex( i );
79 switch( aTokenMap.Get( nPrefix, aLocalName ) )
81 case XML_TOK_DROP_LINES:
82 if (::sax::Converter::convertNumber( nTmp, rValue, 0, 255 ))
84 aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp;
86 break;
88 case XML_TOK_DROP_LENGTH:
89 if( IsXMLToken( rValue, XML_WORD ) )
91 bWholeWord = sal_True;
93 else if (::sax::Converter::convertNumber( nTmp, rValue, 1, 255 ))
95 bWholeWord = sal_False;
96 aFormat.Count = (sal_Int8)nTmp;
98 break;
100 case XML_TOK_DROP_DISTANCE:
101 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
102 nTmp, rValue, 0 ))
104 aFormat.Distance = (sal_uInt16)nTmp;
106 break;
108 case XML_TOK_DROP_STYLE:
109 sStyleName = rValue;
110 break;
114 if( aFormat.Lines > 1 && aFormat.Count < 1 )
115 aFormat.Count = 1;
117 aProp.maValue <<= aFormat;
119 aWholeWordProp.maValue.setValue( &bWholeWord, cppu::UnoType<bool>::get() );
122 XMLTextDropCapImportContext::XMLTextDropCapImportContext(
123 SvXMLImport& rImport, sal_uInt16 nPrfx,
124 const OUString& rLName,
125 const Reference< xml::sax::XAttributeList > & xAttrList,
126 const XMLPropertyState& rProp,
127 sal_Int32 nWholeWordIdx,
128 ::std::vector< XMLPropertyState > &rProps ) :
129 XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
130 aWholeWordProp( nWholeWordIdx )
132 ProcessAttrs( xAttrList );
135 XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
139 void XMLTextDropCapImportContext::EndElement()
141 SetInsert( true );
142 XMLElementPropertyContext::EndElement();
144 if( -1 != aWholeWordProp.mnIndex )
145 rProperties.push_back( aWholeWordProp );
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */