Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 1 | // 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. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 13 | #include "core/fxcrt/fx_coordinates.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 14 | #include "xfa/fgas/layout/cfx_break.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 15 | #include "xfa/fgas/layout/cfx_char.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 16 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 17 | class CFGAS_GEFont; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 18 | class TextCharPos; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 19 | |
| 20 | #define FX_TXTCHARSTYLE_ArabicShadda 0x0020 |
| 21 | #define FX_TXTCHARSTYLE_OddBidiLevel 0x0040 |
| 22 | |
| 23 | enum 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 | |
| 30 | inline bool CFX_BreakTypeNoneOrPiece(CFX_BreakType type) { |
| 31 | return type == CFX_BreakType::None || type == CFX_BreakType::Piece; |
| 32 | } |
| 33 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 34 | class CFX_TxtBreak final : public CFX_Break { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 35 | public: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 36 | 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. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 64 | 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 Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 72 | size_t GetDisplayPos(const Run* pTxtRun, TextCharPos* pCharPos) const; |
| 73 | std::vector<CFX_RectF> GetCharRects(const Run* pTxtRun, bool bCharBBox) const; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 74 | 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 Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 89 | int32_t GetBreakPos(std::vector<CFX_Char>* pChars, |
| 90 | bool bAllChars, |
| 91 | bool bOnlyBrk, |
| 92 | int32_t* pEndPos); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 93 | void SplitTextLine(CFX_BreakLine* pCurLine, |
| 94 | CFX_BreakLine* pNextLine, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 95 | bool bAllChars); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 96 | |
| 97 | int32_t m_iAlignment; |
| 98 | int32_t m_iCombWidth; |
| 99 | }; |
| 100 | |
| 101 | #endif // XFA_FGAS_LAYOUT_CFX_TXTBREAK_H_ |