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