CFX_WideString	FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec)
{
    CFX_WideString wsFileName;
    if (pFileSpec->GetType() == PDFOBJ_DICTIONARY) {
        CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFileSpec;
        wsFileName = pDict->GetUnicodeText(FX_BSTRC("UF"));
        if (wsFileName.IsEmpty()) {
            wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F")));
        }
        if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) {
            return wsFileName;
        }
        if (wsFileName.IsEmpty() && pDict->KeyExist(FX_BSTRC("DOS"))) {
            wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS")));
        }
    } else {
        wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString());
    }
    if (wsFileName[0] != '/') {
        return ChangeSlash(wsFileName);
    }
    if (wsFileName[2] == '/') {
        CFX_WideString result;
        result += wsFileName[1];
        result += ':';
        result += ChangeSlash(((FX_LPCWSTR)wsFileName) + 2);
        return result;
    } else {
        CFX_WideString result;
        result += '\\';
        result += ChangeSlash(wsFileName);
        return result;
    }
}
Example #2
0
FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString &csFileName) const
{
    if (m_pObj == NULL) {
        return FALSE;
    }
    if (m_pObj->GetType() == PDFOBJ_DICTIONARY) {
        CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj;
        csFileName = pDict->GetUnicodeText(FX_BSTRC("UF"));
        if (csFileName.IsEmpty()) {
            csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F")));
        }
        if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) {
            return TRUE;
        }
        if (csFileName.IsEmpty()) {
            if (pDict->KeyExist(FX_BSTRC("DOS"))) {
                csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS")));
            } else if (pDict->KeyExist(FX_BSTRC("Mac"))) {
                csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Mac")));
            } else if (pDict->KeyExist(FX_BSTRC("Unix"))) {
                csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("Unix")));
            } else {
                return FALSE;
            }
        }
    } else {
        csFileName = CFX_WideString::FromLocal(m_pObj->GetString());
    }
    csFileName = FILESPEC_DecodeFileName(csFileName);
    return TRUE;
}
Example #3
0
FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary *pOCGDict) const
{
    if (!FPDFDOC_OCG_HasIntent(pOCGDict, FX_BSTRC("View"), FX_BSTRC("View"))) {
        return TRUE;
    }
    CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType);
    CPDF_Dictionary *pUsage = pOCGDict->GetDict(FX_BSTRC("Usage"));
    if (pUsage) {
        CPDF_Dictionary *pState = pUsage->GetDict(csState);
        if (pState) {
            CFX_ByteString csFind = csState + FX_BSTRC("State");
            if (pState->KeyExist(csFind)) {
                return pState->GetString(csFind) != FX_BSTRC("OFF");
            }
        }
        if (csState != FX_BSTRC("View")) {
            pState = pUsage->GetDict(FX_BSTRC("View"));
            if (pState && pState->KeyExist(FX_BSTRC("ViewState"))) {
                return pState->GetString(FX_BSTRC("ViewState")) != FX_BSTRC("OFF");
            }
        }
    }
    FX_BOOL bDefValid = FALSE;
    return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid);
}
Example #4
0
FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig,
                                               const CPDF_Dictionary* pOCGDict,
                                               FX_BOOL& bValidConfig) const {
  CPDF_Dictionary* pConfig =
      FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict, csConfig);
  if (!pConfig) {
    return TRUE;
  }
  bValidConfig = TRUE;
  FX_BOOL bState = pConfig->GetString(FX_BSTRC("BaseState"), FX_BSTRC("ON")) !=
                   FX_BSTRC("OFF");
  CPDF_Array* pArray = pConfig->GetArray(FX_BSTRC("ON"));
  if (pArray) {
    if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) {
      bState = TRUE;
    }
  }
  pArray = pConfig->GetArray(FX_BSTRC("OFF"));
  if (pArray) {
    if (FPDFDOC_OCG_FindGroup(pArray, pOCGDict) >= 0) {
      bState = FALSE;
    }
  }
  pArray = pConfig->GetArray(FX_BSTRC("AS"));
  if (pArray) {
    CFX_ByteString csFind = csConfig + FX_BSTRC("State");
    int32_t iCount = pArray->GetCount();
    for (int32_t i = 0; i < iCount; i++) {
      CPDF_Dictionary* pUsage = pArray->GetDict(i);
      if (!pUsage) {
        continue;
      }
      if (pUsage->GetString(FX_BSTRC("Event"), FX_BSTRC("View")) != csConfig) {
        continue;
      }
      CPDF_Array* pOCGs = pUsage->GetArray(FX_BSTRC("OCGs"));
      if (!pOCGs) {
        continue;
      }
      if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) {
        continue;
      }
      CPDF_Dictionary* pState = pUsage->GetDict(csConfig);
      if (!pState) {
        continue;
      }
      bState = pState->GetString(csFind) != FX_BSTRC("OFF");
    }
  }
  return bState;
}
Example #5
0
CPDF_Object* CPDF_StructElementImpl::GetAttr(FX_BSTR owner, FX_BSTR name, FX_BOOL bInheritable, FX_FLOAT fLevel)
{
    if (fLevel > nMaxRecursion) {
        return NULL;
    }
    if (bInheritable) {
        CPDF_Object* pAttr = GetAttr(owner, name, FALSE);
        if (pAttr) {
            return pAttr;
        }
        if (m_pParent == NULL) {
            return NULL;
        }
        return m_pParent->GetAttr(owner, name, TRUE, fLevel + 1);
    }
    CPDF_Object* pA = m_pDict->GetElementValue(FX_BSTRC("A"));
    if (pA) {
        CPDF_Dictionary* pAttrDict = FindAttrDict(pA, owner);
        if (pAttrDict) {
            CPDF_Object* pAttr = pAttrDict->GetElementValue(name);
            if (pAttr) {
                return pAttr;
            }
        }
    }
    CPDF_Object* pC = m_pDict->GetElementValue(FX_BSTRC("C"));
    if (pC == NULL) {
        return NULL;
    }
    CPDF_Dictionary* pClassMap = m_pTree->m_pTreeRoot->GetDict(FX_BSTRC("ClassMap"));
    if (pClassMap == NULL) {
        return NULL;
    }
    if (pC->GetType() == PDFOBJ_ARRAY) {
        CPDF_Array* pArray = (CPDF_Array*)pC;
        for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {
            CFX_ByteString class_name = pArray->GetString(i);
            CPDF_Dictionary* pClassDict = pClassMap->GetDict(class_name);
            if (pClassDict && pClassDict->GetString(FX_BSTRC("O")) == owner) {
                return pClassDict->GetElementValue(name);
            }
        }
        return NULL;
    }
    CFX_ByteString class_name = pC->GetString();
    CPDF_Dictionary* pClassDict = pClassMap->GetDict(class_name);
    if (pClassDict && pClassDict->GetString(FX_BSTRC("O")) == owner) {
        return pClassDict->GetElementValue(name);
    }
    return NULL;
}
Example #6
0
FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
                                       CPDF_Document* pSrcPDFDoc) {
  if (!pDestPDFDoc || !pSrcPDFDoc)
    return FALSE;

  CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot();
  if (!pNewRoot)
    return FALSE;

  // Set the document information////////////////////////////////////////////

  CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo();
  if (!DInfoDict)
    return FALSE;

  CFX_ByteString producerstr;
  producerstr.Format("PDFium");
  DInfoDict->SetAt("Producer", new CPDF_String(producerstr));

  // Set type////////////////////////////////////////////////////////////////
  CFX_ByteString cbRootType = pNewRoot->GetString("Type", "");
  if (cbRootType.Equal("")) {
    pNewRoot->SetAt("Type", new CPDF_Name("Catalog"));
  }

  CPDF_Object* pElement = pNewRoot->GetElement("Pages");
  CPDF_Dictionary* pNewPages =
      pElement ? ToDictionary(pElement->GetDirect()) : nullptr;
  if (!pNewPages) {
    pNewPages = new CPDF_Dictionary;
    FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
    pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON));
  }

  CFX_ByteString cbPageType = pNewPages->GetString("Type", "");
  if (cbPageType.Equal("")) {
    pNewPages->SetAt("Type", new CPDF_Name("Pages"));
  }

  CPDF_Array* pKeysArray = pNewPages->GetArray("Kids");
  if (!pKeysArray) {
    CPDF_Array* pNewKids = new CPDF_Array;
    FX_DWORD Kidsobjnum = -1;
    Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids);

    pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum));
    pNewPages->SetAt("Count", new CPDF_Number(0));
  }

  return TRUE;
}
Example #7
0
int	CPDFSDK_Annot::GetBorderStyle() const
{
	ASSERT(m_pAnnot != NULL);
	ASSERT(m_pAnnot->m_pAnnotDict != NULL);

	CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");
	if (pBSDict)
	{
		CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
		if (sBorderStyle == "S") return BBS_SOLID;
		if (sBorderStyle == "D") return BBS_DASH;
		if (sBorderStyle == "B") return BBS_BEVELED;
		if (sBorderStyle == "I") return BBS_INSET;
		if (sBorderStyle == "U") return BBS_UNDERLINE;
	}

	CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");
	if (pBorder)
	{
		if (pBorder->GetCount() >= 4) 
		{ 
			CPDF_Array *pDP = pBorder->GetArray(3);
			if (pDP && pDP->GetCount() > 0)
				return BBS_DASH;
		}
	}

	return BBS_SOLID;
}
Example #8
0
CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict,
                            CPDF_Document* pDocument,
                            FX_DWORD index,
                            CFX_ByteString& csNameTag) {
  if (!pFormDict) {
    return NULL;
  }
  CPDF_Dictionary* pDR = pFormDict->GetDict("DR");
  if (!pDR) {
    return NULL;
  }
  CPDF_Dictionary* pFonts = pDR->GetDict("Font");
  if (!pFonts) {
    return NULL;
  }
  FX_DWORD dwCount = 0;
  for (const auto& it : *pFonts) {
    const CFX_ByteString& csKey = it.first;
    CPDF_Object* pObj = it.second;
    if (!pObj) {
      continue;
    }
    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
    if (!pElement)
      continue;
    if (pElement->GetString("Type") != "Font")
      continue;
    if (dwCount == index) {
      csNameTag = csKey;
      return pDocument->LoadFont(pElement);
    }
    dwCount++;
  }
  return NULL;
}
Example #9
0
FX_DWORD CPDF_ActionFields::GetFieldsCount() const {
  if (!m_pAction) {
    return 0;
  }
  CPDF_Dictionary* pDict = m_pAction->GetDict();
  if (!pDict) {
    return 0;
  }
  CFX_ByteString csType = pDict->GetString("S");
  CPDF_Object* pFields = NULL;
  if (csType == "Hide") {
    pFields = pDict->GetElementValue("T");
  } else {
    pFields = pDict->GetArray("Fields");
  }
  if (!pFields)
    return 0;
  if (pFields->IsDictionary())
    return 1;
  if (pFields->IsString())
    return 1;
  if (CPDF_Array* pArray = pFields->AsArray())
    return pArray->GetCount();
  return 0;
}
Example #10
0
FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict,
                          const CPDF_Font* pFont,
                          CFX_ByteString& csNameTag) {
  if (!pFormDict || !pFont) {
    return FALSE;
  }
  CPDF_Dictionary* pDR = pFormDict->GetDict("DR");
  if (!pDR) {
    return FALSE;
  }
  CPDF_Dictionary* pFonts = pDR->GetDict("Font");
  if (!pFonts) {
    return FALSE;
  }
  for (const auto& it : *pFonts) {
    const CFX_ByteString& csKey = it.first;
    CPDF_Object* pObj = it.second;
    if (!pObj) {
      continue;
    }
    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
    if (!pElement)
      continue;
    if (pElement->GetString("Type") != "Font") {
      continue;
    }
    if (pFont->GetFontDict() == pElement) {
      csNameTag = csKey;
      return TRUE;
    }
  }
  return FALSE;
}
Example #11
0
CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const {
  if (!m_pAction) {
    return NULL;
  }
  CPDF_Dictionary* pDict = m_pAction->GetDict();
  if (!pDict) {
    return NULL;
  }
  CFX_ByteString csType = pDict->GetString("S");
  CPDF_Object* pFields = NULL;
  if (csType == "Hide") {
    pFields = pDict->GetElementValue("T");
  } else {
    pFields = pDict->GetArray("Fields");
  }
  if (!pFields) {
    return NULL;
  }
  CPDF_Object* pFindObj = NULL;
  if (pFields->IsDictionary() || pFields->IsString()) {
    if (iIndex == 0)
      pFindObj = pFields;
  } else if (CPDF_Array* pArray = pFields->AsArray()) {
    pFindObj = pArray->GetElementValue(iIndex);
  }
  return pFindObj;
}
Example #12
0
std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const {
  std::vector<CPDF_Object*> fields;
  if (!m_pAction)
    return fields;

  CPDF_Dictionary* pDict = m_pAction->GetDict();
  if (!pDict)
    return fields;

  CFX_ByteString csType = pDict->GetString("S");
  CPDF_Object* pFields;
  if (csType == "Hide")
    pFields = pDict->GetElementValue("T");
  else
    pFields = pDict->GetArray("Fields");
  if (!pFields)
    return fields;

  if (pFields->IsDictionary() || pFields->IsString()) {
    fields.push_back(pFields);
  } else if (CPDF_Array* pArray = pFields->AsArray()) {
    FX_DWORD iCount = pArray->GetCount();
    for (FX_DWORD i = 0; i < iCount; ++i) {
      CPDF_Object* pObj = pArray->GetElementValue(i);
      if (pObj) {
        fields.push_back(pObj);
      }
    }
  }
  return fields;
}
Example #13
0
static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, FX_BSTR owner, FX_FLOAT nLevel = 0.0F)
{
    if (nLevel > nMaxRecursion) {
        return NULL;
    }
    if (pAttrs == NULL) {
        return NULL;
    }
    CPDF_Dictionary* pDict = NULL;
    if (pAttrs->GetType() == PDFOBJ_DICTIONARY) {
        pDict = (CPDF_Dictionary*)pAttrs;
    } else if (pAttrs->GetType() == PDFOBJ_STREAM) {
        pDict = ((CPDF_Stream*)pAttrs)->GetDict();
    } else if (pAttrs->GetType() == PDFOBJ_ARRAY) {
        CPDF_Array* pArray = (CPDF_Array*)pAttrs;
        for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {
            CPDF_Object* pElement = pArray->GetElementValue(i);
            pDict = FindAttrDict(pElement, owner, nLevel + 1);
            if (pDict) {
                return pDict;
            }
        }
    }
    if (pDict && pDict->GetString(FX_BSTRC("O")) == owner) {
        return pDict;
    }
    return NULL;
}
Example #14
0
FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF,
                                      FX_BOOL bNotify) {
  if (pFDF == NULL) {
    return FALSE;
  }
  CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
  if (pMainDict == NULL) {
    return FALSE;
  }
  CPDF_Array* pFields = pMainDict->GetArray("Fields");
  if (pFields == NULL) {
    return FALSE;
  }
  m_bsEncoding = pMainDict->GetString(FX_BSTRC("Encoding"));
  if (bNotify && m_pFormNotify != NULL) {
    int iRet = m_pFormNotify->BeforeFormImportData(this);
    if (iRet < 0) {
      return FALSE;
    }
  }
  for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
    CPDF_Dictionary* pField = pFields->GetDict(i);
    if (pField == NULL) {
      continue;
    }
    FDF_ImportField(pField, L"", bNotify);
  }
  if (bNotify && m_pFormNotify != NULL) {
    m_pFormNotify->AfterFormImportData(this);
  }
  return TRUE;
}
Example #15
0
CPDF_FormField* CPDF_InterForm::CheckRequiredFields(
    const std::vector<CPDF_FormField*>* fields,
    bool bIncludeOrExclude) const {
  int nCount = m_pFieldTree->m_Root.CountFields();
  for (int i = 0; i < nCount; ++i) {
    CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
    if (!pField)
      continue;

    int32_t iType = pField->GetType();
    if (iType == CPDF_FormField::PushButton ||
        iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) {
      continue;
    }
    FX_DWORD dwFlags = pField->GetFieldFlags();
    // TODO(thestig): Look up these magic numbers and add constants for them.
    if (dwFlags & 0x04)
      continue;

    bool bFind = true;
    if (fields) {
      auto it = std::find(fields->begin(), fields->end(), pField);
      bFind = (it != fields->end());
    }
    if (bIncludeOrExclude == bFind) {
      CPDF_Dictionary* pFieldDict = pField->m_pDict;
      if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) {
        return pField;
      }
    }
  }
  return nullptr;
}
Example #16
0
void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot)
{
    CFX_ByteString cbSubType = pPDFAnnot->GetSubType();
    if(cbSubType.Compare("3D") == 0)
    {
        FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT);
    }
    else if(cbSubType.Compare("Screen") ==0)
    {
        CPDF_Dictionary* pAnnotDict = pPDFAnnot->m_pAnnotDict;
        CFX_ByteString cbString;
        if(pAnnotDict->KeyExist("IT"))
            cbString = pAnnotDict->GetString("IT");
        if(cbString.Compare("Img") != 0)
            FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA);
    }
    else if(cbSubType.Compare("Movie") ==0)
    {
        FPDF_UnSupportError(FPDF_UNSP_ANNOT_MOVIE);
    }
    else if(cbSubType.Compare("Sound") ==0)
    {
        FPDF_UnSupportError(FPDF_UNSP_ANNOT_SOUND);
    }
    else if(cbSubType.Compare("RichMedia") ==0)
    {
        FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA);
    }
    else if(cbSubType.Compare("FileAttachment") ==0)
    {
        FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT);
    }
    else if(cbSubType.Compare("Widget") ==0)
    {
        CPDF_Dictionary* pAnnotDict = pPDFAnnot->m_pAnnotDict;
        CFX_ByteString cbString;
        if(pAnnotDict->KeyExist("FT"))
        {
            cbString = pAnnotDict->GetString("FT");
        }
        if(cbString.Compare("Sig") == 0)
        {
            FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG);
        }
    }

}
Example #17
0
void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum, CPDF_Object* pKidObj, CPDF_StructKid* pKid)
{
    pKid->m_Type = CPDF_StructKid::Invalid;
    if (pKidObj == NULL) {
        return;
    }
    if (pKidObj->GetType() == PDFOBJ_NUMBER) {
        if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) {
            return;
        }
        pKid->m_Type = CPDF_StructKid::PageContent;
        pKid->m_PageContent.m_ContentId = pKidObj->GetInteger();
        pKid->m_PageContent.m_PageObjNum = PageObjNum;
        return;
    }
    if (pKidObj->GetType() != PDFOBJ_DICTIONARY) {
        return;
    }
    CPDF_Dictionary* pKidDict = (CPDF_Dictionary*)pKidObj;
    CPDF_Object* pPageObj = pKidDict->GetElement(FX_BSTRC("Pg"));
    if (pPageObj && pPageObj->GetType() == PDFOBJ_REFERENCE) {
        PageObjNum = ((CPDF_Reference*)pPageObj)->GetRefObjNum();
    }
    CFX_ByteString type = pKidDict->GetString(FX_BSTRC("Type"));
    if (type == FX_BSTRC("MCR")) {
        if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) {
            return;
        }
        pKid->m_Type = CPDF_StructKid::StreamContent;
        CPDF_Object* pStreamObj = pKidDict->GetElement(FX_BSTRC("Stm"));
        if (pStreamObj && pStreamObj->GetType() == PDFOBJ_REFERENCE) {
            pKid->m_StreamContent.m_RefObjNum = ((CPDF_Reference*)pStreamObj)->GetRefObjNum();
        } else {
            pKid->m_StreamContent.m_RefObjNum = 0;
        }
        pKid->m_StreamContent.m_PageObjNum = PageObjNum;
        pKid->m_StreamContent.m_ContentId = pKidDict->GetInteger(FX_BSTRC("MCID"));
    } else if (type == FX_BSTRC("OBJR")) {
        if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) {
            return;
        }
        pKid->m_Type = CPDF_StructKid::Object;
        CPDF_Object* pObj = pKidDict->GetElement(FX_BSTRC("Obj"));
        if (pObj && pObj->GetType() == PDFOBJ_REFERENCE) {
            pKid->m_Object.m_RefObjNum = ((CPDF_Reference*)pObj)->GetRefObjNum();
        } else {
            pKid->m_Object.m_RefObjNum = 0;
        }
        pKid->m_Object.m_PageObjNum = PageObjNum;
    } else {
        pKid->m_Type = CPDF_StructKid::Element;
        pKid->m_Element.m_pDict = pKidDict;
        if (m_pTree->m_pPage == NULL) {
            pKid->m_Element.m_pElement = FX_NEW CPDF_StructElementImpl(m_pTree, this, pKidDict);
        } else {
            pKid->m_Element.m_pElement = NULL;
        }
    }
}
FX_BOOL CPDF_ViewerPreferences::PrintScaling() const {
  CPDF_Dictionary* pDict = m_pDoc->GetRoot();
  pDict = pDict->GetDict(FX_BSTRC("ViewerPreferences"));
  if (!pDict) {
    return TRUE;
  }
  return FX_BSTRC("None") != pDict->GetString(FX_BSTRC("PrintScaling"));
}
CFX_ByteString CPDF_ViewerPreferences::Duplex() const {
  CPDF_Dictionary* pDict = m_pDoc->GetRoot();
  pDict = pDict->GetDict(FX_BSTRC("ViewerPreferences"));
  if (!pDict) {
    return FX_BSTRC("None");
  }
  return pDict->GetString(FX_BSTRC("Duplex"));
}
FX_BOOL CPDF_ViewerPreferences::IsDirectionR2L() const {
  CPDF_Dictionary* pDict = m_pDoc->GetRoot();
  pDict = pDict->GetDict(FX_BSTRC("ViewerPreferences"));
  if (!pDict) {
    return FALSE;
  }
  return FX_BSTRC("R2L") == pDict->GetString(FX_BSTRC("Direction"));
}
Example #21
0
void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage,
                                  std::vector<CPDF_Dictionary*>* pList) {
  CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots");
  if (!pAnnotList)
    return;

  for (FX_DWORD i = 0; i < pAnnotList->GetCount(); ++i) {
    CPDF_Dictionary* pAnnot = pAnnotList->GetDict(i);
    bool add_link = (pAnnot && pAnnot->GetString("Subtype") == "Link");
    // Add non-links as nullptrs to preserve z-order.
    pList->push_back(add_link ? pAnnot : nullptr);
  }
}
Example #22
0
static int InsertDeletePDFPage(CPDF_Document* pDoc,
                               CPDF_Dictionary* pPages,
                               int nPagesToGo,
                               CPDF_Dictionary* pPage,
                               FX_BOOL bInsert,
                               CFX_ArrayTemplate<CPDF_Dictionary*>& stackList) {
  CPDF_Array* pKidList = pPages->GetArray("Kids");
  if (!pKidList) {
    return -1;
  }
  int nKids = pKidList->GetCount();
  for (int i = 0; i < nKids; i++) {
    CPDF_Dictionary* pKid = pKidList->GetDict(i);
    if (pKid->GetString("Type") == "Page") {
      if (nPagesToGo == 0) {
        if (bInsert) {
          pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum()));
          pPage->SetAtReference("Parent", pDoc, pPages->GetObjNum());
        } else {
          pKidList->RemoveAt(i);
        }
        pPages->SetAtInteger("Count",
                             pPages->GetInteger("Count") + (bInsert ? 1 : -1));
        return 1;
      }
      nPagesToGo--;
    } else {
      int nPages = pKid->GetInteger("Count");
      if (nPagesToGo < nPages) {
        int stackCount = stackList.GetSize();
        for (int j = 0; j < stackCount; ++j) {
          if (pKid == stackList[j]) {
            return -1;
          }
        }
        stackList.Add(pKid);
        if (InsertDeletePDFPage(pDoc, pKid, nPagesToGo, pPage, bInsert,
                                stackList) < 0) {
          return -1;
        }
        stackList.RemoveAt(stackCount);
        pPages->SetAtInteger("Count",
                             pPages->GetInteger("Count") + (bInsert ? 1 : -1));
        return 1;
      }
      nPagesToGo -= nPages;
    }
  }
  return 0;
}
static FX_BOOL _LoadCryptInfo(CPDF_Dictionary* pEncryptDict,
                              const CFX_ByteStringC& name,
                              int& cipher,
                              int& keylen) {
  int Version = pEncryptDict->GetInteger(FX_BSTRC("V"));
  cipher = FXCIPHER_RC4;
  keylen = 0;
  if (Version >= 4) {
    CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDict(FX_BSTRC("CF"));
    if (pCryptFilters == NULL) {
      return FALSE;
    }
    if (name == FX_BSTRC("Identity")) {
      cipher = FXCIPHER_NONE;
    } else {
      CPDF_Dictionary* pDefFilter = pCryptFilters->GetDict(name);
      if (pDefFilter == NULL) {
        return FALSE;
      }
      int nKeyBits = 0;
      if (Version == 4) {
        nKeyBits = pDefFilter->GetInteger(FX_BSTRC("Length"), 0);
        if (nKeyBits == 0) {
          nKeyBits = pEncryptDict->GetInteger(FX_BSTRC("Length"), 128);
        }
      } else {
        nKeyBits = pEncryptDict->GetInteger(FX_BSTRC("Length"), 256);
      }
      if (nKeyBits < 40) {
        nKeyBits *= 8;
      }
      keylen = nKeyBits / 8;
      CFX_ByteString cipher_name = pDefFilter->GetString(FX_BSTRC("CFM"));
      if (cipher_name == FX_BSTRC("AESV2") ||
          cipher_name == FX_BSTRC("AESV3")) {
        cipher = FXCIPHER_AES;
      }
    }
  } else {
    keylen =
        Version > 1 ? pEncryptDict->GetInteger(FX_BSTRC("Length"), 40) / 8 : 5;
  }
  if (keylen > 32 || keylen < 0) {
    return FALSE;
  }
  return TRUE;
}
FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csFontName, CPDF_Font*& pFont, CFX_ByteString& csNameTag)
{
    if (pFormDict == NULL) {
        return FALSE;
    }
    CPDF_Dictionary* pDR = pFormDict->GetDict("DR");
    if (pDR == NULL) {
        return FALSE;
    }
    CPDF_Dictionary* pFonts = pDR->GetDict("Font");
    if (pFonts == NULL) {
        return FALSE;
    }
    if (csFontName.GetLength() > 0) {
        csFontName.Remove(' ');
    }
    FX_POSITION pos = pFonts->GetStartPos();
    while (pos) {
        CPDF_Object* pObj = NULL;
        CFX_ByteString csKey, csTmp;
        pObj = pFonts->GetNextElement(pos, csKey);
        if (pObj == NULL) {
            continue;
        }
        CPDF_Object* pDirect = pObj->GetDirect();
        if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) {
            continue;
        }
        CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
        if (pElement->GetString("Type") != "Font") {
            continue;
        }
        pFont = pDocument->LoadFont(pElement);
        if (pFont == NULL) {
            continue;
        }
        CFX_ByteString csBaseFont;
        csBaseFont = pFont->GetBaseFont();
        csBaseFont.Remove(' ');
        if (csBaseFont == csFontName) {
            csNameTag = csKey;
            return TRUE;
        }
    }
    return FALSE;
}
void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList)
{
    CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots");
    if (pAnnotList == NULL) {
        return;
    }
    for (FX_DWORD i = 0; i < pAnnotList->GetCount(); i ++) {
        CPDF_Dictionary* pAnnot = pAnnotList->GetDict(i);
        if (pAnnot == NULL) {
            continue;
        }
        if (pAnnot->GetString("Subtype") != "Link") {
            continue;
        }
        pList->Add(pAnnot);
    }
}
Example #26
0
FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict,
                          CPDF_Document* pDocument,
                          CFX_ByteString csFontName,
                          CPDF_Font*& pFont,
                          CFX_ByteString& csNameTag) {
  if (!pFormDict) {
    return FALSE;
  }
  CPDF_Dictionary* pDR = pFormDict->GetDict("DR");
  if (!pDR) {
    return FALSE;
  }
  CPDF_Dictionary* pFonts = pDR->GetDict("Font");
  if (!pFonts) {
    return FALSE;
  }
  if (csFontName.GetLength() > 0) {
    csFontName.Remove(' ');
  }
  for (const auto& it : *pFonts) {
    const CFX_ByteString& csKey = it.first;
    CPDF_Object* pObj = it.second;
    if (!pObj) {
      continue;
    }
    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
    if (!pElement)
      continue;
    if (pElement->GetString("Type") != "Font") {
      continue;
    }
    pFont = pDocument->LoadFont(pElement);
    if (!pFont) {
      continue;
    }
    CFX_ByteString csBaseFont;
    csBaseFont = pFont->GetBaseFont();
    csBaseFont.Remove(' ');
    if (csBaseFont == csFontName) {
      csNameTag = csKey;
      return TRUE;
    }
  }
  return FALSE;
}
Example #27
0
CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
  CFX_ByteString csURI;
  if (!m_pDict) {
    return csURI;
  }
  if (m_pDict->GetString("S") != "URI") {
    return csURI;
  }
  csURI = m_pDict->GetString("URI");
  CPDF_Dictionary* pRoot = pDoc->GetRoot();
  CPDF_Dictionary* pURI = pRoot->GetDict("URI");
  if (pURI) {
    if (csURI.Find(":", 0) < 1) {
      csURI = pURI->GetString("Base") + csURI;
    }
  }
  return csURI;
}
Example #28
0
void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
  ASSERT(pPage != NULL);
  CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
  if (pPageDict == NULL) {
    return;
  }
  CPDF_Array* pAnnots = pPageDict->GetArray(FX_BSTRC("Annots"));
  if (pAnnots == NULL) {
    return;
  }
  int iAnnotCount = pAnnots->GetCount();
  for (int i = 0; i < iAnnotCount; i++) {
    CPDF_Dictionary* pAnnot = pAnnots->GetDict(i);
    if (pAnnot != NULL && pAnnot->GetString(FX_BSTRC("Subtype")) == "Widget") {
      LoadField(pAnnot);
    }
  }
}
CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, FX_BYTE charSet, CFX_ByteString& csNameTag)
{
    if (pFormDict == NULL) {
        return NULL;
    }
    CPDF_Dictionary* pDR = pFormDict->GetDict("DR");
    if (pDR == NULL) {
        return NULL;
    }
    CPDF_Dictionary* pFonts = pDR->GetDict("Font");
    if (pFonts == NULL) {
        return NULL;
    }
    FX_POSITION pos = pFonts->GetStartPos();
    while (pos) {
        CPDF_Object* pObj = NULL;
        CFX_ByteString csKey;
        pObj = pFonts->GetNextElement(pos, csKey);
        if (pObj == NULL) {
            continue;
        }
        CPDF_Object* pDirect = pObj->GetDirect();
        if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) {
            continue;
        }
        CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
        if (pElement->GetString("Type") != "Font") {
            continue;
        }
        CPDF_Font* pFind = pDocument->LoadFont(pElement);
        if (pFind == NULL) {
            continue;
        }
        CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont();
        if (pSubst == NULL) {
            continue;
        }
        if (pSubst->m_Charset == (int)charSet) {
            csNameTag = csKey;
            return pFind;
        }
    }
    return NULL;
}
Example #30
0
CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict,
                                               CFX_ByteString& sFontAlias,
                                               int32_t nCharset) {
  if (!pResDict)
    return NULL;

  CPDF_Document* pDocument = GetDocument();
  ASSERT(pDocument != NULL);

  CPDF_Dictionary* pFonts = pResDict->GetDict("Font");
  if (pFonts == NULL)
    return NULL;

  CPDF_Font* pFind = NULL;

  FX_POSITION pos = pFonts->GetStartPos();
  while (pos) {
    CPDF_Object* pObj = NULL;
    CFX_ByteString csKey;
    pObj = pFonts->GetNextElement(pos, csKey);
    if (pObj == NULL)
      continue;

    CPDF_Object* pDirect = pObj->GetDirect();
    if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY)
      continue;

    CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
    if (pElement->GetString("Type") != "Font")
      continue;

    CPDF_Font* pFont = pDocument->LoadFont(pElement);
    if (pFont == NULL)
      continue;
    const CFX_SubstFont* pSubst = pFont->GetSubstFont();
    if (pSubst == NULL)
      continue;
    if (pSubst->m_Charset == nCharset) {
      sFontAlias = csKey;
      pFind = pFont;
    }
  }
  return pFind;
}