CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, FX_DWORD size) { int32_t width; int32_t height; int32_t num_comps; int32_t bits; FX_BOOL color_trans; if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( pData, size, width, height, num_comps, bits, color_trans)) { return NULL; } CPDF_Dictionary* pDict = new CPDF_Dictionary; pDict->SetAtName("Type", "XObject"); pDict->SetAtName("Subtype", "Image"); pDict->SetAtInteger("Width", width); pDict->SetAtInteger("Height", height); const FX_CHAR* csname = NULL; if (num_comps == 1) { csname = "DeviceGray"; } else if (num_comps == 3) { csname = "DeviceRGB"; } else if (num_comps == 4) { csname = "DeviceCMYK"; CPDF_Array* pDecode = CPDF_Array::Create(); for (int n = 0; n < 4; n++) { pDecode->AddInteger(1); pDecode->AddInteger(0); } pDict->SetAt(FX_BSTRC("Decode"), pDecode); } pDict->SetAtName("ColorSpace", csname); pDict->SetAtInteger("BitsPerComponent", bits); pDict->SetAtName("Filter", "DCTDecode"); if (!color_trans) { CPDF_Dictionary* pParms = new CPDF_Dictionary; pDict->SetAt("DecodeParms", pParms); pParms->SetAtInteger("ColorTransform", 0); } m_bIsMask = FALSE; m_Width = width; m_Height = height; if (m_pStream == NULL) { m_pStream = new CPDF_Stream(NULL, 0, NULL); } return pDict; }
FX_ARGB CPDF_ApSettings::GetColor(int& iColorType, const CFX_ByteStringC& csEntry) { iColorType = COLORTYPE_TRANSPARENT; if (m_pDict == NULL) { return 0; } FX_ARGB color = 0; CPDF_Array* pEntry = m_pDict->GetArray(csEntry); if (pEntry == NULL) { return color; } FX_DWORD dwCount = pEntry->GetCount(); if (dwCount == 1) { iColorType = COLORTYPE_GRAY; FX_FLOAT g = pEntry->GetNumber(0) * 255; color = ArgbEncode(255, (int)g, (int)g, (int)g); } else if (dwCount == 3) { iColorType = COLORTYPE_RGB; FX_FLOAT r = pEntry->GetNumber(0) * 255; FX_FLOAT g = pEntry->GetNumber(1) * 255; FX_FLOAT b = pEntry->GetNumber(2) * 255; color = ArgbEncode(255, (int)r, (int)g, (int)b); } else if (dwCount == 4) { iColorType = COLORTYPE_CMYK; FX_FLOAT c = pEntry->GetNumber(0); FX_FLOAT m = pEntry->GetNumber(1); FX_FLOAT y = pEntry->GetNumber(2); FX_FLOAT k = pEntry->GetNumber(3); FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255)); } return color; }
void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { m_pPage = pPageDict; if (m_pTreeRoot == NULL) { return; } CPDF_Object* pKids = m_pTreeRoot->GetElementValue(FX_BSTRC("K")); if (pKids == NULL) { return; } FX_DWORD dwKids = 0; if (pKids->GetType() == PDFOBJ_DICTIONARY) { dwKids = 1; } else if (pKids->GetType() == PDFOBJ_ARRAY) { dwKids = ((CPDF_Array*)pKids)->GetCount(); } else { return; } FX_DWORD i; m_Kids.SetSize(dwKids); for (i = 0; i < dwKids; i ++) { m_Kids[i] = NULL; } CFX_MapPtrToPtr element_map; CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDict(FX_BSTRC("ParentTree")); if (pParentTree == NULL) { return; } CPDF_NumberTree parent_tree(pParentTree); int parents_id = pPageDict->GetInteger(FX_BSTRC("StructParents"), -1); if (parents_id >= 0) { CPDF_Object* pParents = parent_tree.LookupValue(parents_id); if (pParents == NULL || pParents->GetType() != PDFOBJ_ARRAY) { return; } CPDF_Array* pParentArray = (CPDF_Array*)pParents; for (i = 0; i < pParentArray->GetCount(); i ++) { CPDF_Dictionary* pParent = pParentArray->GetDict(i); if (pParent == NULL) { continue; } AddPageNode(pParent, element_map); } } }
FX_BOOL CPDF_Type3Font::Load() { m_pFontResources = m_pFontDict->GetDictBy("Resources"); CPDF_Array* pMatrix = m_pFontDict->GetArrayBy("FontMatrix"); FX_FLOAT xscale = 1.0f, yscale = 1.0f; if (pMatrix) { m_FontMatrix = pMatrix->GetMatrix(); xscale = m_FontMatrix.a; yscale = m_FontMatrix.d; } CPDF_Array* pBBox = m_pFontDict->GetArrayBy("FontBBox"); if (pBBox) { m_FontBBox.left = (int32_t)(pBBox->GetNumberAt(0) * xscale * 1000); m_FontBBox.bottom = (int32_t)(pBBox->GetNumberAt(1) * yscale * 1000); m_FontBBox.right = (int32_t)(pBBox->GetNumberAt(2) * xscale * 1000); m_FontBBox.top = (int32_t)(pBBox->GetNumberAt(3) * yscale * 1000); } int StartChar = m_pFontDict->GetIntegerBy("FirstChar"); CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths"); if (pWidthArray && (StartChar >= 0 && StartChar < 256)) { size_t count = pWidthArray->GetCount(); if (count > 256) count = 256; if (StartChar + count > 256) count = 256 - StartChar; for (size_t i = 0; i < count; i++) { m_CharWidthL[StartChar + i] = FXSYS_round(pWidthArray->GetNumberAt(i) * xscale * 1000); } } m_pCharProcs = m_pFontDict->GetDictBy("CharProcs"); CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectBy("Encoding"); if (pEncoding) { LoadPDFEncoding(pEncoding, m_BaseEncoding, &m_CharNames, FALSE, FALSE); if (!m_CharNames.empty()) { for (int i = 0; i < 256; i++) { m_Encoding.m_Unicodes[i] = PDF_UnicodeFromAdobeName(m_CharNames[i].c_str()); if (m_Encoding.m_Unicodes[i] == 0) { m_Encoding.m_Unicodes[i] = i; } } } } return TRUE; }
void CPDF_ApSettings::GetOriginalColor(int& iColorType, FX_FLOAT fc[4], const CFX_ByteStringC& csEntry) const { iColorType = COLORTYPE_TRANSPARENT; for (int i = 0; i < 4; i++) { fc[i] = 0; } if (!m_pDict) { return; } CPDF_Array* pEntry = m_pDict->GetArrayBy(csEntry); if (!pEntry) { return; } FX_DWORD dwCount = pEntry->GetCount(); if (dwCount == 1) { iColorType = COLORTYPE_GRAY; fc[0] = pEntry->GetNumberAt(0); } else if (dwCount == 3) { iColorType = COLORTYPE_RGB; fc[0] = pEntry->GetNumberAt(0); fc[1] = pEntry->GetNumberAt(1); fc[2] = pEntry->GetNumberAt(2); } else if (dwCount == 4) { iColorType = COLORTYPE_CMYK; fc[0] = pEntry->GetNumberAt(0); fc[1] = pEntry->GetNumberAt(1); fc[2] = pEntry->GetNumberAt(2); fc[3] = pEntry->GetNumberAt(3); } }
void PDF_ReplaceFull(CPDF_Object* pObj) { switch (pObj->GetType()) { case PDFOBJ_DICTIONARY: { CPDF_Dictionary* pDict = pObj->AsDictionary(); for (const auto& it : *pDict) { CFX_ByteString key = it.first; CPDF_Object* value = it.second; CFX_ByteStringC abbrName = PDF_FindAbbrName( PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); if (!abbrName.IsEmpty()) { pDict->ReplaceKey(key, abbrName); key = abbrName; } if (value->IsName()) { CFX_ByteString name = value->GetString(); abbrName = PDF_FindAbbrName(PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); if (!abbrName.IsEmpty()) { pDict->SetAtName(key, abbrName); } } else { PDF_ReplaceFull(value); } } break; } case PDFOBJ_ARRAY: { CPDF_Array* pArray = pObj->AsArray(); for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetElement(i); if (pElement->IsName()) { CFX_ByteString name = pElement->GetString(); CFX_ByteStringC abbrName = PDF_FindAbbrName( PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); if (!abbrName.IsEmpty()) { pArray->SetAt(i, new CPDF_Name(abbrName)); } } else { PDF_ReplaceFull(pElement); } } break; } } }
static CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, size_t nIndex, size_t& nCurIndex, CFX_ByteString& csName, CPDF_Array** ppFind, int nLevel = 0) { if (nLevel > nMaxRecursion) return nullptr; CPDF_Array* pNames = pNode->GetArrayBy("Names"); if (pNames) { size_t nCount = pNames->GetCount() / 2; if (nIndex >= nCurIndex + nCount) { nCurIndex += nCount; return nullptr; } if (ppFind) *ppFind = pNames; csName = pNames->GetStringAt((nIndex - nCurIndex) * 2); return pNames->GetDirectObjectAt((nIndex - nCurIndex) * 2 + 1); } CPDF_Array* pKids = pNode->GetArrayBy("Kids"); if (!pKids) return nullptr; for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) continue; CPDF_Object* pFound = SearchNameNode(pKid, nIndex, nCurIndex, csName, ppFind, nLevel + 1); if (pFound) return pFound; } return nullptr; }
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); } } }
void CPWL_Icon::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) { if (m_pIconFit) { fLeft = 0.0f; fBottom = 0.0f; CPDF_Array* pA = m_pIconFit->GetDict() ? m_pIconFit->GetDict()->GetArrayBy("A") : NULL; if (pA) { FX_DWORD dwCount = pA->GetCount(); if (dwCount > 0) fLeft = pA->GetNumberAt(0); if (dwCount > 1) fBottom = pA->GetNumberAt(1); } } else { fLeft = 0.0f; fBottom = 0.0f; } }
FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) { CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); if (pObj == NULL) { return FALSE; } CPDF_Array* pArray = pObj->GetArray(); if (pArray == NULL) { return FALSE; } int iCount = (int)pArray->GetCount(); for (int i = 0; i < iCount; i ++) { if (pArray->GetInteger(i) == iOptIndex) { return TRUE; } } return FALSE; }
FX_BOOL CPDF_CalGray::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { CPDF_Dictionary* pDict = pArray->GetDict(1); CPDF_Array* pParam = pDict->GetArray(FX_BSTRC("WhitePoint")); int i; for (i = 0; i < 3; i ++) { m_WhitePoint[i] = pParam ? pParam->GetNumber(i) : 0; } pParam = pDict->GetArray(FX_BSTRC("BlackPoint")); for (i = 0; i < 3; i ++) { m_BlackPoint[i] = pParam ? pParam->GetNumber(i) : 0; } m_Gamma = pDict->GetNumber(FX_BSTRC("Gamma")); if (m_Gamma == 0) { m_Gamma = 1.0f; } return TRUE; }
FX_BOOL CPDF_FormField::IsItemSelected(int index) const { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) { return FALSE; } if (IsOptionSelected(index)) { return TRUE; } CFX_WideString opt_value = GetOptionValue(index); CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (!pValue) { pValue = FPDF_GetFieldAttr(m_pDict, "I"); if (!pValue) { return FALSE; } } if (pValue->IsString()) return pValue->GetUnicodeText() == opt_value; if (pValue->IsNumber()) { if (pValue->GetString().IsEmpty()) return FALSE; return (pValue->GetInteger() == index); } CPDF_Array* pArray = pValue->AsArray(); if (!pArray) return FALSE; int iPos = -1; for (int j = 0; j < CountSelectedOptions(); j++) { if (GetSelectedOptionIndex(j) == index) { iPos = j; break; } } for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++) if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value && i == iPos) { return TRUE; } return FALSE; }
int ParserAnnots( CPDF_Document* pSourceDoc, CPDF_Dictionary * pPageDic, CPDF_RectArray * pRectArray, CPDF_ObjectArray * pObjectArray, int nUsage) { if (!pSourceDoc || !pPageDic) return FLATTEN_FAIL; GetContentsRect( pSourceDoc, pPageDic, pRectArray ); CPDF_Array* pAnnots = pPageDic->GetArray("Annots"); if (pAnnots) { FX_DWORD dwSize = pAnnots->GetCount(); for (int i = 0; i < (int)dwSize; i++) { CPDF_Object* pObj = pAnnots->GetElementValue(i); if (!pObj)continue; if (pObj->GetType() == PDFOBJ_DICTIONARY) { CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj; CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype"); if (sSubtype == "Popup")continue; int nAnnotFlag = pAnnotDic->GetInteger("F"); if(nAnnotFlag & ANNOTFLAG_HIDDEN) continue; if(nUsage == FLAT_NORMALDISPLAY) { if(nAnnotFlag & ANNOTFLAG_INVISIBLE) continue; ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray ); } else { if(nAnnotFlag & ANNOTFLAG_PRINT) ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray ); } } } return FLATTEN_SUCCESS; }else{ return FLATTEN_NOTINGTODO; } }
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, FPDF_CLIPPATH clipPath) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return; CPDF_Dictionary* pPageDict = pPage->GetDict(); CPDF_Object* pContentObj = GetPageContent(pPageDict); if (!pContentObj) return; std::ostringstream strClip; CPDF_ClipPath* pClipPath = CPDFClipPathFromFPDFClipPath(clipPath); for (size_t i = 0; i < pClipPath->GetPathCount(); ++i) { CPDF_Path path = pClipPath->GetPath(i); if (path.GetPoints().empty()) { // Empty clipping (totally clipped out) strClip << "0 0 m W n "; } else { OutputPath(strClip, path); if (pClipPath->GetClipType(i) == FXFILL_WINDING) strClip << "W n\n"; else strClip << "W* n\n"; } } CPDF_Document* pDoc = pPage->GetDocument(); if (!pDoc) return; CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDoc->New<CPDF_Dictionary>()); pStream->SetDataFromStringstream(&strClip); if (CPDF_Array* pArray = ToArray(pContentObj)) { pArray->InsertAt(0, pStream->MakeReference(pDoc)); } else if (pContentObj->IsStream() && !pContentObj->IsInline()) { CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>(); pContentArray->Add(pStream->MakeReference(pDoc)); pContentArray->Add(pContentObj->MakeReference(pDoc)); pPageDict->SetFor(pdfium::page_object::kContents, pContentArray->MakeReference(pDoc)); } }
static int InsertDeletePDFPage(CPDF_Document* pDoc, CPDF_Dictionary* pPages, int nPagesToGo, CPDF_Dictionary* pPage, FX_BOOL bInsert, CFX_PtrArray& 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") == FX_BSTRC("Page")) { if (nPagesToGo == 0) { if (bInsert) { pKidList->InsertAt(i, CPDF_Reference::Create(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; }
FX_BOOL CPDF_StandardSecurityHandler::CheckUserPassword(FX_LPCBYTE password, FX_DWORD pass_size, FX_BOOL bIgnoreEncryptMeta, FX_LPBYTE key, FX_INT32 key_len) { CalcEncryptKey(m_pEncryptDict, password, pass_size, key, key_len, bIgnoreEncryptMeta, m_pParser->GetIDArray()); CFX_ByteString ukey = m_pEncryptDict ? m_pEncryptDict->GetString(FX_BSTRC("U")) : CFX_ByteString(); if (ukey.GetLength() < 16) { return FALSE; } FX_BYTE ukeybuf[32]; if (m_Revision == 2) { FXSYS_memcpy32(ukeybuf, defpasscode, 32); CRYPT_ArcFourCryptBlock(ukeybuf, 32, key, key_len); } else { FX_BYTE test[32], tmpkey[32]; FX_DWORD copy_len = sizeof(test); if (copy_len > (FX_DWORD)ukey.GetLength()) { copy_len = ukey.GetLength(); } FXSYS_memset32(test, 0, sizeof(test)); FXSYS_memset32(tmpkey, 0, sizeof(tmpkey)); FXSYS_memcpy32(test, (FX_LPCSTR)ukey, copy_len); for (int i = 19; i >= 0; i --) { for (int j = 0; j < key_len; j ++) { tmpkey[j] = key[j] ^ i; } CRYPT_ArcFourCryptBlock(test, 32, tmpkey, key_len); } FX_BYTE md5[100]; CRYPT_MD5Start(md5); CRYPT_MD5Update(md5, defpasscode, 32); CPDF_Array* pIdArray = m_pParser->GetIDArray(); if (pIdArray) { CFX_ByteString id = pIdArray->GetString(0); CRYPT_MD5Update(md5, (FX_LPBYTE)(FX_LPCSTR)id, id.GetLength()); } CRYPT_MD5Finish(md5, ukeybuf); return FXSYS_memcmp32(test, ukeybuf, 16) == 0; } if (FXSYS_memcmp32((FX_LPVOID)(FX_LPCSTR)ukey, ukeybuf, 16) == 0) { return TRUE; } return FALSE; }
void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const { CPDF_Array* pDash = NULL; CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayBy("Border"); if (pBorder) { pDash = pBorder->GetArrayAt(3); } else { CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS"); if (pBSDict) { pDash = pBSDict->GetArrayBy("D"); } } if (pDash) { for (int i = 0, sz = pDash->GetCount(); i < sz; i++) { array.Add(pDash->GetIntegerAt(i)); } } }
FX_BOOL CPDF_LabCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { CPDF_Dictionary* pDict = pArray->GetDict(1); CPDF_Array* pParam = pDict->GetArray(FX_BSTRC("WhitePoint")); int i; for (i = 0; i < 3; i ++) { m_WhitePoint[i] = pParam ? pParam->GetNumber(i) : 0; } pParam = pDict->GetArray(FX_BSTRC("BlackPoint")); for (i = 0; i < 3; i ++) { m_BlackPoint[i] = pParam ? pParam->GetNumber(i) : 0; } pParam = pDict->GetArray(FX_BSTRC("Range")); const FX_FLOAT def_ranges[4] = { -100 * 1.0f, 100 * 1.0f, -100 * 1.0f, 100 * 1.0f}; for (i = 0; i < 4; i ++) { m_Ranges[i] = pParam ? pParam->GetNumber(i) : def_ranges[i]; } return TRUE; }
FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { CPDF_Stream* pStream = pObj->AsStream(); if (!pStream) return false; CPDF_Dictionary* pDict = pStream->GetDict(); CPDF_Array* pSize = pDict->GetArrayBy("Size"); CPDF_Array* pEncode = pDict->GetArrayBy("Encode"); CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); m_nBitsPerSample = pDict->GetIntegerBy("BitsPerSample"); if (!IsValidBitsPerSample(m_nBitsPerSample)) return FALSE; m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); m_pSampleStream.reset(new CPDF_StreamAcc); m_pSampleStream->LoadAllData(pStream, FALSE); FX_SAFE_UINT32 nTotalSampleBits = 1; m_EncodeInfo.resize(m_nInputs); for (uint32_t i = 0; i < m_nInputs; i++) { m_EncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; if (!pSize && i == 0) m_EncodeInfo[i].sizes = pDict->GetIntegerBy("Size"); nTotalSampleBits *= m_EncodeInfo[i].sizes; if (pEncode) { m_EncodeInfo[i].encode_min = pEncode->GetFloatAt(i * 2); m_EncodeInfo[i].encode_max = pEncode->GetFloatAt(i * 2 + 1); } else { m_EncodeInfo[i].encode_min = 0; m_EncodeInfo[i].encode_max = m_EncodeInfo[i].sizes == 1 ? 1 : (FX_FLOAT)m_EncodeInfo[i].sizes - 1; } } nTotalSampleBits *= m_nBitsPerSample; nTotalSampleBits *= m_nOutputs; FX_SAFE_UINT32 nTotalSampleBytes = nTotalSampleBits; nTotalSampleBytes += 7; nTotalSampleBytes /= 8; if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0 || nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) { return FALSE; } m_DecodeInfo.resize(m_nOutputs); for (uint32_t i = 0; i < m_nOutputs; i++) { if (pDecode) { m_DecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i); m_DecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1); } else { m_DecodeInfo[i].decode_min = m_pRanges[i * 2]; m_DecodeInfo[i].decode_max = m_pRanges[i * 2 + 1]; } } return TRUE; }
int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, int index, FX_BOOL bNotify) { if (csOptLabel.IsEmpty()) return -1; if (bNotify && m_pForm->m_pFormNotify) { int iRet = 0; if (GetType() == ListBox) iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csOptLabel); if (GetType() == ComboBox) iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csOptLabel); if (iRet < 0) return -1; } CFX_ByteString csStr = PDF_EncodeText(csOptLabel, csOptLabel.GetLength()); CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); CPDF_Array* pOpt = ToArray(pValue); if (!pOpt) { pOpt = new CPDF_Array; m_pDict->SetAt("Opt", pOpt); } int iCount = (int)pOpt->GetCount(); if (index < 0 || index >= iCount) { pOpt->AddString(csStr); index = iCount; } else { CPDF_String* pString = new CPDF_String(csStr, FALSE); pOpt->InsertAt(index, pString); } if (bNotify && m_pForm->m_pFormNotify) { if (GetType() == ListBox) m_pForm->m_pFormNotify->AfterSelectionChange(this); if (GetType() == ComboBox) m_pForm->m_pFormNotify->AfterValueChange(this); } m_pForm->m_bUpdated = TRUE; return index; }
FX_BOOL CPDF_DeviceNCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { CPDF_Array* pObj = ToArray(pArray->GetElementValue(1)); if (!pObj) return FALSE; m_nComponents = pObj->GetCount(); CPDF_Object* pAltCS = pArray->GetElementValue(2); if (!pAltCS || pAltCS == m_pArray) { return FALSE; } m_pAltCS = Load(pDoc, pAltCS); m_pFunc = CPDF_Function::Load(pArray->GetElementValue(3)); if (!m_pAltCS || !m_pFunc) { return FALSE; } if (m_pFunc->CountOutputs() < m_pAltCS->CountComponents()) { return FALSE; } return TRUE; }
void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array) { ASSERT(m_pAnnot != NULL); ASSERT(m_pAnnot->m_pAnnotDict != NULL); CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); if (!pBSDict) { pBSDict = FX_NEW CPDF_Dictionary; m_pAnnot->m_pAnnotDict->SetAt("BS", pBSDict); } CPDF_Array* pArray = FX_NEW CPDF_Array; for (int i=0,sz=array.GetSize(); i<sz; i++) { pArray->AddInteger(array[i]); } pBSDict->SetAt("D", pArray); }
CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) : m_pDocument(pDocument), m_pFormDict(nullptr), m_pFieldTree(new CFieldTree), m_pFormNotify(nullptr) { CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); if (!pRoot) return; m_pFormDict = pRoot->GetDictFor("AcroForm"); if (!m_pFormDict) return; CPDF_Array* pFields = m_pFormDict->GetArrayFor("Fields"); if (!pFields) return; for (size_t i = 0; i < pFields->GetCount(); ++i) LoadField(pFields->GetDictAt(i), 0); }
DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FPDF_LINK* linkAnnot) { if(!page || !startPos || !linkAnnot) return FALSE; CPDF_Page* pPage = (CPDF_Page*)page; if(!pPage->m_pFormDict) return FALSE; CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots"); if(!pAnnots) return FALSE; for (int i = *startPos; i < (int)pAnnots->GetCount(); i ++) { CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i); if (pDict == NULL || pDict->GetType() != PDFOBJ_DICTIONARY) continue; if(pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))) { *startPos = i+1; *linkAnnot = (FPDF_LINK)pDict; return TRUE; } } return FALSE; }
CPDF_Dictionary* CPDF_Document::_FindPDFPage(CPDF_Dictionary* pPages, int iPage, int nPagesToGo, int level) { CPDF_Array* pKidList = pPages->GetArray("Kids"); if (!pKidList) { if (nPagesToGo == 0) { return pPages; } return NULL; } if (level >= FX_MAX_PAGE_LEVEL) { return NULL; } int nKids = pKidList->GetCount(); for (int i = 0; i < nKids; i++) { CPDF_Dictionary* pKid = pKidList->GetDict(i); if (!pKid) { nPagesToGo--; continue; } if (pKid == pPages) { continue; } if (!pKid->KeyExist("Kids")) { if (nPagesToGo == 0) { return pKid; } m_PageList.SetAt(iPage - nPagesToGo, pKid->GetObjNum()); nPagesToGo--; } else { int nPages = pKid->GetInteger("Count"); if (nPagesToGo < nPages) { return _FindPDFPage(pKid, iPage, nPagesToGo, level + 1); } nPagesToGo -= nPages; } } return NULL; }
FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict, CPDF_StructElementImpl* pElement) { CPDF_Object *pObj = m_pTreeRoot->GetElementValue(FX_BSTRC("K")); if (!pObj) { return FALSE; } if (pObj->GetType() == PDFOBJ_DICTIONARY) { if (pObj->GetObjNum() == pDict->GetObjNum()) { if (m_Kids[0]) { m_Kids[0]->Release(); } m_Kids[0] = pElement->Retain(); } else { return FALSE; } } if (pObj->GetType() == PDFOBJ_ARRAY) { CPDF_Array* pTopKids = (CPDF_Array*)pObj; FX_DWORD i; FX_BOOL bSave = FALSE; for (i = 0; i < pTopKids->GetCount(); i ++) { CPDF_Object* pKidRef = pTopKids->GetElement(i); if (pKidRef == NULL || pKidRef->GetType() != PDFOBJ_REFERENCE) { continue; } if (((CPDF_Reference*) pKidRef)->GetRefObjNum() != pDict->GetObjNum()) { continue; } if (m_Kids[i]) { m_Kids[i]->Release(); } m_Kids[i] = pElement->Retain(); bSave = TRUE; } if (!bSave) { return FALSE; } } return TRUE; }
FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize) { CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); if (!pFDF) return TRUE; CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); if (!pMainDict) return FALSE; CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); if (!pFields) return FALSE; CFX_ByteTextBuf fdfEncodedData; for (uint32_t i = 0; i < pFields->GetCount(); i++) { CPDF_Dictionary* pField = pFields->GetDictAt(i); if (!pField) continue; CFX_WideString name; name = pField->GetUnicodeTextFor("T"); CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); CFX_ByteString csBValue = pField->GetStringFor("V"); CFX_WideString csWValue = PDF_DecodeText(csBValue); CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); name_b.ReleaseBuffer(); fdfEncodedData << "="; fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength()); csValue_b.ReleaseBuffer(); if (i != pFields->GetCount() - 1) fdfEncodedData << "&"; } nBufSize = fdfEncodedData.GetLength(); pBuf = FX_Alloc(uint8_t, nBufSize); FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); return TRUE; }
FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, FX_BOOL bSelected, FX_BOOL bNotify) { CPDF_Array* pArray = m_pDict->GetArrayBy("I"); if (!pArray) { if (!bSelected) return TRUE; pArray = new CPDF_Array; m_pDict->SetAt("I", pArray); } FX_BOOL bReturn = FALSE; for (size_t i = 0; i < pArray->GetCount(); i++) { int iFind = pArray->GetIntegerAt(i); if (iFind == iOptIndex) { if (bSelected) return TRUE; if (bNotify && m_pForm->m_pFormNotify) { CFX_WideString csValue = GetOptionLabel(iOptIndex); if (!NotifyListOrComboBoxBeforeChange(csValue)) return FALSE; } pArray->RemoveAt(i); bReturn = TRUE; break; } if (iFind > iOptIndex) { if (!bSelected) continue; if (bNotify && m_pForm->m_pFormNotify) { CFX_WideString csValue = GetOptionLabel(iOptIndex); if (!NotifyListOrComboBoxBeforeChange(csValue)) return FALSE; } pArray->InsertAt(i, new CPDF_Number(iOptIndex)); bReturn = TRUE; break; } } if (!bReturn) { if (bSelected) pArray->AddInteger(iOptIndex); if (pArray->GetCount() == 0) m_pDict->RemoveAt("I"); } if (bNotify) NotifyListOrComboBoxAfterChange(); return TRUE; }
static int CountNames(CPDF_Dictionary* pNode, int nLevel = 0) { if (nLevel > nMaxRecursion) { return 0; } CPDF_Array* pNames = pNode->GetArrayBy("Names"); if (pNames) { return pNames->GetCount() / 2; } CPDF_Array* pKids = pNode->GetArrayBy("Kids"); if (!pKids) { return 0; } int nCount = 0; for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) { continue; } nCount += CountNames(pKid, nLevel + 1); } return nCount; }
int CPDFSDK_Annot::GetBorderWidth() const { ASSERT(m_pAnnot != NULL); ASSERT(m_pAnnot->m_pAnnotDict != NULL); CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border"); if (pBorder) { return pBorder->GetInteger(2); } else { CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS"); if (pBSDict) { return pBSDict->GetInteger("W", 1); } } return 1; }