Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/editeng/inc/ContentNode.hxx
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
#pragma once
21
22
#include "editattr.hxx"
23
#include "edtspell.hxx"
24
#include <editeng/svxfont.hxx>
25
#include <svl/itemset.hxx>
26
#include <svl/style.hxx>
27
#include <svl/itempool.hxx>
28
29
#include <memory>
30
#include <string_view>
31
#include <vector>
32
33
class SvxTabStop;
34
35
class ContentAttribs
36
{
37
private:
38
    SfxStyleSheet* mpStyle = nullptr;
39
    SfxItemSet maAttribSet;
40
41
public:
42
    ContentAttribs(SfxItemPool& rItemPool);
43
44
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
45
46
    SvxTabStop FindTabStop(sal_Int32 nCurPos, sal_uInt16 nDefTab);
47
81.4M
    SfxItemSet& GetItems() { return maAttribSet; }
48
14.9M
    const SfxItemSet& GetItems() const { return maAttribSet; }
49
0
    const SfxStyleSheet* GetStyleSheet() const { return mpStyle; }
50
73.4M
    SfxStyleSheet* GetStyleSheet() { return mpStyle; }
51
    void SetStyleSheet(SfxStyleSheet* pS);
52
53
    const SfxPoolItem& GetItem(sal_uInt16 nWhich) const;
54
    template <class T> const T& GetItem(TypedWhichId<T> nWhich) const
55
118M
    {
56
118M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
118M
    }
SvxLineSpacingItem const& ContentAttribs::GetItem<SvxLineSpacingItem>(TypedWhichId<SvxLineSpacingItem>) const
Line
Count
Source
55
33.6M
    {
56
33.6M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
33.6M
    }
SvxULSpaceItem const& ContentAttribs::GetItem<SvxULSpaceItem>(TypedWhichId<SvxULSpaceItem>) const
Line
Count
Source
55
29.5M
    {
56
29.5M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
29.5M
    }
SfxBoolItem const& ContentAttribs::GetItem<SfxBoolItem>(TypedWhichId<SfxBoolItem>) const
Line
Count
Source
55
1.88M
    {
56
1.88M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
1.88M
    }
SvxScriptSpaceItem const& ContentAttribs::GetItem<SvxScriptSpaceItem>(TypedWhichId<SvxScriptSpaceItem>) const
Line
Count
Source
55
1.88M
    {
56
1.88M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
1.88M
    }
SvxHangingPunctuationItem const& ContentAttribs::GetItem<SvxHangingPunctuationItem>(TypedWhichId<SvxHangingPunctuationItem>) const
Line
Count
Source
55
2.02M
    {
56
2.02M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
2.02M
    }
SvxForbiddenRuleItem const& ContentAttribs::GetItem<SvxForbiddenRuleItem>(TypedWhichId<SvxForbiddenRuleItem>) const
Line
Count
Source
55
1.04M
    {
56
1.04M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
1.04M
    }
SvxCharScaleWidthItem const& ContentAttribs::GetItem<SvxCharScaleWidthItem>(TypedWhichId<SvxCharScaleWidthItem>) const
Line
Count
Source
55
22.2M
    {
56
22.2M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
22.2M
    }
SvxUnderlineItem const& ContentAttribs::GetItem<SvxUnderlineItem>(TypedWhichId<SvxUnderlineItem>) const
Line
Count
Source
55
1.52k
    {
56
1.52k
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
1.52k
    }
SvxOverlineItem const& ContentAttribs::GetItem<SvxOverlineItem>(TypedWhichId<SvxOverlineItem>) const
Line
Count
Source
55
1.52k
    {
56
1.52k
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
1.52k
    }
SvxLanguageItem const& ContentAttribs::GetItem<SvxLanguageItem>(TypedWhichId<SvxLanguageItem>) const
Line
Count
Source
55
22.0M
    {
56
22.0M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
22.0M
    }
SvxLRSpaceItem const& ContentAttribs::GetItem<SvxLRSpaceItem>(TypedWhichId<SvxLRSpaceItem>) const
Line
Count
Source
55
4.15M
    {
56
4.15M
        return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
57
4.15M
    }
Unexecuted instantiation: SvxTabStopItem const& ContentAttribs::GetItem<SvxTabStopItem>(TypedWhichId<SvxTabStopItem>) const
58
    bool HasItem(sal_uInt16 nWhich) const;
59
};
60
61
class CharAttribList
62
{
63
public:
64
    typedef std::vector<std::unique_ptr<EditCharAttrib>> AttribsType;
65
66
private:
67
    AttribsType maAttribs;
68
    SvxFont maDefFont; // faster than ever from the pool!
69
    bool mbHasEmptyAttribs = false;
70
71
public:
72
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
73
74
    void DeleteEmptyAttribs();
75
76
    const EditCharAttrib* FindAttrib(sal_uInt16 nWhich, sal_Int32 nPos) const;
77
    EditCharAttrib* FindAttrib(sal_uInt16 nWhich, sal_Int32 nPos);
78
    EditCharAttrib* FindAttribRightOpen(sal_uInt16 nWhich, sal_Int32 nPos);
79
    const EditCharAttrib* FindNextAttrib(sal_uInt16 nWhich, sal_Int32 nFromPos) const;
80
    EditCharAttrib* FindEmptyAttrib(sal_uInt16 nWhich, sal_Int32 nPos);
81
    const EditCharAttrib* FindFeature(sal_Int32 nPos) const;
82
83
    void ResortAttribs();
84
    void OptimizeRanges();
85
86
    sal_Int32 Count() const;
87
88
    void InsertAttrib(EditCharAttrib* pAttrib);
89
90
80.2M
    SvxFont& GetDefFont() { return maDefFont; }
91
92
3.89M
    bool HasEmptyAttribs() const { return mbHasEmptyAttribs; }
93
    void SetHasEmptyAttribs(bool b);
94
    bool HasBoundingAttrib(sal_Int32 nBound) const;
95
    bool HasAttrib(sal_Int32 nStartPos, sal_Int32 nEndPos) const;
96
97
145M
    AttribsType& GetAttribs() { return maAttribs; }
98
351k
    const AttribsType& GetAttribs() const { return maAttribs; }
99
100
    void Remove(const EditCharAttrib* p);
101
    void Remove(sal_Int32 nPos);
102
103
#if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
104
    static void DbgCheckAttribs(CharAttribList const& rAttribs);
105
#endif
106
};
107
108
class ContentNode
109
{
110
private:
111
    OUString maString;
112
    ContentAttribs maContentAttribs;
113
    CharAttribList maCharAttribList;
114
    std::unique_ptr<WrongList> mpWrongList;
115
116
    void UnExpandPosition(sal_Int32& rStartPos, bool bBiasStart);
117
118
public:
119
    ContentNode(SfxItemPool& rItemPool);
120
    ContentNode(const OUString& rStr, const ContentAttribs& rContentAttribs);
121
122
    ContentNode(const ContentNode&) = delete;
123
    ContentNode& operator=(const ContentNode&) = delete;
124
125
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
126
127
338M
    ContentAttribs& GetContentAttribs() { return maContentAttribs; }
128
80.0M
    const ContentAttribs& GetContentAttribs() const { return maContentAttribs; }
129
266M
    CharAttribList& GetCharAttribs() { return maCharAttribList; }
130
8.13M
    const CharAttribList& GetCharAttribs() const { return maCharAttribList; }
131
132
    void ExpandAttribs(sal_Int32 nIndex, sal_Int32 nNewChars);
133
    void CollapseAttribs(sal_Int32 nIndex, sal_Int32 nDelChars);
134
    void AppendAttribs(ContentNode* pNextNode);
135
    void CopyAndCutAttribs(ContentNode* pPrevNode, SfxItemPool& rPool, bool bKeepEndingAttribs);
136
137
    void SetStyleSheet(SfxStyleSheet* pS, bool bRecalcFont = true);
138
    void SetStyleSheet(SfxStyleSheet* pS, const SvxFont& rFontFromStyle);
139
51.0M
    SfxStyleSheet* GetStyleSheet() { return maContentAttribs.GetStyleSheet(); }
140
141
    void CreateDefFont();
142
143
    void EnsureWrongList();
144
    WrongList* GetWrongList();
145
    const WrongList* GetWrongList() const;
146
    void SetWrongList(WrongList* p);
147
148
    void CreateWrongList();
149
    void DestroyWrongList();
150
151
    bool IsFeature(sal_Int32 nPos) const;
152
153
    sal_Int32 Len() const;
154
17.6M
    const OUString& GetString() const { return maString; }
155
156
    /// return length including expanded fields
157
    sal_Int32 GetExpandedLen() const;
158
    /// return content including expanded fields
159
    OUString GetExpandedText(sal_Int32 nStartPos = 0, sal_Int32 nEndPos = -1) const;
160
    /// re-write offsets in the expanded text to string offsets
161
    void UnExpandPositions(sal_Int32& rStartPos, sal_Int32& rEndPos);
162
163
    void SetChar(sal_Int32 nPos, sal_Unicode c);
164
    void Insert(const OUString& rStr, sal_Int32 nPos);
165
    void Append(std::u16string_view rStr);
166
    void Erase(sal_Int32 nPos);
167
    void Erase(sal_Int32 nPos, sal_Int32 nCount);
168
    OUString Copy(sal_Int32 nPos) const;
169
    OUString Copy(sal_Int32 nPos, sal_Int32 nCount) const;
170
    sal_Unicode GetChar(sal_Int32 nPos) const;
171
172
    void checkAndDeleteEmptyAttribs() const;
173
};
174
175
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */