summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_annotlist.cpp3
-rw-r--r--core/fpdfdoc/cpdf_filespec.cpp4
-rw-r--r--core/fpdfdoc/cpdf_filespec_unittest.cpp4
-rw-r--r--core/fpdfdoc/cpdf_formfield_unittest.cpp12
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp11
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp47
-rw-r--r--core/fpdfdoc/include/cpdf_annot.h3
-rw-r--r--core/fpdfdoc/include/cpdf_filespec.h4
8 files changed, 51 insertions, 37 deletions
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 8ab99e55d2..38d73460ef 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -30,7 +30,8 @@ std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot,
if (sContents.IsEmpty())
return std::unique_ptr<CPDF_Annot>();
- CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pAnnotDict =
+ new CPDF_Dictionary(pDocument->GetByteStringPool());
pAnnotDict->SetNameFor("Type", "Annot");
pAnnotDict->SetNameFor("Subtype", "Popup");
pAnnotDict->SetStringFor("T", pParentDict->GetStringFor("T"));
diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp
index 3176eb51af..8423d66fc7 100644
--- a/core/fpdfdoc/cpdf_filespec.cpp
+++ b/core/fpdfdoc/cpdf_filespec.cpp
@@ -110,8 +110,8 @@ bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const {
return true;
}
-CPDF_FileSpec::CPDF_FileSpec() {
- m_pObj = new CPDF_Dictionary;
+CPDF_FileSpec::CPDF_FileSpec(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) {
+ m_pObj = new CPDF_Dictionary(pPool);
m_pObj->AsDictionary()->SetNameFor("Type", "Filespec");
}
diff --git a/core/fpdfdoc/cpdf_filespec_unittest.cpp b/core/fpdfdoc/cpdf_filespec_unittest.cpp
index f63c388478..25577bb00b 100644
--- a/core/fpdfdoc/cpdf_filespec_unittest.cpp
+++ b/core/fpdfdoc/cpdf_filespec_unittest.cpp
@@ -105,7 +105,7 @@ TEST(cpdf_filespec, GetFileName) {
};
// Keyword fields in reverse order of precedence to retrieve the file name.
const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"};
- ScopedDict dict_obj(new CPDF_Dictionary);
+ ScopedDict dict_obj(new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()));
CPDF_FileSpec file_spec(dict_obj.get());
CFX_WideString file_name;
for (int i = 0; i < 5; ++i) {
@@ -155,7 +155,7 @@ TEST(cpdf_filespec, SetFileName) {
EXPECT_TRUE(file_name == test_data.input);
// Dictionary object.
- ScopedDict dict_obj(new CPDF_Dictionary);
+ ScopedDict dict_obj(new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>()));
CPDF_FileSpec file_spec2(dict_obj.get());
file_spec2.SetFileName(test_data.input);
// Check internal object value.
diff --git a/core/fpdfdoc/cpdf_formfield_unittest.cpp b/core/fpdfdoc/cpdf_formfield_unittest.cpp
index 34c70caad2..eb7a5927e6 100644
--- a/core/fpdfdoc/cpdf_formfield_unittest.cpp
+++ b/core/fpdfdoc/cpdf_formfield_unittest.cpp
@@ -12,25 +12,29 @@ TEST(cpdf_formfield, FPDF_GetFullName) {
EXPECT_TRUE(name.IsEmpty());
CPDF_IndirectObjectHolder obj_holder;
- CPDF_Dictionary* root = new CPDF_Dictionary;
+ CPDF_Dictionary* root =
+ new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>());
obj_holder.AddIndirectObject(root);
root->SetNameFor("T", "foo");
name = FPDF_GetFullName(root);
EXPECT_STREQ("foo", name.UTF8Encode().c_str());
- CPDF_Dictionary* dict1 = new CPDF_Dictionary;
+ CPDF_Dictionary* dict1 =
+ new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>());
root->SetReferenceFor("Parent", &obj_holder,
obj_holder.AddIndirectObject(dict1));
dict1->SetNameFor("T", "bar");
name = FPDF_GetFullName(root);
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
- CPDF_Dictionary* dict2 = new CPDF_Dictionary;
+ CPDF_Dictionary* dict2 =
+ new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>());
dict1->SetFor("Parent", dict2);
name = FPDF_GetFullName(root);
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
- CPDF_Dictionary* dict3 = new CPDF_Dictionary;
+ CPDF_Dictionary* dict3 =
+ new CPDF_Dictionary(CFX_WeakPtr<CFX_ByteStringPool>());
dict2->SetReferenceFor("Parent", &obj_holder,
obj_holder.AddIndirectObject(dict3));
dict3->SetNameFor("T", "qux");
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index d2a842262e..29063f534b 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -58,7 +58,7 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
return;
if (!pFormDict) {
- pFormDict = new CPDF_Dictionary;
+ pFormDict = new CPDF_Dictionary(pDocument->GetByteStringPool());
pDocument->GetRoot()->SetReferenceFor(
"AcroForm", pDocument, pDocument->AddIndirectObject(pFormDict));
}
@@ -259,12 +259,12 @@ void AddFont(CPDF_Dictionary*& pFormDict,
CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
if (!pDR) {
- pDR = new CPDF_Dictionary;
+ pDR = new CPDF_Dictionary(pDocument->GetByteStringPool());
pFormDict->SetFor("DR", pDR);
}
CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
if (!pFonts) {
- pFonts = new CPDF_Dictionary;
+ pFonts = new CPDF_Dictionary(pDocument->GetByteStringPool());
pDR->SetFor("Font", pFonts);
}
if (csNameTag.IsEmpty())
@@ -1212,7 +1212,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(
pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath));
pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath));
} else {
- CPDF_FileSpec filespec;
+ CPDF_FileSpec filespec(pDoc->GetByteStringPool());
filespec.SetFileName(pdf_path);
pMainDict->SetFor("F", filespec.GetObj());
}
@@ -1235,7 +1235,8 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(
continue;
CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict());
- CPDF_Dictionary* pFieldDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pFieldDict =
+ new CPDF_Dictionary(pDoc->GetByteStringPool());
pFieldDict->SetFor("T", new CPDF_String(fullname));
if (pField->GetType() == CPDF_FormField::CheckBox ||
pField->GetType() == CPDF_FormField::RadioButton) {
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index f7ece9bc35..4c7a56352b 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -58,7 +58,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1));
if (!pFontDict) {
- pFontDict = new CPDF_Dictionary;
+ pFontDict = new CPDF_Dictionary(pDoc->GetByteStringPool());
pFontDict->SetNameFor("Type", "Font");
pFontDict->SetNameFor("Subtype", "Type1");
pFontDict->SetNameFor("BaseFont", "Helvetica");
@@ -163,7 +163,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
rcBody.Normalize();
CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP");
if (!pAPDict) {
- pAPDict = new CPDF_Dictionary;
+ pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool());
pAnnotDict->SetFor("AP", pAPDict);
}
CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N");
@@ -179,7 +179,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
if (pStreamResList) {
CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
if (!pStreamResFontList) {
- pStreamResFontList = new CPDF_Dictionary;
+ pStreamResFontList = new CPDF_Dictionary(pDoc->GetByteStringPool());
pStreamResList->SetFor("Font", pStreamResFontList);
}
if (!pStreamResFontList->KeyExist(sFontName))
@@ -430,7 +430,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_Dictionary* pStreamResFontList =
pStreamResList->GetDictFor("Font");
if (!pStreamResFontList) {
- pStreamResFontList = new CPDF_Dictionary;
+ pStreamResFontList = new CPDF_Dictionary(pDoc->GetByteStringPool());
pStreamResList->SetFor("Font", pStreamResFontList);
}
if (!pStreamResFontList->KeyExist(sFontName))
@@ -540,7 +540,8 @@ CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc,
CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
const CFX_ByteString& sExtGSDictName,
const CFX_ByteString& sBlendMode) {
- CPDF_Dictionary* pGSDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pGSDict =
+ new CPDF_Dictionary(pAnnotDict.GetByteStringPool());
pGSDict->SetStringFor("Type", "ExtGState");
FX_FLOAT fOpacity =
@@ -550,31 +551,33 @@ CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
pGSDict->SetBooleanFor("AIS", false);
pGSDict->SetStringFor("BM", sBlendMode);
- CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pExtGStateDict =
+ new CPDF_Dictionary(pAnnotDict.GetByteStringPool());
pExtGStateDict->SetFor(sExtGSDictName, pGSDict);
-
return pExtGStateDict;
}
CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc,
const CFX_ByteString& sFontDictName) {
- CPDF_Dictionary* pFontDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pFontDict = new CPDF_Dictionary(pDoc->GetByteStringPool());
pFontDict->SetNameFor("Type", "Font");
pFontDict->SetNameFor("Subtype", "Type1");
pFontDict->SetNameFor("BaseFont", "Helvetica");
pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
- CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pResourceFontDict =
+ new CPDF_Dictionary(pDoc->GetByteStringPool());
pResourceFontDict->SetReferenceFor(sFontDictName, pDoc,
pDoc->AddIndirectObject(pFontDict));
-
return pResourceFontDict;
}
// Takes ownership of |pExtGStateDict| and |pResourceFontDict|.
-CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict,
+CPDF_Dictionary* GenerateResourceDict(CPDF_Document* pDoc,
+ CPDF_Dictionary* pExtGStateDict,
CPDF_Dictionary* pResourceFontDict) {
- CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pResourceDict =
+ new CPDF_Dictionary(pDoc->GetByteStringPool());
if (pExtGStateDict)
pResourceDict->SetFor("ExtGState", pExtGStateDict);
@@ -590,7 +593,7 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc,
const CFX_ByteTextBuf& sAppStream,
CPDF_Dictionary* pResourceDict,
bool bIsTextMarkupAnnotation) {
- CPDF_Dictionary* pAPDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool());
pAnnotDict->SetFor("AP", pAPDict);
CPDF_Stream* pNormalStream = new CPDF_Stream;
@@ -789,7 +792,7 @@ bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
false /*IsTextMarkupAnnotation*/);
return true;
@@ -816,7 +819,7 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
true /*IsTextMarkupAnnotation*/);
@@ -871,7 +874,7 @@ bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
false /*IsTextMarkupAnnotation*/);
return true;
@@ -894,7 +897,7 @@ bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
false /*IsTextMarkupAnnotation*/);
return true;
@@ -921,7 +924,7 @@ bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
true /*IsTextMarkupAnnotation*/);
return true;
@@ -954,7 +957,7 @@ bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc,
CPDF_Dictionary* pResourceFontDict =
GenerateResourceFontDict(pDoc, sFontName);
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pResourceFontDict, pExtGStateDict);
+ GenerateResourceDict(pDoc, pResourceFontDict, pExtGStateDict);
CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict);
if (!pDefFont)
@@ -1008,7 +1011,7 @@ bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
false /*IsTextMarkupAnnotation*/);
return true;
@@ -1057,7 +1060,7 @@ bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
true /*IsTextMarkupAnnotation*/);
return true;
@@ -1084,7 +1087,7 @@ bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
CPDF_Dictionary* pExtGStateDict =
GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
CPDF_Dictionary* pResourceDict =
- GenerateResourceDict(pExtGStateDict, nullptr);
+ GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
true /*IsTextMarkupAnnotation*/);
return true;
diff --git a/core/fpdfdoc/include/cpdf_annot.h b/core/fpdfdoc/include/cpdf_annot.h
index 43f58931d3..e88375a903 100644
--- a/core/fpdfdoc/include/cpdf_annot.h
+++ b/core/fpdfdoc/include/cpdf_annot.h
@@ -81,6 +81,8 @@ class CPDF_Annot {
CFX_FloatRect GetRect() const;
const CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict; }
CPDF_Dictionary* GetAnnotDict() { return m_pAnnotDict; }
+ CPDF_Document* GetDocument() const { return m_pDocument; }
+
FX_BOOL DrawAppearance(CPDF_Page* pPage,
CFX_RenderDevice* pDevice,
const CFX_Matrix* pUser2Device,
@@ -90,6 +92,7 @@ class CPDF_Annot {
CPDF_RenderContext* pContext,
const CFX_Matrix* pUser2Device,
AppearanceMode mode);
+
void ClearCachedAP();
void DrawBorder(CFX_RenderDevice* pDevice,
const CFX_Matrix* pUser2Device,
diff --git a/core/fpdfdoc/include/cpdf_filespec.h b/core/fpdfdoc/include/cpdf_filespec.h
index 06badbaa5e..66f35fc202 100644
--- a/core/fpdfdoc/include/cpdf_filespec.h
+++ b/core/fpdfdoc/include/cpdf_filespec.h
@@ -7,13 +7,15 @@
#ifndef CORE_FPDFDOC_INCLUDE_CPDF_FILESPEC_H_
#define CORE_FPDFDOC_INCLUDE_CPDF_FILESPEC_H_
+#include "core/fxcrt/include/cfx_string_pool_template.h"
+#include "core/fxcrt/include/cfx_weak_ptr.h"
#include "core/fxcrt/include/fx_string.h"
class CPDF_Object;
class CPDF_FileSpec {
public:
- CPDF_FileSpec();
+ explicit CPDF_FileSpec(const CFX_WeakPtr<CFX_ByteStringPool>& pPool);
explicit CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {}
// Convert a platform dependent file name into pdf format.