Bump for 3.6-28
[LibreOffice.git] / xmloff / source / text / txtdropi.cxx
blobe0c225a953e3a44368b3d60fefb5a466d09163f2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "txtdropi.hxx"
32 #include <com/sun/star/style/DropCapFormat.hpp>
34 #include <sax/tools/converter.hxx>
36 #include <xmloff/xmltkmap.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include "xmloff/xmlnmspe.hxx"
40 #include <xmloff/xmlimp.hxx>
41 #include <xmloff/xmltoken.hxx>
43 using ::rtl::OUString;
44 using ::rtl::OUStringBuffer;
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::style;
49 using namespace ::xmloff::token;
52 enum SvXMLTokenMapDropAttrs
54 XML_TOK_DROP_LINES,
55 XML_TOK_DROP_LENGTH,
56 XML_TOK_DROP_DISTANCE,
57 XML_TOK_DROP_STYLE,
58 XML_TOK_DROP_END=XML_TOK_UNKNOWN
61 static SvXMLTokenMapEntry aDropAttrTokenMap[] =
63 { XML_NAMESPACE_STYLE, XML_LINES, XML_TOK_DROP_LINES },
64 { XML_NAMESPACE_STYLE, XML_LENGTH, XML_TOK_DROP_LENGTH },
65 { XML_NAMESPACE_STYLE, XML_DISTANCE, XML_TOK_DROP_DISTANCE },
66 { XML_NAMESPACE_STYLE, XML_STYLE_NAME, XML_TOK_DROP_STYLE },
67 XML_TOKEN_MAP_END
70 TYPEINIT1( XMLTextDropCapImportContext, XMLElementPropertyContext );
71 void XMLTextDropCapImportContext::ProcessAttrs(
72 const Reference< xml::sax::XAttributeList >& xAttrList )
74 SvXMLTokenMap aTokenMap( aDropAttrTokenMap );
76 DropCapFormat aFormat;
77 sal_Bool bWholeWord = sal_False;
79 sal_Int32 nTmp;
80 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
81 for( sal_Int16 i=0; i < nAttrCount; i++ )
83 const OUString& rAttrName = xAttrList->getNameByIndex( i );
84 OUString aLocalName;
85 sal_uInt16 nPrefix =
86 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
87 &aLocalName );
88 const OUString& rValue = xAttrList->getValueByIndex( i );
90 switch( aTokenMap.Get( nPrefix, aLocalName ) )
92 case XML_TOK_DROP_LINES:
93 if (::sax::Converter::convertNumber( nTmp, rValue, 0, 255 ))
95 aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp;
97 break;
99 case XML_TOK_DROP_LENGTH:
100 if( IsXMLToken( rValue, XML_WORD ) )
102 bWholeWord = sal_True;
104 else if (::sax::Converter::convertNumber( nTmp, rValue, 1, 255 ))
106 bWholeWord = sal_False;
107 aFormat.Count = (sal_Int8)nTmp;
109 break;
111 case XML_TOK_DROP_DISTANCE:
112 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
113 nTmp, rValue, 0 ))
115 aFormat.Distance = (sal_uInt16)nTmp;
117 break;
119 case XML_TOK_DROP_STYLE:
120 sStyleName = rValue;
121 break;
125 if( aFormat.Lines > 1 && aFormat.Count < 1 )
126 aFormat.Count = 1;
128 aProp.maValue <<= aFormat;
130 aWholeWordProp.maValue.setValue( &bWholeWord, ::getBooleanCppuType() );
133 XMLTextDropCapImportContext::XMLTextDropCapImportContext(
134 SvXMLImport& rImport, sal_uInt16 nPrfx,
135 const OUString& rLName,
136 const Reference< xml::sax::XAttributeList > & xAttrList,
137 const XMLPropertyState& rProp,
138 sal_Int32 nWholeWordIdx,
139 ::std::vector< XMLPropertyState > &rProps ) :
140 XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
141 aWholeWordProp( nWholeWordIdx )
143 ProcessAttrs( xAttrList );
146 XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
150 void XMLTextDropCapImportContext::EndElement()
152 SetInsert( sal_True );
153 XMLElementPropertyContext::EndElement();
155 if( -1 != aWholeWordProp.mnIndex )
156 rProperties.push_back( aWholeWordProp );
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */