Bump for 3.6-28
[LibreOffice.git] / chart2 / source / tools / RelativeSizeHelper.cxx
blob6b605004cc01db01f0d89cfa3d92113d781cbccd
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 ************************************************************************/
29 #include "RelativeSizeHelper.hxx"
30 #include "macros.hxx"
32 #include <vector>
33 #include <algorithm>
35 using namespace ::com::sun::star::awt;
36 using namespace ::com::sun::star::beans;
37 using namespace ::std;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::makeAny;
41 using ::com::sun::star::uno::Exception;
42 using ::rtl::OUString;
44 namespace chart
47 double RelativeSizeHelper::calculate(
48 double fValue,
49 const Size & rOldReferenceSize,
50 const Size & rNewReferenceSize )
52 if( rOldReferenceSize.Width <= 0 ||
53 rOldReferenceSize.Height <= 0 )
54 return fValue;
56 return min(
57 static_cast< double >( rNewReferenceSize.Width ) / static_cast< double >( rOldReferenceSize.Width ),
58 static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height ))
59 * fValue;
62 void RelativeSizeHelper::adaptFontSizes(
63 const Reference< XPropertySet > & xTargetProperties,
64 const Size & rOldReferenceSize,
65 const Size & rNewReferenceSize )
67 if( ! xTargetProperties.is())
68 return;
70 float fFontHeight = 0;
72 vector< OUString > aProperties;
73 aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeight" )));
74 aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightAsian" )));
75 aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightComplex" )));
77 for( vector< OUString >::const_iterator aIt = aProperties.begin();
78 aIt != aProperties.end(); ++aIt )
80 try
82 if( xTargetProperties->getPropertyValue( *aIt ) >>= fFontHeight )
84 xTargetProperties->setPropertyValue(
85 *aIt,
86 makeAny( static_cast< float >(
87 calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize ))));
90 catch( const Exception & ex )
92 ASSERT_EXCEPTION( ex );
97 } // namespace chart
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */