1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <RelativeSizeHelper.hxx>
21 #include <com/sun/star/awt/Size.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <tools/diagnose_ex.h>
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::beans
;
30 using namespace ::std
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::Any
;
34 using ::com::sun::star::uno::Exception
;
39 double RelativeSizeHelper::calculate(
41 const awt::Size
& rOldReferenceSize
,
42 const awt::Size
& rNewReferenceSize
)
44 if( rOldReferenceSize
.Width
<= 0 ||
45 rOldReferenceSize
.Height
<= 0 )
49 static_cast< double >( rNewReferenceSize
.Width
) / static_cast< double >( rOldReferenceSize
.Width
),
50 static_cast< double >( rNewReferenceSize
.Height
) / static_cast< double >( rOldReferenceSize
.Height
))
54 void RelativeSizeHelper::adaptFontSizes(
55 const Reference
< XPropertySet
> & xTargetProperties
,
56 const awt::Size
& rOldReferenceSize
,
57 const awt::Size
& rNewReferenceSize
)
59 if( ! xTargetProperties
.is())
62 float fFontHeight
= 0;
64 vector
< OUString
> aProperties
;
65 aProperties
.emplace_back("CharHeight" );
66 aProperties
.emplace_back("CharHeightAsian" );
67 aProperties
.emplace_back("CharHeightComplex" );
69 for (auto const& property
: aProperties
)
73 if( xTargetProperties
->getPropertyValue(property
) >>= fFontHeight
)
75 xTargetProperties
->setPropertyValue(
77 Any( static_cast< float >(
78 calculate( fFontHeight
, rOldReferenceSize
, rNewReferenceSize
))));
81 catch( const Exception
& )
83 DBG_UNHANDLED_EXCEPTION("chart2");
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */