From 584b1e679f41a580e2b38d5534f126355c78043b Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 21 Mar 2016 09:15:45 -0400 Subject: Move core/include/fpdfapi/fpdf_pageobj.h into core/fpdfapi. This CL splits the file into individual classes and moves them into core/fpdfapi/fpdf_page as needed. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1811053002 . --- BUILD.gn | 45 +- .../fpdf_edit/cpdf_pagecontentgenerator.cpp | 2 + core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 2 + core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp | 4 +- core/fpdfapi/fpdf_edit/include/cpdf_creator.h | 6 +- core/fpdfapi/fpdf_font/fpdf_font.cpp | 1 - core/fpdfapi/fpdf_page/cpdf_allstates.cpp | 185 ++++++ core/fpdfapi/fpdf_page/cpdf_allstates.h | 39 ++ core/fpdfapi/fpdf_page/cpdf_clippath.cpp | 131 ++++ core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp | 77 +++ core/fpdfapi/fpdf_page/cpdf_clippathdata.h | 30 + core/fpdfapi/fpdf_page/cpdf_colorstate.cpp | 70 +++ core/fpdfapi/fpdf_page/cpdf_colorstate.h | 41 ++ core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp | 20 + core/fpdfapi/fpdf_page/cpdf_colorstatedata.h | 26 + core/fpdfapi/fpdf_page/cpdf_contentmark.cpp | 38 ++ core/fpdfapi/fpdf_page/cpdf_contentmark.h | 23 + core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp | 51 ++ core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h | 38 ++ core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp | 36 ++ core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h | 39 ++ core/fpdfapi/fpdf_page/cpdf_form.cpp | 1 + core/fpdfapi/fpdf_page/cpdf_formobject.cpp | 38 ++ core/fpdfapi/fpdf_page/cpdf_generalstate.cpp | 29 + core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp | 95 +++ core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp | 19 + core/fpdfapi/fpdf_page/cpdf_graphicstates.h | 28 + core/fpdfapi/fpdf_page/cpdf_graphstate.h | 14 + core/fpdfapi/fpdf_page/cpdf_imageobject.cpp | 44 ++ core/fpdfapi/fpdf_page/cpdf_page.cpp | 185 ++++++ core/fpdfapi/fpdf_page/cpdf_pageobject.cpp | 43 ++ core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp | 1 + core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp | 1 - core/fpdfapi/fpdf_page/cpdf_pathobject.cpp | 51 ++ core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp | 54 ++ core/fpdfapi/fpdf_page/cpdf_textobject.cpp | 345 ++++++++++ core/fpdfapi/fpdf_page/cpdf_textstate.cpp | 47 ++ core/fpdfapi/fpdf_page/cpdf_textstate.h | 28 + core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp | 43 ++ core/fpdfapi/fpdf_page/fpdf_page.cpp | 636 ------------------- core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp | 694 --------------------- core/fpdfapi/fpdf_page/fpdf_page_image.cpp | 33 - core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 7 + core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 3 + core/fpdfapi/fpdf_page/fpdf_page_path.cpp | 53 -- core/fpdfapi/fpdf_page/include/cpdf_clippath.h | 34 + core/fpdfapi/fpdf_page/include/cpdf_formobject.h | 34 + core/fpdfapi/fpdf_page/include/cpdf_generalstate.h | 29 + .../fpdf_page/include/cpdf_generalstatedata.h | 49 ++ core/fpdfapi/fpdf_page/include/cpdf_imageobject.h | 34 + core/fpdfapi/fpdf_page/include/cpdf_page.h | 3 + core/fpdfapi/fpdf_page/include/cpdf_pageobject.h | 71 +++ core/fpdfapi/fpdf_page/include/cpdf_path.h | 50 ++ core/fpdfapi/fpdf_page/include/cpdf_pathobject.h | 36 ++ .../fpdfapi/fpdf_page/include/cpdf_shadingobject.h | 34 + core/fpdfapi/fpdf_page/include/cpdf_textobject.h | 69 ++ .../fpdfapi/fpdf_page/include/cpdf_textstatedata.h | 31 + core/fpdfapi/fpdf_page/pageint.h | 27 +- core/fpdfapi/fpdf_parser/ipdf_occontext.cpp | 3 +- core/fpdfapi/fpdf_render/fpdf_render.cpp | 7 + core/fpdfapi/fpdf_render/fpdf_render_cache.cpp | 1 - core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 2 +- core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 2 +- core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 5 +- core/fpdfapi/fpdf_render/fpdf_render_text.cpp | 5 +- core/fpdfapi/fpdf_render/render_int.h | 21 +- core/fpdfdoc/doc_annot.cpp | 2 +- core/fpdftext/fpdf_text_int.cpp | 4 +- core/fpdftext/fpdf_text_int.h | 1 + core/fpdftext/include/ipdf_textpage.h | 4 +- core/include/fpdfapi/fpdf_pageobj.h | 464 -------------- fpdfsdk/formfiller/cba_fontmap.cpp | 1 + fpdfsdk/fpdf_flatten.cpp | 1 + fpdfsdk/fpdf_transformpage.cpp | 4 + fpdfsdk/fpdfeditimg.cpp | 3 + fpdfsdk/fpdfeditpage.cpp | 6 + fpdfsdk/fpdfppo.cpp | 1 + fpdfsdk/fpdfsave.cpp | 1 + fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 1 + fpdfsdk/fsdk_baseannot.cpp | 1 + fpdfsdk/fsdk_baseform.cpp | 1 + fpdfsdk/fxedit/fxet_pageobjs.cpp | 5 +- fpdfsdk/include/fsdk_define.h | 1 - fpdfsdk/javascript/Document.h | 3 + pdfium.gyp | 49 +- 85 files changed, 2576 insertions(+), 1920 deletions(-) create mode 100644 core/fpdfapi/fpdf_page/cpdf_allstates.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_allstates.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_clippath.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_clippathdata.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_colorstate.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_colorstate.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_colorstatedata.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_contentmark.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_contentmark.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_formobject.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_generalstate.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_graphicstates.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_graphstate.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_imageobject.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_page.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_pageobject.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_pathobject.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_textobject.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_textstate.cpp create mode 100644 core/fpdfapi/fpdf_page/cpdf_textstate.h create mode 100644 core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp delete mode 100644 core/fpdfapi/fpdf_page/fpdf_page.cpp delete mode 100644 core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp delete mode 100644 core/fpdfapi/fpdf_page/fpdf_page_path.cpp create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_clippath.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_formobject.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_generalstate.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_imageobject.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_pageobject.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_path.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_pathobject.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_textobject.h create mode 100644 core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h delete mode 100644 core/include/fpdfapi/fpdf_pageobj.h diff --git a/BUILD.gn b/BUILD.gn index 85b65c7c3e..904dc6929f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -318,25 +318,63 @@ static_library("fpdfapi") { "core/fpdfapi/fpdf_font/fpdf_font_cid.cpp", "core/fpdfapi/fpdf_font/ttgsubtable.cpp", "core/fpdfapi/fpdf_font/ttgsubtable.h", + "core/fpdfapi/fpdf_page/cpdf_allstates.cpp", + "core/fpdfapi/fpdf_page/cpdf_allstates.h", + "core/fpdfapi/fpdf_page/cpdf_clippath.cpp", + "core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp", + "core/fpdfapi/fpdf_page/cpdf_clippathdata.h", + "core/fpdfapi/fpdf_page/cpdf_colorstate.cpp", + "core/fpdfapi/fpdf_page/cpdf_colorstate.h", + "core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp", + "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h", + "core/fpdfapi/fpdf_page/cpdf_contentmark.cpp", + "core/fpdfapi/fpdf_page/cpdf_contentmark.h", + "core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp", + "core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h", + "core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp", + "core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h", "core/fpdfapi/fpdf_page/cpdf_form.cpp", + "core/fpdfapi/fpdf_page/cpdf_formobject.cpp", + "core/fpdfapi/fpdf_page/cpdf_generalstate.cpp", + "core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp", + "core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp", + "core/fpdfapi/fpdf_page/cpdf_graphicstates.h", + "core/fpdfapi/fpdf_page/cpdf_graphstate.h", + "core/fpdfapi/fpdf_page/cpdf_imageobject.cpp", + "core/fpdfapi/fpdf_page/cpdf_page.cpp", + "core/fpdfapi/fpdf_page/cpdf_pageobject.cpp", "core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp", "core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp", "core/fpdfapi/fpdf_page/cpdf_pageobjectlist.h", "core/fpdfapi/fpdf_page/cpdf_parseoptions.cpp", "core/fpdfapi/fpdf_page/cpdf_parseoptions.h", - "core/fpdfapi/fpdf_page/fpdf_page.cpp", + "core/fpdfapi/fpdf_page/cpdf_pathobject.cpp", + "core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp", + "core/fpdfapi/fpdf_page/cpdf_textobject.cpp", + "core/fpdfapi/fpdf_page/cpdf_textstate.cpp", + "core/fpdfapi/fpdf_page/cpdf_textstate.h", + "core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp", "core/fpdfapi/fpdf_page/fpdf_page_colors.cpp", "core/fpdfapi/fpdf_page/fpdf_page_doc.cpp", "core/fpdfapi/fpdf_page/fpdf_page_func.cpp", - "core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp", "core/fpdfapi/fpdf_page/fpdf_page_image.cpp", "core/fpdfapi/fpdf_page/fpdf_page_parser.cpp", "core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp", - "core/fpdfapi/fpdf_page/fpdf_page_path.cpp", "core/fpdfapi/fpdf_page/fpdf_page_pattern.cpp", + "core/fpdfapi/fpdf_page/include/cpdf_clippath.h", "core/fpdfapi/fpdf_page/include/cpdf_form.h", + "core/fpdfapi/fpdf_page/include/cpdf_formobject.h", + "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h", + "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h", + "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h", "core/fpdfapi/fpdf_page/include/cpdf_page.h", + "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h", "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h", + "core/fpdfapi/fpdf_page/include/cpdf_path.h", + "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h", + "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h", + "core/fpdfapi/fpdf_page/include/cpdf_textobject.h", + "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h", "core/fpdfapi/fpdf_page/pageint.h", "core/fpdfapi/fpdf_parser/cfdf_document.cpp", "core/fpdfapi/fpdf_parser/cpdf_array.cpp", @@ -404,7 +442,6 @@ static_library("fpdfapi") { "core/fpdfapi/include/cpdf_modulemgr.h", "core/fpdfapi/ipdf_pagemodule.h", "core/fpdfapi/ipdf_rendermodule.h", - "core/include/fpdfapi/fpdf_pageobj.h", "core/include/fpdfapi/fpdf_resource.h", ] configs += [ ":pdfium_config" ] diff --git a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp index a09aa1f9b3..20211f27f7 100644 --- a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp @@ -7,7 +7,9 @@ #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h" #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index da3c18fc3f..41bb99defc 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -16,6 +16,8 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" #include "core/fpdfapi/fpdf_parser/ipdf_crypto_handler.h" diff --git a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp index fde9c693e6..42315dad53 100644 --- a/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp +++ b/core/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp @@ -6,6 +6,7 @@ #include +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" @@ -1142,8 +1143,7 @@ void CPDF_Document::DeletePage(int iPage) { } m_PageList.RemoveAt(iPage); } -CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, - const CFX_ByteStringC& name); + void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, const CFX_ByteStringC& name) { if (pPageDict->KeyExist(name)) { diff --git a/core/fpdfapi/fpdf_edit/include/cpdf_creator.h b/core/fpdfapi/fpdf_edit/include/cpdf_creator.h index 7be92f956b..2132457c1c 100644 --- a/core/fpdfapi/fpdf_edit/include/cpdf_creator.h +++ b/core/fpdfapi/fpdf_edit/include/cpdf_creator.h @@ -7,8 +7,12 @@ #ifndef CORE_FPDFAPI_FPDF_EDIT_INCLUDE_CPDF_CREATOR_H_ #define CORE_FPDFAPI_FPDF_EDIT_INCLUDE_CPDF_CREATOR_H_ -#include "core/include/fpdfapi/fpdf_pageobj.h" +#include "core/include/fxcrt/fx_basic.h" +class CPDF_Array; +class CPDF_Dictionary; +class CPDF_Document; +class CPDF_Object; class CPDF_Parser; class CPDF_XRefStream; class IPDF_CryptoHandler; diff --git a/core/fpdfapi/fpdf_font/fpdf_font.cpp b/core/fpdfapi/fpdf_font/fpdf_font.cpp index 5e9b0edfa0..0f58bcba09 100644 --- a/core/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/fpdfapi/fpdf_font/fpdf_font.cpp @@ -15,7 +15,6 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" #include "core/fpdfapi/include/cpdf_modulemgr.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fpdfapi/fpdf_resource.h" #include "core/include/fxcrt/fx_ext.h" #include "core/include/fxge/fx_freetype.h" diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp new file mode 100644 index 0000000000..96ccc77f81 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp @@ -0,0 +1,185 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_allstates.h" + +#include "core/fpdfapi/fpdf_page/pageint.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" + +namespace { + +FX_FLOAT ClipFloat(FX_FLOAT f) { + return std::max(0.0f, std::min(1.0f, f)); +} + +} // namespace + +CPDF_AllStates::CPDF_AllStates() { + m_TextX = m_TextY = m_TextLineX = m_TextLineY = 0; + m_TextLeading = 0; + m_TextRise = 0; + m_TextHorzScale = 1.0f; +} + +CPDF_AllStates::~CPDF_AllStates() {} + +void CPDF_AllStates::Copy(const CPDF_AllStates& src) { + CopyStates(src); + m_TextMatrix.Copy(src.m_TextMatrix); + m_ParentMatrix.Copy(src.m_ParentMatrix); + m_CTM.Copy(src.m_CTM); + m_TextX = src.m_TextX; + m_TextY = src.m_TextY; + m_TextLineX = src.m_TextLineX; + m_TextLineY = src.m_TextLineY; + m_TextLeading = src.m_TextLeading; + m_TextRise = src.m_TextRise; + m_TextHorzScale = src.m_TextHorzScale; +} + +void CPDF_AllStates::SetLineDash(CPDF_Array* pArray, + FX_FLOAT phase, + FX_FLOAT scale) { + CFX_GraphStateData* pData = m_GraphState.GetModify(); + pData->m_DashPhase = phase * scale; + pData->SetDashCount(pArray->GetCount()); + for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { + pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale; + } +} + +void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, + CPDF_StreamContentParser* pParser) { + CPDF_GeneralStateData* pGeneralState = m_GeneralState.GetModify(); + for (const auto& it : *pGS) { + const CFX_ByteString& key_str = it.first; + CPDF_Object* pElement = it.second; + CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr; + if (!pObject) + continue; + + FX_DWORD key = key_str.GetID(); + switch (key) { + case FXBSTR_ID('L', 'W', 0, 0): + m_GraphState.GetModify()->m_LineWidth = pObject->GetNumber(); + break; + case FXBSTR_ID('L', 'C', 0, 0): + m_GraphState.GetModify()->m_LineCap = + (CFX_GraphStateData::LineCap)pObject->GetInteger(); + break; + case FXBSTR_ID('L', 'J', 0, 0): + m_GraphState.GetModify()->m_LineJoin = + (CFX_GraphStateData::LineJoin)pObject->GetInteger(); + break; + case FXBSTR_ID('M', 'L', 0, 0): + m_GraphState.GetModify()->m_MiterLimit = pObject->GetNumber(); + break; + case FXBSTR_ID('D', 0, 0, 0): { + CPDF_Array* pDash = pObject->AsArray(); + if (!pDash) + break; + + CPDF_Array* pArray = pDash->GetArrayAt(0); + if (!pArray) + break; + + SetLineDash(pArray, pDash->GetNumberAt(1), 1.0f); + break; + } + case FXBSTR_ID('R', 'I', 0, 0): + m_GeneralState.SetRenderIntent(pObject->GetString()); + break; + case FXBSTR_ID('F', 'o', 'n', 't'): { + CPDF_Array* pFont = pObject->AsArray(); + if (!pFont) + break; + + m_TextState.GetModify()->m_FontSize = pFont->GetNumberAt(1); + m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0))); + break; + } + case FXBSTR_ID('T', 'R', 0, 0): + if (pGS->KeyExist("TR2")) { + continue; + } + case FXBSTR_ID('T', 'R', '2', 0): + pGeneralState->m_pTR = + (pObject && !pObject->IsName()) ? pObject : nullptr; + break; + case FXBSTR_ID('B', 'M', 0, 0): { + CPDF_Array* pArray = pObject->AsArray(); + CFX_ByteString mode = + pArray ? pArray->GetStringAt(0) : pObject->GetString(); + + pGeneralState->SetBlendMode(mode); + if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) { + pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE); + } + break; + } + case FXBSTR_ID('S', 'M', 'a', 's'): + if (ToDictionary(pObject)) { + pGeneralState->m_pSoftMask = pObject; + FXSYS_memcpy(pGeneralState->m_SMaskMatrix, + &pParser->GetCurStates()->m_CTM, sizeof(CFX_Matrix)); + } else { + pGeneralState->m_pSoftMask = NULL; + } + break; + case FXBSTR_ID('C', 'A', 0, 0): + pGeneralState->m_StrokeAlpha = ClipFloat(pObject->GetNumber()); + break; + case FXBSTR_ID('c', 'a', 0, 0): + pGeneralState->m_FillAlpha = ClipFloat(pObject->GetNumber()); + break; + case FXBSTR_ID('O', 'P', 0, 0): + pGeneralState->m_StrokeOP = pObject->GetInteger(); + if (!pGS->KeyExist("op")) { + pGeneralState->m_FillOP = pObject->GetInteger(); + } + break; + case FXBSTR_ID('o', 'p', 0, 0): + pGeneralState->m_FillOP = pObject->GetInteger(); + break; + case FXBSTR_ID('O', 'P', 'M', 0): + pGeneralState->m_OPMode = pObject->GetInteger(); + break; + case FXBSTR_ID('B', 'G', 0, 0): + if (pGS->KeyExist("BG2")) { + continue; + } + case FXBSTR_ID('B', 'G', '2', 0): + pGeneralState->m_pBG = pObject; + break; + case FXBSTR_ID('U', 'C', 'R', 0): + if (pGS->KeyExist("UCR2")) { + continue; + } + case FXBSTR_ID('U', 'C', 'R', '2'): + pGeneralState->m_pUCR = pObject; + break; + case FXBSTR_ID('H', 'T', 0, 0): + pGeneralState->m_pHT = pObject; + break; + case FXBSTR_ID('F', 'L', 0, 0): + pGeneralState->m_Flatness = pObject->GetNumber(); + break; + case FXBSTR_ID('S', 'M', 0, 0): + pGeneralState->m_Smoothness = pObject->GetNumber(); + break; + case FXBSTR_ID('S', 'A', 0, 0): + pGeneralState->m_StrokeAdjust = pObject->GetInteger(); + break; + case FXBSTR_ID('A', 'I', 'S', 0): + pGeneralState->m_AlphaSource = pObject->GetInteger(); + break; + case FXBSTR_ID('T', 'K', 0, 0): + pGeneralState->m_TextKnockout = pObject->GetInteger(); + break; + } + } + pGeneralState->m_Matrix = m_CTM; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.h b/core/fpdfapi/fpdf_page/cpdf_allstates.h new file mode 100644 index 0000000000..700072f26c --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_allstates.h @@ -0,0 +1,39 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_ALLSTATES_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_ALLSTATES_H_ + +#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Array; +class CPDF_Dictionary; +class CPDF_StreamContentParser; + +class CPDF_AllStates : public CPDF_GraphicStates { + public: + CPDF_AllStates(); + ~CPDF_AllStates(); + + void Copy(const CPDF_AllStates& src); + void ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser); + void SetLineDash(CPDF_Array*, FX_FLOAT, FX_FLOAT scale); + + CFX_Matrix m_TextMatrix; + CFX_Matrix m_CTM; + CFX_Matrix m_ParentMatrix; + FX_FLOAT m_TextX; + FX_FLOAT m_TextY; + FX_FLOAT m_TextLineX; + FX_FLOAT m_TextLineY; + FX_FLOAT m_TextLeading; + FX_FLOAT m_TextRise; + FX_FLOAT m_TextHorzScale; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_ALLSTATES_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp new file mode 100644 index 0000000000..3a3300ae2f --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp @@ -0,0 +1,131 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" + +#define FPDF_CLIPPATH_MAX_TEXTS 1024 + +CFX_FloatRect CPDF_ClipPath::GetClipBox() const { + CFX_FloatRect rect; + FX_BOOL bStarted = FALSE; + int count = GetPathCount(); + if (count) { + rect = GetPath(0).GetBoundingBox(); + for (int i = 1; i < count; i++) { + CFX_FloatRect path_rect = GetPath(i).GetBoundingBox(); + rect.Intersect(path_rect); + } + bStarted = TRUE; + } + count = GetTextCount(); + if (count) { + CFX_FloatRect layer_rect; + FX_BOOL bLayerStarted = FALSE; + for (int i = 0; i < count; i++) { + CPDF_TextObject* pTextObj = GetText(i); + if (!pTextObj) { + if (!bStarted) { + rect = layer_rect; + bStarted = TRUE; + } else { + rect.Intersect(layer_rect); + } + bLayerStarted = FALSE; + } else { + if (!bLayerStarted) { + layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr)); + bLayerStarted = TRUE; + } else { + layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr))); + } + } + } + } + return rect; +} + +void CPDF_ClipPath::AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge) { + CPDF_ClipPathData* pData = GetModify(); + if (pData->m_PathCount && bAutoMerge) { + CPDF_Path old_path = pData->m_pPathList[pData->m_PathCount - 1]; + if (old_path.IsRect()) { + CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0), + old_path.GetPointX(2), old_path.GetPointY(2)); + CFX_FloatRect new_rect = path.GetBoundingBox(); + if (old_rect.Contains(new_rect)) { + pData->m_PathCount--; + pData->m_pPathList[pData->m_PathCount].SetNull(); + } + } + } + if (pData->m_PathCount % 8 == 0) { + CPDF_Path* pNewPath = new CPDF_Path[pData->m_PathCount + 8]; + for (int i = 0; i < pData->m_PathCount; i++) { + pNewPath[i] = pData->m_pPathList[i]; + } + delete[] pData->m_pPathList; + uint8_t* pNewType = FX_Alloc(uint8_t, pData->m_PathCount + 8); + FXSYS_memcpy(pNewType, pData->m_pTypeList, pData->m_PathCount); + FX_Free(pData->m_pTypeList); + pData->m_pPathList = pNewPath; + pData->m_pTypeList = pNewType; + } + pData->m_pPathList[pData->m_PathCount] = path; + pData->m_pTypeList[pData->m_PathCount] = (uint8_t)type; + pData->m_PathCount++; +} + +void CPDF_ClipPath::DeletePath(int index) { + CPDF_ClipPathData* pData = GetModify(); + if (index >= pData->m_PathCount) { + return; + } + pData->m_pPathList[index].SetNull(); + for (int i = index; i < pData->m_PathCount - 1; i++) { + pData->m_pPathList[i] = pData->m_pPathList[i + 1]; + } + pData->m_pPathList[pData->m_PathCount - 1].SetNull(); + FXSYS_memmove(pData->m_pTypeList + index, pData->m_pTypeList + index + 1, + pData->m_PathCount - index - 1); + pData->m_PathCount--; +} + +void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) { + CPDF_ClipPathData* pData = GetModify(); + if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) { + for (int i = 0; i < count; i++) { + delete pTexts[i]; + } + return; + } + CPDF_TextObject** pNewList = + FX_Alloc(CPDF_TextObject*, pData->m_TextCount + count + 1); + if (pData->m_pTextList) { + FXSYS_memcpy(pNewList, pData->m_pTextList, + pData->m_TextCount * sizeof(CPDF_TextObject*)); + FX_Free(pData->m_pTextList); + } + pData->m_pTextList = pNewList; + for (int i = 0; i < count; i++) { + pData->m_pTextList[pData->m_TextCount + i] = pTexts[i]; + } + pData->m_pTextList[pData->m_TextCount + count] = NULL; + pData->m_TextCount += count + 1; +} + +void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) { + CPDF_ClipPathData* pData = GetModify(); + int i; + for (i = 0; i < pData->m_PathCount; i++) { + pData->m_pPathList[i].Transform(&matrix); + } + for (i = 0; i < pData->m_TextCount; i++) + if (pData->m_pTextList[i]) { + pData->m_pTextList[i]->Transform(matrix); + } +} diff --git a/core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp b/core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp new file mode 100644 index 0000000000..e6a5227269 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp @@ -0,0 +1,77 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_clippathdata.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_path.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" + +CPDF_ClipPathData::CPDF_ClipPathData() + : m_PathCount(0), + m_pPathList(nullptr), + m_pTypeList(nullptr), + m_TextCount(0), + m_pTextList(nullptr) {} + +CPDF_ClipPathData::~CPDF_ClipPathData() { + delete[] m_pPathList; + FX_Free(m_pTypeList); + + for (int i = m_TextCount - 1; i > -1; i--) + delete m_pTextList[i]; + FX_Free(m_pTextList); +} + +CPDF_ClipPathData::CPDF_ClipPathData(const CPDF_ClipPathData& src) { + m_pPathList = nullptr; + m_pPathList = nullptr; + m_pTextList = nullptr; + + m_PathCount = src.m_PathCount; + if (m_PathCount) { + int alloc_size = m_PathCount; + if (alloc_size % 8) + alloc_size += 8 - (alloc_size % 8); + + m_pPathList = new CPDF_Path[alloc_size]; + for (int i = 0; i < m_PathCount; i++) + m_pPathList[i] = src.m_pPathList[i]; + + m_pTypeList = FX_Alloc(uint8_t, alloc_size); + FXSYS_memcpy(m_pTypeList, src.m_pTypeList, m_PathCount); + } else { + m_pPathList = nullptr; + m_pTypeList = nullptr; + } + + m_TextCount = src.m_TextCount; + if (m_TextCount) { + m_pTextList = FX_Alloc(CPDF_TextObject*, m_TextCount); + for (int i = 0; i < m_TextCount; i++) { + if (src.m_pTextList[i]) + m_pTextList[i] = src.m_pTextList[i]->Clone(); + else + m_pTextList[i] = nullptr; + } + } else { + m_pTextList = nullptr; + } +} + +void CPDF_ClipPathData::SetCount(int path_count, int text_count) { + ASSERT(m_TextCount == 0 && m_PathCount == 0); + if (path_count) { + m_PathCount = path_count; + int alloc_size = (path_count + 7) / 8 * 8; + m_pPathList = new CPDF_Path[alloc_size]; + m_pTypeList = FX_Alloc(uint8_t, alloc_size); + } + + if (text_count) { + m_TextCount = text_count; + m_pTextList = FX_Alloc(CPDF_TextObject*, text_count); + } +} diff --git a/core/fpdfapi/fpdf_page/cpdf_clippathdata.h b/core/fpdfapi/fpdf_page/cpdf_clippathdata.h new file mode 100644 index 0000000000..05a247f753 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_clippathdata.h @@ -0,0 +1,30 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CLIPPATHDATA_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CLIPPATHDATA_H_ + +#include + +class CPDF_Path; +class CPDF_TextObject; + +class CPDF_ClipPathData { + public: + CPDF_ClipPathData(); + CPDF_ClipPathData(const CPDF_ClipPathData&); + ~CPDF_ClipPathData(); + + void SetCount(int path_count, int text_count); + + int m_PathCount; + CPDF_Path* m_pPathList; + uint8_t* m_pTypeList; + int m_TextCount; + CPDF_TextObject** m_pTextList; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CLIPPATHDATA_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp new file mode 100644 index 0000000000..02999c9d13 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp @@ -0,0 +1,70 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_colorstate.h" + +void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + int nValues) { + CPDF_ColorStateData* pData = GetModify(); + SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues); +} + +void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + int nValues) { + CPDF_ColorStateData* pData = GetModify(); + SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues); +} + +void CPDF_ColorState::SetColor(CPDF_Color& color, + FX_DWORD& rgb, + CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + int nValues) { + if (pCS) { + color.SetColorSpace(pCS); + } else if (color.IsNull()) { + color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); + } + if (color.m_pCS->CountComponents() > nValues) { + return; + } + color.SetValue(pValue); + int R, G, B; + rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1; +} + +void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, + FX_FLOAT* pValue, + int nValues) { + CPDF_ColorStateData* pData = GetModify(); + pData->m_FillColor.SetValue(pPattern, pValue, nValues); + int R, G, B; + FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B); + if (pPattern->m_PatternType == 1 && + ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) { + pData->m_FillRGB = 0x00BFBFBF; + return; + } + pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1; +} + +void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, + FX_FLOAT* pValue, + int nValues) { + CPDF_ColorStateData* pData = GetModify(); + pData->m_StrokeColor.SetValue(pPattern, pValue, nValues); + int R, G, B; + FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B); + if (pPattern->m_PatternType == 1 && + ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) { + pData->m_StrokeRGB = 0x00BFBFBF; + return; + } + pData->m_StrokeRGB = + pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.h b/core/fpdfapi/fpdf_page/cpdf_colorstate.h new file mode 100644 index 0000000000..77a506e1b4 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.h @@ -0,0 +1,41 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_ + +#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" +#include "core/include/fxcrt/fx_basic.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Color; +class CPDF_ColorSpace; +class CPDF_Pattern; + +class CPDF_ColorState : public CFX_CountRef { + public: + CPDF_Color* GetFillColor() const { + return m_pObject ? &m_pObject->m_FillColor : nullptr; + } + + CPDF_Color* GetStrokeColor() const { + return m_pObject ? &m_pObject->m_StrokeColor : nullptr; + } + + void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); + void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); + void SetFillPattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); + void SetStrokePattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); + + private: + void SetColor(CPDF_Color& color, + FX_DWORD& rgb, + CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + int nValues); +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp new file mode 100644 index 0000000000..9dbcdec267 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp @@ -0,0 +1,20 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" + +CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) { + m_FillColor.Copy(&src.m_FillColor); + m_FillRGB = src.m_FillRGB; + m_StrokeColor.Copy(&src.m_StrokeColor); + m_StrokeRGB = src.m_StrokeRGB; +} + +void CPDF_ColorStateData::Default() { + m_FillRGB = m_StrokeRGB = 0; + m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); + m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); +} diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h new file mode 100644 index 0000000000..304410b553 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h @@ -0,0 +1,26 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_ + +#include "core/include/fpdfapi/fpdf_resource.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_ColorStateData { + public: + CPDF_ColorStateData() : m_FillRGB(0), m_StrokeRGB(0) {} + CPDF_ColorStateData(const CPDF_ColorStateData& src); + + void Default(); + + CPDF_Color m_FillColor; + FX_DWORD m_FillRGB; + CPDF_Color m_StrokeColor; + FX_DWORD m_StrokeRGB; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp b/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp new file mode 100644 index 0000000000..6e85d2940f --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp @@ -0,0 +1,38 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h" + +FX_BOOL CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const { + if (!m_pObject) + return FALSE; + + for (int i = 0; i < m_pObject->CountItems(); i++) { + CPDF_ContentMarkItem& item = m_pObject->GetItem(i); + if (item.GetName() == mark) + return TRUE; + } + return FALSE; +} + +FX_BOOL CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark, + CPDF_Dictionary*& pDict) const { + if (!m_pObject) + return FALSE; + + for (int i = 0; i < m_pObject->CountItems(); i++) { + CPDF_ContentMarkItem& item = m_pObject->GetItem(i); + if (item.GetName() == mark) { + pDict = nullptr; + if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict || + item.GetParamType() == CPDF_ContentMarkItem::DirectDict) { + pDict = item.GetParam(); + } + return TRUE; + } + } + return FALSE; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmark.h b/core/fpdfapi/fpdf_page/cpdf_contentmark.h new file mode 100644 index 0000000000..35e4a9664b --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_contentmark.h @@ -0,0 +1,23 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARK_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARK_H_ + +#include "core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h" +#include "core/include/fxcrt/fx_basic.h" + +class CPDF_ContentMark : public CFX_CountRef { + public: + int GetMCID() const { return m_pObject ? m_pObject->GetMCID() : -1; } + + FX_BOOL HasMark(const CFX_ByteStringC& mark) const; + + FX_BOOL LookupMark(const CFX_ByteStringC& mark, + CPDF_Dictionary*& pDict) const; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARK_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp new file mode 100644 index 0000000000..076e8ac521 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp @@ -0,0 +1,51 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" +#include "third_party/base/stl_util.h" + +CPDF_ContentMarkData::CPDF_ContentMarkData(const CPDF_ContentMarkData& src) + : m_Marks(src.m_Marks) {} + +int CPDF_ContentMarkData::CountItems() const { + return pdfium::CollectionSize(m_Marks); +} + +int CPDF_ContentMarkData::GetMCID() const { + for (const auto& mark : m_Marks) { + CPDF_ContentMarkItem::ParamType type = mark.GetParamType(); + if (type == CPDF_ContentMarkItem::PropertiesDict || + type == CPDF_ContentMarkItem::DirectDict) { + CPDF_Dictionary* pDict = mark.GetParam(); + if (pDict->KeyExist("MCID")) + return pDict->GetIntegerBy("MCID"); + } + } + return -1; +} + +void CPDF_ContentMarkData::AddMark(const CFX_ByteString& name, + CPDF_Dictionary* pDict, + FX_BOOL bDirect) { + CPDF_ContentMarkItem item; + item.SetName(name); + if (pDict) { + if (bDirect) { + item.SetParam(CPDF_ContentMarkItem::DirectDict, + ToDictionary(pDict->Clone())); + } else { + item.SetParam(CPDF_ContentMarkItem::PropertiesDict, pDict); + } + } + m_Marks.push_back(item); +} + +void CPDF_ContentMarkData::DeleteLastMark() { + if (!m_Marks.empty()) + m_Marks.pop_back(); +} diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h new file mode 100644 index 0000000000..4cf859fda9 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h @@ -0,0 +1,38 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKDATA_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKDATA_H_ + +#include + +#include "core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Dictionary; + +class CPDF_ContentMarkData { + public: + CPDF_ContentMarkData() {} + CPDF_ContentMarkData(const CPDF_ContentMarkData& src); + + int CountItems() const; + CPDF_ContentMarkItem& GetItem(int index) { return m_Marks[index]; } + const CPDF_ContentMarkItem& GetItem(int index) const { + return m_Marks[index]; + } + + int GetMCID() const; + void AddMark(const CFX_ByteString& name, + CPDF_Dictionary* pDict, + FX_BOOL bDictNeedClone); + void DeleteLastMark(); + + private: + std::vector m_Marks; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKDATA_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp new file mode 100644 index 0000000000..3b7a60c059 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp @@ -0,0 +1,36 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" + +CPDF_ContentMarkItem::CPDF_ContentMarkItem() { + m_ParamType = None; +} + +CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src) { + m_MarkName = src.m_MarkName; + m_ParamType = src.m_ParamType; + if (m_ParamType == DirectDict) { + m_pParam = ToDictionary(src.m_pParam->Clone()); + } else { + m_pParam = src.m_pParam; + } +} + +CPDF_ContentMarkItem::~CPDF_ContentMarkItem() { + if (m_ParamType == DirectDict && m_pParam) + m_pParam->Release(); +} + +FX_BOOL CPDF_ContentMarkItem::HasMCID() const { + if (m_pParam && + (m_ParamType == DirectDict || m_ParamType == PropertiesDict)) { + return m_pParam->KeyExist("MCID"); + } + return FALSE; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h new file mode 100644 index 0000000000..0a9ca1a04b --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h @@ -0,0 +1,39 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKITEM_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKITEM_H_ + +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Dictionary; + +class CPDF_ContentMarkItem { + public: + enum ParamType { None, PropertiesDict, DirectDict }; + + CPDF_ContentMarkItem(); + CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src); + ~CPDF_ContentMarkItem(); + + const CFX_ByteString& GetName() const { return m_MarkName; } + ParamType GetParamType() const { return m_ParamType; } + CPDF_Dictionary* GetParam() const { return m_pParam; } + FX_BOOL HasMCID() const; + void SetName(const CFX_ByteString& name) { m_MarkName = name; } + void SetParam(ParamType type, CPDF_Dictionary* param) { + m_ParamType = type; + m_pParam = param; + } + + private: + CFX_ByteString m_MarkName; + ParamType m_ParamType; + CPDF_Dictionary* m_pParam; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKITEM_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_form.cpp b/core/fpdfapi/fpdf_page/cpdf_form.cpp index a1160397fc..403baa2482 100644 --- a/core/fpdfapi/fpdf_page/cpdf_form.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_form.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" diff --git a/core/fpdfapi/fpdf_page/cpdf_formobject.cpp b/core/fpdfapi/fpdf_page/cpdf_formobject.cpp new file mode 100644 index 0000000000..d85ff7dbb3 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_formobject.cpp @@ -0,0 +1,38 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_form.h" + +CPDF_FormObject::CPDF_FormObject() : m_pForm(nullptr) {} + +CPDF_FormObject::~CPDF_FormObject() { + delete m_pForm; +} + +void CPDF_FormObject::Transform(const CFX_Matrix& matrix) { + m_FormMatrix.Concat(matrix); + CalcBoundingBox(); +} + +CPDF_FormObject* CPDF_FormObject::Clone() const { + CPDF_FormObject* obj = new CPDF_FormObject; + obj->CopyData(this); + + obj->m_pForm = m_pForm->Clone(); + obj->m_FormMatrix = m_FormMatrix; + return obj; +} + +void CPDF_FormObject::CalcBoundingBox() { + CFX_FloatRect form_rect = m_pForm->CalcBoundingBox(); + form_rect.Transform(&m_FormMatrix); + m_Left = form_rect.left; + m_Bottom = form_rect.bottom; + m_Right = form_rect.right; + m_Top = form_rect.top; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp new file mode 100644 index 0000000000..11c4dc7701 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp @@ -0,0 +1,29 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h" + +namespace { + +int RI_StringToId(const CFX_ByteString& ri) { + FX_DWORD id = ri.GetID(); + if (id == FXBSTR_ID('A', 'b', 's', 'o')) + return 1; + + if (id == FXBSTR_ID('S', 'a', 't', 'u')) + return 2; + + if (id == FXBSTR_ID('P', 'e', 'r', 'c')) + return 3; + + return 0; +} + +} // namespace + +void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { + GetModify()->m_RenderIntent = RI_StringToId(ri); +} diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp new file mode 100644 index 0000000000..2e4b5e4dff --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp @@ -0,0 +1,95 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h" + +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_render/render_int.h" + +namespace { + +static int GetBlendTypeInternal(const CFX_ByteStringC& mode) { + switch (mode.GetID()) { + case FXBSTR_ID('N', 'o', 'r', 'm'): + case FXBSTR_ID('C', 'o', 'm', 'p'): + return FXDIB_BLEND_NORMAL; + case FXBSTR_ID('M', 'u', 'l', 't'): + return FXDIB_BLEND_MULTIPLY; + case FXBSTR_ID('S', 'c', 'r', 'e'): + return FXDIB_BLEND_SCREEN; + case FXBSTR_ID('O', 'v', 'e', 'r'): + return FXDIB_BLEND_OVERLAY; + case FXBSTR_ID('D', 'a', 'r', 'k'): + return FXDIB_BLEND_DARKEN; + case FXBSTR_ID('L', 'i', 'g', 'h'): + return FXDIB_BLEND_LIGHTEN; + case FXBSTR_ID('C', 'o', 'l', 'o'): + if (mode.GetLength() == 10) + return FXDIB_BLEND_COLORDODGE; + + if (mode.GetLength() == 9) + return FXDIB_BLEND_COLORBURN; + + return FXDIB_BLEND_COLOR; + case FXBSTR_ID('H', 'a', 'r', 'd'): + return FXDIB_BLEND_HARDLIGHT; + case FXBSTR_ID('S', 'o', 'f', 't'): + return FXDIB_BLEND_SOFTLIGHT; + case FXBSTR_ID('D', 'i', 'f', 'f'): + return FXDIB_BLEND_DIFFERENCE; + case FXBSTR_ID('E', 'x', 'c', 'l'): + return FXDIB_BLEND_EXCLUSION; + case FXBSTR_ID('H', 'u', 'e', 0): + return FXDIB_BLEND_HUE; + case FXBSTR_ID('S', 'a', 't', 'u'): + return FXDIB_BLEND_SATURATION; + case FXBSTR_ID('L', 'u', 'm', 'i'): + return FXDIB_BLEND_LUMINOSITY; + } + return FXDIB_BLEND_NORMAL; +} + +} // namespace + +CPDF_GeneralStateData::CPDF_GeneralStateData() { + FXSYS_memset(this, 0, sizeof(CPDF_GeneralStateData)); + FXSYS_strcpy((FX_CHAR*)m_BlendMode, "Normal"); + m_StrokeAlpha = 1.0f; + m_FillAlpha = 1.0f; + m_Flatness = 1.0f; + m_Matrix.SetIdentity(); +} + +CPDF_GeneralStateData::CPDF_GeneralStateData(const CPDF_GeneralStateData& src) { + FXSYS_memcpy(this, &src, sizeof(CPDF_GeneralStateData)); + if (src.m_pTransferFunc && src.m_pTransferFunc->m_pPDFDoc) { + CPDF_DocRenderData* pDocCache = + src.m_pTransferFunc->m_pPDFDoc->GetRenderData(); + if (!pDocCache) + return; + + m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR); + } +} + +CPDF_GeneralStateData::~CPDF_GeneralStateData() { + if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) { + CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData(); + if (!pDocCache) + return; + + pDocCache->ReleaseTransferFunc(m_pTR); + } +} + +void CPDF_GeneralStateData::SetBlendMode(const CFX_ByteStringC& blend_mode) { + if (blend_mode.GetLength() > 15) { + return; + } + FXSYS_memcpy(m_BlendMode, blend_mode.GetPtr(), blend_mode.GetLength()); + m_BlendMode[blend_mode.GetLength()] = 0; + m_BlendType = GetBlendTypeInternal(blend_mode); +} diff --git a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp new file mode 100644 index 0000000000..9c540941ce --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp @@ -0,0 +1,19 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" + +void CPDF_GraphicStates::DefaultStates() { + m_ColorState.New()->Default(); +} + +void CPDF_GraphicStates::CopyStates(const CPDF_GraphicStates& src) { + m_ClipPath = src.m_ClipPath; + m_GraphState = src.m_GraphState; + m_ColorState = src.m_ColorState; + m_TextState = src.m_TextState; + m_GeneralState = src.m_GeneralState; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_graphicstates.h b/core/fpdfapi/fpdf_page/cpdf_graphicstates.h new file mode 100644 index 0000000000..0add18c910 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_graphicstates.h @@ -0,0 +1,28 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHICSTATES_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHICSTATES_H_ + +#include "core/fpdfapi/fpdf_page/cpdf_colorstate.h" +#include "core/fpdfapi/fpdf_page/cpdf_graphstate.h" +#include "core/fpdfapi/fpdf_page/cpdf_textstate.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h" + +class CPDF_GraphicStates { + public: + void CopyStates(const CPDF_GraphicStates& src); + void DefaultStates(); + + CPDF_ClipPath m_ClipPath; + CPDF_GraphState m_GraphState; + CPDF_ColorState m_ColorState; + CPDF_TextState m_TextState; + CPDF_GeneralState m_GeneralState; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHICSTATES_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_graphstate.h b/core/fpdfapi/fpdf_page/cpdf_graphstate.h new file mode 100644 index 0000000000..d44d32d31c --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_graphstate.h @@ -0,0 +1,14 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHSTATE_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHSTATE_H_ + +#include "core/include/fxge/fx_ge.h" + +class CPDF_GraphState : public CFX_CountRef {}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp b/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp new file mode 100644 index 0000000000..f339935ecb --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp @@ -0,0 +1,44 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" + +#include "core/fpdfapi/fpdf_page/pageint.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" + +CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {} + +CPDF_ImageObject::~CPDF_ImageObject() { + if (!m_pImage) { + return; + } + if (m_pImage->IsInline() || + (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) { + delete m_pImage; + } else { + m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream()); + } +} + +CPDF_ImageObject* CPDF_ImageObject::Clone() const { + CPDF_ImageObject* obj = new CPDF_ImageObject; + obj->CopyData(this); + + obj->m_pImage = m_pImage->Clone(); + obj->m_Matrix = m_Matrix; + return obj; +} + +void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) { + m_Matrix.Concat(matrix); + CalcBoundingBox(); +} + +void CPDF_ImageObject::CalcBoundingBox() { + m_Left = m_Bottom = 0; + m_Right = m_Top = 1.0f; + m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); +} diff --git a/core/fpdfapi/fpdf_page/cpdf_page.cpp b/core/fpdfapi/fpdf_page/cpdf_page.cpp new file mode 100644 index 0000000000..0da5452969 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_page.cpp @@ -0,0 +1,185 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" + +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/pageint.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/fpdfapi/include/cpdf_modulemgr.h" +#include "core/fpdfapi/ipdf_rendermodule.h" + +CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, + const CFX_ByteStringC& name) { + int level = 0; + while (1) { + CPDF_Object* pObj = pPageDict->GetElementValue(name); + if (pObj) { + return pObj; + } + CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent"); + if (!pParent || pParent == pPageDict) { + return NULL; + } + pPageDict = pParent; + level++; + if (level == 1000) { + return NULL; + } + } +} + +CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {} + +CPDF_Page::~CPDF_Page() { + if (m_pPageRender) { + IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule(); + pModule->DestroyPageCache(m_pPageRender); + } +} + +void CPDF_Page::Load(CPDF_Document* pDocument, + CPDF_Dictionary* pPageDict, + FX_BOOL bPageCache) { + m_pDocument = (CPDF_Document*)pDocument; + m_pFormDict = pPageDict; + if (bPageCache) { + m_pPageRender = + CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this); + } + if (!pPageDict) { + m_PageWidth = m_PageHeight = 100 * 1.0f; + m_pPageResources = m_pResources = NULL; + return; + } + CPDF_Object* pageAttr = GetPageAttr("Resources"); + m_pResources = pageAttr ? pageAttr->GetDict() : NULL; + m_pPageResources = m_pResources; + CPDF_Object* pRotate = GetPageAttr("Rotate"); + int rotate = 0; + if (pRotate) { + rotate = pRotate->GetInteger() / 90 % 4; + } + if (rotate < 0) { + rotate += 4; + } + CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); + CFX_FloatRect mediabox; + if (pMediaBox) { + mediabox = pMediaBox->GetRect(); + mediabox.Normalize(); + } + if (mediabox.IsEmpty()) { + mediabox = CFX_FloatRect(0, 0, 612, 792); + } + + CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); + if (pCropBox) { + m_BBox = pCropBox->GetRect(); + m_BBox.Normalize(); + } + if (m_BBox.IsEmpty()) { + m_BBox = mediabox; + } else { + m_BBox.Intersect(mediabox); + } + if (rotate % 2) { + m_PageHeight = m_BBox.right - m_BBox.left; + m_PageWidth = m_BBox.top - m_BBox.bottom; + } else { + m_PageWidth = m_BBox.right - m_BBox.left; + m_PageHeight = m_BBox.top - m_BBox.bottom; + } + switch (rotate) { + case 0: + m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom); + break; + case 1: + m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right); + break; + case 2: + m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top); + break; + case 3: + m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left); + break; + } + m_Transparency = PDFTRANS_ISOLATED; + LoadTransInfo(); +} + +void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) { + if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { + return; + } + m_pParser.reset(new CPDF_ContentParser); + m_pParser->Start(this, pOptions); + m_ParseState = CONTENT_PARSING; +} + +void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) { + StartParse(pOptions); + ContinueParse(nullptr); +} + +CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const { + return FPDFAPI_GetPageAttr(m_pFormDict, name); +} + +void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, + int xPos, + int yPos, + int xSize, + int ySize, + int iRotate) const { + if (m_PageWidth == 0 || m_PageHeight == 0) { + return; + } + CFX_Matrix display_matrix; + int x0, y0, x1, y1, x2, y2; + iRotate %= 4; + switch (iRotate) { + case 0: + x0 = xPos; + y0 = yPos + ySize; + x1 = xPos; + y1 = yPos; + x2 = xPos + xSize; + y2 = yPos + ySize; + break; + case 1: + x0 = xPos; + y0 = yPos; + x1 = xPos + xSize; + y1 = yPos; + x2 = xPos; + y2 = yPos + ySize; + break; + case 2: + x0 = xPos + xSize; + y0 = yPos; + x1 = xPos + xSize; + y1 = yPos + ySize; + x2 = xPos; + y2 = yPos; + break; + case 3: + x0 = xPos + xSize; + y0 = yPos + ySize; + x1 = xPos; + y1 = yPos + ySize; + x2 = xPos + xSize; + y2 = yPos; + break; + } + display_matrix.Set( + ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth, + ((FX_FLOAT)(x1 - x0)) / m_PageHeight, + ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0); + matrix = m_PageMatrix; + matrix.Concat(display_matrix); +} diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp new file mode 100644 index 0000000000..ee6615e2e7 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp @@ -0,0 +1,43 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" + +CPDF_PageObject::CPDF_PageObject() {} + +CPDF_PageObject::~CPDF_PageObject() {} + +void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) { + CopyStates(*pSrc); + m_Left = pSrc->m_Left; + m_Right = pSrc->m_Right; + m_Top = pSrc->m_Top; + m_Bottom = pSrc->m_Bottom; +} + +void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) { + if (m_ClipPath.IsNull()) { + return; + } + m_ClipPath.GetModify(); + m_ClipPath.Transform(matrix); +} + +void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) { + if (m_GeneralState.IsNull()) { + return; + } + CPDF_GeneralStateData* pGS = m_GeneralState.GetModify(); + pGS->m_Matrix.Concat(matrix); +} + +FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { + CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top); + if (pMatrix) { + pMatrix->TransformRect(rect); + } + return rect.GetOutterRect(); +} diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp index a1392f647e..fa6347e5bc 100644 --- a/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fpdfapi/fpdf_page/pageint.h" CPDF_PageObjectHolder::CPDF_PageObjectHolder() diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp index 36fb672849..e433431551 100644 --- a/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp @@ -7,7 +7,6 @@ #include "core/fpdfapi/fpdf_page/cpdf_pageobjectlist.h" #include "core/fpdfapi/fpdf_page/pageint.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "third_party/base/stl_util.h" CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) { diff --git a/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp b/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp new file mode 100644 index 0000000000..cfe7b48c8b --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp @@ -0,0 +1,51 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" + +CPDF_PathObject::CPDF_PathObject() {} + +CPDF_PathObject::~CPDF_PathObject() {} + +CPDF_PathObject* CPDF_PathObject::Clone() const { + CPDF_PathObject* obj = new CPDF_PathObject; + obj->CopyData(this); + + obj->m_Path = m_Path; + obj->m_FillType = m_FillType; + obj->m_bStroke = m_bStroke; + obj->m_Matrix = m_Matrix; + return obj; +} + +void CPDF_PathObject::Transform(const CFX_Matrix& matrix) { + m_Matrix.Concat(matrix); + CalcBoundingBox(); +} + +void CPDF_PathObject::CalcBoundingBox() { + if (m_Path.IsNull()) { + return; + } + CFX_FloatRect rect; + FX_FLOAT width = m_GraphState.GetObject()->m_LineWidth; + if (m_bStroke && width != 0) { + rect = m_Path.GetBoundingBox(width, m_GraphState.GetObject()->m_MiterLimit); + } else { + rect = m_Path.GetBoundingBox(); + } + rect.Transform(&m_Matrix); + if (width == 0 && m_bStroke) { + rect.left += -0.5f; + rect.right += 0.5f; + rect.bottom += -0.5f; + rect.top += 0.5f; + } + m_Left = rect.left; + m_Right = rect.right; + m_Top = rect.top; + m_Bottom = rect.bottom; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp new file mode 100644 index 0000000000..16287fe692 --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp @@ -0,0 +1,54 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h" + +#include "core/fpdfapi/fpdf_page/pageint.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" + +CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {} + +CPDF_ShadingObject::~CPDF_ShadingObject() {} + +CPDF_ShadingObject* CPDF_ShadingObject::Clone() const { + CPDF_ShadingObject* obj = new CPDF_ShadingObject; + obj->CopyData(this); + + obj->m_pShading = m_pShading; + if (obj->m_pShading && obj->m_pShading->m_pDocument) { + CPDF_DocPageData* pDocPageData = + obj->m_pShading->m_pDocument->GetPageData(); + obj->m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern( + obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj, + &obj->m_pShading->m_ParentMatrix); + } + obj->m_Matrix = m_Matrix; + return obj; +} + +void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) { + if (!m_ClipPath.IsNull()) { + m_ClipPath.GetModify(); + m_ClipPath.Transform(matrix); + } + m_Matrix.Concat(matrix); + if (!m_ClipPath.IsNull()) { + CalcBoundingBox(); + } else { + matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); + } +} + +void CPDF_ShadingObject::CalcBoundingBox() { + if (m_ClipPath.IsNull()) { + return; + } + CFX_FloatRect rect = m_ClipPath.GetClipBox(); + m_Left = rect.left; + m_Bottom = rect.bottom; + m_Right = rect.right; + m_Top = rect.top; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_textobject.cpp b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp new file mode 100644 index 0000000000..b4161f320e --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp @@ -0,0 +1,345 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" + +CPDF_TextObject::CPDF_TextObject() + : m_PosX(0), + m_PosY(0), + m_nChars(0), + m_pCharCodes(nullptr), + m_pCharPos(nullptr) {} + +CPDF_TextObject::~CPDF_TextObject() { + if (m_nChars > 1) { + FX_Free(m_pCharCodes); + } + FX_Free(m_pCharPos); +} + +void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { + pInfo->m_CharCode = + m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; + pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; + pInfo->m_OriginY = 0; + if (pInfo->m_CharCode == -1) { + return; + } + CPDF_Font* pFont = m_TextState.GetFont(); + if (!pFont->IsCIDFont()) { + return; + } + if (!pFont->AsCIDFont()->IsVertWriting()) { + return; + } + FX_WORD CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); + pInfo->m_OriginY = pInfo->m_OriginX; + pInfo->m_OriginX = 0; + short vx, vy; + pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); + FX_FLOAT fontsize = m_TextState.GetFontSize(); + pInfo->m_OriginX -= fontsize * vx / 1000; + pInfo->m_OriginY -= fontsize * vy / 1000; +} + +int CPDF_TextObject::CountChars() const { + if (m_nChars == 1) { + return 1; + } + int count = 0; + for (int i = 0; i < m_nChars; ++i) + if (m_pCharCodes[i] != (FX_DWORD)-1) { + ++count; + } + return count; +} + +void CPDF_TextObject::GetCharInfo(int index, + FX_DWORD& charcode, + FX_FLOAT& kerning) const { + if (m_nChars == 1) { + charcode = (FX_DWORD)(uintptr_t)m_pCharCodes; + kerning = 0; + return; + } + int count = 0; + for (int i = 0; i < m_nChars; ++i) { + if (m_pCharCodes[i] != (FX_DWORD)-1) { + if (count == index) { + charcode = m_pCharCodes[i]; + if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (FX_DWORD)-1) { + kerning = 0; + } else { + kerning = m_pCharPos[i]; + } + return; + } + ++count; + } + } +} + +void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const { + if (m_nChars == 1) { + GetItemInfo(0, pInfo); + return; + } + int count = 0; + for (int i = 0; i < m_nChars; ++i) { + FX_DWORD charcode = m_pCharCodes[i]; + if (charcode == (FX_DWORD)-1) { + continue; + } + if (count == index) { + GetItemInfo(i, pInfo); + break; + } + ++count; + } +} + +CPDF_TextObject* CPDF_TextObject::Clone() const { + CPDF_TextObject* obj = new CPDF_TextObject; + obj->CopyData(this); + + obj->m_nChars = m_nChars; + if (m_nChars > 1) { + obj->m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); + FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(FX_DWORD)); + obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); + FXSYS_memcpy(obj->m_pCharPos, m_pCharPos, + (m_nChars - 1) * sizeof(FX_FLOAT)); + } else { + obj->m_pCharCodes = m_pCharCodes; + } + obj->m_PosX = m_PosX; + obj->m_PosY = m_PosY; + return obj; +} + +void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const { + FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); + pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], + m_PosX, m_PosY); +} + +void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, + FX_FLOAT* pKerning, + int nsegs) { + if (m_nChars > 1) { + FX_Free(m_pCharCodes); + m_pCharCodes = nullptr; + } + FX_Free(m_pCharPos); + m_pCharPos = nullptr; + CPDF_Font* pFont = m_TextState.GetFont(); + m_nChars = 0; + for (int i = 0; i < nsegs; ++i) { + m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength()); + } + m_nChars += nsegs - 1; + if (m_nChars > 1) { + m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); + m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); + int index = 0; + for (int i = 0; i < nsegs; ++i) { + const FX_CHAR* segment = pStrs[i]; + int offset = 0, len = pStrs[i].GetLength(); + while (offset < len) { + m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset); + } + if (i != nsegs - 1) { + m_pCharPos[index - 1] = pKerning[i]; + m_pCharCodes[index++] = (FX_DWORD)-1; + } + } + } else { + int offset = 0; + m_pCharCodes = (FX_DWORD*)(uintptr_t)pFont->GetNextChar( + pStrs[0], pStrs[0].GetLength(), offset); + } +} + +void CPDF_TextObject::SetText(const CFX_ByteString& str) { + SetSegments(&str, nullptr, 1); + RecalcPositionData(); +} + +FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const { + FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; + CPDF_Font* pFont = m_TextState.GetFont(); + FX_BOOL bVertWriting = FALSE; + CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); + if (pCIDFont) { + bVertWriting = pCIDFont->IsVertWriting(); + } + if (!bVertWriting) + return pFont->GetCharWidthF(charcode, 0) * fontsize; + + FX_WORD CID = pCIDFont->CIDFromCharCode(charcode); + return pCIDFont->GetVertWidth(CID) * fontsize; +} + +void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, + FX_FLOAT* pTextAdvanceY, + FX_FLOAT horz_scale, + int level) { + FX_FLOAT curpos = 0; + FX_FLOAT min_x = 10000 * 1.0f; + FX_FLOAT max_x = -10000 * 1.0f; + FX_FLOAT min_y = 10000 * 1.0f; + FX_FLOAT max_y = -10000 * 1.0f; + CPDF_Font* pFont = m_TextState.GetFont(); + FX_BOOL bVertWriting = FALSE; + CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); + if (pCIDFont) { + bVertWriting = pCIDFont->IsVertWriting(); + } + FX_FLOAT fontsize = m_TextState.GetFontSize(); + for (int i = 0; i < m_nChars; ++i) { + FX_DWORD charcode = + m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; + if (i > 0) { + if (charcode == (FX_DWORD)-1) { + curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; + continue; + } + m_pCharPos[i - 1] = curpos; + } + FX_RECT char_rect = pFont->GetCharBBox(charcode, level); + FX_FLOAT charwidth; + if (!bVertWriting) { + if (min_y > char_rect.top) { + min_y = (FX_FLOAT)char_rect.top; + } + if (max_y < char_rect.top) { + max_y = (FX_FLOAT)char_rect.top; + } + if (min_y > char_rect.bottom) { + min_y = (FX_FLOAT)char_rect.bottom; + } + if (max_y < char_rect.bottom) { + max_y = (FX_FLOAT)char_rect.bottom; + } + FX_FLOAT char_left = curpos + char_rect.left * fontsize / 1000; + FX_FLOAT char_right = curpos + char_rect.right * fontsize / 1000; + if (min_x > char_left) { + min_x = char_left; + } + if (max_x < char_left) { + max_x = char_left; + } + if (min_x > char_right) { + min_x = char_right; + } + if (max_x < char_right) { + max_x = char_right; + } + charwidth = pFont->GetCharWidthF(charcode, level) * fontsize / 1000; + } else { + FX_WORD CID = pCIDFont->CIDFromCharCode(charcode); + short vx; + short vy; + pCIDFont->GetVertOrigin(CID, vx, vy); + char_rect.left -= vx; + char_rect.right -= vx; + char_rect.top -= vy; + char_rect.bottom -= vy; + if (min_x > char_rect.left) { + min_x = (FX_FLOAT)char_rect.left; + } + if (max_x < char_rect.left) { + max_x = (FX_FLOAT)char_rect.left; + } + if (min_x > char_rect.right) { + min_x = (FX_FLOAT)char_rect.right; + } + if (max_x < char_rect.right) { + max_x = (FX_FLOAT)char_rect.right; + } + FX_FLOAT char_top = curpos + char_rect.top * fontsize / 1000; + FX_FLOAT char_bottom = curpos + char_rect.bottom * fontsize / 1000; + if (min_y > char_top) { + min_y = char_top; + } + if (max_y < char_top) { + max_y = char_top; + } + if (min_y > char_bottom) { + min_y = char_bottom; + } + if (max_y < char_bottom) { + max_y = char_bottom; + } + charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000; + } + curpos += charwidth; + if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(32) == 1)) { + curpos += m_TextState.GetObject()->m_WordSpace; + } + curpos += m_TextState.GetObject()->m_CharSpace; + } + if (bVertWriting) { + if (pTextAdvanceX) { + *pTextAdvanceX = 0; + } + if (pTextAdvanceY) { + *pTextAdvanceY = curpos; + } + min_x = min_x * fontsize / 1000; + max_x = max_x * fontsize / 1000; + } else { + if (pTextAdvanceX) { + *pTextAdvanceX = curpos * horz_scale; + } + if (pTextAdvanceY) { + *pTextAdvanceY = 0; + } + min_y = min_y * fontsize / 1000; + max_y = max_y * fontsize / 1000; + } + CFX_Matrix matrix; + GetTextMatrix(&matrix); + m_Left = min_x; + m_Right = max_x; + m_Bottom = min_y; + m_Top = max_y; + matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); + int textmode = m_TextState.GetObject()->m_TextMode; + if (textmode == 1 || textmode == 2 || textmode == 5 || textmode == 6) { + FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2; + m_Left -= half_width; + m_Right += half_width; + m_Top += half_width; + m_Bottom -= half_width; + } +} + +void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { + m_TextState.GetModify(); + CFX_Matrix text_matrix; + GetTextMatrix(&text_matrix); + text_matrix.Concat(matrix); + FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); + pTextMatrix[0] = text_matrix.GetA(); + pTextMatrix[1] = text_matrix.GetC(); + pTextMatrix[2] = text_matrix.GetB(); + pTextMatrix[3] = text_matrix.GetD(); + m_PosX = text_matrix.GetE(); + m_PosY = text_matrix.GetF(); + CalcPositionData(nullptr, nullptr, 0); +} + +void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) { + FX_FLOAT dx = x - m_PosX; + FX_FLOAT dy = y - m_PosY; + m_PosX = x; + m_PosY = y; + m_Left += dx; + m_Right += dx; + m_Top += dy; + m_Bottom += dy; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.cpp b/core/fpdfapi/fpdf_page/cpdf_textstate.cpp new file mode 100644 index 0000000000..f56d58ed0a --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_textstate.cpp @@ -0,0 +1,47 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/cpdf_textstate.h" +#include "core/fpdfapi/fpdf_page/pageint.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" + +void CPDF_TextState::SetFont(CPDF_Font* pFont) { + CPDF_TextStateData* pStateData = GetModify(); + if (pStateData) { + CPDF_Document* pDoc = pStateData->m_pDocument; + CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : NULL; + if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) { + pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict()); + } + pStateData->m_pDocument = pFont ? pFont->m_pDocument : NULL; + pStateData->m_pFont = pFont; + } +} + +FX_FLOAT CPDF_TextState::GetFontSizeV() const { + FX_FLOAT* pMatrix = GetMatrix(); + FX_FLOAT unit = FXSYS_sqrt2(pMatrix[1], pMatrix[3]); + FX_FLOAT size = unit * GetFontSize(); + return (FX_FLOAT)FXSYS_fabs(size); +} + +FX_FLOAT CPDF_TextState::GetFontSizeH() const { + FX_FLOAT* pMatrix = GetMatrix(); + FX_FLOAT unit = FXSYS_sqrt2(pMatrix[0], pMatrix[2]); + FX_FLOAT size = unit * GetFontSize(); + return (FX_FLOAT)FXSYS_fabs(size); +} + +FX_FLOAT CPDF_TextState::GetBaselineAngle() const { + FX_FLOAT* m_Matrix = GetMatrix(); + return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); +} + +FX_FLOAT CPDF_TextState::GetShearAngle() const { + FX_FLOAT* m_Matrix = GetMatrix(); + FX_FLOAT shear_angle = FXSYS_atan2(m_Matrix[1], m_Matrix[3]); + return GetBaselineAngle() + shear_angle; +} diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.h b/core/fpdfapi/fpdf_page/cpdf_textstate.h new file mode 100644 index 0000000000..8530322aeb --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_textstate.h @@ -0,0 +1,28 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_ +#define CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_ + +#include "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h" +#include "core/include/fxcrt/fx_basic.h" + +class CPDF_Font; + +class CPDF_TextState : public CFX_CountRef { + public: + CPDF_Font* GetFont() const { return m_pObject->m_pFont; } + void SetFont(CPDF_Font* pFont); + + FX_FLOAT GetFontSize() const { return m_pObject->m_FontSize; } + FX_FLOAT* GetMatrix() const { return m_pObject->m_Matrix; } + FX_FLOAT GetFontSizeV() const; + FX_FLOAT GetFontSizeH() const; + FX_FLOAT GetBaselineAngle() const; + FX_FLOAT GetShearAngle() const; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp new file mode 100644 index 0000000000..af65fb530a --- /dev/null +++ b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp @@ -0,0 +1,43 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h" + +#include "core/fpdfapi/fpdf_page/pageint.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/include/fpdfapi/fpdf_resource.h" + +CPDF_TextStateData::CPDF_TextStateData() + : m_pFont(nullptr), + m_pDocument(nullptr), + m_FontSize(1.0f), + m_CharSpace(0), + m_WordSpace(0), + m_TextMode(0) { + m_Matrix[0] = m_Matrix[3] = 1.0f; + m_Matrix[1] = m_Matrix[2] = 0; + m_CTM[0] = m_CTM[3] = 1.0f; + m_CTM[1] = m_CTM[2] = 0; +} + +CPDF_TextStateData::CPDF_TextStateData(const CPDF_TextStateData& src) { + if (this == &src) + return; + + FXSYS_memcpy(this, &src, sizeof(CPDF_TextStateData)); + if (m_pDocument && m_pFont) { + m_pFont = + m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE); + } +} + +CPDF_TextStateData::~CPDF_TextStateData() { + if (m_pDocument && m_pFont) { + CPDF_DocPageData* pPageData = m_pDocument->GetPageData(); + if (pPageData && !pPageData->IsForceClear()) + pPageData->ReleaseFont(m_pFont->GetFontDict()); + } +} diff --git a/core/fpdfapi/fpdf_page/fpdf_page.cpp b/core/fpdfapi/fpdf_page/fpdf_page.cpp deleted file mode 100644 index ad54e320bc..0000000000 --- a/core/fpdfapi/fpdf_page/fpdf_page.cpp +++ /dev/null @@ -1,636 +0,0 @@ -// 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 "core/fpdfapi/fpdf_page/pageint.h" - -#include - -#include "core/fpdfapi/fpdf_page/include/cpdf_form.h" -#include "core/fpdfapi/fpdf_page/include/cpdf_page.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfapi/include/cpdf_modulemgr.h" -#include "core/fpdfapi/ipdf_rendermodule.h" -#include "third_party/base/stl_util.h" - -CPDF_PageObject::CPDF_PageObject() {} - -CPDF_PageObject::~CPDF_PageObject() {} - -void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) { - CopyStates(*pSrc); - m_Left = pSrc->m_Left; - m_Right = pSrc->m_Right; - m_Top = pSrc->m_Top; - m_Bottom = pSrc->m_Bottom; -} - -void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) { - if (m_ClipPath.IsNull()) { - return; - } - m_ClipPath.GetModify(); - m_ClipPath.Transform(matrix); -} - -void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) { - if (m_GeneralState.IsNull()) { - return; - } - CPDF_GeneralStateData* pGS = m_GeneralState.GetModify(); - pGS->m_Matrix.Concat(matrix); -} - -FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { - CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top); - if (pMatrix) { - pMatrix->TransformRect(rect); - } - return rect.GetOutterRect(); -} - -CPDF_TextObject::CPDF_TextObject() - : m_PosX(0), - m_PosY(0), - m_nChars(0), - m_pCharCodes(nullptr), - m_pCharPos(nullptr) {} - -CPDF_TextObject::~CPDF_TextObject() { - if (m_nChars > 1) { - FX_Free(m_pCharCodes); - } - FX_Free(m_pCharPos); -} - -void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { - pInfo->m_CharCode = - m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; - pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; - pInfo->m_OriginY = 0; - if (pInfo->m_CharCode == -1) { - return; - } - CPDF_Font* pFont = m_TextState.GetFont(); - if (!pFont->IsCIDFont()) { - return; - } - if (!pFont->AsCIDFont()->IsVertWriting()) { - return; - } - FX_WORD CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); - pInfo->m_OriginY = pInfo->m_OriginX; - pInfo->m_OriginX = 0; - short vx, vy; - pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); - FX_FLOAT fontsize = m_TextState.GetFontSize(); - pInfo->m_OriginX -= fontsize * vx / 1000; - pInfo->m_OriginY -= fontsize * vy / 1000; -} - -int CPDF_TextObject::CountChars() const { - if (m_nChars == 1) { - return 1; - } - int count = 0; - for (int i = 0; i < m_nChars; ++i) - if (m_pCharCodes[i] != (FX_DWORD)-1) { - ++count; - } - return count; -} - -void CPDF_TextObject::GetCharInfo(int index, - FX_DWORD& charcode, - FX_FLOAT& kerning) const { - if (m_nChars == 1) { - charcode = (FX_DWORD)(uintptr_t)m_pCharCodes; - kerning = 0; - return; - } - int count = 0; - for (int i = 0; i < m_nChars; ++i) { - if (m_pCharCodes[i] != (FX_DWORD)-1) { - if (count == index) { - charcode = m_pCharCodes[i]; - if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (FX_DWORD)-1) { - kerning = 0; - } else { - kerning = m_pCharPos[i]; - } - return; - } - ++count; - } - } -} - -void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const { - if (m_nChars == 1) { - GetItemInfo(0, pInfo); - return; - } - int count = 0; - for (int i = 0; i < m_nChars; ++i) { - FX_DWORD charcode = m_pCharCodes[i]; - if (charcode == (FX_DWORD)-1) { - continue; - } - if (count == index) { - GetItemInfo(i, pInfo); - break; - } - ++count; - } -} - -CPDF_TextObject* CPDF_TextObject::Clone() const { - CPDF_TextObject* obj = new CPDF_TextObject; - obj->CopyData(this); - - obj->m_nChars = m_nChars; - if (m_nChars > 1) { - obj->m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); - FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(FX_DWORD)); - obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); - FXSYS_memcpy(obj->m_pCharPos, m_pCharPos, - (m_nChars - 1) * sizeof(FX_FLOAT)); - } else { - obj->m_pCharCodes = m_pCharCodes; - } - obj->m_PosX = m_PosX; - obj->m_PosY = m_PosY; - return obj; -} - -void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const { - FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); - pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], - m_PosX, m_PosY); -} - -void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, - FX_FLOAT* pKerning, - int nsegs) { - if (m_nChars > 1) { - FX_Free(m_pCharCodes); - m_pCharCodes = nullptr; - } - FX_Free(m_pCharPos); - m_pCharPos = nullptr; - CPDF_Font* pFont = m_TextState.GetFont(); - m_nChars = 0; - for (int i = 0; i < nsegs; ++i) { - m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength()); - } - m_nChars += nsegs - 1; - if (m_nChars > 1) { - m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); - m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); - int index = 0; - for (int i = 0; i < nsegs; ++i) { - const FX_CHAR* segment = pStrs[i]; - int offset = 0, len = pStrs[i].GetLength(); - while (offset < len) { - m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset); - } - if (i != nsegs - 1) { - m_pCharPos[index - 1] = pKerning[i]; - m_pCharCodes[index++] = (FX_DWORD)-1; - } - } - } else { - int offset = 0; - m_pCharCodes = (FX_DWORD*)(uintptr_t)pFont->GetNextChar( - pStrs[0], pStrs[0].GetLength(), offset); - } -} - -void CPDF_TextObject::SetText(const CFX_ByteString& str) { - SetSegments(&str, nullptr, 1); - RecalcPositionData(); -} - -FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const { - FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; - CPDF_Font* pFont = m_TextState.GetFont(); - FX_BOOL bVertWriting = FALSE; - CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); - if (pCIDFont) { - bVertWriting = pCIDFont->IsVertWriting(); - } - if (!bVertWriting) - return pFont->GetCharWidthF(charcode, 0) * fontsize; - - FX_WORD CID = pCIDFont->CIDFromCharCode(charcode); - return pCIDFont->GetVertWidth(CID) * fontsize; -} - -void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, - FX_FLOAT* pTextAdvanceY, - FX_FLOAT horz_scale, - int level) { - FX_FLOAT curpos = 0; - FX_FLOAT min_x = 10000 * 1.0f; - FX_FLOAT max_x = -10000 * 1.0f; - FX_FLOAT min_y = 10000 * 1.0f; - FX_FLOAT max_y = -10000 * 1.0f; - CPDF_Font* pFont = m_TextState.GetFont(); - FX_BOOL bVertWriting = FALSE; - CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); - if (pCIDFont) { - bVertWriting = pCIDFont->IsVertWriting(); - } - FX_FLOAT fontsize = m_TextState.GetFontSize(); - for (int i = 0; i < m_nChars; ++i) { - FX_DWORD charcode = - m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; - if (i > 0) { - if (charcode == (FX_DWORD)-1) { - curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; - continue; - } - m_pCharPos[i - 1] = curpos; - } - FX_RECT char_rect = pFont->GetCharBBox(charcode, level); - FX_FLOAT charwidth; - if (!bVertWriting) { - if (min_y > char_rect.top) { - min_y = (FX_FLOAT)char_rect.top; - } - if (max_y < char_rect.top) { - max_y = (FX_FLOAT)char_rect.top; - } - if (min_y > char_rect.bottom) { - min_y = (FX_FLOAT)char_rect.bottom; - } - if (max_y < char_rect.bottom) { - max_y = (FX_FLOAT)char_rect.bottom; - } - FX_FLOAT char_left = curpos + char_rect.left * fontsize / 1000; - FX_FLOAT char_right = curpos + char_rect.right * fontsize / 1000; - if (min_x > char_left) { - min_x = char_left; - } - if (max_x < char_left) { - max_x = char_left; - } - if (min_x > char_right) { - min_x = char_right; - } - if (max_x < char_right) { - max_x = char_right; - } - charwidth = pFont->GetCharWidthF(charcode, level) * fontsize / 1000; - } else { - FX_WORD CID = pCIDFont->CIDFromCharCode(charcode); - short vx; - short vy; - pCIDFont->GetVertOrigin(CID, vx, vy); - char_rect.left -= vx; - char_rect.right -= vx; - char_rect.top -= vy; - char_rect.bottom -= vy; - if (min_x > char_rect.left) { - min_x = (FX_FLOAT)char_rect.left; - } - if (max_x < char_rect.left) { - max_x = (FX_FLOAT)char_rect.left; - } - if (min_x > char_rect.right) { - min_x = (FX_FLOAT)char_rect.right; - } - if (max_x < char_rect.right) { - max_x = (FX_FLOAT)char_rect.right; - } - FX_FLOAT char_top = curpos + char_rect.top * fontsize / 1000; - FX_FLOAT char_bottom = curpos + char_rect.bottom * fontsize / 1000; - if (min_y > char_top) { - min_y = char_top; - } - if (max_y < char_top) { - max_y = char_top; - } - if (min_y > char_bottom) { - min_y = char_bottom; - } - if (max_y < char_bottom) { - max_y = char_bottom; - } - charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000; - } - curpos += charwidth; - if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(32) == 1)) { - curpos += m_TextState.GetObject()->m_WordSpace; - } - curpos += m_TextState.GetObject()->m_CharSpace; - } - if (bVertWriting) { - if (pTextAdvanceX) { - *pTextAdvanceX = 0; - } - if (pTextAdvanceY) { - *pTextAdvanceY = curpos; - } - min_x = min_x * fontsize / 1000; - max_x = max_x * fontsize / 1000; - } else { - if (pTextAdvanceX) { - *pTextAdvanceX = curpos * horz_scale; - } - if (pTextAdvanceY) { - *pTextAdvanceY = 0; - } - min_y = min_y * fontsize / 1000; - max_y = max_y * fontsize / 1000; - } - CFX_Matrix matrix; - GetTextMatrix(&matrix); - m_Left = min_x; - m_Right = max_x; - m_Bottom = min_y; - m_Top = max_y; - matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); - int textmode = m_TextState.GetObject()->m_TextMode; - if (textmode == 1 || textmode == 2 || textmode == 5 || textmode == 6) { - FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2; - m_Left -= half_width; - m_Right += half_width; - m_Top += half_width; - m_Bottom -= half_width; - } -} - -void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { - m_TextState.GetModify(); - CFX_Matrix text_matrix; - GetTextMatrix(&text_matrix); - text_matrix.Concat(matrix); - FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); - pTextMatrix[0] = text_matrix.GetA(); - pTextMatrix[1] = text_matrix.GetC(); - pTextMatrix[2] = text_matrix.GetB(); - pTextMatrix[3] = text_matrix.GetD(); - m_PosX = text_matrix.GetE(); - m_PosY = text_matrix.GetF(); - CalcPositionData(nullptr, nullptr, 0); -} - -void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) { - FX_FLOAT dx = x - m_PosX; - FX_FLOAT dy = y - m_PosY; - m_PosX = x; - m_PosY = y; - m_Left += dx; - m_Right += dx; - m_Top += dy; - m_Bottom += dy; -} - -CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {} - -CPDF_ShadingObject::~CPDF_ShadingObject() {} - -CPDF_ShadingObject* CPDF_ShadingObject::Clone() const { - CPDF_ShadingObject* obj = new CPDF_ShadingObject; - obj->CopyData(this); - - obj->m_pShading = m_pShading; - if (obj->m_pShading && obj->m_pShading->m_pDocument) { - CPDF_DocPageData* pDocPageData = - obj->m_pShading->m_pDocument->GetPageData(); - obj->m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern( - obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj, - &obj->m_pShading->m_ParentMatrix); - } - obj->m_Matrix = m_Matrix; - return obj; -} - -void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) { - if (!m_ClipPath.IsNull()) { - m_ClipPath.GetModify(); - m_ClipPath.Transform(matrix); - } - m_Matrix.Concat(matrix); - if (!m_ClipPath.IsNull()) { - CalcBoundingBox(); - } else { - matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); - } -} - -void CPDF_ShadingObject::CalcBoundingBox() { - if (m_ClipPath.IsNull()) { - return; - } - CFX_FloatRect rect = m_ClipPath.GetClipBox(); - m_Left = rect.left; - m_Bottom = rect.bottom; - m_Right = rect.right; - m_Top = rect.top; -} - -CPDF_FormObject::CPDF_FormObject() : m_pForm(nullptr) {} - -CPDF_FormObject::~CPDF_FormObject() { - delete m_pForm; -} - -void CPDF_FormObject::Transform(const CFX_Matrix& matrix) { - m_FormMatrix.Concat(matrix); - CalcBoundingBox(); -} - -CPDF_FormObject* CPDF_FormObject::Clone() const { - CPDF_FormObject* obj = new CPDF_FormObject; - obj->CopyData(this); - - obj->m_pForm = m_pForm->Clone(); - obj->m_FormMatrix = m_FormMatrix; - return obj; -} - -void CPDF_FormObject::CalcBoundingBox() { - CFX_FloatRect form_rect = m_pForm->CalcBoundingBox(); - form_rect.Transform(&m_FormMatrix); - m_Left = form_rect.left; - m_Bottom = form_rect.bottom; - m_Right = form_rect.right; - m_Top = form_rect.top; -} - -CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {} - -void CPDF_Page::Load(CPDF_Document* pDocument, - CPDF_Dictionary* pPageDict, - FX_BOOL bPageCache) { - m_pDocument = (CPDF_Document*)pDocument; - m_pFormDict = pPageDict; - if (bPageCache) { - m_pPageRender = - CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this); - } - if (!pPageDict) { - m_PageWidth = m_PageHeight = 100 * 1.0f; - m_pPageResources = m_pResources = NULL; - return; - } - CPDF_Object* pageAttr = GetPageAttr("Resources"); - m_pResources = pageAttr ? pageAttr->GetDict() : NULL; - m_pPageResources = m_pResources; - CPDF_Object* pRotate = GetPageAttr("Rotate"); - int rotate = 0; - if (pRotate) { - rotate = pRotate->GetInteger() / 90 % 4; - } - if (rotate < 0) { - rotate += 4; - } - CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); - CFX_FloatRect mediabox; - if (pMediaBox) { - mediabox = pMediaBox->GetRect(); - mediabox.Normalize(); - } - if (mediabox.IsEmpty()) { - mediabox = CFX_FloatRect(0, 0, 612, 792); - } - - CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); - if (pCropBox) { - m_BBox = pCropBox->GetRect(); - m_BBox.Normalize(); - } - if (m_BBox.IsEmpty()) { - m_BBox = mediabox; - } else { - m_BBox.Intersect(mediabox); - } - if (rotate % 2) { - m_PageHeight = m_BBox.right - m_BBox.left; - m_PageWidth = m_BBox.top - m_BBox.bottom; - } else { - m_PageWidth = m_BBox.right - m_BBox.left; - m_PageHeight = m_BBox.top - m_BBox.bottom; - } - switch (rotate) { - case 0: - m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom); - break; - case 1: - m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right); - break; - case 2: - m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top); - break; - case 3: - m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left); - break; - } - m_Transparency = PDFTRANS_ISOLATED; - LoadTransInfo(); -} - -void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) { - if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { - return; - } - m_pParser.reset(new CPDF_ContentParser); - m_pParser->Start(this, pOptions); - m_ParseState = CONTENT_PARSING; -} - -void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) { - StartParse(pOptions); - ContinueParse(nullptr); -} - -CPDF_Page::~CPDF_Page() { - if (m_pPageRender) { - IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule(); - pModule->DestroyPageCache(m_pPageRender); - } -} - -CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, - const CFX_ByteStringC& name) { - int level = 0; - while (1) { - CPDF_Object* pObj = pPageDict->GetElementValue(name); - if (pObj) { - return pObj; - } - CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent"); - if (!pParent || pParent == pPageDict) { - return NULL; - } - pPageDict = pParent; - level++; - if (level == 1000) { - return NULL; - } - } -} - -CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const { - return FPDFAPI_GetPageAttr(m_pFormDict, name); -} - -void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, - int xPos, - int yPos, - int xSize, - int ySize, - int iRotate) const { - if (m_PageWidth == 0 || m_PageHeight == 0) { - return; - } - CFX_Matrix display_matrix; - int x0, y0, x1, y1, x2, y2; - iRotate %= 4; - switch (iRotate) { - case 0: - x0 = xPos; - y0 = yPos + ySize; - x1 = xPos; - y1 = yPos; - x2 = xPos + xSize; - y2 = yPos + ySize; - break; - case 1: - x0 = xPos; - y0 = yPos; - x1 = xPos + xSize; - y1 = yPos; - x2 = xPos; - y2 = yPos + ySize; - break; - case 2: - x0 = xPos + xSize; - y0 = yPos; - x1 = xPos + xSize; - y1 = yPos + ySize; - x2 = xPos; - y2 = yPos; - break; - case 3: - x0 = xPos + xSize; - y0 = yPos + ySize; - x1 = xPos; - y1 = yPos + ySize; - x2 = xPos + xSize; - y2 = yPos; - break; - } - display_matrix.Set( - ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth, - ((FX_FLOAT)(x1 - x0)) / m_PageHeight, - ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0); - matrix = m_PageMatrix; - matrix.Concat(display_matrix); -} diff --git a/core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp deleted file mode 100644 index cd81b97112..0000000000 --- a/core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp +++ /dev/null @@ -1,694 +0,0 @@ -// 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 "core/fpdfapi/fpdf_page/pageint.h" - -#include - -#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" -#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/fpdfapi/fpdf_render/render_int.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" -#include "third_party/base/stl_util.h" - -namespace { - -FX_FLOAT ClipFloat(FX_FLOAT f) { - return std::max(0.0f, std::min(1.0f, f)); -} - -} // namespace - -void CPDF_GraphicStates::DefaultStates() { - m_ColorState.New()->Default(); -} -void CPDF_GraphicStates::CopyStates(const CPDF_GraphicStates& src) { - m_ClipPath = src.m_ClipPath; - m_GraphState = src.m_GraphState; - m_ColorState = src.m_ColorState; - m_TextState = src.m_TextState; - m_GeneralState = src.m_GeneralState; -} -CPDF_ClipPathData::CPDF_ClipPathData() { - m_PathCount = 0; - m_pPathList = NULL; - m_pTypeList = NULL; - m_TextCount = 0; - m_pTextList = NULL; -} -CPDF_ClipPathData::~CPDF_ClipPathData() { - int i; - delete[] m_pPathList; - FX_Free(m_pTypeList); - for (i = m_TextCount - 1; i > -1; i--) - delete m_pTextList[i]; - FX_Free(m_pTextList); -} -CPDF_ClipPathData::CPDF_ClipPathData(const CPDF_ClipPathData& src) { - m_pPathList = NULL; - m_pPathList = NULL; - m_pTextList = NULL; - m_PathCount = src.m_PathCount; - if (m_PathCount) { - int alloc_size = m_PathCount; - if (alloc_size % 8) { - alloc_size += 8 - (alloc_size % 8); - } - m_pPathList = new CPDF_Path[alloc_size]; - for (int i = 0; i < m_PathCount; i++) { - m_pPathList[i] = src.m_pPathList[i]; - } - m_pTypeList = FX_Alloc(uint8_t, alloc_size); - FXSYS_memcpy(m_pTypeList, src.m_pTypeList, m_PathCount); - } else { - m_pPathList = NULL; - m_pTypeList = NULL; - } - m_TextCount = src.m_TextCount; - if (m_TextCount) { - m_pTextList = FX_Alloc(CPDF_TextObject*, m_TextCount); - for (int i = 0; i < m_TextCount; i++) { - if (src.m_pTextList[i]) { - m_pTextList[i] = src.m_pTextList[i]->Clone(); - } else { - m_pTextList[i] = NULL; - } - } - } else { - m_pTextList = NULL; - } -} -void CPDF_ClipPathData::SetCount(int path_count, int text_count) { - ASSERT(m_TextCount == 0 && m_PathCount == 0); - if (path_count) { - m_PathCount = path_count; - int alloc_size = (path_count + 7) / 8 * 8; - m_pPathList = new CPDF_Path[alloc_size]; - m_pTypeList = FX_Alloc(uint8_t, alloc_size); - } - if (text_count) { - m_TextCount = text_count; - m_pTextList = FX_Alloc(CPDF_TextObject*, text_count); - } -} -CFX_FloatRect CPDF_ClipPath::GetClipBox() const { - CFX_FloatRect rect; - FX_BOOL bStarted = FALSE; - int count = GetPathCount(); - if (count) { - rect = GetPath(0).GetBoundingBox(); - for (int i = 1; i < count; i++) { - CFX_FloatRect path_rect = GetPath(i).GetBoundingBox(); - rect.Intersect(path_rect); - } - bStarted = TRUE; - } - count = GetTextCount(); - if (count) { - CFX_FloatRect layer_rect; - FX_BOOL bLayerStarted = FALSE; - for (int i = 0; i < count; i++) { - CPDF_TextObject* pTextObj = GetText(i); - if (!pTextObj) { - if (!bStarted) { - rect = layer_rect; - bStarted = TRUE; - } else { - rect.Intersect(layer_rect); - } - bLayerStarted = FALSE; - } else { - if (!bLayerStarted) { - layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr)); - bLayerStarted = TRUE; - } else { - layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr))); - } - } - } - } - return rect; -} -void CPDF_ClipPath::AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge) { - CPDF_ClipPathData* pData = GetModify(); - if (pData->m_PathCount && bAutoMerge) { - CPDF_Path old_path = pData->m_pPathList[pData->m_PathCount - 1]; - if (old_path.IsRect()) { - CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0), - old_path.GetPointX(2), old_path.GetPointY(2)); - CFX_FloatRect new_rect = path.GetBoundingBox(); - if (old_rect.Contains(new_rect)) { - pData->m_PathCount--; - pData->m_pPathList[pData->m_PathCount].SetNull(); - } - } - } - if (pData->m_PathCount % 8 == 0) { - CPDF_Path* pNewPath = new CPDF_Path[pData->m_PathCount + 8]; - for (int i = 0; i < pData->m_PathCount; i++) { - pNewPath[i] = pData->m_pPathList[i]; - } - delete[] pData->m_pPathList; - uint8_t* pNewType = FX_Alloc(uint8_t, pData->m_PathCount + 8); - FXSYS_memcpy(pNewType, pData->m_pTypeList, pData->m_PathCount); - FX_Free(pData->m_pTypeList); - pData->m_pPathList = pNewPath; - pData->m_pTypeList = pNewType; - } - pData->m_pPathList[pData->m_PathCount] = path; - pData->m_pTypeList[pData->m_PathCount] = (uint8_t)type; - pData->m_PathCount++; -} -void CPDF_ClipPath::DeletePath(int index) { - CPDF_ClipPathData* pData = GetModify(); - if (index >= pData->m_PathCount) { - return; - } - pData->m_pPathList[index].SetNull(); - for (int i = index; i < pData->m_PathCount - 1; i++) { - pData->m_pPathList[i] = pData->m_pPathList[i + 1]; - } - pData->m_pPathList[pData->m_PathCount - 1].SetNull(); - FXSYS_memmove(pData->m_pTypeList + index, pData->m_pTypeList + index + 1, - pData->m_PathCount - index - 1); - pData->m_PathCount--; -} -#define FPDF_CLIPPATH_MAX_TEXTS 1024 -void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) { - CPDF_ClipPathData* pData = GetModify(); - if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) { - for (int i = 0; i < count; i++) { - delete pTexts[i]; - } - return; - } - CPDF_TextObject** pNewList = - FX_Alloc(CPDF_TextObject*, pData->m_TextCount + count + 1); - if (pData->m_pTextList) { - FXSYS_memcpy(pNewList, pData->m_pTextList, - pData->m_TextCount * sizeof(CPDF_TextObject*)); - FX_Free(pData->m_pTextList); - } - pData->m_pTextList = pNewList; - for (int i = 0; i < count; i++) { - pData->m_pTextList[pData->m_TextCount + i] = pTexts[i]; - } - pData->m_pTextList[pData->m_TextCount + count] = NULL; - pData->m_TextCount += count + 1; -} -void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) { - CPDF_ClipPathData* pData = GetModify(); - int i; - for (i = 0; i < pData->m_PathCount; i++) { - pData->m_pPathList[i].Transform(&matrix); - } - for (i = 0; i < pData->m_TextCount; i++) - if (pData->m_pTextList[i]) { - pData->m_pTextList[i]->Transform(matrix); - } -} -CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) { - m_FillColor.Copy(&src.m_FillColor); - m_FillRGB = src.m_FillRGB; - m_StrokeColor.Copy(&src.m_StrokeColor); - m_StrokeRGB = src.m_StrokeRGB; -} -void CPDF_ColorStateData::Default() { - m_FillRGB = m_StrokeRGB = 0; - m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); - m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); -} -void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - int nValues) { - CPDF_ColorStateData* pData = GetModify(); - SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues); -} -void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - int nValues) { - CPDF_ColorStateData* pData = GetModify(); - SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues); -} -void CPDF_ColorState::SetColor(CPDF_Color& color, - FX_DWORD& rgb, - CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - int nValues) { - if (pCS) { - color.SetColorSpace(pCS); - } else if (color.IsNull()) { - color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY)); - } - if (color.m_pCS->CountComponents() > nValues) { - return; - } - color.SetValue(pValue); - int R, G, B; - rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1; -} -void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, - FX_FLOAT* pValue, - int nValues) { - CPDF_ColorStateData* pData = GetModify(); - pData->m_FillColor.SetValue(pPattern, pValue, nValues); - int R, G, B; - FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B); - if (pPattern->m_PatternType == 1 && - ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) { - pData->m_FillRGB = 0x00BFBFBF; - return; - } - pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1; -} -void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, - FX_FLOAT* pValue, - int nValues) { - CPDF_ColorStateData* pData = GetModify(); - pData->m_StrokeColor.SetValue(pPattern, pValue, nValues); - int R, G, B; - FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B); - if (pPattern->m_PatternType == 1 && - ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) { - pData->m_StrokeRGB = 0x00BFBFBF; - return; - } - pData->m_StrokeRGB = - pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1; -} -CPDF_TextStateData::CPDF_TextStateData() { - m_pFont = NULL; - m_pDocument = NULL; - m_FontSize = 1.0f; - m_WordSpace = 0; - m_CharSpace = 0; - m_TextMode = 0; - m_Matrix[0] = m_Matrix[3] = 1.0f; - m_Matrix[1] = m_Matrix[2] = 0; - m_CTM[0] = m_CTM[3] = 1.0f; - m_CTM[1] = m_CTM[2] = 0; -} -CPDF_TextStateData::CPDF_TextStateData(const CPDF_TextStateData& src) { - if (this == &src) { - return; - } - FXSYS_memcpy(this, &src, sizeof(CPDF_TextStateData)); - if (m_pDocument && m_pFont) { - m_pFont = - m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE); - } -} -CPDF_TextStateData::~CPDF_TextStateData() { - if (m_pDocument && m_pFont) { - CPDF_DocPageData* pPageData = m_pDocument->GetPageData(); - if (pPageData && !pPageData->IsForceClear()) { - pPageData->ReleaseFont(m_pFont->GetFontDict()); - } - } -} -void CPDF_TextState::SetFont(CPDF_Font* pFont) { - CPDF_TextStateData* pStateData = GetModify(); - if (pStateData) { - CPDF_Document* pDoc = pStateData->m_pDocument; - CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : NULL; - if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) { - pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict()); - } - pStateData->m_pDocument = pFont ? pFont->m_pDocument : NULL; - pStateData->m_pFont = pFont; - } -} -FX_FLOAT CPDF_TextState::GetFontSizeV() const { - FX_FLOAT* pMatrix = GetMatrix(); - FX_FLOAT unit = FXSYS_sqrt2(pMatrix[1], pMatrix[3]); - FX_FLOAT size = unit * GetFontSize(); - return (FX_FLOAT)FXSYS_fabs(size); -} -FX_FLOAT CPDF_TextState::GetFontSizeH() const { - FX_FLOAT* pMatrix = GetMatrix(); - FX_FLOAT unit = FXSYS_sqrt2(pMatrix[0], pMatrix[2]); - FX_FLOAT size = unit * GetFontSize(); - return (FX_FLOAT)FXSYS_fabs(size); -} -FX_FLOAT CPDF_TextState::GetBaselineAngle() const { - FX_FLOAT* m_Matrix = GetMatrix(); - return FXSYS_atan2(m_Matrix[2], m_Matrix[0]); -} -FX_FLOAT CPDF_TextState::GetShearAngle() const { - FX_FLOAT* m_Matrix = GetMatrix(); - FX_FLOAT shear_angle = FXSYS_atan2(m_Matrix[1], m_Matrix[3]); - return GetBaselineAngle() + shear_angle; -} -CPDF_GeneralStateData::CPDF_GeneralStateData() { - FXSYS_memset(this, 0, sizeof(CPDF_GeneralStateData)); - FXSYS_strcpy((FX_CHAR*)m_BlendMode, "Normal"); - m_StrokeAlpha = 1.0f; - m_FillAlpha = 1.0f; - m_Flatness = 1.0f; - m_Matrix.SetIdentity(); -} -CPDF_GeneralStateData::CPDF_GeneralStateData(const CPDF_GeneralStateData& src) { - FXSYS_memcpy(this, &src, sizeof(CPDF_GeneralStateData)); - if (src.m_pTransferFunc && src.m_pTransferFunc->m_pPDFDoc) { - CPDF_DocRenderData* pDocCache = - src.m_pTransferFunc->m_pPDFDoc->GetRenderData(); - if (!pDocCache) { - return; - } - m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR); - } -} -CPDF_GeneralStateData::~CPDF_GeneralStateData() { - if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) { - CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData(); - if (!pDocCache) { - return; - } - pDocCache->ReleaseTransferFunc(m_pTR); - } -} -static int GetBlendType(const CFX_ByteStringC& mode) { - switch (mode.GetID()) { - case FXBSTR_ID('N', 'o', 'r', 'm'): - case FXBSTR_ID('C', 'o', 'm', 'p'): - return FXDIB_BLEND_NORMAL; - case FXBSTR_ID('M', 'u', 'l', 't'): - return FXDIB_BLEND_MULTIPLY; - case FXBSTR_ID('S', 'c', 'r', 'e'): - return FXDIB_BLEND_SCREEN; - case FXBSTR_ID('O', 'v', 'e', 'r'): - return FXDIB_BLEND_OVERLAY; - case FXBSTR_ID('D', 'a', 'r', 'k'): - return FXDIB_BLEND_DARKEN; - case FXBSTR_ID('L', 'i', 'g', 'h'): - return FXDIB_BLEND_LIGHTEN; - case FXBSTR_ID('C', 'o', 'l', 'o'): - if (mode.GetLength() == 10) { - return FXDIB_BLEND_COLORDODGE; - } - if (mode.GetLength() == 9) { - return FXDIB_BLEND_COLORBURN; - } - return FXDIB_BLEND_COLOR; - case FXBSTR_ID('H', 'a', 'r', 'd'): - return FXDIB_BLEND_HARDLIGHT; - case FXBSTR_ID('S', 'o', 'f', 't'): - return FXDIB_BLEND_SOFTLIGHT; - case FXBSTR_ID('D', 'i', 'f', 'f'): - return FXDIB_BLEND_DIFFERENCE; - case FXBSTR_ID('E', 'x', 'c', 'l'): - return FXDIB_BLEND_EXCLUSION; - case FXBSTR_ID('H', 'u', 'e', 0): - return FXDIB_BLEND_HUE; - case FXBSTR_ID('S', 'a', 't', 'u'): - return FXDIB_BLEND_SATURATION; - case FXBSTR_ID('L', 'u', 'm', 'i'): - return FXDIB_BLEND_LUMINOSITY; - } - return FXDIB_BLEND_NORMAL; -} -void CPDF_GeneralStateData::SetBlendMode(const CFX_ByteStringC& blend_mode) { - if (blend_mode.GetLength() > 15) { - return; - } - FXSYS_memcpy(m_BlendMode, blend_mode.GetPtr(), blend_mode.GetLength()); - m_BlendMode[blend_mode.GetLength()] = 0; - m_BlendType = ::GetBlendType(blend_mode); -} -int RI_StringToId(const CFX_ByteString& ri) { - FX_DWORD id = ri.GetID(); - if (id == FXBSTR_ID('A', 'b', 's', 'o')) { - return 1; - } - if (id == FXBSTR_ID('S', 'a', 't', 'u')) { - return 2; - } - if (id == FXBSTR_ID('P', 'e', 'r', 'c')) { - return 3; - } - return 0; -} -void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { - GetModify()->m_RenderIntent = RI_StringToId(ri); -} -CPDF_AllStates::CPDF_AllStates() { - m_TextX = m_TextY = m_TextLineX = m_TextLineY = 0; - m_TextLeading = 0; - m_TextRise = 0; - m_TextHorzScale = 1.0f; -} -CPDF_AllStates::~CPDF_AllStates() {} -void CPDF_AllStates::Copy(const CPDF_AllStates& src) { - CopyStates(src); - m_TextMatrix.Copy(src.m_TextMatrix); - m_ParentMatrix.Copy(src.m_ParentMatrix); - m_CTM.Copy(src.m_CTM); - m_TextX = src.m_TextX; - m_TextY = src.m_TextY; - m_TextLineX = src.m_TextLineX; - m_TextLineY = src.m_TextLineY; - m_TextLeading = src.m_TextLeading; - m_TextRise = src.m_TextRise; - m_TextHorzScale = src.m_TextHorzScale; -} -void CPDF_AllStates::SetLineDash(CPDF_Array* pArray, - FX_FLOAT phase, - FX_FLOAT scale) { - CFX_GraphStateData* pData = m_GraphState.GetModify(); - pData->m_DashPhase = phase * scale; - pData->SetDashCount(pArray->GetCount()); - for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { - pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale; - } -} -void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, - CPDF_StreamContentParser* pParser) { - CPDF_GeneralStateData* pGeneralState = m_GeneralState.GetModify(); - for (const auto& it : *pGS) { - const CFX_ByteString& key_str = it.first; - CPDF_Object* pElement = it.second; - CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr; - if (!pObject) - continue; - - FX_DWORD key = key_str.GetID(); - switch (key) { - case FXBSTR_ID('L', 'W', 0, 0): - m_GraphState.GetModify()->m_LineWidth = pObject->GetNumber(); - break; - case FXBSTR_ID('L', 'C', 0, 0): - m_GraphState.GetModify()->m_LineCap = - (CFX_GraphStateData::LineCap)pObject->GetInteger(); - break; - case FXBSTR_ID('L', 'J', 0, 0): - m_GraphState.GetModify()->m_LineJoin = - (CFX_GraphStateData::LineJoin)pObject->GetInteger(); - break; - case FXBSTR_ID('M', 'L', 0, 0): - m_GraphState.GetModify()->m_MiterLimit = pObject->GetNumber(); - break; - case FXBSTR_ID('D', 0, 0, 0): { - CPDF_Array* pDash = pObject->AsArray(); - if (!pDash) - break; - - CPDF_Array* pArray = pDash->GetArrayAt(0); - if (!pArray) - break; - - SetLineDash(pArray, pDash->GetNumberAt(1), 1.0f); - break; - } - case FXBSTR_ID('R', 'I', 0, 0): - m_GeneralState.SetRenderIntent(pObject->GetString()); - break; - case FXBSTR_ID('F', 'o', 'n', 't'): { - CPDF_Array* pFont = pObject->AsArray(); - if (!pFont) - break; - - m_TextState.GetModify()->m_FontSize = pFont->GetNumberAt(1); - m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0))); - break; - } - case FXBSTR_ID('T', 'R', 0, 0): - if (pGS->KeyExist("TR2")) { - continue; - } - case FXBSTR_ID('T', 'R', '2', 0): - pGeneralState->m_pTR = - (pObject && !pObject->IsName()) ? pObject : nullptr; - break; - case FXBSTR_ID('B', 'M', 0, 0): { - CPDF_Array* pArray = pObject->AsArray(); - CFX_ByteString mode = - pArray ? pArray->GetStringAt(0) : pObject->GetString(); - - pGeneralState->SetBlendMode(mode); - if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) { - pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE); - } - break; - } - case FXBSTR_ID('S', 'M', 'a', 's'): - if (ToDictionary(pObject)) { - pGeneralState->m_pSoftMask = pObject; - FXSYS_memcpy(pGeneralState->m_SMaskMatrix, - &pParser->GetCurStates()->m_CTM, sizeof(CFX_Matrix)); - } else { - pGeneralState->m_pSoftMask = NULL; - } - break; - case FXBSTR_ID('C', 'A', 0, 0): - pGeneralState->m_StrokeAlpha = ClipFloat(pObject->GetNumber()); - break; - case FXBSTR_ID('c', 'a', 0, 0): - pGeneralState->m_FillAlpha = ClipFloat(pObject->GetNumber()); - break; - case FXBSTR_ID('O', 'P', 0, 0): - pGeneralState->m_StrokeOP = pObject->GetInteger(); - if (!pGS->KeyExist("op")) { - pGeneralState->m_FillOP = pObject->GetInteger(); - } - break; - case FXBSTR_ID('o', 'p', 0, 0): - pGeneralState->m_FillOP = pObject->GetInteger(); - break; - case FXBSTR_ID('O', 'P', 'M', 0): - pGeneralState->m_OPMode = pObject->GetInteger(); - break; - case FXBSTR_ID('B', 'G', 0, 0): - if (pGS->KeyExist("BG2")) { - continue; - } - case FXBSTR_ID('B', 'G', '2', 0): - pGeneralState->m_pBG = pObject; - break; - case FXBSTR_ID('U', 'C', 'R', 0): - if (pGS->KeyExist("UCR2")) { - continue; - } - case FXBSTR_ID('U', 'C', 'R', '2'): - pGeneralState->m_pUCR = pObject; - break; - case FXBSTR_ID('H', 'T', 0, 0): - pGeneralState->m_pHT = pObject; - break; - case FXBSTR_ID('F', 'L', 0, 0): - pGeneralState->m_Flatness = pObject->GetNumber(); - break; - case FXBSTR_ID('S', 'M', 0, 0): - pGeneralState->m_Smoothness = pObject->GetNumber(); - break; - case FXBSTR_ID('S', 'A', 0, 0): - pGeneralState->m_StrokeAdjust = pObject->GetInteger(); - break; - case FXBSTR_ID('A', 'I', 'S', 0): - pGeneralState->m_AlphaSource = pObject->GetInteger(); - break; - case FXBSTR_ID('T', 'K', 0, 0): - pGeneralState->m_TextKnockout = pObject->GetInteger(); - break; - } - } - pGeneralState->m_Matrix = m_CTM; -} -CPDF_ContentMarkItem::CPDF_ContentMarkItem() { - m_ParamType = None; -} -CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src) { - m_MarkName = src.m_MarkName; - m_ParamType = src.m_ParamType; - if (m_ParamType == DirectDict) { - m_pParam = ToDictionary(src.m_pParam->Clone()); - } else { - m_pParam = src.m_pParam; - } -} -CPDF_ContentMarkItem::~CPDF_ContentMarkItem() { - if (m_ParamType == DirectDict && m_pParam) - m_pParam->Release(); -} -FX_BOOL CPDF_ContentMarkItem::HasMCID() const { - if (m_pParam && - (m_ParamType == DirectDict || m_ParamType == PropertiesDict)) { - return m_pParam->KeyExist("MCID"); - } - return FALSE; -} - -CPDF_ContentMarkData::CPDF_ContentMarkData(const CPDF_ContentMarkData& src) - : m_Marks(src.m_Marks) {} - -int CPDF_ContentMarkData::CountItems() const { - return pdfium::CollectionSize(m_Marks); -} - -int CPDF_ContentMarkData::GetMCID() const { - for (const auto& mark : m_Marks) { - CPDF_ContentMarkItem::ParamType type = mark.GetParamType(); - if (type == CPDF_ContentMarkItem::PropertiesDict || - type == CPDF_ContentMarkItem::DirectDict) { - CPDF_Dictionary* pDict = mark.GetParam(); - if (pDict->KeyExist("MCID")) - return pDict->GetIntegerBy("MCID"); - } - } - return -1; -} - -void CPDF_ContentMarkData::AddMark(const CFX_ByteString& name, - CPDF_Dictionary* pDict, - FX_BOOL bDirect) { - CPDF_ContentMarkItem item; - item.SetName(name); - if (pDict) { - if (bDirect) { - item.SetParam(CPDF_ContentMarkItem::DirectDict, - ToDictionary(pDict->Clone())); - } else { - item.SetParam(CPDF_ContentMarkItem::PropertiesDict, pDict); - } - } - m_Marks.push_back(item); -} - -void CPDF_ContentMarkData::DeleteLastMark() { - if (!m_Marks.empty()) - m_Marks.pop_back(); -} - -FX_BOOL CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const { - if (!m_pObject) { - return FALSE; - } - for (int i = 0; i < m_pObject->CountItems(); i++) { - CPDF_ContentMarkItem& item = m_pObject->GetItem(i); - if (item.GetName() == mark) { - return TRUE; - } - } - return FALSE; -} -FX_BOOL CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark, - CPDF_Dictionary*& pDict) const { - if (!m_pObject) { - return FALSE; - } - for (int i = 0; i < m_pObject->CountItems(); i++) { - CPDF_ContentMarkItem& item = m_pObject->GetItem(i); - if (item.GetName() == mark) { - pDict = NULL; - if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict || - item.GetParamType() == CPDF_ContentMarkItem::DirectDict) { - pDict = item.GetParam(); - } - return TRUE; - } - } - return FALSE; -} diff --git a/core/fpdfapi/fpdf_page/fpdf_page_image.cpp b/core/fpdfapi/fpdf_page/fpdf_page_image.cpp index 247b0b9703..f66823657f 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_image.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_image.cpp @@ -8,40 +8,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" -CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {} - -CPDF_ImageObject::~CPDF_ImageObject() { - if (!m_pImage) { - return; - } - if (m_pImage->IsInline() || - (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) { - delete m_pImage; - } else { - m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream()); - } -} - -CPDF_ImageObject* CPDF_ImageObject::Clone() const { - CPDF_ImageObject* obj = new CPDF_ImageObject; - obj->CopyData(this); - - obj->m_pImage = m_pImage->Clone(); - obj->m_Matrix = m_Matrix; - return obj; -} - -void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) { - m_Matrix.Concat(matrix); - CalcBoundingBox(); -} -void CPDF_ImageObject::CalcBoundingBox() { - m_Left = m_Bottom = 0; - m_Right = m_Top = 1.0f; - m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); -} void CPDF_Image::Release() { if (m_bInline || (m_pStream && m_pStream->GetObjNum() == 0)) { delete this; diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index b62579813a..700103ed41 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -9,7 +9,14 @@ #include #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" +#include "core/fpdfapi/fpdf_page/cpdf_allstates.h" #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index c1bb70ff80..c9f05ac5ab 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -8,8 +8,11 @@ #include +#include "core/fpdfapi/fpdf_page/cpdf_allstates.h" #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_path.h" #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" #include "core/fpdfapi/fpdf_parser/cpdf_null.h" #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" diff --git a/core/fpdfapi/fpdf_page/fpdf_page_path.cpp b/core/fpdfapi/fpdf_page/fpdf_page_path.cpp deleted file mode 100644 index 286dfdfb1c..0000000000 --- a/core/fpdfapi/fpdf_page/fpdf_page_path.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// 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 "core/fpdfapi/fpdf_page/pageint.h" - -#include "core/include/fpdfapi/fpdf_pageobj.h" - -CPDF_PathObject::CPDF_PathObject() {} - -CPDF_PathObject::~CPDF_PathObject() {} - -CPDF_PathObject* CPDF_PathObject::Clone() const { - CPDF_PathObject* obj = new CPDF_PathObject; - obj->CopyData(this); - - obj->m_Path = m_Path; - obj->m_FillType = m_FillType; - obj->m_bStroke = m_bStroke; - obj->m_Matrix = m_Matrix; - return obj; -} - -void CPDF_PathObject::Transform(const CFX_Matrix& matrix) { - m_Matrix.Concat(matrix); - CalcBoundingBox(); -} - -void CPDF_PathObject::CalcBoundingBox() { - if (m_Path.IsNull()) { - return; - } - CFX_FloatRect rect; - FX_FLOAT width = m_GraphState.GetObject()->m_LineWidth; - if (m_bStroke && width != 0) { - rect = m_Path.GetBoundingBox(width, m_GraphState.GetObject()->m_MiterLimit); - } else { - rect = m_Path.GetBoundingBox(); - } - rect.Transform(&m_Matrix); - if (width == 0 && m_bStroke) { - rect.left += -0.5f; - rect.right += 0.5f; - rect.bottom += -0.5f; - rect.top += 0.5f; - } - m_Left = rect.left; - m_Right = rect.right; - m_Top = rect.top; - m_Bottom = rect.bottom; -} diff --git a/core/fpdfapi/fpdf_page/include/cpdf_clippath.h b/core/fpdfapi/fpdf_page/include/cpdf_clippath.h new file mode 100644 index 0000000000..4631e8266a --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_clippath.h @@ -0,0 +1,34 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_CLIPPATH_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_CLIPPATH_H_ + +#include "core/fpdfapi/fpdf_page/cpdf_clippathdata.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_path.h" +#include "core/include/fxcrt/fx_basic.h" +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_TextObject; + +class CPDF_ClipPath : public CFX_CountRef { + public: + FX_DWORD GetPathCount() const { return m_pObject->m_PathCount; } + CPDF_Path GetPath(int i) const { return m_pObject->m_pPathList[i]; } + int GetClipType(int i) const { return m_pObject->m_pTypeList[i]; } + FX_DWORD GetTextCount() const { return m_pObject->m_TextCount; } + CPDF_TextObject* GetText(int i) const { return m_pObject->m_pTextList[i]; } + CFX_FloatRect GetClipBox() const; + + void AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge); + void DeletePath(int layer_index); + + void AppendTexts(CPDF_TextObject** pTexts, int count); + void Transform(const CFX_Matrix& matrix); +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_CLIPPATH_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_formobject.h b/core/fpdfapi/fpdf_page/include/cpdf_formobject.h new file mode 100644 index 0000000000..47d40e0e8b --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_formobject.h @@ -0,0 +1,34 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_ + +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/include/fxcrt/fx_coordinates.h" + +class Form; + +class CPDF_FormObject : public CPDF_PageObject { + public: + CPDF_FormObject(); + ~CPDF_FormObject() override; + + // CPDF_PageObject: + CPDF_FormObject* Clone() const override; + Type GetType() const override { return FORM; }; + void Transform(const CFX_Matrix& matrix) override; + bool IsForm() const override { return true; }; + CPDF_FormObject* AsForm() override { return this; }; + const CPDF_FormObject* AsForm() const override { return this; }; + + void CalcBoundingBox(); + + CPDF_Form* m_pForm; + CFX_Matrix m_FormMatrix; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h new file mode 100644 index 0000000000..3495b6c3ff --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h @@ -0,0 +1,29 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_ + +#include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h" +#include "core/include/fxcrt/fx_basic.h" + +class CPDF_GeneralState : public CFX_CountRef { + public: + void SetRenderIntent(const CFX_ByteString& ri); + + int GetBlendType() const { + return m_pObject ? m_pObject->m_BlendType : FXDIB_BLEND_NORMAL; + } + + int GetAlpha(FX_BOOL bStroke) const { + if (!m_pObject) + return 255; + return FXSYS_round( + (bStroke ? m_pObject->m_StrokeAlpha : m_pObject->m_FillAlpha) * 255); + } +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h new file mode 100644 index 0000000000..f2e5510ccc --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h @@ -0,0 +1,49 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATEDATA_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATEDATA_H_ + +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_dib.h" + +class CPDF_TransferFunc; +class CPDF_Object; + +class CPDF_GeneralStateData { + public: + CPDF_GeneralStateData(); + CPDF_GeneralStateData(const CPDF_GeneralStateData& src); + ~CPDF_GeneralStateData(); + + void SetBlendMode(const CFX_ByteStringC& blend_mode); + + char m_BlendMode[16]; + int m_BlendType; + CPDF_Object* m_pSoftMask; + FX_FLOAT m_SMaskMatrix[6]; + FX_FLOAT m_StrokeAlpha; + FX_FLOAT m_FillAlpha; + CPDF_Object* m_pTR; + CPDF_TransferFunc* m_pTransferFunc; + CFX_Matrix m_Matrix; + int m_RenderIntent; + FX_BOOL m_StrokeAdjust; + FX_BOOL m_AlphaSource; + FX_BOOL m_TextKnockout; + FX_BOOL m_StrokeOP; + FX_BOOL m_FillOP; + int m_OPMode; + CPDF_Object* m_pBG; + CPDF_Object* m_pUCR; + CPDF_Object* m_pHT; + FX_FLOAT m_Flatness; + FX_FLOAT m_Smoothness; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATEDATA_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h b/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h new file mode 100644 index 0000000000..dec60c9d9b --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h @@ -0,0 +1,34 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_IMAGEOBJECT_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_IMAGEOBJECT_H_ + +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/include/fxcrt/fx_coordinates.h" + +class CPDF_Image; + +class CPDF_ImageObject : public CPDF_PageObject { + public: + CPDF_ImageObject(); + ~CPDF_ImageObject() override; + + // CPDF_PageObject: + CPDF_ImageObject* Clone() const override; + Type GetType() const override { return IMAGE; }; + void Transform(const CFX_Matrix& matrix) override; + bool IsImage() const override { return true; }; + CPDF_ImageObject* AsImage() override { return this; }; + const CPDF_ImageObject* AsImage() const override { return this; }; + + void CalcBoundingBox(); + + CPDF_Image* m_pImage; + CFX_Matrix m_Matrix; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_IMAGEOBJECT_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_page.h b/core/fpdfapi/fpdf_page/include/cpdf_page.h index 82c88d1c37..5e27ba2ec7 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_page.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_page.h @@ -18,6 +18,9 @@ class CPDF_Object; class CPDF_PageRenderCache; class CPDF_ParseOptions; +CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, + const CFX_ByteStringC& name); + class CPDF_Page : public CPDF_PageObjectHolder, public CFX_PrivateData { public: CPDF_Page(); diff --git a/core/fpdfapi/fpdf_page/include/cpdf_pageobject.h b/core/fpdfapi/fpdf_page/include/cpdf_pageobject.h new file mode 100644 index 0000000000..2f55547b47 --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_pageobject.h @@ -0,0 +1,71 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGEOBJECT_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGEOBJECT_H_ + +#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h" +#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_TextObject; +class CPDF_PathObject; +class CPDF_ImageObject; +class CPDF_ShadingObject; +class CPDF_FormObject; + +class CPDF_PageObject : public CPDF_GraphicStates { + public: + enum Type { + TEXT = 1, + PATH, + IMAGE, + SHADING, + FORM, + }; + + CPDF_PageObject(); + virtual ~CPDF_PageObject(); + + virtual CPDF_PageObject* Clone() const = 0; + virtual Type GetType() const = 0; + virtual void Transform(const CFX_Matrix& matrix) = 0; + virtual bool IsText() const { return false; } + virtual bool IsPath() const { return false; } + virtual bool IsImage() const { return false; } + virtual bool IsShading() const { return false; } + virtual bool IsForm() const { return false; } + virtual CPDF_TextObject* AsText() { return nullptr; } + virtual const CPDF_TextObject* AsText() const { return nullptr; } + virtual CPDF_PathObject* AsPath() { return nullptr; } + virtual const CPDF_PathObject* AsPath() const { return nullptr; } + virtual CPDF_ImageObject* AsImage() { return nullptr; } + virtual const CPDF_ImageObject* AsImage() const { return nullptr; } + virtual CPDF_ShadingObject* AsShading() { return nullptr; } + virtual const CPDF_ShadingObject* AsShading() const { return nullptr; } + virtual CPDF_FormObject* AsForm() { return nullptr; } + virtual const CPDF_FormObject* AsForm() const { return nullptr; } + + void TransformClipPath(CFX_Matrix& matrix); + void TransformGeneralState(CFX_Matrix& matrix); + FX_RECT GetBBox(const CFX_Matrix* pMatrix) const; + + FX_FLOAT m_Left; + FX_FLOAT m_Right; + FX_FLOAT m_Top; + FX_FLOAT m_Bottom; + CPDF_ContentMark m_ContentMark; + + protected: + void CopyData(const CPDF_PageObject* pSrcObject); + + private: + CPDF_PageObject(const CPDF_PageObject& src) = delete; + void operator=(const CPDF_PageObject& src) = delete; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGEOBJECT_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_path.h b/core/fpdfapi/fpdf_page/include/cpdf_path.h new file mode 100644 index 0000000000..a90115486a --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_path.h @@ -0,0 +1,50 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATH_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATH_H_ + +#include "core/include/fxcrt/fx_system.h" +#include "core/include/fxge/fx_ge.h" + +class CPDF_Path : public CFX_CountRef { + public: + int GetPointCount() const { return m_pObject->m_PointCount; } + int GetFlag(int index) const { return m_pObject->m_pPoints[index].m_Flag; } + + FX_FLOAT GetPointX(int index) const { + return m_pObject->m_pPoints[index].m_PointX; + } + + FX_FLOAT GetPointY(int index) const { + return m_pObject->m_pPoints[index].m_PointY; + } + + FX_PATHPOINT* GetPoints() const { return m_pObject->m_pPoints; } + CFX_FloatRect GetBoundingBox() const { return m_pObject->GetBoundingBox(); } + + CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, + FX_FLOAT miter_limit) const { + return m_pObject->GetBoundingBox(line_width, miter_limit); + } + + FX_BOOL IsRect() const { return m_pObject->IsRect(); } + + void Transform(const CFX_Matrix* pMatrix) { GetModify()->Transform(pMatrix); } + + void Append(CPDF_Path src, const CFX_Matrix* pMatrix) { + m_pObject->Append(src.m_pObject, pMatrix); + } + + void AppendRect(FX_FLOAT left, + FX_FLOAT bottom, + FX_FLOAT right, + FX_FLOAT top) { + m_pObject->AppendRect(left, bottom, right, top); + } +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATH_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_pathobject.h b/core/fpdfapi/fpdf_page/include/cpdf_pathobject.h new file mode 100644 index 0000000000..30df0c2937 --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_pathobject.h @@ -0,0 +1,36 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATHOBJECT_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATHOBJECT_H_ + +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_path.h" +#include "core/include/fxcrt/fx_coordinates.h" +#include "core/include/fxcrt/fx_system.h" + +class CPDF_PathObject : public CPDF_PageObject { + public: + CPDF_PathObject(); + ~CPDF_PathObject() override; + + // CPDF_PageObject: + CPDF_PathObject* Clone() const override; + Type GetType() const override { return PATH; }; + void Transform(const CFX_Matrix& maxtrix) override; + bool IsPath() const override { return true; }; + CPDF_PathObject* AsPath() override { return this; }; + const CPDF_PathObject* AsPath() const override { return this; }; + + void CalcBoundingBox(); + + CPDF_Path m_Path; + int m_FillType; + FX_BOOL m_bStroke; + CFX_Matrix m_Matrix; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATHOBJECT_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h b/core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h new file mode 100644 index 0000000000..f43a1e3a4f --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h @@ -0,0 +1,34 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_SHADINGOBJECT_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_SHADINGOBJECT_H_ + +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/include/fxcrt/fx_coordinates.h" + +class CPDF_ShadingPattern; + +class CPDF_ShadingObject : public CPDF_PageObject { + public: + CPDF_ShadingObject(); + ~CPDF_ShadingObject() override; + + // CPDF_PageObject: + CPDF_ShadingObject* Clone() const override; + Type GetType() const override { return SHADING; }; + void Transform(const CFX_Matrix& matrix) override; + bool IsShading() const override { return true; }; + CPDF_ShadingObject* AsShading() override { return this; }; + const CPDF_ShadingObject* AsShading() const override { return this; }; + + void CalcBoundingBox(); + + CPDF_ShadingPattern* m_pShading; + CFX_Matrix m_Matrix; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_SHADINGOBJECT_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_textobject.h b/core/fpdfapi/fpdf_page/include/cpdf_textobject.h new file mode 100644 index 0000000000..9aaa2f0160 --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_textobject.h @@ -0,0 +1,69 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTOBJECT_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTOBJECT_H_ + +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/include/fxcrt/fx_string.h" +#include "core/include/fxcrt/fx_system.h" + +struct CPDF_TextObjectItem { + FX_DWORD m_CharCode; + FX_FLOAT m_OriginX; + FX_FLOAT m_OriginY; +}; + +class CPDF_TextObject : public CPDF_PageObject { + public: + CPDF_TextObject(); + ~CPDF_TextObject() override; + + // CPDF_PageObject: + CPDF_TextObject* Clone() const override; + Type GetType() const override { return TEXT; }; + void Transform(const CFX_Matrix& matrix) override; + bool IsText() const override { return true; }; + CPDF_TextObject* AsText() override { return this; }; + const CPDF_TextObject* AsText() const override { return this; }; + + int CountItems() const { return m_nChars; } + void GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const; + int CountChars() const; + void GetCharInfo(int index, FX_DWORD& charcode, FX_FLOAT& kerning) const; + void GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const; + FX_FLOAT GetCharWidth(FX_DWORD charcode) const; + FX_FLOAT GetPosX() const { return m_PosX; } + FX_FLOAT GetPosY() const { return m_PosY; } + void GetTextMatrix(CFX_Matrix* pMatrix) const; + CPDF_Font* GetFont() const { return m_TextState.GetFont(); } + FX_FLOAT GetFontSize() const { return m_TextState.GetFontSize(); } + + void SetText(const CFX_ByteString& text); + void SetPosition(FX_FLOAT x, FX_FLOAT y); + + void RecalcPositionData() { CalcPositionData(nullptr, nullptr, 1); } + + protected: + friend class CPDF_RenderStatus; + friend class CPDF_StreamContentParser; + friend class CPDF_TextRenderer; + + void SetSegments(const CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs); + + void CalcPositionData(FX_FLOAT* pTextAdvanceX, + FX_FLOAT* pTextAdvanceY, + FX_FLOAT horz_scale, + int level = 0); + + FX_FLOAT m_PosX; + FX_FLOAT m_PosY; + int m_nChars; + FX_DWORD* m_pCharCodes; + FX_FLOAT* m_pCharPos; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTOBJECT_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h new file mode 100644 index 0000000000..1fcc1fe8c2 --- /dev/null +++ b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h @@ -0,0 +1,31 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTSTATEDATA_H_ +#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTSTATEDATA_H_ + +#include "core/include/fxcrt/fx_system.h" + +class CPDF_Font; +class CPDF_Document; + +class CPDF_TextStateData { + public: + CPDF_TextStateData(); + CPDF_TextStateData(const CPDF_TextStateData& src); + ~CPDF_TextStateData(); + + CPDF_Font* m_pFont; + CPDF_Document* m_pDocument; + FX_FLOAT m_FontSize; + FX_FLOAT m_CharSpace; + FX_FLOAT m_WordSpace; + FX_FLOAT m_Matrix[4]; + int m_TextMode; + FX_FLOAT m_CTM[4]; +}; + +#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTSTATEDATA_H_ diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h index eab3d42b2b..e6a150072e 100644 --- a/core/fpdfapi/fpdf_page/pageint.h +++ b/core/fpdfapi/fpdf_page/pageint.h @@ -12,13 +12,25 @@ #include #include +#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h" #include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h" #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" +#include "core/include/fpdfapi/fpdf_resource.h" +#include "core/include/fxge/fx_ge.h" class CPDF_AllStates; -class CPDF_ParseOptions; +class CPDF_ColorSpace; +class CPDF_Font; +class CPDF_FontEncoding; +class CPDF_Form; class CPDF_IccProfile; +class CPDF_Image; +class CPDF_ImageObject; +class CPDF_ParseOptions; +class CPDF_Pattern; +class CPDF_StreamAcc; +class CPDF_TextObject; +class CPDF_Type3Char; #define PARSE_STEP_LIMIT 100 @@ -308,17 +320,6 @@ class CPDF_ContentParser { FX_DWORD m_CurrentOffset; std::unique_ptr m_pParser; }; -class CPDF_AllStates : public CPDF_GraphicStates { - public: - CPDF_AllStates(); - ~CPDF_AllStates(); - void Copy(const CPDF_AllStates& src); - void ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser); - void SetLineDash(CPDF_Array*, FX_FLOAT, FX_FLOAT scale); - CFX_Matrix m_TextMatrix, m_CTM, m_ParentMatrix; - FX_FLOAT m_TextX, m_TextY, m_TextLineX, m_TextLineY; - FX_FLOAT m_TextLeading, m_TextRise, m_TextHorzScale; -}; class CPDF_DocPageData { public: diff --git a/core/fpdfapi/fpdf_parser/ipdf_occontext.cpp b/core/fpdfapi/fpdf_parser/ipdf_occontext.cpp index 56a2412d9a..0b98b9889e 100644 --- a/core/fpdfapi/fpdf_parser/ipdf_occontext.cpp +++ b/core/fpdfapi/fpdf_parser/ipdf_occontext.cpp @@ -6,7 +6,8 @@ #include "core/fpdfapi/fpdf_parser/ipdf_occontext.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" +#include "core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" IPDF_OCContext::~IPDF_OCContext() {} diff --git a/core/fpdfapi/fpdf_render/fpdf_render.cpp b/core/fpdfapi/fpdf_render/fpdf_render.cpp index b52a7459eb..3f79abe1b8 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render.cpp @@ -6,8 +6,15 @@ #include "core/fpdfapi/fpdf_render/render_int.h" +#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h" +#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" diff --git a/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp b/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp index 298dea0504..15c7dcffcc 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_cache.cpp @@ -12,7 +12,6 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" #include "core/fpdfapi/fpdf_render/render_int.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fxge/fx_ge.h" struct CACHEINFO { diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index b2c89853d7..e16016445e 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -11,6 +11,7 @@ #include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h" #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" @@ -20,7 +21,6 @@ #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fxcodec/fx_codec.h" #include "core/include/fxcrt/fx_safe_types.h" #include "core/include/fxge/fx_ge.h" diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 56af308232..193d0874f1 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -11,13 +11,13 @@ #include #include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" #include "core/fpdfapi/include/cpdf_modulemgr.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fxcodec/fx_codec.h" #include "core/include/fxcrt/fx_safe_types.h" #include "core/include/fxge/fx_ge.h" diff --git a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 8fef5b3ae4..9006f2011f 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -6,14 +6,17 @@ #include "core/fpdfapi/fpdf_render/render_int.h" +#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" #include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h" #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fxge/fx_ge.h" #define SHADING_STEPS 256 diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp index 07790bdf4d..fe72bb3aee 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -8,12 +8,15 @@ #include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h" #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" #include "core/fpdfapi/fpdf_page/pageint.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fxge/fx_ge.h" CPDF_Type3Cache::~CPDF_Type3Cache() { diff --git a/core/fpdfapi/fpdf_render/render_int.h b/core/fpdfapi/fpdf_render/render_int.h index f4cc02357b..b171b60fbe 100644 --- a/core/fpdfapi/fpdf_render/render_int.h +++ b/core/fpdfapi/fpdf_render/render_int.h @@ -10,8 +10,10 @@ #include #include +#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" +#include "core/include/fpdfapi/fpdf_resource.h" class CPDF_PageObjectHolder; class CPDF_PageRenderCache; @@ -21,6 +23,23 @@ class CFX_ImageTransformer; class CPDF_ImageCacheEntry; class CPDF_ImageLoaderHandle; class ICodec_ScanlineDecoder; +class CPDF_Type3Font; +class CPDF_Type3Cache; +class CPDF_Type3Char; +class CPDF_TransferFunc; +class CPDF_Document; +class CPDF_Object; +class CFX_FontCache; +class CPDF_Font; +class CPDF_PageObject; +class CPDF_PathObject; +class CPDF_ShadingObject; +class CPDF_FormObject; +class CPDF_ShadingPattern; +class CPDF_TilingPattern; +class CPDF_Color; +class CPDF_Dictionary; +class CPDF_ImageObject; #define TYPE3_MAX_BLUES 16 diff --git a/core/fpdfdoc/doc_annot.cpp b/core/fpdfdoc/doc_annot.cpp index 52f21922c7..9a407482f1 100644 --- a/core/fpdfdoc/doc_annot.cpp +++ b/core/fpdfdoc/doc_annot.cpp @@ -12,8 +12,8 @@ #include "core/fpdfapi/fpdf_parser/ipdf_occontext.h" #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fpdfdoc/fpdf_doc.h" +#include "core/include/fxge/fx_ge.h" CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) : m_pDocument(pPage->m_pDocument) { diff --git a/core/fpdftext/fpdf_text_int.cpp b/core/fpdftext/fpdf_text_int.cpp index be01648d45..9a2a8c1bde 100644 --- a/core/fpdftext/fpdf_text_int.cpp +++ b/core/fpdftext/fpdf_text_int.cpp @@ -13,13 +13,15 @@ #include #include +#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" #include "core/fpdftext/include/ipdf_linkextract.h" #include "core/fpdftext/include/ipdf_textpage.h" #include "core/fpdftext/include/ipdf_textpagefind.h" #include "core/fpdftext/unicodenormalization.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fpdfapi/fpdf_resource.h" #include "core/include/fxcrt/fx_bidi.h" #include "core/include/fxcrt/fx_ext.h" diff --git a/core/fpdftext/fpdf_text_int.h b/core/fpdftext/fpdf_text_int.h index dc82d3f7d7..c0885b59b7 100644 --- a/core/fpdftext/fpdf_text_int.h +++ b/core/fpdftext/fpdf_text_int.h @@ -22,6 +22,7 @@ class CFX_BidiChar; class CPDF_FormObject; class CPDF_LinkExtract; class CPDF_TextPageFind; +class CPDF_Font; #define FPDFTEXT_CHAR_ERROR -1 #define FPDFTEXT_CHAR_NORMAL 0 diff --git a/core/fpdftext/include/ipdf_textpage.h b/core/fpdftext/include/ipdf_textpage.h index 6808eae511..ad3bea8062 100644 --- a/core/fpdftext/include/ipdf_textpage.h +++ b/core/fpdftext/include/ipdf_textpage.h @@ -7,10 +7,12 @@ #ifndef CORE_FPDFTEXT_INCLUDE_IPDF_TEXTPAGE_H_ #define CORE_FPDFTEXT_INCLUDE_IPDF_TEXTPAGE_H_ -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fxcrt/fx_coordinates.h" #include "core/include/fxcrt/fx_system.h" +class CPDF_TextObject; +class CPDF_Page; + struct FPDF_CHAR_INFO { FX_WCHAR m_Unicode; FX_WCHAR m_Charcode; diff --git a/core/include/fpdfapi/fpdf_pageobj.h b/core/include/fpdfapi/fpdf_pageobj.h deleted file mode 100644 index 388409742a..0000000000 --- a/core/include/fpdfapi/fpdf_pageobj.h +++ /dev/null @@ -1,464 +0,0 @@ -// 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 - -#ifndef CORE_INCLUDE_FPDFAPI_FPDF_PAGEOBJ_H_ -#define CORE_INCLUDE_FPDFAPI_FPDF_PAGEOBJ_H_ - -#include - -#include "core/include/fpdfapi/fpdf_resource.h" -#include "core/include/fxge/fx_ge.h" - -class CPDF_ClipPath; -class CPDF_ClipPathData; -class CPDF_ColorState; -class CPDF_ColorStateData; -class CPDF_ContentMark; -class CPDF_ContentMarkItem; -class CPDF_FormObject; -class CPDF_GeneralState; -class CPDF_GeneralStateData; -class CPDF_GraphicStates; -class CPDF_GraphState; -class CPDF_ImageObject; -class CPDF_PageObject; -class CPDF_Path; -class CPDF_PathObject; -class CPDF_ShadingObject; -class CPDF_TextObject; -class CPDF_TextState; -class CPDF_TextStateData; -class CPDF_TransferFunc; - -class CPDF_Path : public CFX_CountRef { - public: - int GetPointCount() const { return m_pObject->m_PointCount; } - int GetFlag(int index) const { return m_pObject->m_pPoints[index].m_Flag; } - FX_FLOAT GetPointX(int index) const { - return m_pObject->m_pPoints[index].m_PointX; - } - FX_FLOAT GetPointY(int index) const { - return m_pObject->m_pPoints[index].m_PointY; - } - FX_PATHPOINT* GetPoints() const { return m_pObject->m_pPoints; } - CFX_FloatRect GetBoundingBox() const { return m_pObject->GetBoundingBox(); } - CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, - FX_FLOAT miter_limit) const { - return m_pObject->GetBoundingBox(line_width, miter_limit); - } - FX_BOOL IsRect() const { return m_pObject->IsRect(); } - - void Transform(const CFX_Matrix* pMatrix) { GetModify()->Transform(pMatrix); } - void Append(CPDF_Path src, const CFX_Matrix* pMatrix) { - m_pObject->Append(src.m_pObject, pMatrix); - } - void AppendRect(FX_FLOAT left, - FX_FLOAT bottom, - FX_FLOAT right, - FX_FLOAT top) { - m_pObject->AppendRect(left, bottom, right, top); - } -}; - -class CPDF_ClipPathData { - public: - CPDF_ClipPathData(); - CPDF_ClipPathData(const CPDF_ClipPathData&); - ~CPDF_ClipPathData(); - - void SetCount(int path_count, int text_count); - - int m_PathCount; - CPDF_Path* m_pPathList; - uint8_t* m_pTypeList; - int m_TextCount; - CPDF_TextObject** m_pTextList; -}; - -class CPDF_ClipPath : public CFX_CountRef { - public: - FX_DWORD GetPathCount() const { return m_pObject->m_PathCount; } - CPDF_Path GetPath(int i) const { return m_pObject->m_pPathList[i]; } - int GetClipType(int i) const { return m_pObject->m_pTypeList[i]; } - FX_DWORD GetTextCount() const { return m_pObject->m_TextCount; } - CPDF_TextObject* GetText(int i) const { return m_pObject->m_pTextList[i]; } - CFX_FloatRect GetClipBox() const; - void AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge); - void DeletePath(int layer_index); - void AppendTexts(CPDF_TextObject** pTexts, int count); - void Transform(const CFX_Matrix& matrix); -}; - -class CPDF_ColorStateData { - public: - CPDF_ColorStateData() : m_FillRGB(0), m_StrokeRGB(0) {} - CPDF_ColorStateData(const CPDF_ColorStateData& src); - - void Default(); - - CPDF_Color m_FillColor; - FX_DWORD m_FillRGB; - CPDF_Color m_StrokeColor; - FX_DWORD m_StrokeRGB; -}; - -class CPDF_ColorState : public CFX_CountRef { - public: - CPDF_Color* GetFillColor() const { - return m_pObject ? &m_pObject->m_FillColor : nullptr; - } - - CPDF_Color* GetStrokeColor() const { - return m_pObject ? &m_pObject->m_StrokeColor : nullptr; - } - - void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); - void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); - void SetFillPattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); - void SetStrokePattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); - - private: - void SetColor(CPDF_Color& color, - FX_DWORD& rgb, - CPDF_ColorSpace* pCS, - FX_FLOAT* pValue, - int nValues); -}; - -class CPDF_GraphState : public CFX_CountRef { -}; - -class CPDF_TextStateData { - public: - CPDF_TextStateData(); - CPDF_TextStateData(const CPDF_TextStateData& src); - ~CPDF_TextStateData(); - - CPDF_Font* m_pFont; - CPDF_Document* m_pDocument; - FX_FLOAT m_FontSize; - FX_FLOAT m_CharSpace; - FX_FLOAT m_WordSpace; - FX_FLOAT m_Matrix[4]; - int m_TextMode; - FX_FLOAT m_CTM[4]; -}; - -class CPDF_TextState : public CFX_CountRef { - public: - CPDF_Font* GetFont() const { return m_pObject->m_pFont; } - void SetFont(CPDF_Font* pFont); - FX_FLOAT GetFontSize() const { return m_pObject->m_FontSize; } - FX_FLOAT* GetMatrix() const { return m_pObject->m_Matrix; } - FX_FLOAT GetFontSizeV() const; - FX_FLOAT GetFontSizeH() const; - FX_FLOAT GetBaselineAngle() const; - FX_FLOAT GetShearAngle() const; -}; - -class CPDF_GeneralStateData { - public: - CPDF_GeneralStateData(); - CPDF_GeneralStateData(const CPDF_GeneralStateData& src); - ~CPDF_GeneralStateData(); - - void SetBlendMode(const CFX_ByteStringC& blend_mode); - - char m_BlendMode[16]; - int m_BlendType; - CPDF_Object* m_pSoftMask; - FX_FLOAT m_SMaskMatrix[6]; - FX_FLOAT m_StrokeAlpha; - FX_FLOAT m_FillAlpha; - CPDF_Object* m_pTR; - CPDF_TransferFunc* m_pTransferFunc; - CFX_Matrix m_Matrix; - int m_RenderIntent; - FX_BOOL m_StrokeAdjust; - FX_BOOL m_AlphaSource; - FX_BOOL m_TextKnockout; - FX_BOOL m_StrokeOP; - FX_BOOL m_FillOP; - int m_OPMode; - CPDF_Object* m_pBG; - CPDF_Object* m_pUCR; - CPDF_Object* m_pHT; - FX_FLOAT m_Flatness; - FX_FLOAT m_Smoothness; -}; - -class CPDF_GeneralState : public CFX_CountRef { - public: - void SetRenderIntent(const CFX_ByteString& ri); - - int GetBlendType() const { - return m_pObject ? m_pObject->m_BlendType : FXDIB_BLEND_NORMAL; - } - - int GetAlpha(FX_BOOL bStroke) const { - return m_pObject ? FXSYS_round((bStroke ? m_pObject->m_StrokeAlpha - : m_pObject->m_FillAlpha) * - 255) - : 255; - } -}; - -class CPDF_ContentMarkItem { - public: - enum ParamType { None, PropertiesDict, DirectDict }; - - CPDF_ContentMarkItem(); - CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src); - ~CPDF_ContentMarkItem(); - - const CFX_ByteString& GetName() const { return m_MarkName; } - ParamType GetParamType() const { return m_ParamType; } - CPDF_Dictionary* GetParam() const { return m_pParam; } - FX_BOOL HasMCID() const; - void SetName(const CFX_ByteString& name) { m_MarkName = name; } - void SetParam(ParamType type, CPDF_Dictionary* param) { - m_ParamType = type; - m_pParam = param; - } - - private: - CFX_ByteString m_MarkName; - ParamType m_ParamType; - CPDF_Dictionary* m_pParam; -}; - -class CPDF_ContentMarkData { - public: - CPDF_ContentMarkData() {} - CPDF_ContentMarkData(const CPDF_ContentMarkData& src); - - int CountItems() const; - CPDF_ContentMarkItem& GetItem(int index) { return m_Marks[index]; } - const CPDF_ContentMarkItem& GetItem(int index) const { - return m_Marks[index]; - } - - int GetMCID() const; - void AddMark(const CFX_ByteString& name, - CPDF_Dictionary* pDict, - FX_BOOL bDictNeedClone); - void DeleteLastMark(); - - private: - std::vector m_Marks; -}; - -class CPDF_ContentMark : public CFX_CountRef { - public: - int GetMCID() const { return m_pObject ? m_pObject->GetMCID() : -1; } - - FX_BOOL HasMark(const CFX_ByteStringC& mark) const; - - FX_BOOL LookupMark(const CFX_ByteStringC& mark, - CPDF_Dictionary*& pDict) const; -}; - -class CPDF_GraphicStates { - public: - void CopyStates(const CPDF_GraphicStates& src); - - void DefaultStates(); - - CPDF_ClipPath m_ClipPath; - - CPDF_GraphState m_GraphState; - - CPDF_ColorState m_ColorState; - - CPDF_TextState m_TextState; - - CPDF_GeneralState m_GeneralState; -}; - -class CPDF_PageObject : public CPDF_GraphicStates { - public: - enum Type { - TEXT = 1, - PATH, - IMAGE, - SHADING, - FORM, - }; - - CPDF_PageObject(); - virtual ~CPDF_PageObject(); - - virtual CPDF_PageObject* Clone() const = 0; - virtual Type GetType() const = 0; - virtual void Transform(const CFX_Matrix& matrix) = 0; - virtual bool IsText() const { return false; } - virtual bool IsPath() const { return false; } - virtual bool IsImage() const { return false; } - virtual bool IsShading() const { return false; } - virtual bool IsForm() const { return false; } - virtual CPDF_TextObject* AsText() { return nullptr; } - virtual const CPDF_TextObject* AsText() const { return nullptr; } - virtual CPDF_PathObject* AsPath() { return nullptr; } - virtual const CPDF_PathObject* AsPath() const { return nullptr; } - virtual CPDF_ImageObject* AsImage() { return nullptr; } - virtual const CPDF_ImageObject* AsImage() const { return nullptr; } - virtual CPDF_ShadingObject* AsShading() { return nullptr; } - virtual const CPDF_ShadingObject* AsShading() const { return nullptr; } - virtual CPDF_FormObject* AsForm() { return nullptr; } - virtual const CPDF_FormObject* AsForm() const { return nullptr; } - - void TransformClipPath(CFX_Matrix& matrix); - void TransformGeneralState(CFX_Matrix& matrix); - FX_RECT GetBBox(const CFX_Matrix* pMatrix) const; - - FX_FLOAT m_Left; - FX_FLOAT m_Right; - FX_FLOAT m_Top; - FX_FLOAT m_Bottom; - CPDF_ContentMark m_ContentMark; - - protected: - void CopyData(const CPDF_PageObject* pSrcObject); - - private: - CPDF_PageObject(const CPDF_PageObject& src) = delete; - void operator=(const CPDF_PageObject& src) = delete; -}; - -struct CPDF_TextObjectItem { - FX_DWORD m_CharCode; - FX_FLOAT m_OriginX; - FX_FLOAT m_OriginY; -}; - -class CPDF_TextObject : public CPDF_PageObject { - public: - CPDF_TextObject(); - ~CPDF_TextObject() override; - - // CPDF_PageObject: - CPDF_TextObject* Clone() const override; - Type GetType() const override { return TEXT; }; - void Transform(const CFX_Matrix& matrix) override; - bool IsText() const override { return true; }; - CPDF_TextObject* AsText() override { return this; }; - const CPDF_TextObject* AsText() const override { return this; }; - - int CountItems() const { return m_nChars; } - void GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const; - int CountChars() const; - void GetCharInfo(int index, FX_DWORD& charcode, FX_FLOAT& kerning) const; - void GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const; - FX_FLOAT GetCharWidth(FX_DWORD charcode) const; - FX_FLOAT GetPosX() const { return m_PosX; } - FX_FLOAT GetPosY() const { return m_PosY; } - void GetTextMatrix(CFX_Matrix* pMatrix) const; - CPDF_Font* GetFont() const { return m_TextState.GetFont(); } - FX_FLOAT GetFontSize() const { return m_TextState.GetFontSize(); } - - void SetText(const CFX_ByteString& text); - void SetPosition(FX_FLOAT x, FX_FLOAT y); - - void RecalcPositionData() { CalcPositionData(nullptr, nullptr, 1); } - - protected: - friend class CPDF_RenderStatus; - friend class CPDF_StreamContentParser; - friend class CPDF_TextRenderer; - - void SetSegments(const CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs); - - void CalcPositionData(FX_FLOAT* pTextAdvanceX, - FX_FLOAT* pTextAdvanceY, - FX_FLOAT horz_scale, - int level = 0); - - FX_FLOAT m_PosX; - FX_FLOAT m_PosY; - int m_nChars; - FX_DWORD* m_pCharCodes; - FX_FLOAT* m_pCharPos; -}; - -class CPDF_PathObject : public CPDF_PageObject { - public: - CPDF_PathObject(); - ~CPDF_PathObject() override; - - // CPDF_PageObject: - CPDF_PathObject* Clone() const override; - Type GetType() const override { return PATH; }; - void Transform(const CFX_Matrix& maxtrix) override; - bool IsPath() const override { return true; }; - CPDF_PathObject* AsPath() override { return this; }; - const CPDF_PathObject* AsPath() const override { return this; }; - - void CalcBoundingBox(); - - CPDF_Path m_Path; - int m_FillType; - FX_BOOL m_bStroke; - CFX_Matrix m_Matrix; -}; - -class CPDF_ImageObject : public CPDF_PageObject { - public: - CPDF_ImageObject(); - ~CPDF_ImageObject() override; - - // CPDF_PageObject: - CPDF_ImageObject* Clone() const override; - Type GetType() const override { return IMAGE; }; - void Transform(const CFX_Matrix& matrix) override; - bool IsImage() const override { return true; }; - CPDF_ImageObject* AsImage() override { return this; }; - const CPDF_ImageObject* AsImage() const override { return this; }; - - void CalcBoundingBox(); - - CPDF_Image* m_pImage; - CFX_Matrix m_Matrix; -}; - -class CPDF_ShadingObject : public CPDF_PageObject { - public: - CPDF_ShadingObject(); - ~CPDF_ShadingObject() override; - - // CPDF_PageObject: - CPDF_ShadingObject* Clone() const override; - Type GetType() const override { return SHADING; }; - void Transform(const CFX_Matrix& matrix) override; - bool IsShading() const override { return true; }; - CPDF_ShadingObject* AsShading() override { return this; }; - const CPDF_ShadingObject* AsShading() const override { return this; }; - - void CalcBoundingBox(); - - CPDF_ShadingPattern* m_pShading; - CFX_Matrix m_Matrix; -}; - -class CPDF_FormObject : public CPDF_PageObject { - public: - CPDF_FormObject(); - ~CPDF_FormObject() override; - - // CPDF_PageObject: - CPDF_FormObject* Clone() const override; - Type GetType() const override { return FORM; }; - void Transform(const CFX_Matrix& matrix) override; - bool IsForm() const override { return true; }; - CPDF_FormObject* AsForm() override { return this; }; - const CPDF_FormObject* AsForm() const override { return this; }; - - void CalcBoundingBox(); - - CPDF_Form* m_pForm; - CFX_Matrix m_FormMatrix; -}; - -#endif // CORE_INCLUDE_FPDFAPI_FPDF_PAGEOBJ_H_ diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index 0923c4d1ca..519c7d8cef 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -9,6 +9,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" +#include "core/include/fpdfapi/fpdf_resource.h" #include "fpdfsdk/include/fsdk_baseannot.h" CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index 92351364d3..b6333d46f0 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -9,6 +9,7 @@ #include #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index ad119279f7..d3d6fc290b 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -6,11 +6,15 @@ #include "public/fpdf_transformpage.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_path.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" #include "fpdfsdk/include/fsdk_define.h" namespace { diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index 194f5e0c54..f052687172 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -6,7 +6,10 @@ #include "public/fpdf_edit.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fpdfapi/include/cpdf_modulemgr.h" +#include "core/include/fpdfapi/fpdf_resource.h" #include "fpdfsdk/include/fsdk_define.h" DLLEXPORT FPDF_PAGEOBJECT STDCALL diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 1345a1dbb1..72148b8e6d 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -8,7 +8,13 @@ #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h" #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp index e15b086f88..4377c3ed94 100644 --- a/fpdfsdk/fpdfppo.cpp +++ b/fpdfsdk/fpdfppo.cpp @@ -15,6 +15,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" #include "fpdfsdk/include/fsdk_define.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index c93b23b69f..6c02364c1c 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -12,6 +12,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" #include "core/include/fxcrt/fx_ext.h" #include "fpdfsdk/include/fsdk_define.h" diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp index d13bbec6cf..e530797539 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" diff --git a/fpdfsdk/fsdk_baseannot.cpp b/fpdfsdk/fsdk_baseannot.cpp index e50a9f11b2..942751d7df 100644 --- a/fpdfsdk/fsdk_baseannot.cpp +++ b/fpdfsdk/fsdk_baseannot.cpp @@ -9,6 +9,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" #include "core/include/fxcrt/fx_ext.h" #include "fpdfsdk/include/fsdk_baseannot.h" #include "fpdfsdk/include/fsdk_define.h" diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp index f2d2c88fa4..c44f346150 100644 --- a/fpdfsdk/fsdk_baseform.cpp +++ b/fpdfsdk/fsdk_baseform.cpp @@ -14,6 +14,7 @@ #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/fsdk_actionhandler.h" #include "fpdfsdk/include/fsdk_baseannot.h" diff --git a/fpdfsdk/fxedit/fxet_pageobjs.cpp b/fpdfsdk/fxedit/fxet_pageobjs.cpp index 7a229ee352..20133529ae 100644 --- a/fpdfsdk/fxedit/fxet_pageobjs.cpp +++ b/fpdfsdk/fxedit/fxet_pageobjs.cpp @@ -4,10 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" +#include "core/include/fxge/fx_ge.h" #include "fpdfsdk/include/fx_systemhandler.h" #include "fpdfsdk/include/fxedit/fx_edit.h" #include "fpdfsdk/include/fxedit/fxet_edit.h" diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h index 7791fdf0fd..4af327fc93 100644 --- a/fpdfsdk/include/fsdk_define.h +++ b/fpdfsdk/include/fsdk_define.h @@ -8,7 +8,6 @@ #define FPDFSDK_INCLUDE_FSDK_DEFINE_H_ #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" -#include "core/include/fpdfapi/fpdf_pageobj.h" #include "core/include/fpdfdoc/fpdf_doc.h" #include "core/include/fpdfdoc/fpdf_vt.h" #include "core/include/fxge/fx_ge.h" diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index 03e885ce8e..20862c869f 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -11,6 +11,9 @@ #include #include +#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" +#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" +#include "core/include/fpdfapi/fpdf_resource.h" #include "fpdfsdk/javascript/JS_Define.h" class PrintParamsObj : public CJS_EmbedObj { diff --git a/pdfium.gyp b/pdfium.gyp index 97d42c5914..af4a48fa3d 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -328,25 +328,63 @@ 'core/fpdfapi/fpdf_font/fpdf_font_cid.cpp', 'core/fpdfapi/fpdf_font/ttgsubtable.cpp', 'core/fpdfapi/fpdf_font/ttgsubtable.h', + 'core/fpdfapi/fpdf_page/cpdf_allstates.cpp', + 'core/fpdfapi/fpdf_page/cpdf_allstates.h', + 'core/fpdfapi/fpdf_page/cpdf_clippath.cpp', + 'core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp', + 'core/fpdfapi/fpdf_page/cpdf_clippathdata.h', + 'core/fpdfapi/fpdf_page/cpdf_colorstate.cpp', + 'core/fpdfapi/fpdf_page/cpdf_colorstate.h', + 'core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp', + 'core/fpdfpai/fpdf_page/cpdf_colorstatedata.h', + 'core/fpdfapi/fpdf_page/cpdf_contentmark.cpp', + 'core/fpdfapi/fpdf_page/cpdf_contentmark.h', + 'core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp', + 'core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h', + 'core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp', + 'core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h', 'core/fpdfapi/fpdf_page/cpdf_form.cpp', + 'core/fpdfapi/fpdf_page/cpdf_formobject.cpp', + 'core/fpdfapi/fpdf_page/cpdf_generalstate.cpp', + 'core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp', + 'core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp', + 'core/fpdfapi/fpdf_page/cpdf_graphicstates.h', + 'core/fpdfapi/fpdf_page/cpdf_graphstate.h', + 'core/fpdfapi/fpdf_page/cpdf_imageobject.cpp', + 'core/fpdfapi/fpdf_page/cpdf_page.cpp', + 'core/fpdfapi/fpdf_page/cpdf_pageobject.cpp', + 'core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp', 'core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp', 'core/fpdfapi/fpdf_page/cpdf_pageobjectlist.h', - 'core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp', 'core/fpdfapi/fpdf_page/cpdf_parseoptions.cpp', 'core/fpdfapi/fpdf_page/cpdf_parseoptions.h', - 'core/fpdfapi/fpdf_page/fpdf_page.cpp', + 'core/fpdfapi/fpdf_page/cpdf_pathobject.cpp', + 'core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp', + 'core/fpdfapi/fpdf_page/cpdf_textobject.cpp', + 'core/fpdfapi/fpdf_page/cpdf_textstate.cpp', + 'core/fpdfapi/fpdf_page/cpdf_textstate.h', + 'core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp', 'core/fpdfapi/fpdf_page/fpdf_page_colors.cpp', 'core/fpdfapi/fpdf_page/fpdf_page_doc.cpp', 'core/fpdfapi/fpdf_page/fpdf_page_func.cpp', - 'core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp', 'core/fpdfapi/fpdf_page/fpdf_page_image.cpp', 'core/fpdfapi/fpdf_page/fpdf_page_parser.cpp', 'core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp', - 'core/fpdfapi/fpdf_page/fpdf_page_path.cpp', 'core/fpdfapi/fpdf_page/fpdf_page_pattern.cpp', - 'core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h', + 'core/fpdfapi/fpdf_page/include/cpdf_clippath.h', 'core/fpdfapi/fpdf_page/include/cpdf_form.h', + 'core/fpdfapi/fpdf_page/include/cpdf_formobject.h', + 'core/fpdfapi/fpdf_page/include/cpdf_graphstate.h', + 'core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h', + 'core/fpdfapi/fpdf_page/include/cpdf_imageobject.h', 'core/fpdfapi/fpdf_page/include/cpdf_page.h', + 'core/fpdfapi/fpdf_page/include/cpdf_pageobject.h', + 'core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h', + 'core/fpdfapi/fpdf_page/include/cpdf_path.h', + 'core/fpdfapi/fpdf_page/include/cpdf_pathobject.h', + 'core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h', + 'core/fpdfapi/fpdf_page/include/cpdf_textobject.h', + 'core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h', 'core/fpdfapi/fpdf_page/pageint.h', 'core/fpdfapi/fpdf_parser/cfdf_document.cpp', 'core/fpdfapi/fpdf_parser/cpdf_array.cpp', @@ -414,7 +452,6 @@ 'core/fpdfapi/include/cpdf_modulemgr.h', 'core/fpdfapi/ipdf_rendermodule.h', 'core/fpdfapi/ipdf_pagemodule.h', - 'core/include/fpdfapi/fpdf_pageobj.h', 'core/include/fpdfapi/fpdf_resource.h', ], }, -- cgit v1.2.3