summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp95
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp18
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp18
3 files changed, 67 insertions, 64 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 45f93d0afe..15edaf1b66 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -26,19 +26,19 @@ void CPDF_Object::Release() {
}
void CPDF_Object::Destroy() {
switch (m_Type) {
- case PDFOBJ_STRING:
+ case STRING:
delete AsString();
break;
- case PDFOBJ_NAME:
+ case NAME:
delete AsName();
break;
- case PDFOBJ_ARRAY:
+ case ARRAY:
delete AsArray();
break;
- case PDFOBJ_DICTIONARY:
+ case DICTIONARY:
delete AsDictionary();
break;
- case PDFOBJ_STREAM:
+ case STREAM:
delete AsStream();
break;
default:
@@ -61,14 +61,16 @@ CFX_ByteString CPDF_Object::GetString() const {
const CPDF_Object* obj = GetBasicObject();
if (obj) {
switch (obj->GetType()) {
- case PDFOBJ_BOOLEAN:
+ case BOOLEAN:
return obj->AsBoolean()->GetString();
- case PDFOBJ_NUMBER:
+ case NUMBER:
return obj->AsNumber()->GetString();
- case PDFOBJ_STRING:
+ case STRING:
return obj->AsString()->GetString();
- case PDFOBJ_NAME:
+ case NAME:
return obj->AsName()->GetString();
+ default:
+ break;
}
}
return CFX_ByteString();
@@ -78,11 +80,11 @@ CFX_ByteStringC CPDF_Object::GetConstString() const {
const CPDF_Object* obj = GetBasicObject();
if (obj) {
FX_DWORD type = obj->GetType();
- if (type == PDFOBJ_STRING) {
+ if (type == STRING) {
CFX_ByteString str = obj->AsString()->GetString();
return CFX_ByteStringC(str);
}
- if (type == PDFOBJ_NAME) {
+ if (type == NAME) {
CFX_ByteString name = obj->AsName()->GetString();
return CFX_ByteStringC(name);
}
@@ -92,7 +94,7 @@ CFX_ByteStringC CPDF_Object::GetConstString() const {
FX_FLOAT CPDF_Object::GetNumber() const {
const CPDF_Object* obj = GetBasicObject();
- if (obj && obj->GetType() == PDFOBJ_NUMBER)
+ if (obj && obj->GetType() == NUMBER)
return obj->AsNumber()->GetNumber();
return 0;
}
@@ -105,9 +107,9 @@ int CPDF_Object::GetInteger() const {
const CPDF_Object* obj = GetBasicObject();
if (obj) {
FX_DWORD type = obj->GetType();
- if (type == PDFOBJ_BOOLEAN)
+ if (type == BOOLEAN)
return obj->AsBoolean()->GetValue();
- if (type == PDFOBJ_NUMBER)
+ if (type == NUMBER)
return obj->AsNumber()->GetInteger();
}
return 0;
@@ -117,12 +119,12 @@ CPDF_Dictionary* CPDF_Object::GetDict() const {
const CPDF_Object* obj = GetBasicObject();
if (obj) {
FX_DWORD type = obj->GetType();
- if (type == PDFOBJ_DICTIONARY) {
+ if (type == DICTIONARY) {
// The method should be made non-const if we want to not be const.
// See bug #234.
return const_cast<CPDF_Dictionary*>(obj->AsDictionary());
}
- if (type == PDFOBJ_STREAM)
+ if (type == STREAM)
return obj->AsStream()->GetDict();
}
return nullptr;
@@ -136,18 +138,20 @@ CPDF_Array* CPDF_Object::GetArray() const {
void CPDF_Object::SetString(const CFX_ByteString& str) {
switch (m_Type) {
- case PDFOBJ_BOOLEAN:
+ case BOOLEAN:
AsBoolean()->m_bValue = (str == "true");
return;
- case PDFOBJ_NUMBER:
+ case NUMBER:
AsNumber()->SetString(str);
return;
- case PDFOBJ_STRING:
+ case STRING:
AsString()->m_String = str;
return;
- case PDFOBJ_NAME:
+ case NAME:
AsName()->m_Name = str;
return;
+ default:
+ break;
}
ASSERT(FALSE);
}
@@ -164,23 +168,23 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
return FALSE;
}
switch (m_Type) {
- case PDFOBJ_BOOLEAN:
+ case BOOLEAN:
return AsBoolean()->Identical(pOther->AsBoolean());
- case PDFOBJ_NUMBER:
+ case NUMBER:
return AsNumber()->Identical(pOther->AsNumber());
- case PDFOBJ_STRING:
+ case STRING:
return AsString()->Identical(pOther->AsString());
- case PDFOBJ_NAME:
+ case NAME:
return AsName()->Identical(pOther->AsName());
- case PDFOBJ_ARRAY:
+ case ARRAY:
return AsArray()->Identical(pOther->AsArray());
- case PDFOBJ_DICTIONARY:
+ case DICTIONARY:
return AsDictionary()->Identical(pOther->AsDictionary());
- case PDFOBJ_NULL:
+ case NULLOBJ:
return TRUE;
- case PDFOBJ_STREAM:
+ case STREAM:
return AsStream()->Identical(pOther->AsStream());
- case PDFOBJ_REFERENCE:
+ case REFERENCE:
return AsReference()->Identical(pOther->AsReference());
}
return FALSE;
@@ -202,20 +206,20 @@ CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const {
CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
std::set<FX_DWORD>* visited) const {
switch (m_Type) {
- case PDFOBJ_BOOLEAN:
+ case BOOLEAN:
return new CPDF_Boolean(AsBoolean()->m_bValue);
- case PDFOBJ_NUMBER: {
+ case NUMBER: {
const CPDF_Number* pThis = AsNumber();
return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer
: pThis->m_Float);
}
- case PDFOBJ_STRING: {
+ case STRING: {
const CPDF_String* pString = AsString();
return new CPDF_String(pString->m_String, pString->IsHex());
}
- case PDFOBJ_NAME:
+ case NAME:
return new CPDF_Name(AsName()->m_Name);
- case PDFOBJ_ARRAY: {
+ case ARRAY: {
CPDF_Array* pCopy = new CPDF_Array();
const CPDF_Array* pThis = AsArray();
int n = pThis->GetCount();
@@ -225,7 +229,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
}
return pCopy;
}
- case PDFOBJ_DICTIONARY: {
+ case DICTIONARY: {
CPDF_Dictionary* pCopy = new CPDF_Dictionary();
const CPDF_Dictionary* pThis = AsDictionary();
for (const auto& it : *pThis) {
@@ -234,10 +238,10 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
}
return pCopy;
}
- case PDFOBJ_NULL: {
+ case NULLOBJ: {
return new CPDF_Null;
}
- case PDFOBJ_STREAM: {
+ case STREAM: {
const CPDF_Stream* pThis = AsStream();
CPDF_StreamAcc acc;
acc.LoadAllData(pThis, TRUE);
@@ -248,7 +252,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
}
return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
}
- case PDFOBJ_REFERENCE: {
+ case REFERENCE: {
const CPDF_Reference* pRef = AsReference();
FX_DWORD obj_num = pRef->GetRefObjNum();
if (bDirect && !pdfium::ContainsKey(*visited, obj_num)) {
@@ -357,13 +361,12 @@ const CPDF_String* CPDF_Object::AsString() const {
}
CPDF_Number::CPDF_Number(int value)
- : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {}
+ : CPDF_Object(NUMBER), m_bInteger(TRUE), m_Integer(value) {}
CPDF_Number::CPDF_Number(FX_FLOAT value)
- : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(FALSE), m_Float(value) {}
+ : CPDF_Object(NUMBER), m_bInteger(FALSE), m_Float(value) {}
-CPDF_Number::CPDF_Number(const CFX_ByteStringC& str)
- : CPDF_Object(PDFOBJ_NUMBER) {
+CPDF_Number::CPDF_Number(const CFX_ByteStringC& str) : CPDF_Object(NUMBER) {
FX_atonum(str, m_bInteger, &m_Integer);
}
@@ -382,7 +385,7 @@ void CPDF_Number::SetNumber(FX_FLOAT value) {
m_Float = value;
}
CPDF_String::CPDF_String(const CFX_WideString& str)
- : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) {
+ : CPDF_Object(STRING), m_bHex(FALSE) {
m_String = PDF_EncodeText(str);
}
CPDF_Array::~CPDF_Array() {
@@ -675,7 +678,7 @@ void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) {
m_Map.erase(it);
}
void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) {
- ASSERT(m_Type == PDFOBJ_DICTIONARY);
+ ASSERT(m_Type == DICTIONARY);
auto it = m_Map.find(key);
if (it == m_Map.end())
return;
@@ -685,7 +688,7 @@ void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) {
}
void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey,
const CFX_ByteStringC& newkey) {
- ASSERT(m_Type == PDFOBJ_DICTIONARY);
+ ASSERT(m_Type == DICTIONARY);
auto old_it = m_Map.find(oldkey);
if (old_it == m_Map.end())
return;
@@ -768,7 +771,7 @@ void CPDF_Dictionary::SetAtMatrix(const CFX_ByteStringC& key,
SetAt(key, pArray);
}
CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict)
- : CPDF_Object(PDFOBJ_STREAM),
+ : CPDF_Object(STREAM),
m_pDict(pDict),
m_dwSize(size),
m_GenNum(kMemoryBasedGenNum),
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 9f6665d025..c0150b5435 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2940,15 +2940,15 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(
int32_t type = pObj->GetType();
switch (type) {
- case PDFOBJ_ARRAY: {
+ case CPDF_Object::ARRAY: {
CPDF_Array* pArray = pObj->GetArray();
for (FX_DWORD k = 0; k < pArray->GetCount(); k++) {
new_obj_array.Add(pArray->GetElement(k));
}
} break;
- case PDFOBJ_STREAM:
+ case CPDF_Object::STREAM:
pObj = pObj->GetDict();
- case PDFOBJ_DICTIONARY: {
+ case CPDF_Object::DICTIONARY: {
CPDF_Dictionary* pDict = pObj->GetDict();
if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) {
continue;
@@ -2961,7 +2961,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(
}
}
} break;
- case PDFOBJ_REFERENCE: {
+ case CPDF_Object::REFERENCE: {
CPDF_Reference* pRef = pObj->AsReference();
FX_DWORD dwNum = pRef->GetRefObjNum();
FX_FILESIZE offset;
@@ -3348,10 +3348,10 @@ FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) {
return TRUE;
}
switch (pKids->GetType()) {
- case PDFOBJ_REFERENCE:
+ case CPDF_Object::REFERENCE:
m_PageObjList.Add(pKids->AsReference()->GetRefObjNum());
break;
- case PDFOBJ_ARRAY: {
+ case CPDF_Object::ARRAY: {
CPDF_Array* pKidsArray = pKids->AsArray();
for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i)))
@@ -4042,13 +4042,13 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo,
return TRUE;
}
switch (pKids->GetType()) {
- case PDFOBJ_REFERENCE: {
+ case CPDF_Object::REFERENCE: {
CPDF_Reference* pKid = pKids->AsReference();
CPDF_PageNode* pNode = new CPDF_PageNode();
pPageNode->m_childNode.Add(pNode);
pNode->m_dwPageNo = pKid->GetRefObjNum();
} break;
- case PDFOBJ_ARRAY: {
+ case CPDF_Object::ARRAY: {
CPDF_Array* pKidsArray = pKids->AsArray();
for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) {
CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i));
@@ -4851,7 +4851,7 @@ FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) {
return FALSE;
CPDF_Dictionary* pDict = pHintStream->GetDict();
CPDF_Object* pOffset = pDict ? pDict->GetElement("S") : nullptr;
- if (!pOffset || pOffset->GetType() != PDFOBJ_NUMBER)
+ if (!pOffset || pOffset->GetType() != CPDF_Object::NUMBER)
return FALSE;
int shared_hint_table_offset = pOffset->GetInteger();
CPDF_StreamAcc acc;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index b3172dd848..141618030a 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -338,26 +338,26 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
return buf;
}
switch (pObj->GetType()) {
- case PDFOBJ_NULL:
+ case CPDF_Object::NULLOBJ:
buf << " null";
break;
- case PDFOBJ_BOOLEAN:
- case PDFOBJ_NUMBER:
+ case CPDF_Object::BOOLEAN:
+ case CPDF_Object::NUMBER:
buf << " " << pObj->GetString();
break;
- case PDFOBJ_STRING:
+ case CPDF_Object::STRING:
buf << PDF_EncodeString(pObj->GetString(), pObj->AsString()->IsHex());
break;
- case PDFOBJ_NAME: {
+ case CPDF_Object::NAME: {
CFX_ByteString str = pObj->GetString();
buf << "/" << PDF_NameEncode(str);
break;
}
- case PDFOBJ_REFERENCE: {
+ case CPDF_Object::REFERENCE: {
buf << " " << pObj->AsReference()->GetRefObjNum() << " 0 R ";
break;
}
- case PDFOBJ_ARRAY: {
+ case CPDF_Object::ARRAY: {
const CPDF_Array* p = pObj->AsArray();
buf << "[";
for (FX_DWORD i = 0; i < p->GetCount(); i++) {
@@ -371,7 +371,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
buf << "]";
break;
}
- case PDFOBJ_DICTIONARY: {
+ case CPDF_Object::DICTIONARY: {
const CPDF_Dictionary* p = pObj->AsDictionary();
buf << "<<";
for (const auto& it : *p) {
@@ -387,7 +387,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
buf << ">>";
break;
}
- case PDFOBJ_STREAM: {
+ case CPDF_Object::STREAM: {
const CPDF_Stream* p = pObj->AsStream();
buf << p->GetDict() << "stream\r\n";
CPDF_StreamAcc acc;