FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); if (!pDictionary)return FALSE; CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author"); CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title"); CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject"); CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords"); CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator"); CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer"); CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate"); CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate"); CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped"); v8::Isolate* isolate = GetIsolate(cc); if (vp.IsGetting()) { CJS_Context* pContext = (CJS_Context *)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1); JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str()); JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); // It's to be compatible to non-standard info dictionary. FX_POSITION pos = pDictionary->GetStartPos(); while(pos) { CFX_ByteString bsKey; CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey); CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength()); if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) ) JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str()); if(pValueObj->GetType()==PDFOBJ_NUMBER) JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber()); if(pValueObj->GetType()==PDFOBJ_BOOLEAN) JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger()); } vp << pObj; return TRUE; } else { return TRUE; } }
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; }
FX_BOOL Document::title(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) return FALSE; CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); if (!pDictionary)return FALSE; if (vp.IsGetting()) { vp << pDictionary->GetUnicodeText("Title"); return TRUE; } else { if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; CFX_WideString cstitle; vp >> cstitle; pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); m_pDocument->SetChangeMark(); return TRUE; } }
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; } }
CFX_WideString GetFullName(CPDF_Dictionary* pFieldDict) { CFX_WideString full_name; CPDF_Dictionary* pLevel = pFieldDict; while (pLevel) { CFX_WideString short_name = pLevel->GetUnicodeText("T"); if (short_name != L"") { if (full_name == L"") { full_name = short_name; } else { full_name = short_name + L"." + full_name; } } pLevel = pLevel->GetDict("Parent"); } return full_name; }
DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTRING tag, void* buffer, unsigned long buflen) { if (!doc || !tag) return 0; CPDF_Document* pDoc = (CPDF_Document*)doc; // Get info dictionary CPDF_Dictionary* pInfo = pDoc->GetInfo(); if (!pInfo) return 0; CFX_WideString text = pInfo->GetUnicodeText(tag); // Use UTF-16LE encoding CFX_ByteString encodedText = text.UTF16LE_Encode(); unsigned long len = encodedText.GetLength(); if (buffer && buflen >= len) { FXSYS_memcpy(buffer, encodedText.c_str(), len); } return len; }
DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTRING tag, void* buffer, unsigned long buflen) { if (doc == NULL || tag == NULL) return 0; CPDF_Document* pDoc = (CPDF_Document*)doc; // Get info dictionary CPDF_Dictionary* pInfo = pDoc->GetInfo(); if (pInfo == NULL) return 0; CFX_WideString text = pInfo->GetUnicodeText(tag); // Use UTF-16LE encoding CFX_ByteString bstr = text.UTF16LE_Encode(); unsigned long len = bstr.GetLength(); if (buffer != NULL || buflen >= len+2) { FXSYS_memcpy(buffer, (FX_LPCSTR)bstr, len); // use double zero as trailer ((FX_BYTE*)buffer)[len] = ((FX_BYTE*)buffer)[len+1] = 0; } return len+2; }
CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { CFX_WideString wsLabel; if (m_pDocument == NULL) { return wsLabel; } CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); if (pPDFRoot == NULL) { return wsLabel; } CPDF_Dictionary* pLabels = pPDFRoot->GetDict(FX_BSTRC("PageLabels")); CPDF_NumberTree numberTree(pLabels); CPDF_Object* pValue = NULL; int n = nPage; while (n >= 0) { pValue = numberTree.LookupValue(n); if (pValue != NULL) { break; } n--; } if (pValue != NULL) { pValue = pValue->GetDirect(); if (pValue->GetType() == PDFOBJ_DICTIONARY) { CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue; if (pLabel->KeyExist(FX_BSTRC("P"))) { wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P")); } CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), NULL); int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1); CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumberingStyle); wsLabel += wsNumPortion; return wsLabel; } } wsLabel.Format(L"%d", nPage + 1); return wsLabel; }