Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_shadingpattern.cpp

Issue 1824033002: Split core/include/fpdfapi/fpdf_resource.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/fpdf_page/cpdf_shadingpattern.h"
8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
13
14 namespace {
15
16 ShadingType ToShadingType(int type) {
17 return (type > static_cast<int>(kInvalidShading) &&
18 type < static_cast<int>(kMaxShading))
19 ? static_cast<ShadingType>(type)
20 : kInvalidShading;
21 }
22
23 } // namespace
24
25 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc,
26 CPDF_Object* pPatternObj,
27 FX_BOOL bShading,
28 const CFX_Matrix* parentMatrix)
29 : CPDF_Pattern(SHADING,
30 pDoc,
31 bShading ? nullptr : pPatternObj,
32 parentMatrix),
33 m_ShadingType(kInvalidShading),
34 m_bShadingObj(bShading),
35 m_pShadingObj(pPatternObj),
36 m_pCS(nullptr),
37 m_pCountedCS(nullptr),
38 m_nFuncs(0) {
39 if (!bShading) {
40 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
41 m_Pattern2Form = pDict->GetMatrixBy("Matrix");
42 m_pShadingObj = pDict->GetElementValue("Shading");
43 if (parentMatrix)
44 m_Pattern2Form.Concat(*parentMatrix);
45 }
46 for (int i = 0; i < FX_ArraySize(m_pFunctions); ++i)
47 m_pFunctions[i] = nullptr;
48 }
49
50 CPDF_ShadingPattern::~CPDF_ShadingPattern() {
51 for (int i = 0; i < m_nFuncs; ++i)
52 delete m_pFunctions[i];
53
54 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr;
55 if (pCS && m_pDocument)
56 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
57 }
58
59 FX_BOOL CPDF_ShadingPattern::Load() {
60 if (m_ShadingType != kInvalidShading)
61 return TRUE;
62
63 CPDF_Dictionary* pShadingDict =
64 m_pShadingObj ? m_pShadingObj->GetDict() : nullptr;
65 if (!pShadingDict)
66 return FALSE;
67
68 if (m_nFuncs) {
69 for (int i = 0; i < m_nFuncs; i++)
70 delete m_pFunctions[i];
71 m_nFuncs = 0;
72 }
73 CPDF_Object* pFunc = pShadingDict->GetElementValue("Function");
74 if (pFunc) {
75 if (CPDF_Array* pArray = pFunc->AsArray()) {
76 m_nFuncs = std::min<int>(pArray->GetCount(), 4);
77
78 for (int i = 0; i < m_nFuncs; i++)
79 m_pFunctions[i] = CPDF_Function::Load(pArray->GetElementValue(i));
80 } else {
81 m_pFunctions[0] = CPDF_Function::Load(pFunc);
82 m_nFuncs = 1;
83 }
84 }
85 CPDF_Object* pCSObj = pShadingDict->GetElementValue("ColorSpace");
86 if (!pCSObj)
87 return FALSE;
88
89 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData();
90 m_pCS = pDocPageData->GetColorSpace(pCSObj, nullptr);
91 if (m_pCS)
92 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray());
93
94 m_ShadingType = ToShadingType(pShadingDict->GetIntegerBy("ShadingType"));
95
96 // We expect to have a stream if our shading type is a mesh.
97 if (IsMeshShading() && !ToStream(m_pShadingObj))
98 return FALSE;
99
100 return TRUE;
101 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_shadingpattern.h ('k') | core/fpdfapi/fpdf_page/cpdf_textobject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698