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

Side by Side Diff: core/src/fpdfdoc/doc_ocg.cpp

Issue 1194933003: Make CPDF_Object::GetString() a virtual method. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 5 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
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object *pObject, const CPDF_Dict ionary *pGroupDict) 8 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object *pObject, const CPDF_Dict ionary *pGroupDict)
9 { 9 {
10 if (pObject == NULL || pGroupDict == NULL) { 10 if (pObject == NULL || pGroupDict == NULL) {
(...skipping 18 matching lines...) Expand all
29 { 29 {
30 FXSYS_assert(pDict != NULL); 30 FXSYS_assert(pDict != NULL);
31 CPDF_Object *pIntent = pDict->GetElementValue(FX_BSTRC("Intent")); 31 CPDF_Object *pIntent = pDict->GetElementValue(FX_BSTRC("Intent"));
32 if (pIntent == NULL) { 32 if (pIntent == NULL) {
33 return csElement == csDef; 33 return csElement == csDef;
34 } 34 }
35 CFX_ByteString bsIntent; 35 CFX_ByteString bsIntent;
36 if (pIntent->GetType() == PDFOBJ_ARRAY) { 36 if (pIntent->GetType() == PDFOBJ_ARRAY) {
37 FX_DWORD dwCount = ((CPDF_Array*)pIntent)->GetCount(); 37 FX_DWORD dwCount = ((CPDF_Array*)pIntent)->GetCount();
38 for (FX_DWORD i = 0; i < dwCount; i++) { 38 for (FX_DWORD i = 0; i < dwCount; i++) {
39 bsIntent = ((CPDF_Array*)pIntent)->GetString(i); 39 bsIntent = ((CPDF_Array*)pIntent)->GetStringAt(i);
40 if (bsIntent == FX_BSTRC("All") || bsIntent == csElement) { 40 if (bsIntent == FX_BSTRC("All") || bsIntent == csElement) {
41 return TRUE; 41 return TRUE;
42 } 42 }
43 } 43 }
44 return FALSE; 44 return FALSE;
45 } 45 }
46 bsIntent = pIntent->GetString(); 46 bsIntent = pIntent->GetString();
47 return bsIntent == FX_BSTRC("All") || bsIntent == csElement; 47 return bsIntent == FX_BSTRC("All") || bsIntent == csElement;
48 } 48 }
49 static CPDF_Dictionary* FPDFDOC_OCG_GetConfig(CPDF_Document *pDoc, const CPDF_Di ctionary *pOCGDict, const CFX_ByteStringC& bsState) 49 static CPDF_Dictionary* FPDFDOC_OCG_GetConfig(CPDF_Document *pDoc, const CPDF_Di ctionary *pOCGDict, const CFX_ByteStringC& bsState)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 { 101 {
102 m_OCGStates.clear(); 102 m_OCGStates.clear();
103 } 103 }
104 FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, const CPDF_Dictionary *pOCGDict, FX_BOOL &bValidConfig) const 104 FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, const CPDF_Dictionary *pOCGDict, FX_BOOL &bValidConfig) const
105 { 105 {
106 CPDF_Dictionary *pConfig = FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict, csCo nfig); 106 CPDF_Dictionary *pConfig = FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict, csCo nfig);
107 if (!pConfig) { 107 if (!pConfig) {
108 return TRUE; 108 return TRUE;
109 } 109 }
110 bValidConfig = TRUE; 110 bValidConfig = TRUE;
111 FX_BOOL bState = pConfig->GetString(FX_BSTRC("BaseState"), FX_BSTRC("ON")) ! = FX_BSTRC("OFF"); 111 FX_BOOL bState = pConfig->GetStringAt("BaseState", "ON") != "OFF";
112 CPDF_Array *pArray = pConfig->GetArray(FX_BSTRC("ON")); 112 CPDF_Array *pArray = pConfig->GetArray(FX_BSTRC("ON"));
113 if (pArray) { 113 if (pArray) {
114 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { 114 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) {
115 bState = TRUE; 115 bState = TRUE;
116 } 116 }
117 } 117 }
118 pArray = pConfig->GetArray(FX_BSTRC("OFF")); 118 pArray = pConfig->GetArray(FX_BSTRC("OFF"));
119 if (pArray) { 119 if (pArray) {
120 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { 120 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) {
121 bState = FALSE; 121 bState = FALSE;
122 } 122 }
123 } 123 }
124 pArray = pConfig->GetArray(FX_BSTRC("AS")); 124 pArray = pConfig->GetArray(FX_BSTRC("AS"));
125 if (pArray) { 125 if (pArray) {
126 CFX_ByteString csFind = csConfig + FX_BSTRC("State"); 126 CFX_ByteString csFind = csConfig + FX_BSTRC("State");
127 int32_t iCount = pArray->GetCount(); 127 int32_t iCount = pArray->GetCount();
128 for (int32_t i = 0; i < iCount; i ++) { 128 for (int32_t i = 0; i < iCount; i ++) {
129 CPDF_Dictionary *pUsage = pArray->GetDict(i); 129 CPDF_Dictionary *pUsage = pArray->GetDict(i);
130 if (!pUsage) { 130 if (!pUsage) {
131 continue; 131 continue;
132 } 132 }
133 if (pUsage->GetString(FX_BSTRC("Event"), FX_BSTRC("View")) != csConf ig) { 133 if (pUsage->GetStringAt("Event", "View") != csConfig) {
134 continue; 134 continue;
135 } 135 }
136 CPDF_Array *pOCGs = pUsage->GetArray(FX_BSTRC("OCGs")); 136 CPDF_Array *pOCGs = pUsage->GetArray(FX_BSTRC("OCGs"));
137 if (!pOCGs) { 137 if (!pOCGs) {
138 continue; 138 continue;
139 } 139 }
140 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { 140 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) {
141 continue; 141 continue;
142 } 142 }
143 CPDF_Dictionary *pState = pUsage->GetDict(csConfig); 143 CPDF_Dictionary *pState = pUsage->GetDict(csConfig);
144 if (!pState) { 144 if (!pState) {
145 continue; 145 continue;
146 } 146 }
147 bState = pState->GetString(csFind) != FX_BSTRC("OFF"); 147 bState = pState->GetStringAt(csFind) != "OFF";
148 } 148 }
149 } 149 }
150 return bState; 150 return bState;
151 } 151 }
152 FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary *pOCGDict) const 152 FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary *pOCGDict) const
153 { 153 {
154 if (!FPDFDOC_OCG_HasIntent(pOCGDict, FX_BSTRC("View"), FX_BSTRC("View"))) { 154 if (!FPDFDOC_OCG_HasIntent(pOCGDict, FX_BSTRC("View"), FX_BSTRC("View"))) {
155 return TRUE; 155 return TRUE;
156 } 156 }
157 CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType); 157 CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType);
158 CPDF_Dictionary *pUsage = pOCGDict->GetDict(FX_BSTRC("Usage")); 158 CPDF_Dictionary *pUsage = pOCGDict->GetDict(FX_BSTRC("Usage"));
159 if (pUsage) { 159 if (pUsage) {
160 CPDF_Dictionary *pState = pUsage->GetDict(csState); 160 CPDF_Dictionary *pState = pUsage->GetDict(csState);
161 if (pState) { 161 if (pState) {
162 CFX_ByteString csFind = csState + FX_BSTRC("State"); 162 CFX_ByteString csFind = csState + FX_BSTRC("State");
163 if (pState->KeyExist(csFind)) { 163 if (pState->KeyExist(csFind)) {
164 return pState->GetString(csFind) != FX_BSTRC("OFF"); 164 return pState->GetStringAt(csFind) != "OFF";
165 } 165 }
166 } 166 }
167 if (csState != FX_BSTRC("View")) { 167 if (csState != FX_BSTRC("View")) {
168 pState = pUsage->GetDict(FX_BSTRC("View")); 168 pState = pUsage->GetDict(FX_BSTRC("View"));
169 if (pState && pState->KeyExist(FX_BSTRC("ViewState"))) { 169 if (pState && pState->KeyExist(FX_BSTRC("ViewState"))) {
170 return pState->GetString(FX_BSTRC("ViewState")) != FX_BSTRC("OFF "); 170 return pState->GetStringAt("ViewState") != "OFF";
171 } 171 }
172 } 172 }
173 } 173 }
174 FX_BOOL bDefValid = FALSE; 174 FX_BOOL bDefValid = FALSE;
175 return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid); 175 return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid);
176 } 176 }
177 177
178 FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) 178 FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict)
179 { 179 {
180 if (!pOCGDict) 180 if (!pOCGDict)
(...skipping 11 matching lines...) Expand all
192 FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, i nt nLevel) 192 FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, i nt nLevel)
193 { 193 {
194 if (nLevel > 32) { 194 if (nLevel > 32) {
195 return FALSE; 195 return FALSE;
196 } 196 }
197 if (pExpression == NULL) { 197 if (pExpression == NULL) {
198 return FALSE; 198 return FALSE;
199 } 199 }
200 int32_t iCount = pExpression->GetCount(); 200 int32_t iCount = pExpression->GetCount();
201 CPDF_Object *pOCGObj; 201 CPDF_Object *pOCGObj;
202 CFX_ByteString csOperator = pExpression->GetString(0); 202 CFX_ByteString csOperator = pExpression->GetStringAt(0);
203 if (csOperator == FX_BSTRC("Not")) { 203 if (csOperator == FX_BSTRC("Not")) {
204 pOCGObj = pExpression->GetElementValue(1); 204 pOCGObj = pExpression->GetElementValue(1);
205 if (pOCGObj == NULL) { 205 if (pOCGObj == NULL) {
206 return FALSE; 206 return FALSE;
207 } 207 }
208 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { 208 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
209 return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : Get OCGVisible((CPDF_Dictionary*)pOCGObj)); 209 return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : Get OCGVisible((CPDF_Dictionary*)pOCGObj));
210 } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { 210 } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
211 return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); 211 return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
212 } else { 212 } else {
(...skipping 27 matching lines...) Expand all
240 } 240 }
241 return FALSE; 241 return FALSE;
242 } 242 }
243 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary *pOCMDDict, FX_BOOL bFromConfig) 243 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary *pOCMDDict, FX_BOOL bFromConfig)
244 { 244 {
245 FXSYS_assert(pOCMDDict != NULL); 245 FXSYS_assert(pOCMDDict != NULL);
246 CPDF_Array *pVE = pOCMDDict->GetArray(FX_BSTRC("VE")); 246 CPDF_Array *pVE = pOCMDDict->GetArray(FX_BSTRC("VE"));
247 if (pVE != NULL) { 247 if (pVE != NULL) {
248 return GetOCGVE(pVE, bFromConfig); 248 return GetOCGVE(pVE, bFromConfig);
249 } 249 }
250 CFX_ByteString csP = pOCMDDict->GetString(FX_BSTRC("P"), FX_BSTRC("AnyOn")); 250 CFX_ByteString csP = pOCMDDict->GetStringAt("P", "AnyOn");
251 CPDF_Object *pOCGObj = pOCMDDict->GetElementValue(FX_BSTRC("OCGs")); 251 CPDF_Object *pOCGObj = pOCMDDict->GetElementValue(FX_BSTRC("OCGs"));
252 if (pOCGObj == NULL) { 252 if (pOCGObj == NULL) {
253 return TRUE; 253 return TRUE;
254 } 254 }
255 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { 255 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
256 return bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : GetOCGVis ible((CPDF_Dictionary*)pOCGObj); 256 return bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : GetOCGVis ible((CPDF_Dictionary*)pOCGObj);
257 } 257 }
258 if (pOCGObj->GetType() != PDFOBJ_ARRAY) { 258 if (pOCGObj->GetType() != PDFOBJ_ARRAY) {
259 return TRUE; 259 return TRUE;
260 } 260 }
(...skipping 21 matching lines...) Expand all
282 return FALSE; 282 return FALSE;
283 } 283 }
284 } 284 }
285 return bState; 285 return bState;
286 } 286 }
287 FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary *pOCGDict) 287 FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary *pOCGDict)
288 { 288 {
289 if (pOCGDict == NULL) { 289 if (pOCGDict == NULL) {
290 return TRUE; 290 return TRUE;
291 } 291 }
292 CFX_ByteString csType = pOCGDict->GetString(FX_BSTRC("Type"), FX_BSTRC("OCG" )); 292 CFX_ByteString csType = pOCGDict->GetStringAt("Type", "OCG");
293 if (csType == FX_BSTRC("OCG")) { 293 if (csType == FX_BSTRC("OCG")) {
294 return GetOCGVisible(pOCGDict); 294 return GetOCGVisible(pOCGDict);
295 } else { 295 } else {
296 return LoadOCMDState(pOCGDict, FALSE); 296 return LoadOCMDState(pOCGDict, FALSE);
297 } 297 }
298 } 298 }
299 void CPDF_OCContext::ResetOCContext() 299 void CPDF_OCContext::ResetOCContext()
300 { 300 {
301 m_OCGStates.clear(); 301 m_OCGStates.clear();
302 } 302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698