fx_arabic.h revision 4d3acf4ec42bf6e838f9060103aff98fbf170794
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#ifndef CORE_FXCRT_FX_ARABIC_H_
8#define CORE_FXCRT_FX_ARABIC_H_
9
10#include "core/fxcrt/fx_arb.h"
11
12#define FX_BIDIMAXLEVEL 61
13#define FX_BidiDirection(a) (FX_IsOdd(a) ? FX_BIDICLASS_R : FX_BIDICLASS_L)
14#define FX_BidiGetDeferredType(a) (((a) >> 4) & 0x0F)
15#define FX_BidiGetResolvedType(a) ((a)&0x0F)
16
17namespace pdfium {
18namespace arabic {
19
20bool IsArabicChar(FX_WCHAR wch);
21bool IsArabicFormChar(FX_WCHAR wch);
22FX_WCHAR GetFormChar(FX_WCHAR wch, FX_WCHAR prev = 0, FX_WCHAR next = 0);
23FX_WCHAR GetFormChar(const CFX_Char* cur,
24                     const CFX_Char* prev,
25                     const CFX_Char* next);
26
27}  // namespace arabic
28}  // namespace pdfium
29
30void FX_BidiReverseString(CFX_WideString& wsText,
31                          int32_t iStart,
32                          int32_t iCount);
33void FX_BidiSetDeferredRun(CFX_Int32Array& values,
34                           int32_t iStart,
35                           int32_t iCount,
36                           int32_t iValue);
37void FX_BidiClassify(const CFX_WideString& wsText,
38                     CFX_Int32Array& classes,
39                     bool bWS = false);
40int32_t FX_BidiResolveExplicit(int32_t iBaseLevel,
41                               int32_t iDirection,
42                               CFX_Int32Array& classes,
43                               CFX_Int32Array& levels,
44                               int32_t iStart,
45                               int32_t iCount,
46                               int32_t iNest = 0);
47
48enum FX_BIDIWEAKSTATE {
49  FX_BIDIWEAKSTATE_xa = 0,
50  FX_BIDIWEAKSTATE_xr,
51  FX_BIDIWEAKSTATE_xl,
52  FX_BIDIWEAKSTATE_ao,
53  FX_BIDIWEAKSTATE_ro,
54  FX_BIDIWEAKSTATE_lo,
55  FX_BIDIWEAKSTATE_rt,
56  FX_BIDIWEAKSTATE_lt,
57  FX_BIDIWEAKSTATE_cn,
58  FX_BIDIWEAKSTATE_ra,
59  FX_BIDIWEAKSTATE_re,
60  FX_BIDIWEAKSTATE_la,
61  FX_BIDIWEAKSTATE_le,
62  FX_BIDIWEAKSTATE_ac,
63  FX_BIDIWEAKSTATE_rc,
64  FX_BIDIWEAKSTATE_rs,
65  FX_BIDIWEAKSTATE_lc,
66  FX_BIDIWEAKSTATE_ls,
67  FX_BIDIWEAKSTATE_ret,
68  FX_BIDIWEAKSTATE_let,
69};
70#define FX_BWSxa FX_BIDIWEAKSTATE_xa
71#define FX_BWSxr FX_BIDIWEAKSTATE_xr
72#define FX_BWSxl FX_BIDIWEAKSTATE_xl
73#define FX_BWSao FX_BIDIWEAKSTATE_ao
74#define FX_BWSro FX_BIDIWEAKSTATE_ro
75#define FX_BWSlo FX_BIDIWEAKSTATE_lo
76#define FX_BWSrt FX_BIDIWEAKSTATE_rt
77#define FX_BWSlt FX_BIDIWEAKSTATE_lt
78#define FX_BWScn FX_BIDIWEAKSTATE_cn
79#define FX_BWSra FX_BIDIWEAKSTATE_ra
80#define FX_BWSre FX_BIDIWEAKSTATE_re
81#define FX_BWSla FX_BIDIWEAKSTATE_la
82#define FX_BWSle FX_BIDIWEAKSTATE_le
83#define FX_BWSac FX_BIDIWEAKSTATE_ac
84#define FX_BWSrc FX_BIDIWEAKSTATE_rc
85#define FX_BWSrs FX_BIDIWEAKSTATE_rs
86#define FX_BWSlc FX_BIDIWEAKSTATE_lc
87#define FX_BWSls FX_BIDIWEAKSTATE_ls
88#define FX_BWSret FX_BIDIWEAKSTATE_ret
89#define FX_BWSlet FX_BIDIWEAKSTATE_let
90
91enum FX_BIDIWEAKACTION {
92  FX_BIDIWEAKACTION_IX = 0x100,
93  FX_BIDIWEAKACTION_XX = 0x0F,
94  FX_BIDIWEAKACTION_xxx = (0x0F << 4) + 0x0F,
95  FX_BIDIWEAKACTION_xIx = 0x100 + FX_BIDIWEAKACTION_xxx,
96  FX_BIDIWEAKACTION_xxN = (0x0F << 4) + FX_BIDICLASS_ON,
97  FX_BIDIWEAKACTION_xxE = (0x0F << 4) + FX_BIDICLASS_EN,
98  FX_BIDIWEAKACTION_xxA = (0x0F << 4) + FX_BIDICLASS_AN,
99  FX_BIDIWEAKACTION_xxR = (0x0F << 4) + FX_BIDICLASS_R,
100  FX_BIDIWEAKACTION_xxL = (0x0F << 4) + FX_BIDICLASS_L,
101  FX_BIDIWEAKACTION_Nxx = (FX_BIDICLASS_ON << 4) + 0x0F,
102  FX_BIDIWEAKACTION_Axx = (FX_BIDICLASS_AN << 4) + 0x0F,
103  FX_BIDIWEAKACTION_ExE = (FX_BIDICLASS_EN << 4) + FX_BIDICLASS_EN,
104  FX_BIDIWEAKACTION_NIx = (FX_BIDICLASS_ON << 4) + 0x0F + 0x100,
105  FX_BIDIWEAKACTION_NxN = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_ON,
106  FX_BIDIWEAKACTION_NxR = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_R,
107  FX_BIDIWEAKACTION_NxE = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_EN,
108  FX_BIDIWEAKACTION_AxA = (FX_BIDICLASS_AN << 4) + FX_BIDICLASS_AN,
109  FX_BIDIWEAKACTION_NxL = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_L,
110  FX_BIDIWEAKACTION_LxL = (FX_BIDICLASS_L << 4) + FX_BIDICLASS_L,
111  FX_BIDIWEAKACTION_xIL = (0x0F << 4) + FX_BIDICLASS_L + 0x100,
112  FX_BIDIWEAKACTION_AxR = (FX_BIDICLASS_AN << 4) + FX_BIDICLASS_R,
113  FX_BIDIWEAKACTION_Lxx = (FX_BIDICLASS_L << 4) + 0x0F,
114};
115#define FX_BWAIX FX_BIDIWEAKACTION_IX
116#define FX_BWAXX FX_BIDIWEAKACTION_XX
117#define FX_BWAxxx FX_BIDIWEAKACTION_xxx
118#define FX_BWAxIx FX_BIDIWEAKACTION_xIx
119#define FX_BWAxxN FX_BIDIWEAKACTION_xxN
120#define FX_BWAxxE FX_BIDIWEAKACTION_xxE
121#define FX_BWAxxA FX_BIDIWEAKACTION_xxA
122#define FX_BWAxxR FX_BIDIWEAKACTION_xxR
123#define FX_BWAxxL FX_BIDIWEAKACTION_xxL
124#define FX_BWANxx FX_BIDIWEAKACTION_Nxx
125#define FX_BWAAxx FX_BIDIWEAKACTION_Axx
126#define FX_BWAExE FX_BIDIWEAKACTION_ExE
127#define FX_BWANIx FX_BIDIWEAKACTION_NIx
128#define FX_BWANxN FX_BIDIWEAKACTION_NxN
129#define FX_BWANxR FX_BIDIWEAKACTION_NxR
130#define FX_BWANxE FX_BIDIWEAKACTION_NxE
131#define FX_BWAAxA FX_BIDIWEAKACTION_AxA
132#define FX_BWANxL FX_BIDIWEAKACTION_NxL
133#define FX_BWALxL FX_BIDIWEAKACTION_LxL
134#define FX_BWAxIL FX_BIDIWEAKACTION_xIL
135#define FX_BWAAxR FX_BIDIWEAKACTION_AxR
136#define FX_BWALxx FX_BIDIWEAKACTION_Lxx
137
138void FX_BidiResolveWeak(int32_t iBaseLevel,
139                        CFX_Int32Array& classes,
140                        CFX_Int32Array& levels);
141enum FX_BIDINEUTRALSTATE {
142  FX_BIDINEUTRALSTATE_r = 0,
143  FX_BIDINEUTRALSTATE_l,
144  FX_BIDINEUTRALSTATE_rn,
145  FX_BIDINEUTRALSTATE_ln,
146  FX_BIDINEUTRALSTATE_a,
147  FX_BIDINEUTRALSTATE_na,
148};
149#define FX_BNSr FX_BIDINEUTRALSTATE_r
150#define FX_BNSl FX_BIDINEUTRALSTATE_l
151#define FX_BNSrn FX_BIDINEUTRALSTATE_rn
152#define FX_BNSln FX_BIDINEUTRALSTATE_ln
153#define FX_BNSa FX_BIDINEUTRALSTATE_a
154#define FX_BNSna FX_BIDINEUTRALSTATE_na
155enum FX_BIDINEUTRALACTION {
156  FX_BIDINEUTRALACTION_nL = FX_BIDICLASS_L,
157  FX_BIDINEUTRALACTION_En = (FX_BIDICLASS_AN << 4),
158  FX_BIDINEUTRALACTION_Rn = (FX_BIDICLASS_R << 4),
159  FX_BIDINEUTRALACTION_Ln = (FX_BIDICLASS_L << 4),
160  FX_BIDINEUTRALACTION_In = FX_BIDIWEAKACTION_IX,
161  FX_BIDINEUTRALACTION_LnL = (FX_BIDICLASS_L << 4) + FX_BIDICLASS_L,
162};
163#define FX_BNAnL FX_BIDINEUTRALACTION_nL
164#define FX_BNAEn FX_BIDINEUTRALACTION_En
165#define FX_BNARn FX_BIDINEUTRALACTION_Rn
166#define FX_BNALn FX_BIDINEUTRALACTION_Ln
167#define FX_BNAIn FX_BIDINEUTRALACTION_In
168#define FX_BNALnL FX_BIDINEUTRALACTION_LnL
169int32_t FX_BidiGetDeferredNeutrals(int32_t iAction, int32_t iLevel);
170int32_t FX_BidiGetResolvedNeutrals(int32_t iAction);
171void FX_BidiResolveNeutrals(int32_t iBaseLevel,
172                            CFX_Int32Array& classes,
173                            const CFX_Int32Array& levels);
174void FX_BidiResolveImplicit(const CFX_Int32Array& classes,
175                            CFX_Int32Array& levels);
176void FX_BidiResolveWhitespace(int32_t iBaseLevel,
177                              const CFX_Int32Array& classes,
178                              CFX_Int32Array& levels);
179int32_t FX_BidiReorderLevel(int32_t iBaseLevel,
180                            CFX_WideString& wsText,
181                            const CFX_Int32Array& levels,
182                            int32_t iStart,
183                            bool bReverse = false);
184void FX_BidiReorder(int32_t iBaseLevel,
185                    CFX_WideString& wsText,
186                    const CFX_Int32Array& levels);
187
188#endif  // CORE_FXCRT_FX_ARABIC_H_
189