OLD | NEW |
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 FX_INT32 FPDFDOC_OCG_FindGroup(const CPDF_Object *pObject, const CPDF_Dic
tionary *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) { |
11 return -1; | 11 return -1; |
12 } | 12 } |
13 FX_INT32 iType = pObject->GetType(); | 13 int32_t iType = pObject->GetType(); |
14 if (iType == PDFOBJ_ARRAY) { | 14 if (iType == PDFOBJ_ARRAY) { |
15 FX_DWORD dwCount = ((CPDF_Array*)pObject)->GetCount(); | 15 FX_DWORD dwCount = ((CPDF_Array*)pObject)->GetCount(); |
16 for (FX_DWORD i = 0; i < dwCount; i++) { | 16 for (FX_DWORD i = 0; i < dwCount; i++) { |
17 if (((CPDF_Array*)pObject)->GetDict(i) == pGroupDict) { | 17 if (((CPDF_Array*)pObject)->GetDict(i) == pGroupDict) { |
18 return i; | 18 return i; |
19 } | 19 } |
20 } | 20 } |
21 return -1; | 21 return -1; |
22 } | 22 } |
23 if (pObject->GetDict() == pGroupDict) { | 23 if (pObject->GetDict() == pGroupDict) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 if (!pOCGs) { | 57 if (!pOCGs) { |
58 return NULL; | 58 return NULL; |
59 } | 59 } |
60 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { | 60 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { |
61 return NULL; | 61 return NULL; |
62 } | 62 } |
63 CPDF_Dictionary *pConfig = pOCProperties->GetDict(FX_BSTRC("D")); | 63 CPDF_Dictionary *pConfig = pOCProperties->GetDict(FX_BSTRC("D")); |
64 CPDF_Array *pConfigs = pOCProperties->GetArray(FX_BSTRC("Configs")); | 64 CPDF_Array *pConfigs = pOCProperties->GetArray(FX_BSTRC("Configs")); |
65 if (pConfigs) { | 65 if (pConfigs) { |
66 CPDF_Dictionary *pFind; | 66 CPDF_Dictionary *pFind; |
67 FX_INT32 iCount = pConfigs->GetCount(); | 67 int32_t iCount = pConfigs->GetCount(); |
68 for (FX_INT32 i = 0; i < iCount; i ++) { | 68 for (int32_t i = 0; i < iCount; i ++) { |
69 pFind = pConfigs->GetDict(i); | 69 pFind = pConfigs->GetDict(i); |
70 if (!pFind) { | 70 if (!pFind) { |
71 continue; | 71 continue; |
72 } | 72 } |
73 if (!FPDFDOC_OCG_HasIntent(pFind, FX_BSTRC("View"), FX_BSTRC("View")
)) { | 73 if (!FPDFDOC_OCG_HasIntent(pFind, FX_BSTRC("View"), FX_BSTRC("View")
)) { |
74 continue; | 74 continue; |
75 } | 75 } |
76 pConfig = pFind; | 76 pConfig = pFind; |
77 break; | 77 break; |
78 } | 78 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 FX_INT32 iCount = pArray->GetCount(); | 127 int32_t iCount = pArray->GetCount(); |
128 for (FX_INT32 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->GetString(FX_BSTRC("Event"), FX_BSTRC("View")) != csConf
ig) { |
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; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary *pOCGDict) | 177 FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary *pOCGDict) |
178 { | 178 { |
179 if (!pOCGDict) { | 179 if (!pOCGDict) { |
180 return FALSE; | 180 return FALSE; |
181 } | 181 } |
182 FX_LPVOID bState = NULL; | 182 FX_LPVOID bState = NULL; |
183 if (m_OCGStates.Lookup(pOCGDict, bState)) { | 183 if (m_OCGStates.Lookup(pOCGDict, bState)) { |
184 return (FX_UINTPTR)bState != 0; | 184 return (uintptr_t)bState != 0; |
185 } | 185 } |
186 bState = (FX_LPVOID)(FX_UINTPTR)LoadOCGState(pOCGDict); | 186 bState = (FX_LPVOID)(uintptr_t)LoadOCGState(pOCGDict); |
187 m_OCGStates.SetAt(pOCGDict, bState); | 187 m_OCGStates.SetAt(pOCGDict, bState); |
188 return (FX_UINTPTR)bState != 0; | 188 return (uintptr_t)bState != 0; |
189 } | 189 } |
190 FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, i
nt nLevel) | 190 FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, i
nt nLevel) |
191 { | 191 { |
192 if (nLevel > 32) { | 192 if (nLevel > 32) { |
193 return FALSE; | 193 return FALSE; |
194 } | 194 } |
195 if (pExpression == NULL) { | 195 if (pExpression == NULL) { |
196 return FALSE; | 196 return FALSE; |
197 } | 197 } |
198 FX_INT32 iCount = pExpression->GetCount(); | 198 int32_t iCount = pExpression->GetCount(); |
199 CPDF_Object *pOCGObj; | 199 CPDF_Object *pOCGObj; |
200 CFX_ByteString csOperator = pExpression->GetString(0); | 200 CFX_ByteString csOperator = pExpression->GetString(0); |
201 if (csOperator == FX_BSTRC("Not")) { | 201 if (csOperator == FX_BSTRC("Not")) { |
202 pOCGObj = pExpression->GetElementValue(1); | 202 pOCGObj = pExpression->GetElementValue(1); |
203 if (pOCGObj == NULL) { | 203 if (pOCGObj == NULL) { |
204 return FALSE; | 204 return FALSE; |
205 } | 205 } |
206 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { | 206 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { |
207 return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : Get
OCGVisible((CPDF_Dictionary*)pOCGObj)); | 207 return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : Get
OCGVisible((CPDF_Dictionary*)pOCGObj)); |
208 } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { | 208 } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { |
209 return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); | 209 return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); |
210 } else { | 210 } else { |
211 return FALSE; | 211 return FALSE; |
212 } | 212 } |
213 } | 213 } |
214 if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) { | 214 if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) { |
215 FX_BOOL bValue = FALSE; | 215 FX_BOOL bValue = FALSE; |
216 for (FX_INT32 i = 1; i < iCount; i ++) { | 216 for (int32_t i = 1; i < iCount; i ++) { |
217 pOCGObj = pExpression->GetElementValue(1); | 217 pOCGObj = pExpression->GetElementValue(1); |
218 if (pOCGObj == NULL) { | 218 if (pOCGObj == NULL) { |
219 continue; | 219 continue; |
220 } | 220 } |
221 FX_BOOL bItem = FALSE; | 221 FX_BOOL bItem = FALSE; |
222 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { | 222 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { |
223 bItem = bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) :
GetOCGVisible((CPDF_Dictionary*)pOCGObj); | 223 bItem = bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) :
GetOCGVisible((CPDF_Dictionary*)pOCGObj); |
224 } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { | 224 } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) { |
225 bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); | 225 bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1); |
226 } | 226 } |
(...skipping 26 matching lines...) Expand all Loading... |
253 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { | 253 if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) { |
254 return bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : GetOCGVis
ible((CPDF_Dictionary*)pOCGObj); | 254 return bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj) : GetOCGVis
ible((CPDF_Dictionary*)pOCGObj); |
255 } | 255 } |
256 if (pOCGObj->GetType() != PDFOBJ_ARRAY) { | 256 if (pOCGObj->GetType() != PDFOBJ_ARRAY) { |
257 return TRUE; | 257 return TRUE; |
258 } | 258 } |
259 FX_BOOL bState = FALSE; | 259 FX_BOOL bState = FALSE; |
260 if (csP == FX_BSTRC("AllOn") || csP == FX_BSTRC("AllOff")) { | 260 if (csP == FX_BSTRC("AllOn") || csP == FX_BSTRC("AllOff")) { |
261 bState = TRUE; | 261 bState = TRUE; |
262 } | 262 } |
263 FX_INT32 iCount = ((CPDF_Array*)pOCGObj)->GetCount(); | 263 int32_t iCount = ((CPDF_Array*)pOCGObj)->GetCount(); |
264 for (FX_INT32 i = 0; i < iCount; i ++) { | 264 for (int32_t i = 0; i < iCount; i ++) { |
265 FX_BOOL bItem = TRUE; | 265 FX_BOOL bItem = TRUE; |
266 CPDF_Dictionary* pItemDict = ((CPDF_Array*)pOCGObj)->GetDict(i); | 266 CPDF_Dictionary* pItemDict = ((CPDF_Array*)pOCGObj)->GetDict(i); |
267 if (pItemDict) { | 267 if (pItemDict) { |
268 bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemD
ict); | 268 bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemD
ict); |
269 } | 269 } |
270 if (csP == FX_BSTRC("AnyOn") && bItem) { | 270 if (csP == FX_BSTRC("AnyOn") && bItem) { |
271 return TRUE; | 271 return TRUE; |
272 } | 272 } |
273 if (csP == FX_BSTRC("AnyOff") && !bItem) { | 273 if (csP == FX_BSTRC("AnyOff") && !bItem) { |
274 return TRUE; | 274 return TRUE; |
(...skipping 16 matching lines...) Expand all Loading... |
291 if (csType == FX_BSTRC("OCG")) { | 291 if (csType == FX_BSTRC("OCG")) { |
292 return GetOCGVisible(pOCGDict); | 292 return GetOCGVisible(pOCGDict); |
293 } else { | 293 } else { |
294 return LoadOCMDState(pOCGDict, FALSE); | 294 return LoadOCMDState(pOCGDict, FALSE); |
295 } | 295 } |
296 } | 296 } |
297 void CPDF_OCContext::ResetOCContext() | 297 void CPDF_OCContext::ResetOCContext() |
298 { | 298 { |
299 m_OCGStates.RemoveAll(); | 299 m_OCGStates.RemoveAll(); |
300 } | 300 } |
OLD | NEW |