1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 #include "RelativeSizeHelper.hxx" 31 #include "macros.hxx" 32 33 #include <vector> 34 #include <algorithm> 35 36 using namespace ::com::sun::star::awt; 37 using namespace ::com::sun::star::beans; 38 using namespace ::std; 39 40 using ::com::sun::star::uno::Reference; 41 using ::com::sun::star::uno::makeAny; 42 using ::com::sun::star::uno::Exception; 43 using ::rtl::OUString; 44 45 namespace chart 46 { 47 48 double RelativeSizeHelper::calculate( 49 double fValue, 50 const Size & rOldReferenceSize, 51 const Size & rNewReferenceSize ) 52 { 53 if( rOldReferenceSize.Width <= 0 || 54 rOldReferenceSize.Height <= 0 ) 55 return fValue; 56 57 return min( 58 static_cast< double >( rNewReferenceSize.Width ) / static_cast< double >( rOldReferenceSize.Width ), 59 static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height )) 60 * fValue; 61 } 62 63 void RelativeSizeHelper::adaptFontSizes( 64 const Reference< XPropertySet > & xTargetProperties, 65 const Size & rOldReferenceSize, 66 const Size & rNewReferenceSize ) 67 { 68 if( ! xTargetProperties.is()) 69 return; 70 71 float fFontHeight = 0; 72 73 vector< OUString > aProperties; 74 aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeight" ))); 75 aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightAsian" ))); 76 aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightComplex" ))); 77 78 for( vector< OUString >::const_iterator aIt = aProperties.begin(); 79 aIt != aProperties.end(); ++aIt ) 80 { 81 try 82 { 83 if( xTargetProperties->getPropertyValue( *aIt ) >>= fFontHeight ) 84 { 85 xTargetProperties->setPropertyValue( 86 *aIt, 87 makeAny( static_cast< float >( 88 calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize )))); 89 } 90 } 91 catch( const Exception & ex ) 92 { 93 ASSERT_EXCEPTION( ex ); 94 } 95 } 96 } 97 98 } // namespace chart 99