tdf#164627 docx export: consolidate getWordCompatibilityMode()
[LibreOffice.git] / xmloff / source / style / lspachdl.cxx
blob21a3e7dac810fd093caa90b444ebfb8aa12ad1d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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()
38 // nothing to do
41 bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
43 style::LineSpacing aLSp;
44 sal_Int32 nTemp = 0;
46 if( -1 != rStrImpValue.indexOf( '%' ) )
48 aLSp.Mode = style::LineSpacingMode::PROP;
49 if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
50 return false;
51 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
53 else if( IsXMLToken( rStrImpValue, XML_NORMAL) )
55 aLSp.Mode = style::LineSpacingMode::PROP;
56 aLSp.Height = 100;
58 else
60 aLSp.Mode = style::LineSpacingMode::FIX;
61 if (!rUnitConverter.convertMeasureToCore(
62 nTemp, rStrImpValue, 0x0000, 0xffff))
63 return false;
64 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
67 rValue <<= aLSp;
68 return true;
71 bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
73 OUStringBuffer aOut;
75 style::LineSpacing aLSp;
76 if(!(rValue >>= aLSp))
77 return false;
79 if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode )
80 return false;
82 if( style::LineSpacingMode::PROP == aLSp.Mode )
84 ::sax::Converter::convertPercent( aOut, aLSp.Height );
86 else
88 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
91 rStrExpValue = aOut.makeStringAndClear();
92 return !rStrExpValue.isEmpty();
98 XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
100 // nothing to do
103 bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
105 style::LineSpacing aLSp;
107 sal_Int32 nTemp;
108 aLSp.Mode = style::LineSpacingMode::MINIMUM;
109 if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
110 return false;
111 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
113 rValue <<= aLSp;
114 return true;
117 bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
119 OUStringBuffer aOut;
121 style::LineSpacing aLSp;
122 if(!(rValue >>= aLSp))
123 return false;
125 if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
126 return false;
128 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
130 rStrExpValue = aOut.makeStringAndClear();
131 return !rStrExpValue.isEmpty();
137 XMLLineSpacingHdl::~XMLLineSpacingHdl()
139 // nothing to do
142 bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
144 style::LineSpacing aLSp;
145 sal_Int32 nTemp;
147 aLSp.Mode = style::LineSpacingMode::LEADING;
148 if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
149 return false;
150 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
152 rValue <<= aLSp;
153 return true;
156 bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
158 OUStringBuffer aOut;
160 style::LineSpacing aLSp;
161 if(!(rValue >>= aLSp))
162 return false;
164 if( style::LineSpacingMode::LEADING != aLSp.Mode )
165 return false;
167 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
169 rStrExpValue = aOut.makeStringAndClear();
170 return !rStrExpValue.isEmpty();
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */