Chromium Code Reviews| 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_utils.h" | 7 #include "xfa/fxfa/parser/xfa_utils.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fde/xml/fde_xml_imp.h" | 10 #include "xfa/fde/xml/fde_xml_imp.h" |
| 11 #include "xfa/fxfa/parser/cxfa_measurement.h" | |
| 12 #include "xfa/fxfa/parser/xfa_basic_data.h" | |
| 11 #include "xfa/fxfa/parser/xfa_doclayout.h" | 13 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 12 #include "xfa/fxfa/parser/xfa_document.h" | 14 #include "xfa/fxfa/parser/xfa_document.h" |
| 13 #include "xfa/fxfa/parser/xfa_localemgr.h" | 15 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 14 #include "xfa/fxfa/parser/xfa_localevalue.h" | 16 #include "xfa/fxfa/parser/xfa_localevalue.h" |
| 15 #include "xfa/fxfa/parser/xfa_object.h" | 17 #include "xfa/fxfa/parser/xfa_object.h" |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 const FX_DOUBLE fraction_scales[] = {0.1, | 21 const FX_DOUBLE fraction_scales[] = {0.1, |
| 20 0.01, | 22 0.01, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 default: | 197 default: |
| 196 break; | 198 break; |
| 197 } | 199 } |
| 198 for (CFDE_XMLNode* pChildXML = | 200 for (CFDE_XMLNode* pChildXML = |
| 199 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); | 201 pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 200 pChildXML; | 202 pChildXML; |
| 201 pChildXML = pChildXML->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 203 pChildXML = pChildXML->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 202 XFA_GetPlainTextFromRichText(pChildXML, wsPlainText); | 204 XFA_GetPlainTextFromRichText(pChildXML, wsPlainText); |
| 203 } | 205 } |
| 204 } | 206 } |
| 207 | |
| 205 FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode) { | 208 FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode) { |
| 206 FX_BOOL bRet = FALSE; | 209 FX_BOOL bRet = FALSE; |
| 207 if (!pFieldNode) { | 210 if (!pFieldNode) |
| 208 return bRet; | 211 return bRet; |
| 209 } | 212 |
| 210 CXFA_Node* pUIChild = pFieldNode->GetChild(0, XFA_Element::Ui); | 213 CXFA_Node* pUIChild = pFieldNode->GetChild(0, XFA_Element::Ui); |
| 211 if (pUIChild) { | 214 if (pUIChild) { |
| 212 CXFA_Node* pFirstChild = pUIChild->GetNodeItem(XFA_NODEITEM_FirstChild); | 215 CXFA_Node* pFirstChild = pUIChild->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 213 if (pFirstChild && | 216 if (pFirstChild && |
| 214 pFirstChild->GetElementType() == XFA_Element::ChoiceList) { | 217 pFirstChild->GetElementType() == XFA_Element::ChoiceList) { |
| 215 bRet = pFirstChild->GetEnum(XFA_ATTRIBUTE_Open) == | 218 bRet = pFirstChild->GetEnum(XFA_ATTRIBUTE_Open) == |
| 216 XFA_ATTRIBUTEENUM_MultiSelect; | 219 XFA_ATTRIBUTEENUM_MultiSelect; |
| 217 } | 220 } |
| 218 } | 221 } |
| 219 return bRet; | 222 return bRet; |
| 220 } | 223 } |
| 221 | 224 |
| 222 FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { | 225 FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { |
| 223 CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal); | 226 CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal); |
| 224 return WideStringToDouble(wsValue); | 227 return WideStringToDouble(wsValue); |
| 225 } | 228 } |
| 226 | 229 |
| 227 int32_t XFA_MapRotation(int32_t nRotation) { | 230 int32_t XFA_MapRotation(int32_t nRotation) { |
| 228 nRotation = nRotation % 360; | 231 nRotation = nRotation % 360; |
| 229 nRotation = nRotation < 0 ? nRotation + 360 : nRotation; | 232 nRotation = nRotation < 0 ? nRotation + 360 : nRotation; |
| 230 return nRotation; | 233 return nRotation; |
| 231 } | 234 } |
| 235 | |
| 236 const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( | |
|
Lei Zhang
2016/07/20 20:54:33
This looks a lot like GetMethodByName() in xfa/fxf
dsinclair
2016/07/21 13:34:24
Yes, and the ones below as well, it's a very simil
| |
| 237 XFA_Element eElement, | |
| 238 const CFX_WideStringC& wsAttributeName) { | |
| 239 if (wsAttributeName.IsEmpty()) | |
| 240 return nullptr; | |
| 241 | |
| 242 int32_t iElementIndex = static_cast<int32_t>(eElement); | |
| 243 while (iElementIndex != -1) { | |
| 244 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; | |
| 245 int32_t icount = scriptIndex->wAttributeCount; | |
| 246 if (icount == 0) { | |
| 247 iElementIndex = scriptIndex->wParentIndex; | |
| 248 continue; | |
| 249 } | |
| 250 uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false); | |
| 251 int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; | |
| 252 do { | |
| 253 int32_t iMid = (iStart + iEnd) / 2; | |
| 254 const XFA_SCRIPTATTRIBUTEINFO* pInfo = g_SomAttributeData + iMid; | |
| 255 if (uHash == pInfo->uHash) | |
| 256 return pInfo; | |
| 257 if (uHash < pInfo->uHash) | |
| 258 iEnd = iMid - 1; | |
| 259 else | |
| 260 iStart = iMid + 1; | |
| 261 } while (iStart <= iEnd); | |
| 262 iElementIndex = scriptIndex->wParentIndex; | |
| 263 } | |
| 264 return nullptr; | |
| 265 } | |
| 266 | |
| 267 const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_Element eElement, | |
| 268 XFA_ATTRIBUTE eAttribute, | |
| 269 XFA_ATTRIBUTETYPE eType) { | |
| 270 int32_t iStart = 0, iEnd = g_iXFANotsureCount - 1; | |
| 271 do { | |
| 272 int32_t iMid = (iStart + iEnd) / 2; | |
| 273 const XFA_NOTSUREATTRIBUTE* pAttr = g_XFANotsureAttributes + iMid; | |
| 274 if (eElement == pAttr->eElement) { | |
| 275 if (pAttr->eAttribute == eAttribute) { | |
| 276 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) | |
| 277 return pAttr; | |
| 278 return nullptr; | |
| 279 } | |
| 280 int32_t iBefore = iMid - 1; | |
| 281 if (iBefore >= 0) { | |
| 282 pAttr = g_XFANotsureAttributes + iBefore; | |
| 283 while (eElement == pAttr->eElement) { | |
| 284 if (pAttr->eAttribute == eAttribute) { | |
| 285 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) | |
| 286 return pAttr; | |
| 287 return nullptr; | |
| 288 } | |
| 289 iBefore--; | |
| 290 if (iBefore < 0) | |
| 291 break; | |
| 292 | |
| 293 pAttr = g_XFANotsureAttributes + iBefore; | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 int32_t iAfter = iMid + 1; | |
| 298 if (iAfter <= g_iXFANotsureCount - 1) { | |
| 299 pAttr = g_XFANotsureAttributes + iAfter; | |
| 300 while (eElement == pAttr->eElement) { | |
| 301 if (pAttr->eAttribute == eAttribute) { | |
| 302 if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType) | |
| 303 return pAttr; | |
| 304 return nullptr; | |
| 305 } | |
| 306 iAfter++; | |
| 307 if (iAfter > g_iXFANotsureCount - 1) | |
| 308 break; | |
| 309 | |
| 310 pAttr = g_XFANotsureAttributes + iAfter; | |
| 311 } | |
| 312 } | |
| 313 return nullptr; | |
| 314 } | |
| 315 | |
| 316 if (eElement < pAttr->eElement) | |
| 317 iEnd = iMid - 1; | |
| 318 else | |
| 319 iStart = iMid + 1; | |
| 320 } while (iStart <= iEnd); | |
| 321 return nullptr; | |
| 322 } | |
| 323 | |
| 324 const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_Element eElement, | |
| 325 XFA_Element eProperty, | |
| 326 uint32_t dwPacket) { | |
| 327 int32_t iCount = 0; | |
| 328 const XFA_PROPERTY* pProperties = XFA_GetElementProperties(eElement, iCount); | |
| 329 if (!pProperties || iCount < 1) | |
| 330 return nullptr; | |
| 331 | |
| 332 auto it = std::find_if(pProperties, pProperties + iCount, | |
| 333 [eProperty](const XFA_PROPERTY& prop) { | |
| 334 return prop.eName == eProperty; | |
| 335 }); | |
| 336 if (it == pProperties + iCount) | |
| 337 return nullptr; | |
| 338 | |
| 339 const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eProperty); | |
| 340 ASSERT(pInfo); | |
| 341 if (dwPacket != XFA_XDPPACKET_UNKNOWN && !(dwPacket & pInfo->dwPackets)) | |
| 342 return nullptr; | |
| 343 return it; | |
| 344 } | |
| 345 | |
| 346 const XFA_PROPERTY* XFA_GetElementProperties(XFA_Element eElement, | |
| 347 int32_t& iCount) { | |
| 348 if (eElement == XFA_Element::Unknown) | |
| 349 return nullptr; | |
| 350 | |
| 351 const XFA_ELEMENTHIERARCHY* pElement = | |
| 352 g_XFAElementPropertyIndex + static_cast<int32_t>(eElement); | |
| 353 iCount = pElement->wCount; | |
| 354 return g_XFAElementPropertyData + pElement->wStart; | |
| 355 } | |
| 356 | |
| 357 const uint8_t* XFA_GetElementAttributes(XFA_Element eElement, int32_t& iCount) { | |
| 358 if (eElement == XFA_Element::Unknown) | |
| 359 return nullptr; | |
| 360 | |
| 361 const XFA_ELEMENTHIERARCHY* pElement = | |
| 362 g_XFAElementAttributeIndex + static_cast<int32_t>(eElement); | |
| 363 iCount = pElement->wCount; | |
| 364 return g_XFAElementAttributeData + pElement->wStart; | |
| 365 } | |
| 366 | |
| 367 const XFA_ELEMENTINFO* XFA_GetElementByID(XFA_Element eName) { | |
| 368 return eName == XFA_Element::Unknown | |
|
Lei Zhang
2016/07/20 20:54:33
!= and reverse the two return values?
dsinclair
2016/07/21 13:34:24
Done.
| |
| 369 ? nullptr | |
| 370 : g_XFAElementData + static_cast<int32_t>(eName); | |
| 371 } | |
| 372 | |
| 373 XFA_Element XFA_GetElementTypeForName(const CFX_WideStringC& wsName) { | |
| 374 if (wsName.IsEmpty()) | |
| 375 return XFA_Element::Unknown; | |
| 376 | |
| 377 uint32_t uHash = FX_HashCode_GetW(wsName, false); | |
| 378 const XFA_ELEMENTINFO* pEnd = g_XFAElementData + g_iXFAElementCount; | |
| 379 auto pInfo = std::lower_bound(g_XFAElementData, pEnd, uHash, | |
| 380 [](const XFA_ELEMENTINFO& info, uint32_t hash) { | |
| 381 return info.uHash < hash; | |
| 382 }); | |
| 383 if (pInfo < pEnd && pInfo->uHash == uHash) | |
| 384 return pInfo->eName; | |
| 385 return XFA_Element::Unknown; | |
| 386 } | |
| 387 | |
| 388 CXFA_Measurement XFA_GetAttributeDefaultValue_Measure(XFA_Element eElement, | |
| 389 XFA_ATTRIBUTE eAttribute, | |
| 390 uint32_t dwPacket) { | |
| 391 void* pValue; | |
| 392 if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, | |
| 393 XFA_ATTRIBUTETYPE_Measure, dwPacket)) { | |
| 394 return *(CXFA_Measurement*)pValue; | |
| 395 } | |
| 396 return CXFA_Measurement(); | |
| 397 } | |
| 398 | |
| 399 FX_BOOL XFA_GetAttributeDefaultValue(void*& pValue, | |
| 400 XFA_Element eElement, | |
| 401 XFA_ATTRIBUTE eAttribute, | |
| 402 XFA_ATTRIBUTETYPE eType, | |
| 403 uint32_t dwPacket) { | |
| 404 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); | |
| 405 if (!pInfo) | |
| 406 return FALSE; | |
| 407 if (dwPacket && (dwPacket & pInfo->dwPackets) == 0) | |
| 408 return FALSE; | |
| 409 if (pInfo->eType == eType) { | |
| 410 pValue = pInfo->pDefValue; | |
| 411 return TRUE; | |
| 412 } | |
| 413 if (pInfo->eType == XFA_ATTRIBUTETYPE_NOTSURE) { | |
| 414 const XFA_NOTSUREATTRIBUTE* pAttr = | |
| 415 XFA_GetNotsureAttribute(eElement, eAttribute, eType); | |
| 416 if (pAttr) { | |
| 417 pValue = pAttr->pValue; | |
| 418 return TRUE; | |
| 419 } | |
| 420 } | |
| 421 return FALSE; | |
| 422 } | |
| 423 | |
| 424 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { | |
| 425 if (wsName.IsEmpty()) | |
| 426 return nullptr; | |
| 427 | |
| 428 uint32_t uHash = FX_HashCode_GetW(wsName, false); | |
| 429 int32_t iStart = 0; | |
| 430 int32_t iEnd = g_iXFAAttributeCount - 1; | |
| 431 do { | |
| 432 int32_t iMid = (iStart + iEnd) / 2; | |
| 433 const XFA_ATTRIBUTEINFO* pInfo = g_XFAAttributeData + iMid; | |
| 434 if (uHash == pInfo->uHash) | |
| 435 return pInfo; | |
| 436 if (uHash < pInfo->uHash) | |
| 437 iEnd = iMid - 1; | |
| 438 else | |
| 439 iStart = iMid + 1; | |
| 440 } while (iStart <= iEnd); | |
| 441 return nullptr; | |
| 442 } | |
| 443 | |
| 444 const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { | |
| 445 return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) | |
| 446 : nullptr; | |
| 447 } | |
| 448 | |
| 449 const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( | |
| 450 const CFX_WideStringC& wsName) { | |
| 451 if (wsName.IsEmpty()) | |
| 452 return nullptr; | |
| 453 | |
| 454 uint32_t uHash = FX_HashCode_GetW(wsName, false); | |
| 455 int32_t iStart = 0; | |
| 456 int32_t iEnd = g_iXFAEnumCount - 1; | |
| 457 do { | |
| 458 int32_t iMid = (iStart + iEnd) / 2; | |
| 459 const XFA_ATTRIBUTEENUMINFO* pInfo = g_XFAEnumData + iMid; | |
| 460 if (uHash == pInfo->uHash) | |
| 461 return pInfo; | |
| 462 if (uHash < pInfo->uHash) | |
| 463 iEnd = iMid - 1; | |
| 464 else | |
| 465 iStart = iMid + 1; | |
| 466 } while (iStart <= iEnd); | |
| 467 return nullptr; | |
| 468 } | |
| 469 | |
| 470 const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PACKET ePacket) { | |
| 471 return g_XFAPacketData + ePacket; | |
| 472 } | |
| 473 | |
| 474 const XFA_PACKETINFO* XFA_GetPacketByID(uint32_t dwPacket) { | |
| 475 int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1; | |
| 476 do { | |
| 477 int32_t iMid = (iStart + iEnd) / 2; | |
| 478 uint32_t dwFind = (g_XFAPacketData + iMid)->eName; | |
| 479 if (dwPacket == dwFind) | |
| 480 return g_XFAPacketData + iMid; | |
| 481 if (dwPacket < dwFind) | |
| 482 iEnd = iMid - 1; | |
| 483 else | |
| 484 iStart = iMid + 1; | |
| 485 } while (iStart <= iEnd); | |
| 486 return nullptr; | |
| 487 } | |
| OLD | NEW |