From ab36e73c8c5409fa262d4fa2faffe65c8804a792 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 11 Oct 2016 13:42:12 -0700 Subject: Add CPDF_Object::IsInline() Prevent having to remember what an object number of 0 implies. Review-Url: https://codereview.chromium.org/2412673002 --- core/fpdfapi/edit/fpdf_edit_create.cpp | 14 +++++++------- core/fpdfapi/page/cpdf_image.cpp | 2 +- core/fpdfapi/page/fpdf_page_parser.cpp | 4 ++-- core/fpdfapi/parser/cpdf_array.cpp | 6 +++--- core/fpdfapi/parser/cpdf_dictionary.cpp | 2 +- core/fpdfapi/parser/cpdf_object.h | 1 + core/fpdfapi/parser/fpdf_parser_utility.cpp | 4 ++-- core/fpdfapi/render/fpdf_render_loadimage.cpp | 4 ++-- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp index ac8d709a2e..e5b1fe1bb0 100644 --- a/core/fpdfapi/edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/edit/fpdf_edit_create.cpp @@ -97,7 +97,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, const CPDF_Array* p = pObj->AsArray(); for (size_t i = 0; i < p->GetCount(); i++) { CPDF_Object* pElement = p->GetObjectAt(i); - if (pElement->GetObjNum()) { + if (!pElement->IsInline()) { if (pFile->AppendString(" ") < 0) { return -1; } @@ -136,7 +136,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, return -1; } offset += len + 1; - if (pValue->GetObjNum()) { + if (!pValue->IsInline()) { if (pFile->AppendString(" ") < 0) { return -1; } @@ -213,7 +213,7 @@ int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, return -1; } offset += len + 1; - if (pValue->GetObjNum()) { + if (!pValue->IsInline()) { if (pFile->AppendString(" ") < 0) { return -1; } @@ -1157,7 +1157,7 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, const CPDF_Array* p = pObj->AsArray(); for (size_t i = 0; i < p->GetCount(); i++) { CPDF_Object* pElement = p->GetObjectAt(i); - if (pElement->GetObjNum()) { + if (!pElement->IsInline()) { if (m_File.AppendString(" ") < 0) { return -1; } @@ -1203,7 +1203,7 @@ int32_t CPDF_Creator::WriteDirectObj(uint32_t objnum, if (bSignDict && key == "Contents") { bSignValue = TRUE; } - if (pValue->GetObjNum()) { + if (!pValue->IsInline()) { if (m_File.AppendString(" ") < 0) { return -1; } @@ -1562,7 +1562,7 @@ int32_t CPDF_Creator::WriteDoc_Stage2(IFX_Pause* pPause) { m_iStage = 27; } if (m_iStage == 27) { - if (m_pEncryptDict && !m_pEncryptDict->GetObjNum()) { + if (m_pEncryptDict && m_pEncryptDict->IsInline()) { m_dwLastObjNum += 1; FX_FILESIZE saveOffset = m_Offset; if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) { @@ -1728,7 +1728,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { if (m_File.AppendString(PDF_NameEncode(key).AsStringC()) < 0) { return -1; } - if (pValue->GetObjNum()) { + if (!pValue->IsInline()) { if (m_File.AppendString(" ") < 0) { return -1; } diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 64d0114eb9..29d10e1d6b 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -63,7 +63,7 @@ CPDF_Image::~CPDF_Image() { } CPDF_Image* CPDF_Image::Clone() { - if (m_pStream->GetObjNum()) + if (!m_pStream->IsInline()) return m_pDocument->GetPageData()->GetImage(m_pStream); CPDF_Image* pImage = diff --git a/core/fpdfapi/page/fpdf_page_parser.cpp b/core/fpdfapi/page/fpdf_page_parser.cpp index 60cb3b4bfa..a55fa23bef 100644 --- a/core/fpdfapi/page/fpdf_page_parser.cpp +++ b/core/fpdfapi/page/fpdf_page_parser.cpp @@ -613,7 +613,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { CFX_ByteString name = pCSObj->GetString(); if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { pCSObj = FindResourceObj("ColorSpace", name); - if (pCSObj && !pCSObj->GetObjNum()) { + if (pCSObj && pCSObj->IsInline()) { pCSObj = pCSObj->Clone(); pDict->SetFor("ColorSpace", pCSObj); } @@ -773,7 +773,7 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, if (pImage) { pImageObj->SetUnownedImage( m_pDocument->GetPageData()->GetImage(pImage->GetStream())); - } else if (pStream->GetObjNum()) { + } else if (!pStream->IsInline()) { pImageObj->SetUnownedImage(m_pDocument->LoadImageF(pStream)); } else { pImageObj->SetOwnedImage( diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp index 0d0c02f28d..1aec3e06f3 100644 --- a/core/fpdfapi/parser/cpdf_array.cpp +++ b/core/fpdfapi/parser/cpdf_array.cpp @@ -161,7 +161,7 @@ void CPDF_Array::ConvertToIndirectObjectAt(size_t i, void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj) { ASSERT(IsArray()); - CHECK(!pObj || pObj->GetObjNum() == 0); + CHECK(!pObj || pObj->IsInline()); if (i >= m_Objects.size()) { ASSERT(false); return; @@ -174,7 +174,7 @@ void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj) { void CPDF_Array::InsertAt(size_t index, CPDF_Object* pObj) { ASSERT(IsArray()); - CHECK(!pObj || pObj->GetObjNum() == 0); + CHECK(!pObj || pObj->IsInline()); if (index >= m_Objects.size()) { // Allocate space first. m_Objects.resize(index + 1, nullptr); @@ -187,7 +187,7 @@ void CPDF_Array::InsertAt(size_t index, CPDF_Object* pObj) { void CPDF_Array::Add(CPDF_Object* pObj) { ASSERT(IsArray()); - CHECK(!pObj || pObj->GetObjNum() == 0); + CHECK(!pObj || pObj->IsInline()); m_Objects.push_back(pObj); } diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp index 2aa5248be0..aab7422b3c 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/parser/cpdf_dictionary.cpp @@ -174,7 +174,7 @@ bool CPDF_Dictionary::IsSignatureDict() const { } void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { - CHECK(!pObj || pObj->GetObjNum() == 0); + CHECK(!pObj || pObj->IsInline()); auto it = m_Map.find(key); if (it == m_Map.end()) { if (pObj) diff --git a/core/fpdfapi/parser/cpdf_object.h b/core/fpdfapi/parser/cpdf_object.h index e2c30b96ca..3cf23188a7 100644 --- a/core/fpdfapi/parser/cpdf_object.h +++ b/core/fpdfapi/parser/cpdf_object.h @@ -41,6 +41,7 @@ class CPDF_Object { virtual Type GetType() const = 0; uint32_t GetObjNum() const { return m_ObjNum; } uint32_t GetGenNum() const { return m_GenNum; } + bool IsInline() const { return m_ObjNum == 0; } // Create a deep copy of the object. virtual CPDF_Object* Clone() const = 0; diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp index 10fac7fa1c..7b9ead4005 100644 --- a/core/fpdfapi/parser/fpdf_parser_utility.cpp +++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp @@ -179,7 +179,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { buf << "["; for (size_t i = 0; i < p->GetCount(); i++) { CPDF_Object* pElement = p->GetObjectAt(i); - if (pElement && pElement->GetObjNum()) { + if (pElement && !pElement->IsInline()) { buf << " " << pElement->GetObjNum() << " 0 R"; } else { buf << pElement; @@ -195,7 +195,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { const CFX_ByteString& key = it.first; CPDF_Object* pValue = it.second; buf << "/" << PDF_NameEncode(key); - if (pValue && pValue->GetObjNum()) { + if (pValue && !pValue->IsInline()) { buf << " " << pValue->GetObjNum() << " 0 R "; } else { buf << pValue; diff --git a/core/fpdfapi/render/fpdf_render_loadimage.cpp b/core/fpdfapi/render/fpdf_render_loadimage.cpp index 940aa37479..a4f0e7befb 100644 --- a/core/fpdfapi/render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/render/fpdf_render_loadimage.cpp @@ -163,7 +163,7 @@ FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, } m_GroupFamily = GroupFamily; m_bLoadMask = bLoadMask; - if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? nullptr : pFormResources, + if (!LoadColorInfo(m_pStream->IsInline() ? pFormResources : nullptr, pPageResources)) { return FALSE; } @@ -285,7 +285,7 @@ int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, } m_GroupFamily = GroupFamily; m_bLoadMask = bLoadMask; - if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? nullptr : pFormResources, + if (!LoadColorInfo(m_pStream->IsInline() ? pFormResources : nullptr, pPageResources)) { return 0; } -- cgit v1.2.3