| 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_ucd.h" | 7 #include "../../include/fxcrt/fx_ucd.h" |
| 8 | 8 |
| 9 extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536]; | |
| 10 extern const FX_WCHAR gs_FX_TextLayout_VerticalMirror[64]; | |
| 11 extern const FX_WCHAR gs_FX_TextLayout_BidiMirror[512]; | |
| 12 FX_DWORD FX_GetUnicodeProperties(FX_WCHAR wch) { | 9 FX_DWORD FX_GetUnicodeProperties(FX_WCHAR wch) { |
| 13 return gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; | 10 size_t idx = static_cast<size_t>(wch); |
| 11 if (idx < kTextLayoutCodePropertiesSize) |
| 12 return kTextLayoutCodeProperties[(FX_WORD)wch]; |
| 13 return 0; |
| 14 } | 14 } |
| 15 FX_BOOL FX_IsCtrlCode(FX_WCHAR ch) { | 15 |
| 16 FX_DWORD dwRet = | |
| 17 (gs_FX_TextLayout_CodeProperties[(FX_WORD)ch] & FX_CHARTYPEBITSMASK); | |
| 18 return dwRet == FX_CHARTYPE_Tab || dwRet == FX_CHARTYPE_Control; | |
| 19 } | |
| 20 FX_BOOL FX_IsRotationCode(FX_WCHAR ch) { | |
| 21 return (gs_FX_TextLayout_CodeProperties[(FX_WORD)ch] & 0x8000) != 0; | |
| 22 } | |
| 23 FX_BOOL FX_IsCombinationChar(FX_WCHAR wch) { | |
| 24 FX_DWORD dwProps = | |
| 25 (gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK); | |
| 26 return dwProps == FX_CHARTYPE_Combination; | |
| 27 } | |
| 28 FX_BOOL FX_IsBidiChar(FX_WCHAR wch) { | |
| 29 FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; | |
| 30 int32_t iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; | |
| 31 return (FX_BIDICLASS_R == iBidiCls || FX_BIDICLASS_AL == iBidiCls); | |
| 32 } | |
| 33 FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical) { | 16 FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical) { |
| 34 FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; | 17 FX_DWORD dwProps = FX_GetUnicodeProperties(wch); |
| 35 FX_DWORD dwTemp = (dwProps & 0xFF800000); | 18 FX_DWORD dwTemp = (dwProps & 0xFF800000); |
| 36 if (bRTL && dwTemp < 0xFF800000) { | 19 if (bRTL && dwTemp < 0xFF800000) { |
| 37 wch = gs_FX_TextLayout_BidiMirror[dwTemp >> 23]; | 20 size_t idx = dwTemp >> 23; |
| 38 dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; | 21 if (idx < kFXTextLayoutBidiMirrorSize) { |
| 22 wch = kFXTextLayoutBidiMirror[idx]; |
| 23 dwProps = FX_GetUnicodeProperties(wch); |
| 24 } |
| 39 } | 25 } |
| 40 if (bVertical) { | 26 if (bVertical) { |
| 41 dwTemp = (dwProps & 0x007E0000); | 27 dwTemp = (dwProps & 0x007E0000); |
| 42 if (dwTemp < 0x007E0000) { | 28 if (dwTemp < 0x007E0000) { |
| 43 wch = gs_FX_TextLayout_VerticalMirror[dwTemp >> 17]; | 29 size_t idx = dwTemp >> 17; |
| 30 if (idx < kFXTextLayoutVerticalMirrorSize) |
| 31 wch = kFXTextLayoutVerticalMirror[idx]; |
| 44 } | 32 } |
| 45 } | 33 } |
| 46 return wch; | 34 return wch; |
| 47 } | |
| 48 FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, | |
| 49 FX_DWORD dwProps, | |
| 50 FX_BOOL bRTL, | |
| 51 FX_BOOL bVertical) { | |
| 52 FX_DWORD dwTemp = (dwProps & 0xFF800000); | |
| 53 if (bRTL && dwTemp < 0xFF800000) { | |
| 54 wch = gs_FX_TextLayout_BidiMirror[dwTemp >> 23]; | |
| 55 dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]; | |
| 56 } | |
| 57 if (bVertical) { | |
| 58 dwTemp = (dwProps & 0x007E0000); | |
| 59 if (dwTemp < 0x007E0000) { | |
| 60 wch = gs_FX_TextLayout_VerticalMirror[dwTemp >> 17]; | |
| 61 } | |
| 62 } | |
| 63 return wch; | |
| 64 } | 35 } |
| OLD | NEW |