summaryrefslogtreecommitdiff
path: root/editeng/inc/EditLine.hxx
blob: 165f3fcf0a59c2020c386b18872050e46b7a0774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#pragma once

#include <vector>
#include <sal/types.h>
#include <tools/gen.hxx>

class ParaPortion;

class EditLine
{
public:
    typedef std::vector<sal_Int32> CharPosArrayType;

private:
    CharPosArrayType aPositions;
    std::vector<sal_Bool> aKashidaPositions;
    sal_Int32 nTxtWidth = 0;
    sal_Int32 nStartPosX = 0;
    sal_Int32 nStart = 0; // could be replaced by nStartPortion
    sal_Int32 nEnd = 0; // could be replaced by nEndPortion
    sal_Int32 nStartPortion = 0;
    sal_Int32 nEndPortion = 0;
    sal_uInt16 nHeight = 0; //  Total height of the line
    sal_uInt16 nTxtHeight = 0; // Pure Text height
    sal_uInt16 nMaxAscent = 0;
    bool bHangingPunctuation : 1 = false;
    bool bInvalid : 1 = true; // for skillful formatting

public:
    EditLine() = default;
    EditLine(const EditLine& rEditLine)
        : nStart(rEditLine.nStart)
        , nEnd(rEditLine.nEnd)
        , nStartPortion(rEditLine.nStartPortion)
        , nEndPortion(rEditLine.nEndPortion)
        , bHangingPunctuation(rEditLine.bHangingPunctuation)
        , bInvalid(true)
    {
    }

    bool IsIn(sal_Int32 nIndex) const { return ((nIndex >= nStart) && (nIndex < nEnd)); }

    bool IsIn(sal_Int32 nIndex, bool bInclEnd) const
    {
        return ((nIndex >= nStart) && (bInclEnd ? (nIndex <= nEnd) : (nIndex < nEnd)));
    }

    void SetStart(sal_Int32 n) { nStart = n; }
    sal_Int32 GetStart() const { return nStart; }
    sal_Int32& GetStart() { return nStart; }

    void SetEnd(sal_Int32 n) { nEnd = n; }
    sal_Int32 GetEnd() const { return nEnd; }
    sal_Int32& GetEnd() { return nEnd; }

    void SetStartPortion(sal_Int32 n) { nStartPortion = n; }
    sal_Int32 GetStartPortion() const { return nStartPortion; }
    sal_Int32& GetStartPortion() { return nStartPortion; }

    void SetEndPortion(sal_Int32 n) { nEndPortion = n; }
    sal_Int32 GetEndPortion() const { return nEndPortion; }
    sal_Int32& GetEndPortion() { return nEndPortion; }

    void SetHeight(sal_uInt16 nH, sal_uInt16 nTxtH = 0);
    sal_uInt16 GetHeight() const { return nHeight; }
    sal_uInt16 GetTxtHeight() const { return nTxtHeight; }

    void SetTextWidth(sal_Int32 n) { nTxtWidth = n; }
    sal_Int32 GetTextWidth() const { return nTxtWidth; }

    void SetMaxAscent(sal_uInt16 n) { nMaxAscent = n; }
    sal_uInt16 GetMaxAscent() const { return nMaxAscent; }

    void SetHangingPunctuation(bool b) { bHangingPunctuation = b; }
    bool IsHangingPunctuation() const { return bHangingPunctuation; }

    sal_Int32 GetLen() const { return nEnd - nStart; }

    sal_Int32 GetStartPosX() const { return nStartPosX; }
    void SetStartPosX(sal_Int32 start);
    Size CalcTextSize(ParaPortion& rParaPortion);

    bool IsInvalid() const { return bInvalid; }
    bool IsValid() const { return !bInvalid; }
    void SetInvalid() { bInvalid = true; }
    void SetValid() { bInvalid = false; }

    bool IsEmpty() const { return nEnd <= nStart; }

    CharPosArrayType& GetCharPosArray() { return aPositions; }
    const CharPosArrayType& GetCharPosArray() const { return aPositions; }

    std::vector<sal_Bool>& GetKashidaArray() { return aKashidaPositions; }
    const std::vector<sal_Bool>& GetKashidaArray() const { return aKashidaPositions; }

    EditLine* Clone() const;

    EditLine& operator=(const EditLine& rLine)
    {
        nEnd = rLine.nEnd;
        nStart = rLine.nStart;
        nEndPortion = rLine.nEndPortion;
        nStartPortion = rLine.nStartPortion;
        return *this;
    }

    bool operator==(const EditLine& rLine) const
    {
        return nStart == rLine.nStart && nEnd == rLine.nEnd && nStartPortion == rLine.nStartPortion
               && nEndPortion == rLine.nEndPortion;
    }
};

template <typename charT, typename traits>
inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream,
                                                     EditLine const& rLine)
{
    return stream << "EditLine(" << rLine.GetStart() << ", " << rLine.GetEnd() << ")";
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */