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>
30 using namespace ::com::sun::star
;
31 using ::xmloff::token::IsXMLToken
;
32 using ::xmloff::token::XML_CASEMAP_NORMAL
;
34 ///////////////////////////////////////////////////////////////////////////////
36 // class XMLEscapementPropHdl
39 XMLLineHeightHdl::~XMLLineHeightHdl()
44 sal_Bool
XMLLineHeightHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
46 style::LineSpacing aLSp
;
49 if( -1 != rStrImpValue
.indexOf( sal_Unicode( '%' ) ) )
51 aLSp
.Mode
= style::LineSpacingMode::PROP
;
52 if (!::sax::Converter::convertPercent( nTemp
, rStrImpValue
))
54 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
56 else if( IsXMLToken( rStrImpValue
, XML_CASEMAP_NORMAL
) )
58 aLSp
.Mode
= style::LineSpacingMode::PROP
;
63 aLSp
.Mode
= style::LineSpacingMode::FIX
;
64 if (!rUnitConverter
.convertMeasureToCore(
65 nTemp
, rStrImpValue
, 0x0000, 0xffff))
67 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
74 sal_Bool
XMLLineHeightHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
78 style::LineSpacing aLSp
;
79 if(!(rValue
>>= aLSp
))
82 if( style::LineSpacingMode::PROP
!= aLSp
.Mode
&& style::LineSpacingMode::FIX
!= aLSp
.Mode
)
85 if( style::LineSpacingMode::PROP
== aLSp
.Mode
)
87 ::sax::Converter::convertPercent( aOut
, aLSp
.Height
);
91 rUnitConverter
.convertMeasureToXML( aOut
, aLSp
.Height
);
94 rStrExpValue
= aOut
.makeStringAndClear();
95 return !rStrExpValue
.isEmpty();
98 ///////////////////////////////////////////////////////////////////////////////
100 // class XMLLineHeightAtLeastHdl
103 XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
108 sal_Bool
XMLLineHeightAtLeastHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
110 style::LineSpacing aLSp
;
113 aLSp
.Mode
= style::LineSpacingMode::MINIMUM
;
114 if (!rUnitConverter
.convertMeasureToCore( nTemp
, rStrImpValue
, 0, 0xffff))
116 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
122 sal_Bool
XMLLineHeightAtLeastHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
126 style::LineSpacing aLSp
;
127 if(!(rValue
>>= aLSp
))
130 if( style::LineSpacingMode::MINIMUM
!= aLSp
.Mode
)
133 rUnitConverter
.convertMeasureToXML( aOut
, aLSp
.Height
);
135 rStrExpValue
= aOut
.makeStringAndClear();
136 return !rStrExpValue
.isEmpty();
139 ///////////////////////////////////////////////////////////////////////////////
141 // class XMLLineSpacingHdl
144 XMLLineSpacingHdl::~XMLLineSpacingHdl()
149 sal_Bool
XMLLineSpacingHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
151 style::LineSpacing aLSp
;
154 aLSp
.Mode
= style::LineSpacingMode::LEADING
;
155 if (!rUnitConverter
.convertMeasureToCore( nTemp
, rStrImpValue
, 0, 0xffff))
157 aLSp
.Height
= sal::static_int_cast
< sal_Int16
>(nTemp
);
163 sal_Bool
XMLLineSpacingHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
167 style::LineSpacing aLSp
;
168 if(!(rValue
>>= aLSp
))
171 if( style::LineSpacingMode::LEADING
!= aLSp
.Mode
)
174 rUnitConverter
.convertMeasureToXML( aOut
, aLSp
.Height
);
176 rStrExpValue
= aOut
.makeStringAndClear();
177 return !rStrExpValue
.isEmpty();
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */