summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp38
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h14
2 files changed, 11 insertions, 41 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index fe07a63bca..3018630463 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -340,7 +340,7 @@ void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj,
}
}
-const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] = {
+const CPDF_StreamContentParser::OpCodes CPDF_StreamContentParser::s_OpCodes = {
{FXBSTR_ID('"', 0, 0, 0),
&CPDF_StreamContentParser::Handle_NextLineShowText_Space},
{FXBSTR_ID('\'', 0, 0, 0),
@@ -354,8 +354,6 @@ const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] = {
{FXBSTR_ID('B', 'M', 'C', 0),
&CPDF_StreamContentParser::Handle_BeginMarkedContent},
{FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText},
- {FXBSTR_ID('B', 'X', 0, 0),
- &CPDF_StreamContentParser::Handle_BeginSectionUndefined},
{FXBSTR_ID('C', 'S', 0, 0),
&CPDF_StreamContentParser::Handle_SetColorSpace_Stroke},
{FXBSTR_ID('D', 'P', 0, 0),
@@ -366,8 +364,6 @@ const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] = {
{FXBSTR_ID('E', 'M', 'C', 0),
&CPDF_StreamContentParser::Handle_EndMarkedContent},
{FXBSTR_ID('E', 'T', 0, 0), &CPDF_StreamContentParser::Handle_EndText},
- {FXBSTR_ID('E', 'X', 0, 0),
- &CPDF_StreamContentParser::Handle_EndSectionUndefined},
{FXBSTR_ID('F', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPathOld},
{FXBSTR_ID('G', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Stroke},
{FXBSTR_ID('I', 'D', 0, 0),
@@ -451,7 +447,7 @@ const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] = {
{FXBSTR_ID('y', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_13},
};
-FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) {
+void CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) {
int i = 0;
FX_DWORD opid = 0;
while (i < 4 && op[i]) {
@@ -462,21 +458,10 @@ FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) {
opid <<= 8;
i++;
}
- int low = 0, high = sizeof g_OpCodes / sizeof(OpCode) - 1;
- while (low <= high) {
- int middle = (low + high) / 2;
- int compare = opid - g_OpCodes[middle].m_OpId;
- if (compare == 0) {
- (this->*g_OpCodes[middle].m_OpHandler)();
- return TRUE;
- }
- if (compare < 0) {
- high = middle - 1;
- } else {
- low = middle + 1;
- }
- }
- return m_CompatCount != 0;
+
+ auto it = s_OpCodes.find(opid);
+ if (it != s_OpCodes.end())
+ (this->*it->second)();
}
void CPDF_StreamContentParser::Handle_CloseFillStrokePath() {
@@ -625,10 +610,6 @@ void CPDF_StreamContentParser::Handle_BeginText() {
m_pCurStates->m_TextLineY = 0;
}
-void CPDF_StreamContentParser::Handle_BeginSectionUndefined() {
- m_CompatCount++;
-}
-
void CPDF_StreamContentParser::Handle_CurveTo_123() {
if (m_Options.m_bTextOnly) {
return;
@@ -863,12 +844,6 @@ void CPDF_StreamContentParser::Handle_EndText() {
m_ClipTextList.RemoveAll();
}
-void CPDF_StreamContentParser::Handle_EndSectionUndefined() {
- if (m_CompatCount) {
- m_CompatCount--;
- }
-}
-
void CPDF_StreamContentParser::Handle_FillPath() {
if (m_Options.m_bTextOnly) {
return;
@@ -1642,7 +1617,6 @@ FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData,
FX_DWORD InitObjCount = m_pObjectHolder->GetPageObjectList()->size();
CPDF_StreamParser syntax(pData, dwSize);
CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax);
- m_CompatCount = 0;
while (1) {
FX_DWORD cost = m_pObjectHolder->GetPageObjectList()->size() - InitObjCount;
if (max_cost && cost >= max_cost) {
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index fb95b6b30d..a36b848bca 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
+#include <unordered_map>
#include <vector>
#include "core/include/fpdfapi/fpdf_page.h"
@@ -117,7 +118,7 @@ class CPDF_StreamContentParser {
FX_FLOAT GetNumber(FX_DWORD index);
FX_FLOAT GetNumber16(FX_DWORD index);
int GetInteger(FX_DWORD index) { return (int32_t)(GetNumber(index)); }
- FX_BOOL OnOperator(const FX_CHAR* op);
+ void OnOperator(const FX_CHAR* op);
void BigCaseCaller(int index);
FX_DWORD GetParsePos() { return m_pSyntax->GetPos(); }
void AddTextObject(CFX_ByteString* pText,
@@ -151,11 +152,9 @@ class CPDF_StreamContentParser {
const CFX_ByteString& name);
protected:
- struct OpCode {
- FX_DWORD m_OpId;
- void (CPDF_StreamContentParser::*m_OpHandler)();
- };
- static const OpCode g_OpCodes[];
+ using OpCodes =
+ std::unordered_map<FX_DWORD, void (CPDF_StreamContentParser::*)()>;
+ static const OpCodes s_OpCodes;
void Handle_CloseFillStrokePath();
void Handle_FillStrokePath();
@@ -165,7 +164,6 @@ class CPDF_StreamContentParser {
void Handle_BeginImage();
void Handle_BeginMarkedContent();
void Handle_BeginText();
- void Handle_BeginSectionUndefined();
void Handle_CurveTo_123();
void Handle_ConcatMatrix();
void Handle_SetColorSpace_Fill();
@@ -178,7 +176,6 @@ class CPDF_StreamContentParser {
void Handle_EndImage();
void Handle_EndMarkedContent();
void Handle_EndText();
- void Handle_EndSectionUndefined();
void Handle_FillPath();
void Handle_FillPathOld();
void Handle_EOFillPath();
@@ -250,7 +247,6 @@ class CPDF_StreamContentParser {
CFX_ArrayTemplate<CPDF_TextObject*> m_ClipTextList;
CPDF_TextObject* m_pLastTextObject;
FX_FLOAT m_DefFontSize;
- int m_CompatCount;
FX_PATHPOINT* m_pPathPoints;
int m_PathPointCount;
int m_PathAllocSize;