diff options
author | Lei Zhang <thestig@chromium.org> | 2015-08-17 18:00:48 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-08-17 18:00:48 -0700 |
commit | 2ae87d2e8ddff79d0e96aad3db97e090db21fb99 (patch) | |
tree | 9bbae4e8d6b554a4b4b12fe0cfc5a8a5b54e43b7 /core/include/fxcrt | |
parent | 1d9dbd53b205b2b4d9e75a7eeb95e80837917ea3 (diff) | |
download | pdfium-2ae87d2e8ddff79d0e96aad3db97e090db21fb99.tar.xz |
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
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1197643002 .
Diffstat (limited to 'core/include/fxcrt')
-rw-r--r-- | core/include/fxcrt/fx_arb.h | 24 | ||||
-rw-r--r-- | core/include/fxcrt/fx_bidi.h | 59 | ||||
-rw-r--r-- | core/include/fxcrt/fx_ucd.h | 114 |
3 files changed, 88 insertions, 109 deletions
diff --git a/core/include/fxcrt/fx_arb.h b/core/include/fxcrt/fx_arb.h deleted file mode 100644 index 0f6de64b32..0000000000 --- a/core/include/fxcrt/fx_arb.h +++ /dev/null @@ -1,24 +0,0 @@ -// 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_ARB_H_ -#define CORE_INCLUDE_FXCRT_FX_ARB_H_ - -#include "fx_system.h" - -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 8bc5930dd4..62c2dfdf67 100644 --- a/core/include/fxcrt/fx_ucd.h +++ b/core/include/fxcrt/fx_ucd.h @@ -9,97 +9,41 @@ #include "fx_system.h" -enum FX_CHARBREAKPROP { - FX_CBP_OP = 0, - FX_CBP_CL = 1, - FX_CBP_QU = 2, - FX_CBP_GL = 3, - FX_CBP_NS = 4, - FX_CBP_EX = 5, - FX_CBP_SY = 6, - FX_CBP_IS = 7, - FX_CBP_PR = 8, - FX_CBP_PO = 9, - FX_CBP_NU = 10, - FX_CBP_AL = 11, - FX_CBP_ID = 12, - FX_CBP_IN = 13, - FX_CBP_HY = 14, - FX_CBP_BA = 15, - FX_CBP_BB = 16, - FX_CBP_B2 = 17, - FX_CBP_ZW = 18, - FX_CBP_CM = 19, - FX_CBP_WJ = 20, - FX_CBP_H2 = 21, - FX_CBP_H3 = 22, - FX_CBP_JL = 23, - FX_CBP_JV = 24, - FX_CBP_JT = 25, - - FX_CBP_BK = 26, - FX_CBP_CR = 27, - FX_CBP_LF = 28, - FX_CBP_NL = 29, - FX_CBP_SA = 30, - FX_CBP_SG = 31, - FX_CBP_CB = 32, - FX_CBP_XX = 33, - FX_CBP_AI = 34, - FX_CBP_SP = 35, - FX_CBP_TB = 37, - FX_CBP_NONE = 36, -}; #define FX_BIDICLASSBITS 6 #define FX_BIDICLASSBITSMASK (31 << FX_BIDICLASSBITS) enum FX_BIDICLASS { - FX_BIDICLASS_ON = 0, - FX_BIDICLASS_L = 1, - FX_BIDICLASS_R = 2, - FX_BIDICLASS_AN = 3, - FX_BIDICLASS_EN = 4, - FX_BIDICLASS_AL = 5, - FX_BIDICLASS_NSM = 6, - FX_BIDICLASS_CS = 7, - FX_BIDICLASS_ES = 8, - FX_BIDICLASS_ET = 9, - FX_BIDICLASS_BN = 10, - FX_BIDICLASS_S = 11, - FX_BIDICLASS_WS = 12, - FX_BIDICLASS_B = 13, - FX_BIDICLASS_RLO = 14, - FX_BIDICLASS_RLE = 15, - FX_BIDICLASS_LRO = 16, - FX_BIDICLASS_LRE = 17, - FX_BIDICLASS_PDF = 18, + FX_BIDICLASS_ON = 0, // Other Neutral + FX_BIDICLASS_L = 1, // Left Letter + FX_BIDICLASS_R = 2, // Right Letter + FX_BIDICLASS_AN = 3, // Arabic Number + FX_BIDICLASS_EN = 4, // European Number + FX_BIDICLASS_AL = 5, // Arabic Letter + FX_BIDICLASS_NSM = 6, // Non-spacing Mark + FX_BIDICLASS_CS = 7, // Common Number Separator + FX_BIDICLASS_ES = 8, // European Separator + FX_BIDICLASS_ET = 9, // European Number Terminator + FX_BIDICLASS_BN = 10, // Boundary Neutral + FX_BIDICLASS_S = 11, // Segment Separator + FX_BIDICLASS_WS = 12, // Whitespace + FX_BIDICLASS_B = 13, // Paragraph Separator + FX_BIDICLASS_RLO = 14, // Right-to-Left Override + FX_BIDICLASS_RLE = 15, // Right-to-Left Embedding + FX_BIDICLASS_LRO = 16, // Left-to-Right Override + FX_BIDICLASS_LRE = 17, // Left-to-Right Embedding + FX_BIDICLASS_PDF = 18, // Pop Directional Format FX_BIDICLASS_N = FX_BIDICLASS_ON, }; -#define FX_CHARTYPEBITS 11 -#define FX_CHARTYPEBITSMASK (15 << FX_CHARTYPEBITS) -enum FX_CHARTYPE { - FX_CHARTYPE_Unknown = 0, - FX_CHARTYPE_Tab = (1 << FX_CHARTYPEBITS), - FX_CHARTYPE_Space = (2 << FX_CHARTYPEBITS), - FX_CHARTYPE_Control = (3 << FX_CHARTYPEBITS), - FX_CHARTYPE_Combination = (4 << FX_CHARTYPEBITS), - FX_CHARTYPE_Numeric = (5 << FX_CHARTYPEBITS), - FX_CHARTYPE_Normal = (6 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicAlef = (7 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicSpecial = (8 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicDistortion = (9 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicNormal = (10 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicForm = (11 << FX_CHARTYPEBITS), - FX_CHARTYPE_Arabic = (12 << FX_CHARTYPEBITS), -}; + +extern const FX_DWORD kTextLayoutCodeProperties[]; +extern const size_t kTextLayoutCodePropertiesSize; + +extern const FX_WCHAR kFXTextLayoutVerticalMirror[]; +extern const size_t kFXTextLayoutVerticalMirrorSize; + +extern const FX_WCHAR kFXTextLayoutBidiMirror[]; +extern const size_t kFXTextLayoutBidiMirrorSize; + 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, - FX_BOOL bRTL, - FX_BOOL bVertical); #endif // CORE_INCLUDE_FXCRT_FX_UCD_H_ |