• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_UCD_H_
8 #define CORE_FXCRT_FX_UCD_H_
9 
10 #include "core/fxcrt/cfx_retain_ptr.h"
11 #include "core/fxcrt/fx_basic.h"
12 
13 #define FX_BIDICLASSBITS 6
14 #define FX_BIDICLASSBITSMASK (31 << FX_BIDICLASSBITS)
15 
16 enum FX_BIDICLASS {
17   FX_BIDICLASS_ON = 0,    // Other Neutral
18   FX_BIDICLASS_L = 1,     // Left Letter
19   FX_BIDICLASS_R = 2,     // Right Letter
20   FX_BIDICLASS_AN = 3,    // Arabic Number
21   FX_BIDICLASS_EN = 4,    // European Number
22   FX_BIDICLASS_AL = 5,    // Arabic Letter
23   FX_BIDICLASS_NSM = 6,   // Non-spacing Mark
24   FX_BIDICLASS_CS = 7,    // Common Number Separator
25   FX_BIDICLASS_ES = 8,    // European Separator
26   FX_BIDICLASS_ET = 9,    // European Number Terminator
27   FX_BIDICLASS_BN = 10,   // Boundary Neutral
28   FX_BIDICLASS_S = 11,    // Segment Separator
29   FX_BIDICLASS_WS = 12,   // Whitespace
30   FX_BIDICLASS_B = 13,    // Paragraph Separator
31   FX_BIDICLASS_RLO = 14,  // Right-to-Left Override
32   FX_BIDICLASS_RLE = 15,  // Right-to-Left Embedding
33   FX_BIDICLASS_LRO = 16,  // Left-to-Right Override
34   FX_BIDICLASS_LRE = 17,  // Left-to-Right Embedding
35   FX_BIDICLASS_PDF = 18,  // Pop Directional Format
36   FX_BIDICLASS_N = FX_BIDICLASS_ON,
37 };
38 
39 extern const uint32_t kTextLayoutCodeProperties[];
40 extern const size_t kTextLayoutCodePropertiesSize;
41 
42 extern const uint16_t kFXTextLayoutVerticalMirror[];
43 extern const size_t kFXTextLayoutVerticalMirrorSize;
44 
45 extern const uint16_t kFXTextLayoutBidiMirror[];
46 extern const size_t kFXTextLayoutBidiMirrorSize;
47 
48 uint32_t FX_GetUnicodeProperties(FX_WCHAR wch);
49 FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, bool bRTL, bool bVertical);
50 
51 #ifdef PDF_ENABLE_XFA
52 enum FX_CHARBREAKPROP {
53   FX_CBP_OP = 0,
54   FX_CBP_CL = 1,
55   FX_CBP_QU = 2,
56   FX_CBP_GL = 3,
57   FX_CBP_NS = 4,
58   FX_CBP_EX = 5,
59   FX_CBP_SY = 6,
60   FX_CBP_IS = 7,
61   FX_CBP_PR = 8,
62   FX_CBP_PO = 9,
63   FX_CBP_NU = 10,
64   FX_CBP_AL = 11,
65   FX_CBP_ID = 12,
66   FX_CBP_IN = 13,
67   FX_CBP_HY = 14,
68   FX_CBP_BA = 15,
69   FX_CBP_BB = 16,
70   FX_CBP_B2 = 17,
71   FX_CBP_ZW = 18,
72   FX_CBP_CM = 19,
73   FX_CBP_WJ = 20,
74   FX_CBP_H2 = 21,
75   FX_CBP_H3 = 22,
76   FX_CBP_JL = 23,
77   FX_CBP_JV = 24,
78   FX_CBP_JT = 25,
79 
80   FX_CBP_BK = 26,
81   FX_CBP_CR = 27,
82   FX_CBP_LF = 28,
83   FX_CBP_NL = 29,
84   FX_CBP_SA = 30,
85   FX_CBP_SG = 31,
86   FX_CBP_CB = 32,
87   FX_CBP_XX = 33,
88   FX_CBP_AI = 34,
89   FX_CBP_SP = 35,
90   FX_CBP_TB = 37,
91   FX_CBP_NONE = 36,
92 };
93 
94 #define FX_CHARTYPEBITS 11
95 #define FX_CHARTYPEBITSMASK (15 << FX_CHARTYPEBITS)
96 enum FX_CHARTYPE {
97   FX_CHARTYPE_Unknown = 0,
98   FX_CHARTYPE_Tab = (1 << FX_CHARTYPEBITS),
99   FX_CHARTYPE_Space = (2 << FX_CHARTYPEBITS),
100   FX_CHARTYPE_Control = (3 << FX_CHARTYPEBITS),
101   FX_CHARTYPE_Combination = (4 << FX_CHARTYPEBITS),
102   FX_CHARTYPE_Numeric = (5 << FX_CHARTYPEBITS),
103   FX_CHARTYPE_Normal = (6 << FX_CHARTYPEBITS),
104   FX_CHARTYPE_ArabicAlef = (7 << FX_CHARTYPEBITS),
105   FX_CHARTYPE_ArabicSpecial = (8 << FX_CHARTYPEBITS),
106   FX_CHARTYPE_ArabicDistortion = (9 << FX_CHARTYPEBITS),
107   FX_CHARTYPE_ArabicNormal = (10 << FX_CHARTYPEBITS),
108   FX_CHARTYPE_ArabicForm = (11 << FX_CHARTYPEBITS),
109   FX_CHARTYPE_Arabic = (12 << FX_CHARTYPEBITS),
110 };
GetCharTypeFromProp(uint32_t prop)111 inline FX_CHARTYPE GetCharTypeFromProp(uint32_t prop) {
112   return static_cast<FX_CHARTYPE>(prop & FX_CHARTYPEBITSMASK);
113 }
114 
115 bool FX_IsCtrlCode(FX_WCHAR ch);
116 FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch,
117                           uint32_t dwProps,
118                           bool bRTL,
119                           bool bVertical);
120 class CFX_Char {
121  public:
CFX_Char()122   CFX_Char()
123       : m_wCharCode(0),
124         m_nBreakType(0),
125         m_dwCharProps(0),
126         m_iCharWidth(0),
127         m_iHorizontalScale(100),
128         m_iVerticalScale(100) {}
129 
CFX_Char(uint16_t wCharCode,uint32_t dwCharProps)130   CFX_Char(uint16_t wCharCode, uint32_t dwCharProps)
131       : m_wCharCode(wCharCode),
132         m_nBreakType(0),
133         m_dwCharProps(dwCharProps),
134         m_iCharWidth(0),
135         m_iHorizontalScale(100),
136         m_iVerticalScale(100) {}
137 
GetCharType()138   FX_CHARTYPE GetCharType() const { return GetCharTypeFromProp(m_dwCharProps); }
139 
140   uint16_t m_wCharCode;
141   uint8_t m_nBreakType;
142   uint32_t m_dwCharProps;
143   int32_t m_iCharWidth;
144   int32_t m_iHorizontalScale;
145   int32_t m_iVerticalScale;
146 };
147 
148 class CFX_TxtChar : public CFX_Char {
149  public:
CFX_TxtChar()150   CFX_TxtChar()
151       : m_nRotation(0),
152         m_dwCharStyles(0),
153         m_dwStatus(0),
154         m_iBidiClass(0),
155         m_iBidiLevel(0),
156         m_iBidiPos(0),
157         m_iBidiOrder(0),
158         m_pUserData(nullptr) {}
159 
160   int8_t m_nRotation;
161   uint32_t m_dwCharStyles;
162   uint32_t m_dwStatus;
163   int16_t m_iBidiClass;
164   int16_t m_iBidiLevel;
165   int16_t m_iBidiPos;
166   int16_t m_iBidiOrder;
167   void* m_pUserData;
168 };
169 
170 enum class CFX_RTFBreakType { None = 0, Piece, Line, Paragraph, Page };
171 
172 class CFX_RTFChar : public CFX_Char {
173  public:
174   CFX_RTFChar();
175   CFX_RTFChar(const CFX_RTFChar& other);
176   ~CFX_RTFChar();
177 
178   CFX_RTFBreakType m_dwStatus;
179   int32_t m_iFontSize;
180   int32_t m_iFontHeight;
181   int16_t m_iBidiClass;
182   int16_t m_iBidiLevel;
183   int16_t m_iBidiPos;
184   int16_t m_iBidiOrder;
185   uint32_t m_dwIdentity;
186   CFX_RetainPtr<CFX_Retainable> m_pUserData;
187 };
188 
CFX_RTFChar()189 inline CFX_RTFChar::CFX_RTFChar()
190     : m_dwStatus(CFX_RTFBreakType::None),
191       m_iFontSize(0),
192       m_iFontHeight(0),
193       m_iBidiClass(0),
194       m_iBidiLevel(0),
195       m_iBidiPos(0),
196       m_dwIdentity(0),
197       m_pUserData(nullptr) {}
198 
199 inline CFX_RTFChar::CFX_RTFChar(const CFX_RTFChar& other) = default;
200 inline CFX_RTFChar::~CFX_RTFChar() = default;
201 
202 #endif  // PDF_ENABLE_XFA
203 
204 #endif  // CORE_FXCRT_FX_UCD_H_
205