LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - RelativeSizeHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 21 0.0 %
Date: 2012-12-27 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "RelativeSizeHelper.hxx"
      21             : #include "macros.hxx"
      22             : 
      23             : #include <vector>
      24             : #include <algorithm>
      25             : 
      26             : using namespace ::com::sun::star::awt;
      27             : using namespace ::com::sun::star::beans;
      28             : using namespace ::std;
      29             : 
      30             : using ::com::sun::star::uno::Reference;
      31             : using ::com::sun::star::uno::makeAny;
      32             : using ::com::sun::star::uno::Exception;
      33             : using ::rtl::OUString;
      34             : 
      35             : namespace chart
      36             : {
      37             : 
      38           0 : double RelativeSizeHelper::calculate(
      39             :     double fValue,
      40             :     const Size & rOldReferenceSize,
      41             :     const Size & rNewReferenceSize )
      42             : {
      43           0 :     if( rOldReferenceSize.Width <= 0 ||
      44             :         rOldReferenceSize.Height <= 0 )
      45           0 :         return fValue;
      46             : 
      47             :     return min(
      48             :         static_cast< double >( rNewReferenceSize.Width )  / static_cast< double >( rOldReferenceSize.Width ),
      49           0 :         static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height ))
      50           0 :         * fValue;
      51             : }
      52             : 
      53           0 : void RelativeSizeHelper::adaptFontSizes(
      54             :     const Reference< XPropertySet > & xTargetProperties,
      55             :     const Size & rOldReferenceSize,
      56             :     const Size & rNewReferenceSize )
      57             : {
      58           0 :     if( ! xTargetProperties.is())
      59           0 :         return;
      60             : 
      61           0 :     float fFontHeight = 0;
      62             : 
      63           0 :     vector< OUString > aProperties;
      64           0 :     aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeight" )));
      65           0 :     aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightAsian" )));
      66           0 :     aProperties.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "CharHeightComplex" )));
      67             : 
      68           0 :     for( vector< OUString >::const_iterator aIt = aProperties.begin();
      69           0 :          aIt != aProperties.end(); ++aIt )
      70             :     {
      71             :         try
      72             :         {
      73           0 :             if( xTargetProperties->getPropertyValue( *aIt ) >>= fFontHeight )
      74             :             {
      75           0 :                 xTargetProperties->setPropertyValue(
      76           0 :                     *aIt,
      77             :                     makeAny( static_cast< float >(
      78           0 :                                  calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize ))));
      79             :             }
      80             :         }
      81           0 :         catch( const Exception & ex )
      82             :         {
      83             :             ASSERT_EXCEPTION( ex );
      84             :         }
      85           0 :     }
      86             : }
      87             : 
      88             : } //  namespace chart
      89             : 
      90             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10