1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_chart2.hxx"
26*b1cdbd2cSJim Jagielski #include "RelativeSizeHelper.hxx"
27*b1cdbd2cSJim Jagielski #include "macros.hxx"
28*b1cdbd2cSJim Jagielski 
29*b1cdbd2cSJim Jagielski #include <vector>
30*b1cdbd2cSJim Jagielski #include <algorithm>
31*b1cdbd2cSJim Jagielski 
32*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::awt;
33*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::beans;
34*b1cdbd2cSJim Jagielski using namespace ::std;
35*b1cdbd2cSJim Jagielski 
36*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::Reference;
37*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::makeAny;
38*b1cdbd2cSJim Jagielski using ::com::sun::star::uno::Exception;
39*b1cdbd2cSJim Jagielski using ::rtl::OUString;
40*b1cdbd2cSJim Jagielski 
41*b1cdbd2cSJim Jagielski namespace chart
42*b1cdbd2cSJim Jagielski {
43*b1cdbd2cSJim Jagielski 
calculate(double fValue,const Size & rOldReferenceSize,const Size & rNewReferenceSize)44*b1cdbd2cSJim Jagielski double RelativeSizeHelper::calculate(
45*b1cdbd2cSJim Jagielski     double fValue,
46*b1cdbd2cSJim Jagielski     const Size & rOldReferenceSize,
47*b1cdbd2cSJim Jagielski     const Size & rNewReferenceSize )
48*b1cdbd2cSJim Jagielski {
49*b1cdbd2cSJim Jagielski     if( rOldReferenceSize.Width <= 0 ||
50*b1cdbd2cSJim Jagielski         rOldReferenceSize.Height <= 0 )
51*b1cdbd2cSJim Jagielski         return fValue;
52*b1cdbd2cSJim Jagielski 
53*b1cdbd2cSJim Jagielski     return min(
54*b1cdbd2cSJim Jagielski         static_cast< double >( rNewReferenceSize.Width )  / static_cast< double >( rOldReferenceSize.Width ),
55*b1cdbd2cSJim Jagielski         static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height ))
56*b1cdbd2cSJim Jagielski         * fValue;
57*b1cdbd2cSJim Jagielski }
58*b1cdbd2cSJim Jagielski 
adaptFontSizes(const Reference<XPropertySet> & xTargetProperties,const Size & rOldReferenceSize,const Size & rNewReferenceSize)59*b1cdbd2cSJim Jagielski void RelativeSizeHelper::adaptFontSizes(
60*b1cdbd2cSJim Jagielski     const Reference< XPropertySet > & xTargetProperties,
61*b1cdbd2cSJim Jagielski     const Size & rOldReferenceSize,
62*b1cdbd2cSJim Jagielski     const Size & rNewReferenceSize )
63*b1cdbd2cSJim Jagielski {
64*b1cdbd2cSJim Jagielski     if( ! xTargetProperties.is())
65*b1cdbd2cSJim Jagielski         return;
66*b1cdbd2cSJim Jagielski 
67*b1cdbd2cSJim Jagielski     float fFontHeight = 0;
68*b1cdbd2cSJim Jagielski 
69*b1cdbd2cSJim Jagielski     vector< OUString > aProperties;
70*b1cdbd2cSJim Jagielski     aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeight" )));
71*b1cdbd2cSJim Jagielski     aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightAsian" )));
72*b1cdbd2cSJim Jagielski     aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightComplex" )));
73*b1cdbd2cSJim Jagielski 
74*b1cdbd2cSJim Jagielski     for( vector< OUString >::const_iterator aIt = aProperties.begin();
75*b1cdbd2cSJim Jagielski          aIt != aProperties.end(); ++aIt )
76*b1cdbd2cSJim Jagielski     {
77*b1cdbd2cSJim Jagielski         try
78*b1cdbd2cSJim Jagielski         {
79*b1cdbd2cSJim Jagielski             if( xTargetProperties->getPropertyValue( *aIt ) >>= fFontHeight )
80*b1cdbd2cSJim Jagielski             {
81*b1cdbd2cSJim Jagielski                 xTargetProperties->setPropertyValue(
82*b1cdbd2cSJim Jagielski                     *aIt,
83*b1cdbd2cSJim Jagielski                     makeAny( static_cast< float >(
84*b1cdbd2cSJim Jagielski                                  calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize ))));
85*b1cdbd2cSJim Jagielski             }
86*b1cdbd2cSJim Jagielski         }
87*b1cdbd2cSJim Jagielski         catch( const Exception & ex )
88*b1cdbd2cSJim Jagielski         {
89*b1cdbd2cSJim Jagielski             ASSERT_EXCEPTION( ex );
90*b1cdbd2cSJim Jagielski         }
91*b1cdbd2cSJim Jagielski     }
92*b1cdbd2cSJim Jagielski }
93*b1cdbd2cSJim Jagielski 
94*b1cdbd2cSJim Jagielski } //  namespace chart
95