Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1265)

Unified Diff: core/src/fxcrt/fx_bidi.cpp

Issue 1197643002: Cleanup IFX_BidiChar (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments, similarity 20 Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/src/fxcrt/fx_arabic.cpp ('k') | core/src/fxcrt/fx_bidi_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxcrt/fx_bidi.cpp
diff --git a/core/src/fxcrt/fx_arabic.cpp b/core/src/fxcrt/fx_bidi.cpp
similarity index 36%
rename from core/src/fxcrt/fx_arabic.cpp
rename to core/src/fxcrt/fx_bidi.cpp
index 3b7d0c1c71a98781aab5416ddc84c8519cc699e7..0310fa0e94b9d676fc9c9d74dd93691a2a039ccf 100644
--- a/core/src/fxcrt/fx_arabic.cpp
+++ b/core/src/fxcrt/fx_bidi.cpp
@@ -4,81 +4,63 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "../../include/fxcrt/fx_bidi.h"
#include "../../include/fxcrt/fx_ucd.h"
-#include "fx_arabic.h"
-extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536];
-IFX_BidiChar* IFX_BidiChar::Create() {
- return new CFX_BidiChar;
-}
CFX_BidiChar::CFX_BidiChar()
- : m_bSeparateNeutral(TRUE),
- m_iCurStart(0),
+ : m_iCurStart(0),
m_iCurCount(0),
- m_iCurBidi(0),
- m_iLastBidi(0),
+ m_CurBidi(NEUTRAL),
m_iLastStart(0),
- m_iLastCount(0) {}
-void CFX_BidiChar::SetPolicy(FX_BOOL bSeparateNeutral) {
- m_bSeparateNeutral = bSeparateNeutral;
+ m_iLastCount(0),
+ m_LastBidi(NEUTRAL) {
+}
+
+CFX_BidiChar::~CFX_BidiChar() {
}
-FX_BOOL CFX_BidiChar::AppendChar(FX_WCHAR wch) {
- FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
+bool CFX_BidiChar::AppendChar(FX_WCHAR wch) {
+ FX_DWORD dwProps = FX_GetUnicodeProperties(wch);
int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS;
- int32_t iContext = 0;
+ Direction bidi = NEUTRAL;
switch (iBidiCls) {
case FX_BIDICLASS_L:
case FX_BIDICLASS_AN:
case FX_BIDICLASS_EN:
- iContext = 1;
+ bidi = LEFT;
break;
case FX_BIDICLASS_R:
case FX_BIDICLASS_AL:
- iContext = 2;
+ bidi = RIGHT;
break;
}
- FX_BOOL bRet = FALSE;
- if (iContext != m_iCurBidi) {
- if (m_bSeparateNeutral) {
- bRet = TRUE;
- } else {
- if (m_iCurBidi == 0) {
- bRet = (m_iCurCount > 0);
- } else {
- bRet = (iContext != 0);
- }
- }
- if (bRet) {
- m_iLastBidi = m_iCurBidi;
- m_iLastStart = m_iCurStart;
- m_iCurStart = m_iCurCount;
- m_iLastCount = m_iCurCount - m_iLastStart;
- }
- if (m_bSeparateNeutral || iContext != 0) {
- m_iCurBidi = iContext;
- }
+
+ bool bRet = (bidi != m_CurBidi);
+ if (bRet) {
+ SaveCurrentStateToLastState();
+ m_CurBidi = bidi;
}
m_iCurCount++;
return bRet;
}
-FX_BOOL CFX_BidiChar::EndChar() {
- m_iLastBidi = m_iCurBidi;
- m_iLastStart = m_iCurStart;
- m_iCurStart = m_iCurCount;
- m_iLastCount = m_iCurCount - m_iLastStart;
+
+bool CFX_BidiChar::EndChar() {
+ SaveCurrentStateToLastState();
return m_iLastCount > 0;
}
-int32_t CFX_BidiChar::GetBidiInfo(int32_t& iStart, int32_t& iCount) {
- iStart = m_iLastStart;
- iCount = m_iLastCount;
- return m_iLastBidi;
+
+CFX_BidiChar::Direction CFX_BidiChar::GetBidiInfo(int32_t* iStart,
+ int32_t* iCount) const {
+ if (iStart)
+ *iStart = m_iLastStart;
+ if (iCount)
+ *iCount = m_iLastCount;
+ return m_LastBidi;
}
-void CFX_BidiChar::Reset() {
- m_iCurStart = 0;
- m_iCurCount = 0;
- m_iCurBidi = 0;
- m_iLastBidi = 0;
- m_iLastStart = 0;
- m_iLastCount = 0;
+
+void CFX_BidiChar::SaveCurrentStateToLastState() {
+ m_LastBidi = m_CurBidi;
+ m_iLastStart = m_iCurStart;
+ m_iCurStart = m_iCurCount;
+ m_iLastCount = m_iCurCount - m_iLastStart;
}
« no previous file with comments | « core/src/fxcrt/fx_arabic.cpp ('k') | core/src/fxcrt/fx_bidi_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698