1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtdropi.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/style/DropCapFormat.hpp>
34 #include "txtdropi.hxx"
35 #include <xmloff/xmltkmap.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <xmloff/nmspmap.hxx>
38 #include "xmlnmspe.hxx"
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/xmltoken.hxx>
42 using ::rtl::OUString
;
43 using ::rtl::OUStringBuffer
;
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::style
;
48 using namespace ::xmloff::token
;
51 enum SvXMLTokenMapDropAttrs
55 XML_TOK_DROP_DISTANCE
,
57 XML_TOK_DROP_END
=XML_TOK_UNKNOWN
60 static __FAR_DATA SvXMLTokenMapEntry aDropAttrTokenMap
[] =
62 { XML_NAMESPACE_STYLE
, XML_LINES
, XML_TOK_DROP_LINES
},
63 { XML_NAMESPACE_STYLE
, XML_LENGTH
, XML_TOK_DROP_LENGTH
},
64 { XML_NAMESPACE_STYLE
, XML_DISTANCE
, XML_TOK_DROP_DISTANCE
},
65 { XML_NAMESPACE_STYLE
, XML_STYLE_NAME
, XML_TOK_DROP_STYLE
},
69 TYPEINIT1( XMLTextDropCapImportContext
, XMLElementPropertyContext
);
70 void XMLTextDropCapImportContext::ProcessAttrs(
71 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
73 SvXMLTokenMap
aTokenMap( aDropAttrTokenMap
);
75 DropCapFormat aFormat
;
76 sal_Bool bWholeWord
= sal_False
;
79 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
80 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
82 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
85 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
87 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
89 switch( aTokenMap
.Get( nPrefix
, aLocalName
) )
91 case XML_TOK_DROP_LINES
:
92 if( GetImport().GetMM100UnitConverter().convertNumber( nTmp
, rValue
, 0, 255 ) )
94 aFormat
.Lines
= nTmp
< 2 ? 0 : (sal_Int8
)nTmp
;
98 case XML_TOK_DROP_LENGTH
:
99 if( IsXMLToken( rValue
, XML_WORD
) )
101 bWholeWord
= sal_True
;
103 else if( GetImport().GetMM100UnitConverter().convertNumber( nTmp
, rValue
, 1, 255 ) )
105 bWholeWord
= sal_False
;
106 aFormat
.Count
= (sal_Int8
)nTmp
;
110 case XML_TOK_DROP_DISTANCE
:
111 if( GetImport().GetMM100UnitConverter().convertMeasure( nTmp
, rValue
, 0 ) )
113 aFormat
.Distance
= (sal_uInt16
)nTmp
;
117 case XML_TOK_DROP_STYLE
:
123 if( aFormat
.Lines
> 1 && aFormat
.Count
< 1 )
126 aProp
.maValue
<<= aFormat
;
128 aWholeWordProp
.maValue
.setValue( &bWholeWord
, ::getBooleanCppuType() );
131 XMLTextDropCapImportContext::XMLTextDropCapImportContext(
132 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
133 const OUString
& rLName
,
134 const Reference
< xml::sax::XAttributeList
> & xAttrList
,
135 const XMLPropertyState
& rProp
,
136 sal_Int32 nWholeWordIdx
,
137 ::std::vector
< XMLPropertyState
> &rProps
) :
138 XMLElementPropertyContext( rImport
, nPrfx
, rLName
, rProp
, rProps
),
139 aWholeWordProp( nWholeWordIdx
)
141 ProcessAttrs( xAttrList
);
144 XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
148 void XMLTextDropCapImportContext::EndElement()
150 SetInsert( sal_True
);
151 XMLElementPropertyContext::EndElement();
153 if( -1 != aWholeWordProp
.mnIndex
)
154 rProperties
.push_back( aWholeWordProp
);