1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RelativeSizeHelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "RelativeSizeHelper.hxx"
39 using namespace ::com::sun::star::awt
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::std
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::uno::makeAny
;
45 using ::com::sun::star::uno::Exception
;
46 using ::rtl::OUString
;
52 double RelativeSizeHelper::calculate(
54 const Size
& rOldReferenceSize
,
55 const Size
& rNewReferenceSize
)
57 if( rOldReferenceSize
.Width
<= 0 ||
58 rOldReferenceSize
.Height
<= 0 )
62 static_cast< double >( rNewReferenceSize
.Width
) / static_cast< double >( rOldReferenceSize
.Width
),
63 static_cast< double >( rNewReferenceSize
.Height
) / static_cast< double >( rOldReferenceSize
.Height
))
68 void RelativeSizeHelper::adaptFontSizes(
69 const Reference
< XPropertySet
> & xTargetProperties
,
70 const Size
& rOldReferenceSize
,
71 const Size
& rNewReferenceSize
)
73 if( ! xTargetProperties
.is())
76 float fFontHeight
= 0;
78 vector
< OUString
> aProperties
;
79 aProperties
.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeight" )));
80 aProperties
.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightAsian" )));
81 aProperties
.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightComplex" )));
83 for( vector
< OUString
>::const_iterator aIt
= aProperties
.begin();
84 aIt
!= aProperties
.end(); ++aIt
)
88 if( xTargetProperties
->getPropertyValue( *aIt
) >>= fFontHeight
)
90 xTargetProperties
->setPropertyValue(
92 makeAny( static_cast< float >(
93 calculate( fFontHeight
, rOldReferenceSize
, rNewReferenceSize
))));
96 catch( const Exception
& ex
)
98 ASSERT_EXCEPTION( ex
);