diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-10-14 17:45:56 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-10-14 17:45:56 -0700 |
commit | c25a4219431c90a95233a08f25eecc921abbf3ed (patch) | |
tree | bd2ad923d527440785c19623fe2d19cc1a70a92d /core/fpdfapi/parser/cpdf_document.cpp | |
parent | 62f367348ff8ff1e64c6f52c1ee5f77c3a89edc1 (diff) | |
download | pdfium-c25a4219431c90a95233a08f25eecc921abbf3ed.tar.xz |
Revert "Update CPDF_IndirectObjectHolder APIs for unique objects."
This reverts commit 3ba098595ae56b64eacc0c25ab76b89a4d78d920.
TBR=thestig@chromium.org,weili@chromium.org
Review URL: https://codereview.chromium.org/2424533003 .
Diffstat (limited to 'core/fpdfapi/parser/cpdf_document.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index fdd395e351..c5f64a790c 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -256,7 +256,7 @@ int InsertDeletePDFPage(CPDF_Document* pDoc, if (nPagesToGo == 0) { if (bInsert) { pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum())); - pPage->SetReferenceFor("Parent", pDoc, pPages); + pPage->SetReferenceFor("Parent", pDoc, pPages->GetObjNum()); } else { pKidList->RemoveAt(i); } @@ -307,7 +307,7 @@ int InsertNewPage(CPDF_Document* pDoc, } pPagesList->Add(new CPDF_Reference(pDoc, pPageDict->GetObjNum())); pPages->SetIntegerFor("Count", nPages + 1); - pPageDict->SetReferenceFor("Parent", pDoc, pPages); + pPageDict->SetReferenceFor("Parent", pDoc, pPages->GetObjNum()); } else { std::set<CPDF_Dictionary*> stack = {pPages}; if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, &stack) < 0) @@ -693,23 +693,25 @@ CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) { void CPDF_Document::CreateNewDoc() { ASSERT(!m_pRootDict && !m_pInfoDict); - m_pRootDict = AddIndirectDictionary(m_pByteStringPool); + m_pRootDict = new CPDF_Dictionary(m_pByteStringPool); m_pRootDict->SetNameFor("Type", "Catalog"); + AddIndirectObject(m_pRootDict); - CPDF_Dictionary* pPages = AddIndirectDictionary(m_pByteStringPool); + CPDF_Dictionary* pPages = new CPDF_Dictionary(m_pByteStringPool); pPages->SetNameFor("Type", "Pages"); pPages->SetNumberFor("Count", 0); pPages->SetFor("Kids", new CPDF_Array); - - m_pRootDict->SetReferenceFor("Pages", this, pPages); - m_pInfoDict = AddIndirectDictionary(m_pByteStringPool); + m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages)); + m_pInfoDict = new CPDF_Dictionary(m_pByteStringPool); + AddIndirectObject(m_pInfoDict); } CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { - CPDF_Dictionary* pDict = AddIndirectDictionary(m_pByteStringPool); + CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool); pDict->SetNameFor("Type", "Page"); + uint32_t dwObjNum = AddIndirectObject(pDict); if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { - DeleteIndirectObject(pDict->GetObjNum()); + ReleaseIndirectObject(dwObjNum); return nullptr; } return pDict; @@ -748,8 +750,7 @@ size_t CPDF_Document::CalculateEncodingDict(int charset, } if (i == FX_ArraySize(g_FX_CharsetUnicodes)) return i; - - CPDF_Dictionary* pEncodingDict = AddIndirectDictionary(m_pByteStringPool); + CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary(m_pByteStringPool); pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); CPDF_Array* pArray = new CPDF_Array; pArray->AddInteger(128); @@ -759,7 +760,9 @@ size_t CPDF_Document::CalculateEncodingDict(int charset, pArray->AddName(name.IsEmpty() ? ".notdef" : name); } pEncodingDict->SetFor("Differences", pArray); - pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); + pBaseDict->SetReferenceFor("Encoding", this, + AddIndirectObject(pEncodingDict)); + return i; } @@ -769,7 +772,7 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK( FX_BOOL bVert, CFX_ByteString basefont, std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { - CPDF_Dictionary* pFontDict = AddIndirectDictionary(m_pByteStringPool); + CPDF_Dictionary* pFontDict = new CPDF_Dictionary(m_pByteStringPool); CFX_ByteString cmap; CFX_ByteString ordering; int supplement = 0; @@ -819,17 +822,14 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK( pFontDict->SetNameFor("Type", "Font"); pFontDict->SetNameFor("Subtype", "CIDFontType2"); pFontDict->SetNameFor("BaseFont", basefont); - CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); pCIDSysInfo->SetStringFor("Registry", "Adobe"); pCIDSysInfo->SetStringFor("Ordering", ordering); pCIDSysInfo->SetIntegerFor("Supplement", supplement); pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); - CPDF_Array* pArray = new CPDF_Array; pBaseDict->SetFor("DescendantFonts", pArray); - - pArray->AddReference(this, pFontDict); + pArray->AddReference(this, AddIndirectObject(pFontDict)); return pFontDict; } @@ -847,7 +847,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), false, false, charset == FXFONT_SYMBOL_CHARSET); - CPDF_Dictionary* pBaseDict = AddIndirectDictionary(m_pByteStringPool); + CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); pBaseDict->SetNameFor("Type", "Font"); std::unique_ptr<CFX_UnicodeEncoding> pEncoding( new CFX_UnicodeEncoding(pFont)); @@ -888,6 +888,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { end, widthArr); }); } + AddIndirectObject(pBaseDict); int italicangle = pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; FX_RECT bbox; @@ -915,11 +916,8 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { CPDF_Dictionary* pFontDesc = CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), pFont->GetDescent(), pBBox, nStemV); - - // TODO(tsepez): check |pFontDesc| ownership. pFontDict->SetReferenceFor("FontDescriptor", this, - AddIndirectObject(UniqueDictionary(pFontDesc))); - + AddIndirectObject(pFontDesc)); return LoadFont(pBaseDict); } @@ -981,7 +979,7 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; FX_Free(tm_buf); basefont.Replace(" ", ""); - CPDF_Dictionary* pBaseDict = AddIndirectDictionary(m_pByteStringPool); + CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); pBaseDict->SetNameFor("Type", "Font"); CPDF_Dictionary* pFontDict = pBaseDict; if (!bCJK) { @@ -1006,6 +1004,7 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, InsertWidthArray(hDC, start, end, widthArr); }); } + AddIndirectObject(pBaseDict); CPDF_Array* pBBox = new CPDF_Array; for (int i = 0; i < 4; i++) pBBox->AddInteger(bbox[i]); @@ -1013,11 +1012,8 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, pBBox, pLogFont->lfWeight / 5); pFontDesc->SetIntegerFor("CapHeight", capheight); - - // TODO(tsepez): check |pFontDesc| ownership. pFontDict->SetReferenceFor("FontDescriptor", this, - AddIndirectObject(UniqueObject(pFontDesc))); - + AddIndirectObject(pFontDesc)); hFont = SelectObject(hDC, hFont); DeleteObject(hFont); DeleteDC(hDC); |