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..526e826747ef8ebea4941fffcbd05d949bf5c923 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,11 +878,11 @@ 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); |
+ auto pBaseDict = pdfium::MakeUnique<CPDF_Dictionary>(m_pByteStringPool); |
dsinclair
2016/11/15 18:55:51
Why not NewIndirect here?
Tom Sepez
2016/11/15 19:15:16
Ok, I guess we always add it (no return before lin
|
pBaseDict->SetNameFor("Type", "Font"); |
std::unique_ptr<CFX_UnicodeEncoding> pEncoding( |
new CFX_UnicodeEncoding(pFont)); |
- CPDF_Dictionary* pFontDict = pBaseDict; |
+ CPDF_Dictionary* pFontDict = pBaseDict.get(); |
if (!bCJK) { |
CPDF_Array* pWidths = new CPDF_Array; |
for (int charcode = 32; charcode < 128; charcode++) { |
@@ -898,7 +899,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { |
pWidths->AddInteger(char_width); |
} |
} else { |
- size_t i = CalculateEncodingDict(charset, pBaseDict); |
+ size_t i = CalculateEncodingDict(charset, pBaseDict.get()); |
if (i < FX_ArraySize(g_FX_CharsetUnicodes)) { |
const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
for (int j = 0; j < 128; j++) { |
@@ -908,17 +909,18 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { |
} |
} |
} |
- ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, |
- pWidths); |
+ ProcessNonbCJK(pBaseDict.get(), pFont->IsBold(), pFont->IsItalic(), |
+ basefont, pWidths); |
} else { |
- pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, |
+ pFontDict = ProcessbCJK(pBaseDict.get(), charset, bVert, basefont, |
[pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, |
CPDF_Array* widthArr) { |
InsertWidthArray1(pFont, pEncoding.get(), start, |
end, widthArr); |
}); |
} |
- AddIndirectObject(pBaseDict); |
+ CPDF_Dictionary* pUnownedBaseDict = |
+ ToDictionary(AddIndirectObject(std::move(pBaseDict))); |
int italicangle = |
pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; |
FX_RECT bbox; |
@@ -943,12 +945,11 @@ 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)); |
- return LoadFont(pBaseDict); |
+ pFont->GetDescent(), pBBox, nStemV))); |
+ pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); |
+ return LoadFont(pUnownedBaseDict); |
} |
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
@@ -1009,44 +1010,45 @@ 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); |
+ auto pBaseDict = pdfium::MakeUnique<CPDF_Dictionary>(m_pByteStringPool); |
dsinclair
2016/11/15 18:55:51
ditto
Tom Sepez
2016/11/15 19:15:16
Done.
|
pBaseDict->SetNameFor("Type", "Font"); |
- CPDF_Dictionary* pFontDict = pBaseDict; |
+ CPDF_Dictionary* pFontDict = pBaseDict.get(); |
if (!bCJK) { |
if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || |
pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || |
pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { |
pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
} else { |
- CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); |
+ CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict.get()); |
} |
int char_widths[224]; |
GetCharWidth(hDC, 32, 255, char_widths); |
CPDF_Array* pWidths = new CPDF_Array; |
for (size_t i = 0; i < 224; i++) |
pWidths->AddInteger(char_widths[i]); |
- ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, |
+ ProcessNonbCJK(pBaseDict.get(), pLogFont->lfWeight > FW_MEDIUM, |
pLogFont->lfItalic != 0, basefont, pWidths); |
} else { |
pFontDict = |
- ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, |
+ ProcessbCJK(pBaseDict.get(), pLogFont->lfCharSet, bVert, basefont, |
[&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { |
InsertWidthArray(hDC, start, end, widthArr); |
}); |
} |
- AddIndirectObject(pBaseDict); |
+ CPDF_Dictionary* pUnownedBaseDict = |
+ AddIndirectObject(std::move(pBaseDict))->AsDictionary(); |
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); |
- return LoadFont(pBaseDict); |
+ return LoadFont(pUnownedBaseDict); |
} |
#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |