Example #1
0
FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict,
                                      FX_BOOL bFromConfig) {
  CPDF_Array* pVE = pOCMDDict->GetArrayBy("VE");
  if (pVE) {
    return GetOCGVE(pVE, bFromConfig);
  }
  CFX_ByteString csP = pOCMDDict->GetStringBy("P", "AnyOn");
  CPDF_Object* pOCGObj = pOCMDDict->GetElementValue("OCGs");
  if (!pOCGObj)
    return TRUE;
  if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
    return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);

  CPDF_Array* pArray = pOCGObj->AsArray();
  if (!pArray)
    return TRUE;

  FX_BOOL bState = FALSE;
  if (csP == "AllOn" || csP == "AllOff") {
    bState = TRUE;
  }
  int32_t iCount = pArray->GetCount();
  for (int32_t i = 0; i < iCount; i++) {
    FX_BOOL bItem = TRUE;
    CPDF_Dictionary* pItemDict = pArray->GetDictAt(i);
    if (pItemDict)
      bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemDict);

    if ((csP == "AnyOn" && bItem) || (csP == "AnyOff" && !bItem))
      return TRUE;
    if ((csP == "AllOn" && !bItem) || (csP == "AllOff" && bItem))
      return FALSE;
  }
  return bState;
}
Example #2
0
FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression,
                                 FX_BOOL bFromConfig,
                                 int nLevel) {
  if (nLevel > 32) {
    return FALSE;
  }
  if (pExpression == NULL) {
    return FALSE;
  }
  int32_t iCount = pExpression->GetCount();
  CPDF_Object* pOCGObj;
  CFX_ByteString csOperator = pExpression->GetString(0);
  if (csOperator == FX_BSTRC("Not")) {
    pOCGObj = pExpression->GetElementValue(1);
    if (pOCGObj == NULL) {
      return FALSE;
    }
    if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
      return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj)
                           : GetOCGVisible((CPDF_Dictionary*)pOCGObj));
    }
    if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
      return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
    }
    return FALSE;
  }
  if (csOperator == FX_BSTRC("Or") || csOperator == FX_BSTRC("And")) {
    FX_BOOL bValue = FALSE;
    for (int32_t i = 1; i < iCount; i++) {
      pOCGObj = pExpression->GetElementValue(1);
      if (pOCGObj == NULL) {
        continue;
      }
      FX_BOOL bItem = FALSE;
      if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
        bItem = bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj)
                            : GetOCGVisible((CPDF_Dictionary*)pOCGObj);
      } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
        bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
      }
      if (i == 1) {
        bValue = bItem;
      } else {
        if (csOperator == FX_BSTRC("Or")) {
          bValue = bValue || bItem;
        } else {
          bValue = bValue && bItem;
        }
      }
    }
    return bValue;
  }
  return FALSE;
}
Example #3
0
FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression,
                                 FX_BOOL bFromConfig,
                                 int nLevel) {
  if (nLevel > 32) {
    return FALSE;
  }
  if (!pExpression) {
    return FALSE;
  }
  int32_t iCount = pExpression->GetCount();
  CPDF_Object* pOCGObj;
  CFX_ByteString csOperator = pExpression->GetStringAt(0);
  if (csOperator == "Not") {
    pOCGObj = pExpression->GetElementValue(1);
    if (!pOCGObj)
      return FALSE;
    if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
      return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict));
    if (CPDF_Array* pArray = pOCGObj->AsArray())
      return !GetOCGVE(pArray, bFromConfig, nLevel + 1);
    return FALSE;
  }
  if (csOperator == "Or" || csOperator == "And") {
    FX_BOOL bValue = FALSE;
    for (int32_t i = 1; i < iCount; i++) {
      pOCGObj = pExpression->GetElementValue(1);
      if (!pOCGObj) {
        continue;
      }
      FX_BOOL bItem = FALSE;
      if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary())
        bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);
      else if (CPDF_Array* pArray = pOCGObj->AsArray())
        bItem = GetOCGVE(pArray, bFromConfig, nLevel + 1);

      if (i == 1) {
        bValue = bItem;
      } else {
        if (csOperator == "Or") {
          bValue = bValue || bItem;
        } else {
          bValue = bValue && bItem;
        }
      }
    }
    return bValue;
  }
  return FALSE;
}
Example #4
0
FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict,
                                      FX_BOOL bFromConfig) {
  FXSYS_assert(pOCMDDict != NULL);
  CPDF_Array* pVE = pOCMDDict->GetArray(FX_BSTRC("VE"));
  if (pVE != NULL) {
    return GetOCGVE(pVE, bFromConfig);
  }
  CFX_ByteString csP = pOCMDDict->GetString(FX_BSTRC("P"), FX_BSTRC("AnyOn"));
  CPDF_Object* pOCGObj = pOCMDDict->GetElementValue(FX_BSTRC("OCGs"));
  if (pOCGObj == NULL) {
    return TRUE;
  }
  if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
    return bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj)
                       : GetOCGVisible((CPDF_Dictionary*)pOCGObj);
  }
  if (pOCGObj->GetType() != PDFOBJ_ARRAY) {
    return TRUE;
  }
  FX_BOOL bState = FALSE;
  if (csP == FX_BSTRC("AllOn") || csP == FX_BSTRC("AllOff")) {
    bState = TRUE;
  }
  int32_t iCount = ((CPDF_Array*)pOCGObj)->GetCount();
  for (int32_t i = 0; i < iCount; i++) {
    FX_BOOL bItem = TRUE;
    CPDF_Dictionary* pItemDict = ((CPDF_Array*)pOCGObj)->GetDict(i);
    if (pItemDict) {
      bItem = bFromConfig ? LoadOCGState(pItemDict) : GetOCGVisible(pItemDict);
    }
    if (csP == FX_BSTRC("AnyOn") && bItem) {
      return TRUE;
    }
    if (csP == FX_BSTRC("AnyOff") && !bItem) {
      return TRUE;
    }
    if (csP == FX_BSTRC("AllOn") && !bItem) {
      return FALSE;
    }
    if (csP == FX_BSTRC("AllOff") && bItem) {
      return FALSE;
    }
  }
  return bState;
}
Example #5
0
FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) {
  if (!pOCGDict)
    return FALSE;

  const auto it = m_OCGStates.find(pOCGDict);
  if (it != m_OCGStates.end())
    return it->second;

  FX_BOOL bState = LoadOCGState(pOCGDict);
  m_OCGStates[pOCGDict] = bState;
  return bState;
}
Example #6
0
bool CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) const {
  if (!pOCGDict)
    return false;

  const auto it = m_OGCStateCache.find(pOCGDict);
  if (it != m_OGCStateCache.end())
    return it->second;

  bool bState = LoadOCGState(pOCGDict);
  m_OGCStateCache[pOCGDict] = bState;
  return bState;
}
Example #7
0
FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary *pOCGDict)
{
    if (!pOCGDict) {
        return FALSE;
    }
    FX_LPVOID bState = NULL;
    if (m_OCGStates.Lookup(pOCGDict, bState)) {
        return (FX_UINTPTR)bState != 0;
    }
    bState = (FX_LPVOID)(FX_UINTPTR)LoadOCGState(pOCGDict);
    m_OCGStates.SetAt(pOCGDict, bState);
    return (FX_UINTPTR)bState != 0;
}