bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / tools / RelativeSizeHelper.cxx
blobbc4dca1bf67a5fbbdbd3fea9b0a5264a9e45f720
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 "RelativeSizeHelper.hxx"
21 #include "macros.hxx"
23 #include <vector>
24 #include <algorithm>
26 using namespace ::com::sun::star::awt;
27 using namespace ::com::sun::star::beans;
28 using namespace ::std;
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::uno::makeAny;
32 using ::com::sun::star::uno::Exception;
34 namespace chart
37 double RelativeSizeHelper::calculate(
38 double fValue,
39 const Size & rOldReferenceSize,
40 const Size & rNewReferenceSize )
42 if( rOldReferenceSize.Width <= 0 ||
43 rOldReferenceSize.Height <= 0 )
44 return fValue;
46 return min(
47 static_cast< double >( rNewReferenceSize.Width ) / static_cast< double >( rOldReferenceSize.Width ),
48 static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height ))
49 * fValue;
52 void RelativeSizeHelper::adaptFontSizes(
53 const Reference< XPropertySet > & xTargetProperties,
54 const Size & rOldReferenceSize,
55 const Size & rNewReferenceSize )
57 if( ! xTargetProperties.is())
58 return;
60 float fFontHeight = 0;
62 vector< OUString > aProperties;
63 aProperties.push_back( "CharHeight" );
64 aProperties.push_back( "CharHeightAsian" );
65 aProperties.push_back( "CharHeightComplex" );
67 for( vector< OUString >::const_iterator aIt = aProperties.begin();
68 aIt != aProperties.end(); ++aIt )
70 try
72 if( xTargetProperties->getPropertyValue( *aIt ) >>= fFontHeight )
74 xTargetProperties->setPropertyValue(
75 *aIt,
76 makeAny( static_cast< float >(
77 calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize ))));
80 catch( const Exception & ex )
82 ASSERT_EXCEPTION( ex );
87 } // namespace chart
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */