| Index: core/fpdfapi/parser/cpdf_document.cpp
|
| diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
|
| index c5f64a790ca1d31f6cb4357f5a01b18d6b0585e1..fdd395e351a03da5c29363187225bab5a5620b33 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->GetObjNum());
|
| + pPage->SetReferenceFor("Parent", pDoc, pPages);
|
| } 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->GetObjNum());
|
| + pPageDict->SetReferenceFor("Parent", pDoc, pPages);
|
| } else {
|
| std::set<CPDF_Dictionary*> stack = {pPages};
|
| if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, &stack) < 0)
|
| @@ -693,25 +693,23 @@ CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) {
|
|
|
| void CPDF_Document::CreateNewDoc() {
|
| ASSERT(!m_pRootDict && !m_pInfoDict);
|
| - m_pRootDict = new CPDF_Dictionary(m_pByteStringPool);
|
| + m_pRootDict = AddIndirectDictionary(m_pByteStringPool);
|
| m_pRootDict->SetNameFor("Type", "Catalog");
|
| - AddIndirectObject(m_pRootDict);
|
|
|
| - CPDF_Dictionary* pPages = new CPDF_Dictionary(m_pByteStringPool);
|
| + CPDF_Dictionary* pPages = AddIndirectDictionary(m_pByteStringPool);
|
| pPages->SetNameFor("Type", "Pages");
|
| pPages->SetNumberFor("Count", 0);
|
| pPages->SetFor("Kids", new CPDF_Array);
|
| - m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages));
|
| - m_pInfoDict = new CPDF_Dictionary(m_pByteStringPool);
|
| - AddIndirectObject(m_pInfoDict);
|
| +
|
| + m_pRootDict->SetReferenceFor("Pages", this, pPages);
|
| + m_pInfoDict = AddIndirectDictionary(m_pByteStringPool);
|
| }
|
|
|
| CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) {
|
| - CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool);
|
| + CPDF_Dictionary* pDict = AddIndirectDictionary(m_pByteStringPool);
|
| pDict->SetNameFor("Type", "Page");
|
| - uint32_t dwObjNum = AddIndirectObject(pDict);
|
| if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) {
|
| - ReleaseIndirectObject(dwObjNum);
|
| + DeleteIndirectObject(pDict->GetObjNum());
|
| return nullptr;
|
| }
|
| return pDict;
|
| @@ -750,7 +748,8 @@ size_t CPDF_Document::CalculateEncodingDict(int charset,
|
| }
|
| if (i == FX_ArraySize(g_FX_CharsetUnicodes))
|
| return i;
|
| - CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary(m_pByteStringPool);
|
| +
|
| + CPDF_Dictionary* pEncodingDict = AddIndirectDictionary(m_pByteStringPool);
|
| pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding");
|
| CPDF_Array* pArray = new CPDF_Array;
|
| pArray->AddInteger(128);
|
| @@ -760,9 +759,7 @@ size_t CPDF_Document::CalculateEncodingDict(int charset,
|
| pArray->AddName(name.IsEmpty() ? ".notdef" : name);
|
| }
|
| pEncodingDict->SetFor("Differences", pArray);
|
| - pBaseDict->SetReferenceFor("Encoding", this,
|
| - AddIndirectObject(pEncodingDict));
|
| -
|
| + pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict);
|
| return i;
|
| }
|
|
|
| @@ -772,7 +769,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 = new CPDF_Dictionary(m_pByteStringPool);
|
| + CPDF_Dictionary* pFontDict = AddIndirectDictionary(m_pByteStringPool);
|
| CFX_ByteString cmap;
|
| CFX_ByteString ordering;
|
| int supplement = 0;
|
| @@ -822,14 +819,17 @@ 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, AddIndirectObject(pFontDict));
|
| +
|
| + pArray->AddReference(this, 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 = new CPDF_Dictionary(m_pByteStringPool);
|
| + CPDF_Dictionary* pBaseDict = AddIndirectDictionary(m_pByteStringPool);
|
| pBaseDict->SetNameFor("Type", "Font");
|
| std::unique_ptr<CFX_UnicodeEncoding> pEncoding(
|
| new CFX_UnicodeEncoding(pFont));
|
| @@ -888,7 +888,6 @@ 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;
|
| @@ -916,8 +915,11 @@ 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(pFontDesc));
|
| + AddIndirectObject(UniqueDictionary(pFontDesc)));
|
| +
|
| return LoadFont(pBaseDict);
|
| }
|
|
|
| @@ -979,7 +981,7 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont,
|
| ptm->otmrcFontBox.right, ptm->otmrcFontBox.top};
|
| FX_Free(tm_buf);
|
| basefont.Replace(" ", "");
|
| - CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool);
|
| + CPDF_Dictionary* pBaseDict = AddIndirectDictionary(m_pByteStringPool);
|
| pBaseDict->SetNameFor("Type", "Font");
|
| CPDF_Dictionary* pFontDict = pBaseDict;
|
| if (!bCJK) {
|
| @@ -1004,7 +1006,6 @@ 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]);
|
| @@ -1012,8 +1013,11 @@ 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(pFontDesc));
|
| + AddIndirectObject(UniqueObject(pFontDesc)));
|
| +
|
| hFont = SelectObject(hDC, hFont);
|
| DeleteObject(hFont);
|
| DeleteDC(hDC);
|
|
|