summaryrefslogtreecommitdiff
path: root/xfa/src/fgas/src/layout/fx_rtfbreak.h
blob: 09302dfedd18cf1c7ced280f9b8629288b20a1e3 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef _FX_RTFBREAK_IMP
#define _FX_RTFBREAK_IMP

#include "../../../../../core/include/fxcrt/fx_arb.h"

class CFX_RTFLine;
class CFX_RTFBreak;
class CFX_RTFLine
{
public:
    CFX_RTFLine() : m_LinePieces(16)
        , m_iStart(0)
        , m_iWidth(0)
        , m_iArabicChars(0)
        , m_iMBCSChars(0)
    {
    }
    ~CFX_RTFLine()
    {
        RemoveAll();
    }
    int32_t CountChars() const
    {
        return m_LineChars.GetSize();
    }
    CFX_RTFChar& GetChar(int32_t index)
    {
        FXSYS_assert(index > -1 && index < m_LineChars.GetSize());
        return *m_LineChars.GetDataPtr(index);
    }
    CFX_RTFChar* GetCharPtr(int32_t index)
    {
        FXSYS_assert(index > -1 && index < m_LineChars.GetSize());
        return m_LineChars.GetDataPtr(index);
    }
    int32_t CountPieces() const
    {
        return m_LinePieces.GetSize();
    }
    CFX_RTFPiece& GetPiece(int32_t index) const
    {
        FXSYS_assert(index > -1 && index < m_LinePieces.GetSize());
        return m_LinePieces.GetAt(index);
    }
    CFX_RTFPiece* GetPiecePtr(int32_t index) const
    {
        FXSYS_assert(index > -1 && index < m_LinePieces.GetSize());
        return m_LinePieces.GetPtrAt(index);
    }
    int32_t GetLineEnd() const
    {
        return m_iStart + m_iWidth;
    }
    void RemoveAll(FX_BOOL bLeaveMemory = FALSE)
    {
        CFX_RTFChar *pChar;
        IFX_Unknown *pUnknown;
        int32_t iCount = m_LineChars.GetSize();
        for (int32_t i = 0; i < iCount; i ++) {
            pChar = m_LineChars.GetDataPtr(i);
            if ((pUnknown = pChar->m_pUserData) != NULL) {
                pUnknown->Release();
            }
        }
        m_LineChars.RemoveAll();
        m_LinePieces.RemoveAll(bLeaveMemory);
        m_iWidth = 0;
        m_iArabicChars = 0;
        m_iMBCSChars = 0;
    }
    CFX_RTFCharArray	m_LineChars;
    CFX_RTFPieceArray	m_LinePieces;
    int32_t			m_iStart;
    int32_t			m_iWidth;
    int32_t			m_iArabicChars;
    int32_t			m_iMBCSChars;
};
class CFX_RTFBreak : public IFX_RTFBreak
{
public:
    CFX_RTFBreak(FX_DWORD dwPolicies);
    ~CFX_RTFBreak();
    virtual void			Release()
    {
        delete this;
    }
    virtual void			SetLineWidth(FX_FLOAT fLineStart, FX_FLOAT fLineEnd);
    virtual void			SetLinePos(FX_FLOAT fLinePos);
    virtual FX_DWORD		GetLayoutStyles() const
    {
        return m_dwLayoutStyles;
    }
    virtual void			SetLayoutStyles(FX_DWORD dwLayoutStyles);
    virtual void			SetFont(IFX_Font *pFont);
    virtual void			SetFontSize(FX_FLOAT fFontSize);
    virtual void			SetTabWidth(FX_FLOAT fTabWidth);
    virtual void			AddPositionedTab(FX_FLOAT fTabPos);
    virtual void			SetPositionedTabs(const CFX_FloatArray &tabs);
    virtual void			ClearPositionedTabs();
    virtual void			SetDefaultChar(FX_WCHAR wch);
    virtual void			SetLineBreakChar(FX_WCHAR wch);
    virtual void			SetLineBreakTolerance(FX_FLOAT fTolerance);
    virtual void			SetHorizontalScale(int32_t iScale);
    virtual void			SetVerticalScale(int32_t iScale);
    virtual void			SetCharRotation(int32_t iCharRotation);
    virtual void			SetCharSpace(FX_FLOAT fCharSpace);
    virtual void			SetWordSpace(FX_BOOL bDefault, FX_FLOAT fWordSpace);
    virtual void			SetReadingOrder(FX_BOOL bRTL = FALSE);
    virtual void			SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left);
    virtual void			SetUserData(IFX_Unknown *pUserData);
    virtual FX_DWORD					AppendChar(FX_WCHAR wch);
    virtual FX_DWORD					EndBreak(FX_DWORD dwStatus = FX_RTFBREAK_PieceBreak);
    virtual int32_t					CountBreakPieces() const;
    virtual const CFX_RTFPiece*			GetBreakPiece(int32_t index) const;
    virtual void						GetLineRect(CFX_RectF &rect) const;
    virtual void						ClearBreakPieces();
    virtual void			Reset();
    virtual int32_t		GetDisplayPos(FX_LPCRTFTEXTOBJ pText, FXTEXT_CHARPOS *pCharPos, FX_BOOL bCharCode = FALSE, CFX_WideString *pWSForms = NULL, FX_AdjustCharDisplayPos pAdjustPos = NULL) const;
    virtual int32_t		GetCharRects(FX_LPCRTFTEXTOBJ pText, CFX_RectFArray &rtArray, FX_BOOL bCharBBox = FALSE) const;
    FX_DWORD				AppendChar_CharCode(FX_WCHAR wch);
    FX_DWORD				AppendChar_Combination(CFX_RTFChar *pCurChar, int32_t iRotation);
    FX_DWORD				AppendChar_Tab(CFX_RTFChar *pCurChar, int32_t iRotation);
    FX_DWORD				AppendChar_Control(CFX_RTFChar *pCurChar, int32_t iRotation);
    FX_DWORD				AppendChar_Arabic(CFX_RTFChar *pCurChar, int32_t iRotation);
    FX_DWORD				AppendChar_Others(CFX_RTFChar *pCurChar, int32_t iRotation);
