Bump for 3.6-28
[LibreOffice.git] / xmloff / source / style / chrhghdl.cxx
blob0a607efd1bd97c00e0f48266e4528a40c7735af5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <chrhghdl.hxx>
32 #include <rtl/ustrbuf.hxx>
34 #include <com/sun/star/uno/Any.hxx>
36 #include <sax/tools/converter.hxx>
38 #include <xmloff/xmluconv.hxx>
40 using ::rtl::OUString;
41 using ::rtl::OUStringBuffer;
43 using namespace ::com::sun::star;
45 // this is a copy of defines in svx/inc/escpitem.hxx
46 #define DFLT_ESC_PROP 58
47 #define DFLT_ESC_AUTO_SUPER 101
48 #define DFLT_ESC_AUTO_SUB -101
50 ///////////////////////////////////////////////////////////////////////////////
52 // class XMLEscapementPropHdl
55 XMLCharHeightHdl::~XMLCharHeightHdl()
57 // nothing to do
60 sal_Bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
62 if( rStrImpValue.indexOf( sal_Unicode('%') ) == -1 )
64 double fSize;
65 sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
66 rStrImpValue, util::MeasureUnit::POINT );
67 if (::sax::Converter::convertDouble(fSize, rStrImpValue,
68 eSrcUnit, util::MeasureUnit::POINT))
70 fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid
71 rValue <<= (float)fSize;
72 return sal_True;
76 return sal_False;
79 sal_Bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
81 OUStringBuffer aOut;
83 float fSize = 0;
84 if( rValue >>= fSize )
86 fSize = ::std::max<float>(fSize, 1.0f); // fdo#49876: 0pt is invalid
87 ::sax::Converter::convertDouble(aOut, (double)fSize, true,
88 util::MeasureUnit::POINT, util::MeasureUnit::POINT);
89 aOut.append( sal_Unicode('p'));
90 aOut.append( sal_Unicode('t'));
93 rStrExpValue = aOut.makeStringAndClear();
94 return !rStrExpValue.isEmpty();
97 ///////////////////////////////////////////////////////////////////////////////
99 // class XMLEscapementHeightPropHdl
102 XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
104 // nothing to do
107 sal_Bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
109 if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 )
111 sal_Int32 nPrc = 100;
112 if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
114 rValue <<= (sal_Int16)nPrc;
115 return sal_True;
119 return sal_False;
122 sal_Bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
124 OUStringBuffer aOut( rStrExpValue );
126 sal_Int16 nValue = sal_Int16();
127 if( rValue >>= nValue )
129 ::sax::Converter::convertPercent( aOut, nValue );
132 rStrExpValue = aOut.makeStringAndClear();
133 return !rStrExpValue.isEmpty();
136 ///////////////////////////////////////////////////////////////////////////////
138 // class XMLEscapementPropHdl
141 XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
143 // nothing to do
146 sal_Bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
148 sal_Int32 nRel = 0;
150 if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
151 util::MeasureUnit::POINT ))
153 rValue <<= (float)nRel;
154 return sal_True;
157 return sal_False;
160 sal_Bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
162 OUStringBuffer aOut;
164 float nRel = 0;
165 if( (rValue >>= nRel) && (nRel != 0) )
167 ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel),
168 util::MeasureUnit::POINT, util::MeasureUnit::POINT );
169 rStrExpValue = aOut.makeStringAndClear();
172 return !rStrExpValue.isEmpty();
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */