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 "../../include/fxcrt/fx_bidi.h" |
7 #include "../../include/fxcrt/fx_ucd.h" | 8 #include "../../include/fxcrt/fx_ucd.h" |
8 #include "fx_arabic.h" | |
9 | 9 |
10 extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536]; | |
11 IFX_BidiChar* IFX_BidiChar::Create() { | |
12 return new CFX_BidiChar; | |
13 } | |
14 CFX_BidiChar::CFX_BidiChar() | 10 CFX_BidiChar::CFX_BidiChar() |
15 : m_bSeparateNeutral(TRUE), | 11 : m_iCurStart(0), |
16 m_iCurStart(0), | |
17 m_iCurCount(0), | 12 m_iCurCount(0), |
18 m_iCurBidi(0), | 13 m_CurBidi(NEUTRAL), |
19 m_iLastBidi(0), | |
20 m_iLastStart(0), | 14 m_iLastStart(0), |
21 m_iLastCount(0) {} | 15 m_iLastCount(0), |
22 void CFX_BidiChar::SetPolicy(FX_BOOL bSeparateNeutral) { | 16 m_LastBidi(NEUTRAL) { |
23 m_bSeparateNeutral = bSeparateNeutral; | |
24 } | 17 } |
25 | 18 |
26 FX_BOOL CFX_BidiChar::AppendChar(FX_WCHAR wch) { | 19 CFX_BidiChar::~CFX_BidiChar() { |
27 FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; | 20 } |
| 21 |
| 22 bool CFX_BidiChar::AppendChar(FX_WCHAR wch) { |
| 23 FX_DWORD dwProps = FX_GetUnicodeProperties(wch); |
28 int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; | 24 int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; |
29 int32_t iContext = 0; | 25 Direction bidi = NEUTRAL; |
30 switch (iBidiCls) { | 26 switch (iBidiCls) { |
31 case FX_BIDICLASS_L: | 27 case FX_BIDICLASS_L: |
32 case FX_BIDICLASS_AN: | 28 case FX_BIDICLASS_AN: |
33 case FX_BIDICLASS_EN: | 29 case FX_BIDICLASS_EN: |
34 iContext = 1; | 30 bidi = LEFT; |
35 break; | 31 break; |
36 case FX_BIDICLASS_R: | 32 case FX_BIDICLASS_R: |
37 case FX_BIDICLASS_AL: | 33 case FX_BIDICLASS_AL: |
38 iContext = 2; | 34 bidi = RIGHT; |
39 break; | 35 break; |
40 } | 36 } |
41 FX_BOOL bRet = FALSE; | 37 |
42 if (iContext != m_iCurBidi) { | 38 bool bRet = (bidi != m_CurBidi); |
43 if (m_bSeparateNeutral) { | 39 if (bRet) { |
44 bRet = TRUE; | 40 SaveCurrentStateToLastState(); |
45 } else { | 41 m_CurBidi = bidi; |
46 if (m_iCurBidi == 0) { | |
47 bRet = (m_iCurCount > 0); | |
48 } else { | |
49 bRet = (iContext != 0); | |
50 } | |
51 } | |
52 if (bRet) { | |
53 m_iLastBidi = m_iCurBidi; | |
54 m_iLastStart = m_iCurStart; | |
55 m_iCurStart = m_iCurCount; | |
56 m_iLastCount = m_iCurCount - m_iLastStart; | |
57 } | |
58 if (m_bSeparateNeutral || iContext != 0) { | |
59 m_iCurBidi = iContext; | |
60 } | |
61 } | 42 } |
62 m_iCurCount++; | 43 m_iCurCount++; |
63 return bRet; | 44 return bRet; |
64 } | 45 } |
65 FX_BOOL CFX_BidiChar::EndChar() { | 46 |
66 m_iLastBidi = m_iCurBidi; | 47 bool CFX_BidiChar::EndChar() { |
| 48 SaveCurrentStateToLastState(); |
| 49 return m_iLastCount > 0; |
| 50 } |
| 51 |
| 52 CFX_BidiChar::Direction CFX_BidiChar::GetBidiInfo(int32_t* iStart, |
| 53 int32_t* iCount) const { |
| 54 if (iStart) |
| 55 *iStart = m_iLastStart; |
| 56 if (iCount) |
| 57 *iCount = m_iLastCount; |
| 58 return m_LastBidi; |
| 59 } |
| 60 |
| 61 void CFX_BidiChar::SaveCurrentStateToLastState() { |
| 62 m_LastBidi = m_CurBidi; |
67 m_iLastStart = m_iCurStart; | 63 m_iLastStart = m_iCurStart; |
68 m_iCurStart = m_iCurCount; | 64 m_iCurStart = m_iCurCount; |
69 m_iLastCount = m_iCurCount - m_iLastStart; | 65 m_iLastCount = m_iCurCount - m_iLastStart; |
70 return m_iLastCount > 0; | |
71 } | 66 } |
72 int32_t CFX_BidiChar::GetBidiInfo(int32_t& iStart, int32_t& iCount) { | |
73 iStart = m_iLastStart; | |
74 iCount = m_iLastCount; | |
75 return m_iLastBidi; | |
76 } | |
77 void CFX_BidiChar::Reset() { | |
78 m_iCurStart = 0; | |
79 m_iCurCount = 0; | |
80 m_iCurBidi = 0; | |
81 m_iLastBidi = 0; | |
82 m_iLastStart = 0; | |
83 m_iLastCount = 0; | |
84 } | |
OLD | NEW |