Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/editeng/inc/TextPortion.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 <sal/types.h>
23
#include <tools/gen.hxx>
24
#include <tools/long.hxx>
25
#include <o3tl/typed_flags_set.hxx>
26
27
#include <algorithm>
28
#include <string.h>
29
#include <memory>
30
#include <utility>
31
#include <vector>
32
33
enum class PortionKind
34
{
35
    TEXT = 0,
36
    TAB = 1,
37
    LINEBREAK = 2,
38
    FIELD = 3,
39
    HYPHENATOR = 4
40
};
41
42
enum class AsianCompressionFlags
43
{
44
    Normal = 0x00,
45
    Kana = 0x01,
46
    PunctuationLeft = 0x02,
47
    PunctuationRight = 0x04,
48
};
49
namespace o3tl
50
{
51
template <> struct typed_flags<AsianCompressionFlags> : is_typed_flags<AsianCompressionFlags, 0x07>
52
{
53
};
54
}
55
56
struct ExtraPortionInfo
57
{
58
10.7k
    ExtraPortionInfo() {}
59
60
    tools::Long nOrgWidth = 0;
61
    tools::Long nWidthFullCompression = 0;
62
63
    tools::Long nPortionOffsetX = 0;
64
65
    sal_uInt16 nMaxCompression100thPercent = 0;
66
67
    AsianCompressionFlags nAsianCompressionTypes = AsianCompressionFlags::Normal;
68
    bool bCompressed = false;
69
70
    std::unique_ptr<double[]> pOrgDXArray;
71
    std::vector<sal_Int32> lineBreaksList;
72
73
    void SaveOrgDXArray(const double* pDXArray, sal_Int32 nLen)
74
0
    {
75
0
        if (pDXArray)
76
0
        {
77
0
            pOrgDXArray.reset(new double[nLen]);
78
0
            std::copy_n(pDXArray, nLen, pOrgDXArray.get());
79
0
        }
80
0
        else
81
0
            pOrgDXArray.reset();
82
0
    }
83
};
84
85
struct RubyPortionInfo
86
{
87
    tools::Long nXOffset = 0;
88
    tools::Long nYOffset = 0;
89
    sal_uInt16 nMaxAscent = 0;
90
};
91
92
class TextPortion
93
{
94
private:
95
    std::unique_ptr<ExtraPortionInfo> xExtraInfos;
96
    std::unique_ptr<RubyPortionInfo> xRubyInfos;
97
    sal_Int32 nLen;
98
    Size aOutSz = Size(-1, -1);
99
    PortionKind nKind = PortionKind::TEXT;
100
    sal_uInt8 nRightToLeftLevel = 0;
101
    sal_Unicode nExtraValue = 0;
102
103
public:
104
    TextPortion(sal_Int32 nL)
105
10.4M
        : nLen(nL)
106
10.4M
    {
107
10.4M
    }
108
109
    TextPortion(const TextPortion& r)
110
5.64M
        : nLen(r.nLen)
111
5.64M
        , aOutSz(r.aOutSz)
112
5.64M
        , nKind(r.nKind)
113
5.64M
        , nRightToLeftLevel(r.nRightToLeftLevel)
114
5.64M
        , nExtraValue(r.nExtraValue)
115
5.64M
    {
116
5.64M
    }
117
118
429M
    sal_Int32 GetLen() const { return nLen; }
119
2.21M
    void SetLen(sal_Int32 nL) { nLen = nL; }
120
121
2.45M
    void setWidth(tools::Long nWidth) { aOutSz.setWidth(nWidth); }
122
123
268k
    void setHeight(tools::Long nHeight) { aOutSz.setHeight(nHeight); }
124
125
    void adjustSize(tools::Long nDeltaX, tools::Long nDeltaY)
126
1.14M
    {
127
1.14M
        if (nDeltaX != 0)
128
1.14M
            aOutSz.AdjustWidth(nDeltaX);
129
1.14M
        if (nDeltaY != 0)
130
0
            aOutSz.AdjustHeight(nDeltaY);
131
1.14M
    }
132
133
10.6M
    void SetSize(const Size& rSize) { aOutSz = rSize; }
134
135
23.1M
    const Size& GetSize() const { return aOutSz; }
136
137
252k
    void SetKind(PortionKind n) { nKind = n; }
138
26.7M
    PortionKind GetKind() const { return nKind; }
139
140
7.79M
    void SetRightToLeftLevel(sal_uInt8 n) { nRightToLeftLevel = n; }
141
2.78k
    sal_uInt8 GetRightToLeftLevel() const { return nRightToLeftLevel; }
142
1.39k
    bool IsRightToLeft() const { return (nRightToLeftLevel & 1); }
143
144
0
    sal_Unicode GetExtraValue() const { return nExtraValue; }
145
0
    void SetExtraValue(sal_Unicode n) { nExtraValue = n; }
146
147
2.22M
    ExtraPortionInfo* GetExtraInfos() const { return xExtraInfos.get(); }
148
31.9k
    void SetExtraInfos(ExtraPortionInfo* p) { xExtraInfos.reset(p); }
149
150
7.88M
    RubyPortionInfo const* GetRubyInfos() const { return xRubyInfos.get(); }
151
0
    void SetRubyInfos(std::unique_ptr<RubyPortionInfo> p) { xRubyInfos = std::move(p); }
152
};
153
154
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */