1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Copyright 2014 PDFium Authors. All rights reserved.
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Use of this source code is governed by a BSD-style license that can be
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// found in the LICENSE file.
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "../../../include/fpdfapi/fpdf_page.h"
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "../../../include/fpdfapi/fpdf_module.h"
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "../../../include/fpdfapi/fpdf_serial.h"
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "pageint.h"
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define REQUIRE_PARAMS(count) if (m_ParamCount != count) { m_bAbort = TRUE; return; }
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCPDF_StreamContentParser::CPDF_StreamContentParser()
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_DefFontSize = 0;
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates = NULL;
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pLastTextObject = NULL;
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pPathPoints = NULL;
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_PathClipType = 0;
19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_PathPointCount = m_PathAllocSize = 0;
20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_PathCurrentX = m_PathCurrentY = 0.0f;
21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_bResourceMissing = FALSE;
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_bColored = FALSE;
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FXSYS_memset32(m_Type3Data, 0, sizeof(FX_FLOAT) * 6);
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamCount = 0;
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamStartPos = 0;
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_bAbort = FALSE;
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pLastImageDict = NULL;
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pLastCloneImageDict = NULL;
29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pLastImage = NULL;
30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_bReleaseLastDict = TRUE;
31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pParentResources = NULL;
32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _FPDFAPI_MINI_
33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pObjectState = NULL;
34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pObjectStack = NULL;
35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pWordBuf = NULL;
36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pDictName = NULL;
37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pStreamBuf = NULL;
38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_WordState = 0;
39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ObjectSize = 0;
40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
42ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_BOOL CPDF_StreamContentParser::Initialize()
43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _FPDFAPI_MINI_
45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pObjectState = FX_Alloc(FX_BOOL, _FPDF_MAX_OBJECT_STACK_SIZE_);
46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FXSYS_memset32(m_pObjectState, 0, _FPDF_MAX_OBJECT_STACK_SIZE_ * sizeof(FX_BOOL));
47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pObjectStack = FX_Alloc(CPDF_Object*, _FPDF_MAX_OBJECT_STACK_SIZE_);
48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FXSYS_memset32(m_pObjectStack, 0, _FPDF_MAX_OBJECT_STACK_SIZE_ * sizeof(CPDF_Object*));
49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pWordBuf = FX_Alloc(FX_BYTE, 256);
50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FXSYS_memset32(m_pWordBuf, 0, 256 * sizeof(FX_BYTE));
51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pDictName = FX_Alloc(FX_BYTE, 256);
52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FXSYS_memset32(m_pDictName, 0, 256 * sizeof(FX_BYTE));
53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pStreamBuf = FX_Alloc(FX_BYTE, STREAM_PARSE_BUFSIZE);
54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FXSYS_memset32(m_pStreamBuf, 0, STREAM_PARSE_BUFSIZE * sizeof(FX_BYTE));
55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_StringBuf.EstimateSize(1024);
56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ObjectSize = 0;
57ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ImageSrcBuf.EstimateSize(STREAM_PARSE_BUFSIZE);
58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return TRUE;
60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
61ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCPDF_StreamContentParser::~CPDF_StreamContentParser()
62ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
63ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ClearAllParams();
64ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int i = 0;
65ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (i = 0; i < m_StateStack.GetSize(); i ++) {
66ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        delete (CPDF_AllStates*)m_StateStack[i];
67ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
68ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_pPathPoints) {
69ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_Free(m_pPathPoints);
70ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
71ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_pCurStates) {
72ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        delete m_pCurStates;
73ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
74ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_pLastImageDict) {
75ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pLastImageDict->Release();
76ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
77ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_pLastCloneImageDict) {
78ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pLastCloneImageDict->Release();
79ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
80ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _FPDFAPI_MINI_
81ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (i = 0; i < (int)m_ObjectSize; ++i) {
82ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (!m_pObjectState[i]) {
83ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_pObjectStack[i]->Release();
84ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
85ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
86ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_Free(m_pObjectStack);
87ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_Free(m_pObjectState);
88ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_Free(m_pStreamBuf);
89ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_Free(m_pWordBuf);
90ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_Free(m_pDictName);
91ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
92ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
93ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::PrepareParse(CPDF_Document* pDocument,
94ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Dictionary* pPageResources, CPDF_Dictionary* pParentResources, CFX_AffineMatrix* pmtContentToUser, CPDF_PageObjects* pObjList,
95ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Dictionary* pResources, CPDF_Rect* pBBox, CPDF_ParseOptions* pOptions,
96ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_AllStates* pStates, int level)
97ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
98ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < 6; i ++) {
99ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_Type3Data[i] = 0;
100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pDocument = pDocument;
102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pPageResources = pPageResources;
103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pParentResources = pParentResources;
104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pmtContentToUser) {
105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_mtContentToUser = *pmtContentToUser;
106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pOptions) {
108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_Options = *pOptions;
109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pObjectList = pObjList;
111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pResources = pResources;
112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pResources == NULL) {
113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pResources = m_pParentResources;
114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_pResources == NULL) {
116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pResources = pPageResources;
117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pBBox) {
119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_BBox = *pBBox;
120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_Level = level;
122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates = FX_NEW CPDF_AllStates;
123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pStates) {
124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pCurStates->Copy(*pStates);
125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else {
126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pCurStates->m_GeneralState.New();
127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pCurStates->m_GraphState.New();
128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pCurStates->m_TextState.New();
129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pCurStates->m_ColorState.New();
130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _FPDFAPI_MINI_
132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FXSYS_memset32(m_pObjectState, 0, _FPDF_MAX_OBJECT_STACK_SIZE_ * sizeof(FX_BOOL));
133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovint CPDF_StreamContentParser::GetNextParamPos()
136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_ParamCount == PARAM_BUF_SIZE) {
138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_ParamStartPos ++;
139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_ParamStartPos == PARAM_BUF_SIZE) {
140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_ParamStartPos = 0;
141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) {
143ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_ParamBuf1[m_ParamStartPos].m_pObject->Release();
144ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
145ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_ParamStartPos;
146ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
147ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int index = m_ParamStartPos + m_ParamCount;
148ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (index >= PARAM_BUF_SIZE) {
149ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        index -= PARAM_BUF_SIZE;
150ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
151ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamCount ++;
152ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return index;
153ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
154ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::AddNameParam(FX_LPCSTR name, int len)
155ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
156ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int index = GetNextParamPos();
157ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (len > 32) {
158ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_ParamBuf1[index].m_Type = 0;
159ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_ParamBuf1[index].m_pObject = CPDF_Name::Create(PDF_NameDecode(CFX_ByteStringC(name, len)));
160ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else {
161ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_ParamBuf1[index].m_Type = PDFOBJ_NAME;
162ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (FXSYS_memchr(name, '#', len) == NULL) {
163ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            FXSYS_memcpy32(m_ParamBuf1[index].m_Name.m_Buffer, name, len);
164ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_ParamBuf1[index].m_Name.m_Len = len;
165ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        } else {
166ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len));
167ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            FXSYS_memcpy32(m_ParamBuf1[index].m_Name.m_Buffer, (FX_LPCSTR)str, str.GetLength());
168ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_ParamBuf1[index].m_Name.m_Len = str.GetLength();
169ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
170ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
171ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
172ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::AddNumberParam(FX_LPCSTR str, int len)
173ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
174ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int index = GetNextParamPos();
175ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamBuf1[index].m_Type = PDFOBJ_NUMBER;
176ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger,
177ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov              &m_ParamBuf1[index].m_Number.m_Integer);
178ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
179ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj)
180ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
181ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int index = GetNextParamPos();
182ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamBuf1[index].m_Type = 0;
183ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamBuf1[index].m_pObject = pObj;
184ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
185ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::ClearAllParams()
186ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
187ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD index = m_ParamStartPos;
188ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (FX_DWORD i = 0; i < m_ParamCount; i ++) {
189ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_ParamBuf1[index].m_Type == 0) {
190ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_ParamBuf1[index].m_pObject->Release();
191ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
192ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        index ++;
193ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (index == PARAM_BUF_SIZE) {
194ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            index = 0;
195ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
196ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
197ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamStartPos = 0;
198ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ParamCount = 0;
199ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
200ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index)
201ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
202ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (index >= m_ParamCount) {
203ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return NULL;
204ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
205ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int real_index = m_ParamStartPos + m_ParamCount - index - 1;
206ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (real_index >= PARAM_BUF_SIZE) {
207ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        real_index -= PARAM_BUF_SIZE;
208ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
209ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _ContentParam& param = m_ParamBuf1[real_index];
210ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (param.m_Type == PDFOBJ_NUMBER) {
211ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Number* pNumber = CPDF_Number::Create(param.m_Number.m_bInteger, &param.m_Number.m_Integer);
212ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        param.m_Type = 0;
213ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        param.m_pObject = pNumber;
214ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return pNumber;
215ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
216ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (param.m_Type == PDFOBJ_NAME) {
217ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Name* pName = CPDF_Name::Create(CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
218ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        param.m_Type = 0;
219ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        param.m_pObject = pName;
220ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return pName;
221ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
222ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (param.m_Type == 0) {
223ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return param.m_pObject;
224ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
225ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ASSERT(FALSE);
226ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return NULL;
227ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
228ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index)
229ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
230ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (index >= m_ParamCount) {
231ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_ByteString();
232ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
233ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int real_index = m_ParamStartPos + m_ParamCount - index - 1;
234ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (real_index >= PARAM_BUF_SIZE) {
235ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        real_index -= PARAM_BUF_SIZE;
236ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
237ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _ContentParam& param = m_ParamBuf1[real_index];
238ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (param.m_Type == PDFOBJ_NAME) {
239ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len);
240ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
241ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (param.m_Type == 0) {
242ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return param.m_pObject->GetString();
243ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
244ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return CFX_ByteString();
245ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
246ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index)
247ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
248ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (index >= m_ParamCount) {
249ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return 0;
250ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
251ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int real_index = m_ParamStartPos + m_ParamCount - index - 1;
252ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (real_index >= PARAM_BUF_SIZE) {
253ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        real_index -= PARAM_BUF_SIZE;
254ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
255ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _ContentParam& param = m_ParamBuf1[real_index];
256ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (param.m_Type == PDFOBJ_NUMBER) {
257ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer : param.m_Number.m_Float;
258ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
259ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (param.m_Type == 0) {
260ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return param.m_pObject->GetNumber();
261ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
262ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return 0;
263ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
264ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index)
265ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
266ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return GetNumber(index);
267ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
268ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL bColor, FX_BOOL bText, FX_BOOL bGraph)
269ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
270ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pObj->m_GeneralState = m_pCurStates->m_GeneralState;
271ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pObj->m_ClipPath = m_pCurStates->m_ClipPath;
272ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pObj->m_ContentMark = m_CurContentMark;
273ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (bColor) {
274ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pObj->m_ColorState = m_pCurStates->m_ColorState;
275ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
276ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (bGraph) {
277ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pObj->m_GraphState = m_pCurStates->m_GraphState;
278ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
279ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (bText) {
280ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pObj->m_TextState = m_pCurStates->m_TextState;
281ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
282ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
283ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovconst struct _OpCode {
284ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD	m_OpId;
285ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void (CPDF_StreamContentParser::*m_OpHandler)();
286ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov} g_OpCodes[] = {
287ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('"', 0, 0, 0),		&CPDF_StreamContentParser::Handle_NextLineShowText_Space},
288ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('\'', 0, 0, 0),		&CPDF_StreamContentParser::Handle_NextLineShowText},
289ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('B', 0, 0, 0),		&CPDF_StreamContentParser::Handle_FillStrokePath},
290ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('B', '*', 0, 0),	&CPDF_StreamContentParser::Handle_EOFillStrokePath},
291ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('B', 'D', 'C', 0),	&CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary},
292ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('B', 'I', 0, 0),	&CPDF_StreamContentParser::Handle_BeginImage},
293ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('B', 'M', 'C', 0),	&CPDF_StreamContentParser::Handle_BeginMarkedContent},
294ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('B', 'T', 0, 0),	&CPDF_StreamContentParser::Handle_BeginText},
295ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('B', 'X', 0, 0),	&CPDF_StreamContentParser::Handle_BeginSectionUndefined},
296ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('C', 'S', 0, 0),	&CPDF_StreamContentParser::Handle_SetColorSpace_Stroke},
297ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('D', 'P', 0, 0),	&CPDF_StreamContentParser::Handle_MarkPlace_Dictionary},
298ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('D', 'o', 0, 0),	&CPDF_StreamContentParser::Handle_ExecuteXObject},
299ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('E', 'I', 0, 0),	&CPDF_StreamContentParser::Handle_EndImage},
300ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('E', 'M', 'C', 0),	&CPDF_StreamContentParser::Handle_EndMarkedContent},
301ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('E', 'T', 0, 0),	&CPDF_StreamContentParser::Handle_EndText},
302ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('E', 'X', 0, 0),	&CPDF_StreamContentParser::Handle_EndSectionUndefined},
303ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('F', 0, 0, 0),		&CPDF_StreamContentParser::Handle_FillPathOld},
304ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('G', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetGray_Stroke},
305ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('I', 'D', 0, 0),	&CPDF_StreamContentParser::Handle_BeginImageData},
306ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('J', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetLineCap},
307ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('K', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke},
308ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('M', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetMiterLimit},
309ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('M', 'P', 0, 0),	&CPDF_StreamContentParser::Handle_MarkPlace},
310ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('Q', 0, 0, 0),		&CPDF_StreamContentParser::Handle_RestoreGraphState},
311ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('R', 'G', 0, 0),	&CPDF_StreamContentParser::Handle_SetRGBColor_Stroke},
312ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('S', 0, 0, 0),		&CPDF_StreamContentParser::Handle_StrokePath},
313ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('S', 'C', 0, 0),	&CPDF_StreamContentParser::Handle_SetColor_Stroke},
314ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('S', 'C', 'N', 0),	&CPDF_StreamContentParser::Handle_SetColorPS_Stroke},
315ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', '*', 0, 0),	&CPDF_StreamContentParser::Handle_MoveToNextLine},
316ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'D', 0, 0),	&CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading},
317ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'J', 0, 0),	&CPDF_StreamContentParser::Handle_ShowText_Positioning},
318ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'L', 0, 0),	&CPDF_StreamContentParser::Handle_SetTextLeading},
319ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'c', 0, 0),	&CPDF_StreamContentParser::Handle_SetCharSpace},
320ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'd', 0, 0),	&CPDF_StreamContentParser::Handle_MoveTextPoint},
321ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'f', 0, 0),	&CPDF_StreamContentParser::Handle_SetFont},
322ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'j', 0, 0),	&CPDF_StreamContentParser::Handle_ShowText},
323ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'm', 0, 0),	&CPDF_StreamContentParser::Handle_SetTextMatrix},
324ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'r', 0, 0),	&CPDF_StreamContentParser::Handle_SetTextRenderMode},
325ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 's', 0, 0),	&CPDF_StreamContentParser::Handle_SetTextRise},
326ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'w', 0, 0),	&CPDF_StreamContentParser::Handle_SetWordSpace},
327ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('T', 'z', 0, 0),	&CPDF_StreamContentParser::Handle_SetHorzScale},
328ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('W', 0, 0, 0),		&CPDF_StreamContentParser::Handle_Clip},
329ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('W', '*', 0, 0),	&CPDF_StreamContentParser::Handle_EOClip},
330ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('b', 0, 0, 0),		&CPDF_StreamContentParser::Handle_CloseFillStrokePath},
331ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('b', '*', 0, 0),	&CPDF_StreamContentParser::Handle_CloseEOFillStrokePath},
332ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('c', 0, 0, 0),		&CPDF_StreamContentParser::Handle_CurveTo_123},
333ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('c', 'm', 0, 0),	&CPDF_StreamContentParser::Handle_ConcatMatrix},
334ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('c', 's', 0, 0),	&CPDF_StreamContentParser::Handle_SetColorSpace_Fill},
335ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('d', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetDash},
336ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('d', '0', 0, 0),	&CPDF_StreamContentParser::Handle_SetCharWidth},
337ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('d', '1', 0, 0),	&CPDF_StreamContentParser::Handle_SetCachedDevice},
338ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('f', 0, 0, 0),		&CPDF_StreamContentParser::Handle_FillPath},
339ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('f', '*', 0, 0),	&CPDF_StreamContentParser::Handle_EOFillPath},
340ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('g', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetGray_Fill},
341ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('g', 's', 0, 0),	&CPDF_StreamContentParser::Handle_SetExtendGraphState},
342ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('h', 0, 0, 0),		&CPDF_StreamContentParser::Handle_ClosePath},
343ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('i', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetFlat},
344ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('j', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetLineJoin},
345ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('k', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetCMYKColor_Fill},
346ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('l', 0, 0, 0),		&CPDF_StreamContentParser::Handle_LineTo},
347ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('m', 0, 0, 0),		&CPDF_StreamContentParser::Handle_MoveTo},
348ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('n', 0, 0, 0),		&CPDF_StreamContentParser::Handle_EndPath},
349ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('q', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SaveGraphState},
350ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('r', 'e', 0, 0),	&CPDF_StreamContentParser::Handle_Rectangle},
351ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('r', 'g', 0, 0),	&CPDF_StreamContentParser::Handle_SetRGBColor_Fill},
352ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('r', 'i', 0, 0),	&CPDF_StreamContentParser::Handle_SetRenderIntent},
353ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('s', 0, 0, 0),		&CPDF_StreamContentParser::Handle_CloseStrokePath},
354ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('s', 'c', 0, 0),	&CPDF_StreamContentParser::Handle_SetColor_Fill},
355ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('s', 'c', 'n', 0),	&CPDF_StreamContentParser::Handle_SetColorPS_Fill},
356ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('s', 'h', 0, 0),	&CPDF_StreamContentParser::Handle_ShadeFill},
357ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('v', 0, 0, 0),		&CPDF_StreamContentParser::Handle_CurveTo_23},
358ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('w', 0, 0, 0),		&CPDF_StreamContentParser::Handle_SetLineWidth},
359ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {FXBSTR_ID('y', 0, 0, 0),		&CPDF_StreamContentParser::Handle_CurveTo_13},
360ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
361ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovFX_BOOL CPDF_StreamContentParser::OnOperator(FX_LPCSTR op)
362ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
363ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int i = 0;
364ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD opid = 0;
365ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    while (i < 4 && op[i]) {
366ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        opid = (opid << 8) + op[i];
367ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        i ++;
368ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
369ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    while (i < 4) {
370ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        opid <<= 8;
371ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        i ++;
372ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    };
373ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int low = 0, high = sizeof g_OpCodes / sizeof(struct _OpCode) - 1;
374ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    while (low <= high) {
375ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        int middle = (low + high) / 2;
376ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        int compare = opid - g_OpCodes[middle].m_OpId;
377ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (compare == 0) {
378ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            (this->*g_OpCodes[middle].m_OpHandler)();
379ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return TRUE;
380ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        } else if (compare < 0) {
381ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            high = middle - 1;
382ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        } else {
383ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            low = middle + 1;
384ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
385ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
386ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return m_CompatCount != 0;
387ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
388ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_CloseFillStrokePath()
389ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
390ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
391ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
392ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
393ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    Handle_ClosePath();
394ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(FXFILL_WINDING, TRUE);
395ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
396ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_FillStrokePath()
397ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
398ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
399ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
400ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
401ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(FXFILL_WINDING, TRUE);
402ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
403ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_CloseEOFillStrokePath()
404ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
405ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
406ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
407ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
408ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
409ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(FXFILL_ALTERNATE, TRUE);
410ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
411ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_EOFillStrokePath()
412ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
413ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
414ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
415ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
416ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(FXFILL_ALTERNATE, TRUE);
417ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
418ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary()
419ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
420ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (!m_Options.m_bMarkedContent) {
421ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
422ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
423ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteString tag = GetString(1);
424ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_Object* pProperty = GetObject(0);
425ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pProperty == NULL) {
426ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
427ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
428ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL bDirect = TRUE;
429ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pProperty->GetType() == PDFOBJ_NAME) {
430ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pProperty = FindResourceObj(FX_BSTRC("Properties"), pProperty->GetString());
431ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (pProperty == NULL) {
432ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return;
433ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
434ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        bDirect = FALSE;
435ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
436ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pProperty->GetType() != PDFOBJ_DICTIONARY) {
437ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
438ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
439ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_CurContentMark.GetModify()->AddMark(tag, (CPDF_Dictionary*)pProperty, bDirect);
440ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
441ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_BeginMarkedContent()
442ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
443ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (!m_Options.m_bMarkedContent) {
444ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
445ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
446ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteString tag = GetString(0);
447ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
448ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
449ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovstruct _FX_BSTR {
450ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPCSTR	m_Ptr;
451ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int			m_Size;
452ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
453ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_BSTRC(str) {str, sizeof(str)-1}
454ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovconst _FX_BSTR _PDF_InlineKeyAbbr[] = {
455ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("BitsPerComponent"), _FX_BSTRC("BPC"),
456ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("ColorSpace"), _FX_BSTRC("CS"),
457ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("Decode"), _FX_BSTRC("D"),
458ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("DecodeParms"), _FX_BSTRC("DP"),
459ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("Filter"), _FX_BSTRC("F"),
460ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("Height"), _FX_BSTRC("H"),
461ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("ImageMask"), _FX_BSTRC("IM"),
462ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("Interpolate"), _FX_BSTRC("I"),
463ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("Width"), _FX_BSTRC("W"),
464ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
465ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovconst _FX_BSTR _PDF_InlineValueAbbr[] = {
466ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("DeviceGray"), _FX_BSTRC("G"),
467ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB"),
468ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK"),
469ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("Indexed"), _FX_BSTRC("I"),
470ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx"),
471ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85"),
472ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW"),
473ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl"),
474ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"),
475ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"),
476ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"),
477ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
478ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovstatic CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table, int count, FX_BSTR abbr)
479ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
480ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int i = 0;
481ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    while (i < count) {
482ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (abbr.GetLength() == table[i + 1].m_Size && FXSYS_memcmp32(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) == 0) {
483ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size);
484ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
485ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        i += 2;
486ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
487ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return CFX_ByteStringC();
488ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
489ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid _PDF_ReplaceAbbr(CPDF_Object* pObj)
490ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
491ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    switch (pObj->GetType()) {
492ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        case PDFOBJ_DICTIONARY: {
493ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
494ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                FX_POSITION pos = pDict->GetStartPos();
495ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                while (pos) {
496ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CFX_ByteString key;
497ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CPDF_Object* value = pDict->GetNextElement(pos, key);
498ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CFX_ByteStringC fullname = _PDF_FindFullName(_PDF_InlineKeyAbbr,
499ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                               sizeof _PDF_InlineKeyAbbr / sizeof(_FX_BSTR), key);
500ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    if (!fullname.IsEmpty()) {
501ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        pDict->ReplaceKey(key, fullname);
502ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        key = fullname;
503ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    }
504ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    if (value->GetType() == PDFOBJ_NAME) {
505ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        CFX_ByteString name = value->GetString();
506ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        fullname = _PDF_FindFullName(_PDF_InlineValueAbbr,
507ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                                     sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
508ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        if (!fullname.IsEmpty()) {
509ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                            pDict->SetAtName(key, fullname);
510ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        }
511ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    } else {
512ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        _PDF_ReplaceAbbr(value);
513ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    }
514ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
515ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                break;
516ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
517ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        case PDFOBJ_ARRAY: {
518ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                CPDF_Array* pArray = (CPDF_Array*)pObj;
519ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {
520ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CPDF_Object* pElement = pArray->GetElement(i);
521ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    if (pElement->GetType() == PDFOBJ_NAME) {
522ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        CFX_ByteString name = pElement->GetString();
523ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        CFX_ByteStringC fullname = _PDF_FindFullName(_PDF_InlineValueAbbr,
524ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                                   sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
525ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        if (!fullname.IsEmpty()) {
526ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                            pArray->SetAt(i, CPDF_Name::Create(fullname));
527ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        }
528ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    } else {
529ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        _PDF_ReplaceAbbr(pElement);
530ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    }
531ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
532ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                break;
533ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
534ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
535ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
536ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovstatic CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table, int count, FX_BSTR fullName)
537ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
538ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int i = 0;
539ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    while (i < count) {
540ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (fullName.GetLength() == table[i].m_Size && FXSYS_memcmp32(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) == 0) {
541ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);
542ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
543ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        i += 2;
544ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
545ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return CFX_ByteStringC();
546ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
547ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid _PDF_ReplaceFull(CPDF_Object* pObj)
548ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
549ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    switch (pObj->GetType()) {
550ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        case PDFOBJ_DICTIONARY: {
551ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
552ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                FX_POSITION pos = pDict->GetStartPos();
553ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                while (pos) {
554ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CFX_ByteString key;
555ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CPDF_Object* value = pDict->GetNextElement(pos, key);
556ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CFX_ByteStringC abbrName = _PDF_FindAbbrName(_PDF_InlineKeyAbbr,
557ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                               sizeof(_PDF_InlineKeyAbbr) / sizeof(_FX_BSTR), key);
558ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    if (!abbrName.IsEmpty()) {
559ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        pDict->ReplaceKey(key, abbrName);
560ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        key = abbrName;
561ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    }
562ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    if (value->GetType() == PDFOBJ_NAME) {
563ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        CFX_ByteString name = value->GetString();
564ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        abbrName = _PDF_FindAbbrName(_PDF_InlineValueAbbr,
565ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                                     sizeof(_PDF_InlineValueAbbr) / sizeof(_FX_BSTR), name);
566ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        if (!abbrName.IsEmpty()) {
567ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                            pDict->SetAtName(key, abbrName);
568ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        }
569ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    } else {
570ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        _PDF_ReplaceFull(value);
571ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    }
572ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
573ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                break;
574ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
575ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        case PDFOBJ_ARRAY: {
576ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                CPDF_Array* pArray = (CPDF_Array*)pObj;
577ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {
578ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    CPDF_Object* pElement = pArray->GetElement(i);
579ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    if (pElement->GetType() == PDFOBJ_NAME) {
580ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        CFX_ByteString name = pElement->GetString();
581ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        CFX_ByteStringC abbrName = _PDF_FindAbbrName(_PDF_InlineValueAbbr,
582ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                                                   sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
583ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        if (!abbrName.IsEmpty()) {
584ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                            pArray->SetAt(i, CPDF_Name::Create(abbrName));
585ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        }
586ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    } else {
587ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                        _PDF_ReplaceFull(pElement);
588ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    }
589ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
590ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                break;
591ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
592ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
593ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
594ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_BeginText()
595ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
596ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0);
597ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    OnChangeTextMatrix();
598ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_TextX = 0;
599ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_TextY = 0;
600ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_TextLineX = 0;
601ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_TextLineY = 0;
602ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
603ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_BeginSectionUndefined()
604ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
605ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_CompatCount ++;
606ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
607ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_CurveTo_123()
608ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
609ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
610ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
611ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
612ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO);
613ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
614ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
615ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
616ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_ConcatMatrix()
617ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
618ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3), d2 = GetNumber16(2);
619ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0);
620ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT old_width_scale = m_pCurStates->m_CTM.GetXUnit();
621ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_AffineMatrix new_matrix(a2, b2, c2, d2, e2, f2);
622ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    new_matrix.Concat(m_pCurStates->m_CTM);
623ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_CTM = new_matrix;
624ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT new_width_scale = m_pCurStates->m_CTM.GetXUnit();
625ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    OnChangeTextMatrix();
626ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
627ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetColorSpace_Fill()
628ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
629ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
630ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
631ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
632ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteString csname = GetString(0);
633ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = FindColorSpace(csname);
634ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pCS == NULL) {
635ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
636ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
637ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.GetModify()->m_FillColor.SetColorSpace(pCS);
638ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
639ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetColorSpace_Stroke()
640ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
641ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
642ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
643ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
644ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteString csname = GetString(0);
645ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = FindColorSpace(csname);
646ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pCS == NULL) {
647ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
648ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
649ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.GetModify()->m_StrokeColor.SetColorSpace(pCS);
650ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
651ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetDash()
652ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
653ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
654ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
655ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
656ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_Array* pArray = GetObject(1)->GetArray();
657ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pArray == NULL) {
658ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
659ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
660ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f);
661ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
662ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetCharWidth()
663ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
664ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_Type3Data[0] = GetNumber(1);
665ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_Type3Data[1] = GetNumber(0);
666ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_bColored = TRUE;
667ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
668ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetCachedDevice()
669ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
670ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < 6; i ++) {
671ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_Type3Data[i] = GetNumber(5 - i);
672ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
673ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_bColored = FALSE;
674ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
675ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_ExecuteXObject()
676ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
677ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteString name = GetString(0);
678ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() && m_pLastImage->GetStream()->GetObjNum()) {
679ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if defined(_FPDFAPI_MINI_) && !defined(_FXCORE_FEATURE_ALL_)
680ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AddDuplicateImage();
681ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
682ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AddImage(NULL, m_pLastImage, FALSE);
683ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
684ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
685ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
686ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
687ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Object* pRes = NULL;
688ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_pResources == NULL) {
689ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return;
690ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
691ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_pResources == m_pPageResources) {
692ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
693ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            if (pList == NULL) {
694ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                return;
695ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
696ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            pRes = pList->GetElement(name);
697ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
698ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                return;
699ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
700ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        } else {
701ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
702ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            if (pList == NULL) {
703ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                if (m_pPageResources == NULL) {
704ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    return;
705ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
706ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                CPDF_Dictionary* pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));
707ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                if (pList == NULL) {
708ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    return;
709ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
710ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                pRes = pList->GetElement(name);
711ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
712ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    return;
713ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
714ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            } else {
715ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                pRes = pList->GetElement(name);
716ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
717ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                    return;
718ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                }
719ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
720ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
721ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_BOOL bForm;
722ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(), bForm) && !bForm) {
723ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return;
724ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
725ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
726ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_Stream* pXObject = (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), name);
727ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) {
728ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_bResourceMissing = TRUE;
729ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
730ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
731ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteStringC type = pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype"));
732ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (type == FX_BSTRC("Image")) {
733ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_Options.m_bTextOnly) {
734ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return;
735ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
736ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE);
737ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_LastImageName = name;
738ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pLastImage = pObj->m_pImage;
739ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else if (type == FX_BSTRC("Form")) {
740ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AddForm(pXObject);
741ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else {
742ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
743ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
744ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
745ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream)
746ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
747ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if !defined(_FPDFAPI_MINI_) || defined(_FXCORE_FEATURE_ALL_)
748ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (!m_Options.m_bSeparateForm) {
749ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Dictionary* pResources = pStream->GetDict()->GetDict(FX_BSTRC("Resources"));
750ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_AffineMatrix form_matrix = pStream->GetDict()->GetMatrix(FX_BSTRC("Matrix"));
751ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        form_matrix.Concat(m_pCurStates->m_CTM);
752ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox"));
753ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_FloatRect form_bbox;
754ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_Path ClipPath;
755ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (pBBox) {
756ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox"));
757ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ClipPath.New();
758ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, form_bbox.top);
759ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ClipPath.Transform(&form_matrix);
760ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            form_bbox.Transform(&form_matrix);
761ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
762ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_StreamContentParser parser;
763ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        parser.Initialize();
764ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        parser.PrepareParse(m_pDocument, m_pPageResources, m_pResources, &m_mtContentToUser,
765ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                            m_pObjectList, pResources, &form_bbox, &m_Options, m_pCurStates, m_Level + 1);
766ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        parser.m_pCurStates->m_CTM = form_matrix;
767ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (ClipPath.NotNull()) {
768ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE);
769ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
770ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_StreamAcc stream;
771ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        stream.LoadAllData(pStream, FALSE);
772ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (stream.GetSize() == 0) {
773ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return;
774ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
775ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifdef _FPDFAPI_MINI_
776ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        parser.InputData(stream.GetData(), stream.GetSize());
777ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        parser.Finish();
778ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#else
779ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        parser.Parse(stream.GetData(), stream.GetSize(), 0);
780ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
781ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
782ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
783ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
784ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_FormObject* pFormObj = FX_NEW CPDF_FormObject;
785ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pFormObj->m_pForm = FX_NEW CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);
786ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pFormObj->m_FormMatrix = m_pCurStates->m_CTM;
787ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pFormObj->m_FormMatrix.Concat(m_mtContentToUser);
788ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_AllStates status;
789ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    status.m_GeneralState = m_pCurStates->m_GeneralState;
790ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    status.m_GraphState = m_pCurStates->m_GraphState;
791ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    status.m_ColorState = m_pCurStates->m_ColorState;
792ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    status.m_TextState = m_pCurStates->m_TextState;
793ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1);
794ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (!m_pObjectList->m_bBackgroundAlphaNeeded && pFormObj->m_pForm->m_bBackgroundAlphaNeeded) {
795ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pObjectList->m_bBackgroundAlphaNeeded = TRUE;
796ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
797ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pFormObj->CalcBoundingBox();
798ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    SetGraphicStates(pFormObj, TRUE, TRUE, TRUE);
799ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pObjectList->m_ObjectList.AddTail(pFormObj);
800ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
801ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if defined(_FPDFAPI_MINI_) && !defined(_FXCORE_FEATURE_ALL_)
802ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::AddDuplicateImage()
803ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
804ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION tailpos = m_pObjectList->m_ObjectList.GetTailPosition();
805ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_PageObject* pLastObj = (CPDF_PageObject*)m_pObjectList->m_ObjectList.GetAt(tailpos);
806ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pLastObj == NULL || (pLastObj->m_Type != PDFPAGE_INLINES && pLastObj->m_Type != PDFPAGE_IMAGE)) {
807ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AddImage(NULL, m_pLastImage, FALSE);
808ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
809ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
810ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pLastObj->m_GeneralState != m_pCurStates->m_GeneralState ||
811ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            pLastObj->m_ClipPath != m_pCurStates->m_ClipPath ||
812ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            pLastObj->m_ColorState != m_pCurStates->m_ColorState) {
813ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AddImage(NULL, m_pLastImage, FALSE);
814ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
815ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
816ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_AffineMatrix ImageMatrix;
817ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ImageMatrix.Copy(m_pCurStates->m_CTM);
818ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ImageMatrix.Concat(m_mtContentToUser);
819ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pLastObj->m_Type == PDFPAGE_INLINES) {
820ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_InlineImages* pInlines = (CPDF_InlineImages*)pLastObj;
821ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (pInlines->m_pStream != m_pLastImage->GetStream()) {
822ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            AddImage(NULL, m_pLastImage, FALSE);
823ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return;
824ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
825ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pInlines->AddMatrix(ImageMatrix);
826ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else {
827ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_ImageObject* pImageObj = (CPDF_ImageObject*)pLastObj;
828ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CPDF_InlineImages* pInlines = FX_NEW CPDF_InlineImages;
829ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pInlines->m_pStream = m_pLastImage->GetStream();
830ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        SetGraphicStates(pInlines, !pInlines->m_pStream->GetDict()->KeyExist(FX_BSTRC("ColorSpace")), FALSE, FALSE);
831ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pInlines->AddMatrix(pImageObj->m_Matrix);
832ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pInlines->AddMatrix(ImageMatrix);
833ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pObjectList->m_ObjectList.RemoveAt(tailpos);
834ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pObjectList->m_ObjectList.AddTail(pInlines);
835ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pLastObj->Release();
836ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
837ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
838ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
839ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, CPDF_Image* pImage, FX_BOOL bInline)
840ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
841ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pStream == NULL && pImage == NULL) {
842ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return NULL;
843ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
844ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_AffineMatrix ImageMatrix;
845ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ImageMatrix.Copy(m_pCurStates->m_CTM);
846ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ImageMatrix.Concat(m_mtContentToUser);
847ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
848ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pImage) {
849ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pImage->GetStream());
850ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else if (pStream->GetObjNum()) {
851ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pImageObj->m_pImage = m_pDocument->LoadImageF(pStream);
852ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else {
853ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pImageObj->m_pImage = FX_NEW CPDF_Image(m_pDocument);
854ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pImageObj->m_pImage->LoadImageF(pStream, bInline);
855ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
856ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE);
857ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pImageObj->m_Matrix = ImageMatrix;
858ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pImageObj->CalcBoundingBox();
859ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pObjectList->m_ObjectList.AddTail(pImageObj);
860ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    return pImageObj;
861ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
862ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_MarkPlace_Dictionary()
863ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
864ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
865ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_EndImage()
866ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
867ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
868ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_EndMarkedContent()
869ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
870ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (!m_Options.m_bMarkedContent) {
871ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
872ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
873ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_CurContentMark.IsNull()) {
874ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
875ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
876ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int count = m_CurContentMark.GetObject()->CountItems();
877ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (count == 1) {
878ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_CurContentMark.SetNull();
879ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
880ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
881ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_CurContentMark.GetModify()->DeleteLastMark();
882ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
883ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_EndText()
884ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
885ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int count = m_ClipTextList.GetSize();
886ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (count == 0) {
887ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
888ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
889ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_pCurStates->m_TextState.GetObject()->m_TextMode < 4) {
890ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        for (int i = 0; i < count; i ++) {
891ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            CPDF_TextObject* pText = (CPDF_TextObject*)m_ClipTextList.GetAt(i);
892ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            if (pText) {
893ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                delete pText;
894ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
895ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
896ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else {
897ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pCurStates->m_ClipPath.AppendTexts((CPDF_TextObject**)m_ClipTextList.GetData(), count);
898ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
899ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_ClipTextList.RemoveAll();
900ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
901ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_EndSectionUndefined()
902ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
903ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_CompatCount) {
904ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_CompatCount --;
905ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
906ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
907ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_FillPath()
908ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
909ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
910ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
911ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
912ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(FXFILL_WINDING, FALSE);
913ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
914ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_FillPathOld()
915ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
916ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
917ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
918ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
919ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(FXFILL_WINDING, FALSE);
920ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
921ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_EOFillPath()
922ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
923ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
924ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
925ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
926ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(FXFILL_ALTERNATE, FALSE);
927ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
928ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetGray_Fill()
929ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
930ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT value = GetNumber(0);
931ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
932ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetFillColor(pCS, &value, 1);
933ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
934ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetGray_Stroke()
935ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
936ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT value = GetNumber(0);
937ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
938ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetStrokeColor(pCS, &value, 1);
939ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
940ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetExtendGraphState()
941ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
942ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteString name = GetString(0);
943ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_Dictionary* pGS = (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("ExtGState"), name);
944ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (pGS == NULL || pGS->GetType() != PDFOBJ_DICTIONARY) {
945ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_bResourceMissing = TRUE;
946ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
947ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
948ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->ProcessExtGS(pGS, this);
949ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
950ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_ClosePath()
951ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
952ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
953ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
954ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
955ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_PathPointCount == 0) {
956ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
957ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
958ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_PathStartX != m_PathCurrentX || m_PathStartY != m_PathCurrentY) {
959ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
960ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    } else if (m_pPathPoints[m_PathPointCount - 1].m_Flag != FXPT_MOVETO) {
961ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pPathPoints[m_PathPointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
962ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
963ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
964ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetFlat()
965ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
966ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#if !defined(_FPDFAPI_MINI_) || defined(_FXCORE_FEATURE_ALL_)
967ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_GeneralState.GetModify()->m_Flatness = GetNumber(0);
968ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
969ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
970ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_BeginImageData()
971ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
972ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
973ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetLineJoin()
974ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
975ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_GraphState.GetModify()->m_LineJoin = (CFX_GraphStateData::LineJoin)GetInteger(0);
976ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
977ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetLineCap()
978ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
979ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_GraphState.GetModify()->m_LineCap = (CFX_GraphStateData::LineCap)GetInteger(0);
980ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
981ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetCMYKColor_Fill()
982ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
983ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    REQUIRE_PARAMS(4);
984ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT values[4];
985ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < 4; i ++) {
986ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        values[i] = GetNumber(3 - i);
987ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
988ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
989ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4);
990ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
991ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke()
992ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
993ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    REQUIRE_PARAMS(4);
994ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT values[4];
995ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < 4; i ++) {
996ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        values[i] = GetNumber(3 - i);
997ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
998ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
999ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4);
1000ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1001ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_LineTo()
1002ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1003ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    REQUIRE_PARAMS(2);
1004ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1005ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1006ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1007ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO);
1008ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1009ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_MoveTo()
1010ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1011ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    REQUIRE_PARAMS(2);
1012ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1013ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FPDFAPI_MINI_
1014ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pSyntax->SkipPathObject();
1015ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
1016ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1017ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1018ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_MOVETO);
1019ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FPDFAPI_MINI_
1020ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ParsePathObject();
1021ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
1022ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1023ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetMiterLimit()
1024ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1025ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_GraphState.GetModify()->m_MiterLimit = GetNumber(0);
1026ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1027ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_MarkPlace()
1028ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1029ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1030ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_EndPath()
1031ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1032ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1033ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1034ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1035ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(0, FALSE);
1036ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1037ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SaveGraphState()
1038ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1039ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_AllStates* pStates = FX_NEW CPDF_AllStates;
1040ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    pStates->Copy(*m_pCurStates);
1041ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_StateStack.Add(pStates);
1042ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1043ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_RestoreGraphState()
1044ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1045ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int size = m_StateStack.GetSize();
1046ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (size == 0) {
1047ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1048ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1049ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_AllStates* pStates = (CPDF_AllStates*)m_StateStack.GetAt(size - 1);
1050ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->Copy(*pStates);
1051ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    delete pStates;
1052ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_StateStack.RemoveAt(size - 1);
1053ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1054ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_Rectangle()
1055ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1056ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1057ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1058ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1059ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT x = GetNumber(3), y = GetNumber(2);
1060ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT w = GetNumber(1), h = GetNumber(0);
1061ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathRect(x, y, w, h);
1062ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1063ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, FX_FLOAT h)
1064ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1065ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(x, y, FXPT_MOVETO);
1066ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(x + w, y, FXPT_LINETO);
1067ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(x + w, y + h, FXPT_LINETO);
1068ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(x, y + h, FXPT_LINETO);
1069ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathPoint(x, y, FXPT_LINETO | FXPT_CLOSEFIGURE);
1070ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1071ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetRGBColor_Fill()
1072ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1073ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    REQUIRE_PARAMS(3);
1074ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT values[3];
1075ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < 3; i ++) {
1076ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        values[i] = GetNumber(2 - i);
1077ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1078ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
1079ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3);
1080ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1081ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetRGBColor_Stroke()
1082ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1083ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    REQUIRE_PARAMS(3);
1084ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT values[3];
1085ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < 3; i ++) {
1086ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        values[i] = GetNumber(2 - i);
1087ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1088ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
1089ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 3);
1090ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1091ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetRenderIntent()
1092ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1093ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1094ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_CloseStrokePath()
1095ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1096ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1097ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1098ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1099ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    Handle_ClosePath();
1100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(0, TRUE);
1101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_StrokePath()
1103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    AddPathObject(0, TRUE);
1108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetColor_Fill()
1110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT values[4];
1115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int nargs = m_ParamCount;
1116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (nargs > 4) {
1117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        nargs = 4;
1118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < nargs; i ++) {
1120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        values[i] = GetNumber(nargs - i - 1);
1121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetFillColor(NULL, values, nargs);
1123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetColor_Stroke()
1125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_FLOAT values[4];
1130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int nargs = m_ParamCount;
1131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (nargs > 4) {
1132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        nargs = 4;
1133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    for (int i = 0; i < nargs; i ++) {
1135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        values[i] = GetNumber(nargs - i - 1);
1136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nargs);
1138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}
1139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovvoid CPDF_StreamContentParser::Handle_SetColorPS_Fill()
1140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    if (m_Options.m_bTextOnly) {
1142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return;
1143ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1144ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov