LibreOffice Module chart2 (master) 1
RelativeSizeHelper.cxx
Go to the documentation of this file.
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
21#include <com/sun/star/awt/Size.hpp>
22#include <com/sun/star/beans/XPropertySet.hpp>
24#include <svx/unoshape.hxx>
25#include <vector>
26#include <algorithm>
27
28using namespace ::com::sun::star;
29using namespace ::com::sun::star::beans;
30
31using ::com::sun::star::uno::Reference;
32using ::com::sun::star::uno::Any;
33using ::com::sun::star::uno::Exception;
34
35namespace chart
36{
37
39 double fValue,
40 const awt::Size & rOldReferenceSize,
41 const awt::Size & rNewReferenceSize )
42{
43 if( rOldReferenceSize.Width <= 0 ||
44 rOldReferenceSize.Height <= 0 )
45 return fValue;
46
47 return std::min(
48 static_cast< double >( rNewReferenceSize.Width ) / static_cast< double >( rOldReferenceSize.Width ),
49 static_cast< double >( rNewReferenceSize.Height ) / static_cast< double >( rOldReferenceSize.Height ))
50 * fValue;
51}
52
54 SvxShapeText& xTargetProperties,
55 const awt::Size & rOldReferenceSize,
56 const awt::Size & rNewReferenceSize )
57{
58 float fFontHeight = 0;
59
60 std::vector< OUString > aProperties;
61 aProperties.emplace_back("CharHeight" );
62 aProperties.emplace_back("CharHeightAsian" );
63 aProperties.emplace_back("CharHeightComplex" );
64
65 for (auto const& property : aProperties)
66 {
67 try
68 {
69 if( xTargetProperties.SvxShape::getPropertyValue(property) >>= fFontHeight )
70 {
71 xTargetProperties.SvxShape::setPropertyValue(
73 Any( static_cast< float >(
74 calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize ))));
75 }
76 }
77 catch( const Exception & )
78 {
80 }
81 }
82}
83
85 const Reference< XPropertySet > & xTargetProperties,
86 const awt::Size & rOldReferenceSize,
87 const awt::Size & rNewReferenceSize )
88{
89 if( ! xTargetProperties.is())
90 return;
91
92 float fFontHeight = 0;
93
94 std::vector< OUString > aProperties;
95 aProperties.emplace_back("CharHeight" );
96 aProperties.emplace_back("CharHeightAsian" );
97 aProperties.emplace_back("CharHeightComplex" );
98
99 for (auto const& property : aProperties)
100 {
101 try
102 {
103 if( xTargetProperties->getPropertyValue(property) >>= fFontHeight )
104 {
105 xTargetProperties->setPropertyValue(
106 property,
107 Any( static_cast< float >(
108 calculate( fFontHeight, rOldReferenceSize, rNewReferenceSize ))));
109 }
110 }
111 catch( const Exception & )
112 {
113 DBG_UNHANDLED_EXCEPTION("chart2");
114 }
115 }
116}
117
118} // namespace chart
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
static double calculate(double fValue, const css::awt::Size &rOldReferenceSize, const css::awt::Size &rNewReferenceSize)
static void adaptFontSizes(const css::uno::Reference< css::beans::XPropertySet > &xTargetProperties, const css::awt::Size &rOldReferenceSize, const css::awt::Size &rNewReferenceSize)
#define DBG_UNHANDLED_EXCEPTION(...)