protected:
    FX_DWORD			m_dwPolicies;
    IFX_ArabicChar		*m_pArabicChar;
    int32_t			m_iLineStart;
    int32_t			m_iLineEnd;
    FX_DWORD			m_dwLayoutStyles;
    FX_BOOL				m_bPagination;
    FX_BOOL				m_bVertical;
    FX_BOOL				m_bSingleLine;
    FX_BOOL				m_bCharCode;
    IFX_Font			*m_pFont;
    int32_t			m_iFontHeight;
    int32_t			m_iFontSize;
    int32_t			m_iTabWidth;
    CFX_Int32Array		m_PositionedTabs;
    FX_BOOL				m_bOrphanLine;
    FX_WCHAR			m_wDefChar;
    int32_t			m_iDefChar;
    FX_WCHAR			m_wLineBreakChar;
    int32_t			m_iHorizontalScale;
    int32_t			m_iVerticalScale;
    int32_t			m_iLineRotation;
    int32_t			m_iCharRotation;
    int32_t			m_iRotation;
    int32_t			m_iCharSpace;
    FX_BOOL				m_bWordSpace;
    int32_t			m_iWordSpace;
    FX_BOOL				m_bRTL;
    int32_t			m_iAlignment;
    IFX_Unknown			*m_pUserData;
    FX_DWORD			m_dwCharType;
    FX_DWORD			m_dwIdentity;
    CFX_RTFLine			m_RTFLine1;
    CFX_RTFLine			m_RTFLine2;
    CFX_RTFLine			*m_pCurLine;
    int32_t			m_iReady;
    int32_t			m_iTolerance;
    int32_t			GetLineRotation(FX_DWORD dwStyles) const;
    void				SetBreakStatus();
    CFX_RTFChar*		GetLastChar(int32_t index) const;
    CFX_RTFLine*		GetRTFLine(FX_BOOL bReady) const;
    CFX_RTFPieceArray*	GetRTFPieces(FX_BOOL bReady) const;
    FX_DWORD			GetUnifiedCharType(FX_DWORD dwType) const;
    int32_t			GetLastPositionedTab() const;
    FX_BOOL				GetPositionedTab(int32_t &iTabPos) const;
    int32_t			GetBreakPos(CFX_RTFCharArray &tca, int32_t &iEndPos, FX_BOOL bAllChars = FALSE, FX_BOOL bOnlyBrk = FALSE);
    void				SplitTextLine(CFX_RTFLine *pCurLine, CFX_RTFLine *pNextLine, FX_BOOL bAllChars = FALSE);
    FX_BOOL				EndBreak_SplitLine(CFX_RTFLine *pNextLine, FX_BOOL bAllChars, FX_DWORD dwStatus);
    void				EndBreak_BidiLine(CFX_TPOArray &tpos, FX_DWORD dwStatus);
    void				EndBreak_Alignment(CFX_TPOArray &tpos, FX_BOOL bAllChars, FX_DWORD dwStatus);
};
#endif