Fix the issue that pdfium swallows 'fi' or 'ff' in some pdf files
[pdfium.git] / core / src / fpdfapi / fpdf_page / fpdf_page_parser.cpp
index 40f6d04..4e5ef1c 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../../include/fpdfapi/fpdf_page.h"\r
-#include "../../../include/fpdfapi/fpdf_module.h"\r
-#include "../../../include/fpdfapi/fpdf_serial.h"\r
-#include "pageint.h"\r
-#define REQUIRE_PARAMS(count) if (m_ParamCount != count) { m_bAbort = TRUE; return; }\r
-CPDF_StreamContentParser::CPDF_StreamContentParser()\r
-{\r
-    m_DefFontSize = 0;\r
-    m_pCurStates = NULL;\r
-    m_pLastTextObject = NULL;\r
-    m_pPathPoints = NULL;\r
-    m_PathClipType = 0;\r
-    m_PathPointCount = m_PathAllocSize = 0;\r
-    m_PathCurrentX = m_PathCurrentY = 0.0f;\r
-    m_bResourceMissing = FALSE;\r
-    m_bColored = FALSE;\r
-    FXSYS_memset32(m_Type3Data, 0, sizeof(FX_FLOAT) * 6);\r
-    m_ParamCount = 0;\r
-    m_ParamStartPos = 0;\r
-    m_bAbort = FALSE;\r
-    m_pLastImageDict = NULL;\r
-    m_pLastCloneImageDict = NULL;\r
-    m_pLastImage = NULL;\r
-    m_bReleaseLastDict = TRUE;\r
-    m_pParentResources = NULL;\r
-#ifdef _FPDFAPI_MINI_\r
-    m_pObjectState = NULL;\r
-    m_pObjectStack = NULL;\r
-    m_pWordBuf = NULL;\r
-    m_pDictName = NULL;\r
-    m_pStreamBuf = NULL;\r
-    m_WordState = 0;\r
-    m_ObjectSize = 0;\r
-#endif\r
-}\r
-FX_BOOL CPDF_StreamContentParser::Initialize()\r
-{\r
-#ifdef _FPDFAPI_MINI_\r
-    m_pObjectState = FX_Alloc(FX_BOOL, _FPDF_MAX_OBJECT_STACK_SIZE_);\r
-    FXSYS_memset32(m_pObjectState, 0, _FPDF_MAX_OBJECT_STACK_SIZE_ * sizeof(FX_BOOL));\r
-    m_pObjectStack = FX_Alloc(CPDF_Object*, _FPDF_MAX_OBJECT_STACK_SIZE_);\r
-    FXSYS_memset32(m_pObjectStack, 0, _FPDF_MAX_OBJECT_STACK_SIZE_ * sizeof(CPDF_Object*));\r
-    m_pWordBuf = FX_Alloc(FX_BYTE, 256);\r
-    FXSYS_memset32(m_pWordBuf, 0, 256 * sizeof(FX_BYTE));\r
-    m_pDictName = FX_Alloc(FX_BYTE, 256);\r
-    FXSYS_memset32(m_pDictName, 0, 256 * sizeof(FX_BYTE));\r
-    m_pStreamBuf = FX_Alloc(FX_BYTE, STREAM_PARSE_BUFSIZE);\r
-    FXSYS_memset32(m_pStreamBuf, 0, STREAM_PARSE_BUFSIZE * sizeof(FX_BYTE));\r
-    m_StringBuf.EstimateSize(1024);\r
-    m_ObjectSize = 0;\r
-    m_ImageSrcBuf.EstimateSize(STREAM_PARSE_BUFSIZE);\r
-#endif\r
-    return TRUE;\r
-}\r
-CPDF_StreamContentParser::~CPDF_StreamContentParser()\r
-{\r
-    ClearAllParams();\r
-    int i = 0;\r
-    for (i = 0; i < m_StateStack.GetSize(); i ++) {\r
-        delete (CPDF_AllStates*)m_StateStack[i];\r
-    }\r
-    if (m_pPathPoints) {\r
-        FX_Free(m_pPathPoints);\r
-    }\r
-    if (m_pCurStates) {\r
-        delete m_pCurStates;\r
-    }\r
-    if (m_pLastImageDict) {\r
-        m_pLastImageDict->Release();\r
-    }\r
-    if (m_pLastCloneImageDict) {\r
-        m_pLastCloneImageDict->Release();\r
-    }\r
-#ifdef _FPDFAPI_MINI_\r
-    for (i = 0; i < (int)m_ObjectSize; ++i) {\r
-        if (!m_pObjectState[i]) {\r
-            m_pObjectStack[i]->Release();\r
-        }\r
-    }\r
-    FX_Free(m_pObjectStack);\r
-    FX_Free(m_pObjectState);\r
-    FX_Free(m_pStreamBuf);\r
-    FX_Free(m_pWordBuf);\r
-    FX_Free(m_pDictName);\r
-#endif\r
-}\r
-void CPDF_StreamContentParser::PrepareParse(CPDF_Document* pDocument,\r
-        CPDF_Dictionary* pPageResources, CPDF_Dictionary* pParentResources, CFX_AffineMatrix* pmtContentToUser, CPDF_PageObjects* pObjList,\r
-        CPDF_Dictionary* pResources, CPDF_Rect* pBBox, CPDF_ParseOptions* pOptions,\r
-        CPDF_AllStates* pStates, int level)\r
-{\r
-    for (int i = 0; i < 6; i ++) {\r
-        m_Type3Data[i] = 0;\r
-    }\r
-    m_pDocument = pDocument;\r
-    m_pPageResources = pPageResources;\r
-    m_pParentResources = pParentResources;\r
-    if (pmtContentToUser) {\r
-        m_mtContentToUser = *pmtContentToUser;\r
-    }\r
-    if (pOptions) {\r
-        m_Options = *pOptions;\r
-    }\r
-    m_pObjectList = pObjList;\r
-    m_pResources = pResources;\r
-    if (pResources == NULL) {\r
-        m_pResources = m_pParentResources;\r
-    }\r
-    if (m_pResources == NULL) {\r
-        m_pResources = pPageResources;\r
-    }\r
-    if (pBBox) {\r
-        m_BBox = *pBBox;\r
-    }\r
-    m_Level = level;\r
-    m_pCurStates = FX_NEW CPDF_AllStates;\r
-    if (pStates) {\r
-        m_pCurStates->Copy(*pStates);\r
-    } else {\r
-        m_pCurStates->m_GeneralState.New();\r
-        m_pCurStates->m_GraphState.New();\r
-        m_pCurStates->m_TextState.New();\r
-        m_pCurStates->m_ColorState.New();\r
-    }\r
-#ifdef _FPDFAPI_MINI_\r
-    FXSYS_memset32(m_pObjectState, 0, _FPDF_MAX_OBJECT_STACK_SIZE_ * sizeof(FX_BOOL));\r
-#endif\r
-}\r
-int CPDF_StreamContentParser::GetNextParamPos()\r
-{\r
-    if (m_ParamCount == PARAM_BUF_SIZE) {\r
-        m_ParamStartPos ++;\r
-        if (m_ParamStartPos == PARAM_BUF_SIZE) {\r
-            m_ParamStartPos = 0;\r
-        }\r
-        if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) {\r
-            m_ParamBuf1[m_ParamStartPos].m_pObject->Release();\r
-        }\r
-        return m_ParamStartPos;\r
-    }\r
-    int index = m_ParamStartPos + m_ParamCount;\r
-    if (index >= PARAM_BUF_SIZE) {\r
-        index -= PARAM_BUF_SIZE;\r
-    }\r
-    m_ParamCount ++;\r
-    return index;\r
-}\r
-void CPDF_StreamContentParser::AddNameParam(FX_LPCSTR name, int len)\r
-{\r
-    int index = GetNextParamPos();\r
-    if (len > 32) {\r
-        m_ParamBuf1[index].m_Type = 0;\r
-        m_ParamBuf1[index].m_pObject = CPDF_Name::Create(PDF_NameDecode(CFX_ByteStringC(name, len)));\r
-    } else {\r
-        m_ParamBuf1[index].m_Type = PDFOBJ_NAME;\r
-        if (FXSYS_memchr(name, '#', len) == NULL) {\r
-            FXSYS_memcpy32(m_ParamBuf1[index].m_Name.m_Buffer, name, len);\r
-            m_ParamBuf1[index].m_Name.m_Len = len;\r
-        } else {\r
-            CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len));\r
-            FXSYS_memcpy32(m_ParamBuf1[index].m_Name.m_Buffer, (FX_LPCSTR)str, str.GetLength());\r
-            m_ParamBuf1[index].m_Name.m_Len = str.GetLength();\r
-        }\r
-    }\r
-}\r
-void CPDF_StreamContentParser::AddNumberParam(FX_LPCSTR str, int len)\r
-{\r
-    int index = GetNextParamPos();\r
-    m_ParamBuf1[index].m_Type = PDFOBJ_NUMBER;\r
-    FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger,\r
-              &m_ParamBuf1[index].m_Number.m_Integer);\r
-}\r
-void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj)\r
-{\r
-    int index = GetNextParamPos();\r
-    m_ParamBuf1[index].m_Type = 0;\r
-    m_ParamBuf1[index].m_pObject = pObj;\r
-}\r
-void CPDF_StreamContentParser::ClearAllParams()\r
-{\r
-    FX_DWORD index = m_ParamStartPos;\r
-    for (FX_DWORD i = 0; i < m_ParamCount; i ++) {\r
-        if (m_ParamBuf1[index].m_Type == 0) {\r
-            m_ParamBuf1[index].m_pObject->Release();\r
-        }\r
-        index ++;\r
-        if (index == PARAM_BUF_SIZE) {\r
-            index = 0;\r
-        }\r
-    }\r
-    m_ParamStartPos = 0;\r
-    m_ParamCount = 0;\r
-}\r
-CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index)\r
-{\r
-    if (index >= m_ParamCount) {\r
-        return NULL;\r
-    }\r
-    int real_index = m_ParamStartPos + m_ParamCount - index - 1;\r
-    if (real_index >= PARAM_BUF_SIZE) {\r
-        real_index -= PARAM_BUF_SIZE;\r
-    }\r
-    _ContentParam& param = m_ParamBuf1[real_index];\r
-    if (param.m_Type == PDFOBJ_NUMBER) {\r
-        CPDF_Number* pNumber = CPDF_Number::Create(param.m_Number.m_bInteger, &param.m_Number.m_Integer);\r
-        param.m_Type = 0;\r
-        param.m_pObject = pNumber;\r
-        return pNumber;\r
-    }\r
-    if (param.m_Type == PDFOBJ_NAME) {\r
-        CPDF_Name* pName = CPDF_Name::Create(CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));\r
-        param.m_Type = 0;\r
-        param.m_pObject = pName;\r
-        return pName;\r
-    }\r
-    if (param.m_Type == 0) {\r
-        return param.m_pObject;\r
-    }\r
-    ASSERT(FALSE);\r
-    return NULL;\r
-}\r
-CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index)\r
-{\r
-    if (index >= m_ParamCount) {\r
-        return CFX_ByteString();\r
-    }\r
-    int real_index = m_ParamStartPos + m_ParamCount - index - 1;\r
-    if (real_index >= PARAM_BUF_SIZE) {\r
-        real_index -= PARAM_BUF_SIZE;\r
-    }\r
-    _ContentParam& param = m_ParamBuf1[real_index];\r
-    if (param.m_Type == PDFOBJ_NAME) {\r
-        return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len);\r
-    }\r
-    if (param.m_Type == 0) {\r
-        return param.m_pObject->GetString();\r
-    }\r
-    return CFX_ByteString();\r
-}\r
-FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index)\r
-{\r
-    if (index >= m_ParamCount) {\r
-        return 0;\r
-    }\r
-    int real_index = m_ParamStartPos + m_ParamCount - index - 1;\r
-    if (real_index >= PARAM_BUF_SIZE) {\r
-        real_index -= PARAM_BUF_SIZE;\r
-    }\r
-    _ContentParam& param = m_ParamBuf1[real_index];\r
-    if (param.m_Type == PDFOBJ_NUMBER) {\r
-        return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer : param.m_Number.m_Float;\r
-    }\r
-    if (param.m_Type == 0) {\r
-        return param.m_pObject->GetNumber();\r
-    }\r
-    return 0;\r
-}\r
-FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index)\r
-{\r
-    return GetNumber(index);\r
-}\r
-void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL bColor, FX_BOOL bText, FX_BOOL bGraph)\r
-{\r
-    pObj->m_GeneralState = m_pCurStates->m_GeneralState;\r
-    pObj->m_ClipPath = m_pCurStates->m_ClipPath;\r
-    pObj->m_ContentMark = m_CurContentMark;\r
-    if (bColor) {\r
-        pObj->m_ColorState = m_pCurStates->m_ColorState;\r
-    }\r
-    if (bGraph) {\r
-        pObj->m_GraphState = m_pCurStates->m_GraphState;\r
-    }\r
-    if (bText) {\r
-        pObj->m_TextState = m_pCurStates->m_TextState;\r
-    }\r
-}\r
-const struct _OpCode {\r
-    FX_DWORD   m_OpId;\r
-    void (CPDF_StreamContentParser::*m_OpHandler)();\r
-} g_OpCodes[] = {\r
-    {FXBSTR_ID('"', 0, 0, 0),          &CPDF_StreamContentParser::Handle_NextLineShowText_Space},\r
-    {FXBSTR_ID('\'', 0, 0, 0),         &CPDF_StreamContentParser::Handle_NextLineShowText},\r
-    {FXBSTR_ID('B', 0, 0, 0),          &CPDF_StreamContentParser::Handle_FillStrokePath},\r
-    {FXBSTR_ID('B', '*', 0, 0),        &CPDF_StreamContentParser::Handle_EOFillStrokePath},\r
-    {FXBSTR_ID('B', 'D', 'C', 0),      &CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary},\r
-    {FXBSTR_ID('B', 'I', 0, 0),        &CPDF_StreamContentParser::Handle_BeginImage},\r
-    {FXBSTR_ID('B', 'M', 'C', 0),      &CPDF_StreamContentParser::Handle_BeginMarkedContent},\r
-    {FXBSTR_ID('B', 'T', 0, 0),        &CPDF_StreamContentParser::Handle_BeginText},\r
-    {FXBSTR_ID('B', 'X', 0, 0),        &CPDF_StreamContentParser::Handle_BeginSectionUndefined},\r
-    {FXBSTR_ID('C', 'S', 0, 0),        &CPDF_StreamContentParser::Handle_SetColorSpace_Stroke},\r
-    {FXBSTR_ID('D', 'P', 0, 0),        &CPDF_StreamContentParser::Handle_MarkPlace_Dictionary},\r
-    {FXBSTR_ID('D', 'o', 0, 0),        &CPDF_StreamContentParser::Handle_ExecuteXObject},\r
-    {FXBSTR_ID('E', 'I', 0, 0),        &CPDF_StreamContentParser::Handle_EndImage},\r
-    {FXBSTR_ID('E', 'M', 'C', 0),      &CPDF_StreamContentParser::Handle_EndMarkedContent},\r
-    {FXBSTR_ID('E', 'T', 0, 0),        &CPDF_StreamContentParser::Handle_EndText},\r
-    {FXBSTR_ID('E', 'X', 0, 0),        &CPDF_StreamContentParser::Handle_EndSectionUndefined},\r
-    {FXBSTR_ID('F', 0, 0, 0),          &CPDF_StreamContentParser::Handle_FillPathOld},\r
-    {FXBSTR_ID('G', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetGray_Stroke},\r
-    {FXBSTR_ID('I', 'D', 0, 0),        &CPDF_StreamContentParser::Handle_BeginImageData},\r
-    {FXBSTR_ID('J', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetLineCap},\r
-    {FXBSTR_ID('K', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke},\r
-    {FXBSTR_ID('M', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetMiterLimit},\r
-    {FXBSTR_ID('M', 'P', 0, 0),        &CPDF_StreamContentParser::Handle_MarkPlace},\r
-    {FXBSTR_ID('Q', 0, 0, 0),          &CPDF_StreamContentParser::Handle_RestoreGraphState},\r
-    {FXBSTR_ID('R', 'G', 0, 0),        &CPDF_StreamContentParser::Handle_SetRGBColor_Stroke},\r
-    {FXBSTR_ID('S', 0, 0, 0),          &CPDF_StreamContentParser::Handle_StrokePath},\r
-    {FXBSTR_ID('S', 'C', 0, 0),        &CPDF_StreamContentParser::Handle_SetColor_Stroke},\r
-    {FXBSTR_ID('S', 'C', 'N', 0),      &CPDF_StreamContentParser::Handle_SetColorPS_Stroke},\r
-    {FXBSTR_ID('T', '*', 0, 0),        &CPDF_StreamContentParser::Handle_MoveToNextLine},\r
-    {FXBSTR_ID('T', 'D', 0, 0),        &CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading},\r
-    {FXBSTR_ID('T', 'J', 0, 0),        &CPDF_StreamContentParser::Handle_ShowText_Positioning},\r
-    {FXBSTR_ID('T', 'L', 0, 0),        &CPDF_StreamContentParser::Handle_SetTextLeading},\r
-    {FXBSTR_ID('T', 'c', 0, 0),        &CPDF_StreamContentParser::Handle_SetCharSpace},\r
-    {FXBSTR_ID('T', 'd', 0, 0),        &CPDF_StreamContentParser::Handle_MoveTextPoint},\r
-    {FXBSTR_ID('T', 'f', 0, 0),        &CPDF_StreamContentParser::Handle_SetFont},\r
-    {FXBSTR_ID('T', 'j', 0, 0),        &CPDF_StreamContentParser::Handle_ShowText},\r
-    {FXBSTR_ID('T', 'm', 0, 0),        &CPDF_StreamContentParser::Handle_SetTextMatrix},\r
-    {FXBSTR_ID('T', 'r', 0, 0),        &CPDF_StreamContentParser::Handle_SetTextRenderMode},\r
-    {FXBSTR_ID('T', 's', 0, 0),        &CPDF_StreamContentParser::Handle_SetTextRise},\r
-    {FXBSTR_ID('T', 'w', 0, 0),        &CPDF_StreamContentParser::Handle_SetWordSpace},\r
-    {FXBSTR_ID('T', 'z', 0, 0),        &CPDF_StreamContentParser::Handle_SetHorzScale},\r
-    {FXBSTR_ID('W', 0, 0, 0),          &CPDF_StreamContentParser::Handle_Clip},\r
-    {FXBSTR_ID('W', '*', 0, 0),        &CPDF_StreamContentParser::Handle_EOClip},\r
-    {FXBSTR_ID('b', 0, 0, 0),          &CPDF_StreamContentParser::Handle_CloseFillStrokePath},\r
-    {FXBSTR_ID('b', '*', 0, 0),        &CPDF_StreamContentParser::Handle_CloseEOFillStrokePath},\r
-    {FXBSTR_ID('c', 0, 0, 0),          &CPDF_StreamContentParser::Handle_CurveTo_123},\r
-    {FXBSTR_ID('c', 'm', 0, 0),        &CPDF_StreamContentParser::Handle_ConcatMatrix},\r
-    {FXBSTR_ID('c', 's', 0, 0),        &CPDF_StreamContentParser::Handle_SetColorSpace_Fill},\r
-    {FXBSTR_ID('d', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetDash},\r
-    {FXBSTR_ID('d', '0', 0, 0),        &CPDF_StreamContentParser::Handle_SetCharWidth},\r
-    {FXBSTR_ID('d', '1', 0, 0),        &CPDF_StreamContentParser::Handle_SetCachedDevice},\r
-    {FXBSTR_ID('f', 0, 0, 0),          &CPDF_StreamContentParser::Handle_FillPath},\r
-    {FXBSTR_ID('f', '*', 0, 0),        &CPDF_StreamContentParser::Handle_EOFillPath},\r
-    {FXBSTR_ID('g', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetGray_Fill},\r
-    {FXBSTR_ID('g', 's', 0, 0),        &CPDF_StreamContentParser::Handle_SetExtendGraphState},\r
-    {FXBSTR_ID('h', 0, 0, 0),          &CPDF_StreamContentParser::Handle_ClosePath},\r
-    {FXBSTR_ID('i', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetFlat},\r
-    {FXBSTR_ID('j', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetLineJoin},\r
-    {FXBSTR_ID('k', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetCMYKColor_Fill},\r
-    {FXBSTR_ID('l', 0, 0, 0),          &CPDF_StreamContentParser::Handle_LineTo},\r
-    {FXBSTR_ID('m', 0, 0, 0),          &CPDF_StreamContentParser::Handle_MoveTo},\r
-    {FXBSTR_ID('n', 0, 0, 0),          &CPDF_StreamContentParser::Handle_EndPath},\r
-    {FXBSTR_ID('q', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SaveGraphState},\r
-    {FXBSTR_ID('r', 'e', 0, 0),        &CPDF_StreamContentParser::Handle_Rectangle},\r
-    {FXBSTR_ID('r', 'g', 0, 0),        &CPDF_StreamContentParser::Handle_SetRGBColor_Fill},\r
-    {FXBSTR_ID('r', 'i', 0, 0),        &CPDF_StreamContentParser::Handle_SetRenderIntent},\r
-    {FXBSTR_ID('s', 0, 0, 0),          &CPDF_StreamContentParser::Handle_CloseStrokePath},\r
-    {FXBSTR_ID('s', 'c', 0, 0),        &CPDF_StreamContentParser::Handle_SetColor_Fill},\r
-    {FXBSTR_ID('s', 'c', 'n', 0),      &CPDF_StreamContentParser::Handle_SetColorPS_Fill},\r
-    {FXBSTR_ID('s', 'h', 0, 0),        &CPDF_StreamContentParser::Handle_ShadeFill},\r
-    {FXBSTR_ID('v', 0, 0, 0),          &CPDF_StreamContentParser::Handle_CurveTo_23},\r
-    {FXBSTR_ID('w', 0, 0, 0),          &CPDF_StreamContentParser::Handle_SetLineWidth},\r
-    {FXBSTR_ID('y', 0, 0, 0),          &CPDF_StreamContentParser::Handle_CurveTo_13},\r
-};\r
-FX_BOOL CPDF_StreamContentParser::OnOperator(FX_LPCSTR op)\r
-{\r
-    int i = 0;\r
-    FX_DWORD opid = 0;\r
-    while (i < 4 && op[i]) {\r
-        opid = (opid << 8) + op[i];\r
-        i ++;\r
-    }\r
-    while (i < 4) {\r
-        opid <<= 8;\r
-        i ++;\r
-    };\r
-    int low = 0, high = sizeof g_OpCodes / sizeof(struct _OpCode) - 1;\r
-    while (low <= high) {\r
-        int middle = (low + high) / 2;\r
-        int compare = opid - g_OpCodes[middle].m_OpId;\r
-        if (compare == 0) {\r
-            (this->*g_OpCodes[middle].m_OpHandler)();\r
-            return TRUE;\r
-        } else if (compare < 0) {\r
-            high = middle - 1;\r
-        } else {\r
-            low = middle + 1;\r
-        }\r
-    }\r
-    return m_CompatCount != 0;\r
-}\r
-void CPDF_StreamContentParser::Handle_CloseFillStrokePath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    Handle_ClosePath();\r
-    AddPathObject(FXFILL_WINDING, TRUE);\r
-}\r
-void CPDF_StreamContentParser::Handle_FillStrokePath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathObject(FXFILL_WINDING, TRUE);\r
-}\r
-void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);\r
-    AddPathObject(FXFILL_ALTERNATE, TRUE);\r
-}\r
-void CPDF_StreamContentParser::Handle_EOFillStrokePath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathObject(FXFILL_ALTERNATE, TRUE);\r
-}\r
-void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary()\r
-{\r
-    if (!m_Options.m_bMarkedContent) {\r
-        return;\r
-    }\r
-    CFX_ByteString tag = GetString(1);\r
-    CPDF_Object* pProperty = GetObject(0);\r
-    if (pProperty == NULL) {\r
-        return;\r
-    }\r
-    FX_BOOL bDirect = TRUE;\r
-    if (pProperty->GetType() == PDFOBJ_NAME) {\r
-        pProperty = FindResourceObj(FX_BSTRC("Properties"), pProperty->GetString());\r
-        if (pProperty == NULL) {\r
-            return;\r
-        }\r
-        bDirect = FALSE;\r
-    }\r
-    if (pProperty->GetType() != PDFOBJ_DICTIONARY) {\r
-        return;\r
-    }\r
-    m_CurContentMark.GetModify()->AddMark(tag, (CPDF_Dictionary*)pProperty, bDirect);\r
-}\r
-void CPDF_StreamContentParser::Handle_BeginMarkedContent()\r
-{\r
-    if (!m_Options.m_bMarkedContent) {\r
-        return;\r
-    }\r
-    CFX_ByteString tag = GetString(0);\r
-    m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);\r
-}\r
-struct _FX_BSTR {\r
-    FX_LPCSTR  m_Ptr;\r
-    int                        m_Size;\r
-};\r
-#define _FX_BSTRC(str) {str, sizeof(str)-1}\r
-const _FX_BSTR _PDF_InlineKeyAbbr[] = {\r
-    _FX_BSTRC("BitsPerComponent"), _FX_BSTRC("BPC"),\r
-    _FX_BSTRC("ColorSpace"), _FX_BSTRC("CS"),\r
-    _FX_BSTRC("Decode"), _FX_BSTRC("D"),\r
-    _FX_BSTRC("DecodeParms"), _FX_BSTRC("DP"),\r
-    _FX_BSTRC("Filter"), _FX_BSTRC("F"),\r
-    _FX_BSTRC("Height"), _FX_BSTRC("H"),\r
-    _FX_BSTRC("ImageMask"), _FX_BSTRC("IM"),\r
-    _FX_BSTRC("Interpolate"), _FX_BSTRC("I"),\r
-    _FX_BSTRC("Width"), _FX_BSTRC("W"),\r
-};\r
-const _FX_BSTR _PDF_InlineValueAbbr[] = {\r
-    _FX_BSTRC("DeviceGray"), _FX_BSTRC("G"),\r
-    _FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB"),\r
-    _FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK"),\r
-    _FX_BSTRC("Indexed"), _FX_BSTRC("I"),\r
-    _FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx"),\r
-    _FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85"),\r
-    _FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW"),\r
-    _FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl"),\r
-    _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"),\r
-    _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"),\r
-    _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"),\r
-};\r
-static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table, int count, FX_BSTR abbr)\r
-{\r
-    int i = 0;\r
-    while (i < count) {\r
-        if (abbr.GetLength() == table[i + 1].m_Size && FXSYS_memcmp32(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) == 0) {\r
-            return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size);\r
-        }\r
-        i += 2;\r
-    }\r
-    return CFX_ByteStringC();\r
-}\r
-void _PDF_ReplaceAbbr(CPDF_Object* pObj)\r
-{\r
-    switch (pObj->GetType()) {\r
-        case PDFOBJ_DICTIONARY: {\r
-                CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;\r
-                FX_POSITION pos = pDict->GetStartPos();\r
-                while (pos) {\r
-                    CFX_ByteString key;\r
-                    CPDF_Object* value = pDict->GetNextElement(pos, key);\r
-                    CFX_ByteStringC fullname = _PDF_FindFullName(_PDF_InlineKeyAbbr,\r
-                                               sizeof _PDF_InlineKeyAbbr / sizeof(_FX_BSTR), key);\r
-                    if (!fullname.IsEmpty()) {\r
-                        pDict->ReplaceKey(key, fullname);\r
-                        key = fullname;\r
-                    }\r
-                    if (value->GetType() == PDFOBJ_NAME) {\r
-                        CFX_ByteString name = value->GetString();\r
-                        fullname = _PDF_FindFullName(_PDF_InlineValueAbbr,\r
-                                                     sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);\r
-                        if (!fullname.IsEmpty()) {\r
-                            pDict->SetAtName(key, fullname);\r
-                        }\r
-                    } else {\r
-                        _PDF_ReplaceAbbr(value);\r
-                    }\r
-                }\r
-                break;\r
-            }\r
-        case PDFOBJ_ARRAY: {\r
-                CPDF_Array* pArray = (CPDF_Array*)pObj;\r
-                for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {\r
-                    CPDF_Object* pElement = pArray->GetElement(i);\r
-                    if (pElement->GetType() == PDFOBJ_NAME) {\r
-                        CFX_ByteString name = pElement->GetString();\r
-                        CFX_ByteStringC fullname = _PDF_FindFullName(_PDF_InlineValueAbbr,\r
-                                                   sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);\r
-                        if (!fullname.IsEmpty()) {\r
-                            pArray->SetAt(i, CPDF_Name::Create(fullname));\r
-                        }\r
-                    } else {\r
-                        _PDF_ReplaceAbbr(pElement);\r
-                    }\r
-                }\r
-                break;\r
-            }\r
-    }\r
-}\r
-static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table, int count, FX_BSTR fullName)\r
-{\r
-    int i = 0;\r
-    while (i < count) {\r
-        if (fullName.GetLength() == table[i].m_Size && FXSYS_memcmp32(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) == 0) {\r
-            return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);\r
-        }\r
-        i += 2;\r
-    }\r
-    return CFX_ByteStringC();\r
-}\r
-void _PDF_ReplaceFull(CPDF_Object* pObj)\r
-{\r
-    switch (pObj->GetType()) {\r
-        case PDFOBJ_DICTIONARY: {\r
-                CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;\r
-                FX_POSITION pos = pDict->GetStartPos();\r
-                while (pos) {\r
-                    CFX_ByteString key;\r
-                    CPDF_Object* value = pDict->GetNextElement(pos, key);\r
-                    CFX_ByteStringC abbrName = _PDF_FindAbbrName(_PDF_InlineKeyAbbr,\r
-                                               sizeof(_PDF_InlineKeyAbbr) / sizeof(_FX_BSTR), key);\r
-                    if (!abbrName.IsEmpty()) {\r
-                        pDict->ReplaceKey(key, abbrName);\r
-                        key = abbrName;\r
-                    }\r
-                    if (value->GetType() == PDFOBJ_NAME) {\r
-                        CFX_ByteString name = value->GetString();\r
-                        abbrName = _PDF_FindAbbrName(_PDF_InlineValueAbbr,\r
-                                                     sizeof(_PDF_InlineValueAbbr) / sizeof(_FX_BSTR), name);\r
-                        if (!abbrName.IsEmpty()) {\r
-                            pDict->SetAtName(key, abbrName);\r
-                        }\r
-                    } else {\r
-                        _PDF_ReplaceFull(value);\r
-                    }\r
-                }\r
-                break;\r
-            }\r
-        case PDFOBJ_ARRAY: {\r
-                CPDF_Array* pArray = (CPDF_Array*)pObj;\r
-                for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {\r
-                    CPDF_Object* pElement = pArray->GetElement(i);\r
-                    if (pElement->GetType() == PDFOBJ_NAME) {\r
-                        CFX_ByteString name = pElement->GetString();\r
-                        CFX_ByteStringC abbrName = _PDF_FindAbbrName(_PDF_InlineValueAbbr,\r
-                                                   sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);\r
-                        if (!abbrName.IsEmpty()) {\r
-                            pArray->SetAt(i, CPDF_Name::Create(abbrName));\r
-                        }\r
-                    } else {\r
-                        _PDF_ReplaceFull(pElement);\r
-                    }\r
-                }\r
-                break;\r
-            }\r
-    }\r
-}\r
-void CPDF_StreamContentParser::Handle_BeginText()\r
-{\r
-    m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0);\r
-    OnChangeTextMatrix();\r
-    m_pCurStates->m_TextX = 0;\r
-    m_pCurStates->m_TextY = 0;\r
-    m_pCurStates->m_TextLineX = 0;\r
-    m_pCurStates->m_TextLineY = 0;\r
-}\r
-void CPDF_StreamContentParser::Handle_BeginSectionUndefined()\r
-{\r
-    m_CompatCount ++;\r
-}\r
-void CPDF_StreamContentParser::Handle_CurveTo_123()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO);\r
-    AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);\r
-    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);\r
-}\r
-void CPDF_StreamContentParser::Handle_ConcatMatrix()\r
-{\r
-    FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3), d2 = GetNumber16(2);\r
-    FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0);\r
-    FX_FLOAT old_width_scale = m_pCurStates->m_CTM.GetXUnit();\r
-    CFX_AffineMatrix new_matrix(a2, b2, c2, d2, e2, f2);\r
-    new_matrix.Concat(m_pCurStates->m_CTM);\r
-    m_pCurStates->m_CTM = new_matrix;\r
-    FX_FLOAT new_width_scale = m_pCurStates->m_CTM.GetXUnit();\r
-    OnChangeTextMatrix();\r
-}\r
-void CPDF_StreamContentParser::Handle_SetColorSpace_Fill()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    CFX_ByteString csname = GetString(0);\r
-    CPDF_ColorSpace* pCS = FindColorSpace(csname);\r
-    if (pCS == NULL) {\r
-        return;\r
-    }\r
-    m_pCurStates->m_ColorState.GetModify()->m_FillColor.SetColorSpace(pCS);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    CFX_ByteString csname = GetString(0);\r
-    CPDF_ColorSpace* pCS = FindColorSpace(csname);\r
-    if (pCS == NULL) {\r
-        return;\r
-    }\r
-    m_pCurStates->m_ColorState.GetModify()->m_StrokeColor.SetColorSpace(pCS);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetDash()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    CPDF_Array* pArray = GetObject(1)->GetArray();\r
-    if (pArray == NULL) {\r
-        return;\r
-    }\r
-    m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetCharWidth()\r
-{\r
-    m_Type3Data[0] = GetNumber(1);\r
-    m_Type3Data[1] = GetNumber(0);\r
-    m_bColored = TRUE;\r
-}\r
-void CPDF_StreamContentParser::Handle_SetCachedDevice()\r
-{\r
-    for (int i = 0; i < 6; i ++) {\r
-        m_Type3Data[i] = GetNumber(5 - i);\r
-    }\r
-    m_bColored = FALSE;\r
-}\r
-void CPDF_StreamContentParser::Handle_ExecuteXObject()\r
-{\r
-    CFX_ByteString name = GetString(0);\r
-    if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() && m_pLastImage->GetStream()->GetObjNum()) {\r
-#if defined(_FPDFAPI_MINI_) && !defined(_FXCORE_FEATURE_ALL_)\r
-        AddDuplicateImage();\r
-#else\r
-        AddImage(NULL, m_pLastImage, FALSE);\r
-#endif\r
-        return;\r
-    }\r
-    if (m_Options.m_bTextOnly) {\r
-        CPDF_Object* pRes = NULL;\r
-        if (m_pResources == NULL) {\r
-            return;\r
-        }\r
-        if (m_pResources == m_pPageResources) {\r
-            CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));\r
-            if (pList == NULL) {\r
-                return;\r
-            }\r
-            pRes = pList->GetElement(name);\r
-            if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {\r
-                return;\r
-            }\r
-        } else {\r
-            CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));\r
-            if (pList == NULL) {\r
-                if (m_pPageResources == NULL) {\r
-                    return;\r
-                }\r
-                CPDF_Dictionary* pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));\r
-                if (pList == NULL) {\r
-                    return;\r
-                }\r
-                pRes = pList->GetElement(name);\r
-                if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {\r
-                    return;\r
-                }\r
-            } else {\r
-                pRes = pList->GetElement(name);\r
-                if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {\r
-                    return;\r
-                }\r
-            }\r
-        }\r
-        FX_BOOL bForm;\r
-        if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(), bForm) && !bForm) {\r
-            return;\r
-        }\r
-    }\r
-    CPDF_Stream* pXObject = (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), name);\r
-    if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) {\r
-        m_bResourceMissing = TRUE;\r
-        return;\r
-    }\r
-    CFX_ByteStringC type = pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype"));\r
-    if (type == FX_BSTRC("Image")) {\r
-        if (m_Options.m_bTextOnly) {\r
-            return;\r
-        }\r
-        CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE);\r
-        m_LastImageName = name;\r
-        m_pLastImage = pObj->m_pImage;\r
-    } else if (type == FX_BSTRC("Form")) {\r
-        AddForm(pXObject);\r
-    } else {\r
-        return;\r
-    }\r
-}\r
-void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream)\r
-{\r
-#if !defined(_FPDFAPI_MINI_) || defined(_FXCORE_FEATURE_ALL_)\r
-    if (!m_Options.m_bSeparateForm) {\r
-        CPDF_Dictionary* pResources = pStream->GetDict()->GetDict(FX_BSTRC("Resources"));\r
-        CFX_AffineMatrix form_matrix = pStream->GetDict()->GetMatrix(FX_BSTRC("Matrix"));\r
-        form_matrix.Concat(m_pCurStates->m_CTM);\r
-        CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox"));\r
-        CFX_FloatRect form_bbox;\r
-        CPDF_Path ClipPath;\r
-        if (pBBox) {\r
-            form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox"));\r
-            ClipPath.New();\r
-            ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, form_bbox.top);\r
-            ClipPath.Transform(&form_matrix);\r
-            form_bbox.Transform(&form_matrix);\r
-        }\r
-        CPDF_StreamContentParser parser;\r
-        parser.Initialize();\r
-        parser.PrepareParse(m_pDocument, m_pPageResources, m_pResources, &m_mtContentToUser,\r
-                            m_pObjectList, pResources, &form_bbox, &m_Options, m_pCurStates, m_Level + 1);\r
-        parser.m_pCurStates->m_CTM = form_matrix;\r
-        if (ClipPath.NotNull()) {\r
-            parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE);\r
-        }\r
-        CPDF_StreamAcc stream;\r
-        stream.LoadAllData(pStream, FALSE);\r
-        if (stream.GetSize() == 0) {\r
-            return;\r
-        }\r
-#ifdef _FPDFAPI_MINI_\r
-        parser.InputData(stream.GetData(), stream.GetSize());\r
-        parser.Finish();\r
-#else\r
-        parser.Parse(stream.GetData(), stream.GetSize(), 0);\r
-#endif\r
-        return;\r
-    }\r
-#endif\r
-    CPDF_FormObject* pFormObj = FX_NEW CPDF_FormObject;\r
-    pFormObj->m_pForm = FX_NEW CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);\r
-    pFormObj->m_FormMatrix = m_pCurStates->m_CTM;\r
-    pFormObj->m_FormMatrix.Concat(m_mtContentToUser);\r
-    CPDF_AllStates status;\r
-    status.m_GeneralState = m_pCurStates->m_GeneralState;\r
-    status.m_GraphState = m_pCurStates->m_GraphState;\r
-    status.m_ColorState = m_pCurStates->m_ColorState;\r
-    status.m_TextState = m_pCurStates->m_TextState;\r
-    pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1);\r
-    if (!m_pObjectList->m_bBackgroundAlphaNeeded && pFormObj->m_pForm->m_bBackgroundAlphaNeeded) {\r
-        m_pObjectList->m_bBackgroundAlphaNeeded = TRUE;\r
-    }\r
-    pFormObj->CalcBoundingBox();\r
-    SetGraphicStates(pFormObj, TRUE, TRUE, TRUE);\r
-    m_pObjectList->m_ObjectList.AddTail(pFormObj);\r
-}\r
-#if defined(_FPDFAPI_MINI_) && !defined(_FXCORE_FEATURE_ALL_)\r
-void CPDF_StreamContentParser::AddDuplicateImage()\r
-{\r
-    FX_POSITION tailpos = m_pObjectList->m_ObjectList.GetTailPosition();\r
-    CPDF_PageObject* pLastObj = (CPDF_PageObject*)m_pObjectList->m_ObjectList.GetAt(tailpos);\r
-    if (pLastObj == NULL || (pLastObj->m_Type != PDFPAGE_INLINES && pLastObj->m_Type != PDFPAGE_IMAGE)) {\r
-        AddImage(NULL, m_pLastImage, FALSE);\r
-        return;\r
-    }\r
-    if (pLastObj->m_GeneralState != m_pCurStates->m_GeneralState ||\r
-            pLastObj->m_ClipPath != m_pCurStates->m_ClipPath ||\r
-            pLastObj->m_ColorState != m_pCurStates->m_ColorState) {\r
-        AddImage(NULL, m_pLastImage, FALSE);\r
-        return;\r
-    }\r
-    CFX_AffineMatrix ImageMatrix;\r
-    ImageMatrix.Copy(m_pCurStates->m_CTM);\r
-    ImageMatrix.Concat(m_mtContentToUser);\r
-    if (pLastObj->m_Type == PDFPAGE_INLINES) {\r
-        CPDF_InlineImages* pInlines = (CPDF_InlineImages*)pLastObj;\r
-        if (pInlines->m_pStream != m_pLastImage->GetStream()) {\r
-            AddImage(NULL, m_pLastImage, FALSE);\r
-            return;\r
-        }\r
-        pInlines->AddMatrix(ImageMatrix);\r
-    } else {\r
-        CPDF_ImageObject* pImageObj = (CPDF_ImageObject*)pLastObj;\r
-        CPDF_InlineImages* pInlines = FX_NEW CPDF_InlineImages;\r
-        pInlines->m_pStream = m_pLastImage->GetStream();\r
-        SetGraphicStates(pInlines, !pInlines->m_pStream->GetDict()->KeyExist(FX_BSTRC("ColorSpace")), FALSE, FALSE);\r
-        pInlines->AddMatrix(pImageObj->m_Matrix);\r
-        pInlines->AddMatrix(ImageMatrix);\r
-        m_pObjectList->m_ObjectList.RemoveAt(tailpos);\r
-        m_pObjectList->m_ObjectList.AddTail(pInlines);\r
-        pLastObj->Release();\r
-    }\r
-}\r
-#endif\r
-CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, CPDF_Image* pImage, FX_BOOL bInline)\r
-{\r
-    if (pStream == NULL && pImage == NULL) {\r
-        return NULL;\r
-    }\r
-    CFX_AffineMatrix ImageMatrix;\r
-    ImageMatrix.Copy(m_pCurStates->m_CTM);\r
-    ImageMatrix.Concat(m_mtContentToUser);\r
-    CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;\r
-    if (pImage) {\r
-        pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pImage->GetStream());\r
-    } else if (pStream->GetObjNum()) {\r
-        pImageObj->m_pImage = m_pDocument->LoadImageF(pStream);\r
-    } else {\r
-        pImageObj->m_pImage = FX_NEW CPDF_Image(m_pDocument);\r
-        pImageObj->m_pImage->LoadImageF(pStream, bInline);\r
-    }\r
-    SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE);\r
-    pImageObj->m_Matrix = ImageMatrix;\r
-    pImageObj->CalcBoundingBox();\r
-    m_pObjectList->m_ObjectList.AddTail(pImageObj);\r
-    return pImageObj;\r
-}\r
-void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary()\r
-{\r
-}\r
-void CPDF_StreamContentParser::Handle_EndImage()\r
-{\r
-}\r
-void CPDF_StreamContentParser::Handle_EndMarkedContent()\r
-{\r
-    if (!m_Options.m_bMarkedContent) {\r
-        return;\r
-    }\r
-    if (m_CurContentMark.IsNull()) {\r
-        return;\r
-    }\r
-    int count = m_CurContentMark.GetObject()->CountItems();\r
-    if (count == 1) {\r
-        m_CurContentMark.SetNull();\r
-        return;\r
-    }\r
-    m_CurContentMark.GetModify()->DeleteLastMark();\r
-}\r
-void CPDF_StreamContentParser::Handle_EndText()\r
-{\r
-    int count = m_ClipTextList.GetSize();\r
-    if (count == 0) {\r
-        return;\r
-    }\r
-    if (m_pCurStates->m_TextState.GetObject()->m_TextMode < 4) {\r
-        for (int i = 0; i < count; i ++) {\r
-            CPDF_TextObject* pText = (CPDF_TextObject*)m_ClipTextList.GetAt(i);\r
-            if (pText) {\r
-                delete pText;\r
-            }\r
-        }\r
-    } else {\r
-        m_pCurStates->m_ClipPath.AppendTexts((CPDF_TextObject**)m_ClipTextList.GetData(), count);\r
-    }\r
-    m_ClipTextList.RemoveAll();\r
-}\r
-void CPDF_StreamContentParser::Handle_EndSectionUndefined()\r
-{\r
-    if (m_CompatCount) {\r
-        m_CompatCount --;\r
-    }\r
-}\r
-void CPDF_StreamContentParser::Handle_FillPath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathObject(FXFILL_WINDING, FALSE);\r
-}\r
-void CPDF_StreamContentParser::Handle_FillPathOld()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathObject(FXFILL_WINDING, FALSE);\r
-}\r
-void CPDF_StreamContentParser::Handle_EOFillPath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathObject(FXFILL_ALTERNATE, FALSE);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetGray_Fill()\r
-{\r
-    FX_FLOAT value = GetNumber(0);\r
-    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);\r
-    m_pCurStates->m_ColorState.SetFillColor(pCS, &value, 1);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetGray_Stroke()\r
-{\r
-    FX_FLOAT value = GetNumber(0);\r
-    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);\r
-    m_pCurStates->m_ColorState.SetStrokeColor(pCS, &value, 1);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetExtendGraphState()\r
-{\r
-    CFX_ByteString name = GetString(0);\r
-    CPDF_Dictionary* pGS = (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("ExtGState"), name);\r
-    if (pGS == NULL || pGS->GetType() != PDFOBJ_DICTIONARY) {\r
-        m_bResourceMissing = TRUE;\r
-        return;\r
-    }\r
-    m_pCurStates->ProcessExtGS(pGS, this);\r
-}\r
-void CPDF_StreamContentParser::Handle_ClosePath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    if (m_PathPointCount == 0) {\r
-        return;\r
-    }\r
-    if (m_PathStartX != m_PathCurrentX || m_PathStartY != m_PathCurrentY) {\r
-        AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);\r
-    } else if (m_pPathPoints[m_PathPointCount - 1].m_Flag != FXPT_MOVETO) {\r
-        m_pPathPoints[m_PathPointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;\r
-    }\r
-}\r
-void CPDF_StreamContentParser::Handle_SetFlat()\r
-{\r
-#if !defined(_FPDFAPI_MINI_) || defined(_FXCORE_FEATURE_ALL_)\r
-    m_pCurStates->m_GeneralState.GetModify()->m_Flatness = GetNumber(0);\r
-#endif\r
-}\r
-void CPDF_StreamContentParser::Handle_BeginImageData()\r
-{\r
-}\r
-void CPDF_StreamContentParser::Handle_SetLineJoin()\r
-{\r
-    m_pCurStates->m_GraphState.GetModify()->m_LineJoin = (CFX_GraphStateData::LineJoin)GetInteger(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetLineCap()\r
-{\r
-    m_pCurStates->m_GraphState.GetModify()->m_LineCap = (CFX_GraphStateData::LineCap)GetInteger(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill()\r
-{\r
-    REQUIRE_PARAMS(4);\r
-    FX_FLOAT values[4];\r
-    for (int i = 0; i < 4; i ++) {\r
-        values[i] = GetNumber(3 - i);\r
-    }\r
-    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);\r
-    m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke()\r
-{\r
-    REQUIRE_PARAMS(4);\r
-    FX_FLOAT values[4];\r
-    for (int i = 0; i < 4; i ++) {\r
-        values[i] = GetNumber(3 - i);\r
-    }\r
-    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);\r
-    m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4);\r
-}\r
-void CPDF_StreamContentParser::Handle_LineTo()\r
-{\r
-    REQUIRE_PARAMS(2);\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO);\r
-}\r
-void CPDF_StreamContentParser::Handle_MoveTo()\r
-{\r
-    REQUIRE_PARAMS(2);\r
-    if (m_Options.m_bTextOnly) {\r
-#ifndef _FPDFAPI_MINI_\r
-        m_pSyntax->SkipPathObject();\r
-#endif\r
-        return;\r
-    }\r
-    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_MOVETO);\r
-#ifndef _FPDFAPI_MINI_\r
-    ParsePathObject();\r
-#endif\r
-}\r
-void CPDF_StreamContentParser::Handle_SetMiterLimit()\r
-{\r
-    m_pCurStates->m_GraphState.GetModify()->m_MiterLimit = GetNumber(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_MarkPlace()\r
-{\r
-}\r
-void CPDF_StreamContentParser::Handle_EndPath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathObject(0, FALSE);\r
-}\r
-void CPDF_StreamContentParser::Handle_SaveGraphState()\r
-{\r
-    CPDF_AllStates* pStates = FX_NEW CPDF_AllStates;\r
-    pStates->Copy(*m_pCurStates);\r
-    m_StateStack.Add(pStates);\r
-}\r
-void CPDF_StreamContentParser::Handle_RestoreGraphState()\r
-{\r
-    int size = m_StateStack.GetSize();\r
-    if (size == 0) {\r
-        return;\r
-    }\r
-    CPDF_AllStates* pStates = (CPDF_AllStates*)m_StateStack.GetAt(size - 1);\r
-    m_pCurStates->Copy(*pStates);\r
-    delete pStates;\r
-    m_StateStack.RemoveAt(size - 1);\r
-}\r
-void CPDF_StreamContentParser::Handle_Rectangle()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    FX_FLOAT x = GetNumber(3), y = GetNumber(2);\r
-    FX_FLOAT w = GetNumber(1), h = GetNumber(0);\r
-    AddPathRect(x, y, w, h);\r
-}\r
-void CPDF_StreamContentParser::AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, FX_FLOAT h)\r
-{\r
-    AddPathPoint(x, y, FXPT_MOVETO);\r
-    AddPathPoint(x + w, y, FXPT_LINETO);\r
-    AddPathPoint(x + w, y + h, FXPT_LINETO);\r
-    AddPathPoint(x, y + h, FXPT_LINETO);\r
-    AddPathPoint(x, y, FXPT_LINETO | FXPT_CLOSEFIGURE);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetRGBColor_Fill()\r
-{\r
-    REQUIRE_PARAMS(3);\r
-    FX_FLOAT values[3];\r
-    for (int i = 0; i < 3; i ++) {\r
-        values[i] = GetNumber(2 - i);\r
-    }\r
-    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);\r
-    m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke()\r
-{\r
-    REQUIRE_PARAMS(3);\r
-    FX_FLOAT values[3];\r
-    for (int i = 0; i < 3; i ++) {\r
-        values[i] = GetNumber(2 - i);\r
-    }\r
-    CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);\r
-    m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 3);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetRenderIntent()\r
-{\r
-}\r
-void CPDF_StreamContentParser::Handle_CloseStrokePath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    Handle_ClosePath();\r
-    AddPathObject(0, TRUE);\r
-}\r
-void CPDF_StreamContentParser::Handle_StrokePath()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathObject(0, TRUE);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetColor_Fill()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    FX_FLOAT values[4];\r
-    int nargs = m_ParamCount;\r
-    if (nargs > 4) {\r
-        nargs = 4;\r
-    }\r
-    for (int i = 0; i < nargs; i ++) {\r
-        values[i] = GetNumber(nargs - i - 1);\r
-    }\r
-    m_pCurStates->m_ColorState.SetFillColor(NULL, values, nargs);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetColor_Stroke()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    FX_FLOAT values[4];\r
-    int nargs = m_ParamCount;\r
-    if (nargs > 4) {\r
-        nargs = 4;\r
-    }\r
-    for (int i = 0; i < nargs; i ++) {\r
-        values[i] = GetNumber(nargs - i - 1);\r
-    }\r
-    m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nargs);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetColorPS_Fill()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    CPDF_Object* pLastParam = GetObject(0);\r
-    if (pLastParam == NULL) {\r
-        return;\r
-    }\r
-    int nargs = m_ParamCount;\r
-    int nvalues = nargs;\r
-    if (pLastParam->GetType() == PDFOBJ_NAME) {\r
-        nvalues --;\r
-    }\r
-    FX_FLOAT* values = NULL;\r
-    if (nvalues) {\r
-        values = FX_Alloc(FX_FLOAT, nvalues);\r
-        for (int i = 0; i < nvalues; i ++) {\r
-            values[i] = GetNumber(nargs - i - 1);\r
-        }\r
-    }\r
-    if (nvalues != nargs) {\r
-        CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);\r
-        if (pPattern) {\r
-            m_pCurStates->m_ColorState.SetFillPattern(pPattern, values, nvalues);\r
-        }\r
-    } else {\r
-        m_pCurStates->m_ColorState.SetFillColor(NULL, values, nvalues);\r
-    }\r
-    if (values) {\r
-        FX_Free(values);\r
-    }\r
-}\r
-void CPDF_StreamContentParser::Handle_SetColorPS_Stroke()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    CPDF_Object* pLastParam = GetObject(0);\r
-    if (pLastParam == NULL) {\r
-        return;\r
-    }\r
-    int nargs = m_ParamCount;\r
-    int nvalues = nargs;\r
-    if (pLastParam->GetType() == PDFOBJ_NAME) {\r
-        nvalues --;\r
-    }\r
-    FX_FLOAT* values = NULL;\r
-    if (nvalues) {\r
-        values = FX_Alloc(FX_FLOAT, nvalues);\r
-        for (int i = 0; i < nvalues; i ++) {\r
-            values[i] = GetNumber(nargs - i - 1);\r
-        }\r
-    }\r
-    if (nvalues != nargs) {\r
-        CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);\r
-        if (pPattern) {\r
-            m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues);\r
-        }\r
-    } else {\r
-        m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nvalues);\r
-    }\r
-    if (values) {\r
-        FX_Free(values);\r
-    }\r
-}\r
-CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, int type, const CFX_AffineMatrix* pMatrix,\r
-                              CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpace* pCS);\r
-void CPDF_StreamContentParser::Handle_ShadeFill()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE);\r
-    if (pPattern == NULL) {\r
-        return;\r
-    }\r
-    if (pPattern->m_PatternType != PATTERN_SHADING) {\r
-        return;\r
-    }\r
-    CPDF_ShadingPattern* pShading = (CPDF_ShadingPattern*)pPattern;\r
-    if (!pShading->m_bShadingObj) {\r
-        return;\r
-    }\r
-    if (!pShading->Load()) {\r
-        return;\r
-    }\r
-    CPDF_ShadingObject* pObj = FX_NEW CPDF_ShadingObject;\r
-    pObj->m_pShading = pShading;\r
-    SetGraphicStates(pObj, FALSE, FALSE, FALSE);\r
-    pObj->m_Matrix = m_pCurStates->m_CTM;\r
-    pObj->m_Matrix.Concat(m_mtContentToUser);\r
-    CFX_FloatRect bbox;\r
-    if (!pObj->m_ClipPath.IsNull()) {\r
-        bbox = pObj->m_ClipPath.GetClipBox();\r
-    } else {\r
-        bbox = m_BBox;\r
-    }\r
-    if (pShading->m_ShadingType >= 4) {\r
-        bbox.Intersect(_GetShadingBBox((CPDF_Stream*)pShading->m_pShadingObj, pShading->m_ShadingType, &pObj->m_Matrix,\r
-                                       pShading->m_pFunctions, pShading->m_nFuncs, pShading->m_pCS));\r
-    }\r
-    pObj->m_Left = bbox.left;\r
-    pObj->m_Right = bbox.right;\r
-    pObj->m_Top = bbox.top;\r
-    pObj->m_Bottom = bbox.bottom;\r
-    m_pObjectList->m_ObjectList.AddTail(pObj);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetCharSpace()\r
-{\r
-    m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_MoveTextPoint()\r
-{\r
-    m_pCurStates->m_TextLineX += GetNumber(1);\r
-    m_pCurStates->m_TextLineY += GetNumber(0);\r
-    m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;\r
-    m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;\r
-}\r
-void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading()\r
-{\r
-    Handle_MoveTextPoint();\r
-    m_pCurStates->m_TextLeading = -GetNumber(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetFont()\r
-{\r
-    FX_FLOAT fs = GetNumber(0);\r
-    if (fs == 0) {\r
-        fs = m_DefFontSize;\r
-    }\r
-    m_pCurStates->m_TextState.GetModify()->m_FontSize = fs;\r
-    CPDF_Font* pFont = FindFont(GetString(1));\r
-    if (pFont) {\r
-        m_pCurStates->m_TextState.SetFont(pFont);\r
-    }\r
-}\r
-CPDF_Object* CPDF_StreamContentParser::FindResourceObj(FX_BSTR type, const CFX_ByteString& name)\r
-{\r
-    if (m_pResources == NULL) {\r
-        return NULL;\r
-    }\r
-    if (m_pResources == m_pPageResources) {\r
-        CPDF_Dictionary* pList = m_pResources->GetDict(type);\r
-        if (pList == NULL) {\r
-            return NULL;\r
-        }\r
-        CPDF_Object* pRes = pList->GetElementValue(name);\r
-        return pRes;\r
-    }\r
-    CPDF_Dictionary* pList = m_pResources->GetDict(type);\r
-    if (pList == NULL) {\r
-        if (m_pPageResources == NULL) {\r
-            return NULL;\r
-        }\r
-        CPDF_Dictionary* pList = m_pPageResources->GetDict(type);\r
-        if (pList == NULL) {\r
-            return NULL;\r
-        }\r
-        CPDF_Object* pRes = pList->GetElementValue(name);\r
-        return pRes;\r
-    }\r
-    CPDF_Object* pRes = pList->GetElementValue(name);\r
-    return pRes;\r
-}\r
-CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name)\r
-{\r
-    CPDF_Dictionary* pFontDict = (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("Font"), name);\r
-    if (pFontDict == NULL || pFontDict->GetType() != PDFOBJ_DICTIONARY) {\r
-        m_bResourceMissing = TRUE;\r
-        return CPDF_Font::GetStockFont(m_pDocument, FX_BSTRC("Helvetica"));\r
-    }\r
-    CPDF_Font* pFont = m_pDocument->LoadFont(pFontDict);\r
-    if (pFont && pFont->GetType3Font()) {\r
-        pFont->GetType3Font()->SetPageResources(m_pResources);\r
-        pFont->GetType3Font()->CheckType3FontMetrics();\r
-    }\r
-    return pFont;\r
-}\r
-CPDF_ColorSpace* CPDF_StreamContentParser::FindColorSpace(const CFX_ByteString& name)\r
-{\r
-    if (name == FX_BSTRC("Pattern")) {\r
-        return CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN);\r
-    }\r
-    if (name == FX_BSTRC("DeviceGray") || name == FX_BSTRC("DeviceCMYK") || name == FX_BSTRC("DeviceRGB")) {\r
-        CFX_ByteString defname = "Default";\r
-        defname += name.Mid(7);\r
-        CPDF_Object* pDefObj = FindResourceObj(FX_BSTRC("ColorSpace"), defname);\r
-        if (pDefObj == NULL) {\r
-            if (name == FX_BSTRC("DeviceGray")) {\r
-                return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);\r
-            }\r
-            if (name == FX_BSTRC("DeviceRGB")) {\r
-                return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);\r
-            }\r
-            return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);\r
-        }\r
-        return m_pDocument->LoadColorSpace(pDefObj);\r
-    }\r
-    CPDF_Object* pCSObj = FindResourceObj(FX_BSTRC("ColorSpace"), name);\r
-    if (pCSObj == NULL) {\r
-        m_bResourceMissing = TRUE;\r
-        return NULL;\r
-    }\r
-    return m_pDocument->LoadColorSpace(pCSObj);\r
-}\r
-CPDF_Pattern* CPDF_StreamContentParser::FindPattern(const CFX_ByteString& name, FX_BOOL bShading)\r
-{\r
-    CPDF_Object* pPattern = FindResourceObj(bShading ? FX_BSTRC("Shading") : FX_BSTRC("Pattern"), name);\r
-    if (pPattern == NULL || (pPattern->GetType() != PDFOBJ_DICTIONARY &&\r
-                             pPattern->GetType() != PDFOBJ_STREAM)) {\r
-        m_bResourceMissing = TRUE;\r
-        return NULL;\r
-    }\r
-    return m_pDocument->LoadPattern(pPattern, bShading, &m_pCurStates->m_ParentMatrix);\r
-}\r
-void CPDF_StreamContentParser::ConvertTextSpace(FX_FLOAT& x, FX_FLOAT& y)\r
-{\r
-    m_pCurStates->m_TextMatrix.Transform(x, y, x, y);\r
-    ConvertUserSpace(x, y);\r
-}\r
-void CPDF_StreamContentParser::ConvertUserSpace(FX_FLOAT& x, FX_FLOAT& y)\r
-{\r
-    m_pCurStates->m_CTM.Transform(x, y, x, y);\r
-    m_mtContentToUser.Transform(x, y, x, y);\r
-}\r
-void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, FX_FLOAT fInitKerning, FX_FLOAT* pKerning, int nsegs)\r
-{\r
-    CPDF_Font* pFont = m_pCurStates->m_TextState.GetFont();\r
-    if (pFont == NULL) {\r
-        return;\r
-    }\r
-    if (fInitKerning != 0) {\r
-        if (!pFont->IsVertWriting()) {\r
-            m_pCurStates->m_TextX -= FXSYS_Mul(fInitKerning, m_pCurStates->m_TextState.GetFontSize()) / 1000;\r
-        } else {\r
-            m_pCurStates->m_TextY -= FXSYS_Mul(fInitKerning, m_pCurStates->m_TextState.GetFontSize()) / 1000;\r
-        }\r
-    }\r
-    if (nsegs == 0) {\r
-        return;\r
-    }\r
-    int textmode;\r
-    if (pFont->GetFontType() == PDFFONT_TYPE3) {\r
-        textmode = 0;\r
-    } else {\r
-        textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode;\r
-    }\r
-    CPDF_TextObject* pText = FX_NEW CPDF_TextObject;\r
-    m_pLastTextObject = pText;\r
-    SetGraphicStates(pText, TRUE, TRUE, TRUE);\r
-    if (textmode && textmode != 3 && textmode != 4 && textmode != 7) {\r
-        FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM;\r
-        pCTM[0] = m_pCurStates->m_CTM.a;\r
-        pCTM[1] = m_pCurStates->m_CTM.c;\r
-        pCTM[2] = m_pCurStates->m_CTM.b;\r
-        pCTM[3] = m_pCurStates->m_CTM.d;\r
-    }\r
-    pText->SetSegments(pStrs, pKerning, nsegs);\r
-    pText->m_PosX = m_pCurStates->m_TextX;\r
-    pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise;\r
-    ConvertTextSpace(pText->m_PosX, pText->m_PosY);\r
-    FX_FLOAT x_advance, y_advance;\r
-    pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScale, m_Level);\r
-    m_pCurStates->m_TextX += x_advance;\r
-    m_pCurStates->m_TextY += y_advance;\r
-    if (textmode > 3) {\r
-        CPDF_TextObject* pCopy = FX_NEW CPDF_TextObject;\r
-        pCopy->Copy(pText);\r
-        m_ClipTextList.Add(pCopy);\r
-    }\r
-    m_pObjectList->m_ObjectList.AddTail(pText);\r
-    if (pKerning && pKerning[nsegs - 1] != 0) {\r
-        if (!pFont->IsVertWriting()) {\r
-            m_pCurStates->m_TextX -= FXSYS_Mul(pKerning[nsegs - 1], m_pCurStates->m_TextState.GetFontSize()) / 1000;\r
-        } else {\r
-            m_pCurStates->m_TextY -= FXSYS_Mul(pKerning[nsegs - 1], m_pCurStates->m_TextState.GetFontSize()) / 1000;\r
-        }\r
-    }\r
-}\r
-void CPDF_StreamContentParser::Handle_ShowText()\r
-{\r
-    CFX_ByteString str = GetString(0);\r
-    if (str.IsEmpty()) {\r
-        return;\r
-    }\r
-    AddTextObject(&str, 0, NULL, 1);\r
-}\r
-void CPDF_StreamContentParser::Handle_ShowText_Positioning()\r
-{\r
-    CPDF_Array* pArray = GetObject(0)->GetArray();\r
-    if (pArray == NULL) {\r
-        return;\r
-    }\r
-    int n = pArray->GetCount(), nsegs = 0, i;\r
-    for (i = 0; i < n; i ++) {\r
-        CPDF_Object* pObj = pArray->GetElementValue(i);\r
-        if (pObj->GetType() == PDFOBJ_STRING) {\r
-            nsegs ++;\r
-        }\r
-    }\r
-    if (nsegs == 0) {\r
-        for (i = 0; i < n; i ++) {\r
-            m_pCurStates->m_TextX -= FXSYS_Mul(pArray->GetNumber(i), m_pCurStates->m_TextState.GetFontSize()) / 1000;\r
-        };\r
-        return;\r
-    }\r
-    CFX_ByteString* pStrs;\r
-    FX_NEW_VECTOR(pStrs, CFX_ByteString, nsegs);\r
-    FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs);\r
-    int iSegment = 0;\r
-    FX_FLOAT fInitKerning = 0;\r
-    for (i = 0; i < n; i ++) {\r
-        CPDF_Object* pObj = pArray->GetElementValue(i);\r
-        if (pObj->GetType() == PDFOBJ_STRING) {\r
-            CFX_ByteString str = pObj->GetString();\r
-            if (str.IsEmpty()) {\r
-                continue;\r
-            }\r
-            pStrs[iSegment] = str;\r
-            pKerning[iSegment ++] = 0;\r
-        } else {\r
-            if (iSegment == 0) {\r
-                fInitKerning += pObj->GetNumber();\r
-            } else {\r
-                pKerning[iSegment - 1] += pObj->GetNumber();\r
-            }\r
-        }\r
-    }\r
-    AddTextObject(pStrs, fInitKerning, pKerning, iSegment);\r
-    FX_DELETE_VECTOR(pStrs, CFX_ByteString, nsegs);\r
-    FX_Free(pKerning);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetTextLeading()\r
-{\r
-    m_pCurStates->m_TextLeading = GetNumber(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetTextMatrix()\r
-{\r
-    m_pCurStates->m_TextMatrix.Set(GetNumber16(5), GetNumber16(4), GetNumber16(3),\r
-                                   GetNumber16(2), GetNumber(1), GetNumber(0));\r
-    OnChangeTextMatrix();\r
-    m_pCurStates->m_TextX = 0;\r
-    m_pCurStates->m_TextY = 0;\r
-    m_pCurStates->m_TextLineX = 0;\r
-    m_pCurStates->m_TextLineY = 0;\r
-}\r
-void CPDF_StreamContentParser::OnChangeTextMatrix()\r
-{\r
-    CFX_AffineMatrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);\r
-    text_matrix.Concat(m_pCurStates->m_TextMatrix);\r
-    text_matrix.Concat(m_pCurStates->m_CTM);\r
-    text_matrix.Concat(m_mtContentToUser);\r
-    FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetModify()->m_Matrix;\r
-    pTextMatrix[0] = text_matrix.a;\r
-    pTextMatrix[1] = text_matrix.c;\r
-    pTextMatrix[2] = text_matrix.b;\r
-    pTextMatrix[3] = text_matrix.d;\r
-}\r
-void CPDF_StreamContentParser::Handle_SetTextRenderMode()\r
-{\r
-    int mode = GetInteger(0);\r
-    if (mode < 0 || mode > 7) {\r
-        return;\r
-    }\r
-    m_pCurStates->m_TextState.GetModify()->m_TextMode = mode;\r
-}\r
-void CPDF_StreamContentParser::Handle_SetTextRise()\r
-{\r
-    m_pCurStates->m_TextRise = GetNumber(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetWordSpace()\r
-{\r
-    m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(0);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetHorzScale()\r
-{\r
-    if (m_ParamCount != 1) {\r
-        return;\r
-    }\r
-    m_pCurStates->m_TextHorzScale = GetNumber(0) / 100;\r
-    OnChangeTextMatrix();\r
-}\r
-void CPDF_StreamContentParser::Handle_MoveToNextLine()\r
-{\r
-    m_pCurStates->m_TextLineY -= m_pCurStates->m_TextLeading;\r
-    m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;\r
-    m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;\r
-}\r
-void CPDF_StreamContentParser::Handle_CurveTo_23()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_BEZIERTO);\r
-    AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);\r
-    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);\r
-}\r
-void CPDF_StreamContentParser::Handle_SetLineWidth()\r
-{\r
-    FX_FLOAT width = GetNumber(0);\r
-    m_pCurStates->m_GraphState.GetModify()->m_LineWidth = width;\r
-}\r
-void CPDF_StreamContentParser::Handle_Clip()\r
-{\r
-    m_PathClipType = FXFILL_WINDING;\r
-}\r
-void CPDF_StreamContentParser::Handle_EOClip()\r
-{\r
-    m_PathClipType = FXFILL_ALTERNATE;\r
-}\r
-void CPDF_StreamContentParser::Handle_CurveTo_13()\r
-{\r
-    if (m_Options.m_bTextOnly) {\r
-        return;\r
-    }\r
-    AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);\r
-    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);\r
-    AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);\r
-}\r
-void CPDF_StreamContentParser::Handle_NextLineShowText()\r
-{\r
-    Handle_MoveToNextLine();\r
-    Handle_ShowText();\r
-}\r
-void CPDF_StreamContentParser::Handle_NextLineShowText_Space()\r
-{\r
-    m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(2);\r
-    m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(1);\r
-    Handle_NextLineShowText();\r
-}\r
-void CPDF_StreamContentParser::Handle_Invalid()\r
-{\r
-}\r
-void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag)\r
-{\r
-    m_PathCurrentX = x;\r
-    m_PathCurrentY = y;\r
-    if (flag == FXPT_MOVETO) {\r
-        m_PathStartX = x;\r
-        m_PathStartY = y;\r
-        if (m_PathPointCount && m_pPathPoints[m_PathPointCount - 1].m_Flag == FXPT_MOVETO) {\r
-            m_pPathPoints[m_PathPointCount - 1].m_PointX = x;\r
-            m_pPathPoints[m_PathPointCount - 1].m_PointY = y;\r
-            return;\r
-        }\r
-    } else if (m_PathPointCount == 0) {\r
-        return;\r
-    }\r
-    m_PathPointCount ++;\r
-    if (m_PathPointCount > m_PathAllocSize) {\r
-        int newsize = m_PathPointCount + 256;\r
-        FX_PATHPOINT* pNewPoints = FX_Alloc(FX_PATHPOINT, newsize);\r
-        if (m_PathAllocSize) {\r
-            FXSYS_memcpy32(pNewPoints, m_pPathPoints, m_PathAllocSize * sizeof(FX_PATHPOINT));\r
-            FX_Free(m_pPathPoints);\r
-        }\r
-        m_pPathPoints = pNewPoints;\r
-        m_PathAllocSize = newsize;\r
-    }\r
-    m_pPathPoints[m_PathPointCount - 1].m_Flag = flag;\r
-    m_pPathPoints[m_PathPointCount - 1].m_PointX = x;\r
-    m_pPathPoints[m_PathPointCount - 1].m_PointY = y;\r
-}\r
-void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke)\r
-{\r
-    int PathPointCount = m_PathPointCount, PathClipType = m_PathClipType;\r
-    m_PathPointCount = 0;\r
-    m_PathClipType = 0;\r
-    if (PathPointCount <= 1) {\r
-        if (PathPointCount && PathClipType) {\r
-            CPDF_Path path;\r
-            path.New()->AppendRect(0, 0, 0, 0);\r
-            m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE);\r
-        }\r
-        return;\r
-    }\r
-    if (PathPointCount && m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) {\r
-        PathPointCount --;\r
-    }\r
-    CPDF_Path Path;\r
-    CFX_PathData* pPathData = Path.New();\r
-    pPathData->SetPointCount(PathPointCount);\r
-    FXSYS_memcpy32(pPathData->GetPoints(), m_pPathPoints, sizeof(FX_PATHPOINT) * PathPointCount);\r
-    CFX_AffineMatrix matrix = m_pCurStates->m_CTM;\r
-    matrix.Concat(m_mtContentToUser);\r
-    if (bStroke || FillType) {\r
-        CPDF_PathObject* pPathObj = FX_NEW CPDF_PathObject;\r
-        pPathObj->m_bStroke = bStroke;\r
-        pPathObj->m_FillType = FillType;\r
-        pPathObj->m_Path = Path;\r
-        pPathObj->m_Matrix = matrix;\r
-        SetGraphicStates(pPathObj, TRUE, FALSE, TRUE);\r
-        pPathObj->CalcBoundingBox();\r
-        m_pObjectList->m_ObjectList.AddTail(pPathObj);\r
-    }\r
-    if (PathClipType) {\r
-        if (!matrix.IsIdentity()) {\r
-            Path.Transform(&matrix);\r
-            matrix.SetIdentity();\r
-        }\r
-        m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE);\r
-    }\r
-}\r
-CFX_ByteString _FPDF_ByteStringFromHex(CFX_BinaryBuf& src_buf)\r
-{\r
-    CFX_ByteTextBuf buf;\r
-    FX_BOOL bFirst = TRUE;\r
-    int code = 0;\r
-    FX_LPCBYTE str = src_buf.GetBuffer();\r
-    FX_DWORD size = src_buf.GetSize();\r
-    for (FX_DWORD i = 0; i < size; i ++) {\r
-        FX_BYTE ch = str[i];\r
-        if (ch >= '0' && ch <= '9') {\r
-            if (bFirst) {\r
-                code = (ch - '0') * 16;\r
-            } else {\r
-                code += ch - '0';\r
-                buf.AppendChar((char)code);\r
-            }\r
-            bFirst = !bFirst;\r
-        } else if (ch >= 'A' && ch <= 'F') {\r
-            if (bFirst) {\r
-                code = (ch - 'A' + 10) * 16;\r
-            } else {\r
-                code += ch - 'A' + 10;\r
-                buf.AppendChar((char)code);\r
-            }\r
-            bFirst = !bFirst;\r
-        } else if (ch >= 'a' && ch <= 'f') {\r
-            if (bFirst) {\r
-                code = (ch - 'a' + 10) * 16;\r
-            } else {\r
-                code += ch - 'a' + 10;\r
-                buf.AppendChar((char)code);\r
-            }\r
-            bFirst = !bFirst;\r
-        }\r
-    }\r
-    if (!bFirst) {\r
-        buf.AppendChar((char)code);\r
-    }\r
-    return buf.GetByteString();\r
-}\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../../include/fpdfapi/fpdf_page.h"
+#include "../../../include/fpdfapi/fpdf_module.h"
+#include "../../../include/fpdfapi/fpdf_serial.h"
+#include "pageint.h"
+
+#define REQUIRE_PARAMS(count)  \
+  if (m_ParamCount != count) { \
+    return;                    \
+  }
+
+CPDF_StreamContentParser::CPDF_StreamContentParser(
+    CPDF_Document* pDocument,
+    CPDF_Dictionary* pPageResources,
+    CPDF_Dictionary* pParentResources,
+    CFX_AffineMatrix* pmtContentToUser,
+    CPDF_PageObjects* pObjList,
+    CPDF_Dictionary* pResources,
+    CPDF_Rect* pBBox,
+    CPDF_ParseOptions* pOptions,
+    CPDF_AllStates* pStates,
+    int level)
+    : m_pDocument(pDocument),
+      m_pPageResources(pPageResources),
+      m_pParentResources(pParentResources),
+      m_pResources(pResources),
+      m_pObjectList(pObjList),
+      m_Level(level),
+      m_ParamStartPos(0),
+      m_ParamCount(0),
+      m_pCurStates(new CPDF_AllStates),
+      m_pLastTextObject(nullptr),
+      m_DefFontSize(0),
+      m_pPathPoints(nullptr),
+      m_PathPointCount(0),
+      m_PathAllocSize(0),
+      m_PathCurrentX(0.0f),
+      m_PathCurrentY(0.0f),
+      m_PathClipType(0),
+      m_pLastImage(nullptr),
+      m_pLastImageDict(nullptr),
+      m_pLastCloneImageDict(nullptr),
+      m_bReleaseLastDict(TRUE),
+      m_bColored(FALSE),
+      m_bResourceMissing(FALSE) {
+  if (pmtContentToUser) {
+    m_mtContentToUser = *pmtContentToUser;
+  }
+  if (pOptions) {
+    m_Options = *pOptions;
+  }
+  if (!m_pResources) {
+    m_pResources = m_pParentResources;
+  }
+  if (!m_pResources) {
+    m_pResources = m_pPageResources;
+  }
+  if (pBBox) {
+    m_BBox = *pBBox;
+  }
+  if (pStates) {
+    m_pCurStates->Copy(*pStates);
+  } else {
+    m_pCurStates->m_GeneralState.New();
+    m_pCurStates->m_GraphState.New();
+    m_pCurStates->m_TextState.New();
+    m_pCurStates->m_ColorState.New();
+  }
+  for (int i = 0; i < FX_ArraySize(m_Type3Data); ++i) {
+    m_Type3Data[i] = 0.0;
+  }
+}
+
+CPDF_StreamContentParser::~CPDF_StreamContentParser() {
+  ClearAllParams();
+  for (int i = 0; i < m_StateStack.GetSize(); ++i) {
+    delete (CPDF_AllStates*)m_StateStack[i];
+  }
+  FX_Free(m_pPathPoints);
+  if (m_pLastImageDict) {
+    m_pLastImageDict->Release();
+  }
+  if (m_pLastCloneImageDict) {
+    m_pLastCloneImageDict->Release();
+  }
+}
+int CPDF_StreamContentParser::GetNextParamPos() {
+  if (m_ParamCount == PARAM_BUF_SIZE) {
+    m_ParamStartPos++;
+    if (m_ParamStartPos == PARAM_BUF_SIZE) {
+      m_ParamStartPos = 0;
+    }
+    if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) {
+      if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject)
+        pObject->Release();
+    }
+    return m_ParamStartPos;
+  }
+  int index = m_ParamStartPos + m_ParamCount;
+  if (index >= PARAM_BUF_SIZE) {
+    index -= PARAM_BUF_SIZE;
+  }
+  m_ParamCount++;
+  return index;
+}
+void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) {
+  int index = GetNextParamPos();
+  if (len > 32) {
+    m_ParamBuf1[index].m_Type = 0;
+    m_ParamBuf1[index].m_pObject =
+        CPDF_Name::Create(PDF_NameDecode(CFX_ByteStringC(name, len)));
+  } else {
+    m_ParamBuf1[index].m_Type = PDFOBJ_NAME;
+    if (FXSYS_memchr(name, '#', len) == NULL) {
+      FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, name, len);
+      m_ParamBuf1[index].m_Name.m_Len = len;
+    } else {
+      CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len));
+      FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, str.c_str(),
+                   str.GetLength());
+      m_ParamBuf1[index].m_Name.m_Len = str.GetLength();
+    }
+  }
+}
+void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) {
+  int index = GetNextParamPos();
+  m_ParamBuf1[index].m_Type = PDFOBJ_NUMBER;
+  FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger,
+            &m_ParamBuf1[index].m_Number.m_Integer);
+}
+void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) {
+  int index = GetNextParamPos();
+  m_ParamBuf1[index].m_Type = 0;
+  m_ParamBuf1[index].m_pObject = pObj;
+}
+void CPDF_StreamContentParser::ClearAllParams() {
+  FX_DWORD index = m_ParamStartPos;
+  for (FX_DWORD i = 0; i < m_ParamCount; i++) {
+    if (m_ParamBuf1[index].m_Type == 0) {
+      if (CPDF_Object* pObject = m_ParamBuf1[index].m_pObject)
+        pObject->Release();
+    }
+    index++;
+    if (index == PARAM_BUF_SIZE) {
+      index = 0;
+    }
+  }
+  m_ParamStartPos = 0;
+  m_ParamCount = 0;
+}
+CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) {
+  if (index >= m_ParamCount) {
+    return NULL;
+  }
+  int real_index = m_ParamStartPos + m_ParamCount - index - 1;
+  if (real_index >= PARAM_BUF_SIZE) {
+    real_index -= PARAM_BUF_SIZE;
+  }
+  _ContentParam& param = m_ParamBuf1[real_index];
+  if (param.m_Type == PDFOBJ_NUMBER) {
+    CPDF_Number* pNumber = CPDF_Number::Create(param.m_Number.m_bInteger,
+                                               &param.m_Number.m_Integer);
+    param.m_Type = 0;
+    param.m_pObject = pNumber;
+    return pNumber;
+  }
+  if (param.m_Type == PDFOBJ_NAME) {
+    CPDF_Name* pName = CPDF_Name::Create(
+        CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
+    param.m_Type = 0;
+    param.m_pObject = pName;
+    return pName;
+  }
+  if (param.m_Type == 0) {
+    return param.m_pObject;
+  }
+  ASSERT(FALSE);
+  return NULL;
+}
+CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index) {
+  if (index >= m_ParamCount) {
+    return CFX_ByteString();
+  }
+  int real_index = m_ParamStartPos + m_ParamCount - index - 1;
+  if (real_index >= PARAM_BUF_SIZE) {
+    real_index -= PARAM_BUF_SIZE;
+  }
+  _ContentParam& param = m_ParamBuf1[real_index];
+  if (param.m_Type == PDFOBJ_NAME) {
+    return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len);
+  }
+  if (param.m_Type == 0 && param.m_pObject) {
+    return param.m_pObject->GetString();
+  }
+  return CFX_ByteString();
+}
+FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) {
+  if (index >= m_ParamCount) {
+    return 0;
+  }
+  int real_index = m_ParamStartPos + m_ParamCount - index - 1;
+  if (real_index >= PARAM_BUF_SIZE) {
+    real_index -= PARAM_BUF_SIZE;
+  }
+  _ContentParam& param = m_ParamBuf1[real_index];
+  if (param.m_Type == PDFOBJ_NUMBER) {
+    return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer
+                                     : param.m_Number.m_Float;
+  }
+  if (param.m_Type == 0 && param.m_pObject) {
+    return param.m_pObject->GetNumber();
+  }
+  return 0;
+}
+FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) {
+  return GetNumber(index);
+}
+void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj,
+                                                FX_BOOL bColor,
+                                                FX_BOOL bText,
+                                                FX_BOOL bGraph) {
+  pObj->m_GeneralState = m_pCurStates->m_GeneralState;
+  pObj->m_ClipPath = m_pCurStates->m_ClipPath;
+  pObj->m_ContentMark = m_CurContentMark;
+  if (bColor) {
+    pObj->m_ColorState = m_pCurStates->m_ColorState;
+  }
+  if (bGraph) {
+    pObj->m_GraphState = m_pCurStates->m_GraphState;
+  }
+  if (bText) {
+    pObj->m_TextState = m_pCurStates->m_TextState;
+  }
+}
+
+const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] = {
+    {FXBSTR_ID('"', 0, 0, 0),
+     &CPDF_StreamContentParser::Handle_NextLineShowText_Space},
+    {FXBSTR_ID('\'', 0, 0, 0),
+     &CPDF_StreamContentParser::Handle_NextLineShowText},
+    {FXBSTR_ID('B', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillStrokePath},
+    {FXBSTR_ID('B', '*', 0, 0),
+     &CPDF_StreamContentParser::Handle_EOFillStrokePath},
+    {FXBSTR_ID('B', 'D', 'C', 0),
+     &CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary},
+    {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage},
+    {FXBSTR_ID('B', 'M', 'C', 0),
+     &CPDF_StreamContentParser::Handle_BeginMarkedContent},
+    {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText},
+    {FXBSTR_ID('B', 'X', 0, 0),
+     &CPDF_StreamContentParser::Handle_BeginSectionUndefined},
+    {FXBSTR_ID('C', 'S', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetColorSpace_Stroke},
+    {FXBSTR_ID('D', 'P', 0, 0),
+     &CPDF_StreamContentParser::Handle_MarkPlace_Dictionary},
+    {FXBSTR_ID('D', 'o', 0, 0),
+     &CPDF_StreamContentParser::Handle_ExecuteXObject},
+    {FXBSTR_ID('E', 'I', 0, 0), &CPDF_StreamContentParser::Handle_EndImage},
+    {FXBSTR_ID('E', 'M', 'C', 0),
+     &CPDF_StreamContentParser::Handle_EndMarkedContent},
+    {FXBSTR_ID('E', 'T', 0, 0), &CPDF_StreamContentParser::Handle_EndText},
+    {FXBSTR_ID('E', 'X', 0, 0),
+     &CPDF_StreamContentParser::Handle_EndSectionUndefined},
+    {FXBSTR_ID('F', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPathOld},
+    {FXBSTR_ID('G', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Stroke},
+    {FXBSTR_ID('I', 'D', 0, 0),
+     &CPDF_StreamContentParser::Handle_BeginImageData},
+    {FXBSTR_ID('J', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineCap},
+    {FXBSTR_ID('K', 0, 0, 0),
+     &CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke},
+    {FXBSTR_ID('M', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetMiterLimit},
+    {FXBSTR_ID('M', 'P', 0, 0), &CPDF_StreamContentParser::Handle_MarkPlace},
+    {FXBSTR_ID('Q', 0, 0, 0),
+     &CPDF_StreamContentParser::Handle_RestoreGraphState},
+    {FXBSTR_ID('R', 'G', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetRGBColor_Stroke},
+    {FXBSTR_ID('S', 0, 0, 0), &CPDF_StreamContentParser::Handle_StrokePath},
+    {FXBSTR_ID('S', 'C', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetColor_Stroke},
+    {FXBSTR_ID('S', 'C', 'N', 0),
+     &CPDF_StreamContentParser::Handle_SetColorPS_Stroke},
+    {FXBSTR_ID('T', '*', 0, 0),
+     &CPDF_StreamContentParser::Handle_MoveToNextLine},
+    {FXBSTR_ID('T', 'D', 0, 0),
+     &CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading},
+    {FXBSTR_ID('T', 'J', 0, 0),
+     &CPDF_StreamContentParser::Handle_ShowText_Positioning},
+    {FXBSTR_ID('T', 'L', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetTextLeading},
+    {FXBSTR_ID('T', 'c', 0, 0), &CPDF_StreamContentParser::Handle_SetCharSpace},
+    {FXBSTR_ID('T', 'd', 0, 0),
+     &CPDF_StreamContentParser::Handle_MoveTextPoint},
+    {FXBSTR_ID('T', 'f', 0, 0), &CPDF_StreamContentParser::Handle_SetFont},
+    {FXBSTR_ID('T', 'j', 0, 0), &CPDF_StreamContentParser::Handle_ShowText},
+    {FXBSTR_ID('T', 'm', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetTextMatrix},
+    {FXBSTR_ID('T', 'r', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetTextRenderMode},
+    {FXBSTR_ID('T', 's', 0, 0), &CPDF_StreamContentParser::Handle_SetTextRise},
+    {FXBSTR_ID('T', 'w', 0, 0), &CPDF_StreamContentParser::Handle_SetWordSpace},
+    {FXBSTR_ID('T', 'z', 0, 0), &CPDF_StreamContentParser::Handle_SetHorzScale},
+    {FXBSTR_ID('W', 0, 0, 0), &CPDF_StreamContentParser::Handle_Clip},
+    {FXBSTR_ID('W', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOClip},
+    {FXBSTR_ID('b', 0, 0, 0),
+     &CPDF_StreamContentParser::Handle_CloseFillStrokePath},
+    {FXBSTR_ID('b', '*', 0, 0),
+     &CPDF_StreamContentParser::Handle_CloseEOFillStrokePath},
+    {FXBSTR_ID('c', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_123},
+    {FXBSTR_ID('c', 'm', 0, 0), &CPDF_StreamContentParser::Handle_ConcatMatrix},
+    {FXBSTR_ID('c', 's', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetColorSpace_Fill},
+    {FXBSTR_ID('d', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetDash},
+    {FXBSTR_ID('d', '0', 0, 0), &CPDF_StreamContentParser::Handle_SetCharWidth},
+    {FXBSTR_ID('d', '1', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetCachedDevice},
+    {FXBSTR_ID('f', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPath},
+    {FXBSTR_ID('f', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillPath},
+    {FXBSTR_ID('g', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Fill},
+    {FXBSTR_ID('g', 's', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetExtendGraphState},
+    {FXBSTR_ID('h', 0, 0, 0), &CPDF_StreamContentParser::Handle_ClosePath},
+    {FXBSTR_ID('i', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetFlat},
+    {FXBSTR_ID('j', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineJoin},
+    {FXBSTR_ID('k', 0, 0, 0),
+     &CPDF_StreamContentParser::Handle_SetCMYKColor_Fill},
+    {FXBSTR_ID('l', 0, 0, 0), &CPDF_StreamContentParser::Handle_LineTo},
+    {FXBSTR_ID('m', 0, 0, 0), &CPDF_StreamContentParser::Handle_MoveTo},
+    {FXBSTR_ID('n', 0, 0, 0), &CPDF_StreamContentParser::Handle_EndPath},
+    {FXBSTR_ID('q', 0, 0, 0), &CPDF_StreamContentParser::Handle_SaveGraphState},
+    {FXBSTR_ID('r', 'e', 0, 0), &CPDF_StreamContentParser::Handle_Rectangle},
+    {FXBSTR_ID('r', 'g', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetRGBColor_Fill},
+    {FXBSTR_ID('r', 'i', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetRenderIntent},
+    {FXBSTR_ID('s', 0, 0, 0),
+     &CPDF_StreamContentParser::Handle_CloseStrokePath},
+    {FXBSTR_ID('s', 'c', 0, 0),
+     &CPDF_StreamContentParser::Handle_SetColor_Fill},
+    {FXBSTR_ID('s', 'c', 'n', 0),
+     &CPDF_StreamContentParser::Handle_SetColorPS_Fill},
+    {FXBSTR_ID('s', 'h', 0, 0), &CPDF_StreamContentParser::Handle_ShadeFill},
+    {FXBSTR_ID('v', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_23},
+    {FXBSTR_ID('w', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineWidth},
+    {FXBSTR_ID('y', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_13},
+};
+FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) {
+  int i = 0;
+  FX_DWORD opid = 0;
+  while (i < 4 && op[i]) {
+    opid = (opid << 8) + op[i];
+    i++;
+  }
+  while (i < 4) {
+    opid <<= 8;
+    i++;
+  };
+  int low = 0, high = sizeof g_OpCodes / sizeof(OpCode) - 1;
+  while (low <= high) {
+    int middle = (low + high) / 2;
+    int compare = opid - g_OpCodes[middle].m_OpId;
+    if (compare == 0) {
+      (this->*g_OpCodes[middle].m_OpHandler)();
+      return TRUE;
+    }
+    if (compare < 0) {
+      high = middle - 1;
+    } else {
+      low = middle + 1;
+    }
+  }
+  return m_CompatCount != 0;
+}
+void CPDF_StreamContentParser::Handle_CloseFillStrokePath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  Handle_ClosePath();
+  AddPathObject(FXFILL_WINDING, TRUE);
+}
+void CPDF_StreamContentParser::Handle_FillStrokePath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathObject(FXFILL_WINDING, TRUE);
+}
+void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
+  AddPathObject(FXFILL_ALTERNATE, TRUE);
+}
+void CPDF_StreamContentParser::Handle_EOFillStrokePath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathObject(FXFILL_ALTERNATE, TRUE);
+}
+void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
+  if (!m_Options.m_bMarkedContent) {
+    return;
+  }
+  CFX_ByteString tag = GetString(1);
+  CPDF_Object* pProperty = GetObject(0);
+  if (pProperty == NULL) {
+    return;
+  }
+  FX_BOOL bDirect = TRUE;
+  if (pProperty->GetType() == PDFOBJ_NAME) {
+    pProperty = FindResourceObj(FX_BSTRC("Properties"), pProperty->GetString());
+    if (pProperty == NULL) {
+      return;
+    }
+    bDirect = FALSE;
+  }
+  if (pProperty->GetType() != PDFOBJ_DICTIONARY) {
+    return;
+  }
+  m_CurContentMark.GetModify()->AddMark(tag, (CPDF_Dictionary*)pProperty,
+                                        bDirect);
+}
+void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
+  if (!m_Options.m_bMarkedContent) {
+    return;
+  }
+  CFX_ByteString tag = GetString(0);
+  m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
+}
+struct _FX_BSTR {
+  const FX_CHAR* m_Ptr;
+  int m_Size;
+};
+#define _FX_BSTRC(str) \
+  { str, sizeof(str) - 1 }
+const _FX_BSTR _PDF_InlineKeyAbbr[] = {
+    _FX_BSTRC("BitsPerComponent"),
+    _FX_BSTRC("BPC"),
+    _FX_BSTRC("ColorSpace"),
+    _FX_BSTRC("CS"),
+    _FX_BSTRC("Decode"),
+    _FX_BSTRC("D"),
+    _FX_BSTRC("DecodeParms"),
+    _FX_BSTRC("DP"),
+    _FX_BSTRC("Filter"),
+    _FX_BSTRC("F"),
+    _FX_BSTRC("Height"),
+    _FX_BSTRC("H"),
+    _FX_BSTRC("ImageMask"),
+    _FX_BSTRC("IM"),
+    _FX_BSTRC("Interpolate"),
+    _FX_BSTRC("I"),
+    _FX_BSTRC("Width"),
+    _FX_BSTRC("W"),
+};
+const _FX_BSTR _PDF_InlineValueAbbr[] = {
+    _FX_BSTRC("DeviceGray"),      _FX_BSTRC("G"),
+    _FX_BSTRC("DeviceRGB"),       _FX_BSTRC("RGB"),
+    _FX_BSTRC("DeviceCMYK"),      _FX_BSTRC("CMYK"),
+    _FX_BSTRC("Indexed"),         _FX_BSTRC("I"),
+    _FX_BSTRC("ASCIIHexDecode"),  _FX_BSTRC("AHx"),
+    _FX_BSTRC("ASCII85Decode"),   _FX_BSTRC("A85"),
+    _FX_BSTRC("LZWDecode"),       _FX_BSTRC("LZW"),
+    _FX_BSTRC("FlateDecode"),     _FX_BSTRC("Fl"),
+    _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"),
+    _FX_BSTRC("CCITTFaxDecode"),  _FX_BSTRC("CCF"),
+    _FX_BSTRC("DCTDecode"),       _FX_BSTRC("DCT"),
+};
+static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table,
+                                         int count,
+                                         const CFX_ByteStringC& abbr) {
+  int i = 0;
+  while (i < count) {
+    if (abbr.GetLength() == table[i + 1].m_Size &&
+        FXSYS_memcmp(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) ==
+            0) {
+      return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size);
+    }
+    i += 2;
+  }
+  return CFX_ByteStringC();
+}
+void _PDF_ReplaceAbbr(CPDF_Object* pObj) {
+  switch (pObj->GetType()) {
+    case PDFOBJ_DICTIONARY: {
+      CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
+      FX_POSITION pos = pDict->GetStartPos();
+      while (pos) {
+        CFX_ByteString key;
+        CPDF_Object* value = pDict->GetNextElement(pos, key);
+        CFX_ByteStringC fullname = _PDF_FindFullName(
+            _PDF_InlineKeyAbbr, sizeof _PDF_InlineKeyAbbr / sizeof(_FX_BSTR),
+            key);
+        if (!fullname.IsEmpty()) {
+          pDict->ReplaceKey(key, fullname);
+          key = fullname;
+        }
+        if (value->GetType() == PDFOBJ_NAME) {
+          CFX_ByteString name = value->GetString();
+          fullname = _PDF_FindFullName(
+              _PDF_InlineValueAbbr,
+              sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
+          if (!fullname.IsEmpty()) {
+            pDict->SetAtName(key, fullname);
+          }
+        } else {
+          _PDF_ReplaceAbbr(value);
+        }
+      }
+      break;
+    }
+    case PDFOBJ_ARRAY: {
+      CPDF_Array* pArray = (CPDF_Array*)pObj;
+      for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
+        CPDF_Object* pElement = pArray->GetElement(i);
+        if (pElement->GetType() == PDFOBJ_NAME) {
+          CFX_ByteString name = pElement->GetString();
+          CFX_ByteStringC fullname = _PDF_FindFullName(
+              _PDF_InlineValueAbbr,
+              sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
+          if (!fullname.IsEmpty()) {
+            pArray->SetAt(i, CPDF_Name::Create(fullname));
+          }
+        } else {
+          _PDF_ReplaceAbbr(pElement);
+        }
+      }
+      break;
+    }
+  }
+}
+static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table,
+                                         int count,
+                                         const CFX_ByteStringC& fullName) {
+  int i = 0;
+  while (i < count) {
+    if (fullName.GetLength() == table[i].m_Size &&
+        FXSYS_memcmp(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) ==
+            0) {
+      return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);
+    }
+    i += 2;
+  }
+  return CFX_ByteStringC();
+}
+void _PDF_ReplaceFull(CPDF_Object* pObj) {
+  switch (pObj->GetType()) {
+    case PDFOBJ_DICTIONARY: {
+      CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
+      FX_POSITION pos = pDict->GetStartPos();
+      while (pos) {
+        CFX_ByteString key;
+        CPDF_Object* value = pDict->GetNextElement(pos, key);
+        CFX_ByteStringC abbrName = _PDF_FindAbbrName(
+            _PDF_InlineKeyAbbr, sizeof(_PDF_InlineKeyAbbr) / sizeof(_FX_BSTR),
+            key);
+        if (!abbrName.IsEmpty()) {
+          pDict->ReplaceKey(key, abbrName);
+          key = abbrName;
+        }
+        if (value->GetType() == PDFOBJ_NAME) {
+          CFX_ByteString name = value->GetString();
+          abbrName = _PDF_FindAbbrName(
+              _PDF_InlineValueAbbr,
+              sizeof(_PDF_InlineValueAbbr) / sizeof(_FX_BSTR), name);
+          if (!abbrName.IsEmpty()) {
+            pDict->SetAtName(key, abbrName);
+          }
+        } else {
+          _PDF_ReplaceFull(value);
+        }
+      }
+      break;
+    }
+    case PDFOBJ_ARRAY: {
+      CPDF_Array* pArray = (CPDF_Array*)pObj;
+      for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
+        CPDF_Object* pElement = pArray->GetElement(i);
+        if (pElement->GetType() == PDFOBJ_NAME) {
+          CFX_ByteString name = pElement->GetString();
+          CFX_ByteStringC abbrName = _PDF_FindAbbrName(
+              _PDF_InlineValueAbbr,
+              sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
+          if (!abbrName.IsEmpty()) {
+            pArray->SetAt(i, CPDF_Name::Create(abbrName));
+          }
+        } else {
+          _PDF_ReplaceFull(pElement);
+        }
+      }
+      break;
+    }
+  }
+}
+void CPDF_StreamContentParser::Handle_BeginText() {
+  m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0);
+  OnChangeTextMatrix();
+  m_pCurStates->m_TextX = 0;
+  m_pCurStates->m_TextY = 0;
+  m_pCurStates->m_TextLineX = 0;
+  m_pCurStates->m_TextLineY = 0;
+}
+void CPDF_StreamContentParser::Handle_BeginSectionUndefined() {
+  m_CompatCount++;
+}
+void CPDF_StreamContentParser::Handle_CurveTo_123() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO);
+  AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
+  AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
+}
+void CPDF_StreamContentParser::Handle_ConcatMatrix() {
+  FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3),
+           d2 = GetNumber16(2);
+  FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0);
+  CFX_AffineMatrix new_matrix(a2, b2, c2, d2, e2, f2);
+  new_matrix.Concat(m_pCurStates->m_CTM);
+  m_pCurStates->m_CTM = new_matrix;
+  OnChangeTextMatrix();
+}
+void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  CFX_ByteString csname = GetString(0);
+  CPDF_ColorSpace* pCS = FindColorSpace(csname);
+  if (pCS == NULL) {
+    return;
+  }
+  m_pCurStates->m_ColorState.GetModify()->m_FillColor.SetColorSpace(pCS);
+}
+void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  CFX_ByteString csname = GetString(0);
+  CPDF_ColorSpace* pCS = FindColorSpace(csname);
+  if (pCS == NULL) {
+    return;
+  }
+  m_pCurStates->m_ColorState.GetModify()->m_StrokeColor.SetColorSpace(pCS);
+}
+void CPDF_StreamContentParser::Handle_SetDash() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  CPDF_Array* pArray = GetObject(1) ? GetObject(1)->GetArray() : NULL;
+  if (pArray == NULL) {
+    return;
+  }
+  m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f);
+}
+void CPDF_StreamContentParser::Handle_SetCharWidth() {
+  m_Type3Data[0] = GetNumber(1);
+  m_Type3Data[1] = GetNumber(0);
+  m_bColored = TRUE;
+}
+void CPDF_StreamContentParser::Handle_SetCachedDevice() {
+  for (int i = 0; i < 6; i++) {
+    m_Type3Data[i] = GetNumber(5 - i);
+  }
+  m_bColored = FALSE;
+}
+void CPDF_StreamContentParser::Handle_ExecuteXObject() {
+  CFX_ByteString name = GetString(0);
+  if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() &&
+      m_pLastImage->GetStream()->GetObjNum()) {
+    AddImage(NULL, m_pLastImage, FALSE);
+    return;
+  }
+  if (m_Options.m_bTextOnly) {
+    CPDF_Object* pRes = NULL;
+    if (m_pResources == NULL) {
+      return;
+    }
+    if (m_pResources == m_pPageResources) {
+      CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
+      if (pList == NULL) {
+        return;
+      }
+      pRes = pList->GetElement(name);
+      if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
+        return;
+      }
+    } else {
+      CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
+      if (pList == NULL) {
+        if (m_pPageResources == NULL) {
+          return;
+        }
+        CPDF_Dictionary* pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));
+        if (pList == NULL) {
+          return;
+        }
+        pRes = pList->GetElement(name);
+        if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
+          return;
+        }
+      } else {
+        pRes = pList->GetElement(name);
+        if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
+          return;
+        }
+      }
+    }
+    FX_BOOL bForm;
+    if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(),
+                                  bForm) &&
+        !bForm) {
+      return;
+    }
+  }
+  CPDF_Stream* pXObject =
+      (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), name);
+  if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) {
+    m_bResourceMissing = TRUE;
+    return;
+  }
+  CFX_ByteStringC type =
+      pXObject->GetDict()
+          ? pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype"))
+          : CFX_ByteStringC();
+  if (type == FX_BSTRC("Image")) {
+    if (m_Options.m_bTextOnly) {
+      return;
+    }
+    CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE);
+    m_LastImageName = name;
+    m_pLastImage = pObj->m_pImage;
+  } else if (type == FX_BSTRC("Form")) {
+    AddForm(pXObject);
+  } else {
+    return;
+  }
+}
+void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
+  if (!m_Options.m_bSeparateForm) {
+    CPDF_Dictionary* pResources =
+        pStream->GetDict()->GetDict(FX_BSTRC("Resources"));
+    CFX_AffineMatrix form_matrix =
+        pStream->GetDict()->GetMatrix(FX_BSTRC("Matrix"));
+    form_matrix.Concat(m_pCurStates->m_CTM);
+    CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox"));
+    CFX_FloatRect form_bbox;
+    CPDF_Path ClipPath;
+    if (pBBox) {
+      form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox"));
+      ClipPath.New();
+      ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right,
+                          form_bbox.top);
+      ClipPath.Transform(&form_matrix);
+      form_bbox.Transform(&form_matrix);
+    }
+    CPDF_StreamContentParser parser(m_pDocument, m_pPageResources, m_pResources,
+                                    &m_mtContentToUser, m_pObjectList,
+                                    pResources, &form_bbox, &m_Options,
+                                    m_pCurStates.get(), m_Level + 1);
+    parser.m_pCurStates->m_CTM = form_matrix;
+    if (ClipPath.NotNull()) {
+      parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING,
+                                                 TRUE);
+    }
+    CPDF_StreamAcc stream;
+    stream.LoadAllData(pStream, FALSE);
+    if (stream.GetSize() == 0) {
+      return;
+    }
+    parser.Parse(stream.GetData(), stream.GetSize(), 0);
+    return;
+  }
+  CPDF_FormObject* pFormObj = new CPDF_FormObject;
+  pFormObj->m_pForm =
+      new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);
+  pFormObj->m_FormMatrix = m_pCurStates->m_CTM;
+  pFormObj->m_FormMatrix.Concat(m_mtContentToUser);
+  CPDF_AllStates status;
+  status.m_GeneralState = m_pCurStates->m_GeneralState;
+  status.m_GraphState = m_pCurStates->m_GraphState;
+  status.m_ColorState = m_pCurStates->m_ColorState;
+  status.m_TextState = m_pCurStates->m_TextState;
+  pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1);
+  if (!m_pObjectList->m_bBackgroundAlphaNeeded &&
+      pFormObj->m_pForm->m_bBackgroundAlphaNeeded) {
+    m_pObjectList->m_bBackgroundAlphaNeeded = TRUE;
+  }
+  pFormObj->CalcBoundingBox();
+  SetGraphicStates(pFormObj, TRUE, TRUE, TRUE);
+  m_pObjectList->m_ObjectList.AddTail(pFormObj);
+}
+CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream,
+                                                     CPDF_Image* pImage,
+                                                     FX_BOOL bInline) {
+  if (pStream == NULL && pImage == NULL) {
+    return NULL;
+  }
+  CFX_AffineMatrix ImageMatrix;
+  ImageMatrix.Copy(m_pCurStates->m_CTM);
+  ImageMatrix.Concat(m_mtContentToUser);
+  CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
+  if (pImage) {
+    pImageObj->m_pImage =
+        m_pDocument->GetPageData()->GetImage(pImage->GetStream());
+  } else if (pStream->GetObjNum()) {
+    pImageObj->m_pImage = m_pDocument->LoadImageF(pStream);
+  } else {
+    pImageObj->m_pImage = new CPDF_Image(m_pDocument);
+    pImageObj->m_pImage->LoadImageF(pStream, bInline);
+  }
+  SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE);
+  pImageObj->m_Matrix = ImageMatrix;
+  pImageObj->CalcBoundingBox();
+  m_pObjectList->m_ObjectList.AddTail(pImageObj);
+  return pImageObj;
+}
+void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {}
+void CPDF_StreamContentParser::Handle_EndImage() {}
+void CPDF_StreamContentParser::Handle_EndMarkedContent() {
+  if (!m_Options.m_bMarkedContent) {
+    return;
+  }
+  if (m_CurContentMark.IsNull()) {
+    return;
+  }
+  int count = m_CurContentMark.GetObject()->CountItems();
+  if (count == 1) {
+    m_CurContentMark.SetNull();
+    return;
+  }
+  m_CurContentMark.GetModify()->DeleteLastMark();
+}
+void CPDF_StreamContentParser::Handle_EndText() {
+  int count = m_ClipTextList.GetSize();
+  if (count == 0) {
+    return;
+  }
+  if (m_pCurStates->m_TextState.GetObject()->m_TextMode < 4) {
+    for (int i = 0; i < count; i++) {
+      CPDF_TextObject* pText = (CPDF_TextObject*)m_ClipTextList.GetAt(i);
+      delete pText;
+    }
+  } else {
+    m_pCurStates->m_ClipPath.AppendTexts(
+        (CPDF_TextObject**)m_ClipTextList.GetData(), count);
+  }
+  m_ClipTextList.RemoveAll();
+}
+void CPDF_StreamContentParser::Handle_EndSectionUndefined() {
+  if (m_CompatCount) {
+    m_CompatCount--;
+  }
+}
+void CPDF_StreamContentParser::Handle_FillPath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathObject(FXFILL_WINDING, FALSE);
+}
+void CPDF_StreamContentParser::Handle_FillPathOld() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathObject(FXFILL_WINDING, FALSE);
+}
+void CPDF_StreamContentParser::Handle_EOFillPath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathObject(FXFILL_ALTERNATE, FALSE);
+}
+void CPDF_StreamContentParser::Handle_SetGray_Fill() {
+  FX_FLOAT value = GetNumber(0);
+  CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
+  m_pCurStates->m_ColorState.SetFillColor(pCS, &value, 1);
+}
+void CPDF_StreamContentParser::Handle_SetGray_Stroke() {
+  FX_FLOAT value = GetNumber(0);
+  CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
+  m_pCurStates->m_ColorState.SetStrokeColor(pCS, &value, 1);
+}
+void CPDF_StreamContentParser::Handle_SetExtendGraphState() {
+  CFX_ByteString name = GetString(0);
+  CPDF_Dictionary* pGS =
+      (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("ExtGState"), name);
+  if (pGS == NULL || pGS->GetType() != PDFOBJ_DICTIONARY) {
+    m_bResourceMissing = TRUE;
+    return;
+  }
+  m_pCurStates->ProcessExtGS(pGS, this);
+}
+void CPDF_StreamContentParser::Handle_ClosePath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  if (m_PathPointCount == 0) {
+    return;
+  }
+  if (m_PathStartX != m_PathCurrentX || m_PathStartY != m_PathCurrentY) {
+    AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
+  } else if (m_pPathPoints[m_PathPointCount - 1].m_Flag != FXPT_MOVETO) {
+    m_pPathPoints[m_PathPointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
+  }
+}
+void CPDF_StreamContentParser::Handle_SetFlat() {
+  m_pCurStates->m_GeneralState.GetModify()->m_Flatness = GetNumber(0);
+}
+void CPDF_StreamContentParser::Handle_BeginImageData() {}
+void CPDF_StreamContentParser::Handle_SetLineJoin() {
+  m_pCurStates->m_GraphState.GetModify()->m_LineJoin =
+      (CFX_GraphStateData::LineJoin)GetInteger(0);
+}
+void CPDF_StreamContentParser::Handle_SetLineCap() {
+  m_pCurStates->m_GraphState.GetModify()->m_LineCap =
+      (CFX_GraphStateData::LineCap)GetInteger(0);
+}
+void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill() {
+  REQUIRE_PARAMS(4);
+  FX_FLOAT values[4];
+  for (int i = 0; i < 4; i++) {
+    values[i] = GetNumber(3 - i);
+  }
+  CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
+  m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4);
+}
+void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() {
+  REQUIRE_PARAMS(4);
+  FX_FLOAT values[4];
+  for (int i = 0; i < 4; i++) {
+    values[i] = GetNumber(3 - i);
+  }
+  CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
+  m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4);
+}
+void CPDF_StreamContentParser::Handle_LineTo() {
+  REQUIRE_PARAMS(2);
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO);
+}
+void CPDF_StreamContentParser::Handle_MoveTo() {
+  REQUIRE_PARAMS(2);
+  if (m_Options.m_bTextOnly) {
+    m_pSyntax->SkipPathObject();
+    return;
+  }
+  AddPathPoint(GetNumber(1), GetNumber(0), FXPT_MOVETO);
+  ParsePathObject();
+}
+void CPDF_StreamContentParser::Handle_SetMiterLimit() {
+  m_pCurStates->m_GraphState.GetModify()->m_MiterLimit = GetNumber(0);
+}
+void CPDF_StreamContentParser::Handle_MarkPlace() {}
+void CPDF_StreamContentParser::Handle_EndPath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathObject(0, FALSE);
+}
+void CPDF_StreamContentParser::Handle_SaveGraphState() {
+  CPDF_AllStates* pStates = new CPDF_AllStates;
+  pStates->Copy(*m_pCurStates);
+  m_StateStack.Add(pStates);
+}
+void CPDF_StreamContentParser::Handle_RestoreGraphState() {
+  int size = m_StateStack.GetSize();
+  if (size == 0) {
+    return;
+  }
+  CPDF_AllStates* pStates = (CPDF_AllStates*)m_StateStack.GetAt(size - 1);
+  m_pCurStates->Copy(*pStates);
+  delete pStates;
+  m_StateStack.RemoveAt(size - 1);
+}
+void CPDF_StreamContentParser::Handle_Rectangle() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  FX_FLOAT x = GetNumber(3), y = GetNumber(2);
+  FX_FLOAT w = GetNumber(1), h = GetNumber(0);
+  AddPathRect(x, y, w, h);
+}
+void CPDF_StreamContentParser::AddPathRect(FX_FLOAT x,
+                                           FX_FLOAT y,
+                                           FX_FLOAT w,
+                                           FX_FLOAT h) {
+  AddPathPoint(x, y, FXPT_MOVETO);
+  AddPathPoint(x + w, y, FXPT_LINETO);
+  AddPathPoint(x + w, y + h, FXPT_LINETO);
+  AddPathPoint(x, y + h, FXPT_LINETO);
+  AddPathPoint(x, y, FXPT_LINETO | FXPT_CLOSEFIGURE);
+}
+void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() {
+  REQUIRE_PARAMS(3);
+  FX_FLOAT values[3];
+  for (int i = 0; i < 3; i++) {
+    values[i] = GetNumber(2 - i);
+  }
+  CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
+  m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3);
+}
+void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() {
+  REQUIRE_PARAMS(3);
+  FX_FLOAT values[3];
+  for (int i = 0; i < 3; i++) {
+    values[i] = GetNumber(2 - i);
+  }
+  CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
+  m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 3);
+}
+void CPDF_StreamContentParser::Handle_SetRenderIntent() {}
+void CPDF_StreamContentParser::Handle_CloseStrokePath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  Handle_ClosePath();
+  AddPathObject(0, TRUE);
+}
+void CPDF_StreamContentParser::Handle_StrokePath() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathObject(0, TRUE);
+}
+void CPDF_StreamContentParser::Handle_SetColor_Fill() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  FX_FLOAT values[4];
+  int nargs = m_ParamCount;
+  if (nargs > 4) {
+    nargs = 4;
+  }
+  for (int i = 0; i < nargs; i++) {
+    values[i] = GetNumber(nargs - i - 1);
+  }
+  m_pCurStates->m_ColorState.SetFillColor(NULL, values, nargs);
+}
+void CPDF_StreamContentParser::Handle_SetColor_Stroke() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  FX_FLOAT values[4];
+  int nargs = m_ParamCount;
+  if (nargs > 4) {
+    nargs = 4;
+  }
+  for (int i = 0; i < nargs; i++) {
+    values[i] = GetNumber(nargs - i - 1);
+  }
+  m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nargs);
+}
+void CPDF_StreamContentParser::Handle_SetColorPS_Fill() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  CPDF_Object* pLastParam = GetObject(0);
+  if (pLastParam == NULL) {
+    return;
+  }
+  int nargs = m_ParamCount;
+  int nvalues = nargs;
+  if (pLastParam->GetType() == PDFOBJ_NAME) {
+    nvalues--;
+  }
+  FX_FLOAT* values = NULL;
+  if (nvalues) {
+    values = FX_Alloc(FX_FLOAT, nvalues);
+    for (int i = 0; i < nvalues; i++) {
+      values[i] = GetNumber(nargs - i - 1);
+    }
+  }
+  if (nvalues != nargs) {
+    CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);
+    if (pPattern) {
+      m_pCurStates->m_ColorState.SetFillPattern(pPattern, values, nvalues);
+    }
+  } else {
+    m_pCurStates->m_ColorState.SetFillColor(NULL, values, nvalues);
+  }
+  FX_Free(values);
+}
+void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  CPDF_Object* pLastParam = GetObject(0);
+  if (pLastParam == NULL) {
+    return;
+  }
+  int nargs = m_ParamCount;
+  int nvalues = nargs;
+  if (pLastParam->GetType() == PDFOBJ_NAME) {
+    nvalues--;
+  }
+  FX_FLOAT* values = NULL;
+  if (nvalues) {
+    values = FX_Alloc(FX_FLOAT, nvalues);
+    for (int i = 0; i < nvalues; i++) {
+      values[i] = GetNumber(nargs - i - 1);
+    }
+  }
+  if (nvalues != nargs) {
+    CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);
+    if (pPattern) {
+      m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues);
+    }
+  } else {
+    m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nvalues);
+  }
+  FX_Free(values);
+}
+CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream,
+                              int type,
+                              const CFX_AffineMatrix* pMatrix,
+                              CPDF_Function** pFuncs,
+                              int nFuncs,
+                              CPDF_ColorSpace* pCS);
+void CPDF_StreamContentParser::Handle_ShadeFill() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE);
+  if (pPattern == NULL) {
+    return;
+  }
+  if (pPattern->m_PatternType != PATTERN_SHADING) {
+    return;
+  }
+  CPDF_ShadingPattern* pShading = (CPDF_ShadingPattern*)pPattern;
+  if (!pShading->m_bShadingObj) {
+    return;
+  }
+  if (!pShading->Load()) {
+    return;
+  }
+  CPDF_ShadingObject* pObj = new CPDF_ShadingObject;
+  pObj->m_pShading = pShading;
+  SetGraphicStates(pObj, FALSE, FALSE, FALSE);
+  pObj->m_Matrix = m_pCurStates->m_CTM;
+  pObj->m_Matrix.Concat(m_mtContentToUser);
+  CFX_FloatRect bbox;
+  if (!pObj->m_ClipPath.IsNull()) {
+    bbox = pObj->m_ClipPath.GetClipBox();
+  } else {
+    bbox = m_BBox;
+  }
+  if (pShading->m_ShadingType >= 4) {
+    bbox.Intersect(_GetShadingBBox((CPDF_Stream*)pShading->m_pShadingObj,
+                                   pShading->m_ShadingType, &pObj->m_Matrix,
+                                   pShading->m_pFunctions, pShading->m_nFuncs,
+                                   pShading->m_pCS));
+  }
+  pObj->m_Left = bbox.left;
+  pObj->m_Right = bbox.right;
+  pObj->m_Top = bbox.top;
+  pObj->m_Bottom = bbox.bottom;
+  m_pObjectList->m_ObjectList.AddTail(pObj);
+}
+void CPDF_StreamContentParser::Handle_SetCharSpace() {
+  m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0);
+}
+void CPDF_StreamContentParser::Handle_MoveTextPoint() {
+  m_pCurStates->m_TextLineX += GetNumber(1);
+  m_pCurStates->m_TextLineY += GetNumber(0);
+  m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
+  m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
+}
+void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading() {
+  Handle_MoveTextPoint();
+  m_pCurStates->m_TextLeading = -GetNumber(0);
+}
+void CPDF_StreamContentParser::Handle_SetFont() {
+  FX_FLOAT fs = GetNumber(0);
+  if (fs == 0) {
+    fs = m_DefFontSize;
+  }
+  m_pCurStates->m_TextState.GetModify()->m_FontSize = fs;
+  CPDF_Font* pFont = FindFont(GetString(1));
+  if (pFont) {
+    m_pCurStates->m_TextState.SetFont(pFont);
+  }
+}
+CPDF_Object* CPDF_StreamContentParser::FindResourceObj(
+    const CFX_ByteStringC& type,
+    const CFX_ByteString& name) {
+  if (m_pResources == NULL) {
+    return NULL;
+  }
+  if (m_pResources == m_pPageResources) {
+    CPDF_Dictionary* pList = m_pResources->GetDict(type);
+    if (pList == NULL) {
+      return NULL;
+    }
+    CPDF_Object* pRes = pList->GetElementValue(name);
+    return pRes;
+  }
+  CPDF_Dictionary* pList = m_pResources->GetDict(type);
+  if (pList == NULL) {
+    if (m_pPageResources == NULL) {
+      return NULL;
+    }
+    CPDF_Dictionary* pList = m_pPageResources->GetDict(type);
+    if (pList == NULL) {
+      return NULL;
+    }
+    CPDF_Object* pRes = pList->GetElementValue(name);
+    return pRes;
+  }
+  CPDF_Object* pRes = pList->GetElementValue(name);
+  return pRes;
+}
+CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) {
+  CPDF_Dictionary* pFontDict =
+      (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("Font"), name);
+  if (pFontDict == NULL || pFontDict->GetType() != PDFOBJ_DICTIONARY) {
+    m_bResourceMissing = TRUE;
+    return CPDF_Font::GetStockFont(m_pDocument, FX_BSTRC("Helvetica"));
+  }
+  CPDF_Font* pFont = m_pDocument->LoadFont(pFontDict);
+  if (pFont && pFont->GetType3Font()) {
+    pFont->GetType3Font()->SetPageResources(m_pResources);
+    pFont->GetType3Font()->CheckType3FontMetrics();
+  }
+  return pFont;
+}
+CPDF_ColorSpace* CPDF_StreamContentParser::FindColorSpace(
+    const CFX_ByteString& name) {
+  if (name == FX_BSTRC("Pattern")) {
+    return CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN);
+  }
+  if (name == FX_BSTRC("DeviceGray") || name == FX_BSTRC("DeviceCMYK") ||
+      name == FX_BSTRC("DeviceRGB")) {
+    CFX_ByteString defname = "Default";
+    defname += name.Mid(7);
+    CPDF_Object* pDefObj = FindResourceObj(FX_BSTRC("ColorSpace"), defname);
+    if (pDefObj == NULL) {
+      if (name == FX_BSTRC("DeviceGray")) {
+        return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
+      }
+      if (name == FX_BSTRC("DeviceRGB")) {
+        return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
+      }
+      return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
+    }
+    return m_pDocument->LoadColorSpace(pDefObj);
+  }
+  CPDF_Object* pCSObj = FindResourceObj(FX_BSTRC("ColorSpace"), name);
+  if (pCSObj == NULL) {
+    m_bResourceMissing = TRUE;
+    return NULL;
+  }
+  return m_pDocument->LoadColorSpace(pCSObj);
+}
+CPDF_Pattern* CPDF_StreamContentParser::FindPattern(const CFX_ByteString& name,
+                                                    FX_BOOL bShading) {
+  CPDF_Object* pPattern = FindResourceObj(
+      bShading ? FX_BSTRC("Shading") : FX_BSTRC("Pattern"), name);
+  if (pPattern == NULL || (pPattern->GetType() != PDFOBJ_DICTIONARY &&
+                           pPattern->GetType() != PDFOBJ_STREAM)) {
+    m_bResourceMissing = TRUE;
+    return NULL;
+  }
+  return m_pDocument->LoadPattern(pPattern, bShading,
+                                  &m_pCurStates->m_ParentMatrix);
+}
+void CPDF_StreamContentParser::ConvertTextSpace(FX_FLOAT& x, FX_FLOAT& y) {
+  m_pCurStates->m_TextMatrix.Transform(x, y, x, y);
+  ConvertUserSpace(x, y);
+}
+void CPDF_StreamContentParser::ConvertUserSpace(FX_FLOAT& x, FX_FLOAT& y) {
+  m_pCurStates->m_CTM.Transform(x, y, x, y);
+  m_mtContentToUser.Transform(x, y, x, y);
+}
+void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
+                                             FX_FLOAT fInitKerning,
+                                             FX_FLOAT* pKerning,
+                                             int nsegs) {
+  CPDF_Font* pFont = m_pCurStates->m_TextState.GetFont();
+  if (pFont == NULL) {
+    return;
+  }
+  if (fInitKerning != 0) {
+    if (!pFont->IsVertWriting()) {
+      m_pCurStates->m_TextX -=
+          FXSYS_Mul(fInitKerning, m_pCurStates->m_TextState.GetFontSize()) /
+          1000;
+    } else {
+      m_pCurStates->m_TextY -=
+          FXSYS_Mul(fInitKerning, m_pCurStates->m_TextState.GetFontSize()) /
+          1000;
+    }
+  }
+  if (nsegs == 0) {
+    return;
+  }
+  int textmode;
+  if (pFont->GetFontType() == PDFFONT_TYPE3) {
+    textmode = 0;
+  } else {
+    textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode;
+  }
+  CPDF_TextObject* pText = new CPDF_TextObject;
+  m_pLastTextObject = pText;
+  SetGraphicStates(pText, TRUE, TRUE, TRUE);
+  if (textmode && textmode != 3 && textmode != 4 && textmode != 7) {
+    FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM;
+    pCTM[0] = m_pCurStates->m_CTM.a;
+    pCTM[1] = m_pCurStates->m_CTM.c;
+    pCTM[2] = m_pCurStates->m_CTM.b;
+    pCTM[3] = m_pCurStates->m_CTM.d;
+  }
+  pText->SetSegments(pStrs, pKerning, nsegs);
+  pText->m_PosX = m_pCurStates->m_TextX;
+  pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise;
+  ConvertTextSpace(pText->m_PosX, pText->m_PosY);
+  FX_FLOAT x_advance, y_advance;
+  pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScale,
+                          m_Level);
+  m_pCurStates->m_TextX += x_advance;
+  m_pCurStates->m_TextY += y_advance;
+  if (textmode > 3) {
+    CPDF_TextObject* pCopy = new CPDF_TextObject;
+    pCopy->Copy(pText);
+    m_ClipTextList.Add(pCopy);
+  }
+  m_pObjectList->m_ObjectList.AddTail(pText);
+  if (pKerning && pKerning[nsegs - 1] != 0) {
+    if (!pFont->IsVertWriting()) {
+      m_pCurStates->m_TextX -=
+          FXSYS_Mul(pKerning[nsegs - 1],
+                    m_pCurStates->m_TextState.GetFontSize()) /
+          1000;
+    } else {
+      m_pCurStates->m_TextY -=
+          FXSYS_Mul(pKerning[nsegs - 1],
+                    m_pCurStates->m_TextState.GetFontSize()) /
+          1000;
+    }
+  }
+}
+void CPDF_StreamContentParser::Handle_ShowText() {
+  CFX_ByteString str = GetString(0);
+  if (str.IsEmpty()) {
+    return;
+  }
+  AddTextObject(&str, 0, NULL, 1);
+}
+void CPDF_StreamContentParser::Handle_ShowText_Positioning() {
+  CPDF_Array* pArray = GetObject(0) ? GetObject(0)->GetArray() : NULL;
+  if (pArray == NULL) {
+    return;
+  }
+  int n = pArray->GetCount(), nsegs = 0, i;
+  for (i = 0; i < n; i++) {
+    CPDF_Object* pObj = pArray->GetElementValue(i);
+    if (pObj->GetType() == PDFOBJ_STRING) {
+      nsegs++;
+    }
+  }
+  if (nsegs == 0) {
+    for (i = 0; i < n; i++) {
+      m_pCurStates->m_TextX -=
+          FXSYS_Mul(pArray->GetNumber(i),
+                    m_pCurStates->m_TextState.GetFontSize()) /
+          1000;
+    };
+    return;
+  }
+  CFX_ByteString* pStrs = new CFX_ByteString[nsegs];
+  FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs);
+  int iSegment = 0;
+  FX_FLOAT fInitKerning = 0;
+  for (i = 0; i < n; i++) {
+    CPDF_Object* pObj = pArray->GetElementValue(i);
+    if (pObj->GetType() == PDFOBJ_STRING) {
+      CFX_ByteString str = pObj->GetString();
+      if (str.IsEmpty()) {
+        continue;
+      }
+      pStrs[iSegment] = str;
+      pKerning[iSegment++] = 0;
+    } else {
+      FX_FLOAT num = pObj ? pObj->GetNumber() : 0;
+      if (iSegment == 0) {
+        fInitKerning += num;
+      } else {
+        pKerning[iSegment - 1] += num;
+      }
+    }
+  }
+  AddTextObject(pStrs, fInitKerning, pKerning, iSegment);
+  delete[] pStrs;
+  FX_Free(pKerning);
+}
+void CPDF_StreamContentParser::Handle_SetTextLeading() {
+  m_pCurStates->m_TextLeading = GetNumber(0);
+}
+void CPDF_StreamContentParser::Handle_SetTextMatrix() {
+  m_pCurStates->m_TextMatrix.Set(GetNumber16(5), GetNumber16(4), GetNumber16(3),
+                                 GetNumber16(2), GetNumber(1), GetNumber(0));
+  OnChangeTextMatrix();
+  m_pCurStates->m_TextX = 0;
+  m_pCurStates->m_TextY = 0;
+  m_pCurStates->m_TextLineX = 0;
+  m_pCurStates->m_TextLineY = 0;
+}
+void CPDF_StreamContentParser::OnChangeTextMatrix() {
+  CFX_AffineMatrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f,
+                               0.0f, 0.0f);
+  text_matrix.Concat(m_pCurStates->m_TextMatrix);
+  text_matrix.Concat(m_pCurStates->m_CTM);
+  text_matrix.Concat(m_mtContentToUser);
+  FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetModify()->m_Matrix;
+  pTextMatrix[0] = text_matrix.a;
+  pTextMatrix[1] = text_matrix.c;
+  pTextMatrix[2] = text_matrix.b;
+  pTextMatrix[3] = text_matrix.d;
+}
+void CPDF_StreamContentParser::Handle_SetTextRenderMode() {
+  int mode = GetInteger(0);
+  if (mode < 0 || mode > 7) {
+    return;
+  }
+  m_pCurStates->m_TextState.GetModify()->m_TextMode = mode;
+}
+void CPDF_StreamContentParser::Handle_SetTextRise() {
+  m_pCurStates->m_TextRise = GetNumber(0);
+}
+void CPDF_StreamContentParser::Handle_SetWordSpace() {
+  m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(0);
+}
+void CPDF_StreamContentParser::Handle_SetHorzScale() {
+  if (m_ParamCount != 1) {
+    return;
+  }
+  m_pCurStates->m_TextHorzScale = GetNumber(0) / 100;
+  OnChangeTextMatrix();
+}
+void CPDF_StreamContentParser::Handle_MoveToNextLine() {
+  m_pCurStates->m_TextLineY -= m_pCurStates->m_TextLeading;
+  m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
+  m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
+}
+void CPDF_StreamContentParser::Handle_CurveTo_23() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_BEZIERTO);
+  AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
+  AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
+}
+void CPDF_StreamContentParser::Handle_SetLineWidth() {
+  FX_FLOAT width = GetNumber(0);
+  m_pCurStates->m_GraphState.GetModify()->m_LineWidth = width;
+}
+void CPDF_StreamContentParser::Handle_Clip() {
+  m_PathClipType = FXFILL_WINDING;
+}
+void CPDF_StreamContentParser::Handle_EOClip() {
+  m_PathClipType = FXFILL_ALTERNATE;
+}
+void CPDF_StreamContentParser::Handle_CurveTo_13() {
+  if (m_Options.m_bTextOnly) {
+    return;
+  }
+  AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
+  AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
+  AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
+}
+void CPDF_StreamContentParser::Handle_NextLineShowText() {
+  Handle_MoveToNextLine();
+  Handle_ShowText();
+}
+void CPDF_StreamContentParser::Handle_NextLineShowText_Space() {
+  m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(2);
+  m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(1);
+  Handle_NextLineShowText();
+}
+void CPDF_StreamContentParser::Handle_Invalid() {}
+void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag) {
+  m_PathCurrentX = x;
+  m_PathCurrentY = y;
+  if (flag == FXPT_MOVETO) {
+    m_PathStartX = x;
+    m_PathStartY = y;
+    if (m_PathPointCount &&
+        m_pPathPoints[m_PathPointCount - 1].m_Flag == FXPT_MOVETO) {
+      m_pPathPoints[m_PathPointCount - 1].m_PointX = x;
+      m_pPathPoints[m_PathPointCount - 1].m_PointY = y;
+      return;
+    }
+  } else if (m_PathPointCount == 0) {
+    return;
+  }
+  m_PathPointCount++;
+  if (m_PathPointCount > m_PathAllocSize) {
+    int newsize = m_PathPointCount + 256;
+    FX_PATHPOINT* pNewPoints = FX_Alloc(FX_PATHPOINT, newsize);
+    if (m_PathAllocSize) {
+      FXSYS_memcpy(pNewPoints, m_pPathPoints,
+                   m_PathAllocSize * sizeof(FX_PATHPOINT));
+      FX_Free(m_pPathPoints);
+    }
+    m_pPathPoints = pNewPoints;
+    m_PathAllocSize = newsize;
+  }
+  m_pPathPoints[m_PathPointCount - 1].m_Flag = flag;
+  m_pPathPoints[m_PathPointCount - 1].m_PointX = x;
+  m_pPathPoints[m_PathPointCount - 1].m_PointY = y;
+}
+void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) {
+  int PathPointCount = m_PathPointCount, PathClipType = m_PathClipType;
+  m_PathPointCount = 0;
+  m_PathClipType = 0;
+  if (PathPointCount <= 1) {
+    if (PathPointCount && PathClipType) {
+      CPDF_Path path;
+      path.New()->AppendRect(0, 0, 0, 0);
+      m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE);
+    }
+    return;
+  }
+  if (PathPointCount &&
+      m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) {
+    PathPointCount--;
+  }
+  CPDF_Path Path;
+  CFX_PathData* pPathData = Path.New();
+  pPathData->SetPointCount(PathPointCount);
+  FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints,
+               sizeof(FX_PATHPOINT) * PathPointCount);
+  CFX_AffineMatrix matrix = m_pCurStates->m_CTM;
+  matrix.Concat(m_mtContentToUser);
+  if (bStroke || FillType) {
+    CPDF_PathObject* pPathObj = new CPDF_PathObject;
+    pPathObj->m_bStroke = bStroke;
+    pPathObj->m_FillType = FillType;
+    pPathObj->m_Path = Path;
+    pPathObj->m_Matrix = matrix;
+    SetGraphicStates(pPathObj, TRUE, FALSE, TRUE);
+    pPathObj->CalcBoundingBox();
+    m_pObjectList->m_ObjectList.AddTail(pPathObj);
+  }
+  if (PathClipType) {
+    if (!matrix.IsIdentity()) {
+      Path.Transform(&matrix);
+      matrix.SetIdentity();
+    }
+    m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE);
+  }
+}
+CFX_ByteString _FPDF_ByteStringFromHex(CFX_BinaryBuf& src_buf) {
+  CFX_ByteTextBuf buf;
+  FX_BOOL bFirst = TRUE;
+  int code = 0;
+  const uint8_t* str = src_buf.GetBuffer();
+  FX_DWORD size = src_buf.GetSize();
+  for (FX_DWORD i = 0; i < size; i++) {
+    uint8_t ch = str[i];
+    if (ch >= '0' && ch <= '9') {
+      if (bFirst) {
+        code = (ch - '0') * 16;
+      } else {
+        code += ch - '0';
+        buf.AppendChar((char)code);
+      }
+      bFirst = !bFirst;
+    } else if (ch >= 'A' && ch <= 'F') {
+      if (bFirst) {
+        code = (ch - 'A' + 10) * 16;
+      } else {
+        code += ch - 'A' + 10;
+        buf.AppendChar((char)code);
+      }
+      bFirst = !bFirst;
+    } else if (ch >= 'a' && ch <= 'f') {
+      if (bFirst) {
+        code = (ch - 'a' + 10) * 16;
+      } else {
+        code += ch - 'a' + 10;
+        buf.AppendChar((char)code);
+      }
+      bFirst = !bFirst;
+    }
+  }
+  if (!bFirst) {
+    buf.AppendChar((char)code);
+  }
+  return buf.GetByteString();
+}