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
56 XML_TOK_DROP_DISTANCE
,
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
},
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
;
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
);
86 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
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
;
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
;
111 case XML_TOK_DROP_DISTANCE
:
112 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
115 aFormat
.Distance
= (sal_uInt16
)nTmp
;
119 case XML_TOK_DROP_STYLE
:
125 if( aFormat
.Lines
> 1 && 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: */