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 "xfa/fxfa/parser/xfa_basic_imp.h" | 7 #include "xfa/fxfa/parser/xfa_basic_imp.h" |
8 | 8 |
9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
10 #include "xfa/fgas/crt/fgas_algorithm.h" | 10 #include "xfa/fgas/crt/fgas_algorithm.h" |
11 #include "xfa/fgas/crt/fgas_codepage.h" | 11 #include "xfa/fgas/crt/fgas_codepage.h" |
12 #include "xfa/fgas/crt/fgas_system.h" | 12 #include "xfa/fgas/crt/fgas_system.h" |
13 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 13 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
14 #include "xfa/fxfa/parser/xfa_basic_data.h" | 14 #include "xfa/fxfa/parser/xfa_basic_data.h" |
15 #include "xfa/fxfa/parser/xfa_doclayout.h" | 15 #include "xfa/fxfa/parser/xfa_doclayout.h" |
16 #include "xfa/fxfa/parser/xfa_document.h" | 16 #include "xfa/fxfa/parser/xfa_document.h" |
17 #include "xfa/fxfa/parser/xfa_localemgr.h" | 17 #include "xfa/fxfa/parser/xfa_localemgr.h" |
18 #include "xfa/fxfa/parser/xfa_object.h" | 18 #include "xfa/fxfa/parser/xfa_object.h" |
19 #include "xfa/fxfa/parser/xfa_parser.h" | 19 #include "xfa/fxfa/parser/xfa_parser.h" |
20 #include "xfa/fxfa/parser/xfa_script.h" | 20 #include "xfa/fxfa/parser/xfa_script.h" |
21 #include "xfa/fxfa/parser/xfa_utils.h" | 21 #include "xfa/fxfa/parser/xfa_utils.h" |
22 | 22 |
23 const XFA_PACKETINFO* XFA_GetPacketByName(const CFX_WideStringC& wsName) { | 23 const XFA_PACKETINFO* XFA_GetPacketByName(const CFX_WideStringC& wsName) { |
24 int32_t iLength = wsName.GetLength(); | 24 if (wsName.IsEmpty()) |
25 if (iLength == 0) { | 25 return nullptr; |
26 return NULL; | 26 |
27 } | 27 uint32_t uHash = FX_HashCode_GetW(wsName, false); |
28 uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); | 28 int32_t iStart = 0; |
29 int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1; | 29 int32_t iEnd = g_iXFAPacketCount - 1; |
30 do { | 30 do { |
31 int32_t iMid = (iStart + iEnd) / 2; | 31 int32_t iMid = (iStart + iEnd) / 2; |
32 const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid; | 32 const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid; |
33 if (uHash == pInfo->uHash) { | 33 if (uHash == pInfo->uHash) { |
34 return pInfo; | 34 return pInfo; |
35 } else if (uHash < pInfo->uHash) { | 35 } else if (uHash < pInfo->uHash) { |
36 iEnd = iMid - 1; | 36 iEnd = iMid - 1; |
37 } else { | 37 } else { |
38 iStart = iMid + 1; | 38 iStart = iMid + 1; |
39 } | 39 } |
(...skipping 16 matching lines...) Expand all Loading... |
56 } while (iStart <= iEnd); | 56 } while (iStart <= iEnd); |
57 return NULL; | 57 return NULL; |
58 } | 58 } |
59 | 59 |
60 const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PACKET ePacket) { | 60 const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PACKET ePacket) { |
61 return g_XFAPacketData + ePacket; | 61 return g_XFAPacketData + ePacket; |
62 } | 62 } |
63 | 63 |
64 const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( | 64 const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( |
65 const CFX_WideStringC& wsName) { | 65 const CFX_WideStringC& wsName) { |
66 int32_t iLength = wsName.GetLength(); | 66 if (wsName.IsEmpty()) |
67 if (iLength == 0) { | 67 return nullptr; |
68 return NULL; | 68 |
69 } | 69 uint32_t uHash = FX_HashCode_GetW(wsName, false); |
70 uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); | 70 int32_t iStart = 0; |
71 int32_t iStart = 0, iEnd = g_iXFAEnumCount - 1; | 71 int32_t iEnd = g_iXFAEnumCount - 1; |
72 do { | 72 do { |
73 int32_t iMid = (iStart + iEnd) / 2; | 73 int32_t iMid = (iStart + iEnd) / 2; |
74 const XFA_ATTRIBUTEENUMINFO* pInfo = g_XFAEnumData + iMid; | 74 const XFA_ATTRIBUTEENUMINFO* pInfo = g_XFAEnumData + iMid; |
75 if (uHash == pInfo->uHash) { | 75 if (uHash == pInfo->uHash) { |
76 return pInfo; | 76 return pInfo; |
77 } else if (uHash < pInfo->uHash) { | 77 } else if (uHash < pInfo->uHash) { |
78 iEnd = iMid - 1; | 78 iEnd = iMid - 1; |
79 } else { | 79 } else { |
80 iStart = iMid + 1; | 80 iStart = iMid + 1; |
81 } | 81 } |
82 } while (iStart <= iEnd); | 82 } while (iStart <= iEnd); |
83 return NULL; | 83 return NULL; |
84 } | 84 } |
85 const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { | 85 const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
86 return g_XFAEnumData + eName; | 86 return g_XFAEnumData + eName; |
87 } | 87 } |
88 | 88 |
89 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { | 89 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { |
90 int32_t iLength = wsName.GetLength(); | 90 if (wsName.IsEmpty()) |
91 if (iLength == 0) { | 91 return nullptr; |
92 return NULL; | 92 |
93 } | 93 uint32_t uHash = FX_HashCode_GetW(wsName, false); |
94 uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); | 94 int32_t iStart = 0; |
95 int32_t iStart = 0, iEnd = g_iXFAAttributeCount - 1; | 95 int32_t iEnd = g_iXFAAttributeCount - 1; |
96 do { | 96 do { |
97 int32_t iMid = (iStart + iEnd) / 2; | 97 int32_t iMid = (iStart + iEnd) / 2; |
98 const XFA_ATTRIBUTEINFO* pInfo = g_XFAAttributeData + iMid; | 98 const XFA_ATTRIBUTEINFO* pInfo = g_XFAAttributeData + iMid; |
99 if (uHash == pInfo->uHash) { | 99 if (uHash == pInfo->uHash) { |
100 return pInfo; | 100 return pInfo; |
101 } else if (uHash < pInfo->uHash) { | 101 } else if (uHash < pInfo->uHash) { |
102 iEnd = iMid - 1; | 102 iEnd = iMid - 1; |
103 } else { | 103 } else { |
104 iStart = iMid + 1; | 104 iStart = iMid + 1; |
105 } | 105 } |
106 } while (iStart <= iEnd); | 106 } while (iStart <= iEnd); |
107 return NULL; | 107 return nullptr; |
108 } | 108 } |
109 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { | 109 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { |
110 return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) : NULL; | 110 return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) : NULL; |
111 } | 111 } |
112 FX_BOOL XFA_GetAttributeDefaultValue(void*& pValue, | 112 FX_BOOL XFA_GetAttributeDefaultValue(void*& pValue, |
113 XFA_ELEMENT eElement, | 113 XFA_ELEMENT eElement, |
114 XFA_ATTRIBUTE eAttribute, | 114 XFA_ATTRIBUTE eAttribute, |
115 XFA_ATTRIBUTETYPE eType, | 115 XFA_ATTRIBUTETYPE eType, |
116 uint32_t dwPacket) { | 116 uint32_t dwPacket) { |
117 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); | 117 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 uint32_t dwPacket) { | 170 uint32_t dwPacket) { |
171 void* pValue; | 171 void* pValue; |
172 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | 172 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
173 XFA_ATTRIBUTETYPE_Measure, dwPacket)) { | 173 XFA_ATTRIBUTETYPE_Measure, dwPacket)) { |
174 return *(CXFA_Measurement*)pValue; | 174 return *(CXFA_Measurement*)pValue; |
175 } | 175 } |
176 return CXFA_Measurement(); | 176 return CXFA_Measurement(); |
177 } | 177 } |
178 | 178 |
179 const XFA_ELEMENTINFO* XFA_GetElementByName(const CFX_WideStringC& wsName) { | 179 const XFA_ELEMENTINFO* XFA_GetElementByName(const CFX_WideStringC& wsName) { |
180 int32_t iLength = wsName.GetLength(); | 180 if (wsName.IsEmpty()) |
181 if (iLength == 0) { | 181 return nullptr; |
182 return NULL; | 182 |
183 } | 183 uint32_t uHash = FX_HashCode_GetW(wsName, false); |
184 uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); | 184 int32_t iStart = 0; |
185 int32_t iStart = 0, iEnd = g_iXFAElementCount - 1; | 185 int32_t iEnd = g_iXFAElementCount - 1; |
186 do { | 186 do { |
187 int32_t iMid = (iStart + iEnd) / 2; | 187 int32_t iMid = (iStart + iEnd) / 2; |
188 const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; | 188 const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; |
189 if (uHash == pInfo->uHash) { | 189 if (uHash == pInfo->uHash) { |
190 return pInfo; | 190 return pInfo; |
191 } else if (uHash < pInfo->uHash) { | 191 } else if (uHash < pInfo->uHash) { |
192 iEnd = iMid - 1; | 192 iEnd = iMid - 1; |
193 } else { | 193 } else { |
194 iStart = iMid + 1; | 194 iStart = iMid + 1; |
195 } | 195 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 iEnd = iMid - 1; | 327 iEnd = iMid - 1; |
328 } else { | 328 } else { |
329 iStart = iMid + 1; | 329 iStart = iMid + 1; |
330 } | 330 } |
331 } while (iStart <= iEnd); | 331 } while (iStart <= iEnd); |
332 return NULL; | 332 return NULL; |
333 } | 333 } |
334 | 334 |
335 const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, | 335 const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, |
336 const CFX_WideStringC& wsMethodName) { | 336 const CFX_WideStringC& wsMethodName) { |
337 int32_t iLength = wsMethodName.GetLength(); | 337 if (wsMethodName.IsEmpty()) |
338 if (iLength == 0) { | 338 return nullptr; |
339 return NULL; | 339 |
340 } | |
341 int32_t iElementIndex = eElement; | 340 int32_t iElementIndex = eElement; |
342 while (iElementIndex != -1) { | 341 while (iElementIndex != -1) { |
343 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; | 342 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; |
344 int32_t icount = scriptIndex->wMethodCount; | 343 int32_t icount = scriptIndex->wMethodCount; |
345 if (icount == 0) { | 344 if (icount == 0) { |
346 iElementIndex = scriptIndex->wParentIndex; | 345 iElementIndex = scriptIndex->wParentIndex; |
347 continue; | 346 continue; |
348 } | 347 } |
349 uint32_t uHash = FX_HashCode_String_GetW(wsMethodName.c_str(), iLength); | 348 uint32_t uHash = FX_HashCode_GetW(wsMethodName, false); |
350 int32_t iStart = scriptIndex->wMethodStart, iEnd = iStart + icount - 1; | 349 int32_t iStart = scriptIndex->wMethodStart; |
| 350 int32_t iEnd = iStart + icount - 1; |
351 do { | 351 do { |
352 int32_t iMid = (iStart + iEnd) / 2; | 352 int32_t iMid = (iStart + iEnd) / 2; |
353 const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; | 353 const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; |
354 if (uHash == pInfo->uHash) { | 354 if (uHash == pInfo->uHash) { |
355 return pInfo; | 355 return pInfo; |
356 } else if (uHash < pInfo->uHash) { | 356 } else if (uHash < pInfo->uHash) { |
357 iEnd = iMid - 1; | 357 iEnd = iMid - 1; |
358 } else { | 358 } else { |
359 iStart = iMid + 1; | 359 iStart = iMid + 1; |
360 } | 360 } |
361 } while (iStart <= iEnd); | 361 } while (iStart <= iEnd); |
362 iElementIndex = scriptIndex->wParentIndex; | 362 iElementIndex = scriptIndex->wParentIndex; |
363 } | 363 } |
364 return NULL; | 364 return NULL; |
365 } | 365 } |
366 const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( | 366 const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( |
367 XFA_ELEMENT eElement, | 367 XFA_ELEMENT eElement, |
368 const CFX_WideStringC& wsAttributeName) { | 368 const CFX_WideStringC& wsAttributeName) { |
369 int32_t iLength = wsAttributeName.GetLength(); | 369 if (wsAttributeName.IsEmpty()) |
370 if (iLength == 0) { | 370 return nullptr; |
371 return NULL; | 371 |
372 } | |
373 int32_t iElementIndex = eElement; | 372 int32_t iElementIndex = eElement; |
374 while (iElementIndex != -1) { | 373 while (iElementIndex != -1) { |
375 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; | 374 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; |
376 int32_t icount = scriptIndex->wAttributeCount; | 375 int32_t icount = scriptIndex->wAttributeCount; |
377 if (icount == 0) { | 376 if (icount == 0) { |
378 iElementIndex = scriptIndex->wParentIndex; | 377 iElementIndex = scriptIndex->wParentIndex; |
379 continue; | 378 continue; |
380 } | 379 } |
381 uint32_t uHash = FX_HashCode_String_GetW(wsAttributeName.c_str(), iLength); | 380 uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false); |
382 int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; | 381 int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; |
383 do { | 382 do { |
384 int32_t iMid = (iStart + iEnd) / 2; | 383 int32_t iMid = (iStart + iEnd) / 2; |
385 const XFA_SCRIPTATTRIBUTEINFO* pInfo = g_SomAttributeData + iMid; | 384 const XFA_SCRIPTATTRIBUTEINFO* pInfo = g_SomAttributeData + iMid; |
386 if (uHash == pInfo->uHash) { | 385 if (uHash == pInfo->uHash) { |
387 return pInfo; | 386 return pInfo; |
388 } else if (uHash < pInfo->uHash) { | 387 } else if (uHash < pInfo->uHash) { |
389 iEnd = iMid - 1; | 388 iEnd = iMid - 1; |
390 } else { | 389 } else { |
391 iStart = iMid + 1; | 390 iStart = iMid + 1; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 m_iPosition += iMaxLength; | 568 m_iPosition += iMaxLength; |
570 bEOS = IsEOF(); | 569 bEOS = IsEOF(); |
571 return iMaxLength; | 570 return iMaxLength; |
572 } | 571 } |
573 uint16_t CXFA_WideTextRead::GetCodePage() const { | 572 uint16_t CXFA_WideTextRead::GetCodePage() const { |
574 return (sizeof(FX_WCHAR) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE; | 573 return (sizeof(FX_WCHAR) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE; |
575 } | 574 } |
576 uint16_t CXFA_WideTextRead::SetCodePage(uint16_t wCodePage) { | 575 uint16_t CXFA_WideTextRead::SetCodePage(uint16_t wCodePage) { |
577 return GetCodePage(); | 576 return GetCodePage(); |
578 } | 577 } |
OLD | NEW |