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 .
20 #include "lspachdl.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmluconv.hxx>
23 #include <sax/tools/converter.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/style/LineSpacing.hpp>
27 #include <com/sun/star/style/LineSpacingMode.hpp>
29 using namespace ::com::sun::star
;
30 using ::xmloff::token::IsXMLToken
;
31 using ::xmloff::token::XML_NORMAL
;
36 XMLLineHeightHdl::~XMLLineHeightHdl()
41 bool XMLLineHeightHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
43 style::LineSpacing aLSp
;
46 if( -1 != rStrImpValue
.indexOf( '%' ) )
48 aLSp
.Mode
= style::LineSpacingMode::PROP
;
49 if (!::sax::Converter::convertPercent( nTemp
, rStrImpValue
))
51 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
53 else if( IsXMLToken( rStrImpValue
, XML_NORMAL
) )
55 aLSp
.Mode
= style::LineSpacingMode::PROP
;
60 aLSp
.Mode
= style::LineSpacingMode::FIX
;
61 if (!rUnitConverter
.convertMeasureToCore(
62 nTemp
, rStrImpValue
, 0x0000, 0xffff))
64 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
71 bool XMLLineHeightHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
75 style::LineSpacing aLSp
;
76 if(!(rValue
>>= aLSp
))
79 if( style::LineSpacingMode::PROP
!= aLSp
.Mode
&& style::LineSpacingMode::FIX
!= aLSp
.Mode
)
82 if( style::LineSpacingMode::PROP
== aLSp
.Mode
)
84 ::sax::Converter::convertPercent( aOut
, aLSp
.Height
);
88 rUnitConverter
.convertMeasureToXML( aOut
, aLSp
.Height
);
91 rStrExpValue
= aOut
.makeStringAndClear();
92 return !rStrExpValue
.isEmpty();
98 XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
103 bool XMLLineHeightAtLeastHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
105 style::LineSpacing aLSp
;
108 aLSp
.Mode
= style::LineSpacingMode::MINIMUM
;
109 if (!rUnitConverter
.convertMeasureToCore( nTemp
, rStrImpValue
, 0, 0xffff))
111 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
117 bool XMLLineHeightAtLeastHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
121 style::LineSpacing aLSp
;
122 if(!(rValue
>>= aLSp
))
125 if( style::LineSpacingMode::MINIMUM
!= aLSp
.Mode
)
128 rUnitConverter
.convertMeasureToXML( aOut
, aLSp
.Height
);
130 rStrExpValue
= aOut
.makeStringAndClear();
131 return !rStrExpValue
.isEmpty();
137 XMLLineSpacingHdl::~XMLLineSpacingHdl()
142 bool XMLLineSpacingHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
144 style::LineSpacing aLSp
;
147 aLSp
.Mode
= style::LineSpacingMode::LEADING
;
148 if (!rUnitConverter
.convertMeasureToCore( nTemp
, rStrImpValue
, 0, 0xffff))
150 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
156 bool XMLLineSpacingHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
160 style::LineSpacing aLSp
;
161 if(!(rValue
>>= aLSp
))
164 if( style::LineSpacingMode::LEADING
!= aLSp
.Mode
)
167 rUnitConverter
.convertMeasureToXML( aOut
, aLSp
.Height
);
169 rStrExpValue
= aOut
.makeStringAndClear();
170 return !rStrExpValue
.isEmpty();
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */