Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / tools / RelativeSizeHelper.cxx
bloba142d5b293e8798e698d3a4ad8497169888cc879
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 <com/sun/star/awt/Size.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <tools/diagnose_ex.h>
25 #include <vector>
26 #include <algorithm>
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::beans;
30 using namespace ::std;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Any;
34 using ::com::sun::star::uno::Exception;
36 namespace chart
39 double RelativeSizeHelper::calculate(
40 double fValue,
41 const awt::Size & rOldReferenceSize,
42 const awt::Size & rNewReferenceSize )
44 if( rOldReferenceSize.Width <= 0 ||
45 rOldReferenceSize.Height <= 0 )
46 return fValue;
48 return min(
49 static_cast< double >( rNewReferenceSize.Width ) / static_cast< double >( rOldReferenceSize.Width ),
50 static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height ))
51 * fValue;
54 void RelativeSizeHelper::adaptFontSizes(
55 const Reference< XPropertySet > & xTargetProperties,
56 const awt::Size & rOldReferenceSize,
57 const awt::Size & rNewReferenceSize )
59 if( ! xTargetProperties.is())
60 return;
62 float fFontHeight = 0;
64 vector< OUString > aProperties;
65 aProperties.emplace_back("CharHeight" );
66 aProperties.emplace_back("CharHeightAsian" );
67 aProperties.emplace_back("CharHeightComplex" );
69 for (auto const& property : aProperties)
71 try
73 if( xTargetProperties->getPropertyValue(property) >>= fFontHeight )
75 xTargetProperties->setPropertyValue(
76 property,
77 Any( static_cast< float >(
78 calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize ))));
81 catch( const Exception & )
83 DBG_UNHANDLED_EXCEPTION("chart2");
88 } // namespace chart
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */