| 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 "core/include/fpdfdoc/fpdf_doc.h" | 7 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 8 | 8 |
| 9 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, | 9 static int32_t FPDFDOC_OCG_FindGroup(const CPDF_Object* pObject, |
| 10 const CPDF_Dictionary* pGroupDict) { | 10 const CPDF_Dictionary* pGroupDict) { |
| 11 if (!pObject || !pGroupDict) | 11 if (!pObject || !pGroupDict) |
| 12 return -1; | 12 return -1; |
| 13 | 13 |
| 14 if (const CPDF_Array* pArray = pObject->AsArray()) { | 14 if (const CPDF_Array* pArray = pObject->AsArray()) { |
| 15 FX_DWORD dwCount = pArray->GetCount(); | 15 FX_DWORD dwCount = pArray->GetCount(); |
| 16 for (FX_DWORD i = 0; i < dwCount; i++) { | 16 for (FX_DWORD i = 0; i < dwCount; i++) { |
| 17 if (pArray->GetDict(i) == pGroupDict) | 17 if (pArray->GetDictAt(i) == pGroupDict) |
| 18 return i; | 18 return i; |
| 19 } | 19 } |
| 20 return -1; | 20 return -1; |
| 21 } | 21 } |
| 22 return pObject->GetDict() == pGroupDict ? 0 : -1; | 22 return pObject->GetDict() == pGroupDict ? 0 : -1; |
| 23 } | 23 } |
| 24 static FX_BOOL FPDFDOC_OCG_HasIntent(const CPDF_Dictionary* pDict, | 24 static FX_BOOL FPDFDOC_OCG_HasIntent(const CPDF_Dictionary* pDict, |
| 25 const CFX_ByteStringC& csElement, | 25 const CFX_ByteStringC& csElement, |
| 26 const CFX_ByteStringC& csDef = "") { | 26 const CFX_ByteStringC& csDef = "") { |
| 27 CPDF_Object* pIntent = pDict->GetElementValue("Intent"); | 27 CPDF_Object* pIntent = pDict->GetElementValue("Intent"); |
| 28 if (!pIntent) { | 28 if (!pIntent) { |
| 29 return csElement == csDef; | 29 return csElement == csDef; |
| 30 } | 30 } |
| 31 CFX_ByteString bsIntent; | 31 CFX_ByteString bsIntent; |
| 32 if (CPDF_Array* pArray = pIntent->AsArray()) { | 32 if (CPDF_Array* pArray = pIntent->AsArray()) { |
| 33 FX_DWORD dwCount = pArray->GetCount(); | 33 FX_DWORD dwCount = pArray->GetCount(); |
| 34 for (FX_DWORD i = 0; i < dwCount; i++) { | 34 for (FX_DWORD i = 0; i < dwCount; i++) { |
| 35 bsIntent = pArray->GetString(i); | 35 bsIntent = pArray->GetStringAt(i); |
| 36 if (bsIntent == "All" || bsIntent == csElement) | 36 if (bsIntent == "All" || bsIntent == csElement) |
| 37 return TRUE; | 37 return TRUE; |
| 38 } | 38 } |
| 39 return FALSE; | 39 return FALSE; |
| 40 } | 40 } |
| 41 bsIntent = pIntent->GetString(); | 41 bsIntent = pIntent->GetString(); |
| 42 return bsIntent == "All" || bsIntent == csElement; | 42 return bsIntent == "All" || bsIntent == csElement; |
| 43 } | 43 } |
| 44 static CPDF_Dictionary* FPDFDOC_OCG_GetConfig(CPDF_Document* pDoc, | 44 static CPDF_Dictionary* FPDFDOC_OCG_GetConfig(CPDF_Document* pDoc, |
| 45 const CPDF_Dictionary* pOCGDict, | 45 const CPDF_Dictionary* pOCGDict, |
| 46 const CFX_ByteStringC& bsState) { | 46 const CFX_ByteStringC& bsState) { |
| 47 FXSYS_assert(pDoc && pOCGDict); | 47 FXSYS_assert(pDoc && pOCGDict); |
| 48 CPDF_Dictionary* pOCProperties = pDoc->GetRoot()->GetDict("OCProperties"); | 48 CPDF_Dictionary* pOCProperties = pDoc->GetRoot()->GetDictBy("OCProperties"); |
| 49 if (!pOCProperties) { | 49 if (!pOCProperties) { |
| 50 return NULL; | 50 return NULL; |
| 51 } | 51 } |
| 52 CPDF_Array* pOCGs = pOCProperties->GetArray("OCGs"); | 52 CPDF_Array* pOCGs = pOCProperties->GetArrayBy("OCGs"); |
| 53 if (!pOCGs) { | 53 if (!pOCGs) { |
| 54 return NULL; | 54 return NULL; |
| 55 } | 55 } |
| 56 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { | 56 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { |
| 57 return NULL; | 57 return NULL; |
| 58 } | 58 } |
| 59 CPDF_Dictionary* pConfig = pOCProperties->GetDict("D"); | 59 CPDF_Dictionary* pConfig = pOCProperties->GetDictBy("D"); |
| 60 CPDF_Array* pConfigs = pOCProperties->GetArray("Configs"); | 60 CPDF_Array* pConfigs = pOCProperties->GetArrayBy("Configs"); |
| 61 if (pConfigs) { | 61 if (pConfigs) { |
| 62 CPDF_Dictionary* pFind; | 62 CPDF_Dictionary* pFind; |
| 63 int32_t iCount = pConfigs->GetCount(); | 63 int32_t iCount = pConfigs->GetCount(); |
| 64 for (int32_t i = 0; i < iCount; i++) { | 64 for (int32_t i = 0; i < iCount; i++) { |
| 65 pFind = pConfigs->GetDict(i); | 65 pFind = pConfigs->GetDictAt(i); |
| 66 if (!pFind) { | 66 if (!pFind) { |
| 67 continue; | 67 continue; |
| 68 } | 68 } |
| 69 if (!FPDFDOC_OCG_HasIntent(pFind, "View", "View")) { | 69 if (!FPDFDOC_OCG_HasIntent(pFind, "View", "View")) { |
| 70 continue; | 70 continue; |
| 71 } | 71 } |
| 72 pConfig = pFind; | 72 pConfig = pFind; |
| 73 break; | 73 break; |
| 74 } | 74 } |
| 75 } | 75 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 97 } | 97 } |
| 98 FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, | 98 FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, |
| 99 const CPDF_Dictionary* pOCGDict, | 99 const CPDF_Dictionary* pOCGDict, |
| 100 FX_BOOL& bValidConfig) const { | 100 FX_BOOL& bValidConfig) const { |
| 101 CPDF_Dictionary* pConfig = | 101 CPDF_Dictionary* pConfig = |
| 102 FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict, csConfig); | 102 FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict, csConfig); |
| 103 if (!pConfig) { | 103 if (!pConfig) { |
| 104 return TRUE; | 104 return TRUE; |
| 105 } | 105 } |
| 106 bValidConfig = TRUE; | 106 bValidConfig = TRUE; |
| 107 FX_BOOL bState = pConfig->GetString("BaseState", "ON") != "OFF"; | 107 FX_BOOL bState = pConfig->GetStringBy("BaseState", "ON") != "OFF"; |
| 108 CPDF_Array* pArray = pConfig->GetArray("ON"); | 108 CPDF_Array* pArray = pConfig->GetArrayBy("ON"); |
| 109 if (pArray) { | 109 if (pArray) { |
| 110 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { | 110 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { |
| 111 bState = TRUE; | 111 bState = TRUE; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 pArray = pConfig->GetArray("OFF"); | 114 pArray = pConfig->GetArrayBy("OFF"); |
| 115 if (pArray) { | 115 if (pArray) { |
| 116 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { | 116 if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) { |
| 117 bState = FALSE; | 117 bState = FALSE; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 pArray = pConfig->GetArray("AS"); | 120 pArray = pConfig->GetArrayBy("AS"); |
| 121 if (pArray) { | 121 if (pArray) { |
| 122 CFX_ByteString csFind = csConfig + "State"; | 122 CFX_ByteString csFind = csConfig + "State"; |
| 123 int32_t iCount = pArray->GetCount(); | 123 int32_t iCount = pArray->GetCount(); |
| 124 for (int32_t i = 0; i < iCount; i++) { | 124 for (int32_t i = 0; i < iCount; i++) { |
| 125 CPDF_Dictionary* pUsage = pArray->GetDict(i); | 125 CPDF_Dictionary* pUsage = pArray->GetDictAt(i); |
| 126 if (!pUsage) { | 126 if (!pUsage) { |
| 127 continue; | 127 continue; |
| 128 } | 128 } |
| 129 if (pUsage->GetString("Event", "View") != csConfig) { | 129 if (pUsage->GetStringBy("Event", "View") != csConfig) { |
| 130 continue; | 130 continue; |
| 131 } | 131 } |
| 132 CPDF_Array* pOCGs = pUsage->GetArray("OCGs"); | 132 CPDF_Array* pOCGs = pUsage->GetArrayBy("OCGs"); |
| 133 if (!pOCGs) { | 133 if (!pOCGs) { |
| 134 continue; | 134 continue; |
| 135 } | 135 } |
| 136 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { | 136 if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) { |
| 137 continue; | 137 continue; |
| 138 } | 138 } |
| 139 CPDF_Dictionary* pState = pUsage->GetDict(csConfig); | 139 CPDF_Dictionary* pState = pUsage->GetDictBy(csConfig); |
| 140 if (!pState) { | 140 if (!pState) { |
| 141 continue; | 141 continue; |
| 142 } | 142 } |
| 143 bState = pState->GetString(csFind) != "OFF"; | 143 bState = pState->GetStringBy(csFind) != "OFF"; |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 return bState; | 146 return bState; |
| 147 } | 147 } |
| 148 FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const { | 148 FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const { |
| 149 if (!FPDFDOC_OCG_HasIntent(pOCGDict, "View", "View")) { | 149 if (!FPDFDOC_OCG_HasIntent(pOCGDict, "View", "View")) { |
| 150 return TRUE; | 150 return TRUE; |
| 151 } | 151 } |
| 152 CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType); | 152 CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType); |
| 153 CPDF_Dictionary* pUsage = pOCGDict->GetDict("Usage"); | 153 CPDF_Dictionary* pUsage = pOCGDict->GetDictBy("Usage"); |
| 154 if (pUsage) { | 154 if (pUsage) { |
| 155 CPDF_Dictionary* pState = pUsage->GetDict(csState); | 155 CPDF_Dictionary* pState = pUsage->GetDictBy(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->GetString(csFind) != "OFF"; | 159 return pState->GetStringBy(csFind) != "OFF"; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 if (csState != "View") { | 162 if (csState != "View") { |
| 163 pState = pUsage->GetDict("View"); | 163 pState = pUsage->GetDictBy("View"); |
| 164 if (pState && pState->KeyExist("ViewState")) { | 164 if (pState && pState->KeyExist("ViewState")) { |
| 165 return pState->GetString("ViewState") != "OFF"; | 165 return pState->GetStringBy("ViewState") != "OFF"; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 FX_BOOL bDefValid = FALSE; | 169 FX_BOOL bDefValid = FALSE; |
| 170 return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid); | 170 return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid); |
| 171 } | 171 } |
| 172 | 172 |
| 173 FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) { | 173 FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) { |
| 174 if (!pOCGDict) | 174 if (!pOCGDict) |
| 175 return FALSE; | 175 return FALSE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 FX_BOOL bFromConfig, | 187 FX_BOOL bFromConfig, |
| 188 int nLevel) { | 188 int nLevel) { |
| 189 if (nLevel > 32) { | 189 if (nLevel > 32) { |
| 190 return FALSE; | 190 return FALSE; |
| 191 } | 191 } |
| 192 if (!pExpression) { | 192 if (!pExpression) { |
| 193 return FALSE; | 193 return FALSE; |
| 194 } | 194 } |
| 195 int32_t iCount = pExpression->GetCount(); | 195 int32_t iCount = pExpression->GetCount(); |
| 196 CPDF_Object* pOCGObj; | 196 CPDF_Object* pOCGObj; |
| 197 CFX_ByteString csOperator = pExpression->GetString(0); | 197 CFX_ByteString csOperator = pExpression->GetStringAt(0); |
| 198 if (csOperator == "Not") { | 198 if (csOperator == "Not") { |
| 199 pOCGObj = pExpression->GetElementValue(1); | 199 pOCGObj = pExpression->GetElementValue(1); |
| 200 if (!pOCGObj) | 200 if (!pOCGObj) |
| 201 return FALSE; | 201 return FALSE; |
| 202 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) | 202 if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) |
| 203 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); | 203 return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict)); |
| 204 if (CPDF_Array* pArray = pOCGObj->AsArray()) | 204 if (CPDF_Array* pArray = pOCGObj->AsArray()) |
| 205 return !GetOCGVE(pArray, bFromConfig, nLevel + 1); | 205 return !GetOCGVE(pArray, bFromConfig, nLevel + 1); |
| 206 return FALSE; | 206 return FALSE; |
| 207 } | 207 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 bValue = bValue && bItem; | 227 bValue = bValue && bItem; |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 return bValue; | 231 return bValue; |
| 232 } | 232 } |
| 233 return FALSE; | 233 return FALSE; |
| 234 } | 234 } |
| 235 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict, | 235 FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict, |
| 236 FX_BOOL bFromConfig) { | 236 FX_BOOL bFromConfig) { |
| 237 CPDF_Array* pVE = pOCMDDict->GetArray("VE"); | 237 CPDF_Array* pVE = pOCMDDict->GetArrayBy("VE"); |
| 238 if (pVE) { | 238 if (pVE) { |
| 239 return GetOCGVE(pVE, bFromConfig); | 239 return GetOCGVE(pVE, bFromConfig); |
| 240 } | 240 } |
| 241 CFX_ByteString csP = pOCMDDict->GetString("P", "AnyOn"); | 241 CFX_ByteString csP = pOCMDDict->GetStringBy("P", "AnyOn"); |
| 242 CPDF_Object* pOCGObj = pOCMDDict->GetElementValue("OCGs"); | 242 CPDF_Object* pOCGObj = pOCMDDict->GetElementValue("OCGs"); |
| 243 if (!pOCGObj) | 243 if (!pOCGObj) |
| 244 return TRUE; | 244 return TRUE; |
| 245 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) | 245 if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) |
| 246 return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); | 246 return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict); |
| 247 | 247 |
| 248 CPDF_Array* pArray = pOCGObj->AsArray(); | 248 CPDF_Array* pArray = pOCGObj->AsArray(); |
| 249 if (!pArray) | 249 if (!pArray) |
| 250 return TRUE; | 250 return TRUE; |
| 251 | 251 |
| 252 FX_BOOL bState = FALSE; | 252 FX_BOOL bState = FALSE; |
| 253 if (csP == "AllOn" || csP == "AllOff") { | 253 if (csP == "AllOn" || csP == "AllOff") { |
| 254 bState = TRUE; | 254 bState = TRUE; |
| 255 } | 255 } |
| 256 int32_t iCount = pArray->GetCount(); | 256 int32_t iCount = pArray->GetCount(); |
| 257 for (int32_t i = 0; i < iCount; i++) { | 257 for (int32_t i = 0; i < iCount; i++) { |
| 258 FX_BOOL bItem = TRUE; | 258 FX_BOOL bItem = TRUE; |
| 259 CPDF_Dictionary* pItemDict = pArray->GetDict(i); | 259 CPDF_Dictionary* pItemDict = pArray->GetDictAt(i); |
| 260 if (pItemDict) | 260 if (pItemDict) |
| 261 bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemDict); | 261 bItem = bFromConfig ? LoadOCGState(pItemDict) : 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 FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary* pOCGDict) { | 270 FX_BOOL CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary* pOCGDict) { |
| 271 if (!pOCGDict) { | 271 if (!pOCGDict) { |
| 272 return TRUE; | 272 return TRUE; |
| 273 } | 273 } |
| 274 CFX_ByteString csType = pOCGDict->GetString("Type", "OCG"); | 274 CFX_ByteString csType = pOCGDict->GetStringBy("Type", "OCG"); |
| 275 if (csType == "OCG") { | 275 if (csType == "OCG") { |
| 276 return GetOCGVisible(pOCGDict); | 276 return GetOCGVisible(pOCGDict); |
| 277 } | 277 } |
| 278 return LoadOCMDState(pOCGDict, FALSE); | 278 return LoadOCMDState(pOCGDict, FALSE); |
| 279 } | 279 } |
| 280 void CPDF_OCContext::ResetOCContext() { | 280 void CPDF_OCContext::ResetOCContext() { |
| 281 m_OCGStates.clear(); | 281 m_OCGStates.clear(); |
| 282 } | 282 } |
| OLD | NEW |