blob: 7f3d4ac107c80c399bfc2756670ef49497f62083 [file] [log] [blame]
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef XFA_FGAS_LAYOUT_CFX_TXTBREAK_H_
8#define XFA_FGAS_LAYOUT_CFX_TXTBREAK_H_
9
10#include <deque>
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070011#include <vector>
12
Haibo Huang49cc9302020-04-27 16:14:24 -070013#include "core/fxcrt/fx_coordinates.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070014#include "xfa/fgas/layout/cfx_break.h"
Haibo Huang49cc9302020-04-27 16:14:24 -070015#include "xfa/fgas/layout/cfx_char.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070016
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070017class CFGAS_GEFont;
Haibo Huang49cc9302020-04-27 16:14:24 -070018class TextCharPos;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070019
20#define FX_TXTCHARSTYLE_ArabicShadda 0x0020
21#define FX_TXTCHARSTYLE_OddBidiLevel 0x0040
22
23enum CFX_TxtLineAlignment {
24 CFX_TxtLineAlignment_Left = 0,
25 CFX_TxtLineAlignment_Center = 1 << 0,
26 CFX_TxtLineAlignment_Right = 1 << 1,
27 CFX_TxtLineAlignment_Justified = 1 << 2
28};
29
30inline bool CFX_BreakTypeNoneOrPiece(CFX_BreakType type) {
31 return type == CFX_BreakType::None || type == CFX_BreakType::Piece;
32}
33
Haibo Huang49cc9302020-04-27 16:14:24 -070034class CFX_TxtBreak final : public CFX_Break {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070035 public:
Haibo Huang49cc9302020-04-27 16:14:24 -070036 class Engine {
37 public:
38 virtual ~Engine();
39 virtual wchar_t GetChar(size_t idx) const = 0;
40 // Non-const so we can force a layout if needed.
41 virtual size_t GetWidthOfChar(size_t idx) = 0;
42 };
43
44 struct Run {
45 Run();
46 Run(const Run& other);
47 ~Run();
48
49 CFX_TxtBreak::Engine* pEdtEngine = nullptr;
50 WideString wsStr;
51 int32_t* pWidths = nullptr;
52 int32_t iStart = 0;
53 int32_t iLength = 0;
54 RetainPtr<CFGAS_GEFont> pFont;
55 float fFontSize = 12.0f;
56 uint32_t dwStyles = 0;
57 int32_t iHorizontalScale = 100;
58 int32_t iVerticalScale = 100;
59 uint32_t dwCharStyles = 0;
60 const CFX_RectF* pRect = nullptr;
61 bool bSkipSpace = true;
62 };
63
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070064 CFX_TxtBreak();
65 ~CFX_TxtBreak() override;
66
67 void SetLineWidth(float fLineWidth);
68 void SetAlignment(int32_t iAlignment);
69 void SetCombWidth(float fCombWidth);
70 CFX_BreakType EndBreak(CFX_BreakType dwStatus);
71
Haibo Huang49cc9302020-04-27 16:14:24 -070072 size_t GetDisplayPos(const Run* pTxtRun, TextCharPos* pCharPos) const;
73 std::vector<CFX_RectF> GetCharRects(const Run* pTxtRun, bool bCharBBox) const;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070074 CFX_BreakType AppendChar(wchar_t wch);
75
76 private:
77 void AppendChar_Combination(CFX_Char* pCurChar);
78 void AppendChar_Tab(CFX_Char* pCurChar);
79 CFX_BreakType AppendChar_Control(CFX_Char* pCurChar);
80 CFX_BreakType AppendChar_Arabic(CFX_Char* pCurChar);
81 CFX_BreakType AppendChar_Others(CFX_Char* pCurChar);
82
83 void ResetContextCharStyles();
84 bool EndBreak_SplitLine(CFX_BreakLine* pNextLine, bool bAllChars);
85 void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_BreakType dwStatus);
86 void EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
87 bool bAllChars,
88 CFX_BreakType dwStatus);
Haibo Huang49cc9302020-04-27 16:14:24 -070089 int32_t GetBreakPos(std::vector<CFX_Char>* pChars,
90 bool bAllChars,
91 bool bOnlyBrk,
92 int32_t* pEndPos);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070093 void SplitTextLine(CFX_BreakLine* pCurLine,
94 CFX_BreakLine* pNextLine,
Haibo Huang49cc9302020-04-27 16:14:24 -070095 bool bAllChars);
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070096
97 int32_t m_iAlignment;
98 int32_t m_iCombWidth;
99};
100
101#endif // XFA_FGAS_LAYOUT_CFX_TXTBREAK_H_