| Index: core/fpdfapi/parser/cpdf_document.cpp
|
| diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
|
| index ebd3156e35c6bcabff641a3d887b0fe9679f2a17..35c18997b95cded2635cd6173ab0e57e8cf9f618 100644
|
| --- a/core/fpdfapi/parser/cpdf_document.cpp
|
| +++ b/core/fpdfapi/parser/cpdf_document.cpp
|
| @@ -310,15 +310,16 @@ void ProcessNonbCJK(CPDF_Dictionary* pBaseDict,
|
| pBaseDict->SetFor("Widths", pWidths);
|
| }
|
|
|
| -CPDF_Dictionary* CalculateFontDesc(CPDF_Document* pDoc,
|
| - CFX_ByteString basefont,
|
| - int flags,
|
| - int italicangle,
|
| - int ascend,
|
| - int descend,
|
| - CPDF_Array* bbox,
|
| - int32_t stemV) {
|
| - CPDF_Dictionary* pFontDesc = new CPDF_Dictionary(pDoc->GetByteStringPool());
|
| +std::unique_ptr<CPDF_Dictionary> CalculateFontDesc(CPDF_Document* pDoc,
|
| + CFX_ByteString basefont,
|
| + int flags,
|
| + int italicangle,
|
| + int ascend,
|
| + int descend,
|
| + CPDF_Array* bbox,
|
| + int32_t stemV) {
|
| + auto pFontDesc =
|
| + pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
|
| pFontDesc->SetNameFor("Type", "FontDescriptor");
|
| pFontDesc->SetNameFor("FontName", basefont);
|
| pFontDesc->SetIntegerFor("Flags", flags);
|
| @@ -648,23 +649,21 @@ CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) {
|
|
|
| void CPDF_Document::CreateNewDoc() {
|
| ASSERT(!m_pRootDict && !m_pInfoDict);
|
| - m_pRootDict = new CPDF_Dictionary(m_pByteStringPool);
|
| + m_pRootDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
|
| m_pRootDict->SetNameFor("Type", "Catalog");
|
| - AddIndirectObject(m_pRootDict);
|
|
|
| - CPDF_Dictionary* pPages = new CPDF_Dictionary(m_pByteStringPool);
|
| + CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(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 = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
|
| }
|
|
|
| CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) {
|
| - CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool);
|
| + CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
|
| pDict->SetNameFor("Type", "Page");
|
| - uint32_t dwObjNum = AddIndirectObject(pDict);
|
| + uint32_t dwObjNum = pDict->GetObjNum();
|
| if (!InsertNewPage(iPage, pDict)) {
|
| DeleteIndirectObject(dwObjNum);
|
| return nullptr;
|
| @@ -780,19 +779,21 @@ 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 =
|
| + NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
|
| pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding");
|
| +
|
| CPDF_Array* pArray = new CPDF_Array;
|
| pArray->AddInteger(128);
|
| +
|
| const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes;
|
| for (int j = 0; j < 128; j++) {
|
| CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]);
|
| pArray->AddName(name.IsEmpty() ? ".notdef" : name);
|
| }
|
| pEncodingDict->SetFor("Differences", pArray);
|
| - pBaseDict->SetReferenceFor("Encoding", this,
|
| - AddIndirectObject(pEncodingDict));
|
| -
|
| + pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict);
|
| return i;
|
| }
|
|
|
| @@ -802,7 +803,7 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK(
|
| 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 = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
|
| CFX_ByteString cmap;
|
| CFX_ByteString ordering;
|
| int supplement = 0;
|
| @@ -859,7 +860,7 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK(
|
| pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo);
|
| CPDF_Array* pArray = new CPDF_Array;
|
| pBaseDict->SetFor("DescendantFonts", pArray);
|
| - pArray->AddReference(this, AddIndirectObject(pFontDict));
|
| + pArray->AddReference(this, pFontDict->GetObjNum());
|
| return pFontDict;
|
| }
|
|
|
| @@ -877,7 +878,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, 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 = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
|
| pBaseDict->SetNameFor("Type", "Font");
|
| std::unique_ptr<CFX_UnicodeEncoding> pEncoding(
|
| new CFX_UnicodeEncoding(pFont));
|
| @@ -918,7 +919,6 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) {
|
| end, widthArr);
|
| });
|
| }
|
| - AddIndirectObject(pBaseDict);
|
| int italicangle =
|
| pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0;
|
| FX_RECT bbox;
|
| @@ -943,11 +943,10 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) {
|
| nStemV = width;
|
| }
|
| }
|
| - CPDF_Dictionary* pFontDesc =
|
| + CPDF_Dictionary* pFontDesc = ToDictionary(AddIndirectObject(
|
| CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(),
|
| - pFont->GetDescent(), pBBox, nStemV);
|
| - pFontDict->SetReferenceFor("FontDescriptor", this,
|
| - AddIndirectObject(pFontDesc));
|
| + pFont->GetDescent(), pBBox, nStemV)));
|
| + pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc);
|
| return LoadFont(pBaseDict);
|
| }
|
|
|
| @@ -1009,7 +1008,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 = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
|
| pBaseDict->SetNameFor("Type", "Font");
|
| CPDF_Dictionary* pFontDict = pBaseDict;
|
| if (!bCJK) {
|
| @@ -1034,16 +1033,15 @@ 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]);
|
| - CPDF_Dictionary* pFontDesc =
|
| + std::unique_ptr<CPDF_Dictionary> pFontDesc =
|
| CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend,
|
| pBBox, pLogFont->lfWeight / 5);
|
| pFontDesc->SetIntegerFor("CapHeight", capheight);
|
| pFontDict->SetReferenceFor("FontDescriptor", this,
|
| - AddIndirectObject(pFontDesc));
|
| + AddIndirectObject(std::move(pFontDesc)));
|
| hFont = SelectObject(hDC, hFont);
|
| DeleteObject(hFont);
|
| DeleteDC(hDC);
|
|
|