diff options
author | Lei Zhang <thestig@chromium.org> | 2015-10-29 15:01:55 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-10-29 15:01:55 -0700 |
commit | ee02ea37e8f85920885600d56df706d690e648ff (patch) | |
tree | 055bbc66a5c95a8bc75ccc491f73505bb8eb6676 | |
parent | 5a88b1131c450dee0500a02f80f0838385e4c4d2 (diff) | |
download | pdfium-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 .
-rw-r--r-- | BUILD.gn | 3 | ||||
-rw-r--r-- | core/include/fxcrt/fx_arb.h | 42 | ||||
-rw-r--r-- | core/include/fxcrt/fx_bidi.h | 59 | ||||
-rw-r--r-- | core/include/fxcrt/fx_ucd.h | 18 | ||||
-rw-r--r-- | core/src/fpdftext/fpdf_text.cpp | 16 | ||||
-rw-r--r-- | core/src/fpdftext/fpdf_text_int.cpp | 36 | ||||
-rw-r--r-- | core/src/fpdftext/text_int.h | 2 | ||||
-rw-r--r-- | core/src/fxcrt/fx_arabic.cpp | 383 | ||||
-rw-r--r-- | core/src/fxcrt/fx_arabic.h | 26 | ||||
-rw-r--r-- | core/src/fxcrt/fx_bidi.cpp | 66 | ||||
-rw-r--r-- | core/src/fxcrt/fx_bidi_unittest.cpp | 136 | ||||
-rw-r--r-- | core/src/fxcrt/fx_unicode.cpp | 48 | ||||
-rw-r--r-- | pdfium.gyp | 3 |
13 files changed, 539 insertions, 299 deletions
@@ -467,6 +467,7 @@ static_library("fxcrt") { sources = [ "core/include/fxcrt/fx_arb.h", "core/include/fxcrt/fx_basic.h", + "core/include/fxcrt/fx_bidi.h", "core/include/fxcrt/fx_coordinates.h", "core/include/fxcrt/fx_ext.h", "core/include/fxcrt/fx_memory.h", @@ -491,6 +492,7 @@ static_library("fxcrt") { "core/src/fxcrt/fx_basic_utf.cpp", "core/src/fxcrt/fx_basic_util.cpp", "core/src/fxcrt/fx_basic_wstring.cpp", + "core/src/fxcrt/fx_bidi.cpp", "core/src/fxcrt/fx_extension.cpp", "core/src/fxcrt/fx_ucddata.cpp", "core/src/fxcrt/fx_unicode.cpp", @@ -1477,6 +1479,7 @@ test("pdfium_unittests") { "core/src/fxcrt/fx_basic_bstring_unittest.cpp", "core/src/fxcrt/fx_basic_memmgr_unittest.cpp", "core/src/fxcrt/fx_basic_wstring_unittest.cpp", + "core/src/fxcrt/fx_bidi_unittest.cpp", "core/src/fxcrt/fx_system_unittest.cpp", "third_party/base/nonstd_unique_ptr_unittest.cpp", "xfa/src/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp", diff --git a/core/include/fxcrt/fx_arb.h b/core/include/fxcrt/fx_arb.h index d3612db4e7..6760ef3d79 100644 --- a/core/include/fxcrt/fx_arb.h +++ b/core/include/fxcrt/fx_arb.h @@ -11,39 +11,35 @@ #include "fx_ucd.h" class IFX_ArabicChar; -class IFX_BidiChar; -#ifdef __cplusplus -extern "C" { -#endif -typedef struct _FX_ARBFORMTABLE { + +struct FX_ARBFORMTABLE { FX_WCHAR wIsolated; FX_WCHAR wFinal; FX_WCHAR wInitial; FX_WCHAR wMedial; -} FX_ARBFORMTABLE, *FX_LPARBFORMTABLE; -typedef FX_ARBFORMTABLE const* FX_LPCARBFORMTABLE; -typedef struct _FX_ARAALEF { +}; + +struct FX_ARAALEF { FX_WCHAR wAlef; FX_WCHAR wIsolated; -} FX_ARAALEF, *FX_LPARAALEF; -typedef FX_ARAALEF const* FX_LPCARAALEF; -typedef struct _FX_ARASHADDA { +}; + +struct FX_ARASHADDA { FX_WCHAR wShadda; FX_WCHAR wIsolated; -} FX_ARASHADDA, *FX_LPARASHADDA; -typedef FX_ARASHADDA const* FX_LPCARASHADDA; -FX_LPCARBFORMTABLE FX_GetArabicFormTable(FX_WCHAR unicode); +}; + +const FX_ARBFORMTABLE* FX_GetArabicFormTable(FX_WCHAR unicode); FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef); FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda); -#ifdef __cplusplus -}; -#endif + enum FX_ARBPOSITION { FX_ARBPOSITION_Isolated = 0, FX_ARBPOSITION_Final, FX_ARBPOSITION_Initial, FX_ARBPOSITION_Medial, }; + class IFX_ArabicChar { public: static IFX_ArabicChar* Create(); @@ -58,6 +54,7 @@ class IFX_ArabicChar { const CFX_Char* prev, const CFX_Char* next) const = 0; }; + void FX_BidiLine(CFX_WideString& wsText, int32_t iBaseLevel = 0); void FX_BidiLine(CFX_TxtCharArray& chars, int32_t iCount, @@ -65,16 +62,5 @@ void FX_BidiLine(CFX_TxtCharArray& chars, void FX_BidiLine(CFX_RTFCharArray& chars, int32_t iCount, int32_t iBaseLevel = 0); -class IFX_BidiChar { - public: - static IFX_BidiChar* Create(); - virtual ~IFX_BidiChar() {} - - virtual void SetPolicy(FX_BOOL bSeparateNeutral = TRUE) = 0; - virtual FX_BOOL AppendChar(FX_WCHAR wch) = 0; - virtual FX_BOOL EndChar() = 0; - virtual int32_t GetBidiInfo(int32_t& iStart, int32_t& iCount) = 0; - virtual void Reset() = 0; -}; #endif // CORE_INCLUDE_FXCRT_FX_ARB_H_ diff --git a/core/include/fxcrt/fx_bidi.h b/core/include/fxcrt/fx_bidi.h new file mode 100644 index 0000000000..a55ce6cfd2 --- /dev/null +++ b/core/include/fxcrt/fx_bidi.h @@ -0,0 +1,59 @@ +// 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 + +#ifndef CORE_INCLUDE_FXCRT_FX_BIDI_H_ +#define CORE_INCLUDE_FXCRT_FX_BIDI_H_ + +#include "fx_system.h" + +// Processes characters and group them into segments based on text direction. +class CFX_BidiChar { + public: + enum Direction { NEUTRAL, LEFT, RIGHT }; + + CFX_BidiChar(); + ~CFX_BidiChar(); + + // Append a character and classify it as left, right, or neutral. + // Returns true if the character has a different direction than the + // existing direction to indicate there is a segment to process. + bool AppendChar(FX_WCHAR wch); + + // Call this after the last character has been appended. AppendChar() + // must not be called after this. + // Returns true if there is still a segment to process. + bool EndChar(); + + // Get information about the segment to process. + // The segment's start position and character count is returned in |iStart| + // and |iCount|, respectively. Pass in null pointers if the information is + // not needed. + // Returns the segment direction. + Direction GetBidiInfo(int32_t* iStart, int32_t* iCount) const; + + private: + void SaveCurrentStateToLastState(); + + // Position of the current segment. + int32_t m_iCurStart; + + // Number of characters in the current segment. + int32_t m_iCurCount; + + // Direction of the current segment. + Direction m_CurBidi; + + // Number of characters in the last segment. + int32_t m_iLastStart; + + // Number of characters in the last segment. + int32_t m_iLastCount; + + // Direction of the last segment. + Direction m_LastBidi; +}; + +#endif // CORE_INCLUDE_FXCRT_FX_BIDI_H_ diff --git a/core/include/fxcrt/fx_ucd.h b/core/include/fxcrt/fx_ucd.h index 823b80700a..d4a43bd096 100644 --- a/core/include/fxcrt/fx_ucd.h +++ b/core/include/fxcrt/fx_ucd.h @@ -101,25 +101,9 @@ enum FX_CHARTYPE { FX_CHARTYPE_ArabicForm = (11 << FX_CHARTYPEBITS), FX_CHARTYPE_Arabic = (12 << FX_CHARTYPEBITS), }; -typedef struct _FX_CHARPROPERTIES { - union FX_CHARPROPERTIES_UNION { - struct FX_CHARPROPERTIES_BIT { - FX_DWORD dwBreakType : 6; - FX_DWORD dwBidiClass : 5; - FX_DWORD dwCharType : 4; - FX_DWORD dwRotation : 1; - FX_DWORD dwCJKSpecial : 1; - FX_DWORD dwVertIndex : 6; - FX_DWORD dwBidiIndex : 9; - }; - FX_DWORD dwCharProps; - }; -} FX_CHARPROPERTIES; + FX_DWORD FX_GetUnicodeProperties(FX_WCHAR wch); FX_BOOL FX_IsCtrlCode(FX_WCHAR ch); -FX_BOOL FX_IsRotationCode(FX_WCHAR ch); -FX_BOOL FX_IsCombinationChar(FX_WCHAR wch); -FX_BOOL FX_IsBidiChar(FX_WCHAR wch); FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical); FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_DWORD dwProps, diff --git a/core/src/fpdftext/fpdf_text.cpp b/core/src/fpdftext/fpdf_text.cpp index 2bd8b7d6ce..9ecbc21bda 100644 --- a/core/src/fpdftext/fpdf_text.cpp +++ b/core/src/fpdftext/fpdf_text.cpp @@ -9,7 +9,7 @@ #include "../../include/fpdfapi/fpdf_pageobj.h" #include "../../include/fpdfapi/fpdf_resource.h" #include "../../include/fpdftext/fpdf_text.h" -#include "../../include/fxcrt/fx_arb.h" +#include "../../include/fxcrt/fx_bidi.h" #include "../../include/fxcrt/fx_ucd.h" #include "text_int.h" #include "txtproc.h" @@ -315,35 +315,35 @@ void NormalizeString(CFX_WideString& str) { return; } CFX_WideString sBuffer; - nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); + nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); CFX_WordArray order; FX_BOOL bR2L = FALSE; int32_t start = 0, count = 0, i = 0; int nR2L = 0, nL2R = 0; for (i = 0; i < str.GetLength(); i++) { if (pBidiChar->AppendChar(str.GetAt(i))) { - int32_t ret = pBidiChar->GetBidiInfo(start, count); + CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); order.Add(start); order.Add(count); order.Add(ret); if (!bR2L) { - if (ret == 2) { + if (ret == CFX_BidiChar::RIGHT) { nR2L++; - } else if (ret == 1) { + } else if (ret == CFX_BidiChar::LEFT) { nL2R++; } } } } if (pBidiChar->EndChar()) { - int32_t ret = pBidiChar->GetBidiInfo(start, count); + CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); order.Add(start); order.Add(count); order.Add(ret); if (!bR2L) { - if (ret == 2) { + if (ret == CFX_BidiChar::RIGHT) { nR2L++; - } else if (ret == 1) { + } else if (ret == CFX_BidiChar::LEFT) { nL2R++; } } diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp index aa25728c15..202fab45fa 100644 --- a/core/src/fpdftext/fpdf_text_int.cpp +++ b/core/src/fpdftext/fpdf_text_int.cpp @@ -13,7 +13,7 @@ #include "../../include/fpdfapi/fpdf_pageobj.h" #include "../../include/fpdfapi/fpdf_resource.h" #include "../../include/fpdftext/fpdf_text.h" -#include "../../include/fxcrt/fx_arb.h" +#include "../../include/fxcrt/fx_bidi.h" #include "../../include/fxcrt/fx_ucd.h" #include "text_int.h" @@ -1001,10 +1001,10 @@ int CPDF_TextPage::GetCharWidth(FX_DWORD charCode, CPDF_Font* pFont) const { } return w; } -void CPDF_TextPage::OnPiece(IFX_BidiChar* pBidi, CFX_WideString& str) { +void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) { int32_t start, count; - int32_t ret = pBidi->GetBidiInfo(start, count); - if (ret == 2) { + CFX_BidiChar::Direction ret = pBidi->GetBidiInfo(&start, &count); + if (ret == CFX_BidiChar::RIGHT) { for (int i = start + count - 1; i >= start; i--) { m_TextBuf.AppendChar(str.GetAt(i)); m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); @@ -1085,7 +1085,7 @@ void CPDF_TextPage::CloseTempLine() { if (count1 <= 0) { return; } - nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); + nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); CFX_WideString str = m_TempTextBuf.GetWideString(); CFX_WordArray order; FX_BOOL bR2L = FALSE; @@ -1107,28 +1107,28 @@ void CPDF_TextPage::CloseTempLine() { bPrevSpace = FALSE; } if (pBidiChar->AppendChar(str.GetAt(i))) { - int32_t ret = pBidiChar->GetBidiInfo(start, count); + CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); order.Add(start); order.Add(count); order.Add(ret); if (!bR2L) { - if (ret == 2) { + if (ret == CFX_BidiChar::RIGHT) { nR2L++; - } else if (ret == 1) { + } else if (ret == CFX_BidiChar::LEFT) { nL2R++; } } } } if (pBidiChar->EndChar()) { - int32_t ret = pBidiChar->GetBidiInfo(start, count); + CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); order.Add(start); order.Add(count); order.Add(ret); if (!bR2L) { - if (ret == 2) { + if (ret == CFX_BidiChar::RIGHT) { nR2L++; - } else if (ret == 1) { + } else if (ret == CFX_BidiChar::LEFT) { nL2R++; } } @@ -1560,7 +1560,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); FX_BOOL bIsBidiAndMirrosInverse = FALSE; - IFX_BidiChar* BidiChar = IFX_BidiChar::Create(); + CFX_BidiChar* BidiChar = new CFX_BidiChar; int32_t nR2L = 0; int32_t nL2R = 0; int32_t start = 0, count = 0; @@ -1579,19 +1579,19 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { continue; } if (BidiChar && BidiChar->AppendChar(wChar)) { - int32_t ret = BidiChar->GetBidiInfo(start, count); - if (ret == 2) { + CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count); + if (ret == CFX_BidiChar::RIGHT) { nR2L++; - } else if (ret == 1) { + } else if (ret == CFX_BidiChar::LEFT) { nL2R++; } } } if (BidiChar && BidiChar->EndChar()) { - int32_t ret = BidiChar->GetBidiInfo(start, count); - if (ret == 2) { + CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count); + if (ret == CFX_BidiChar::RIGHT) { nR2L++; - } else if (ret == 1) { + } else if (ret == CFX_BidiChar::LEFT) { nL2R++; } } diff --git a/core/src/fpdftext/text_int.h b/core/src/fpdftext/text_int.h index b5a7734e54..d10c5501e6 100644 --- a/core/src/fpdftext/text_int.h +++ b/core/src/fpdftext/text_int.h @@ -119,7 +119,7 @@ class CPDF_TextPage : public IPDF_TextPage { CPDF_TextObject* pTextObj2); int GetCharWidth(FX_DWORD charCode, CPDF_Font* pFont) const; void CloseTempLine(); - void OnPiece(IFX_BidiChar* pBidi, CFX_WideString& str); + void OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str); int32_t PreMarkedContent(PDFTEXT_Obj pObj); void ProcessMarkedContent(PDFTEXT_Obj pObj); void CheckMarkedContentObject(int32_t& start, int32_t& nCount) const; diff --git a/core/src/fxcrt/fx_arabic.cpp b/core/src/fxcrt/fx_arabic.cpp index 139e9f1f48..1869cb2008 100644 --- a/core/src/fxcrt/fx_arabic.cpp +++ b/core/src/fxcrt/fx_arabic.cpp @@ -7,112 +7,209 @@ #include "../../include/fxcrt/fx_ucd.h" #include "fx_arabic.h" -#ifdef __cplusplus -extern "C" { -#endif -static const FX_ARBFORMTABLE g_FX_ArabicFormTables[] = { - {0xFE81, 0xFE82, 0xFE81, 0xFE82}, {0xFE83, 0xFE84, 0xFE83, 0xFE84}, - {0xFE85, 0xFE86, 0xFE85, 0xFE86}, {0xFE87, 0xFE88, 0xFE87, 0xFE88}, - {0xFE89, 0xFE8A, 0xFE8B, 0xFE8C}, {0xFE8D, 0xFE8E, 0xFE8D, 0xFE8E}, - {0xFE8F, 0xFE90, 0xFE91, 0xFE92}, {0xFE93, 0xFE94, 0xFE93, 0xFE94}, - {0xFE95, 0xFE96, 0xFE97, 0xFE98}, {0xFE99, 0xFE9A, 0xFE9B, 0xFE9C}, - {0xFE9D, 0xFE9E, 0xFE9F, 0xFEA0}, {0xFEA1, 0xFEA2, 0xFEA3, 0xFEA4}, - {0xFEA5, 0xFEA6, 0xFEA7, 0xFEA8}, {0xFEA9, 0xFEAA, 0xFEA9, 0xFEAA}, - {0xFEAB, 0xFEAC, 0xFEAB, 0xFEAC}, {0xFEAD, 0xFEAE, 0xFEAD, 0xFEAE}, - {0xFEAF, 0xFEB0, 0xFEAF, 0xFEB0}, {0xFEB1, 0xFEB2, 0xFEB3, 0xFEB4}, - {0xFEB5, 0xFEB6, 0xFEB7, 0xFEB8}, {0xFEB9, 0xFEBA, 0xFEBB, 0xFEBC}, - {0xFEBD, 0xFEBE, 0xFEBF, 0xFEC0}, {0xFEC1, 0xFEC2, 0xFEC3, 0xFEC4}, - {0xFEC5, 0xFEC6, 0xFEC7, 0xFEC8}, {0xFEC9, 0xFECA, 0xFECB, 0xFECC}, - {0xFECD, 0xFECE, 0xFECF, 0xFED0}, {0x063B, 0x063B, 0x063B, 0x063B}, - {0x063C, 0x063C, 0x063C, 0x063C}, {0x063D, 0x063D, 0x063D, 0x063D}, - {0x063E, 0x063E, 0x063E, 0x063E}, {0x063F, 0x063F, 0x063F, 0x063F}, - {0x0640, 0x0640, 0x0640, 0x0640}, {0xFED1, 0xFED2, 0xFED3, 0xFED4}, - {0xFED5, 0xFED6, 0xFED7, 0xFED8}, {0xFED9, 0xFEDA, 0xFEDB, 0xFEDC}, - {0xFEDD, 0xFEDE, 0xFEDF, 0xFEE0}, {0xFEE1, 0xFEE2, 0xFEE3, 0xFEE4}, - {0xFEE5, 0xFEE6, 0xFEE7, 0xFEE8}, {0xFEE9, 0xFEEA, 0xFEEB, 0xFEEC}, - {0xFEED, 0xFEEE, 0xFEED, 0xFEEE}, {0xFEEF, 0xFEF0, 0xFBFE, 0xFBFF}, - {0xFEF1, 0xFEF2, 0xFEF3, 0xFEF4}, {0x064B, 0x064B, 0x064B, 0x064B}, - {0x064C, 0x064C, 0x064C, 0x064C}, {0x064D, 0x064D, 0x064D, 0x064D}, - {0x064E, 0x064E, 0x064E, 0x064E}, {0x064F, 0x064F, 0x064F, 0x064F}, - {0x0650, 0x0650, 0x0650, 0x0650}, {0x0651, 0x0651, 0x0651, 0x0651}, - {0x0652, 0x0652, 0x0652, 0x0652}, {0x0653, 0x0653, 0x0653, 0x0653}, - {0x0654, 0x0654, 0x0654, 0x0654}, {0x0655, 0x0655, 0x0655, 0x0655}, - {0x0656, 0x0656, 0x0656, 0x0656}, {0x0657, 0x0657, 0x0657, 0x0657}, - {0x0658, 0x0658, 0x0658, 0x0658}, {0x0659, 0x0659, 0x0659, 0x0659}, - {0x065A, 0x065A, 0x065A, 0x065A}, {0x065B, 0x065B, 0x065B, 0x065B}, - {0x065C, 0x065C, 0x065C, 0x065C}, {0x065D, 0x065D, 0x065D, 0x065D}, - {0x065E, 0x065E, 0x065E, 0x065E}, {0x065F, 0x065F, 0x065F, 0x065F}, - {0x0660, 0x0660, 0x0660, 0x0660}, {0x0661, 0x0661, 0x0661, 0x0661}, - {0x0662, 0x0662, 0x0662, 0x0662}, {0x0663, 0x0663, 0x0663, 0x0663}, - {0x0664, 0x0664, 0x0664, 0x0664}, {0x0665, 0x0665, 0x0665, 0x0665}, - {0x0666, 0x0666, 0x0666, 0x0666}, {0x0667, 0x0667, 0x0667, 0x0667}, - {0x0668, 0x0668, 0x0668, 0x0668}, {0x0669, 0x0669, 0x0669, 0x0669}, - {0x066A, 0x066A, 0x066A, 0x066A}, {0x066B, 0x066B, 0x066B, 0x066B}, - {0x066C, 0x066C, 0x066C, 0x066C}, {0x066D, 0x066D, 0x066D, 0x066D}, - {0x066E, 0x066E, 0x066E, 0x066E}, {0x066F, 0x066F, 0x066F, 0x066F}, - {0x0670, 0x0670, 0x0670, 0x0670}, {0xFB50, 0xFB51, 0xFB50, 0xFB51}, - {0x0672, 0x0672, 0x0672, 0x0672}, {0x0673, 0x0673, 0x0673, 0x0673}, - {0x0674, 0x0674, 0x0674, 0x0674}, {0x0675, 0x0675, 0x0675, 0x0675}, - {0x0676, 0x0676, 0x0676, 0x0676}, {0x0677, 0x0677, 0x0677, 0x0677}, - {0x0678, 0x0678, 0x0678, 0x0678}, {0xFB66, 0xFB67, 0xFB68, 0xFB69}, - {0xFB5E, 0xFB5F, 0xFB60, 0xFB61}, {0xFB52, 0xFB53, 0xFB54, 0xFB55}, - {0x067C, 0x067C, 0x067C, 0x067C}, {0x067D, 0x067D, 0x067D, 0x067D}, - {0xFB56, 0xFB57, 0xFB58, 0xFB59}, {0xFB62, 0xFB63, 0xFB64, 0xFB65}, - {0xFB5A, 0xFB5B, 0xFB5C, 0xFB5D}, {0x0681, 0x0681, 0x0681, 0x0681}, - {0x0682, 0x0682, 0x0682, 0x0682}, {0xFB76, 0xFB77, 0xFB78, 0xFB79}, - {0xFB72, 0xFB73, 0xFB74, 0xFB75}, {0x0685, 0x0685, 0x0685, 0x0685}, - {0xFB7A, 0xFB7B, 0xFB7C, 0xFB7D}, {0xFB7E, 0xFB7F, 0xFB80, 0xFB81}, - {0xFB88, 0xFB89, 0xFB88, 0xFB89}, {0x0689, 0x0689, 0x0689, 0x0689}, - {0x068A, 0x068A, 0x068A, 0x068A}, {0x068B, 0x068B, 0x068B, 0x068B}, - {0xFB84, 0xFB85, 0xFB84, 0xFB85}, {0xFB82, 0xFB83, 0xFB82, 0xFB83}, - {0xFB86, 0xFB87, 0xFB86, 0xFB87}, {0x068F, 0x068F, 0x068F, 0x068F}, - {0x0690, 0x0690, 0x0690, 0x0690}, {0xFB8C, 0xFB8D, 0xFB8C, 0xFB8D}, - {0x0692, 0x0692, 0x0692, 0x0692}, {0x0693, 0x0693, 0x0693, 0x0693}, - {0x0694, 0x0694, 0x0694, 0x0694}, {0x0695, 0x0695, 0x0695, 0x0695}, - {0x0696, 0x0696, 0x0696, 0x0696}, {0x0697, 0x0697, 0x0697, 0x0697}, - {0xFB8A, 0xFB8B, 0xFB8A, 0xFB8B}, {0x0699, 0x0699, 0x0699, 0x0699}, - {0x069A, 0x069A, 0x069A, 0x069A}, {0x069B, 0x069B, 0x069B, 0x069B}, - {0x069C, 0x069C, 0x069C, 0x069C}, {0x069D, 0x069D, 0x069D, 0x069D}, - {0x069E, 0x069E, 0x069E, 0x069E}, {0x069F, 0x069F, 0x069F, 0x069F}, - {0x06A0, 0x06A0, 0x06A0, 0x06A0}, {0x06A1, 0x06A1, 0x06A1, 0x06A1}, - {0x06A2, 0x06A2, 0x06A2, 0x06A2}, {0x06A3, 0x06A3, 0x06A3, 0x06A3}, - {0xFB6A, 0xFB6B, 0xFB6C, 0xFB6D}, {0x06A5, 0x06A5, 0x06A5, 0x06A5}, - {0xFB6E, 0xFB6F, 0xFB70, 0xFB71}, {0x06A7, 0x06A7, 0x06A7, 0x06A7}, - {0x06A8, 0x06A8, 0x06A8, 0x06A8}, {0xFB8E, 0xFB8F, 0xFB90, 0xFB91}, - {0x06AA, 0x06AA, 0x06AA, 0x06AA}, {0x06AB, 0x06AB, 0x06AB, 0x06AB}, - {0x06AC, 0x06AC, 0x06AC, 0x06AC}, {0xFBD3, 0xFBD4, 0xFBD5, 0xFBD6}, - {0x06AE, 0x06AE, 0x06AE, 0x06AE}, {0xFB92, 0xFB93, 0xFB94, 0xFB95}, - {0x06B0, 0x06B0, 0x06B0, 0x06B0}, {0xFB9A, 0xFB9B, 0xFB9C, 0xFB9D}, - {0x06B2, 0x06B2, 0x06B2, 0x06B2}, {0xFB96, 0xFB97, 0xFB98, 0xFB99}, - {0x06B4, 0x06B4, 0x06B4, 0x06B4}, {0x06B5, 0x06B5, 0x06B5, 0x06B5}, - {0x06B6, 0x06B6, 0x06B6, 0x06B6}, {0x06B7, 0x06B7, 0x06B7, 0x06B7}, - {0x06B8, 0x06B8, 0x06B8, 0x06B8}, {0x06B9, 0x06B9, 0x06B9, 0x06B9}, - {0xFB9E, 0xFB9F, 0xFBE8, 0xFBE9}, {0xFBA0, 0xFBA1, 0xFBA2, 0xFBA3}, - {0x06BC, 0x06BC, 0x06BC, 0x06BC}, {0x06BD, 0x06BD, 0x06BD, 0x06BD}, - {0xFBAA, 0xFBAB, 0xFBAC, 0xFBAD}, {0x06BF, 0x06BF, 0x06BF, 0x06BF}, - {0xFBA4, 0xFBA5, 0xFBA4, 0xFBA5}, {0xFBA6, 0xFBA7, 0xFBA8, 0xFBA9}, - {0x06C2, 0x06C2, 0x06C2, 0x06C2}, {0x06C3, 0x06C3, 0x06C3, 0x06C3}, - {0x06C4, 0x06C4, 0x06C4, 0x06C4}, {0xFBE0, 0xFBE1, 0xFBE0, 0xFBE1}, - {0xFBD9, 0xFBDA, 0xFBD9, 0xFBDA}, {0xFBD7, 0xFBD8, 0xFBD7, 0xFBD8}, - {0xFBDB, 0xFBDC, 0xFBDB, 0xFBDC}, {0xFBE2, 0xFBE3, 0xFBE2, 0xFBE3}, - {0x06CA, 0x06CA, 0x06CA, 0x06CA}, {0xFBDE, 0xFBDF, 0xFBDE, 0xFBDF}, - {0xFBFC, 0xFBFD, 0xFBFE, 0xFBFF}, {0x06CD, 0x06CD, 0x06CD, 0x06CD}, - {0x06CE, 0x06CE, 0x06CE, 0x06CE}, {0x06CF, 0x06CF, 0x06CF, 0x06CF}, - {0xFBE4, 0xFBE5, 0xFBE6, 0xFBE7}, {0x06D1, 0x06D1, 0x06D1, 0x06D1}, - {0xFBAE, 0xFBAF, 0xFBAE, 0xFBAF}, {0xFBB0, 0xFBB1, 0xFBB0, 0xFBB1}, - {0x06D4, 0x06D4, 0x06D4, 0x06D4}, {0x06D5, 0x06D5, 0x06D5, 0x06D5}, +namespace { + +const FX_ARBFORMTABLE g_FX_ArabicFormTables[] = { + {0xFE81, 0xFE82, 0xFE81, 0xFE82}, + {0xFE83, 0xFE84, 0xFE83, 0xFE84}, + {0xFE85, 0xFE86, 0xFE85, 0xFE86}, + {0xFE87, 0xFE88, 0xFE87, 0xFE88}, + {0xFE89, 0xFE8A, 0xFE8B, 0xFE8C}, + {0xFE8D, 0xFE8E, 0xFE8D, 0xFE8E}, + {0xFE8F, 0xFE90, 0xFE91, 0xFE92}, + {0xFE93, 0xFE94, 0xFE93, 0xFE94}, + {0xFE95, 0xFE96, 0xFE97, 0xFE98}, + {0xFE99, 0xFE9A, 0xFE9B, 0xFE9C}, + {0xFE9D, 0xFE9E, 0xFE9F, 0xFEA0}, + {0xFEA1, 0xFEA2, 0xFEA3, 0xFEA4}, + {0xFEA5, 0xFEA6, 0xFEA7, 0xFEA8}, + {0xFEA9, 0xFEAA, 0xFEA9, 0xFEAA}, + {0xFEAB, 0xFEAC, 0xFEAB, 0xFEAC}, + {0xFEAD, 0xFEAE, 0xFEAD, 0xFEAE}, + {0xFEAF, 0xFEB0, 0xFEAF, 0xFEB0}, + {0xFEB1, 0xFEB2, 0xFEB3, 0xFEB4}, + {0xFEB5, 0xFEB6, 0xFEB7, 0xFEB8}, + {0xFEB9, 0xFEBA, 0xFEBB, 0xFEBC}, + {0xFEBD, 0xFEBE, 0xFEBF, 0xFEC0}, + {0xFEC1, 0xFEC2, 0xFEC3, 0xFEC4}, + {0xFEC5, 0xFEC6, 0xFEC7, 0xFEC8}, + {0xFEC9, 0xFECA, 0xFECB, 0xFECC}, + {0xFECD, 0xFECE, 0xFECF, 0xFED0}, + {0x063B, 0x063B, 0x063B, 0x063B}, + {0x063C, 0x063C, 0x063C, 0x063C}, + {0x063D, 0x063D, 0x063D, 0x063D}, + {0x063E, 0x063E, 0x063E, 0x063E}, + {0x063F, 0x063F, 0x063F, 0x063F}, + {0x0640, 0x0640, 0x0640, 0x0640}, + {0xFED1, 0xFED2, 0xFED3, 0xFED4}, + {0xFED5, 0xFED6, 0xFED7, 0xFED8}, + {0xFED9, 0xFEDA, 0xFEDB, 0xFEDC}, + {0xFEDD, 0xFEDE, 0xFEDF, 0xFEE0}, + {0xFEE1, 0xFEE2, 0xFEE3, 0xFEE4}, + {0xFEE5, 0xFEE6, 0xFEE7, 0xFEE8}, + {0xFEE9, 0xFEEA, 0xFEEB, 0xFEEC}, + {0xFEED, 0xFEEE, 0xFEED, 0xFEEE}, + {0xFEEF, 0xFEF0, 0xFBFE, 0xFBFF}, + {0xFEF1, 0xFEF2, 0xFEF3, 0xFEF4}, + {0x064B, 0x064B, 0x064B, 0x064B}, + {0x064C, 0x064C, 0x064C, 0x064C}, + {0x064D, 0x064D, 0x064D, 0x064D}, + {0x064E, 0x064E, 0x064E, 0x064E}, + {0x064F, 0x064F, 0x064F, 0x064F}, + {0x0650, 0x0650, 0x0650, 0x0650}, + {0x0651, 0x0651, 0x0651, 0x0651}, + {0x0652, 0x0652, 0x0652, 0x0652}, + {0x0653, 0x0653, 0x0653, 0x0653}, + {0x0654, 0x0654, 0x0654, 0x0654}, + {0x0655, 0x0655, 0x0655, 0x0655}, + {0x0656, 0x0656, 0x0656, 0x0656}, + {0x0657, 0x0657, 0x0657, 0x0657}, + {0x0658, 0x0658, 0x0658, 0x0658}, + {0x0659, 0x0659, 0x0659, 0x0659}, + {0x065A, 0x065A, 0x065A, 0x065A}, + {0x065B, 0x065B, 0x065B, 0x065B}, + {0x065C, 0x065C, 0x065C, 0x065C}, + {0x065D, 0x065D, 0x065D, 0x065D}, + {0x065E, 0x065E, 0x065E, 0x065E}, + {0x065F, 0x065F, 0x065F, 0x065F}, + {0x0660, 0x0660, 0x0660, 0x0660}, + {0x0661, 0x0661, 0x0661, 0x0661}, + {0x0662, 0x0662, 0x0662, 0x0662}, + {0x0663, 0x0663, 0x0663, 0x0663}, + {0x0664, 0x0664, 0x0664, 0x0664}, + {0x0665, 0x0665, 0x0665, 0x0665}, + {0x0666, 0x0666, 0x0666, 0x0666}, + {0x0667, 0x0667, 0x0667, 0x0667}, + {0x0668, 0x0668, 0x0668, 0x0668}, + {0x0669, 0x0669, 0x0669, 0x0669}, + {0x066A, 0x066A, 0x066A, 0x066A}, + {0x066B, 0x066B, 0x066B, 0x066B}, + {0x066C, 0x066C, 0x066C, 0x066C}, + {0x066D, 0x066D, 0x066D, 0x066D}, + {0x066E, 0x066E, 0x066E, 0x066E}, + {0x066F, 0x066F, 0x066F, 0x066F}, + {0x0670, 0x0670, 0x0670, 0x0670}, + {0xFB50, 0xFB51, 0xFB50, 0xFB51}, + {0x0672, 0x0672, 0x0672, 0x0672}, + {0x0673, 0x0673, 0x0673, 0x0673}, + {0x0674, 0x0674, 0x0674, 0x0674}, + {0x0675, 0x0675, 0x0675, 0x0675}, + {0x0676, 0x0676, 0x0676, 0x0676}, + {0x0677, 0x0677, 0x0677, 0x0677}, + {0x0678, 0x0678, 0x0678, 0x0678}, + {0xFB66, 0xFB67, 0xFB68, 0xFB69}, + {0xFB5E, 0xFB5F, 0xFB60, 0xFB61}, + {0xFB52, 0xFB53, 0xFB54, 0xFB55}, + {0x067C, 0x067C, 0x067C, 0x067C}, + {0x067D, 0x067D, 0x067D, 0x067D}, + {0xFB56, 0xFB57, 0xFB58, 0xFB59}, + {0xFB62, 0xFB63, 0xFB64, 0xFB65}, + {0xFB5A, 0xFB5B, 0xFB5C, 0xFB5D}, + {0x0681, 0x0681, 0x0681, 0x0681}, + {0x0682, 0x0682, 0x0682, 0x0682}, + {0xFB76, 0xFB77, 0xFB78, 0xFB79}, + {0xFB72, 0xFB73, 0xFB74, 0xFB75}, + {0x0685, 0x0685, 0x0685, 0x0685}, + {0xFB7A, 0xFB7B, 0xFB7C, 0xFB7D}, + {0xFB7E, 0xFB7F, 0xFB80, 0xFB81}, + {0xFB88, 0xFB89, 0xFB88, 0xFB89}, + {0x0689, 0x0689, 0x0689, 0x0689}, + {0x068A, 0x068A, 0x068A, 0x068A}, + {0x068B, 0x068B, 0x068B, 0x068B}, + {0xFB84, 0xFB85, 0xFB84, 0xFB85}, + {0xFB82, 0xFB83, 0xFB82, 0xFB83}, + {0xFB86, 0xFB87, 0xFB86, 0xFB87}, + {0x068F, 0x068F, 0x068F, 0x068F}, + {0x0690, 0x0690, 0x0690, 0x0690}, + {0xFB8C, 0xFB8D, 0xFB8C, 0xFB8D}, + {0x0692, 0x0692, 0x0692, 0x0692}, + {0x0693, 0x0693, 0x0693, 0x0693}, + {0x0694, 0x0694, 0x0694, 0x0694}, + {0x0695, 0x0695, 0x0695, 0x0695}, + {0x0696, 0x0696, 0x0696, 0x0696}, + {0x0697, 0x0697, 0x0697, 0x0697}, + {0xFB8A, 0xFB8B, 0xFB8A, 0xFB8B}, + {0x0699, 0x0699, 0x0699, 0x0699}, + {0x069A, 0x069A, 0x069A, 0x069A}, + {0x069B, 0x069B, 0x069B, 0x069B}, + {0x069C, 0x069C, 0x069C, 0x069C}, + {0x069D, 0x069D, 0x069D, 0x069D}, + {0x069E, 0x069E, 0x069E, 0x069E}, + {0x069F, 0x069F, 0x069F, 0x069F}, + {0x06A0, 0x06A0, 0x06A0, 0x06A0}, + {0x06A1, 0x06A1, 0x06A1, 0x06A1}, + {0x06A2, 0x06A2, 0x06A2, 0x06A2}, + {0x06A3, 0x06A3, 0x06A3, 0x06A3}, + {0xFB6A, 0xFB6B, 0xFB6C, 0xFB6D}, + {0x06A5, 0x06A5, 0x06A5, 0x06A5}, + {0xFB6E, 0xFB6F, 0xFB70, 0xFB71}, + {0x06A7, 0x06A7, 0x06A7, 0x06A7}, + {0x06A8, 0x06A8, 0x06A8, 0x06A8}, + {0xFB8E, 0xFB8F, 0xFB90, 0xFB91}, + {0x06AA, 0x06AA, 0x06AA, 0x06AA}, + {0x06AB, 0x06AB, 0x06AB, 0x06AB}, + {0x06AC, 0x06AC, 0x06AC, 0x06AC}, + {0xFBD3, 0xFBD4, 0xFBD5, 0xFBD6}, + {0x06AE, 0x06AE, 0x06AE, 0x06AE}, + {0xFB92, 0xFB93, 0xFB94, 0xFB95}, + {0x06B0, 0x06B0, 0x06B0, 0x06B0}, + {0xFB9A, 0xFB9B, 0xFB9C, 0xFB9D}, + {0x06B2, 0x06B2, 0x06B2, 0x06B2}, + {0xFB96, 0xFB97, 0xFB98, 0xFB99}, + {0x06B4, 0x06B4, 0x06B4, 0x06B4}, + {0x06B5, 0x06B5, 0x06B5, 0x06B5}, + {0x06B6, 0x06B6, 0x06B6, 0x06B6}, + {0x06B7, 0x06B7, 0x06B7, 0x06B7}, + {0x06B8, 0x06B8, 0x06B8, 0x06B8}, + {0x06B9, 0x06B9, 0x06B9, 0x06B9}, + {0xFB9E, 0xFB9F, 0xFBE8, 0xFBE9}, + {0xFBA0, 0xFBA1, 0xFBA2, 0xFBA3}, + {0x06BC, 0x06BC, 0x06BC, 0x06BC}, + {0x06BD, 0x06BD, 0x06BD, 0x06BD}, + {0xFBAA, 0xFBAB, 0xFBAC, 0xFBAD}, + {0x06BF, 0x06BF, 0x06BF, 0x06BF}, + {0xFBA4, 0xFBA5, 0xFBA4, 0xFBA5}, + {0xFBA6, 0xFBA7, 0xFBA8, 0xFBA9}, + {0x06C2, 0x06C2, 0x06C2, 0x06C2}, + {0x06C3, 0x06C3, 0x06C3, 0x06C3}, + {0x06C4, 0x06C4, 0x06C4, 0x06C4}, + {0xFBE0, 0xFBE1, 0xFBE0, 0xFBE1}, + {0xFBD9, 0xFBDA, 0xFBD9, 0xFBDA}, + {0xFBD7, 0xFBD8, 0xFBD7, 0xFBD8}, + {0xFBDB, 0xFBDC, 0xFBDB, 0xFBDC}, + {0xFBE2, 0xFBE3, 0xFBE2, 0xFBE3}, + {0x06CA, 0x06CA, 0x06CA, 0x06CA}, + {0xFBDE, 0xFBDF, 0xFBDE, 0xFBDF}, + {0xFBFC, 0xFBFD, 0xFBFE, 0xFBFF}, + {0x06CD, 0x06CD, 0x06CD, 0x06CD}, + {0x06CE, 0x06CE, 0x06CE, 0x06CE}, + {0x06CF, 0x06CF, 0x06CF, 0x06CF}, + {0xFBE4, 0xFBE5, 0xFBE6, 0xFBE7}, + {0x06D1, 0x06D1, 0x06D1, 0x06D1}, + {0xFBAE, 0xFBAF, 0xFBAE, 0xFBAF}, + {0xFBB0, 0xFBB1, 0xFBB0, 0xFBB1}, + {0x06D4, 0x06D4, 0x06D4, 0x06D4}, + {0x06D5, 0x06D5, 0x06D5, 0x06D5}, }; -static const FX_ARAALEF gs_FX_AlefTable[] = { + +const FX_ARAALEF gs_FX_AlefTable[] = { {0x0622, 0xFEF5}, {0x0623, 0xFEF7}, {0x0625, 0xFEF9}, {0x0627, 0xFEFB}, }; -static const FX_ARASHADDA gs_FX_ShaddaTable[] = { - {0x064C, 0xFC5E}, {0x064D, 0xFC5F}, {0x064E, 0xFC60}, - {0x064F, 0xFC61}, {0x0650, 0xFC62}, + +const FX_ARASHADDA gs_FX_ShaddaTable[] = { + {0x064C, 0xFC5E}, + {0x064D, 0xFC5F}, + {0x064E, 0xFC60}, + {0x064F, 0xFC61}, + {0x0650, 0xFC62}, }; -FX_LPCARBFORMTABLE FX_GetArabicFormTable(FX_WCHAR unicode) { + +} // namespace + +const FX_ARBFORMTABLE* FX_GetArabicFormTable(FX_WCHAR unicode) { if (unicode < 0x622 || unicode > 0x6d5) { return NULL; } @@ -140,9 +237,7 @@ FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda) { } return shadda; } -#ifdef __cplusplus -}; -#endif + IFX_ArabicChar* IFX_ArabicChar::Create() { return new CFX_ArabicChar; } @@ -168,7 +263,7 @@ FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char* cur, const CFX_Char* next) const { FX_CHARTYPE eCur; FX_WCHAR wCur; - FX_LPCARBFORMTABLE ft = ParseChar(cur, wCur, eCur); + const FX_ARBFORMTABLE* ft = ParseChar(cur, wCur, eCur); if (eCur < FX_CHARTYPE_ArabicAlef || eCur >= FX_CHARTYPE_ArabicNormal) { return wCur; } @@ -200,9 +295,9 @@ FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char* cur, } } } -FX_LPCARBFORMTABLE CFX_ArabicChar::ParseChar(const CFX_Char* pTC, - FX_WCHAR& wChar, - FX_CHARTYPE& eType) const { +const FX_ARBFORMTABLE* CFX_ArabicChar::ParseChar(const CFX_Char* pTC, + FX_WCHAR& wChar, + FX_CHARTYPE& eType) const { if (pTC == NULL) { eType = FX_CHARTYPE_Unknown; wChar = 0xFEFF; @@ -210,7 +305,7 @@ FX_LPCARBFORMTABLE CFX_ArabicChar::ParseChar(const CFX_Char* pTC, } eType = (FX_CHARTYPE)pTC->GetCharType(); wChar = (FX_WCHAR)pTC->m_wCharCode; - FX_LPCARBFORMTABLE pFT = FX_GetArabicFormTable(wChar); + const FX_ARBFORMTABLE* pFT = FX_GetArabicFormTable(wChar); if (pFT == NULL || eType >= FX_CHARTYPE_ArabicNormal) { eType = FX_CHARTYPE_Unknown; } @@ -1053,77 +1148,3 @@ void FX_BidiLine(CFX_RTFCharArray& chars, int32_t iCount, int32_t iBaseLevel) { CFX_BidiLineTemplate<CFX_RTFChar> blt; blt.FX_BidiLine(chars, iCount, iBaseLevel); } -IFX_BidiChar* IFX_BidiChar::Create() { - return new CFX_BidiChar; -} -CFX_BidiChar::CFX_BidiChar() - : m_bSeparateNeutral(TRUE), - m_iCurStart(0), - m_iCurCount(0), - m_iCurBidi(0), - m_iLastBidi(0), - m_iLastStart(0), - m_iLastCount(0) {} -void CFX_BidiChar::SetPolicy(FX_BOOL bSeparateNeutral) { - m_bSeparateNeutral = bSeparateNeutral; -} - -FX_BOOL CFX_BidiChar::AppendChar(FX_WCHAR wch) { - FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; - int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; - int32_t iContext = 0; - switch (iBidiCls) { - case FX_BIDICLASS_L: - case FX_BIDICLASS_AN: - case FX_BIDICLASS_EN: - iContext = 1; - break; - case FX_BIDICLASS_R: - case FX_BIDICLASS_AL: - iContext = 2; - 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; - } - } - 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; - return m_iLastCount > 0; -} -int32_t CFX_BidiChar::GetBidiInfo(int32_t& iStart, int32_t& iCount) { - iStart = m_iLastStart; - iCount = m_iLastCount; - return m_iLastBidi; -} -void CFX_BidiChar::Reset() { - m_iCurStart = 0; - m_iCurCount = 0; - m_iCurBidi = 0; - m_iLastBidi = 0; - m_iLastStart = 0; - m_iLastCount = 0; -} diff --git a/core/src/fxcrt/fx_arabic.h b/core/src/fxcrt/fx_arabic.h index 83893e3774..8fde73d5d9 100644 --- a/core/src/fxcrt/fx_arabic.h +++ b/core/src/fxcrt/fx_arabic.h @@ -23,9 +23,9 @@ class CFX_ArabicChar : public IFX_ArabicChar { const CFX_Char* next) const; protected: - FX_LPCARBFORMTABLE ParseChar(const CFX_Char* pTC, - FX_WCHAR& wChar, - FX_CHARTYPE& eType) const; + const FX_ARBFORMTABLE* ParseChar(const CFX_Char* pTC, + FX_WCHAR& wChar, + FX_CHARTYPE& eType) const; }; void FX_BidiReverseString(CFX_WideString& wsText, int32_t iStart, @@ -207,25 +207,5 @@ int32_t FX_BidiReorderLevel(int32_t iBaseLevel, void FX_BidiReorder(int32_t iBaseLevel, CFX_WideString& wsText, const CFX_Int32Array& levels); -class CFX_BidiChar final : public IFX_BidiChar { - public: - CFX_BidiChar(); - ~CFX_BidiChar() override {} - - void SetPolicy(FX_BOOL bSeparateNeutral = TRUE) override; - FX_BOOL AppendChar(FX_WCHAR wch) override; - FX_BOOL EndChar() override; - int32_t GetBidiInfo(int32_t& iStart, int32_t& iCount) override; - void Reset() override; - - private: - FX_BOOL m_bSeparateNeutral; - int32_t m_iCurStart; - int32_t m_iCurCount; - int32_t m_iCurBidi; - int32_t m_iLastBidi; - int32_t m_iLastStart; - int32_t m_iLastCount; -}; #endif // CORE_SRC_FXCRT_FX_ARABIC_H_ 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; +} diff --git a/core/src/fxcrt/fx_bidi_unittest.cpp b/core/src/fxcrt/fx_bidi_unittest.cpp new file mode 100644 index 0000000000..c629cbbdc6 --- /dev/null +++ b/core/src/fxcrt/fx_bidi_unittest.cpp @@ -0,0 +1,136 @@ +// Copyright 2015 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. + +#include "testing/gtest/include/gtest/gtest.h" +#include "../../include/fxcrt/fx_bidi.h" + +namespace { + +const FX_WCHAR kNeutralChar = 32; +const FX_WCHAR kLeftChar = 65; +const FX_WCHAR kRightChar = 1424; + +} // namespace + +TEST(fxcrt, BidiCharEmpty) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(nullptr, nullptr); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + + dir = bidi.GetBidiInfo(&start, nullptr); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, start); + + dir = bidi.GetBidiInfo(nullptr, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, count); + + start = -1; + count = -1; + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.EndChar()); +} + +TEST(fxcrt, BidiCharLeft) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_TRUE(bidi.EndChar()); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::LEFT, dir); + EXPECT_EQ(0, start); + EXPECT_EQ(3, count); + + EXPECT_FALSE(bidi.EndChar()); +} + +TEST(fxcrt, BidiCharLeftNeutralRight) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_TRUE(bidi.AppendChar(kNeutralChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(3, count); + + EXPECT_FALSE(bidi.AppendChar(kNeutralChar)); + EXPECT_FALSE(bidi.AppendChar(kNeutralChar)); + EXPECT_FALSE(bidi.AppendChar(kNeutralChar)); + EXPECT_TRUE(bidi.AppendChar(kRightChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::NEUTRAL, dir); + EXPECT_EQ(3, start); + EXPECT_EQ(4, count); + + EXPECT_TRUE(bidi.EndChar()); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::RIGHT, dir); + EXPECT_EQ(7, start); + EXPECT_EQ(1, count); + + EXPECT_FALSE(bidi.EndChar()); +} + +TEST(fxcrt, BidiCharLeftRightLeft) { + int32_t start = -1; + int32_t count = -1; + CFX_BidiChar bidi; + + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + CFX_BidiChar::Direction dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(0, count); + + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_FALSE(bidi.AppendChar(kLeftChar)); + EXPECT_TRUE(bidi.AppendChar(kRightChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(0, start); + EXPECT_EQ(3, count); + + EXPECT_FALSE(bidi.AppendChar(kRightChar)); + EXPECT_FALSE(bidi.AppendChar(kRightChar)); + EXPECT_FALSE(bidi.AppendChar(kRightChar)); + EXPECT_TRUE(bidi.AppendChar(kLeftChar)); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::RIGHT, dir); + EXPECT_EQ(3, start); + EXPECT_EQ(4, count); + + EXPECT_TRUE(bidi.EndChar()); + dir = bidi.GetBidiInfo(&start, &count); + EXPECT_EQ(CFX_BidiChar::LEFT, dir); + EXPECT_EQ(7, start); + EXPECT_EQ(1, count); + + EXPECT_FALSE(bidi.EndChar()); +} diff --git a/core/src/fxcrt/fx_unicode.cpp b/core/src/fxcrt/fx_unicode.cpp index 67ff009513..105301e0a8 100644 --- a/core/src/fxcrt/fx_unicode.cpp +++ b/core/src/fxcrt/fx_unicode.cpp @@ -7,54 +7,56 @@ #include "../../include/fxcrt/fx_ucd.h" FX_DWORD FX_GetUnicodeProperties(FX_WCHAR wch) { - return kTextLayoutCodeProperties[(FX_WORD)wch]; + size_t idx = static_cast<size_t>(wch); + if (idx < kTextLayoutCodePropertiesSize) + return kTextLayoutCodeProperties[(FX_WORD)wch]; + return 0; } + FX_BOOL FX_IsCtrlCode(FX_WCHAR ch) { - FX_DWORD dwRet = - (kTextLayoutCodeProperties[(FX_WORD)ch] & FX_CHARTYPEBITSMASK); + FX_DWORD dwRet = (FX_GetUnicodeProperties(ch) & FX_CHARTYPEBITSMASK); return dwRet == FX_CHARTYPE_Tab || dwRet == FX_CHARTYPE_Control; } -FX_BOOL FX_IsRotationCode(FX_WCHAR ch) { - return (kTextLayoutCodeProperties[(FX_WORD)ch] & 0x8000) != 0; -} -FX_BOOL FX_IsCombinationChar(FX_WCHAR wch) { - FX_DWORD dwProps = - (kTextLayoutCodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK); - return dwProps == FX_CHARTYPE_Combination; -} -FX_BOOL FX_IsBidiChar(FX_WCHAR wch) { - FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; - int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; - return (FX_BIDICLASS_R == iBidiCls || FX_BIDICLASS_AL == iBidiCls); -} + FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical) { - FX_DWORD dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; + FX_DWORD dwProps = FX_GetUnicodeProperties(wch); FX_DWORD dwTemp = (dwProps & 0xFF800000); if (bRTL && dwTemp < 0xFF800000) { - wch = kFXTextLayoutBidiMirror[dwTemp >> 23]; - dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; + size_t idx = dwTemp >> 23; + if (idx < kFXTextLayoutBidiMirrorSize) { + wch = kFXTextLayoutBidiMirror[idx]; + dwProps = FX_GetUnicodeProperties(wch); + } } if (bVertical) { dwTemp = (dwProps & 0x007E0000); if (dwTemp < 0x007E0000) { - wch = kFXTextLayoutVerticalMirror[dwTemp >> 17]; + size_t idx = dwTemp >> 17; + if (idx < kFXTextLayoutVerticalMirrorSize) + wch = kFXTextLayoutVerticalMirror[idx]; } } return wch; } + FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_DWORD dwProps, FX_BOOL bRTL, FX_BOOL bVertical) { FX_DWORD dwTemp = (dwProps & 0xFF800000); if (bRTL && dwTemp < 0xFF800000) { - wch = kFXTextLayoutBidiMirror[dwTemp >> 23]; - dwProps = kTextLayoutCodeProperties[(FX_WORD)wch]; + size_t idx = dwTemp >> 23; + if (idx < kFXTextLayoutBidiMirrorSize) { + wch = kFXTextLayoutBidiMirror[idx]; + dwProps = FX_GetUnicodeProperties(wch); + } } if (bVertical) { dwTemp = (dwProps & 0x007E0000); if (dwTemp < 0x007E0000) { - wch = kFXTextLayoutVerticalMirror[dwTemp >> 17]; + size_t idx = dwTemp >> 17; + if (idx < kFXTextLayoutVerticalMirrorSize) + wch = kFXTextLayoutVerticalMirror[idx]; } } return wch; diff --git a/pdfium.gyp b/pdfium.gyp index 991dac4a52..d369c30308 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -419,6 +419,7 @@ 'sources': [ 'core/include/fxcrt/fx_arb.h', 'core/include/fxcrt/fx_basic.h', + 'core/include/fxcrt/fx_bidi.h', 'core/include/fxcrt/fx_coordinates.h', 'core/include/fxcrt/fx_ext.h', 'core/include/fxcrt/fx_memory.h', @@ -449,6 +450,7 @@ 'core/src/fxcrt/fx_basic_utf.cpp', 'core/src/fxcrt/fx_basic_util.cpp', 'core/src/fxcrt/fx_basic_wstring.cpp', + 'core/src/fxcrt/fx_bidi.cpp', 'core/src/fxcrt/fx_extension.cpp', 'core/src/fxcrt/fx_ucddata.cpp', 'core/src/fxcrt/fx_unicode.cpp', @@ -766,6 +768,7 @@ 'core/src/fxcrt/fx_basic_bstring_unittest.cpp', 'core/src/fxcrt/fx_basic_memmgr_unittest.cpp', 'core/src/fxcrt/fx_basic_wstring_unittest.cpp', + 'core/src/fxcrt/fx_bidi_unittest.cpp', 'core/src/fxcrt/fx_system_unittest.cpp', 'testing/fx_string_testhelpers.h', 'testing/fx_string_testhelpers.cpp', |