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

Side by Side Diff: core/fpdfdoc/cpdf_occontext.cpp

Issue 2334323005: Rename dictionary set and get methods (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « core/fpdfdoc/cpdf_numbertree.cpp ('k') | core/fpdfdoc/cpdf_pagelabel.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfdoc/include/cpdf_occontext.h" 7 #include "core/fpdfdoc/include/cpdf_occontext.h"
8 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12 12
13 namespace { 13 namespace {
14 14
15 int32_t FindGroup(const CPDF_Array* pArray, const CPDF_Dictionary* pGroupDict) { 15 int32_t FindGroup(const CPDF_Array* pArray, const CPDF_Dictionary* pGroupDict) {
16 if (!pArray || !pGroupDict) 16 if (!pArray || !pGroupDict)
17 return -1; 17 return -1;
18 18
19 for (size_t i = 0; i < pArray->GetCount(); i++) { 19 for (size_t i = 0; i < pArray->GetCount(); i++) {
20 if (pArray->GetDictAt(i) == pGroupDict) 20 if (pArray->GetDictAt(i) == pGroupDict)
21 return i; 21 return i;
22 } 22 }
23 return -1; 23 return -1;
24 } 24 }
25 25
26 bool HasIntent(const CPDF_Dictionary* pDict, 26 bool HasIntent(const CPDF_Dictionary* pDict,
27 const CFX_ByteStringC& csElement, 27 const CFX_ByteStringC& csElement,
28 const CFX_ByteStringC& csDef) { 28 const CFX_ByteStringC& csDef) {
29 CPDF_Object* pIntent = pDict->GetDirectObjectBy("Intent"); 29 CPDF_Object* pIntent = pDict->GetDirectObjectFor("Intent");
30 if (!pIntent) 30 if (!pIntent)
31 return csElement == csDef; 31 return csElement == csDef;
32 32
33 CFX_ByteString bsIntent; 33 CFX_ByteString bsIntent;
34 if (CPDF_Array* pArray = pIntent->AsArray()) { 34 if (CPDF_Array* pArray = pIntent->AsArray()) {
35 for (size_t i = 0; i < pArray->GetCount(); i++) { 35 for (size_t i = 0; i < pArray->GetCount(); i++) {
36 bsIntent = pArray->GetStringAt(i); 36 bsIntent = pArray->GetStringAt(i);
37 if (bsIntent == "All" || bsIntent == csElement) 37 if (bsIntent == "All" || bsIntent == csElement)
38 return true; 38 return true;
39 } 39 }
40 return false; 40 return false;
41 } 41 }
42 bsIntent = pIntent->GetString(); 42 bsIntent = pIntent->GetString();
43 return bsIntent == "All" || bsIntent == csElement; 43 return bsIntent == "All" || bsIntent == csElement;
44 } 44 }
45 45
46 CPDF_Dictionary* GetConfig(CPDF_Document* pDoc, 46 CPDF_Dictionary* GetConfig(CPDF_Document* pDoc,
47 const CPDF_Dictionary* pOCGDict) { 47 const CPDF_Dictionary* pOCGDict) {
48 ASSERT(pOCGDict); 48 ASSERT(pOCGDict);
49 CPDF_Dictionary* pOCProperties = pDoc->GetRoot()->GetDictBy("OCProperties"); 49 CPDF_Dictionary* pOCProperties = pDoc->GetRoot()->GetDictFor("OCProperties");
50 if (!pOCProperties) 50 if (!pOCProperties)
51 return nullptr; 51 return nullptr;
52 52
53 CPDF_Array* pOCGs = pOCProperties->GetArrayBy("OCGs"); 53 CPDF_Array* pOCGs = pOCProperties->GetArrayFor("OCGs");
54 if (!pOCGs) 54 if (!pOCGs)
55 return nullptr; 55 return nullptr;
56 56
57 if (FindGroup(pOCGs, pOCGDict) < 0) 57 if (FindGroup(pOCGs, pOCGDict) < 0)
58 return nullptr; 58 return nullptr;
59 59
60 CPDF_Dictionary* pConfig = pOCProperties->GetDictBy("D"); 60 CPDF_Dictionary* pConfig = pOCProperties->GetDictFor("D");
61 CPDF_Array* pConfigs = pOCProperties->GetArrayBy("Configs"); 61 CPDF_Array* pConfigs = pOCProperties->GetArrayFor("Configs");
62 if (!pConfigs) 62 if (!pConfigs)
63 return pConfig; 63 return pConfig;
64 64
65 for (size_t i = 0; i < pConfigs->GetCount(); i++) { 65 for (size_t i = 0; i < pConfigs->GetCount(); i++) {
66 CPDF_Dictionary* pFind = pConfigs->GetDictAt(i); 66 CPDF_Dictionary* pFind = pConfigs->GetDictAt(i);
67 if (pFind && HasIntent(pFind, "View", "View")) 67 if (pFind && HasIntent(pFind, "View", "View"))
68 return pFind; 68 return pFind;
69 } 69 }
70 return pConfig; 70 return pConfig;
71 } 71 }
(...skipping 26 matching lines...) Expand all
98 98
99 CPDF_OCContext::~CPDF_OCContext() {} 99 CPDF_OCContext::~CPDF_OCContext() {}
100 100
101 bool CPDF_OCContext::LoadOCGStateFromConfig( 101 bool CPDF_OCContext::LoadOCGStateFromConfig(
102 const CFX_ByteString& csConfig, 102 const CFX_ByteString& csConfig,
103 const CPDF_Dictionary* pOCGDict) const { 103 const CPDF_Dictionary* pOCGDict) const {
104 CPDF_Dictionary* pConfig = GetConfig(m_pDocument, pOCGDict); 104 CPDF_Dictionary* pConfig = GetConfig(m_pDocument, pOCGDict);
105 if (!pConfig) 105 if (!pConfig)
106 return true; 106 return true;
107 107
108 bool bState = pConfig->GetStringBy("BaseState", "ON") != "OFF"; 108 bool bState = pConfig->GetStringFor("BaseState", "ON") != "OFF";
109 CPDF_Array* pArray = pConfig->GetArrayBy("ON"); 109 CPDF_Array* pArray = pConfig->GetArrayFor("ON");
110 if (pArray) { 110 if (pArray) {
111 if (FindGroup(pArray, pOCGDict) >= 0) 111 if (FindGroup(pArray, pOCGDict) >= 0)
112 bState = true; 112 bState = true;
113 } 113 }
114 pArray = pConfig->GetArrayBy("OFF"); 114 pArray = pConfig->GetArrayFor("OFF");
115 if (pArray) { 115 if (pArray) {
116 if (FindGroup(pArray, pOCGDict) >= 0) 116 if (FindGroup(pArray, pOCGDict) >= 0)
117 bState = false; 117 bState = false;
118 } 118 }
119 pArray = pConfig->GetArrayBy("AS"); 119 pArray = pConfig->GetArrayFor("AS");
120 if (!pArray) 120 if (!pArray)
121 return bState; 121 return bState;
122 122
123 CFX_ByteString csFind = csConfig + "State"; 123 CFX_ByteString csFind = csConfig + "State";
124 for (size_t i = 0; i < pArray->GetCount(); i++) { 124 for (size_t i = 0; i < pArray->GetCount(); i++) {
125 CPDF_Dictionary* pUsage = pArray->GetDictAt(i); 125 CPDF_Dictionary* pUsage = pArray->GetDictAt(i);
126 if (!pUsage) 126 if (!pUsage)
127 continue; 127 continue;
128 128
129 if (pUsage->GetStringBy("Event", "View") != csConfig) 129 if (pUsage->GetStringFor("Event", "View") != csConfig)
130 continue; 130 continue;
131 131
132 CPDF_Array* pOCGs = pUsage->GetArrayBy("OCGs"); 132 CPDF_Array* pOCGs = pUsage->GetArrayFor("OCGs");
133 if (!pOCGs) 133 if (!pOCGs)
134 continue; 134 continue;
135 135
136 if (FindGroup(pOCGs, pOCGDict) < 0) 136 if (FindGroup(pOCGs, pOCGDict) < 0)
137 continue; 137 continue;
138 138
139 CPDF_Dictionary* pState = pUsage->GetDictBy(csConfig); 139 CPDF_Dictionary* pState = pUsage->GetDictFor(csConfig);
140 if (!pState) 140 if (!pState)
141 continue; 141 continue;
142 142
143 bState = pState->GetStringBy(csFind) != "OFF"; 143 bState = pState->GetStringFor(csFind) != "OFF";
144 } 144 }
145 return bState; 145 return bState;
146 } 146 }
147 147
148 bool CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const { 148 bool CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const {
149 if (!HasIntent(pOCGDict, "View", "View")) 149 if (!HasIntent(pOCGDict, "View", "View"))
150 return true; 150 return true;
151 151
152 CFX_ByteString csState = GetUsageTypeString(m_eUsageType); 152 CFX_ByteString csState = GetUsageTypeString(m_eUsageType);
153 CPDF_Dictionary* pUsage = pOCGDict->GetDictBy("Usage"); 153 CPDF_Dictionary* pUsage = pOCGDict->GetDictFor("Usage");
154 if (pUsage) { 154 if (pUsage) {
155 CPDF_Dictionary* pState = pUsage->GetDictBy(csState); 155 CPDF_Dictionary* pState = pUsage->GetDictFor(csState);
156 if (pState) { 156 if (pState) {
157 CFX_ByteString csFind = csState + "State"; 157 CFX_ByteString csFind = csState + "State";
158 if (pState->KeyExist(csFind)) 158 if (pState->KeyExist(csFind))
159 return pState->GetStringBy(csFind) != "OFF"; 159 return pState->GetStringFor(csFind) != "OFF";
160 } 160 }
161 if (csState != "View") { 161 if (csState != "View") {
162 pState = pUsage->GetDictBy("View"); 162 pState = pUsage->GetDictFor("View");
163 if (pState && pState->KeyExist("ViewState")) 163 if (pState && pState->KeyExist("ViewState"))
164 return pState->GetStringBy("ViewState") != "OFF"; 164 return pState->GetStringFor("ViewState") != "OFF";
165 } 165 }
166 } 166 }
167 return LoadOCGStateFromConfig(csState, pOCGDict); 167 return LoadOCGStateFromConfig(csState, pOCGDict);
168 } 168 }
169 169
170 bool CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) { 170 bool CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) {
171 if (!pOCGDict) 171 if (!pOCGDict)
172 return false; 172 return false;
173 173
174 const auto it = m_OCGStates.find(pOCGDict); 174 const auto it = m_OCGStates.find(pOCGDict);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 bValue = bValue || bItem; 230 bValue = bValue || bItem;
231 } else { 231 } else {
232 bValue = bValue && bItem; 232 bValue = bValue && bItem;
233 } 233 }
234 } 234 }
235 } 235 }
236 return bValue; 236 return bValue;
237 } 237 }
238 238
239 bool CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict) { 239 bool CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict) {
240 CPDF_Array* pVE = pOCMDDict->GetArrayBy("VE"); 240 CPDF_Array* pVE = pOCMDDict->GetArrayFor("VE");
241 if (pVE) 241 if (pVE)
242 return GetOCGVE(pVE, 0); 242 return GetOCGVE(pVE, 0);
243 243
244 CFX_ByteString csP = pOCMDDict->GetStringBy("P", "AnyOn"); 244 CFX_ByteString csP = pOCMDDict->GetStringFor("P", "AnyOn");
245 CPDF_Object* pOCGObj = pOCMDDict->GetDirectObjectBy("OCGs"); 245 CPDF_Object* pOCGObj = pOCMDDict->GetDirectObjectFor("OCGs");
246 if (!pOCGObj) 246 if (!pOCGObj)
247 return true; 247 return true;
248 248
249 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) 249 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
250 return GetOCGVisible(pDict); 250 return GetOCGVisible(pDict);
251 251
252 CPDF_Array* pArray = pOCGObj->AsArray(); 252 CPDF_Array* pArray = pOCGObj->AsArray();
253 if (!pArray) 253 if (!pArray)
254 return true; 254 return true;
255 255
256 bool bState = (csP == "AllOn" || csP == "AllOff"); 256 bool bState = (csP == "AllOn" || csP == "AllOff");
257 for (size_t i = 0; i < pArray->GetCount(); i++) { 257 for (size_t i = 0; i < pArray->GetCount(); i++) {
258 bool bItem = true; 258 bool bItem = true;
259 CPDF_Dictionary* pItemDict = pArray->GetDictAt(i); 259 CPDF_Dictionary* pItemDict = pArray->GetDictAt(i);
260 if (pItemDict) 260 if (pItemDict)
261 bItem = GetOCGVisible(pItemDict); 261 bItem = GetOCGVisible(pItemDict);
262 262
263 if ((csP == "AnyOn" && bItem) || (csP == "AnyOff" && !bItem)) 263 if ((csP == "AnyOn" && bItem) || (csP == "AnyOff" && !bItem))
264 return true; 264 return true;
265 if ((csP == "AllOn" && !bItem) || (csP == "AllOff" && bItem)) 265 if ((csP == "AllOn" && !bItem) || (csP == "AllOff" && bItem))
266 return false; 266 return false;
267 } 267 }
268 return bState; 268 return bState;
269 } 269 }
270 270
271 bool CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary* pOCGDict) { 271 bool CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary* pOCGDict) {
272 if (!pOCGDict) 272 if (!pOCGDict)
273 return true; 273 return true;
274 274
275 CFX_ByteString csType = pOCGDict->GetStringBy("Type", "OCG"); 275 CFX_ByteString csType = pOCGDict->GetStringFor("Type", "OCG");
276 if (csType == "OCG") 276 if (csType == "OCG")
277 return GetOCGVisible(pOCGDict); 277 return GetOCGVisible(pOCGDict);
278 return LoadOCMDState(pOCGDict); 278 return LoadOCMDState(pOCGDict);
279 } 279 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_numbertree.cpp ('k') | core/fpdfdoc/cpdf_pagelabel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698