1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
45 XML_TOK_DROP_DISTANCE
,
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
},
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
;
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
);
75 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
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
;
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
;
100 case XML_TOK_DROP_DISTANCE
:
101 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
104 aFormat
.Distance
= (sal_uInt16
)nTmp
;
108 case XML_TOK_DROP_STYLE
:
114 if( aFormat
.Lines
> 1 && 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()
142 XMLElementPropertyContext::EndElement();
144 if( -1 != aWholeWordProp
.mnIndex
)
145 rProperties
.push_back( aWholeWordProp
);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */