OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
14 #include "core/fxcrt/include/fx_safe_types.h" | 14 #include "core/fxcrt/include/fx_safe_types.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 bool CanReadFromBitStream(const CFX_BitStream* hStream, | 18 bool CanReadFromBitStream(const CFX_BitStream* hStream, |
19 const FX_SAFE_UINT32& num_bits) { | 19 const FX_SAFE_UINT32& num_bits) { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // The object number of remaining pages starts from 1. | 355 // The object number of remaining pages starts from 1. |
356 dwObjNum = 1; | 356 dwObjNum = 1; |
357 for (int i = 0; i < index; ++i) { | 357 for (int i = 0; i < index; ++i) { |
358 if (i == nFirstPageNum) | 358 if (i == nFirstPageNum) |
359 continue; | 359 continue; |
360 dwObjNum += m_dwDeltaNObjsArray[i]; | 360 dwObjNum += m_dwDeltaNObjsArray[i]; |
361 } | 361 } |
362 return TRUE; | 362 return TRUE; |
363 } | 363 } |
364 | 364 |
365 IPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( | 365 CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( |
366 int index, | 366 int index, |
367 IPDF_DataAvail::DownloadHints* pHints) { | 367 CPDF_DataAvail::DownloadHints* pHints) { |
368 if (!m_pLinearizedDict || !pHints) | 368 if (!m_pLinearizedDict || !pHints) |
369 return IPDF_DataAvail::DataError; | 369 return CPDF_DataAvail::DataError; |
370 | 370 |
371 CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetDirectObjectBy("P"); | 371 CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetDirectObjectBy("P"); |
372 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0; | 372 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0; |
373 if (index == nFirstAvailPage) | 373 if (index == nFirstAvailPage) |
374 return IPDF_DataAvail::DataAvailable; | 374 return CPDF_DataAvail::DataAvailable; |
375 | 375 |
376 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray); | 376 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray); |
377 // If two pages have the same offset, it should be treated as an error. | 377 // If two pages have the same offset, it should be treated as an error. |
378 if (!dwLength) | 378 if (!dwLength) |
379 return IPDF_DataAvail::DataError; | 379 return CPDF_DataAvail::DataError; |
380 | 380 |
381 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) | 381 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) |
382 return IPDF_DataAvail::DataNotAvailable; | 382 return CPDF_DataAvail::DataNotAvailable; |
383 | 383 |
384 // Download data of shared objects in the page. | 384 // Download data of shared objects in the page. |
385 uint32_t offset = 0; | 385 uint32_t offset = 0; |
386 for (int i = 0; i < index; ++i) | 386 for (int i = 0; i < index; ++i) |
387 offset += m_dwNSharedObjsArray[i]; | 387 offset += m_dwNSharedObjsArray[i]; |
388 | 388 |
389 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectBy("O"); | 389 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectBy("O"); |
390 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; | 390 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; |
391 if (nFirstPageObjNum < 0) | 391 if (nFirstPageObjNum < 0) |
392 return IPDF_DataAvail::DataError; | 392 return CPDF_DataAvail::DataError; |
393 | 393 |
394 uint32_t dwIndex = 0; | 394 uint32_t dwIndex = 0; |
395 uint32_t dwObjNum = 0; | 395 uint32_t dwObjNum = 0; |
396 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { | 396 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { |
397 dwIndex = m_dwIdentifierArray[offset + j]; | 397 dwIndex = m_dwIdentifierArray[offset + j]; |
398 if (dwIndex >= static_cast<uint32_t>(m_dwSharedObjNumArray.GetSize())) | 398 if (dwIndex >= static_cast<uint32_t>(m_dwSharedObjNumArray.GetSize())) |
399 return IPDF_DataAvail::DataNotAvailable; | 399 return CPDF_DataAvail::DataNotAvailable; |
400 | 400 |
401 dwObjNum = m_dwSharedObjNumArray[dwIndex]; | 401 dwObjNum = m_dwSharedObjNumArray[dwIndex]; |
402 if (dwObjNum >= static_cast<uint32_t>(nFirstPageObjNum) && | 402 if (dwObjNum >= static_cast<uint32_t>(nFirstPageObjNum) && |
403 dwObjNum < | 403 dwObjNum < |
404 static_cast<uint32_t>(nFirstPageObjNum) + m_nFirstPageSharedObjs) { | 404 static_cast<uint32_t>(nFirstPageObjNum) + m_nFirstPageSharedObjs) { |
405 continue; | 405 continue; |
406 } | 406 } |
407 | 407 |
408 dwLength = GetItemLength(dwIndex, m_szSharedObjOffsetArray); | 408 dwLength = GetItemLength(dwIndex, m_szSharedObjOffsetArray); |
409 // If two objects have the same offset, it should be treated as an error. | 409 // If two objects have the same offset, it should be treated as an error. |
410 if (!dwLength) | 410 if (!dwLength) |
411 return IPDF_DataAvail::DataError; | 411 return CPDF_DataAvail::DataError; |
412 | 412 |
413 if (!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength, | 413 if (!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength, |
414 pHints)) { | 414 pHints)) { |
415 return IPDF_DataAvail::DataNotAvailable; | 415 return CPDF_DataAvail::DataNotAvailable; |
416 } | 416 } |
417 } | 417 } |
418 return IPDF_DataAvail::DataAvailable; | 418 return CPDF_DataAvail::DataAvailable; |
419 } | 419 } |
420 | 420 |
421 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { | 421 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { |
422 if (!pHintStream || !m_pLinearizedDict) | 422 if (!pHintStream || !m_pLinearizedDict) |
423 return FALSE; | 423 return FALSE; |
424 | 424 |
425 CPDF_Dictionary* pDict = pHintStream->GetDict(); | 425 CPDF_Dictionary* pDict = pHintStream->GetDict(); |
426 CPDF_Object* pOffset = pDict ? pDict->GetObjectBy("S") : nullptr; | 426 CPDF_Object* pOffset = pDict ? pDict->GetObjectBy("S") : nullptr; |
427 if (!pOffset || !pOffset->IsNumber()) | 427 if (!pOffset || !pOffset->IsNumber()) |
428 return FALSE; | 428 return FALSE; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 470 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
471 if (!pRange) | 471 if (!pRange) |
472 return -1; | 472 return -1; |
473 | 473 |
474 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(1); | 474 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(1); |
475 if (!pStreamLen) | 475 if (!pStreamLen) |
476 return -1; | 476 return -1; |
477 | 477 |
478 return pStreamLen->GetInteger(); | 478 return pStreamLen->GetInteger(); |
479 } | 479 } |
OLD | NEW |