1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfapi/page/cpdf_form.h"
8
9 #include "core/fpdfapi/page/cpdf_contentparser.h"
10 #include "core/fpdfapi/page/cpdf_pageobject.h"
11 #include "core/fpdfapi/page/cpdf_pageobjectholder.h"
12 #include "core/fpdfapi/parser/cpdf_dictionary.h"
13 #include "core/fpdfapi/parser/cpdf_stream.h"
14 #include "third_party/base/ptr_util.h"
15
CPDF_Form(CPDF_Document * pDoc,CPDF_Dictionary * pPageResources,CPDF_Stream * pFormStream,CPDF_Dictionary * pParentResources)16 CPDF_Form::CPDF_Form(CPDF_Document* pDoc,
17 CPDF_Dictionary* pPageResources,
18 CPDF_Stream* pFormStream,
19 CPDF_Dictionary* pParentResources)
20 : CPDF_PageObjectHolder(pDoc, pFormStream->GetDict()) {
21 m_pFormStream = pFormStream;
22 m_pResources = m_pFormDict->GetDictFor("Resources");
23 m_pPageResources = pPageResources;
24 if (!m_pResources)
25 m_pResources = pParentResources;
26 if (!m_pResources)
27 m_pResources = pPageResources;
28 m_iTransparency = 0;
29 LoadTransInfo();
30 }
31
~CPDF_Form()32 CPDF_Form::~CPDF_Form() {}
33
StartParse(CPDF_AllStates * pGraphicStates,const CFX_Matrix * pParentMatrix,CPDF_Type3Char * pType3Char,std::set<const uint8_t * > * parsedSet)34 void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates,
35 const CFX_Matrix* pParentMatrix,
36 CPDF_Type3Char* pType3Char,
37 std::set<const uint8_t*>* parsedSet) {
38 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING)
39 return;
40
41 if (!parsedSet) {
42 if (!m_ParsedSet)
43 m_ParsedSet = pdfium::MakeUnique<std::set<const uint8_t*>>();
44 parsedSet = m_ParsedSet.get();
45 }
46
47 m_pParser = pdfium::MakeUnique<CPDF_ContentParser>(
48 this, pGraphicStates, pParentMatrix, pType3Char, parsedSet);
49 m_ParseState = CONTENT_PARSING;
50 }
51
ParseContent()52 void CPDF_Form::ParseContent() {
53 ParseContentWithParams(nullptr, nullptr, nullptr, nullptr);
54 }
55
ParseContentWithParams(CPDF_AllStates * pGraphicStates,const CFX_Matrix * pParentMatrix,CPDF_Type3Char * pType3Char,std::set<const uint8_t * > * parsedSet)56 void CPDF_Form::ParseContentWithParams(CPDF_AllStates* pGraphicStates,
57 const CFX_Matrix* pParentMatrix,
58 CPDF_Type3Char* pType3Char,
59 std::set<const uint8_t*>* parsedSet) {
60 StartParse(pGraphicStates, pParentMatrix, pType3Char, parsedSet);
61 ContinueParse(nullptr);
62 }
63