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: lspachdl.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"
35 #include <lspachdl.hxx>
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/style/LineSpacing.hpp>
41 #include <com/sun/star/style/LineSpacingMode.hpp>
43 #ifndef _XMLOFF_XMLEMENT_HXX
44 #include <xmloff/xmlelement.hxx>
47 using ::rtl::OUString
;
48 using ::rtl::OUStringBuffer
;
50 using namespace ::com::sun::star
;
51 using ::xmloff::token::IsXMLToken
;
52 using ::xmloff::token::XML_CASEMAP_NORMAL
;
54 // this is a copy of defines in svx/inc/escpitem.hxx
55 #define DFLT_ESC_PROP 58
56 #define DFLT_ESC_AUTO_SUPER 101
57 #define DFLT_ESC_AUTO_SUB -101
59 ///////////////////////////////////////////////////////////////////////////////
61 // class XMLEscapementPropHdl
64 XMLLineHeightHdl::~XMLLineHeightHdl()
69 sal_Bool
XMLLineHeightHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
71 style::LineSpacing aLSp
;
74 if( -1 != rStrImpValue
.indexOf( sal_Unicode( '%' ) ) )
76 aLSp
.Mode
= style::LineSpacingMode::PROP
;
77 if(!rUnitConverter
.convertPercent( nTemp
, rStrImpValue
))
79 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
81 else if( IsXMLToken( rStrImpValue
, XML_CASEMAP_NORMAL
) )
83 aLSp
.Mode
= style::LineSpacingMode::PROP
;
88 aLSp
.Mode
= style::LineSpacingMode::FIX
;
89 if(!rUnitConverter
.convertMeasure( nTemp
, rStrImpValue
, 0x0000, 0xffff ))
91 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
98 sal_Bool
XMLLineHeightHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
102 style::LineSpacing aLSp
;
103 if(!(rValue
>>= aLSp
))
106 if( style::LineSpacingMode::PROP
!= aLSp
.Mode
&& style::LineSpacingMode::FIX
!= aLSp
.Mode
)
109 if( style::LineSpacingMode::PROP
== aLSp
.Mode
)
111 rUnitConverter
.convertPercent( aOut
, aLSp
.Height
);
115 rUnitConverter
.convertMeasure( aOut
, aLSp
.Height
);
118 rStrExpValue
= aOut
.makeStringAndClear();
119 return rStrExpValue
.getLength() != 0;
122 ///////////////////////////////////////////////////////////////////////////////
124 // class XMLLineHeightAtLeastHdl
127 XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
132 sal_Bool
XMLLineHeightAtLeastHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
134 style::LineSpacing aLSp
;
137 aLSp
.Mode
= style::LineSpacingMode::MINIMUM
;
138 if(!rUnitConverter
.convertMeasure( nTemp
, rStrImpValue
, 0x0000, 0xffff ))
140 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
146 sal_Bool
XMLLineHeightAtLeastHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
150 style::LineSpacing aLSp
;
151 if(!(rValue
>>= aLSp
))
154 if( style::LineSpacingMode::MINIMUM
!= aLSp
.Mode
)
157 rUnitConverter
.convertMeasure( aOut
, aLSp
.Height
);
159 rStrExpValue
= aOut
.makeStringAndClear();
160 return rStrExpValue
.getLength() != 0;
163 ///////////////////////////////////////////////////////////////////////////////
165 // class XMLLineSpacingHdl
168 XMLLineSpacingHdl::~XMLLineSpacingHdl()
173 sal_Bool
XMLLineSpacingHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
175 style::LineSpacing aLSp
;
178 aLSp
.Mode
= style::LineSpacingMode::LEADING
;
179 if(!rUnitConverter
.convertMeasure( nTemp
, rStrImpValue
, 0x0000, 0xffff ))
181 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
187 sal_Bool
XMLLineSpacingHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
191 style::LineSpacing aLSp
;
192 if(!(rValue
>>= aLSp
))
195 if( style::LineSpacingMode::LEADING
!= aLSp
.Mode
)
198 rUnitConverter
.convertMeasure( aOut
, aLSp
.Height
);
200 rStrExpValue
= aOut
.makeStringAndClear();
201 return rStrExpValue
.getLength() != 0;