OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fgas/layout/fgas_textbreak.h" | 7 #include "xfa/fgas/layout/fgas_textbreak.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
| 11 #include "core/fxcrt/include/fx_arabic.h" |
11 #include "core/fxcrt/include/fx_arb.h" | 12 #include "core/fxcrt/include/fx_arb.h" |
12 #include "core/fxcrt/include/fx_memory.h" | 13 #include "core/fxcrt/include/fx_memory.h" |
13 #include "xfa/fgas/layout/fgas_linebreak.h" | 14 #include "xfa/fgas/layout/fgas_linebreak.h" |
14 #include "xfa/fgas/layout/fgas_unicode.h" | 15 #include "xfa/fgas/layout/fgas_unicode.h" |
15 | 16 |
16 namespace { | |
17 | |
18 class CFX_TxtLine { | |
19 public: | |
20 CFX_TxtLine(int32_t iBlockSize) | |
21 : m_iStart(0), m_iWidth(0), m_iArabicChars(0) { | |
22 m_pLineChars = new CFX_TxtCharArray; | |
23 m_pLinePieces = new CFX_TxtPieceArray(16); | |
24 } | |
25 ~CFX_TxtLine() { | |
26 RemoveAll(); | |
27 delete m_pLineChars; | |
28 delete m_pLinePieces; | |
29 } | |
30 int32_t CountChars() const { return m_pLineChars->GetSize(); } | |
31 CFX_TxtChar* GetCharPtr(int32_t index) const { | |
32 FXSYS_assert(index > -1 && index < m_pLineChars->GetSize()); | |
33 return m_pLineChars->GetDataPtr(index); | |
34 } | |
35 int32_t CountPieces() const { return m_pLinePieces->GetSize(); } | |
36 CFX_TxtPiece* GetPiecePtr(int32_t index) const { | |
37 FXSYS_assert(index > -1 && index < m_pLinePieces->GetSize()); | |
38 return m_pLinePieces->GetPtrAt(index); | |
39 } | |
40 void GetString(CFX_WideString& wsStr) const { | |
41 int32_t iCount = m_pLineChars->GetSize(); | |
42 FX_WCHAR* pBuf = wsStr.GetBuffer(iCount); | |
43 CFX_Char* pChar; | |
44 for (int32_t i = 0; i < iCount; i++) { | |
45 pChar = m_pLineChars->GetDataPtr(i); | |
46 *pBuf++ = (FX_WCHAR)pChar->m_wCharCode; | |
47 } | |
48 wsStr.ReleaseBuffer(iCount); | |
49 } | |
50 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { | |
51 m_pLineChars->RemoveAll(); | |
52 m_pLinePieces->RemoveAll(bLeaveMemory); | |
53 m_iWidth = 0; | |
54 m_iArabicChars = 0; | |
55 } | |
56 CFX_TxtCharArray* m_pLineChars; | |
57 CFX_TxtPieceArray* m_pLinePieces; | |
58 int32_t m_iStart; | |
59 int32_t m_iWidth; | |
60 int32_t m_iArabicChars; | |
61 }; | |
62 | |
63 class CFX_TxtBreak : public IFX_TxtBreak { | |
64 public: | |
65 CFX_TxtBreak(uint32_t dwPolicies); | |
66 ~CFX_TxtBreak(); | |
67 virtual void Release() { delete this; } | |
68 virtual void SetLineWidth(FX_FLOAT fLineWidth); | |
69 virtual void SetLinePos(FX_FLOAT fLinePos); | |
70 virtual uint32_t GetLayoutStyles() const { return m_dwLayoutStyles; } | |
71 virtual void SetLayoutStyles(uint32_t dwLayoutStyles); | |
72 virtual void SetFont(IFX_Font* pFont); | |
73 virtual void SetFontSize(FX_FLOAT fFontSize); | |
74 virtual void SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant); | |
75 virtual void SetDefaultChar(FX_WCHAR wch); | |
76 virtual void SetParagraphBreakChar(FX_WCHAR wch); | |
77 virtual void SetLineBreakTolerance(FX_FLOAT fTolerance); | |
78 virtual void SetHorizontalScale(int32_t iScale); | |
79 virtual void SetVerticalScale(int32_t iScale); | |
80 virtual void SetCharRotation(int32_t iCharRotation); | |
81 virtual void SetCharSpace(FX_FLOAT fCharSpace); | |
82 virtual void SetAlignment(int32_t iAlignment); | |
83 virtual uint32_t GetContextCharStyles() const; | |
84 virtual void SetContextCharStyles(uint32_t dwCharStyles); | |
85 virtual void SetCombWidth(FX_FLOAT fCombWidth); | |
86 virtual void SetUserData(void* pUserData); | |
87 virtual uint32_t AppendChar(FX_WCHAR wch); | |
88 virtual uint32_t EndBreak(uint32_t dwStatus = FX_TXTBREAK_PieceBreak); | |
89 virtual int32_t CountBreakChars() const; | |
90 virtual int32_t CountBreakPieces() const; | |
91 virtual const CFX_TxtPiece* GetBreakPiece(int32_t index) const; | |
92 virtual void ClearBreakPieces(); | |
93 virtual void Reset(); | |
94 virtual int32_t GetDisplayPos( | |
95 const FX_TXTRUN* pTxtRun, | |
96 FXTEXT_CHARPOS* pCharPos, | |
97 FX_BOOL bCharCode = FALSE, | |
98 CFX_WideString* pWSForms = NULL, | |
99 FX_AdjustCharDisplayPos pAdjustPos = NULL) const; | |
100 virtual int32_t GetCharRects(const FX_TXTRUN* pTxtRun, | |
101 CFX_RectFArray& rtArray, | |
102 FX_BOOL bCharBBox = FALSE) const; | |
103 void AppendChar_PageLoad(CFX_Char* pCurChar, uint32_t dwProps); | |
104 uint32_t AppendChar_Combination(CFX_Char* pCurChar, int32_t iRotation); | |
105 uint32_t AppendChar_Tab(CFX_Char* pCurChar, int32_t iRotation); | |
106 uint32_t AppendChar_Control(CFX_Char* pCurChar, int32_t iRotation); | |
107 uint32_t AppendChar_Arabic(CFX_Char* pCurChar, int32_t iRotation); | |
108 uint32_t AppendChar_Others(CFX_Char* pCurChar, int32_t iRotation); | |
109 | |
110 protected: | |
111 uint32_t m_dwPolicies; | |
112 FX_BOOL m_bPagination; | |
113 IFX_ArabicChar* m_pArabicChar; | |
114 int32_t m_iLineWidth; | |
115 uint32_t m_dwLayoutStyles; | |
116 FX_BOOL m_bVertical; | |
117 FX_BOOL m_bArabicContext; | |
118 FX_BOOL m_bArabicShapes; | |
119 FX_BOOL m_bRTL; | |
120 FX_BOOL m_bSingleLine; | |
121 FX_BOOL m_bCombText; | |
122 int32_t m_iArabicContext; | |
123 int32_t m_iCurArabicContext; | |
124 IFX_Font* m_pFont; | |
125 int32_t m_iFontSize; | |
126 FX_BOOL m_bEquidistant; | |
127 int32_t m_iTabWidth; | |
128 FX_WCHAR m_wDefChar; | |
129 FX_WCHAR m_wParagBreakChar; | |
130 int32_t m_iDefChar; | |
131 int32_t m_iLineRotation; | |
132 int32_t m_iCharRotation; | |
133 int32_t m_iRotation; | |
134 int32_t m_iAlignment; | |
135 uint32_t m_dwContextCharStyles; | |
136 int32_t m_iCombWidth; | |
137 void* m_pUserData; | |
138 uint32_t m_dwCharType; | |
139 FX_BOOL m_bCurRTL; | |
140 int32_t m_iCurAlignment; | |
141 FX_BOOL m_bArabicNumber; | |
142 FX_BOOL m_bArabicComma; | |
143 CFX_TxtLine* m_pTxtLine1; | |
144 CFX_TxtLine* m_pTxtLine2; | |
145 CFX_TxtLine* m_pCurLine; | |
146 int32_t m_iReady; | |
147 int32_t m_iTolerance; | |
148 int32_t m_iHorScale; | |
149 int32_t m_iVerScale; | |
150 int32_t m_iCharSpace; | |
151 void SetBreakStatus(); | |
152 int32_t GetLineRotation(uint32_t dwStyles) const; | |
153 CFX_TxtChar* GetLastChar(int32_t index, FX_BOOL bOmitChar = TRUE) const; | |
154 CFX_TxtLine* GetTxtLine(FX_BOOL bReady) const; | |
155 CFX_TxtPieceArray* GetTxtPieces(FX_BOOL bReady) const; | |
156 uint32_t GetUnifiedCharType(uint32_t dwType) const; | |
157 void ResetArabicContext(); | |
158 void ResetContextCharStyles(); | |
159 void EndBreak_UpdateArabicShapes(); | |
160 FX_BOOL EndBreak_SplitLine(CFX_TxtLine* pNextLine, | |
161 FX_BOOL bAllChars, | |
162 uint32_t dwStatus); | |
163 void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus); | |
164 void EndBreak_Alignment(CFX_TPOArray& tpos, | |
165 FX_BOOL bAllChars, | |
166 uint32_t dwStatus); | |
167 int32_t GetBreakPos(CFX_TxtCharArray& ca, | |
168 int32_t& iEndPos, | |
169 FX_BOOL bAllChars = FALSE, | |
170 FX_BOOL bOnlyBrk = FALSE); | |
171 void SplitTextLine(CFX_TxtLine* pCurLine, | |
172 CFX_TxtLine* pNextLine, | |
173 FX_BOOL bAllChars = FALSE); | |
174 }; | |
175 | |
176 } // namespace | |
177 | |
178 extern const FX_LINEBREAKTYPE gs_FX_LineBreak_PairTable[64][32]; | |
179 IFX_TxtBreak* IFX_TxtBreak::Create(uint32_t dwPolicies) { | |
180 return new CFX_TxtBreak(dwPolicies); | |
181 } | |
182 CFX_TxtBreak::CFX_TxtBreak(uint32_t dwPolicies) | 17 CFX_TxtBreak::CFX_TxtBreak(uint32_t dwPolicies) |
183 : m_dwPolicies(dwPolicies), | 18 : m_dwPolicies(dwPolicies), |
184 m_pArabicChar(NULL), | 19 m_pArabicChar(NULL), |
185 m_iLineWidth(2000000), | 20 m_iLineWidth(2000000), |
186 m_dwLayoutStyles(0), | 21 m_dwLayoutStyles(0), |
187 m_bVertical(FALSE), | 22 m_bVertical(FALSE), |
188 m_bArabicContext(FALSE), | 23 m_bArabicContext(FALSE), |
189 m_bArabicShapes(FALSE), | 24 m_bArabicShapes(FALSE), |
190 m_bRTL(FALSE), | 25 m_bRTL(FALSE), |
191 m_bSingleLine(FALSE), | 26 m_bSingleLine(FALSE), |
(...skipping 17 matching lines...) Expand all Loading... |
209 m_dwCharType(0), | 44 m_dwCharType(0), |
210 m_bArabicNumber(FALSE), | 45 m_bArabicNumber(FALSE), |
211 m_bArabicComma(FALSE), | 46 m_bArabicComma(FALSE), |
212 m_pCurLine(NULL), | 47 m_pCurLine(NULL), |
213 m_iReady(0), | 48 m_iReady(0), |
214 m_iTolerance(0), | 49 m_iTolerance(0), |
215 m_iHorScale(100), | 50 m_iHorScale(100), |
216 m_iVerScale(100), | 51 m_iVerScale(100), |
217 m_iCharSpace(0) { | 52 m_iCharSpace(0) { |
218 m_bPagination = (m_dwPolicies & FX_TXTBREAKPOLICY_Pagination) != 0; | 53 m_bPagination = (m_dwPolicies & FX_TXTBREAKPOLICY_Pagination) != 0; |
219 m_pArabicChar = IFX_ArabicChar::Create(); | 54 m_pArabicChar = new CFX_ArabicChar; |
220 if (m_bPagination) { | 55 if (m_bPagination) { |
221 m_pTxtLine1 = new CFX_TxtLine(sizeof(CFX_Char)); | 56 m_pTxtLine1 = new CFX_TxtLine(sizeof(CFX_Char)); |
222 m_pTxtLine2 = new CFX_TxtLine(sizeof(CFX_Char)); | 57 m_pTxtLine2 = new CFX_TxtLine(sizeof(CFX_Char)); |
223 } else { | 58 } else { |
224 m_pTxtLine1 = new CFX_TxtLine(sizeof(CFX_TxtChar)); | 59 m_pTxtLine1 = new CFX_TxtLine(sizeof(CFX_TxtChar)); |
225 m_pTxtLine2 = new CFX_TxtLine(sizeof(CFX_TxtChar)); | 60 m_pTxtLine2 = new CFX_TxtLine(sizeof(CFX_TxtChar)); |
226 } | 61 } |
227 m_pCurLine = m_pTxtLine1; | 62 m_pCurLine = m_pTxtLine1; |
228 ResetArabicContext(); | 63 ResetArabicContext(); |
229 } | 64 } |
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 rtBBoxF.height = fHeight; | 1650 rtBBoxF.height = fHeight; |
1816 rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); | 1651 rtBBoxF.top = std::max(rtBBoxF.top, 0.0f); |
1817 } | 1652 } |
1818 rtArray.SetAt(i, rtBBoxF); | 1653 rtArray.SetAt(i, rtBBoxF); |
1819 continue; | 1654 continue; |
1820 } | 1655 } |
1821 rtArray.SetAt(i, rect); | 1656 rtArray.SetAt(i, rect); |
1822 } | 1657 } |
1823 return iLength; | 1658 return iLength; |
1824 } | 1659 } |
OLD | NEW |