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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 return *(CXFA_Measurement*)pValue; | 173 return *(CXFA_Measurement*)pValue; |
174 } | 174 } |
175 return CXFA_Measurement(); | 175 return CXFA_Measurement(); |
176 } | 176 } |
177 | 177 |
178 XFA_Element XFA_GetElementTypeForName(const CFX_WideStringC& wsName) { | 178 XFA_Element XFA_GetElementTypeForName(const CFX_WideStringC& wsName) { |
179 if (wsName.IsEmpty()) | 179 if (wsName.IsEmpty()) |
180 return XFA_Element::Unknown; | 180 return XFA_Element::Unknown; |
181 | 181 |
182 uint32_t uHash = FX_HashCode_GetW(wsName, false); | 182 uint32_t uHash = FX_HashCode_GetW(wsName, false); |
183 int32_t iStart = 0; | 183 const XFA_ELEMENTINFO* pEnd = g_XFAElementData + g_iXFAElementCount; |
184 int32_t iEnd = g_iXFAElementCount - 1; | 184 auto pInfo = std::lower_bound(g_XFAElementData, pEnd, uHash, |
185 do { | 185 [](const XFA_ELEMENTINFO& info, uint32_t hash) { |
186 int32_t iMid = (iStart + iEnd) / 2; | 186 return info.uHash < hash; |
187 const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; | 187 }); |
188 if (uHash == pInfo->uHash) | 188 if (pInfo < pEnd && pInfo->uHash == uHash) |
189 return pInfo->eName; | 189 return pInfo->eName; |
190 if (uHash < pInfo->uHash) | |
191 iEnd = iMid - 1; | |
192 else | |
193 iStart = iMid + 1; | |
194 } while (iStart <= iEnd); | |
195 return XFA_Element::Unknown; | 190 return XFA_Element::Unknown; |
196 } | 191 } |
192 | |
197 const XFA_ELEMENTINFO* XFA_GetElementByID(XFA_Element eName) { | 193 const XFA_ELEMENTINFO* XFA_GetElementByID(XFA_Element eName) { |
198 return eName == XFA_Element::Unknown | 194 return eName == XFA_Element::Unknown |
199 ? nullptr | 195 ? nullptr |
200 : g_XFAElementData + static_cast<int32_t>(eName); | 196 : g_XFAElementData + static_cast<int32_t>(eName); |
201 } | 197 } |
202 | 198 |
203 const uint8_t* XFA_GetElementAttributes(XFA_Element eElement, int32_t& iCount) { | 199 const uint8_t* XFA_GetElementAttributes(XFA_Element eElement, int32_t& iCount) { |
204 if (eElement == XFA_Element::Unknown) | 200 if (eElement == XFA_Element::Unknown) |
205 return nullptr; | 201 return nullptr; |
206 | 202 |
(...skipping 24 matching lines...) Expand all Loading... | |
231 const XFA_PROPERTY* XFA_GetElementProperties(XFA_Element eElement, | 227 const XFA_PROPERTY* XFA_GetElementProperties(XFA_Element eElement, |
232 int32_t& iCount) { | 228 int32_t& iCount) { |
233 if (eElement == XFA_Element::Unknown) | 229 if (eElement == XFA_Element::Unknown) |
234 return nullptr; | 230 return nullptr; |
235 | 231 |
236 const XFA_ELEMENTHIERARCHY* pElement = | 232 const XFA_ELEMENTHIERARCHY* pElement = |
237 g_XFAElementPropertyIndex + static_cast<int32_t>(eElement); | 233 g_XFAElementPropertyIndex + static_cast<int32_t>(eElement); |
238 iCount = pElement->wCount; | 234 iCount = pElement->wCount; |
239 return g_XFAElementPropertyData + pElement->wStart; | 235 return g_XFAElementPropertyData + pElement->wStart; |
240 } | 236 } |
237 | |
241 const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_Element eElement, | 238 const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_Element eElement, |
242 XFA_Element eProperty, | 239 XFA_Element eProperty, |
243 uint32_t dwPacket) { | 240 uint32_t dwPacket) { |
244 int32_t iCount = 0; | 241 int32_t iCount = 0; |
245 const XFA_PROPERTY* pProperty = XFA_GetElementProperties(eElement, iCount); | 242 const XFA_PROPERTY* pProperties = XFA_GetElementProperties(eElement, iCount); |
246 if (!pProperty || iCount < 1) { | 243 if (!pProperties || iCount < 1) |
247 return nullptr; | 244 return nullptr; |
248 } | 245 |
249 int32_t iStart = 0, iEnd = iCount - 1, iMid; | 246 auto it = std::find_if(pProperties, pProperties + iCount, |
dsinclair
2016/06/30 03:40:16
I'm looking into generating some of these tables.
| |
250 do { | 247 [eProperty](const XFA_PROPERTY& prop) { |
251 iMid = (iStart + iEnd) / 2; | 248 return prop.eName == eProperty; |
252 XFA_Element eName = pProperty[iMid].eName; | 249 }); |
253 if (eProperty == eName) { | 250 if (it == pProperties + iCount) |
254 break; | |
255 } else if (eProperty < eName) { | |
256 iEnd = iMid - 1; | |
257 } else { | |
258 iStart = iMid + 1; | |
259 } | |
260 } while (iStart <= iEnd); | |
261 if (iStart > iEnd) { | |
262 return nullptr; | 251 return nullptr; |
263 } | 252 |
264 const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eProperty); | 253 const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eProperty); |
265 ASSERT(pInfo); | 254 ASSERT(pInfo); |
266 if (dwPacket == XFA_XDPPACKET_UNKNOWN) | 255 if (dwPacket != XFA_XDPPACKET_UNKNOWN && !(dwPacket & pInfo->dwPackets)) |
267 return pProperty + iMid; | 256 return nullptr; |
268 return (dwPacket & pInfo->dwPackets) ? (pProperty + iMid) : nullptr; | 257 return it; |
269 } | 258 } |
259 | |
270 const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_Element eElement, | 260 const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_Element eElement, |
271 XFA_ATTRIBUTE eAttribute, | 261 XFA_ATTRIBUTE eAttribute, |
272 XFA_ATTRIBUTETYPE eType) { | 262 XFA_ATTRIBUTETYPE eType) { |
273 int32_t iStart = 0, iEnd = g_iXFANotsureCount - 1; | 263 int32_t iStart = 0, iEnd = g_iXFANotsureCount - 1; |
274 do { | 264 do { |
275 int32_t iMid = (iStart + iEnd) / 2; | 265 int32_t iMid = (iStart + iEnd) / 2; |
276 const XFA_NOTSUREATTRIBUTE* pAttr = g_XFANotsureAttributes + iMid; | 266 const XFA_NOTSUREATTRIBUTE* pAttr = g_XFANotsureAttributes + iMid; |
277 if (eElement == pAttr->eElement) { | 267 if (eElement == pAttr->eElement) { |
278 if (pAttr->eAttribute == eAttribute) { | 268 if (pAttr->eAttribute == eAttribute) { |
279 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) { | 269 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) { |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 return nullptr; | 582 return nullptr; |
593 } | 583 } |
594 | 584 |
595 void CXFA_WideTextRead::Lock() {} | 585 void CXFA_WideTextRead::Lock() {} |
596 | 586 |
597 void CXFA_WideTextRead::Unlock() {} | 587 void CXFA_WideTextRead::Unlock() {} |
598 | 588 |
599 CFX_WideString CXFA_WideTextRead::GetSrcText() const { | 589 CFX_WideString CXFA_WideTextRead::GetSrcText() const { |
600 return m_wsBuffer; | 590 return m_wsBuffer; |
601 } | 591 } |
OLD | NEW |