Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/editeng/source/outliner/outlobj.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 <editeng/outliner.hxx>
21
#include <editeng/outlobj.hxx>
22
#include <editeng/editobj.hxx>
23
#include <sal/log.hxx>
24
#include <osl/diagnose.h>
25
26
#include <o3tl/cow_wrapper.hxx>
27
#include <o3tl/safeint.hxx>
28
#include <libxml/xmlwriter.h>
29
30
OutlinerParaObjData::OutlinerParaObjData( std::unique_ptr<EditTextObject> pEditTextObject, ParagraphDataVector&& rParagraphDataVector, bool bIsEditDoc ) :
31
2.99M
    mpEditTextObject(std::move(pEditTextObject)),
32
2.99M
    maParagraphDataVector(std::move(rParagraphDataVector)),
33
2.99M
    mbIsEditDoc(bIsEditDoc)
34
2.99M
{
35
2.99M
    if( maParagraphDataVector.empty() && (mpEditTextObject->GetParagraphCount() != 0) )
36
48.4k
        maParagraphDataVector.resize(mpEditTextObject->GetParagraphCount());
37
2.99M
}
38
39
OutlinerParaObjData::OutlinerParaObjData( const OutlinerParaObjData& r ):
40
2
    mpEditTextObject(r.mpEditTextObject->Clone()),
41
2
    maParagraphDataVector(r.maParagraphDataVector),
42
2
    mbIsEditDoc(r.mbIsEditDoc)
43
2
{
44
2
}
45
46
OutlinerParaObjData::~OutlinerParaObjData()
47
5.99M
{
48
5.99M
}
49
50
bool OutlinerParaObjData::operator==(const OutlinerParaObjData& rCandidate) const
51
0
{
52
0
    return (*mpEditTextObject == *rCandidate.mpEditTextObject
53
0
        && maParagraphDataVector == rCandidate.maParagraphDataVector
54
0
        && mbIsEditDoc == rCandidate.mbIsEditDoc);
55
0
}
56
57
bool OutlinerParaObjData::isWrongListEqual(const OutlinerParaObjData& rCompare) const
58
0
{
59
0
    return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject);
60
0
}
61
62
OutlinerParaObject::OutlinerParaObject(
63
    std::unique_ptr<EditTextObject> xTextObj, ParagraphDataVector&& rParagraphDataVector, bool bIsEditDoc ) :
64
2.94M
    mpImpl(OutlinerParaObjData(std::move(xTextObj), std::move(rParagraphDataVector), bIsEditDoc))
65
2.94M
{
66
2.94M
}
67
68
OutlinerParaObject::OutlinerParaObject( std::unique_ptr<EditTextObject> pTextObj ) :
69
48.4k
    mpImpl(OutlinerParaObjData(std::move(pTextObj), ParagraphDataVector(), true))
70
48.4k
{
71
48.4k
}
72
73
OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) :
74
281k
    mpImpl(r.mpImpl)
75
281k
{
76
281k
}
77
78
OutlinerParaObject::OutlinerParaObject( OutlinerParaObject&& r ) noexcept :
79
10.0M
    mpImpl(std::move(r.mpImpl))
80
10.0M
{
81
10.0M
}
82
83
OutlinerParaObject::~OutlinerParaObject()
84
15.9M
{
85
15.9M
}
86
87
OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r )
88
0
{
89
0
    mpImpl = r.mpImpl;
90
0
    return *this;
91
0
}
92
93
OutlinerParaObject& OutlinerParaObject::operator=( OutlinerParaObject&& r ) noexcept
94
3.53M
{
95
3.53M
    mpImpl = std::move(r.mpImpl);
96
3.53M
    return *this;
97
3.53M
}
98
99
bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const
100
384
{
101
384
    return r.mpImpl == mpImpl;
102
384
}
103
104
// #i102062#
105
bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const
106
384
{
107
384
    if (r.mpImpl.same_object(mpImpl))
108
384
    {
109
384
        return true;
110
384
    }
111
112
0
    return mpImpl->isWrongListEqual(*r.mpImpl);
113
384
}
114
115
OutlinerMode OutlinerParaObject::GetOutlinerMode() const
116
1.60M
{
117
1.60M
    return mpImpl->mpEditTextObject->GetUserType();
118
1.60M
}
119
120
void OutlinerParaObject::SetOutlinerMode(OutlinerMode nNew)
121
2.99M
{
122
    // create a const pointer to avoid an early call to
123
    // make_unique() in the dereference of mpImpl
124
2.99M
    const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl;
125
2.99M
    if ( ( *pImpl )->mpEditTextObject->GetUserType() != nNew )
126
2.99M
    {
127
2.99M
        mpImpl->mpEditTextObject->SetUserType(nNew);
128
2.99M
    }
129
2.99M
}
130
131
bool OutlinerParaObject::IsEffectivelyVertical() const
132
5.93M
{
133
5.93M
    return mpImpl->mpEditTextObject->IsEffectivelyVertical();
134
5.93M
}
135
136
bool OutlinerParaObject::GetVertical() const
137
0
{
138
0
    return mpImpl->mpEditTextObject->GetVertical();
139
0
}
140
141
bool OutlinerParaObject::IsTopToBottom() const
142
18.1k
{
143
18.1k
    return mpImpl->mpEditTextObject->IsTopToBottom();
144
18.1k
}
145
146
void OutlinerParaObject::SetVertical(bool bNew)
147
16.4k
{
148
16.4k
    const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl;
149
16.4k
    if ( ( *pImpl )->mpEditTextObject->IsEffectivelyVertical() != bNew)
150
2.37k
    {
151
2.37k
        mpImpl->mpEditTextObject->SetVertical(bNew);
152
2.37k
    }
153
16.4k
}
154
void OutlinerParaObject::SetRotation(TextRotation nRotation)
155
0
{
156
0
    mpImpl->mpEditTextObject->SetRotation(nRotation);
157
0
}
158
159
TextRotation OutlinerParaObject::GetRotation() const
160
0
{
161
0
    return mpImpl->mpEditTextObject->GetRotation();
162
0
}
163
164
sal_Int32 OutlinerParaObject::Count() const
165
5.24M
{
166
5.24M
    size_t nSize = mpImpl->maParagraphDataVector.size();
167
5.24M
    if (nSize > o3tl::make_unsigned(EE_PARA_MAX))
168
0
    {
169
0
        SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
170
0
        return EE_PARA_MAX;
171
0
    }
172
5.24M
    return static_cast<sal_Int32>(nSize);
173
5.24M
}
174
175
sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
176
140
{
177
140
    if(0 <= nPara && o3tl::make_unsigned(nPara) < mpImpl->maParagraphDataVector.size())
178
140
    {
179
140
        return mpImpl->maParagraphDataVector[nPara].getDepth();
180
140
    }
181
0
    else
182
0
    {
183
0
        return -1;
184
0
    }
185
140
}
186
187
const EditTextObject& OutlinerParaObject::GetTextObject() const
188
4.93M
{
189
4.93M
    return *mpImpl->mpEditTextObject;
190
4.93M
}
191
192
const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const
193
3.63M
{
194
3.63M
    if(0 <= nIndex && o3tl::make_unsigned(nIndex) < mpImpl->maParagraphDataVector.size())
195
3.63M
    {
196
3.63M
        return mpImpl->maParagraphDataVector[nIndex];
197
3.63M
    }
198
0
    else
199
0
    {
200
0
        OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
201
0
        static ParagraphData aEmptyParagraphData;
202
0
        return aEmptyParagraphData;
203
0
    }
204
3.63M
}
205
206
void OutlinerParaObject::ClearPortionInfo()
207
442k
{
208
442k
    mpImpl->mpEditTextObject->ClearPortionInfo();
209
442k
}
210
211
bool OutlinerParaObject::ChangeStyleSheets(std::u16string_view rOldName,
212
    SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
213
1.06M
{
214
1.06M
    return mpImpl->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
215
1.06M
}
216
217
void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
218
    std::u16string_view rOldName, const OUString& rNewName)
219
8.35M
{
220
8.35M
    mpImpl->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
221
8.35M
}
222
223
void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
224
    const SfxStyleFamily& rNewFamily)
225
20
{
226
20
    const sal_Int32 nCount(Count());
227
228
20
    if(nCount)
229
20
    {
230
20
        sal_Int32 nDecrementer(nCount);
231
232
160
        while(nDecrementer > 0)
233
140
        {
234
140
            if(GetDepth(--nDecrementer) == nLevel)
235
14
            {
236
14
                mpImpl->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
237
14
            }
238
140
        }
239
20
    }
240
20
}
241
242
void OutlinerParaObject::dumpAsXml(xmlTextWriterPtr pWriter) const
243
0
{
244
0
    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("OutlinerParaObject"));
245
0
    (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
246
0
    mpImpl->mpEditTextObject->dumpAsXml(pWriter);
247
0
    for (ParagraphData const & p : mpImpl->maParagraphDataVector)
248
0
        Paragraph(p).dumpAsXml(pWriter);
249
0
    (void)xmlTextWriterEndElement(pWriter);
250
0
}
251
252
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */