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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp

Issue 1544963002: Clean up misc nits found while fixing bugs. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 11 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 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 "pageint.h" 7 #include "pageint.h"
8 8
9 #include "core/include/fpdfapi/fpdf_module.h" 9 #include "core/include/fpdfapi/fpdf_module.h"
10 #include "core/include/fpdfapi/fpdf_page.h" 10 #include "core/include/fpdfapi/fpdf_page.h"
11 #include "core/include/fpdfapi/fpdf_serial.h" 11 #include "core/include/fpdfapi/fpdf_serial.h"
12 12
13 #define REQUIRE_PARAMS(count) \ 13 #define REQUIRE_PARAMS(count) \
Tom Sepez 2016/01/07 17:27:02 nit: bleh on hiding an early return.
Lei Zhang 2016/01/08 02:54:30 Gone.
14 if (m_ParamCount != count) { \ 14 if (m_ParamCount != count) { \
15 return; \ 15 return; \
16 } 16 }
17 17
18 CPDF_StreamContentParser::CPDF_StreamContentParser( 18 CPDF_StreamContentParser::CPDF_StreamContentParser(
19 CPDF_Document* pDocument, 19 CPDF_Document* pDocument,
20 CPDF_Dictionary* pPageResources, 20 CPDF_Dictionary* pPageResources,
21 CPDF_Dictionary* pParentResources, 21 CPDF_Dictionary* pParentResources,
22 CFX_Matrix* pmtContentToUser, 22 CFX_Matrix* pmtContentToUser,
23 CPDF_PageObjects* pObjList, 23 CPDF_PageObjects* pObjList,
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 m_CurContentMark.GetModify()->AddMark(tag, pDict, bDirect); 424 m_CurContentMark.GetModify()->AddMark(tag, pDict, bDirect);
425 } 425 }
426 } 426 }
427 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { 427 void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
428 if (!m_Options.m_bMarkedContent) { 428 if (!m_Options.m_bMarkedContent) {
429 return; 429 return;
430 } 430 }
431 CFX_ByteString tag = GetString(0); 431 CFX_ByteString tag = GetString(0);
432 m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE); 432 m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
433 } 433 }
434 struct _FX_BSTR { 434 struct _FX_BSTR {
Tom Sepez 2016/01/07 17:27:02 Down the road. I've thought that the real CFX_Byte
Lei Zhang 2016/01/08 02:54:30 Sounds ok to me. Or maybe Blink's String class wil
435 const FX_CHAR* m_Ptr; 435 const FX_CHAR* m_Ptr;
436 int m_Size; 436 int m_Size;
437 }; 437 };
438 #define _FX_BSTRC(str) \ 438 #define _FX_BSTRC(str) \
439 { str, sizeof(str) - 1 } 439 { str, sizeof(str) - 1 }
440 const _FX_BSTR _PDF_InlineKeyAbbr[] = { 440 const _FX_BSTR _PDF_InlineKeyAbbr[] = {
441 _FX_BSTRC("BitsPerComponent"), 441 _FX_BSTRC("BitsPerComponent"),
442 _FX_BSTRC("BPC"), 442 _FX_BSTRC("BPC"),
443 _FX_BSTRC("ColorSpace"), 443 _FX_BSTRC("ColorSpace"),
444 _FX_BSTRC("CS"), 444 _FX_BSTRC("CS"),
(...skipping 23 matching lines...) Expand all
468 _FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl"), 468 _FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl"),
469 _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"), 469 _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"),
470 _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"), 470 _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"),
471 _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"), 471 _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"),
472 }; 472 };
473 static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table, 473 static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table,
474 int count, 474 int count,
475 const CFX_ByteStringC& abbr) { 475 const CFX_ByteStringC& abbr) {
476 int i = 0; 476 int i = 0;
477 while (i < count) { 477 while (i < count) {
478 if (abbr.GetLength() == table[i + 1].m_Size && 478 if (abbr.GetLength() == table[i + 1].m_Size &&
Tom Sepez 2016/01/07 17:27:02 Is it too much to ask to make a struct containing
Lei Zhang 2016/01/08 02:54:30 Done.
479 FXSYS_memcmp(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) == 479 FXSYS_memcmp(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) ==
480 0) { 480 0) {
481 return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size); 481 return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size);
482 } 482 }
483 i += 2; 483 i += 2;
484 } 484 }
485 return CFX_ByteStringC(); 485 return CFX_ByteStringC();
486 } 486 }
487 void _PDF_ReplaceAbbr(CPDF_Object* pObj) { 487
488 void PDF_ReplaceAbbr(CPDF_Object* pObj) {
488 switch (pObj->GetType()) { 489 switch (pObj->GetType()) {
489 case PDFOBJ_DICTIONARY: { 490 case PDFOBJ_DICTIONARY: {
490 CPDF_Dictionary* pDict = pObj->AsDictionary(); 491 CPDF_Dictionary* pDict = pObj->AsDictionary();
491 FX_POSITION pos = pDict->GetStartPos(); 492 FX_POSITION pos = pDict->GetStartPos();
492 while (pos) { 493 while (pos) {
493 CFX_ByteString key; 494 CFX_ByteString key;
494 CPDF_Object* value = pDict->GetNextElement(pos, key); 495 CPDF_Object* value = pDict->GetNextElement(pos, key);
495 CFX_ByteStringC fullname = _PDF_FindFullName( 496 CFX_ByteStringC fullname = _PDF_FindFullName(
496 _PDF_InlineKeyAbbr, sizeof _PDF_InlineKeyAbbr / sizeof(_FX_BSTR), 497 _PDF_InlineKeyAbbr, sizeof _PDF_InlineKeyAbbr / sizeof(_FX_BSTR),
497 key); 498 key);
498 if (!fullname.IsEmpty()) { 499 if (!fullname.IsEmpty()) {
499 pDict->ReplaceKey(key, fullname); 500 pDict->ReplaceKey(key, fullname);
500 key = fullname; 501 key = fullname;
501 } 502 }
502 503
503 if (value->IsName()) { 504 if (value->IsName()) {
504 CFX_ByteString name = value->GetString(); 505 CFX_ByteString name = value->GetString();
505 fullname = _PDF_FindFullName( 506 fullname = _PDF_FindFullName(
506 _PDF_InlineValueAbbr, 507 _PDF_InlineValueAbbr,
507 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name); 508 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
508 if (!fullname.IsEmpty()) { 509 if (!fullname.IsEmpty()) {
509 pDict->SetAtName(key, fullname); 510 pDict->SetAtName(key, fullname);
510 } 511 }
511 } else { 512 } else {
512 _PDF_ReplaceAbbr(value); 513 PDF_ReplaceAbbr(value);
513 } 514 }
514 } 515 }
515 break; 516 break;
516 } 517 }
517 case PDFOBJ_ARRAY: { 518 case PDFOBJ_ARRAY: {
518 CPDF_Array* pArray = pObj->AsArray(); 519 CPDF_Array* pArray = pObj->AsArray();
519 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { 520 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
520 CPDF_Object* pElement = pArray->GetElement(i); 521 CPDF_Object* pElement = pArray->GetElement(i);
521 if (pElement->IsName()) { 522 if (pElement->IsName()) {
522 CFX_ByteString name = pElement->GetString(); 523 CFX_ByteString name = pElement->GetString();
523 CFX_ByteStringC fullname = _PDF_FindFullName( 524 CFX_ByteStringC fullname = _PDF_FindFullName(
524 _PDF_InlineValueAbbr, 525 _PDF_InlineValueAbbr,
525 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name); 526 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
526 if (!fullname.IsEmpty()) { 527 if (!fullname.IsEmpty()) {
527 pArray->SetAt(i, new CPDF_Name(fullname)); 528 pArray->SetAt(i, new CPDF_Name(fullname));
528 } 529 }
529 } else { 530 } else {
530 _PDF_ReplaceAbbr(pElement); 531 PDF_ReplaceAbbr(pElement);
531 } 532 }
532 } 533 }
533 break; 534 break;
534 } 535 }
535 } 536 }
536 } 537 }
538
537 static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table, 539 static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table,
538 int count, 540 int count,
539 const CFX_ByteStringC& fullName) { 541 const CFX_ByteStringC& fullName) {
540 int i = 0; 542 int i = 0;
541 while (i < count) { 543 while (i < count) {
542 if (fullName.GetLength() == table[i].m_Size && 544 if (fullName.GetLength() == table[i].m_Size &&
543 FXSYS_memcmp(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) == 545 FXSYS_memcmp(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) ==
544 0) { 546 0) {
545 return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size); 547 return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);
546 } 548 }
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 m_pObjectList->m_ObjectList.AddTail(pPathObj); 1522 m_pObjectList->m_ObjectList.AddTail(pPathObj);
1521 } 1523 }
1522 if (PathClipType) { 1524 if (PathClipType) {
1523 if (!matrix.IsIdentity()) { 1525 if (!matrix.IsIdentity()) {
1524 Path.Transform(&matrix); 1526 Path.Transform(&matrix);
1525 matrix.SetIdentity(); 1527 matrix.SetIdentity();
1526 } 1528 }
1527 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); 1529 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE);
1528 } 1530 }
1529 } 1531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698