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_codepage.h" | 10 #include "xfa/fgas/crt/fgas_codepage.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } else { | 101 } else { |
102 iStart = iMid + 1; | 102 iStart = iMid + 1; |
103 } | 103 } |
104 } while (iStart <= iEnd); | 104 } while (iStart <= iEnd); |
105 return nullptr; | 105 return nullptr; |
106 } | 106 } |
107 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { | 107 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { |
108 return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) : NULL; | 108 return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) : NULL; |
109 } | 109 } |
110 FX_BOOL XFA_GetAttributeDefaultValue(void*& pValue, | 110 FX_BOOL XFA_GetAttributeDefaultValue(void*& pValue, |
111 XFA_ELEMENT eElement, | 111 XFA_Element eElement, |
112 XFA_ATTRIBUTE eAttribute, | 112 XFA_ATTRIBUTE eAttribute, |
113 XFA_ATTRIBUTETYPE eType, | 113 XFA_ATTRIBUTETYPE eType, |
114 uint32_t dwPacket) { | 114 uint32_t dwPacket) { |
115 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); | 115 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
116 if (pInfo == NULL) { | 116 if (pInfo == NULL) { |
117 return FALSE; | 117 return FALSE; |
118 } | 118 } |
119 if (dwPacket && (dwPacket & pInfo->dwPackets) == 0) { | 119 if (dwPacket && (dwPacket & pInfo->dwPackets) == 0) { |
120 return FALSE; | 120 return FALSE; |
121 } | 121 } |
122 if (pInfo->eType == eType) { | 122 if (pInfo->eType == eType) { |
123 pValue = pInfo->pDefValue; | 123 pValue = pInfo->pDefValue; |
124 return TRUE; | 124 return TRUE; |
125 } else if (pInfo->eType == XFA_ATTRIBUTETYPE_NOTSURE) { | 125 } else if (pInfo->eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
126 const XFA_NOTSUREATTRIBUTE* pAttr = | 126 const XFA_NOTSUREATTRIBUTE* pAttr = |
127 XFA_GetNotsureAttribute(eElement, eAttribute, eType); | 127 XFA_GetNotsureAttribute(eElement, eAttribute, eType); |
128 if (pAttr) { | 128 if (pAttr) { |
129 pValue = pAttr->pValue; | 129 pValue = pAttr->pValue; |
130 return TRUE; | 130 return TRUE; |
131 } | 131 } |
132 } | 132 } |
133 return FALSE; | 133 return FALSE; |
134 } | 134 } |
135 XFA_ATTRIBUTEENUM XFA_GetAttributeDefaultValue_Enum(XFA_ELEMENT eElement, | 135 XFA_ATTRIBUTEENUM XFA_GetAttributeDefaultValue_Enum(XFA_Element eElement, |
136 XFA_ATTRIBUTE eAttribute, | 136 XFA_ATTRIBUTE eAttribute, |
137 uint32_t dwPacket) { | 137 uint32_t dwPacket) { |
138 void* pValue; | 138 void* pValue; |
139 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | 139 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
140 XFA_ATTRIBUTETYPE_Enum, dwPacket)) { | 140 XFA_ATTRIBUTETYPE_Enum, dwPacket)) { |
141 return (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; | 141 return (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
142 } | 142 } |
143 return XFA_ATTRIBUTEENUM_Unknown; | 143 return XFA_ATTRIBUTEENUM_Unknown; |
144 } | 144 } |
145 CFX_WideStringC XFA_GetAttributeDefaultValue_Cdata(XFA_ELEMENT eElement, | 145 CFX_WideStringC XFA_GetAttributeDefaultValue_Cdata(XFA_Element eElement, |
146 XFA_ATTRIBUTE eAttribute, | 146 XFA_ATTRIBUTE eAttribute, |
147 uint32_t dwPacket) { | 147 uint32_t dwPacket) { |
148 void* pValue; | 148 void* pValue; |
149 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | 149 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
150 XFA_ATTRIBUTETYPE_Cdata, dwPacket)) { | 150 XFA_ATTRIBUTETYPE_Cdata, dwPacket)) { |
151 return (const FX_WCHAR*)pValue; | 151 return (const FX_WCHAR*)pValue; |
152 } | 152 } |
153 return NULL; | 153 return NULL; |
154 } | 154 } |
155 FX_BOOL XFA_GetAttributeDefaultValue_Boolean(XFA_ELEMENT eElement, | 155 FX_BOOL XFA_GetAttributeDefaultValue_Boolean(XFA_Element eElement, |
156 XFA_ATTRIBUTE eAttribute, | 156 XFA_ATTRIBUTE eAttribute, |
157 uint32_t dwPacket) { | 157 uint32_t dwPacket) { |
158 void* pValue; | 158 void* pValue; |
159 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | 159 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
160 XFA_ATTRIBUTETYPE_Boolean, dwPacket)) { | 160 XFA_ATTRIBUTETYPE_Boolean, dwPacket)) { |
161 return (FX_BOOL)(uintptr_t)pValue; | 161 return (FX_BOOL)(uintptr_t)pValue; |
162 } | 162 } |
163 return FALSE; | 163 return FALSE; |
164 } | 164 } |
165 | 165 |
166 CXFA_Measurement XFA_GetAttributeDefaultValue_Measure(XFA_ELEMENT eElement, | 166 CXFA_Measurement XFA_GetAttributeDefaultValue_Measure(XFA_Element eElement, |
167 XFA_ATTRIBUTE eAttribute, | 167 XFA_ATTRIBUTE eAttribute, |
168 uint32_t dwPacket) { | 168 uint32_t dwPacket) { |
169 void* pValue; | 169 void* pValue; |
170 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | 170 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, |
171 XFA_ATTRIBUTETYPE_Measure, dwPacket)) { | 171 XFA_ATTRIBUTETYPE_Measure, dwPacket)) { |
172 return *(CXFA_Measurement*)pValue; | 172 return *(CXFA_Measurement*)pValue; |
173 } | 173 } |
174 return CXFA_Measurement(); | 174 return CXFA_Measurement(); |
175 } | 175 } |
176 | 176 |
177 const XFA_ELEMENTINFO* XFA_GetElementByName(const CFX_WideStringC& wsName) { | 177 const XFA_ELEMENTINFO* XFA_GetElementByName(const CFX_WideStringC& wsName) { |
178 if (wsName.IsEmpty()) | 178 if (wsName.IsEmpty()) |
179 return nullptr; | 179 return nullptr; |
180 | 180 |
181 uint32_t uHash = FX_HashCode_GetW(wsName, false); | 181 uint32_t uHash = FX_HashCode_GetW(wsName, false); |
182 int32_t iStart = 0; | 182 int32_t iStart = 0; |
183 int32_t iEnd = g_iXFAElementCount - 1; | 183 int32_t iEnd = g_iXFAElementCount - 1; |
184 do { | 184 do { |
185 int32_t iMid = (iStart + iEnd) / 2; | 185 int32_t iMid = (iStart + iEnd) / 2; |
186 const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; | 186 const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; |
187 if (uHash == pInfo->uHash) { | 187 if (uHash == pInfo->uHash) { |
188 return pInfo; | 188 return pInfo; |
189 } else if (uHash < pInfo->uHash) { | 189 } else if (uHash < pInfo->uHash) { |
190 iEnd = iMid - 1; | 190 iEnd = iMid - 1; |
191 } else { | 191 } else { |
192 iStart = iMid + 1; | 192 iStart = iMid + 1; |
193 } | 193 } |
194 } while (iStart <= iEnd); | 194 } while (iStart <= iEnd); |
195 return NULL; | 195 return nullptr; |
196 } | 196 } |
197 const XFA_ELEMENTINFO* XFA_GetElementByID(XFA_ELEMENT eName) { | 197 const XFA_ELEMENTINFO* XFA_GetElementByID(XFA_Element eName) { |
198 return (eName < g_iXFAElementCount) ? (g_XFAElementData + eName) : NULL; | 198 return eName == XFA_Element::Unknown |
| 199 ? nullptr |
| 200 : g_XFAElementData + static_cast<int32_t>(eName); |
199 } | 201 } |
200 | 202 |
201 const uint8_t* XFA_GetElementAttributes(XFA_ELEMENT eElement, int32_t& iCount) { | 203 const uint8_t* XFA_GetElementAttributes(XFA_Element eElement, int32_t& iCount) { |
202 if (eElement >= g_iXFAElementCount) { | 204 if (eElement == XFA_Element::Unknown) |
203 return NULL; | 205 return nullptr; |
204 } | 206 |
205 const XFA_ELEMENTHIERARCHY* pElement = g_XFAElementAttributeIndex + eElement; | 207 const XFA_ELEMENTHIERARCHY* pElement = |
| 208 g_XFAElementAttributeIndex + static_cast<int32_t>(eElement); |
206 iCount = pElement->wCount; | 209 iCount = pElement->wCount; |
207 return g_XFAElementAttributeData + pElement->wStart; | 210 return g_XFAElementAttributeData + pElement->wStart; |
208 } | 211 } |
209 | 212 |
210 const XFA_ATTRIBUTEINFO* XFA_GetAttributeOfElement(XFA_ELEMENT eElement, | 213 const XFA_ATTRIBUTEINFO* XFA_GetAttributeOfElement(XFA_Element eElement, |
211 XFA_ATTRIBUTE eAttribute, | 214 XFA_ATTRIBUTE eAttribute, |
212 uint32_t dwPacket) { | 215 uint32_t dwPacket) { |
213 int32_t iCount = 0; | 216 int32_t iCount = 0; |
214 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); | 217 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
215 if (!pAttr || iCount < 1) | 218 if (!pAttr || iCount < 1) |
216 return nullptr; | 219 return nullptr; |
217 | 220 |
218 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) | 221 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
219 return nullptr; | 222 return nullptr; |
220 | 223 |
221 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); | 224 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
222 ASSERT(pInfo); | 225 ASSERT(pInfo); |
223 if (dwPacket == XFA_XDPPACKET_UNKNOWN) | 226 if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
224 return pInfo; | 227 return pInfo; |
225 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; | 228 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
226 } | 229 } |
227 | 230 |
228 const XFA_PROPERTY* XFA_GetElementProperties(XFA_ELEMENT eElement, | 231 const XFA_PROPERTY* XFA_GetElementProperties(XFA_Element eElement, |
229 int32_t& iCount) { | 232 int32_t& iCount) { |
230 if (eElement >= g_iXFAElementCount) { | 233 if (eElement == XFA_Element::Unknown) |
231 return NULL; | 234 return NULL; |
232 } | 235 |
233 const XFA_ELEMENTHIERARCHY* pElement = g_XFAElementPropertyIndex + eElement; | 236 const XFA_ELEMENTHIERARCHY* pElement = |
| 237 g_XFAElementPropertyIndex + static_cast<int32_t>(eElement); |
234 iCount = pElement->wCount; | 238 iCount = pElement->wCount; |
235 return g_XFAElementPropertyData + pElement->wStart; | 239 return g_XFAElementPropertyData + pElement->wStart; |
236 } | 240 } |
237 const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_ELEMENT eElement, | 241 const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_Element eElement, |
238 XFA_ELEMENT eProperty, | 242 XFA_Element eProperty, |
239 uint32_t dwPacket) { | 243 uint32_t dwPacket) { |
240 int32_t iCount = 0; | 244 int32_t iCount = 0; |
241 const XFA_PROPERTY* pProperty = XFA_GetElementProperties(eElement, iCount); | 245 const XFA_PROPERTY* pProperty = XFA_GetElementProperties(eElement, iCount); |
242 if (pProperty == NULL || iCount < 1) { | 246 if (pProperty == NULL || iCount < 1) { |
243 return NULL; | 247 return NULL; |
244 } | 248 } |
245 int32_t iStart = 0, iEnd = iCount - 1, iMid; | 249 int32_t iStart = 0, iEnd = iCount - 1, iMid; |
246 do { | 250 do { |
247 iMid = (iStart + iEnd) / 2; | 251 iMid = (iStart + iEnd) / 2; |
248 XFA_ELEMENT eName = (XFA_ELEMENT)pProperty[iMid].eName; | 252 XFA_Element eName = pProperty[iMid].eName; |
249 if (eProperty == eName) { | 253 if (eProperty == eName) { |
250 break; | 254 break; |
251 } else if (eProperty < eName) { | 255 } else if (eProperty < eName) { |
252 iEnd = iMid - 1; | 256 iEnd = iMid - 1; |
253 } else { | 257 } else { |
254 iStart = iMid + 1; | 258 iStart = iMid + 1; |
255 } | 259 } |
256 } while (iStart <= iEnd); | 260 } while (iStart <= iEnd); |
257 if (iStart > iEnd) { | 261 if (iStart > iEnd) { |
258 return NULL; | 262 return NULL; |
259 } | 263 } |
260 const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eProperty); | 264 const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eProperty); |
261 ASSERT(pInfo); | 265 ASSERT(pInfo); |
262 if (dwPacket == XFA_XDPPACKET_UNKNOWN) | 266 if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
263 return pProperty + iMid; | 267 return pProperty + iMid; |
264 return (dwPacket & pInfo->dwPackets) ? (pProperty + iMid) : NULL; | 268 return (dwPacket & pInfo->dwPackets) ? (pProperty + iMid) : NULL; |
265 } | 269 } |
266 const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_ELEMENT eElement, | 270 const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_Element eElement, |
267 XFA_ATTRIBUTE eAttribute, | 271 XFA_ATTRIBUTE eAttribute, |
268 XFA_ATTRIBUTETYPE eType) { | 272 XFA_ATTRIBUTETYPE eType) { |
269 int32_t iStart = 0, iEnd = g_iXFANotsureCount - 1; | 273 int32_t iStart = 0, iEnd = g_iXFANotsureCount - 1; |
270 do { | 274 do { |
271 int32_t iMid = (iStart + iEnd) / 2; | 275 int32_t iMid = (iStart + iEnd) / 2; |
272 const XFA_NOTSUREATTRIBUTE* pAttr = g_XFANotsureAttributes + iMid; | 276 const XFA_NOTSUREATTRIBUTE* pAttr = g_XFANotsureAttributes + iMid; |
273 if (eElement == pAttr->eElement) { | 277 if (eElement == pAttr->eElement) { |
274 if (pAttr->eAttribute == eAttribute) { | 278 if (pAttr->eAttribute == eAttribute) { |
275 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) { | 279 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) { |
276 return pAttr; | 280 return pAttr; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 319 } |
316 } else if (eElement < pAttr->eElement) { | 320 } else if (eElement < pAttr->eElement) { |
317 iEnd = iMid - 1; | 321 iEnd = iMid - 1; |
318 } else { | 322 } else { |
319 iStart = iMid + 1; | 323 iStart = iMid + 1; |
320 } | 324 } |
321 } while (iStart <= iEnd); | 325 } while (iStart <= iEnd); |
322 return NULL; | 326 return NULL; |
323 } | 327 } |
324 | 328 |
325 const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, | 329 const XFA_METHODINFO* XFA_GetMethodByName(XFA_Element eElement, |
326 const CFX_WideStringC& wsMethodName) { | 330 const CFX_WideStringC& wsMethodName) { |
327 if (wsMethodName.IsEmpty()) | 331 if (wsMethodName.IsEmpty()) |
328 return nullptr; | 332 return nullptr; |
329 | 333 |
330 int32_t iElementIndex = eElement; | 334 int32_t iElementIndex = static_cast<int32_t>(eElement); |
331 while (iElementIndex != -1) { | 335 while (iElementIndex != -1) { |
332 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; | 336 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; |
333 int32_t icount = scriptIndex->wMethodCount; | 337 int32_t icount = scriptIndex->wMethodCount; |
334 if (icount == 0) { | 338 if (icount == 0) { |
335 iElementIndex = scriptIndex->wParentIndex; | 339 iElementIndex = scriptIndex->wParentIndex; |
336 continue; | 340 continue; |
337 } | 341 } |
338 uint32_t uHash = FX_HashCode_GetW(wsMethodName, false); | 342 uint32_t uHash = FX_HashCode_GetW(wsMethodName, false); |
339 int32_t iStart = scriptIndex->wMethodStart; | 343 int32_t iStart = scriptIndex->wMethodStart; |
340 int32_t iEnd = iStart + icount - 1; | 344 int32_t iEnd = iStart + icount - 1; |
341 do { | 345 do { |
342 int32_t iMid = (iStart + iEnd) / 2; | 346 int32_t iMid = (iStart + iEnd) / 2; |
343 const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; | 347 const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; |
344 if (uHash == pInfo->uHash) { | 348 if (uHash == pInfo->uHash) { |
345 return pInfo; | 349 return pInfo; |
346 } else if (uHash < pInfo->uHash) { | 350 } else if (uHash < pInfo->uHash) { |
347 iEnd = iMid - 1; | 351 iEnd = iMid - 1; |
348 } else { | 352 } else { |
349 iStart = iMid + 1; | 353 iStart = iMid + 1; |
350 } | 354 } |
351 } while (iStart <= iEnd); | 355 } while (iStart <= iEnd); |
352 iElementIndex = scriptIndex->wParentIndex; | 356 iElementIndex = scriptIndex->wParentIndex; |
353 } | 357 } |
354 return NULL; | 358 return NULL; |
355 } | 359 } |
356 const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( | 360 const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( |
357 XFA_ELEMENT eElement, | 361 XFA_Element eElement, |
358 const CFX_WideStringC& wsAttributeName) { | 362 const CFX_WideStringC& wsAttributeName) { |
359 if (wsAttributeName.IsEmpty()) | 363 if (wsAttributeName.IsEmpty()) |
360 return nullptr; | 364 return nullptr; |
361 | 365 |
362 int32_t iElementIndex = eElement; | 366 int32_t iElementIndex = static_cast<int32_t>(eElement); |
363 while (iElementIndex != -1) { | 367 while (iElementIndex != -1) { |
364 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; | 368 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; |
365 int32_t icount = scriptIndex->wAttributeCount; | 369 int32_t icount = scriptIndex->wAttributeCount; |
366 if (icount == 0) { | 370 if (icount == 0) { |
367 iElementIndex = scriptIndex->wParentIndex; | 371 iElementIndex = scriptIndex->wParentIndex; |
368 continue; | 372 continue; |
369 } | 373 } |
370 uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false); | 374 uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false); |
371 int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; | 375 int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; |
372 do { | 376 do { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 return NULL; | 592 return NULL; |
589 } | 593 } |
590 | 594 |
591 void CXFA_WideTextRead::Lock() {} | 595 void CXFA_WideTextRead::Lock() {} |
592 | 596 |
593 void CXFA_WideTextRead::Unlock() {} | 597 void CXFA_WideTextRead::Unlock() {} |
594 | 598 |
595 CFX_WideString CXFA_WideTextRead::GetSrcText() const { | 599 CFX_WideString CXFA_WideTextRead::GetSrcText() const { |
596 return m_wsBuffer; | 600 return m_wsBuffer; |
597 } | 601 } |
OLD | NEW |