| 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 "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 Loading... |
| 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 Loading... |
| 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 // static |
| 166 bool CFX_ArabicChar::IsArabicChar(FX_WCHAR wch) { |
| 149 uint32_t dwRet = | 167 uint32_t dwRet = |
| 150 kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK; | 168 kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK; |
| 151 return dwRet >= FX_CHARTYPE_ArabicAlef; | 169 return dwRet >= FX_CHARTYPE_ArabicAlef; |
| 152 } | 170 } |
| 153 FX_BOOL CFX_ArabicChar::IsArabicFormChar(FX_WCHAR wch) const { | 171 |
| 172 // static |
| 173 bool CFX_ArabicChar::IsArabicFormChar(FX_WCHAR wch) { |
| 154 return (kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK) == | 174 return (kTextLayoutCodeProperties[(uint16_t)wch] & FX_CHARTYPEBITSMASK) == |
| 155 FX_CHARTYPE_ArabicForm; | 175 FX_CHARTYPE_ArabicForm; |
| 156 } | 176 } |
| 177 |
| 178 // static |
| 157 FX_WCHAR CFX_ArabicChar::GetFormChar(FX_WCHAR wch, | 179 FX_WCHAR CFX_ArabicChar::GetFormChar(FX_WCHAR wch, |
| 158 FX_WCHAR prev, | 180 FX_WCHAR prev, |
| 159 FX_WCHAR next) const { | 181 FX_WCHAR next) { |
| 160 CFX_Char c(wch, kTextLayoutCodeProperties[(uint16_t)wch]); | 182 CFX_Char c(wch, kTextLayoutCodeProperties[(uint16_t)wch]); |
| 161 CFX_Char p(prev, kTextLayoutCodeProperties[(uint16_t)prev]); | 183 CFX_Char p(prev, kTextLayoutCodeProperties[(uint16_t)prev]); |
| 162 CFX_Char n(next, kTextLayoutCodeProperties[(uint16_t)next]); | 184 CFX_Char n(next, kTextLayoutCodeProperties[(uint16_t)next]); |
| 163 return GetFormChar(&c, &p, &n); | 185 return GetFormChar(&c, &p, &n); |
| 164 } | 186 } |
| 187 |
| 188 // static |
| 165 FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char* cur, | 189 FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char* cur, |
| 166 const CFX_Char* prev, | 190 const CFX_Char* prev, |
| 167 const CFX_Char* next) const { | 191 const CFX_Char* next) { |
| 168 FX_CHARTYPE eCur; | 192 FX_CHARTYPE eCur; |
| 169 FX_WCHAR wCur; | 193 FX_WCHAR wCur; |
| 170 const FX_ARBFORMTABLE* ft = ParseChar(cur, wCur, eCur); | 194 const FX_ARBFORMTABLE* ft = ParseChar(cur, wCur, eCur); |
| 171 if (eCur < FX_CHARTYPE_ArabicAlef || eCur >= FX_CHARTYPE_ArabicNormal) { | 195 if (eCur < FX_CHARTYPE_ArabicAlef || eCur >= FX_CHARTYPE_ArabicNormal) { |
| 172 return wCur; | 196 return wCur; |
| 173 } | 197 } |
| 174 FX_CHARTYPE ePrev; | 198 FX_CHARTYPE ePrev; |
| 175 FX_WCHAR wPrev; | 199 FX_WCHAR wPrev; |
| 176 ParseChar(prev, wPrev, ePrev); | 200 ParseChar(prev, wPrev, ePrev); |
| 177 if (wPrev == 0x0644 && eCur == FX_CHARTYPE_ArabicAlef) { | 201 if (wPrev == 0x0644 && eCur == FX_CHARTYPE_ArabicAlef) { |
| 178 return 0xFEFF; | 202 return 0xFEFF; |
| 179 } | 203 } |
| 180 FX_CHARTYPE eNext; | 204 FX_CHARTYPE eNext; |
| 181 FX_WCHAR wNext; | 205 FX_WCHAR wNext; |
| 182 ParseChar(next, wNext, eNext); | 206 ParseChar(next, wNext, eNext); |
| 183 bool bAlef = (eNext == FX_CHARTYPE_ArabicAlef && wCur == 0x644); | 207 bool bAlef = (eNext == FX_CHARTYPE_ArabicAlef && wCur == 0x644); |
| 184 if (ePrev < FX_CHARTYPE_ArabicAlef) { | 208 if (ePrev < FX_CHARTYPE_ArabicAlef) { |
| 185 if (bAlef) { | 209 if (bAlef) { |
| 186 return FX_GetArabicFromAlefTable(wNext); | 210 return FX_GetArabicFromAlefTable(wNext); |
| 187 } else { | |
| 188 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial; | |
| 189 } | 211 } |
| 190 } else { | 212 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 } | 213 } |
| 214 if (bAlef) { |
| 215 wCur = FX_GetArabicFromAlefTable(wNext); |
| 216 return (ePrev != FX_CHARTYPE_ArabicDistortion) ? wCur : ++wCur; |
| 217 } |
| 218 if (ePrev == FX_CHARTYPE_ArabicAlef || ePrev == FX_CHARTYPE_ArabicSpecial) { |
| 219 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial; |
| 220 } |
| 221 return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wFinal : ft->wMedial; |
| 201 } | 222 } |
| 202 const FX_ARBFORMTABLE* CFX_ArabicChar::ParseChar(const CFX_Char* pTC, | 223 |
| 203 FX_WCHAR& wChar, | |
| 204 FX_CHARTYPE& eType) const { | |
| 205 if (pTC == NULL) { | |
| 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 Loading... |
| 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 } |
| OLD | NEW |