Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp

Issue 1841173002: Rename GetElementValue() to GetDirectObject{By,At}(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix test name Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/cpdf_data_avail.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // Item 12: The number of bits needed to represent the numerator of 96 // Item 12: The number of bits needed to represent the numerator of
97 // the fractional position for each shared object reference. For each 97 // the fractional position for each shared object reference. For each
98 // shared object referenced from a page, there is an indication of 98 // shared object referenced from a page, there is an indication of
99 // where in the page's content stream the object is first referenced. 99 // where in the page's content stream the object is first referenced.
100 uint32_t dwSharedNumeratorBits = hStream->GetBits(16); 100 uint32_t dwSharedNumeratorBits = hStream->GetBits(16);
101 101
102 // Item 13: Skip Item 13 which has 16 bits. 102 // Item 13: Skip Item 13 which has 16 bits.
103 hStream->SkipBits(16); 103 hStream->SkipBits(16);
104 104
105 CPDF_Object* pPageNum = m_pLinearizedDict->GetElementValue("N"); 105 CPDF_Object* pPageNum = m_pLinearizedDict->GetDirectObjectBy("N");
106 int nPages = pPageNum ? pPageNum->GetInteger() : 0; 106 int nPages = pPageNum ? pPageNum->GetInteger() : 0;
107 if (nPages < 1) 107 if (nPages < 1)
108 return FALSE; 108 return FALSE;
109 109
110 FX_SAFE_DWORD required_bits = dwDeltaObjectsBits; 110 FX_SAFE_DWORD required_bits = dwDeltaObjectsBits;
111 required_bits *= pdfium::base::checked_cast<uint32_t>(nPages); 111 required_bits *= pdfium::base::checked_cast<uint32_t>(nPages);
112 if (!CanReadFromBitStream(hStream, required_bits)) 112 if (!CanReadFromBitStream(hStream, required_bits))
113 return FALSE; 113 return FALSE;
114 114
115 for (int i = 0; i < nPages; ++i) { 115 for (int i = 0; i < nPages; ++i) {
(...skipping 12 matching lines...) Expand all
128 128
129 CFX_ArrayTemplate<uint32_t> dwPageLenArray; 129 CFX_ArrayTemplate<uint32_t> dwPageLenArray;
130 for (int i = 0; i < nPages; ++i) { 130 for (int i = 0; i < nPages; ++i) {
131 FX_SAFE_DWORD safePageLen = hStream->GetBits(dwDeltaPageLenBits); 131 FX_SAFE_DWORD safePageLen = hStream->GetBits(dwDeltaPageLenBits);
132 safePageLen += dwPageLeastLen; 132 safePageLen += dwPageLeastLen;
133 if (!safePageLen.IsValid()) 133 if (!safePageLen.IsValid())
134 return FALSE; 134 return FALSE;
135 dwPageLenArray.Add(safePageLen.ValueOrDie()); 135 dwPageLenArray.Add(safePageLen.ValueOrDie());
136 } 136 }
137 137
138 CPDF_Object* pOffsetE = m_pLinearizedDict->GetElementValue("E"); 138 CPDF_Object* pOffsetE = m_pLinearizedDict->GetDirectObjectBy("E");
139 int nOffsetE = pOffsetE ? pOffsetE->GetInteger() : -1; 139 int nOffsetE = pOffsetE ? pOffsetE->GetInteger() : -1;
140 if (nOffsetE < 0) 140 if (nOffsetE < 0)
141 return FALSE; 141 return FALSE;
142 142
143 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetElementValue("P"); 143 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetDirectObjectBy("P");
144 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0; 144 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0;
145 for (int i = 0; i < nPages; ++i) { 145 for (int i = 0; i < nPages; ++i) {
146 if (i == nFirstPageNum) { 146 if (i == nFirstPageNum) {
147 m_szPageOffsetArray.push_back(m_szFirstPageObjOffset); 147 m_szPageOffsetArray.push_back(m_szFirstPageObjOffset);
148 } else if (i == nFirstPageNum + 1) { 148 } else if (i == nFirstPageNum + 1) {
149 if (i == 1) { 149 if (i == 1) {
150 m_szPageOffsetArray.push_back(nOffsetE); 150 m_szPageOffsetArray.push_back(nOffsetE);
151 } else { 151 } else {
152 m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 2] + 152 m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 2] +
153 dwPageLenArray[i - 2]); 153 dwPageLenArray[i - 2]);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // Item 5: The number of bits needed to represent the greatest number of 249 // Item 5: The number of bits needed to represent the greatest number of
250 // objects in a shared object group. Skipped. 250 // objects in a shared object group. Skipped.
251 hStream->SkipBits(16); 251 hStream->SkipBits(16);
252 252
253 // Item 6: The least length of a shared object group in bytes. 253 // Item 6: The least length of a shared object group in bytes.
254 uint32_t dwGroupLeastLen = hStream->GetBits(32); 254 uint32_t dwGroupLeastLen = hStream->GetBits(32);
255 255
256 // Item 7: The number of bits needed to represent the difference between the 256 // Item 7: The number of bits needed to represent the difference between the
257 // greatest and least length of a shared object group, in bytes. 257 // greatest and least length of a shared object group, in bytes.
258 uint32_t dwDeltaGroupLen = hStream->GetBits(16); 258 uint32_t dwDeltaGroupLen = hStream->GetBits(16);
259 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); 259 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectBy("O");
260 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; 260 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1;
261 if (nFirstPageObjNum < 0) 261 if (nFirstPageObjNum < 0)
262 return FALSE; 262 return FALSE;
263 263
264 uint32_t dwPrevObjLen = 0; 264 uint32_t dwPrevObjLen = 0;
265 uint32_t dwCurObjLen = 0; 265 uint32_t dwCurObjLen = 0;
266 FX_SAFE_DWORD required_bits = dwSharedObjTotal; 266 FX_SAFE_DWORD required_bits = dwSharedObjTotal;
267 required_bits *= dwDeltaGroupLen; 267 required_bits *= dwDeltaGroupLen;
268 if (!CanReadFromBitStream(hStream, required_bits)) 268 if (!CanReadFromBitStream(hStream, required_bits))
269 return FALSE; 269 return FALSE;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 FX_BOOL CPDF_HintTables::GetPagePos(int index, 324 FX_BOOL CPDF_HintTables::GetPagePos(int index,
325 FX_FILESIZE& szPageStartPos, 325 FX_FILESIZE& szPageStartPos,
326 FX_FILESIZE& szPageLength, 326 FX_FILESIZE& szPageLength,
327 uint32_t& dwObjNum) { 327 uint32_t& dwObjNum) {
328 if (!m_pLinearizedDict) 328 if (!m_pLinearizedDict)
329 return FALSE; 329 return FALSE;
330 330
331 szPageStartPos = m_szPageOffsetArray[index]; 331 szPageStartPos = m_szPageOffsetArray[index];
332 szPageLength = GetItemLength(index, m_szPageOffsetArray); 332 szPageLength = GetItemLength(index, m_szPageOffsetArray);
333 333
334 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetElementValue("P"); 334 CPDF_Object* pFirstPageNum = m_pLinearizedDict->GetDirectObjectBy("P");
335 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0; 335 int nFirstPageNum = pFirstPageNum ? pFirstPageNum->GetInteger() : 0;
336 336
337 CPDF_Object* pFirstPageObjNum = m_pLinearizedDict->GetElementValue("O"); 337 CPDF_Object* pFirstPageObjNum = m_pLinearizedDict->GetDirectObjectBy("O");
338 if (!pFirstPageObjNum) 338 if (!pFirstPageObjNum)
339 return FALSE; 339 return FALSE;
340 340
341 int nFirstPageObjNum = pFirstPageObjNum->GetInteger(); 341 int nFirstPageObjNum = pFirstPageObjNum->GetInteger();
342 if (index == nFirstPageNum) { 342 if (index == nFirstPageNum) {
343 dwObjNum = nFirstPageObjNum; 343 dwObjNum = nFirstPageObjNum;
344 return TRUE; 344 return TRUE;
345 } 345 }
346 346
347 // The object number of remaining pages starts from 1. 347 // The object number of remaining pages starts from 1.
348 dwObjNum = 1; 348 dwObjNum = 1;
349 for (int i = 0; i < index; ++i) { 349 for (int i = 0; i < index; ++i) {
350 if (i == nFirstPageNum) 350 if (i == nFirstPageNum)
351 continue; 351 continue;
352 dwObjNum += m_dwDeltaNObjsArray[i]; 352 dwObjNum += m_dwDeltaNObjsArray[i];
353 } 353 }
354 return TRUE; 354 return TRUE;
355 } 355 }
356 356
357 IPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( 357 IPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(
358 int index, 358 int index,
359 IPDF_DataAvail::DownloadHints* pHints) { 359 IPDF_DataAvail::DownloadHints* pHints) {
360 if (!m_pLinearizedDict || !pHints) 360 if (!m_pLinearizedDict || !pHints)
361 return IPDF_DataAvail::DataError; 361 return IPDF_DataAvail::DataError;
362 362
363 CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetElementValue("P"); 363 CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetDirectObjectBy("P");
364 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0; 364 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0;
365 if (index == nFirstAvailPage) 365 if (index == nFirstAvailPage)
366 return IPDF_DataAvail::DataAvailable; 366 return IPDF_DataAvail::DataAvailable;
367 367
368 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray); 368 uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray);
369 // If two pages have the same offset, it should be treated as an error. 369 // If two pages have the same offset, it should be treated as an error.
370 if (!dwLength) 370 if (!dwLength)
371 return IPDF_DataAvail::DataError; 371 return IPDF_DataAvail::DataError;
372 372
373 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) 373 if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints))
374 return IPDF_DataAvail::DataNotAvailable; 374 return IPDF_DataAvail::DataNotAvailable;
375 375
376 // Download data of shared objects in the page. 376 // Download data of shared objects in the page.
377 uint32_t offset = 0; 377 uint32_t offset = 0;
378 for (int i = 0; i < index; ++i) 378 for (int i = 0; i < index; ++i)
379 offset += m_dwNSharedObjsArray[i]; 379 offset += m_dwNSharedObjsArray[i];
380 380
381 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetElementValue("O"); 381 CPDF_Object* pFirstPageObj = m_pLinearizedDict->GetDirectObjectBy("O");
382 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; 382 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1;
383 if (nFirstPageObjNum < 0) 383 if (nFirstPageObjNum < 0)
384 return IPDF_DataAvail::DataError; 384 return IPDF_DataAvail::DataError;
385 385
386 uint32_t dwIndex = 0; 386 uint32_t dwIndex = 0;
387 uint32_t dwObjNum = 0; 387 uint32_t dwObjNum = 0;
388 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) { 388 for (uint32_t j = 0; j < m_dwNSharedObjsArray[index]; ++j) {
389 dwIndex = m_dwIdentifierArray[offset + j]; 389 dwIndex = m_dwIdentifierArray[offset + j];
390 if (dwIndex >= m_dwSharedObjNumArray.GetSize()) 390 if (dwIndex >= m_dwSharedObjNumArray.GetSize())
391 return IPDF_DataAvail::DataNotAvailable; 391 return IPDF_DataAvail::DataNotAvailable;
(...skipping 15 matching lines...) Expand all
407 } 407 }
408 } 408 }
409 return IPDF_DataAvail::DataAvailable; 409 return IPDF_DataAvail::DataAvailable;
410 } 410 }
411 411
412 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { 412 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) {
413 if (!pHintStream || !m_pLinearizedDict) 413 if (!pHintStream || !m_pLinearizedDict)
414 return FALSE; 414 return FALSE;
415 415
416 CPDF_Dictionary* pDict = pHintStream->GetDict(); 416 CPDF_Dictionary* pDict = pHintStream->GetDict();
417 CPDF_Object* pOffset = pDict ? pDict->GetElement("S") : nullptr; 417 CPDF_Object* pOffset = pDict ? pDict->GetObjectBy("S") : nullptr;
418 if (!pOffset || !pOffset->IsNumber()) 418 if (!pOffset || !pOffset->IsNumber())
419 return FALSE; 419 return FALSE;
420 420
421 int shared_hint_table_offset = pOffset->GetInteger(); 421 int shared_hint_table_offset = pOffset->GetInteger();
422 CPDF_StreamAcc acc; 422 CPDF_StreamAcc acc;
423 acc.LoadAllData(pHintStream); 423 acc.LoadAllData(pHintStream);
424 424
425 uint32_t size = acc.GetSize(); 425 uint32_t size = acc.GetSize();
426 // The header section of page offset hint table is 36 bytes. 426 // The header section of page offset hint table is 36 bytes.
427 // The header section of shared object hint table is 24 bytes. 427 // The header section of shared object hint table is 24 bytes.
(...skipping 12 matching lines...) Expand all
440 } 440 }
441 441
442 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { 442 int CPDF_HintTables::ReadPrimaryHintStreamOffset() const {
443 if (!m_pLinearizedDict) 443 if (!m_pLinearizedDict)
444 return -1; 444 return -1;
445 445
446 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); 446 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H");
447 if (!pRange) 447 if (!pRange)
448 return -1; 448 return -1;
449 449
450 CPDF_Object* pStreamOffset = pRange->GetElementValue(0); 450 CPDF_Object* pStreamOffset = pRange->GetDirectObjectAt(0);
451 if (!pStreamOffset) 451 if (!pStreamOffset)
452 return -1; 452 return -1;
453 453
454 return pStreamOffset->GetInteger(); 454 return pStreamOffset->GetInteger();
455 } 455 }
456 456
457 int CPDF_HintTables::ReadPrimaryHintStreamLength() const { 457 int CPDF_HintTables::ReadPrimaryHintStreamLength() const {
458 if (!m_pLinearizedDict) 458 if (!m_pLinearizedDict)
459 return -1; 459 return -1;
460 460
461 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); 461 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H");
462 if (!pRange) 462 if (!pRange)
463 return -1; 463 return -1;
464 464
465 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 465 CPDF_Object* pStreamLen = pRange->GetDirectObjectAt(1);
466 if (!pStreamLen) 466 if (!pStreamLen)
467 return -1; 467 return -1;
468 468
469 return pStreamLen->GetInteger(); 469 return pStreamLen->GetInteger();
470 } 470 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_document.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698