Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: core/fxcrt/fx_arabic.cpp

Issue 1954593004: CFX_ArabicChar contains only static methods, no need to instantiate. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: re-namespace Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fxcrt/include/fx_arabic.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/fxcrt/include/fx_arabic.h" 7 #include "core/fxcrt/include/fx_arabic.h"
8 #include "core/fxcrt/include/fx_ucd.h" 8 #include "core/fxcrt/include/fx_ucd.h"
9 9
10 namespace { 10 namespace {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 {0x0623, 0xFEF7}, 107 {0x0623, 0xFEF7},
108 {0x0625, 0xFEF9}, 108 {0x0625, 0xFEF9},
109 {0x0627, 0xFEFB}, 109 {0x0627, 0xFEFB},
110 }; 110 };
111 111
112 const FX_ARASHADDA gs_FX_ShaddaTable[] = { 112 const FX_ARASHADDA gs_FX_ShaddaTable[] = {
113 {0x064C, 0xFC5E}, {0x064D, 0xFC5F}, {0x064E, 0xFC60}, 113 {0x064C, 0xFC5E}, {0x064D, 0xFC5F}, {0x064E, 0xFC60},
114 {0x064F, 0xFC61}, {0x0650, 0xFC62}, 114 {0x064F, 0xFC61}, {0x0650, 0xFC62},
115 }; 115 };
116 116
117 const FX_ARBFORMTABLE* ParseChar(const CFX_Char* pTC,
118 FX_WCHAR& wChar,
119 FX_CHARTYPE& eType) {
120 if (!pTC) {
121 eType = FX_CHARTYPE_Unknown;
122 wChar = 0xFEFF;
123 return nullptr;
124 }
125 eType = (FX_CHARTYPE)pTC->GetCharType();
126 wChar = (FX_WCHAR)pTC->m_wCharCode;
127 const FX_ARBFORMTABLE* pFT = FX_GetArabicFormTable(wChar);
128 if (!pFT || eType >= FX_CHARTYPE_ArabicNormal)
129 eType = FX_CHARTYPE_Unknown;
130
131 return pFT;
132 }
133
117 } // namespace 134 } // namespace
118 135
119 const FX_ARBFORMTABLE* FX_GetArabicFormTable(FX_WCHAR unicode) { 136 const FX_ARBFORMTABLE* FX_GetArabicFormTable(FX_WCHAR unicode) {
120 if (unicode < 0x622 || unicode > 0x6d5) { 137 if (unicode < 0x622 || unicode > 0x6d5) {
121 return NULL; 138 return NULL;
122 } 139 }
123 return g_FX_ArabicFormTables + unicode - 0x622; 140 return g_FX_ArabicFormTables + unicode - 0x622;
124 } 141 }
125 FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef) { 142 FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef) {
126 static const int32_t s_iAlefCount = 143 static const int32_t s_iAlefCount =
(...skipping 11 matching lines...) Expand all
138 sizeof(gs_FX_ShaddaTable) / sizeof(FX_ARASHADDA); 155 sizeof(gs_FX_ShaddaTable) / sizeof(FX_ARASHADDA);
139 for (int32_t iStart = 0; iStart < s_iShaddaCount; iStart++) { 156 for (int32_t iStart = 0; iStart < s_iShaddaCount; iStart++) {
140 const FX_ARASHADDA& v = gs_FX_ShaddaTable[iStart]; 157 const FX_ARASHADDA& v = gs_FX_ShaddaTable[iStart];
141 if (v.wShadda == shadda) { 158 if (v.wShadda == shadda) {
142 return v.wIsolated; 159 return v.wIsolated;
143 } 160 }
144 } 161 }
145 return shadda; 162 return shadda;
146 } 163 }
147 164
148 FX_BOOL CFX_ArabicChar::IsArabicChar(FX_WCHAR wch) const { 165 namespace pdfium {
166 namespace arabic {
167
168 bool IsArabicChar(FX_WCHAR wch) {
149 uint32_t dwRet = 169 uint32_t dwRet =
150 kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK; 170 kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK;
151 return dwRet >= FX_CHARTYPE_ArabicAlef; 171 return dwRet >= FX_CHARTYPE_ArabicAlef;
152 } 172 }
153 FX_BOOL CFX_ArabicChar::IsArabicFormChar(FX_WCHAR wch) const { 173
174 bool IsArabicFormChar(FX_WCHAR wch) {
154 return (kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK) == 175 return (kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK) ==
155 FX_CHARTYPE_ArabicForm; 176 FX_CHARTYPE_ArabicForm;
156 } 177 }
157 FX_WCHAR CFX_ArabicChar::GetFormChar(FX_WCHAR wch, 178
158 FX_WCHAR prev, 179 FX_WCHAR GetFormChar(FX_WCHAR wch, FX_WCHAR prev, FX_WCHAR next) {
159 FX_WCHAR next) const {
160 CFX_Char c(wch, kTextLayoutCodeProperties[(uint16_t)wch]); 180 CFX_Char c(wch, kTextLayoutCodeProperties[(uint16_t)wch]);
161 CFX_Char p(prev, kTextLayoutCodeProperties[(uint16_t)prev]); 181 CFX_Char p(prev, kTextLayoutCodeProperties[(uint16_t)prev]);
162 CFX_Char n(next, kTextLayoutCodeProperties[(uint16_t)next]); 182 CFX_Char n(next, kTextLayoutCodeProperties[(uint16_t)next]);
163 return GetFormChar(&c, &p, &n); 183 return GetFormChar(&c, &p, &n);
164 } 184 }
165 FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char* cur, 185
166 const CFX_Char* prev, 186 FX_WCHAR GetFormChar(const CFX_Char* cur,
167 const CFX_Char* next) const { 187 const CFX_Char* prev,
188 const CFX_Char* next) {
168 FX_CHARTYPE eCur; 189 FX_CHARTYPE eCur;
169 FX_WCHAR wCur; 190 FX_WCHAR wCur;
170 const FX_ARBFORMTABLE* ft = ParseChar(cur, wCur, eCur); 191 const FX_ARBFORMTABLE* ft = ParseChar(cur, wCur, eCur);
171 if (eCur < FX_CHARTYPE_ArabicAlef || eCur >= FX_CHARTYPE_ArabicNormal) { 192 if (eCur < FX_CHARTYPE_ArabicAlef || eCur >= FX_CHARTYPE_ArabicNormal) {
172 return wCur; 193 return wCur;
173 } 194 }
174 FX_CHARTYPE ePrev; 195 FX_CHARTYPE ePrev;
175 FX_WCHAR wPrev; 196 FX_WCHAR wPrev;
176 ParseChar(prev, wPrev, ePrev); 197 ParseChar(prev, wPrev, ePrev);
177 if (wPrev == 0x0644 && eCur == FX_CHARTYPE_ArabicAlef) { 198 if (wPrev == 0x0644 && eCur == FX_CHARTYPE_ArabicAlef) {
178 return 0xFEFF; 199 return 0xFEFF;
179 } 200 }
180 FX_CHARTYPE eNext; 201 FX_CHARTYPE eNext;
181 FX_WCHAR wNext; 202 FX_WCHAR wNext;
182 ParseChar(next, wNext, eNext); 203 ParseChar(next, wNext, eNext);
183 bool bAlef = (eNext == FX_CHARTYPE_ArabicAlef && wCur == 0x644); 204 bool bAlef = (eNext == FX_CHARTYPE_ArabicAlef && wCur == 0x644);
184 if (ePrev < FX_CHARTYPE_ArabicAlef) { 205 if (ePrev < FX_CHARTYPE_ArabicAlef) {
185 if (bAlef) { 206 if (bAlef) {
186 return FX_GetArabicFromAlefTable(wNext); 207 return FX_GetArabicFromAlefTable(wNext);
187 } else {
188 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial;
189 } 208 }
190 } else { 209 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial;
191 if (bAlef) {
192 wCur = FX_GetArabicFromAlefTable(wNext);
193 return (ePrev != FX_CHARTYPE_ArabicDistortion) ? wCur : ++wCur;
194 } else if (ePrev == FX_CHARTYPE_ArabicAlef ||
195 ePrev == FX_CHARTYPE_ArabicSpecial) {
196 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial;
197 } else {
198 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wFinal : ft->wMedial;
199 }
200 } 210 }
211 if (bAlef) {
212 wCur = FX_GetArabicFromAlefTable(wNext);
213 return (ePrev != FX_CHARTYPE_ArabicDistortion) ? wCur : ++wCur;
214 }
215 if (ePrev == FX_CHARTYPE_ArabicAlef || ePrev == FX_CHARTYPE_ArabicSpecial) {
216 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial;
217 }
218 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wFinal : ft->wMedial;
201 } 219 }
202 const FX_ARBFORMTABLE* CFX_ArabicChar::ParseChar(const CFX_Char* pTC, 220
203 FX_WCHAR& wChar, 221 } // namespace arabic
204 FX_CHARTYPE& eType) const { 222 } // namespace pdfium
205 if (pTC == NULL) { 223
206 eType = FX_CHARTYPE_Unknown;
207 wChar = 0xFEFF;
208 return NULL;
209 }
210 eType = (FX_CHARTYPE)pTC->GetCharType();
211 wChar = (FX_WCHAR)pTC->m_wCharCode;
212 const FX_ARBFORMTABLE* pFT = FX_GetArabicFormTable(wChar);
213 if (pFT == NULL || eType >= FX_CHARTYPE_ArabicNormal) {
214 eType = FX_CHARTYPE_Unknown;
215 }
216 return pFT;
217 }
218 void FX_BidiReverseString(CFX_WideString& wsText, 224 void FX_BidiReverseString(CFX_WideString& wsText,
219 int32_t iStart, 225 int32_t iStart,
220 int32_t iCount) { 226 int32_t iCount) {
221 ASSERT(iStart > -1 && iStart < wsText.GetLength()); 227 ASSERT(iStart > -1 && iStart < wsText.GetLength());
222 ASSERT(iCount >= 0 && iStart + iCount <= wsText.GetLength()); 228 ASSERT(iCount >= 0 && iStart + iCount <= wsText.GetLength());
223 FX_WCHAR wch; 229 FX_WCHAR wch;
224 FX_WCHAR* pStart = const_cast<FX_WCHAR*>(wsText.c_str()); 230 FX_WCHAR* pStart = const_cast<FX_WCHAR*>(wsText.c_str());
225 pStart += iStart; 231 pStart += iStart;
226 FX_WCHAR* pEnd = pStart + iCount - 1; 232 FX_WCHAR* pEnd = pStart + iCount - 1;
227 while (pStart < pEnd) { 233 while (pStart < pEnd) {
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 } 964 }
959 }; 965 };
960 void FX_BidiLine(CFX_TxtCharArray& chars, int32_t iCount, int32_t iBaseLevel) { 966 void FX_BidiLine(CFX_TxtCharArray& chars, int32_t iCount, int32_t iBaseLevel) {
961 CFX_BidiLineTemplate<CFX_TxtChar> blt; 967 CFX_BidiLineTemplate<CFX_TxtChar> blt;
962 blt.FX_BidiLine(chars, iCount, iBaseLevel); 968 blt.FX_BidiLine(chars, iCount, iBaseLevel);
963 } 969 }
964 void FX_BidiLine(CFX_RTFCharArray& chars, int32_t iCount, int32_t iBaseLevel) { 970 void FX_BidiLine(CFX_RTFCharArray& chars, int32_t iCount, int32_t iBaseLevel) {
965 CFX_BidiLineTemplate<CFX_RTFChar> blt; 971 CFX_BidiLineTemplate<CFX_RTFChar> blt;
966 blt.FX_BidiLine(chars, iCount, iBaseLevel); 972 blt.FX_BidiLine(chars, iCount, iBaseLevel);
967 } 973 }
OLDNEW
« no previous file with comments | « no previous file | core/fxcrt/include/fx_arabic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698