| Index: core/fpdfapi/page/cpdf_streamparser.cpp
|
| diff --git a/core/fpdfapi/page/fpdf_page_parser_old.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
|
| similarity index 67%
|
| rename from core/fpdfapi/page/fpdf_page_parser_old.cpp
|
| rename to core/fpdfapi/page/cpdf_streamparser.cpp
|
| index 51ffc11b03405a5c98b3ab39dffd923b6353d64a..9d36d0a38b821320e30f1436d51c6f33ea887fda 100644
|
| --- a/core/fpdfapi/page/fpdf_page_parser_old.cpp
|
| +++ b/core/fpdfapi/page/cpdf_streamparser.cpp
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2014 PDFium Authors. All rights reserved.
|
| +// Copyright 2016 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.
|
|
|
| @@ -9,13 +9,7 @@
|
| #include <limits.h>
|
|
|
| #include "core/fpdfapi/cpdf_modulemgr.h"
|
| -#include "core/fpdfapi/font/cpdf_type3char.h"
|
| -#include "core/fpdfapi/page/cpdf_allstates.h"
|
| #include "core/fpdfapi/page/cpdf_docpagedata.h"
|
| -#include "core/fpdfapi/page/cpdf_form.h"
|
| -#include "core/fpdfapi/page/cpdf_page.h"
|
| -#include "core/fpdfapi/page/cpdf_pageobject.h"
|
| -#include "core/fpdfapi/page/cpdf_path.h"
|
| #include "core/fpdfapi/parser/cpdf_array.h"
|
| #include "core/fpdfapi/parser/cpdf_boolean.h"
|
| #include "core/fpdfapi/parser/cpdf_dictionary.h"
|
| @@ -24,15 +18,11 @@
|
| #include "core/fpdfapi/parser/cpdf_null.h"
|
| #include "core/fpdfapi/parser/cpdf_number.h"
|
| #include "core/fpdfapi/parser/cpdf_stream.h"
|
| -#include "core/fpdfapi/parser/cpdf_stream_acc.h"
|
| #include "core/fpdfapi/parser/cpdf_string.h"
|
| #include "core/fpdfapi/parser/fpdf_parser_decode.h"
|
| #include "core/fpdfapi/parser/fpdf_parser_utility.h"
|
| #include "core/fxcodec/fx_codec.h"
|
| #include "core/fxcrt/fx_ext.h"
|
| -#include "core/fxcrt/fx_safe_types.h"
|
| -#include "core/fxge/cfx_fxgedevice.h"
|
| -#include "core/fxge/cfx_renderdevice.h"
|
|
|
| CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(
|
| const uint8_t* src_buf,
|
| @@ -50,9 +40,8 @@ const FX_STRSIZE kMaxStringLength = 32767;
|
| uint32_t DecodeAllScanlines(CCodec_ScanlineDecoder* pDecoder,
|
| uint8_t*& dest_buf,
|
| uint32_t& dest_size) {
|
| - if (!pDecoder) {
|
| + if (!pDecoder)
|
| return FX_INVALID_OFFSET;
|
| - }
|
| int ncomps = pDecoder->CountComps();
|
| int bpc = pDecoder->GetBPC();
|
| int width = pDecoder->GetWidth();
|
| @@ -89,12 +78,10 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf,
|
| FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam);
|
| return DecodeAllScanlines(pDecoder, dest_buf, dest_size);
|
| }
|
| - if (decoder == "ASCII85Decode" || decoder == "A85") {
|
| + if (decoder == "ASCII85Decode" || decoder == "A85")
|
| return A85Decode(src_buf, limit, dest_buf, dest_size);
|
| - }
|
| - if (decoder == "ASCIIHexDecode" || decoder == "AHx") {
|
| + if (decoder == "ASCIIHexDecode" || decoder == "AHx")
|
| return HexDecode(src_buf, limit, dest_buf, dest_size);
|
| - }
|
| if (decoder == "FlateDecode" || decoder == "Fl") {
|
| return FPDFAPI_FlateOrLZWDecode(false, src_buf, limit, pParam, dest_size,
|
| dest_buf, dest_size);
|
| @@ -110,9 +97,8 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf,
|
| !pParam || pParam->GetIntegerFor("ColorTransform", 1));
|
| return DecodeAllScanlines(pDecoder, dest_buf, dest_size);
|
| }
|
| - if (decoder == "RunLengthDecode" || decoder == "RL") {
|
| + if (decoder == "RunLengthDecode" || decoder == "RL")
|
| return RunLengthDecode(src_buf, limit, dest_buf, dest_size);
|
| - }
|
| dest_size = 0;
|
| dest_buf = 0;
|
| return (uint32_t)-1;
|
| @@ -205,9 +191,8 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc,
|
| uint8_t* pData = nullptr;
|
| uint32_t dwStreamSize;
|
| if (Decoder.IsEmpty()) {
|
| - if (OrigSize > m_Size - m_Pos) {
|
| + if (OrigSize > m_Size - m_Pos)
|
| OrigSize = m_Size - m_Pos;
|
| - }
|
| pData = FX_Alloc(uint8_t, OrigSize);
|
| FXSYS_memcpy(pData, m_pBuf + m_Pos, OrigSize);
|
| dwStreamSize = OrigSize;
|
| @@ -218,7 +203,7 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc,
|
| PDF_DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height,
|
| Decoder, pParam, pData, dwDestSize);
|
| FX_Free(pData);
|
| - if ((int)dwStreamSize < 0)
|
| + if (static_cast<int>(dwStreamSize) < 0)
|
| return nullptr;
|
|
|
| uint32_t dwSavePos = m_Pos;
|
| @@ -424,6 +409,7 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(bool bAllowNestedArray,
|
| return nullptr;
|
| }
|
|
|
| +// TODO(npm): the following methods are almost identical in cpdf_syntaxparser
|
| void CPDF_StreamParser::GetNextWord(bool& bIsNumber) {
|
| m_WordSize = 0;
|
| bIsNumber = true;
|
| @@ -639,204 +625,3 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() {
|
| bool CPDF_StreamParser::PositionIsInBounds() const {
|
| return m_Pos < m_Size;
|
| }
|
| -
|
| -CPDF_ContentParser::CPDF_ContentParser()
|
| - : m_Status(Ready),
|
| - m_InternalStage(STAGE_GETCONTENT),
|
| - m_pObjectHolder(nullptr),
|
| - m_bForm(false),
|
| - m_pType3Char(nullptr),
|
| - m_pData(nullptr),
|
| - m_Size(0),
|
| - m_CurrentOffset(0) {}
|
| -
|
| -CPDF_ContentParser::~CPDF_ContentParser() {
|
| - if (!m_pSingleStream)
|
| - FX_Free(m_pData);
|
| -}
|
| -
|
| -void CPDF_ContentParser::Start(CPDF_Page* pPage) {
|
| - if (m_Status != Ready || !pPage || !pPage->m_pDocument ||
|
| - !pPage->m_pFormDict) {
|
| - m_Status = Done;
|
| - return;
|
| - }
|
| - m_pObjectHolder = pPage;
|
| - m_bForm = false;
|
| - m_Status = ToBeContinued;
|
| - m_InternalStage = STAGE_GETCONTENT;
|
| - m_CurrentOffset = 0;
|
| -
|
| - CPDF_Object* pContent = pPage->m_pFormDict->GetDirectObjectFor("Contents");
|
| - if (!pContent) {
|
| - m_Status = Done;
|
| - return;
|
| - }
|
| - if (CPDF_Stream* pStream = pContent->AsStream()) {
|
| - m_nStreams = 0;
|
| - m_pSingleStream.reset(new CPDF_StreamAcc);
|
| - m_pSingleStream->LoadAllData(pStream, false);
|
| - } else if (CPDF_Array* pArray = pContent->AsArray()) {
|
| - m_nStreams = pArray->GetCount();
|
| - if (m_nStreams)
|
| - m_StreamArray.resize(m_nStreams);
|
| - else
|
| - m_Status = Done;
|
| - } else {
|
| - m_Status = Done;
|
| - }
|
| -}
|
| -
|
| -void CPDF_ContentParser::Start(CPDF_Form* pForm,
|
| - CPDF_AllStates* pGraphicStates,
|
| - const CFX_Matrix* pParentMatrix,
|
| - CPDF_Type3Char* pType3Char,
|
| - int level) {
|
| - m_pType3Char = pType3Char;
|
| - m_pObjectHolder = pForm;
|
| - m_bForm = true;
|
| - CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixFor("Matrix");
|
| - if (pGraphicStates) {
|
| - form_matrix.Concat(pGraphicStates->m_CTM);
|
| - }
|
| - CPDF_Array* pBBox = pForm->m_pFormDict->GetArrayFor("BBox");
|
| - CFX_FloatRect form_bbox;
|
| - CPDF_Path ClipPath;
|
| - if (pBBox) {
|
| - form_bbox = pBBox->GetRect();
|
| - ClipPath.Emplace();
|
| - ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right,
|
| - form_bbox.top);
|
| - ClipPath.Transform(&form_matrix);
|
| - if (pParentMatrix) {
|
| - ClipPath.Transform(pParentMatrix);
|
| - }
|
| - form_bbox.Transform(&form_matrix);
|
| - if (pParentMatrix) {
|
| - form_bbox.Transform(pParentMatrix);
|
| - }
|
| - }
|
| - CPDF_Dictionary* pResources = pForm->m_pFormDict->GetDictFor("Resources");
|
| - m_pParser.reset(new CPDF_StreamContentParser(
|
| - pForm->m_pDocument, pForm->m_pPageResources, pForm->m_pResources,
|
| - pParentMatrix, pForm, pResources, &form_bbox, pGraphicStates, level));
|
| - m_pParser->GetCurStates()->m_CTM = form_matrix;
|
| - m_pParser->GetCurStates()->m_ParentMatrix = form_matrix;
|
| - if (ClipPath) {
|
| - m_pParser->GetCurStates()->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING,
|
| - true);
|
| - }
|
| - if (pForm->m_Transparency & PDFTRANS_GROUP) {
|
| - CPDF_GeneralState* pState = &m_pParser->GetCurStates()->m_GeneralState;
|
| - pState->SetBlendType(FXDIB_BLEND_NORMAL);
|
| - pState->SetStrokeAlpha(1.0f);
|
| - pState->SetFillAlpha(1.0f);
|
| - pState->SetSoftMask(nullptr);
|
| - }
|
| - m_nStreams = 0;
|
| - m_pSingleStream.reset(new CPDF_StreamAcc);
|
| - m_pSingleStream->LoadAllData(pForm->m_pFormStream, false);
|
| - m_pData = (uint8_t*)m_pSingleStream->GetData();
|
| - m_Size = m_pSingleStream->GetSize();
|
| - m_Status = ToBeContinued;
|
| - m_InternalStage = STAGE_PARSE;
|
| - m_CurrentOffset = 0;
|
| -}
|
| -
|
| -void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
|
| - int steps = 0;
|
| - while (m_Status == ToBeContinued) {
|
| - if (m_InternalStage == STAGE_GETCONTENT) {
|
| - if (m_CurrentOffset == m_nStreams) {
|
| - if (!m_StreamArray.empty()) {
|
| - FX_SAFE_UINT32 safeSize = 0;
|
| - for (const auto& stream : m_StreamArray) {
|
| - safeSize += stream->GetSize();
|
| - safeSize += 1;
|
| - }
|
| - if (!safeSize.IsValid()) {
|
| - m_Status = Done;
|
| - return;
|
| - }
|
| - m_Size = safeSize.ValueOrDie();
|
| - m_pData = FX_Alloc(uint8_t, m_Size);
|
| - uint32_t pos = 0;
|
| - for (const auto& stream : m_StreamArray) {
|
| - FXSYS_memcpy(m_pData + pos, stream->GetData(), stream->GetSize());
|
| - pos += stream->GetSize();
|
| - m_pData[pos++] = ' ';
|
| - }
|
| - m_StreamArray.clear();
|
| - } else {
|
| - m_pData = (uint8_t*)m_pSingleStream->GetData();
|
| - m_Size = m_pSingleStream->GetSize();
|
| - }
|
| - m_InternalStage = STAGE_PARSE;
|
| - m_CurrentOffset = 0;
|
| - } else {
|
| - CPDF_Array* pContent =
|
| - m_pObjectHolder->m_pFormDict->GetArrayFor("Contents");
|
| - m_StreamArray[m_CurrentOffset].reset(new CPDF_StreamAcc);
|
| - CPDF_Stream* pStreamObj = ToStream(
|
| - pContent ? pContent->GetDirectObjectAt(m_CurrentOffset) : nullptr);
|
| - m_StreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, false);
|
| - m_CurrentOffset++;
|
| - }
|
| - }
|
| - if (m_InternalStage == STAGE_PARSE) {
|
| - if (!m_pParser) {
|
| - m_pParser.reset(new CPDF_StreamContentParser(
|
| - m_pObjectHolder->m_pDocument, m_pObjectHolder->m_pPageResources,
|
| - nullptr, nullptr, m_pObjectHolder, m_pObjectHolder->m_pResources,
|
| - &m_pObjectHolder->m_BBox, nullptr, 0));
|
| - m_pParser->GetCurStates()->m_ColorState.SetDefault();
|
| - }
|
| - if (m_CurrentOffset >= m_Size) {
|
| - m_InternalStage = STAGE_CHECKCLIP;
|
| - } else {
|
| - m_CurrentOffset +=
|
| - m_pParser->Parse(m_pData + m_CurrentOffset,
|
| - m_Size - m_CurrentOffset, PARSE_STEP_LIMIT);
|
| - }
|
| - }
|
| - if (m_InternalStage == STAGE_CHECKCLIP) {
|
| - if (m_pType3Char) {
|
| - m_pType3Char->m_bColored = m_pParser->IsColored();
|
| - m_pType3Char->m_Width =
|
| - FXSYS_round(m_pParser->GetType3Data()[0] * 1000);
|
| - m_pType3Char->m_BBox.left =
|
| - FXSYS_round(m_pParser->GetType3Data()[2] * 1000);
|
| - m_pType3Char->m_BBox.bottom =
|
| - FXSYS_round(m_pParser->GetType3Data()[3] * 1000);
|
| - m_pType3Char->m_BBox.right =
|
| - FXSYS_round(m_pParser->GetType3Data()[4] * 1000);
|
| - m_pType3Char->m_BBox.top =
|
| - FXSYS_round(m_pParser->GetType3Data()[5] * 1000);
|
| - }
|
| - for (auto& pObj : *m_pObjectHolder->GetPageObjectList()) {
|
| - if (!pObj->m_ClipPath)
|
| - continue;
|
| - if (pObj->m_ClipPath.GetPathCount() != 1)
|
| - continue;
|
| - if (pObj->m_ClipPath.GetTextCount())
|
| - continue;
|
| - CPDF_Path ClipPath = pObj->m_ClipPath.GetPath(0);
|
| - if (!ClipPath.IsRect() || pObj->IsShading())
|
| - continue;
|
| - CFX_FloatRect old_rect(ClipPath.GetPointX(0), ClipPath.GetPointY(0),
|
| - ClipPath.GetPointX(2), ClipPath.GetPointY(2));
|
| - CFX_FloatRect obj_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right,
|
| - pObj->m_Top);
|
| - if (old_rect.Contains(obj_rect)) {
|
| - pObj->m_ClipPath.SetNull();
|
| - }
|
| - }
|
| - m_Status = Done;
|
| - return;
|
| - }
|
| - steps++;
|
| - if (pPause && pPause->NeedToPauseNow()) {
|
| - break;
|
| - }
|
| - }
|
| -}
|
|
|