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