summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_page
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_image.cpp17
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_doc.cpp5
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp12
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp35
-rw-r--r--core/fpdfapi/fpdf_page/pageint.h16
5 files changed, 54 insertions, 31 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_image.cpp b/core/fpdfapi/fpdf_page/cpdf_image.cpp
index 4112ad86ee..91f1268eae 100644
--- a/core/fpdfapi/fpdf_page/cpdf_image.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_image.cpp
@@ -85,7 +85,8 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
return nullptr;
}
- CPDF_Dictionary* pDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pDict =
+ new CPDF_Dictionary(m_pDocument->GetByteStringPool());
pDict->SetNameFor("Type", "XObject");
pDict->SetNameFor("Subtype", "Image");
pDict->SetIntegerFor("Width", width);
@@ -108,7 +109,8 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
pDict->SetIntegerFor("BitsPerComponent", bits);
pDict->SetNameFor("Filter", "DCTDecode");
if (!color_trans) {
- CPDF_Dictionary* pParms = new CPDF_Dictionary;
+ CPDF_Dictionary* pParms =
+ new CPDF_Dictionary(m_pDocument->GetByteStringPool());
pDict->SetFor("DecodeParms", pParms);
pParms->SetIntegerFor("ColorTransform", 0);
}
@@ -150,7 +152,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
int32_t src_pitch = pBitmap->GetPitch();
int32_t bpp = pBitmap->GetBPP();
- CPDF_Dictionary* pDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pDict =
+ new CPDF_Dictionary(m_pDocument->GetByteStringPool());
pDict->SetNameFor("Type", "XObject");
pDict->SetNameFor("Subtype", "Image");
pDict->SetIntegerFor("Width", BitmapWidth);
@@ -213,8 +216,9 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
ptr[2] = (uint8_t)argb;
ptr += 3;
}
- CPDF_Stream* pCTS =
- new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary);
+ CPDF_Stream* pCTS = new CPDF_Stream(
+ pColorTable, iPalette * 3,
+ new CPDF_Dictionary(m_pDocument->GetByteStringPool()));
pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS));
pDict->SetReferenceFor("ColorSpace", m_pDocument,
m_pDocument->AddIndirectObject(pCS));
@@ -249,7 +253,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
int32_t maskHeight = pMaskBitmap->GetHeight();
uint8_t* mask_buf = nullptr;
FX_STRSIZE mask_size = 0;
- CPDF_Dictionary* pMaskDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pMaskDict =
+ new CPDF_Dictionary(m_pDocument->GetByteStringPool());
pMaskDict->SetNameFor("Type", "XObject");
pMaskDict->SetNameFor("Subtype", "Image");
pMaskDict->SetIntegerFor("Width", maskWidth);
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index c4e2a24424..192e0947bc 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -184,12 +184,13 @@ CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName,
return fontData->AddRef();
}
- CPDF_Dictionary* pDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pPDFDoc->GetByteStringPool());
pDict->SetNameFor("Type", "Font");
pDict->SetNameFor("Subtype", "Type1");
pDict->SetNameFor("BaseFont", fontName);
if (pEncoding) {
- pDict->SetFor("Encoding", pEncoding->Realize());
+ pDict->SetFor("Encoding",
+ pEncoding->Realize(m_pPDFDoc->GetByteStringPool()));
}
m_pPDFDoc->AddIndirectObject(pDict);
std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pDict);
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 46ab067b3e..881f9eed25 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -281,7 +281,8 @@ void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) {
ContentParam& param = m_ParamBuf[GetNextParamPos()];
if (len > 32) {
param.m_Type = ContentParam::OBJECT;
- param.m_pObject = new CPDF_Name(PDF_NameDecode(bsName));
+ param.m_pObject = new CPDF_Name(
+ m_pDocument->GetByteStringPool()->Intern(PDF_NameDecode(bsName)));
} else {
param.m_Type = ContentParam::NAME;
if (bsName.Find('#') == -1) {
@@ -343,8 +344,8 @@ CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) {
return pNumber;
}
if (param.m_Type == ContentParam::NAME) {
- CPDF_Name* pName = new CPDF_Name(
- CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
+ CPDF_Name* pName = new CPDF_Name(m_pDocument->GetByteStringPool()->Intern(
+ CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len)));
param.m_Type = ContentParam::OBJECT;
param.m_pObject = pName;
return pName;
@@ -589,7 +590,8 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
void CPDF_StreamContentParser::Handle_BeginImage() {
FX_FILESIZE savePos = m_pSyntax->GetPos();
- CPDF_Dictionary* pDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pDict =
+ new CPDF_Dictionary(m_pDocument->GetByteStringPool());
while (1) {
CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement();
if (type == CPDF_StreamParser::Keyword) {
@@ -1499,7 +1501,7 @@ uint32_t CPDF_StreamContentParser::Parse(const uint8_t* pData,
return dwSize;
}
uint32_t InitObjCount = m_pObjectHolder->GetPageObjectList()->size();
- CPDF_StreamParser syntax(pData, dwSize);
+ CPDF_StreamParser syntax(pData, dwSize, m_pDocument->GetByteStringPool());
CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax);
while (1) {
uint32_t cost = m_pObjectHolder->GetPageObjectList()->size() - InitObjCount;
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index eab0ee595b..0e9cd3b55d 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -41,12 +41,22 @@ const FX_STRSIZE kMaxStringLength = 32767;
} // namespace
-CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize) {
- m_pBuf = pData;
- m_Size = dwSize;
- m_Pos = 0;
- m_pLastObj = nullptr;
-}
+CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize)
+ : m_pBuf(pData),
+ m_Size(dwSize),
+ m_Pos(0),
+ m_pLastObj(nullptr),
+ m_pPool(nullptr) {}
+
+CPDF_StreamParser::CPDF_StreamParser(
+ const uint8_t* pData,
+ uint32_t dwSize,
+ const CFX_WeakPtr<CFX_ByteStringPool>& pPool)
+ : m_pBuf(pData),
+ m_Size(dwSize),
+ m_Pos(0),
+ m_pLastObj(nullptr),
+ m_pPool(pPool) {}
CPDF_StreamParser::~CPDF_StreamParser() {
if (m_pLastObj) {
@@ -336,18 +346,21 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(bool bAllowNestedArray,
int first_char = m_WordBuffer[0];
if (first_char == '/') {
- return new CPDF_Name(
- PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
+ CFX_ByteString name =
+ PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1));
+ return new CPDF_Name(m_pPool ? m_pPool->Intern(name) : name);
}
- if (first_char == '(')
- return new CPDF_String(ReadString(), FALSE);
+ if (first_char == '(') {
+ CFX_ByteString str = ReadString();
+ return new CPDF_String(m_pPool ? m_pPool->Intern(str) : str, FALSE);
+ }
if (first_char == '<') {
if (m_WordSize == 1)
return new CPDF_String(ReadHexString(), TRUE);
- CPDF_Dictionary* pDict = new CPDF_Dictionary;
+ CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pPool);
while (1) {
GetNextWord(bIsNumber);
if (m_WordSize == 2 && m_WordBuffer[0] == '>')
diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h
index 427a363e8e..c5b80aa550 100644
--- a/core/fpdfapi/fpdf_page/pageint.h
+++ b/core/fpdfapi/fpdf_page/pageint.h
@@ -16,6 +16,8 @@
#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h"
#include "core/fpdfapi/fpdf_page/cpdf_countedobject.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h"
+#include "core/fxcrt/include/cfx_string_pool_template.h"
+#include "core/fxcrt/include/cfx_weak_ptr.h"
#include "core/fxge/include/cfx_pathdata.h"
#include "core/fxge/include/cfx_renderdevice.h"
@@ -43,6 +45,9 @@ class CPDF_StreamParser {
enum SyntaxType { EndOfData, Number, Keyword, Name, Others };
CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize);
+ CPDF_StreamParser(const uint8_t* pData,
+ uint32_t dwSize,
+ const CFX_WeakPtr<CFX_ByteStringPool>& pPool);
~CPDF_StreamParser();
CPDF_Stream* ReadInlineStream(CPDF_Document* pDoc,
@@ -66,17 +71,14 @@ class CPDF_StreamParser {
void GetNextWord(FX_BOOL& bIsNumber);
CFX_ByteString ReadString();
CFX_ByteString ReadHexString();
- const uint8_t* m_pBuf;
-
- // Length in bytes of m_pBuf.
- uint32_t m_Size;
-
- // Current byte position within m_pBuf.
- uint32_t m_Pos;
+ const uint8_t* m_pBuf;
+ uint32_t m_Size; // Length in bytes of m_pBuf.
+ uint32_t m_Pos; // Current byte position within m_pBuf.
uint8_t m_WordBuffer[256];
uint32_t m_WordSize;
CPDF_Object* m_pLastObj;
+ CFX_WeakPtr<CFX_ByteStringPool> m_pPool;
private:
bool PositionIsInBounds() const;