Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/view/main/VTitle.cxx
Line
Count
Source
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 "VTitle.hxx"
21
#include <CommonConverters.hxx>
22
#include <ShapeFactory.hxx>
23
#include <Title.hxx>
24
#include <com/sun/star/chart2/XTitle.hpp>
25
#include <com/sun/star/beans/XPropertySet.hpp>
26
#include <utility>
27
#include <comphelper/diagnose_ex.hxx>
28
29
namespace chart
30
{
31
using namespace ::com::sun::star;
32
using namespace ::com::sun::star::chart2;
33
34
VTitle::VTitle( uno::Reference< XTitle > xTitle )
35
0
                : m_xTitle(std::move(xTitle))
36
0
                , m_fRotationAngleDegree(0.0)
37
0
                , m_nXPos(0)
38
0
                , m_nYPos(0)
39
0
{
40
0
}
41
42
VTitle::~VTitle()
43
0
{
44
0
}
45
46
void VTitle::init(
47
              const rtl::Reference<SvxShapeGroupAnyD>& xTargetPage
48
            , const OUString& rCID )
49
0
{
50
0
    m_xTarget = xTargetPage;
51
0
    m_aCID = rCID;
52
0
}
53
54
double VTitle::getRotationAnglePi() const
55
0
{
56
0
    return basegfx::deg2rad(m_fRotationAngleDegree);
57
0
}
58
59
awt::Size VTitle::getUnrotatedSize() const //size before rotation
60
0
{
61
0
    awt::Size aRet;
62
0
    if(m_xShape.is())
63
0
        aRet = m_xShape->getSize();
64
0
    return aRet;
65
0
}
66
67
awt::Size VTitle::getFinalSize() const //size after rotation
68
0
{
69
0
    return ShapeFactory::getSizeAfterRotation(
70
0
         *m_xShape, m_fRotationAngleDegree );
71
0
}
72
73
void VTitle::changePosition( const awt::Point& rPos )
74
0
{
75
0
    if(!m_xShape.is())
76
0
        return;
77
0
    try
78
0
    {
79
0
        m_nXPos = rPos.X;
80
0
        m_nYPos = rPos.Y;
81
82
        //set position matrix
83
        //the matrix needs to be set at the end behind autogrow and such position influencing properties
84
0
        ::basegfx::B2DHomMatrix aM;
85
0
        aM.rotate( basegfx::deg2rad(-m_fRotationAngleDegree) );//#i78696#->#i80521#
86
0
        aM.translate( m_nXPos, m_nYPos);
87
0
        m_xShape->SvxShape::setPropertyValue( u"Transformation"_ustr, uno::Any( B2DHomMatrixToHomogenMatrix3(aM) ) );
88
0
    }
89
0
    catch( const uno::Exception& )
90
0
    {
91
0
        TOOLS_WARN_EXCEPTION("chart2", "" );
92
0
    }
93
0
}
94
95
0
bool VTitle::isVisible(const rtl::Reference< Title >& xTitle) {
96
0
    if (!xTitle.is()) {
97
0
        return false;
98
0
    }
99
0
    bool bShow = true;
100
0
    try {
101
0
        xTitle->getPropertyValue(u"Visible"_ustr) >>= bShow;
102
0
    } catch (const uno::Exception &) {
103
0
        DBG_UNHANDLED_EXCEPTION("chart2");
104
0
    }
105
0
    return bShow;
106
0
}
107
108
109
void VTitle::createShapes(
110
      const awt::Point& rPos
111
    , const awt::Size& rReferenceSize
112
    , const awt::Size& rTextMaxWidth
113
    , bool bYAxisTitle )
114
0
{
115
0
    if(!m_xTitle.is())
116
0
        return;
117
118
0
    uno::Sequence< uno::Reference< XFormattedString > > aStringList = m_xTitle->getText();
119
0
    if(!aStringList.hasElements())
120
0
        return;
121
122
0
    m_nXPos = rPos.X;
123
0
    m_nYPos = rPos.Y;
124
125
0
    uno::Reference< beans::XPropertySet > xTitleProperties( m_xTitle, uno::UNO_QUERY );
126
127
0
    try
128
0
    {
129
0
        double fAngleDegree = 0;
130
0
        xTitleProperties->getPropertyValue( u"TextRotation"_ustr ) >>= fAngleDegree;
131
0
        m_fRotationAngleDegree += fAngleDegree;
132
0
    }
133
0
    catch( const uno::Exception& )
134
0
    {
135
0
        TOOLS_WARN_EXCEPTION("chart2", "" );
136
0
    }
137
138
0
    sal_Int32 nTextMaxWidth;
139
0
    if (bYAxisTitle)
140
0
    {
141
0
        if (m_fRotationAngleDegree < 75.0 || m_fRotationAngleDegree > 285.0
142
0
            || (m_fRotationAngleDegree > 105.0 && m_fRotationAngleDegree < 255.0))
143
0
            nTextMaxWidth = rTextMaxWidth.Width;
144
0
        else
145
0
            nTextMaxWidth = rTextMaxWidth.Height;
146
0
    }
147
0
    else if (m_fRotationAngleDegree <= 15.0 || m_fRotationAngleDegree >= 345.0
148
0
             || (m_fRotationAngleDegree >= 165.0 && m_fRotationAngleDegree <= 195.0))
149
0
        nTextMaxWidth = rTextMaxWidth.Width;
150
0
    else
151
0
        nTextMaxWidth = rTextMaxWidth.Height;
152
153
0
    m_xShape = ShapeFactory::createText( m_xTarget, rReferenceSize, rPos, aStringList, xTitleProperties,
154
0
                                    m_fRotationAngleDegree, m_aCID, nTextMaxWidth );
155
0
}
156
157
} //namespace chart
158
159
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */