| 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 "../../include/fpdftext/fpdf_text.h" | 7 #include "../../include/fpdftext/fpdf_text.h" |
| 8 extern const FX_WCHAR g_UnicodeData_Normalization[]; | 8 extern const FX_WCHAR g_UnicodeData_Normalization[]; |
| 9 extern const FX_WCHAR g_UnicodeData_Normalization_Map1[]; | 9 extern const FX_WCHAR g_UnicodeData_Normalization_Map1[]; |
| 10 extern const FX_WCHAR g_UnicodeData_Normalization_Map2[]; | 10 extern const FX_WCHAR g_UnicodeData_Normalization_Map2[]; |
| 11 extern const FX_WCHAR g_UnicodeData_Normalization_Map3[]; | 11 extern const FX_WCHAR g_UnicodeData_Normalization_Map3[]; |
| 12 extern const FX_WCHAR g_UnicodeData_Normalization_Map4[]; | 12 extern const FX_WCHAR g_UnicodeData_Normalization_Map4[]; |
| 13 FX_LPCWSTR g_UnicodeData_Normalization_Maps[5] = { | 13 const FX_WCHAR* g_UnicodeData_Normalization_Maps[5] = { |
| 14 NULL, | 14 NULL, |
| 15 g_UnicodeData_Normalization_Map1, | 15 g_UnicodeData_Normalization_Map1, |
| 16 g_UnicodeData_Normalization_Map2, | 16 g_UnicodeData_Normalization_Map2, |
| 17 g_UnicodeData_Normalization_Map3, | 17 g_UnicodeData_Normalization_Map3, |
| 18 g_UnicodeData_Normalization_Map4 | 18 g_UnicodeData_Normalization_Map4 |
| 19 }; | 19 }; |
| 20 FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_LPWSTR pDst) | 20 FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst) |
| 21 { | 21 { |
| 22 wch = wch & 0xFFFF; | 22 wch = wch & 0xFFFF; |
| 23 FX_WCHAR wFind = g_UnicodeData_Normalization[wch]; | 23 FX_WCHAR wFind = g_UnicodeData_Normalization[wch]; |
| 24 if (!wFind) { | 24 if (!wFind) { |
| 25 if (pDst) { | 25 if (pDst) { |
| 26 *pDst = wch; | 26 *pDst = wch; |
| 27 } | 27 } |
| 28 return 1; | 28 return 1; |
| 29 } | 29 } |
| 30 if(wFind >= 0x8000) { | 30 if(wFind >= 0x8000) { |
| 31 wch = wFind - 0x8000; | 31 wch = wFind - 0x8000; |
| 32 wFind = 1; | 32 wFind = 1; |
| 33 } else { | 33 } else { |
| 34 wch = wFind & 0x0FFF; | 34 wch = wFind & 0x0FFF; |
| 35 wFind >>= 12; | 35 wFind >>= 12; |
| 36 } | 36 } |
| 37 FX_LPCWSTR pMap = g_UnicodeData_Normalization_Maps[wFind]; | 37 const FX_WCHAR* pMap = g_UnicodeData_Normalization_Maps[wFind]; |
| 38 if (pMap == g_UnicodeData_Normalization_Map4) { | 38 if (pMap == g_UnicodeData_Normalization_Map4) { |
| 39 pMap = g_UnicodeData_Normalization_Map4 + wch; | 39 pMap = g_UnicodeData_Normalization_Map4 + wch; |
| 40 wFind = (FX_WCHAR)(*pMap ++); | 40 wFind = (FX_WCHAR)(*pMap ++); |
| 41 } else { | 41 } else { |
| 42 pMap += wch; | 42 pMap += wch; |
| 43 } | 43 } |
| 44 if (pDst) { | 44 if (pDst) { |
| 45 FX_WCHAR n = wFind; | 45 FX_WCHAR n = wFind; |
| 46 while (n --) { | 46 while (n --) { |
| 47 *pDst ++ = *pMap ++; | 47 *pDst ++ = *pMap ++; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 return (FX_STRSIZE)wFind; | 50 return (FX_STRSIZE)wFind; |
| 51 } | 51 } |
| 52 FX_STRSIZE FX_WideString_GetNormalization(FX_WSTR wsSrc, FX_LPWSTR pDst) | 52 FX_STRSIZE FX_WideString_GetNormalization(FX_WSTR wsSrc, FX_WCHAR* pDst) |
| 53 { | 53 { |
| 54 FX_STRSIZE nCount = 0; | 54 FX_STRSIZE nCount = 0; |
| 55 for (FX_STRSIZE len = 0; len < wsSrc.GetLength(); len ++) { | 55 for (FX_STRSIZE len = 0; len < wsSrc.GetLength(); len ++) { |
| 56 FX_WCHAR wch = wsSrc.GetAt(len); | 56 FX_WCHAR wch = wsSrc.GetAt(len); |
| 57 if(pDst) { | 57 if(pDst) { |
| 58 nCount += FX_Unicode_GetNormalization(wch, pDst + nCount); | 58 nCount += FX_Unicode_GetNormalization(wch, pDst + nCount); |
| 59 } else { | 59 } else { |
| 60 nCount += FX_Unicode_GetNormalization(wch, pDst); | 60 nCount += FX_Unicode_GetNormalization(wch, pDst); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 return nCount; | 63 return nCount; |
| 64 } | 64 } |
| 65 FX_STRSIZE FX_WideString_GetNormalization(FX_WSTR wsSrc, CFX_WideString &wsDst) | 65 FX_STRSIZE FX_WideString_GetNormalization(FX_WSTR wsSrc, CFX_WideString &wsDst) |
| 66 { | 66 { |
| 67 FX_STRSIZE nLen = FX_WideString_GetNormalization(wsSrc, (FX_LPWSTR)NULL); | 67 FX_STRSIZE nLen = FX_WideString_GetNormalization(wsSrc, (FX_WCHAR*)NULL); |
| 68 if (!nLen) { | 68 if (!nLen) { |
| 69 return 0; | 69 return 0; |
| 70 } | 70 } |
| 71 FX_LPWSTR pBuf = wsDst.GetBuffer(nLen); | 71 FX_WCHAR* pBuf = wsDst.GetBuffer(nLen); |
| 72 FX_WideString_GetNormalization(wsSrc, pBuf); | 72 FX_WideString_GetNormalization(wsSrc, pBuf); |
| 73 wsDst.ReleaseBuffer(nLen); | 73 wsDst.ReleaseBuffer(nLen); |
| 74 return nLen; | 74 return nLen; |
| 75 } | 75 } |
| OLD | NEW |