summaryrefslogtreecommitdiff
path: root/core/src/fxcrt/fx_bidi.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-29 15:01:55 -0700
committerLei Zhang <thestig@chromium.org>2015-10-29 15:01:55 -0700
commitee02ea37e8f85920885600d56df706d690e648ff (patch)
tree055bbc66a5c95a8bc75ccc491f73505bb8eb6676 /core/src/fxcrt/fx_bidi.cpp
parent5a88b1131c450dee0500a02f80f0838385e4c4d2 (diff)
downloadpdfium-ee02ea37e8f85920885600d56df706d690e648ff.tar.xz
XFA: Manual merge of Clean up IFX_BidiChar
- Replace IFX_BidiChar with just CFX_BidiChar - Document implementation - Change out parameters to pointers - Remove dead code - Add an enum for bidi directions - Move several externs to a header - Add unit tests Original CL: https://codereview.chromium.org/1197643002 This version does not remove fx_arb.h and fx_arabic.h, as there is code on the XFA branch that still uses parts of it. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1423103002 .
Diffstat (limited to 'core/src/fxcrt/fx_bidi.cpp')
-rw-r--r--core/src/fxcrt/fx_bidi.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/core/src/fxcrt/fx_bidi.cpp b/core/src/fxcrt/fx_bidi.cpp
new file mode 100644
index 0000000000..0310fa0e94
--- /dev/null
+++ b/core/src/fxcrt/fx_bidi.cpp
@@ -0,0 +1,66 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fxcrt/fx_bidi.h"
+#include "../../include/fxcrt/fx_ucd.h"
+
+CFX_BidiChar::CFX_BidiChar()
+ : m_iCurStart(0),
+ m_iCurCount(0),
+ m_CurBidi(NEUTRAL),
+ m_iLastStart(0),
+ m_iLastCount(0),
+ m_LastBidi(NEUTRAL) {
+}
+
+CFX_BidiChar::~CFX_BidiChar() {
+}
+
+bool CFX_BidiChar::AppendChar(FX_WCHAR wch) {
+ FX_DWORD dwProps = FX_GetUnicodeProperties(wch);
+ int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS;
+ Direction bidi = NEUTRAL;
+ switch (iBidiCls) {
+ case FX_BIDICLASS_L:
+ case FX_BIDICLASS_AN:
+ case FX_BIDICLASS_EN:
+ bidi = LEFT;
+ break;
+ case FX_BIDICLASS_R:
+ case FX_BIDICLASS_AL:
+ bidi = RIGHT;
+ break;
+ }
+
+ bool bRet = (bidi != m_CurBidi);
+ if (bRet) {
+ SaveCurrentStateToLastState();
+ m_CurBidi = bidi;
+ }
+ m_iCurCount++;
+ return bRet;
+}
+
+bool CFX_BidiChar::EndChar() {
+ SaveCurrentStateToLastState();
+ return m_iLastCount > 0;
+}
+
+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::SaveCurrentStateToLastState() {
+ m_LastBidi = m_CurBidi;
+ m_iLastStart = m_iCurStart;
+ m_iCurStart = m_iCurCount;
+ m_iLastCount = m_iCurCount - m_iLastStart;
+}