1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "../../include/fxcrt/fx_ext.h"
8 extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536];
9 extern const FX_WCHAR gs_FX_TextLayout_VerticalMirror[64];
10 extern const FX_WCHAR gs_FX_TextLayout_BidiMirror[512];
FX_GetUnicodeProperties(FX_WCHAR wch)11 FX_DWORD FX_GetUnicodeProperties(FX_WCHAR wch)
12 {
13     return gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
14 }
FX_IsCtrlCode(FX_WCHAR ch)15 FX_BOOL FX_IsCtrlCode(FX_WCHAR ch)
16 {
17     FX_DWORD dwRet = (gs_FX_TextLayout_CodeProperties[(FX_WORD)ch] & FX_CHARTYPEBITSMASK);
18     return dwRet == FX_CHARTYPE_Tab || dwRet == FX_CHARTYPE_Control;
19 }
FX_IsRotationCode(FX_WCHAR ch)20 FX_BOOL FX_IsRotationCode(FX_WCHAR ch)
21 {
22     return (gs_FX_TextLayout_CodeProperties[(FX_WORD)ch] & 0x8000) != 0;
23 }
FX_IsCombinationChar(FX_WCHAR wch)24 FX_BOOL FX_IsCombinationChar(FX_WCHAR wch)
25 {
26     FX_DWORD dwProps = (gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK);
27     return dwProps == FX_CHARTYPE_Combination;
28 }
FX_IsBidiChar(FX_WCHAR wch)29 FX_BOOL	FX_IsBidiChar(FX_WCHAR wch)
30 {
31     FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
32     FX_INT32 iBidiCls = (dwProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS;
33     return (FX_BIDICLASS_R == iBidiCls || FX_BIDICLASS_AL == iBidiCls);
34 }
FX_GetMirrorChar(FX_WCHAR wch,FX_BOOL bRTL,FX_BOOL bVertical)35 FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical)
36 {
37     FX_DWORD dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
38     FX_DWORD dwTemp = (dwProps & 0xFF800000);
39     if (bRTL && dwTemp < 0xFF800000) {
40         wch = gs_FX_TextLayout_BidiMirror[dwTemp >> 23];
41         dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
42     }
43     if (bVertical) {
44         dwTemp = (dwProps & 0x007E0000);
45         if (dwTemp < 0x007E0000) {
46             wch = gs_FX_TextLayout_VerticalMirror[dwTemp >> 17];
47         }
48     }
49     return wch;
50 }
FX_GetMirrorChar(FX_WCHAR wch,FX_DWORD dwProps,FX_BOOL bRTL,FX_BOOL bVertical)51 FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_DWORD dwProps, FX_BOOL bRTL, FX_BOOL bVertical)
52 {
53     FX_DWORD dwTemp = (dwProps & 0xFF800000);
54     if (bRTL && dwTemp < 0xFF800000) {
55         wch = gs_FX_TextLayout_BidiMirror[dwTemp >> 23];
56         dwProps = gs_FX_TextLayout_CodeProperties[(FX_WORD)wch];
57     }
58     if (bVertical) {
59         dwTemp = (dwProps & 0x007E0000);
60         if (dwTemp < 0x007E0000) {
61             wch = gs_FX_TextLayout_VerticalMirror[dwTemp >> 17];
62         }
63     }
64     return wch;
65 }
66