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