summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_page
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2016-01-08 14:24:37 -0800
committerLei Zhang <thestig@chromium.org>2016-01-08 14:24:37 -0800
commit1b97664bc5b84c7a2b87cc656f8c6a0476f9b71f (patch)
tree11c6727d7fa3d2dac36b879c3bbd106326c7ca43 /core/src/fpdfapi/fpdf_page
parent6a1c51b9eb666f2e120ec098d900663627ebcb3e (diff)
downloadpdfium-1b97664bc5b84c7a2b87cc656f8c6a0476f9b71f.tar.xz
Merge to XFA: Clean up misc nits found while fixing bugs.
Some bits regressed in commit 338805f. Also merge: IWYU fix after commit c5a8933. R=tsepez@chromium.org TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1544963002 . Review URL: https://codereview.chromium.org/1570973002 . (cherry picked from commit c5a8933f260ca1034fde902058442984e55c0f7a) (cherry picked from commit e6bd31873c3dba3f79c5ebbbefed636948629cc9) Review URL: https://codereview.chromium.org/1577453002 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_page')
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp210
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp14
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h2
3 files changed, 114 insertions, 112 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 99d0c5adc0..cfc581f4c8 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -4,16 +4,79 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "pageint.h"
+#include "core/src/fpdfapi/fpdf_page/pageint.h"
#include "core/include/fpdfapi/fpdf_module.h"
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_serial.h"
-#define REQUIRE_PARAMS(count) \
- if (m_ParamCount != count) { \
- return; \
+namespace {
+
+struct _FX_BSTR {
+ const FX_CHAR* m_Ptr;
+ int m_Size;
+};
+#define _FX_BSTRC(str) \
+ { str, sizeof(str) - 1 }
+
+struct PDF_AbbrPairs {
+ _FX_BSTR full_name;
+ _FX_BSTR abbr;
+};
+
+const PDF_AbbrPairs PDF_InlineKeyAbbr[] = {
+ {_FX_BSTRC("BitsPerComponent"), _FX_BSTRC("BPC")},
+ {_FX_BSTRC("ColorSpace"), _FX_BSTRC("CS")},
+ {_FX_BSTRC("Decode"), _FX_BSTRC("D")},
+ {_FX_BSTRC("DecodeParms"), _FX_BSTRC("DP")},
+ {_FX_BSTRC("Filter"), _FX_BSTRC("F")},
+ {_FX_BSTRC("Height"), _FX_BSTRC("H")},
+ {_FX_BSTRC("ImageMask"), _FX_BSTRC("IM")},
+ {_FX_BSTRC("Interpolate"), _FX_BSTRC("I")},
+ {_FX_BSTRC("Width"), _FX_BSTRC("W")},
+};
+
+const PDF_AbbrPairs PDF_InlineValueAbbr[] = {
+ {_FX_BSTRC("DeviceGray"), _FX_BSTRC("G")},
+ {_FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB")},
+ {_FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK")},
+ {_FX_BSTRC("Indexed"), _FX_BSTRC("I")},
+ {_FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx")},
+ {_FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85")},
+ {_FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW")},
+ {_FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl")},
+ {_FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL")},
+ {_FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF")},
+ {_FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT")},
+};
+
+CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPairs* table,
+ size_t count,
+ const CFX_ByteStringC& abbr) {
+ for (size_t i = 0; i < count; ++i) {
+ if (abbr.GetLength() != table[i].abbr.m_Size)
+ continue;
+ if (memcmp(abbr.GetPtr(), table[i].abbr.m_Ptr, abbr.GetLength()))
+ continue;
+ return CFX_ByteStringC(table[i].full_name.m_Ptr, table[i].full_name.m_Size);
}
+ return CFX_ByteStringC();
+}
+
+CFX_ByteStringC PDF_FindAbbrName(const PDF_AbbrPairs* table,
+ size_t count,
+ const CFX_ByteStringC& name) {
+ for (size_t i = 0; i < count; ++i) {
+ if (name.GetLength() != table[i].full_name.m_Size)
+ continue;
+ if (memcmp(name.GetPtr(), table[i].full_name.m_Ptr, name.GetLength()))
+ continue;
+ return CFX_ByteStringC(table[i].abbr.m_Ptr, table[i].abbr.m_Size);
+ }
+ return CFX_ByteStringC();
+}
+
+} // namespace
CPDF_StreamContentParser::CPDF_StreamContentParser(
CPDF_Document* pDocument,
@@ -361,7 +424,7 @@ FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) {
while (i < 4) {
opid <<= 8;
i++;
- };
+ }
int low = 0, high = sizeof g_OpCodes / sizeof(OpCode) - 1;
while (low <= high) {
int middle = (low + high) / 2;
@@ -431,60 +494,8 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
CFX_ByteString tag = GetString(0);
m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
}
-struct _FX_BSTR {
- const FX_CHAR* m_Ptr;
- int m_Size;
-};
-#define _FX_BSTRC(str) \
- { str, sizeof(str) - 1 }
-const _FX_BSTR _PDF_InlineKeyAbbr[] = {
- _FX_BSTRC("BitsPerComponent"),
- _FX_BSTRC("BPC"),
- _FX_BSTRC("ColorSpace"),
- _FX_BSTRC("CS"),
- _FX_BSTRC("Decode"),
- _FX_BSTRC("D"),
- _FX_BSTRC("DecodeParms"),
- _FX_BSTRC("DP"),
- _FX_BSTRC("Filter"),
- _FX_BSTRC("F"),
- _FX_BSTRC("Height"),
- _FX_BSTRC("H"),
- _FX_BSTRC("ImageMask"),
- _FX_BSTRC("IM"),
- _FX_BSTRC("Interpolate"),
- _FX_BSTRC("I"),
- _FX_BSTRC("Width"),
- _FX_BSTRC("W"),
-};
-const _FX_BSTR _PDF_InlineValueAbbr[] = {
- _FX_BSTRC("DeviceGray"), _FX_BSTRC("G"),
- _FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB"),
- _FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK"),
- _FX_BSTRC("Indexed"), _FX_BSTRC("I"),
- _FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx"),
- _FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85"),
- _FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW"),
- _FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl"),
- _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"),
- _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"),
- _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"),
-};
-static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table,
- int count,
- const CFX_ByteStringC& abbr) {
- int i = 0;
- while (i < count) {
- if (abbr.GetLength() == table[i + 1].m_Size &&
- FXSYS_memcmp(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) ==
- 0) {
- return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size);
- }
- i += 2;
- }
- return CFX_ByteStringC();
-}
-void _PDF_ReplaceAbbr(CPDF_Object* pObj) {
+
+void PDF_ReplaceAbbr(CPDF_Object* pObj) {
switch (pObj->GetType()) {
case PDFOBJ_DICTIONARY: {
CPDF_Dictionary* pDict = pObj->AsDictionary();
@@ -492,9 +503,8 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj) {
while (pos) {
CFX_ByteString key;
CPDF_Object* value = pDict->GetNextElement(pos, key);
- CFX_ByteStringC fullname = _PDF_FindFullName(
- _PDF_InlineKeyAbbr, sizeof _PDF_InlineKeyAbbr / sizeof(_FX_BSTR),
- key);
+ CFX_ByteStringC fullname = PDF_FindFullName(
+ PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key);
if (!fullname.IsEmpty()) {
pDict->ReplaceKey(key, fullname);
key = fullname;
@@ -502,14 +512,13 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj) {
if (value->IsName()) {
CFX_ByteString name = value->GetString();
- fullname = _PDF_FindFullName(
- _PDF_InlineValueAbbr,
- sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
+ fullname = PDF_FindFullName(PDF_InlineValueAbbr,
+ FX_ArraySize(PDF_InlineValueAbbr), name);
if (!fullname.IsEmpty()) {
pDict->SetAtName(key, fullname);
}
} else {
- _PDF_ReplaceAbbr(value);
+ PDF_ReplaceAbbr(value);
}
}
break;
@@ -520,35 +529,21 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj) {
CPDF_Object* pElement = pArray->GetElement(i);
if (pElement->IsName()) {
CFX_ByteString name = pElement->GetString();
- CFX_ByteStringC fullname = _PDF_FindFullName(
- _PDF_InlineValueAbbr,
- sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
+ CFX_ByteStringC fullname = PDF_FindFullName(
+ PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name);
if (!fullname.IsEmpty()) {
pArray->SetAt(i, new CPDF_Name(fullname));
}
} else {
- _PDF_ReplaceAbbr(pElement);
+ PDF_ReplaceAbbr(pElement);
}
}
break;
}
}
}
-static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table,
- int count,
- const CFX_ByteStringC& fullName) {
- int i = 0;
- while (i < count) {
- if (fullName.GetLength() == table[i].m_Size &&
- FXSYS_memcmp(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) ==
- 0) {
- return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);
- }
- i += 2;
- }
- return CFX_ByteStringC();
-}
-void _PDF_ReplaceFull(CPDF_Object* pObj) {
+
+void PDF_ReplaceFull(CPDF_Object* pObj) {
switch (pObj->GetType()) {
case PDFOBJ_DICTIONARY: {
CPDF_Dictionary* pDict = pObj->AsDictionary();
@@ -556,23 +551,21 @@ void _PDF_ReplaceFull(CPDF_Object* pObj) {
while (pos) {
CFX_ByteString key;
CPDF_Object* value = pDict->GetNextElement(pos, key);
- CFX_ByteStringC abbrName = _PDF_FindAbbrName(
- _PDF_InlineKeyAbbr, sizeof(_PDF_InlineKeyAbbr) / sizeof(_FX_BSTR),
- key);
+ CFX_ByteStringC abbrName = PDF_FindAbbrName(
+ PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key);
if (!abbrName.IsEmpty()) {
pDict->ReplaceKey(key, abbrName);
key = abbrName;
}
if (value->IsName()) {
CFX_ByteString name = value->GetString();
- abbrName = _PDF_FindAbbrName(
- _PDF_InlineValueAbbr,
- sizeof(_PDF_InlineValueAbbr) / sizeof(_FX_BSTR), name);
+ abbrName = PDF_FindAbbrName(PDF_InlineValueAbbr,
+ FX_ArraySize(PDF_InlineValueAbbr), name);
if (!abbrName.IsEmpty()) {
pDict->SetAtName(key, abbrName);
}
} else {
- _PDF_ReplaceFull(value);
+ PDF_ReplaceFull(value);
}
}
break;
@@ -583,14 +576,13 @@ void _PDF_ReplaceFull(CPDF_Object* pObj) {
CPDF_Object* pElement = pArray->GetElement(i);
if (pElement->IsName()) {
CFX_ByteString name = pElement->GetString();
- CFX_ByteStringC abbrName = _PDF_FindAbbrName(
- _PDF_InlineValueAbbr,
- sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
+ CFX_ByteStringC abbrName = PDF_FindAbbrName(
+ PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name);
if (!abbrName.IsEmpty()) {
pArray->SetAt(i, new CPDF_Name(abbrName));
}
} else {
- _PDF_ReplaceFull(pElement);
+ PDF_ReplaceFull(pElement);
}
}
break;
@@ -893,7 +885,9 @@ void CPDF_StreamContentParser::Handle_SetLineCap() {
(CFX_GraphStateData::LineCap)GetInteger(0);
}
void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill() {
- REQUIRE_PARAMS(4);
+ if (m_ParamCount != 4)
+ return;
+
FX_FLOAT values[4];
for (int i = 0; i < 4; i++) {
values[i] = GetNumber(3 - i);
@@ -902,7 +896,9 @@ void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill() {
m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4);
}
void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() {
- REQUIRE_PARAMS(4);
+ if (m_ParamCount != 4)
+ return;
+
FX_FLOAT values[4];
for (int i = 0; i < 4; i++) {
values[i] = GetNumber(3 - i);
@@ -911,14 +907,18 @@ void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() {
m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4);
}
void CPDF_StreamContentParser::Handle_LineTo() {
- REQUIRE_PARAMS(2);
+ if (m_ParamCount != 2)
+ return;
+
if (m_Options.m_bTextOnly) {
return;
}
AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO);
}
void CPDF_StreamContentParser::Handle_MoveTo() {
- REQUIRE_PARAMS(2);
+ if (m_ParamCount != 2)
+ return;
+
if (m_Options.m_bTextOnly) {
m_pSyntax->SkipPathObject();
return;
@@ -970,7 +970,9 @@ void CPDF_StreamContentParser::AddPathRect(FX_FLOAT x,
AddPathPoint(x, y, FXPT_LINETO | FXPT_CLOSEFIGURE);
}
void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() {
- REQUIRE_PARAMS(3);
+ if (m_ParamCount != 3)
+ return;
+
FX_FLOAT values[3];
for (int i = 0; i < 3; i++) {
values[i] = GetNumber(2 - i);
@@ -979,7 +981,9 @@ void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() {
m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3);
}
void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() {
- REQUIRE_PARAMS(3);
+ if (m_ParamCount != 3)
+ return;
+
FX_FLOAT values[3];
for (int i = 0; i < 3; i++) {
values[i] = GetNumber(2 - i);
@@ -1341,7 +1345,7 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() {
FXSYS_Mul(pArray->GetNumber(i),
m_pCurStates->m_TextState.GetFontSize()) /
1000;
- };
+ }
return;
}
CFX_ByteString* pStrs = new CFX_ByteString[nsegs];
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index 1c4cc24208..8846c023e1 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -4,7 +4,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "pageint.h"
+#include "core/src/fpdfapi/fpdf_page/pageint.h"
#include <limits.h>
@@ -72,7 +72,7 @@ FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData,
}
return m_pSyntax->GetPos();
}
-void _PDF_ReplaceAbbr(CPDF_Object* pObj);
+
void CPDF_StreamContentParser::Handle_BeginImage() {
FX_FILESIZE savePos = m_pSyntax->GetPos();
CPDF_Dictionary* pDict = new CPDF_Dictionary;
@@ -102,7 +102,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
pDict->SetAt(key, pObj.release());
}
}
- _PDF_ReplaceAbbr(pDict);
+ PDF_ReplaceAbbr(pDict);
CPDF_Object* pCSObj = NULL;
if (pDict->KeyExist("ColorSpace")) {
pCSObj = pDict->GetElementValue("ColorSpace");
@@ -933,6 +933,7 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) {
m_Status = ToBeContinued;
m_InternalStage = PAGEPARSE_STAGE_GETCONTENT;
m_CurrentOffset = 0;
+
CPDF_Object* pContent = pPage->m_pFormDict->GetElementValue("Contents");
if (!pContent) {
m_Status = Done;
@@ -951,7 +952,6 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) {
m_pStreamArray = FX_Alloc(CPDF_StreamAcc*, m_nStreams);
} else {
m_Status = Done;
- return;
}
}
void CPDF_ContentParser::Start(CPDF_Form* pForm,
@@ -1006,11 +1006,7 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm,
}
m_nStreams = 0;
m_pSingleStream = new CPDF_StreamAcc;
- if (pForm->m_pDocument) {
- m_pSingleStream->LoadAllData(pForm->m_pFormStream, FALSE);
- } else {
- m_pSingleStream->LoadAllData(pForm->m_pFormStream, FALSE);
- }
+ m_pSingleStream->LoadAllData(pForm->m_pFormStream, FALSE);
m_pData = (uint8_t*)m_pSingleStream->GetData();
m_Size = m_pSingleStream->GetSize();
m_Status = ToBeContinued;
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index 6113e5ea4d..69f06881f9 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -449,4 +449,6 @@ class CPDF_PatternCS : public CPDF_ColorSpace {
CPDF_CountedColorSpace* m_pCountedBaseCS;
};
+void PDF_ReplaceAbbr(CPDF_Object* pObj);
+
#endif // CORE_SRC_FPDFAPI_FPDF_PAGE_PAGEINT_H_