FX_DOUBLE XFA_WideStringToDouble(const CFX_WideString& wsStringVal) { CFX_WideString wsValue = wsStringVal; wsValue.TrimLeft(); wsValue.TrimRight(); int64_t nIntegral = 0; FX_DWORD dwFractional = 0; int32_t nExponent = 0; int32_t cc = 0; FX_BOOL bNegative = FALSE, bExpSign = FALSE; const FX_WCHAR* str = (const FX_WCHAR*)wsValue; int32_t len = wsValue.GetLength(); if (str[0] == '+') { cc++; } else if (str[0] == '-') { bNegative = TRUE; cc++; } int32_t nIntegralLen = 0; while (cc < len) { if (str[cc] == '.' || str[cc] == 'E' || str[cc] == 'e' || nIntegralLen > 17) { break; } if (!XFA_IsDigit(str[cc])) { return 0; } nIntegral = nIntegral * 10 + str[cc] - '0'; cc++; nIntegralLen++; } nIntegral = bNegative ? -nIntegral : nIntegral; int32_t scale = 0; FX_DOUBLE fraction = 0.0; if (cc < len && str[cc] == '.') { cc++; while (cc < len) { fraction += fraction_scales[scale] * (str[cc] - '0'); scale++; cc++; if (cc == len) { break; } if (scale == sizeof(fraction_scales) / sizeof(FX_DOUBLE) || str[cc] == 'E' || str[cc] == 'e') { break; } if (!XFA_IsDigit(str[cc])) { return 0; } } dwFractional = (FX_DWORD)(fraction * 4294967296.0); } if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { cc++; if (cc < len) { if (str[cc] == '+') { cc++; } else if (str[cc] == '-') { bExpSign = TRUE; cc++; } } while (cc < len) { if (str[cc] == '.' || !XFA_IsDigit(str[cc])) { return 0; } nExponent = nExponent * 10 + str[cc] - '0'; cc++; } nExponent = bExpSign ? -nExponent : nExponent; } FX_DOUBLE dValue = (dwFractional / 4294967296.0); dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue); if (nExponent != 0) { dValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); } return dValue; }
int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, int32_t startpos, int32_t currentMode) { if (startpos >= msg.GetLength()) { return currentMode; } CFX_FloatArray charCounts; if (currentMode == ASCII_ENCODATION) { charCounts.Add(0); charCounts.Add(1); charCounts.Add(1); charCounts.Add(1); charCounts.Add(1); charCounts.Add(1.25f); } else { charCounts.Add(1); charCounts.Add(2); charCounts.Add(2); charCounts.Add(2); charCounts.Add(2); charCounts.Add(2.25f); charCounts[currentMode] = 0; } int32_t charsProcessed = 0; while (TRUE) { if ((startpos + charsProcessed) == msg.GetLength()) { FX_DWORD min = std::numeric_limits<int32_t>::max(); CFX_ByteArray mins; mins.SetSize(6); CFX_Int32Array intCharCounts; intCharCounts.SetSize(6); min = findMinimums(charCounts, intCharCounts, min, mins); int32_t minCount = getMinimumCount(mins); if (intCharCounts[ASCII_ENCODATION] == min) { return ASCII_ENCODATION; } if (minCount == 1 && mins[BASE256_ENCODATION] > 0) { return BASE256_ENCODATION; } if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) { return EDIFACT_ENCODATION; } if (minCount == 1 && mins[TEXT_ENCODATION] > 0) { return TEXT_ENCODATION; } if (minCount == 1 && mins[X12_ENCODATION] > 0) { return X12_ENCODATION; } return C40_ENCODATION; } FX_WCHAR c = msg.GetAt(startpos + charsProcessed); charsProcessed++; if (isDigit(c)) { charCounts[ASCII_ENCODATION] += 0.5; } else if (isExtendedASCII(c)) { charCounts[ASCII_ENCODATION] = (FX_FLOAT)ceil(charCounts[ASCII_ENCODATION]); charCounts[ASCII_ENCODATION] += 2; } else { charCounts[ASCII_ENCODATION] = (FX_FLOAT)ceil(charCounts[ASCII_ENCODATION]); charCounts[ASCII_ENCODATION]++; } if (isNativeC40(c)) { charCounts[C40_ENCODATION] += 2.0f / 3.0f; } else if (isExtendedASCII(c)) { charCounts[C40_ENCODATION] += 8.0f / 3.0f; } else { charCounts[C40_ENCODATION] += 4.0f / 3.0f; } if (isNativeText(c)) { charCounts[TEXT_ENCODATION] += 2.0f / 3.0f; } else if (isExtendedASCII(c)) { charCounts[TEXT_ENCODATION] += 8.0f / 3.0f; } else { charCounts[TEXT_ENCODATION] += 4.0f / 3.0f; } if (isNativeX12(c)) { charCounts[X12_ENCODATION] += 2.0f / 3.0f; } else if (isExtendedASCII(c)) { charCounts[X12_ENCODATION] += 13.0f / 3.0f; } else { charCounts[X12_ENCODATION] += 10.0f / 3.0f; } if (isNativeEDIFACT(c)) { charCounts[EDIFACT_ENCODATION] += 3.0f / 4.0f; } else if (isExtendedASCII(c)) { charCounts[EDIFACT_ENCODATION] += 17.0f / 4.0f; } else { charCounts[EDIFACT_ENCODATION] += 13.0f / 4.0f; } if (isSpecialB256(c)) { charCounts[BASE256_ENCODATION] += 4; } else { charCounts[BASE256_ENCODATION]++; } if (charsProcessed >= 4) { CFX_Int32Array intCharCounts; intCharCounts.SetSize(6); CFX_ByteArray mins; mins.SetSize(6); findMinimums(charCounts, intCharCounts, std::numeric_limits<int32_t>::max(), mins); int32_t minCount = getMinimumCount(mins); if (intCharCounts[ASCII_ENCODATION] < intCharCounts[BASE256_ENCODATION] && intCharCounts[ASCII_ENCODATION] < intCharCounts[C40_ENCODATION] && intCharCounts[ASCII_ENCODATION] < intCharCounts[TEXT_ENCODATION] && intCharCounts[ASCII_ENCODATION] < intCharCounts[X12_ENCODATION] && intCharCounts[ASCII_ENCODATION] < intCharCounts[EDIFACT_ENCODATION]) { return ASCII_ENCODATION; } if (intCharCounts[BASE256_ENCODATION] < intCharCounts[ASCII_ENCODATION] || (mins[C40_ENCODATION] + mins[TEXT_ENCODATION] + mins[X12_ENCODATION] + mins[EDIFACT_ENCODATION]) == 0) { return BASE256_ENCODATION; } if (minCount == 1 && mins[EDIFACT_ENCODATION] > 0) { return EDIFACT_ENCODATION; } if (minCount == 1 && mins[TEXT_ENCODATION] > 0) { return TEXT_ENCODATION; } if (minCount == 1 && mins[X12_ENCODATION] > 0) { return X12_ENCODATION; } if (intCharCounts[C40_ENCODATION] + 1 < intCharCounts[ASCII_ENCODATION] && intCharCounts[C40_ENCODATION] + 1 < intCharCounts[BASE256_ENCODATION] && intCharCounts[C40_ENCODATION] + 1 < intCharCounts[EDIFACT_ENCODATION] && intCharCounts[C40_ENCODATION] + 1 < intCharCounts[TEXT_ENCODATION]) { if (intCharCounts[C40_ENCODATION] < intCharCounts[X12_ENCODATION]) { return C40_ENCODATION; } if (intCharCounts[C40_ENCODATION] == intCharCounts[X12_ENCODATION]) { int32_t p = startpos + charsProcessed + 1; while (p < msg.GetLength()) { FX_WCHAR tc = msg.GetAt(p); if (isX12TermSep(tc)) { return X12_ENCODATION; } if (!isNativeX12(tc)) { break; } p++; } return C40_ENCODATION; } } } } }
CFX_WideString ChangeObjName(const CFX_WideString& str) { CFX_WideString sRet = str; sRet.Replace(L"_", L"."); return sRet; }
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; } }
int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2) { if (Name1.Find(Name2.c_str()) != -1) return 1; return 0; }
CPDF_String::CPDF_String(const CFX_WideString& str) : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { m_String = PDF_EncodeText(str, str.GetLength()); }
FX_BOOL Document::getPageNthWord(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0; bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true; CPDF_Document* pDocument = m_pDocument->GetDocument(); if (!pDocument) return FALSE; CJS_Context* pContext = static_cast<CJS_Context*>(cc); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); return FALSE; } CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); if (!pPageDict) return FALSE; CPDF_Page page; page.Load(pDocument, pPageDict); page.StartParse(); page.ParseContent(); FX_POSITION pos = page.GetFirstObjectPosition(); int nWords = 0; CFX_WideString swRet; while (pos) { if (CPDF_PageObject* pPageObj = page.GetNextObject(pos)) { if (pPageObj->m_Type == PDFPAGE_TEXT) { int nObjWords = CountWords((CPDF_TextObject*)pPageObj); if (nWords + nObjWords >= nWordNo) { swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords); break; } nWords += nObjWords; } } } if (bStrip) { swRet.TrimLeft(); swRet.TrimRight(); } vRet = swRet.c_str(); return TRUE; }
bool CPDFXFA_DocEnvironment::SubmitDataInternal(CXFA_FFDoc* hDoc, CXFA_Submit submit) { CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return false; CFX_WideStringC csURLC; submit.GetSubmitTarget(csURLC); CFX_WideString csURL(csURLC); if (csURL.IsEmpty()) { CFX_WideString ws; ws.FromLocal("Submit cancelled."); CFX_ByteString bs = ws.UTF16LE_Encode(); int len = bs.GetLength(); pFormFillEnv->Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"", 0, 4); bs.ReleaseBuffer(len); return false; } FPDF_FILEHANDLER* pFileHandler = nullptr; int fileFlag = -1; switch (submit.GetSubmitFormat()) { case XFA_ATTRIBUTEENUM_Xdp: { CFX_WideStringC csContentC; submit.GetSubmitXDPContent(csContentC); CFX_WideString csContent; csContent = csContentC; csContent.TrimLeft(); csContent.TrimRight(); CFX_WideString space; space.FromLocal(" "); csContent = space + csContent + space; FPDF_DWORD flag = 0; if (submit.IsSubmitEmbedPDF()) flag |= FXFA_PDF; ToXFAContentFlags(csContent, flag); pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); fileFlag = FXFA_SAVEAS_XDP; ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag); break; } case XFA_ATTRIBUTEENUM_Xml: pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); fileFlag = FXFA_SAVEAS_XML; ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); break; case XFA_ATTRIBUTEENUM_Pdf: break; case XFA_ATTRIBUTEENUM_Urlencoded: pFileHandler = pFormFillEnv->OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); fileFlag = FXFA_SAVEAS_XML; ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, FXFA_XFA_ALL); break; default: return false; } if (!pFileHandler) return false; if (csURL.Left(7).CompareNoCase(L"mailto:") == 0) { CFX_WideString csToAddress; CFX_WideString csCCAddress; CFX_WideString csBCCAddress; CFX_WideString csSubject; CFX_WideString csMsg; if (!MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, csMsg)) { return false; } CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode(); CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode(); CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode(); CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode(); CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode(); FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); pFormFillEnv->EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg); bsTo.ReleaseBuffer(); bsCC.ReleaseBuffer(); bsBcc.ReleaseBuffer(); bsSubject.ReleaseBuffer(); bsMsg.ReleaseBuffer(); } else { // HTTP or FTP CFX_WideString ws; CFX_ByteString bs = csURL.UTF16LE_Encode(); int len = bs.GetLength(); pFormFillEnv->UploadTo(pFileHandler, fileFlag, (FPDF_WIDESTRING)bs.GetBuffer(len)); bs.ReleaseBuffer(len); } return true; }
FX_BOOL CPDF_TextPageFind::FindNext() { if (!m_pTextPage) return FALSE; m_resArray.clear(); if (m_findNextStart == -1) return FALSE; if (m_strText.IsEmpty()) { m_IsFind = FALSE; return m_IsFind; } int strLen = m_strText.GetLength(); if (m_findNextStart > strLen - 1) { m_IsFind = FALSE; return m_IsFind; } int nCount = pdfium::CollectionSize<int>(m_csFindWhatArray); int nResultPos = 0; int nStartPos = 0; nStartPos = m_findNextStart; bool bSpaceStart = false; for (int iWord = 0; iWord < nCount; iWord++) { CFX_WideString csWord = m_csFindWhatArray[iWord]; if (csWord.IsEmpty()) { if (iWord == nCount - 1) { FX_WCHAR strInsert = m_strText.GetAt(nStartPos); if (strInsert == TEXT_LINEFEED_CHAR || strInsert == TEXT_SPACE_CHAR || strInsert == TEXT_RETURN_CHAR || strInsert == 160) { nResultPos = nStartPos + 1; break; } iWord = -1; } else if (iWord == 0) { bSpaceStart = true; } continue; } int endIndex; nResultPos = m_strText.Find(csWord.c_str(), nStartPos); if (nResultPos == -1) { m_IsFind = FALSE; return m_IsFind; } endIndex = nResultPos + csWord.GetLength() - 1; if (iWord == 0) m_resStart = nResultPos; FX_BOOL bMatch = TRUE; if (iWord != 0 && !bSpaceStart) { int PreResEndPos = nStartPos; int curChar = csWord.GetAt(0); CFX_WideString lastWord = m_csFindWhatArray[iWord - 1]; int lastChar = lastWord.GetAt(lastWord.GetLength() - 1); if (nStartPos == nResultPos && !(IsIgnoreSpaceCharacter(lastChar) || IsIgnoreSpaceCharacter(curChar))) { bMatch = FALSE; } for (int d = PreResEndPos; d < nResultPos; d++) { FX_WCHAR strInsert = m_strText.GetAt(d); if (strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_SPACE_CHAR && strInsert != TEXT_RETURN_CHAR && strInsert != 160) { bMatch = FALSE; break; } } } else if (bSpaceStart) { if (nResultPos > 0) { FX_WCHAR strInsert = m_strText.GetAt(nResultPos - 1); if (strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_SPACE_CHAR && strInsert != TEXT_RETURN_CHAR && strInsert != 160) { bMatch = FALSE; m_resStart = nResultPos; } else { m_resStart = nResultPos - 1; } } } if (m_bMatchWholeWord && bMatch) { bMatch = IsMatchWholeWord(m_strText, nResultPos, endIndex); } nStartPos = endIndex + 1; if (!bMatch) { iWord = -1; if (bSpaceStart) nStartPos = m_resStart + m_csFindWhatArray[1].GetLength(); else nStartPos = m_resStart + m_csFindWhatArray[0].GetLength(); } } m_resEnd = nResultPos + m_csFindWhatArray.back().GetLength() - 1; m_IsFind = TRUE; int resStart = GetCharIndex(m_resStart); int resEnd = GetCharIndex(m_resEnd); m_resArray = m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1); if (m_flags & FPDFTEXT_CONSECUTIVE) { m_findNextStart = m_resStart + 1; m_findPreStart = m_resEnd - 1; } else { m_findNextStart = m_resEnd + 1; m_findPreStart = m_resStart - 1; } return m_IsFind; }
void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, const CFX_WideString& wsFilePath, bool bXDP) { if (hDoc != m_pContext->GetXFADoc()) return; if (m_pContext->GetDocType() != DOCTYPE_DYNAMIC_XFA && m_pContext->GetDocType() != DOCTYPE_STATIC_XFA) { return; } CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML; CFX_ByteString bs = wsFilePath.UTF16LE_Encode(); if (wsFilePath.IsEmpty()) { if (!pFormFillEnv->GetFormFillInfo() || !pFormFillEnv->GetFormFillInfo()->m_pJsPlatform) { return; } CFX_WideString filepath = pFormFillEnv->JS_fieldBrowse(); bs = filepath.UTF16LE_Encode(); } int len = bs.GetLength(); FPDF_FILEHANDLER* pFileHandler = pFormFillEnv->OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, (FPDF_WIDESTRING)bs.GetBuffer(len), "wb"); bs.ReleaseBuffer(len); if (!pFileHandler) return; CFX_RetainPtr<IFX_SeekableStream> fileWrite = MakeSeekableStream(pFileHandler); CFX_ByteString content; if (fileType == FXFA_SAVEAS_XML) { content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(), content.GetLength()); m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Data, fileWrite, nullptr); } else if (fileType == FXFA_SAVEAS_XDP) { if (!m_pContext->GetPDFDoc()) return; CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); if (!pRoot) return; CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); if (!pAcroForm) return; CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); if (!pArray) return; int size = pArray->GetCount(); for (int i = 1; i < size; i += 2) { CPDF_Object* pPDFObj = pArray->GetObjectAt(i); CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); if (!pPrePDFObj->IsString()) continue; if (!pPDFObj->IsReference()) continue; CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); if (!pStream) continue; if (pPrePDFObj->GetString() == "form") { m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Form, fileWrite, nullptr); continue; } if (pPrePDFObj->GetString() == "datasets") { m_pContext->GetXFADocView()->GetDoc()->SavePackage( XFA_HASHCODE_Datasets, fileWrite, nullptr); continue; } if (i == size - 1) { CFX_WideString wPath = CFX_WideString::FromUTF16LE( reinterpret_cast<const unsigned short*>(bs.c_str()), bs.GetLength() / sizeof(unsigned short)); CFX_ByteString bPath = wPath.UTF8Encode(); const char* szFormat = "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; content.Format(szFormat, bPath.c_str()); fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(), content.GetLength()); } std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc); pAcc->LoadAllData(pStream); fileWrite->WriteBlock(pAcc->GetData(), fileWrite->GetSize(), pAcc->GetSize()); } } fileWrite->Flush(); }
bool CPDFXFA_DocEnvironment::MailToInfo(CFX_WideString& csURL, CFX_WideString& csToAddress, CFX_WideString& csCCAddress, CFX_WideString& csBCCAddress, CFX_WideString& csSubject, CFX_WideString& csMsg) { CFX_WideString srcURL = csURL; srcURL.TrimLeft(); if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0) return false; int pos = srcURL.Find(L'?', 0); CFX_WideString tmp; if (pos == -1) { pos = srcURL.Find(L'@', 0); if (pos == -1) return false; tmp = srcURL.Right(csURL.GetLength() - 7); } else { tmp = srcURL.Left(pos); tmp = tmp.Right(tmp.GetLength() - 7); } tmp.TrimLeft(); tmp.TrimRight(); csToAddress = tmp; srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1)); while (!srcURL.IsEmpty()) { srcURL.TrimLeft(); srcURL.TrimRight(); pos = srcURL.Find(L'&', 0); tmp = (pos == -1) ? srcURL : srcURL.Left(pos); tmp.TrimLeft(); tmp.TrimRight(); if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) { tmp = tmp.Right(tmp.GetLength() - 3); if (!csCCAddress.IsEmpty()) csCCAddress += L';'; csCCAddress += tmp; } else if (tmp.GetLength() >= 4 && tmp.Left(4).CompareNoCase(L"bcc=") == 0) { tmp = tmp.Right(tmp.GetLength() - 4); if (!csBCCAddress.IsEmpty()) csBCCAddress += L';'; csBCCAddress += tmp; } else if (tmp.GetLength() >= 8 && tmp.Left(8).CompareNoCase(L"subject=") == 0) { tmp = tmp.Right(tmp.GetLength() - 8); csSubject += tmp; } else if (tmp.GetLength() >= 5 && tmp.Left(5).CompareNoCase(L"body=") == 0) { tmp = tmp.Right(tmp.GetLength() - 5); csMsg += tmp; } srcURL = (pos == -1) ? L"" : srcURL.Right(csURL.GetLength() - (pos + 1)); } csToAddress.Replace(L",", L";"); csCCAddress.Replace(L",", L";"); csBCCAddress.Replace(L",", L";"); return true; }
FX_BOOL CXFA_NodeHelper::XFA_ResolveNodes_CreateNode( CFX_WideString wsName, CFX_WideString wsCondition, FX_BOOL bLastNode, CXFA_ScriptContext* pScriptContext) { if (m_pCreateParent == NULL) { return FALSE; } FX_BOOL bIsClassName = FALSE; FX_BOOL bResult = FALSE; if (wsName.GetAt(0) == '!') { wsName = wsName.Right(wsName.GetLength() - 1); m_pCreateParent = ToNode( pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); } if (wsName.GetAt(0) == '#') { bIsClassName = TRUE; wsName = wsName.Right(wsName.GetLength() - 1); } if (m_iCreateCount == 0) { XFA_CreateNode_ForCondition(wsCondition); } if (bIsClassName) { XFA_LPCELEMENTINFO lpElement = XFA_GetElementByName(wsName); if (lpElement == NULL) { return FALSE; } for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(lpElement->eName); if (pNewNode) { m_pCreateParent->InsertChild(pNewNode); if (iIndex == m_iCreateCount - 1) { m_pCreateParent = pNewNode; } bResult = TRUE; } } } else { XFA_ELEMENT eClassType = XFA_ELEMENT_DataGroup; if (bLastNode) { eClassType = m_eLastCreateType; } for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eClassType); if (pNewNode) { pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, wsName); pNewNode->CreateXMLMappingNode(); m_pCreateParent->InsertChild(pNewNode); if (iIndex == m_iCreateCount - 1) { m_pCreateParent = pNewNode; } bResult = TRUE; } } } if (!bResult) { m_pCreateParent = NULL; } return bResult; }
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( IFDE_CSSSyntaxParser* pSyntax, CFDE_CSSRuleArray& ruleArray) { m_Selectors.RemoveAt(0, m_Selectors.GetSize()); CFDE_CSSStyleRule* pStyleRule = NULL; const FX_WCHAR* pszValue = NULL; int32_t iValueLen = 0; FDE_CSSPROPERTYARGS propertyArgs; propertyArgs.pStaticStore = m_pAllocator; propertyArgs.pStringCache = &m_StringCache; propertyArgs.pProperty = NULL; CFX_WideString wsName; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_Selector: { pszValue = pSyntax->GetCurrentString(iValueLen); IFDE_CSSSelector* pSelector = CFDE_CSSSelector::FromString(m_pAllocator, pszValue, iValueLen); if (pSelector != NULL) { m_Selectors.Add(pSelector); } } break; case FDE_CSSSYNTAXSTATUS_PropertyName: pszValue = pSyntax->GetCurrentString(iValueLen); propertyArgs.pProperty = FDE_GetCSSPropertyByName(pszValue, iValueLen); if (propertyArgs.pProperty == NULL) { wsName = CFX_WideStringC(pszValue, iValueLen); } break; case FDE_CSSSYNTAXSTATUS_PropertyValue: if (propertyArgs.pProperty != NULL) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pStyleRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, iValueLen); } } else if (iValueLen > 0) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pStyleRule->GetDeclImp().AddProperty( &propertyArgs, wsName, wsName.GetLength(), pszValue, iValueLen); } } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: if (pStyleRule == NULL && m_Selectors.GetSize() > 0) { pStyleRule = FDE_NewWith(m_pAllocator) CFDE_CSSStyleRule; pStyleRule->SetSelector(m_pAllocator, m_Selectors); ruleArray.Add(pStyleRule); } else { SkipRuleSet(pSyntax); return FDE_CSSSYNTAXSTATUS_None; } break; case FDE_CSSSYNTAXSTATUS_DeclClose: if (pStyleRule != NULL && pStyleRule->GetDeclImp().GetStartPosition() == NULL) { pStyleRule->~CFDE_CSSStyleRule(); ruleArray.RemoveLast(1); } return FDE_CSSSYNTAXSTATUS_None; FDE_CSSSWITCHDEFAULTS(); } } }
CPDF_String::CPDF_String(const CFX_WideString& str) { m_Type = PDFOBJ_STRING; m_String = PDF_EncodeText(str, str.GetLength()); m_bHex = FALSE; }
CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { if (!pFieldDict->KeyExist("FT")) { // Key "FT" is required for terminal fields, it is also inheritable. CPDF_Dictionary* pParentDict = pFieldDict->GetDictFor("Parent"); if (!pParentDict || !pParentDict->KeyExist("FT")) return nullptr; } CPDF_Dictionary* pDict = pFieldDict; CFX_WideString csWName = FPDF_GetFullName(pFieldDict); if (csWName.IsEmpty()) return nullptr; CPDF_FormField* pField = nullptr; pField = m_pFieldTree->GetField(csWName); if (!pField) { CPDF_Dictionary* pParent = pFieldDict; if (!pFieldDict->KeyExist("T") && pFieldDict->GetStringFor("Subtype") == "Widget") { pParent = pFieldDict->GetDictFor("Parent"); if (!pParent) pParent = pFieldDict; } if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { if (pFieldDict->KeyExist("FT")) { CPDF_Object* pFTValue = pFieldDict->GetDirectObjectFor("FT"); if (pFTValue) pParent->SetFor("FT", pFTValue->Clone()); } if (pFieldDict->KeyExist("Ff")) { CPDF_Object* pFfValue = pFieldDict->GetDirectObjectFor("Ff"); if (pFfValue) pParent->SetFor("Ff", pFfValue->Clone()); } } pField = new CPDF_FormField(this, pParent); CPDF_Object* pTObj = pDict->GetObjectFor("T"); if (ToReference(pTObj)) { std::unique_ptr<CPDF_Object> pClone = pTObj->CloneDirectObject(); if (pClone) pDict->SetFor("T", std::move(pClone)); else pDict->SetNewFor<CPDF_Name>("T", ""); } m_pFieldTree->SetField(csWName, pField); } CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); if (pKids) { for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) continue; if (pKid->GetStringFor("Subtype") != "Widget") continue; AddControl(pField, pKid); } } else { if (pFieldDict->GetStringFor("Subtype") == "Widget") AddControl(pField, pFieldDict); } return pField; }
void CPDF_TextPageFind::ExtractFindWhat(const CFX_WideString& findwhat) { if (findwhat.IsEmpty()) return; int index = 0; while (1) { CFX_WideString csWord = TEXT_EMPTY; int ret = ExtractSubString(csWord, findwhat.c_str(), index, TEXT_SPACE_CHAR); if (csWord.IsEmpty()) { if (ret) { m_csFindWhatArray.push_back(L""); index++; continue; } else { break; } } int pos = 0; while (pos < csWord.GetLength()) { CFX_WideString curStr = csWord.Mid(pos, 1); FX_WCHAR curChar = csWord.GetAt(pos); if (IsIgnoreSpaceCharacter(curChar)) { if (pos > 0 && curChar == 0x2019) { pos++; continue; } if (pos > 0) m_csFindWhatArray.push_back(csWord.Mid(0, pos)); m_csFindWhatArray.push_back(curStr); if (pos == csWord.GetLength() - 1) { csWord.clear(); break; } csWord = csWord.Right(csWord.GetLength() - pos - 1); pos = 0; continue; } pos++; } if (!csWord.IsEmpty()) m_csFindWhatArray.push_back(csWord); index++; } }
void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, int32_t iPageNo, const CFX_WideString& wsType, FX_BOOL bOnPageArea, CXFA_NodeArray& retArray) { CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(iPageNo); if (!pLayoutPage) { return; } if (wsType == FX_WSTRC(L"pageArea")) { if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { retArray.Add(pMasterPage); } return; } if (wsType == FX_WSTRC(L"contentArea")) { for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { retArray.Add(pItem->m_pFormNode); } } return; } std::set<CXFA_Node*> formItems; if (wsType.IsEmpty()) { if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { retArray.Add(pMasterPage); } for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { retArray.Add(pItem->m_pFormNode); if (!bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); if (eType != XFA_Element::Field && eType != XFA_Element::Draw && eType != XFA_Element::Subform && eType != XFA_Element::Area) { continue; } if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } else { if (bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) { continue; } XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); if (eType != XFA_Element::Field && eType != XFA_Element::Draw && eType != XFA_Element::Subform && eType != XFA_Element::Area) { continue; } if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } } return; } XFA_Element eType = XFA_Element::Unknown; if (wsType == FX_WSTRC(L"field")) { eType = XFA_Element::Field; } else if (wsType == FX_WSTRC(L"draw")) { eType = XFA_Element::Draw; } else if (wsType == FX_WSTRC(L"subform")) { eType = XFA_Element::Subform; } else if (wsType == FX_WSTRC(L"area")) { eType = XFA_Element::Area; } if (eType != XFA_Element::Unknown) { for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { if (!bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) continue; if (pItemChild->m_pFormNode->GetElementType() != eType) continue; if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } else { if (bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) { if (!pItemChild->IsContentLayoutItem()) continue; if (pItemChild->m_pFormNode->GetElementType() != eType) continue; if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); retArray.Add(pItemChild->m_pFormNode); } } } } return; } }
FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField, CFX_WideString& csNewFieldName) { return pField && !csNewFieldName.IsEmpty() && ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, nullptr); }
FX_FLOAT CXFA_Font::GetVerticalScale() { CFX_WideString wsValue; m_pNode->TryCData(XFA_ATTRIBUTE_FontVerticalScale, wsValue); int32_t iScale = FXSYS_wtoi(wsValue.c_str()); return iScale > 0 ? (FX_FLOAT)iScale : 100.0f; }
CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { if (!pFieldDict->KeyExist("T")) return nullptr; CPDF_Dictionary* pDict = pFieldDict; CFX_WideString csWName = FPDF_GetFullName(pFieldDict); if (csWName.IsEmpty()) return nullptr; CPDF_FormField* pField = nullptr; pField = m_pFieldTree->GetField(csWName); if (!pField) { CPDF_Dictionary* pParent = pFieldDict; if (!pFieldDict->KeyExist("T") && pFieldDict->GetStringBy("Subtype") == "Widget") { pParent = pFieldDict->GetDictBy("Parent"); if (!pParent) pParent = pFieldDict; } if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { if (pFieldDict->KeyExist("FT")) { CPDF_Object* pFTValue = pFieldDict->GetDirectObjectBy("FT"); if (pFTValue) pParent->SetAt("FT", pFTValue->Clone()); } if (pFieldDict->KeyExist("Ff")) { CPDF_Object* pFfValue = pFieldDict->GetDirectObjectBy("Ff"); if (pFfValue) pParent->SetAt("Ff", pFfValue->Clone()); } } pField = new CPDF_FormField(this, pParent); CPDF_Object* pTObj = pDict->GetObjectBy("T"); if (ToReference(pTObj)) { CPDF_Object* pClone = pTObj->CloneDirectObject(); if (pClone) pDict->SetAt("T", pClone); else pDict->SetAtName("T", ""); } m_pFieldTree->SetField(csWName, pField); } CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); if (!pKids) { if (pFieldDict->GetStringBy("Subtype") == "Widget") AddControl(pField, pFieldDict); } else { for (size_t i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDictAt(i); if (!pKid) continue; if (pKid->GetStringBy("Subtype") != "Widget") continue; AddControl(pField, pKid); } } return pField; }
FX_BOOL Document::mailDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); FX_BOOL bUI = TRUE; CFX_WideString cTo = L""; CFX_WideString cCc = L""; CFX_WideString cBcc = L""; CFX_WideString cSubject = L""; CFX_WideString cMsg = L""; if (params.size() >= 1) bUI = params[0].ToBool(); if (params.size() >= 2) cTo = params[1].ToCFXWideString(); if (params.size() >= 3) cCc = params[2].ToCFXWideString(); if (params.size() >= 4) cBcc = params[3].ToCFXWideString(); if (params.size() >= 5) cSubject = params[4].ToCFXWideString(); if (params.size() >= 6) cMsg = params[5].ToCFXWideString(); v8::Isolate* isolate = GetIsolate(cc); if(params.size() >= 1 && params[0].GetType() == VT_object) { JSObject pObj = params[0].ToV8Object(); v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI"); bUI = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToInt(); pValue = JS_GetObjectElement(isolate,pObj, L"cTo"); cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cCc"); cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cBcc"); cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cSubject"); cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cMsg"); cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); } CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); pRuntime->BeginBlock(); CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str()); pRuntime->EndBlock(); return TRUE; }
FX_BOOL CPDF_InterForm::ValidateFieldName( CFX_WideString& csNewFieldName, int iType, const CPDF_FormField* pExcludedField, const CPDF_FormControl* pExcludedControl) { if (csNewFieldName.IsEmpty()) return FALSE; int iPos = 0; int iLength = csNewFieldName.GetLength(); CFX_WideString csSub; while (TRUE) { while (iPos < iLength && (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) { iPos++; } if (iPos < iLength && !csSub.IsEmpty()) csSub += L'.'; while (iPos < iLength && csNewFieldName[iPos] != L'.') csSub += csNewFieldName[iPos++]; for (int i = csSub.GetLength() - 1; i > -1; i--) { if (csSub[i] == L' ' || csSub[i] == L'.') csSub.SetAt(i, L'\0'); else break; } uint32_t dwCount = m_pFieldTree->m_Root.CountFields(); for (uint32_t m = 0; m < dwCount; m++) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); if (!pField) continue; if (pField == pExcludedField) { if (pExcludedControl) { if (pField->CountControls() < 2) continue; } else { continue; } } CFX_WideString csFullName = pField->GetFullName(); int iRet = CompareFieldName(csSub, csFullName); if (iRet == 1) { if (pField->GetFieldType() != iType) return FALSE; } else if (iRet == 2 && csSub == csNewFieldName) { if (csFullName[iPos] == L'.') return FALSE; } else if (iRet == 3 && csSub == csNewFieldName) { if (csNewFieldName[csFullName.GetLength()] == L'.') return FALSE; } } if (iPos >= iLength) break; } if (csSub.IsEmpty()) return FALSE; csNewFieldName = csSub; return TRUE; }
CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, int32_t numECWords, int32_t& e) { return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e); }
FX_BOOL CPWL_Edit::OnRButtonUp(const CPDF_Point& point, FX_DWORD nFlag) { if (m_bMouseDown) return FALSE; CPWL_Wnd::OnRButtonUp(point, nFlag); if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) return TRUE; IFX_SystemHandler* pSH = GetSystemHandler(); if (!pSH) return FALSE; SetFocus(); CPVT_WordRange wrLatin = GetLatinWordsRange(point); CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); FX_HMENU hPopup = pSH->CreatePopupMenu(); if (!hPopup) return FALSE; CFX_ByteStringArray sSuggestWords; CPDF_Point ptPopup = point; if (!IsReadOnly()) { if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) { if (m_pSpellCheck) { CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin); if (!m_pSpellCheck->CheckWord(sLatin)) { m_pSpellCheck->SuggestWords(sLatin, sSuggestWords); int32_t nSuggest = sSuggestWords.GetSize(); for (int32_t nWord = 0; nWord < nSuggest; nWord++) { pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST + nWord, sSuggestWords[nWord].UTF8Decode()); } if (nSuggest > 0) pSH->AppendMenuItem(hPopup, 0, L""); ptPopup = GetWordRightBottomPoint(wrLatin.EndPos); } } } } IPWL_Provider* pProvider = GetProvider(); if (HasFlag(PES_UNDO)) { pSH->AppendMenuItem( hPopup, WM_PWLEDIT_UNDO, pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); pSH->AppendMenuItem( hPopup, WM_PWLEDIT_REDO, pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); pSH->AppendMenuItem(hPopup, 0, L""); if (!m_pEdit->CanUndo()) pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE); if (!m_pEdit->CanRedo()) pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE); } pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT, pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t"); pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY, pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy"); pSH->AppendMenuItem( hPopup, WM_PWLEDIT_PASTE, pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste"); pSH->AppendMenuItem( hPopup, WM_PWLEDIT_DELETE, pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete"); CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd()); if (swText.IsEmpty()) pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); if (!m_pEdit->IsSelected()) { pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); } if (IsReadOnly()) { pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); } if (HasFlag(PES_PASSWORD)) { pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); } if (HasFlag(PES_NOREAD)) { pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); } pSH->AppendMenuItem(hPopup, 0, L""); pSH->AppendMenuItem( hPopup, WM_PWLEDIT_SELECTALL, pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All"); if (m_pEdit->GetTotalWords() == 0) { pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE); } int32_t x, y; PWLtoWnd(ptPopup, x, y); pSH->ClientToScreen(GetAttachedHWnd(), x, y); pSH->SetCursor(FXCT_ARROW); int32_t nCmd = pSH->TrackPopupMenu(hPopup, x, y, GetAttachedHWnd()); switch (nCmd) { case WM_PWLEDIT_UNDO: Undo(); break; case WM_PWLEDIT_REDO: Redo(); break; case WM_PWLEDIT_CUT: CutText(); break; case WM_PWLEDIT_COPY: CopyText(); break; case WM_PWLEDIT_PASTE: PasteText(); break; case WM_PWLEDIT_DELETE: Clear(); break; case WM_PWLEDIT_SELECTALL: SelectAll(); break; case WM_PWLEDIT_SUGGEST + 0: SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); ReplaceSel(sSuggestWords[0].UTF8Decode().c_str()); break; case WM_PWLEDIT_SUGGEST + 1: SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); ReplaceSel(sSuggestWords[1].UTF8Decode().c_str()); break; case WM_PWLEDIT_SUGGEST + 2: SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); ReplaceSel(sSuggestWords[2].UTF8Decode().c_str()); break; case WM_PWLEDIT_SUGGEST + 3: SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); ReplaceSel(sSuggestWords[3].UTF8Decode().c_str()); break; case WM_PWLEDIT_SUGGEST + 4: SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); ReplaceSel(sSuggestWords[4].UTF8Decode().c_str()); break; default: break; } pSH->DestroyMenu(hPopup); return TRUE; }
int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, uint16_t wCodePage, uint32_t dwFontStyles, const CFX_WideString& FontName, FX_WCHAR wcUnicode) { int32_t nPenalty = 30000; if (FontName.GetLength() != 0) { if (FontName != pInstalled->m_wsFaceName) { int32_t i; for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { if (pInstalled->m_wsFamilyNames[i] == FontName) break; } if (i == pInstalled->m_wsFamilyNames.GetSize()) nPenalty += 0xFFFF; else nPenalty -= 28000; } else { nPenalty -= 30000; } if (30000 == nPenalty && 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { int32_t i; for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { if (IsPartName(pInstalled->m_wsFamilyNames[i], FontName) != 0) break; } if (i == pInstalled->m_wsFamilyNames.GetSize()) nPenalty += 0xFFFF; else nPenalty -= 26000; } else { nPenalty -= 27000; } } uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; if (dwStyleMask & FX_FONTSTYLE_Bold) nPenalty += 4500; if (dwStyleMask & FX_FONTSTYLE_FixedPitch) nPenalty += 10000; if (dwStyleMask & FX_FONTSTYLE_Italic) nPenalty += 10000; if (dwStyleMask & FX_FONTSTYLE_Serif) nPenalty += 500; if (dwStyleMask & FX_FONTSTYLE_Symbolic) nPenalty += 0xFFFF; if (nPenalty >= 0xFFFF) return 0xFFFF; uint16_t wBit = (wCodePage == 0 || wCodePage == 0xFFFF) ? static_cast<uint16_t>(-1) : FX_GetCodePageBit(wCodePage); if (wBit != static_cast<uint16_t>(-1)) { ASSERT(wBit < 64); if ((pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32))) == 0) nPenalty += 0xFFFF; else nPenalty -= 60000; } wBit = (wcUnicode == 0 || wcUnicode == 0xFFFE) ? static_cast<uint16_t>(999) : FX_GetUnicodeBit(wcUnicode); if (wBit != static_cast<uint16_t>(999)) { ASSERT(wBit < 128); if ((pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32))) == 0) nPenalty += 0xFFFF; else nPenalty -= 60000; } return nPenalty; }
void CFWL_CheckBoxImp::Layout() { int32_t width = int32_t(m_pProperties->m_rtWidget.width + 0.5f); int32_t height = int32_t(m_pProperties->m_rtWidget.height + 0.5f); m_pProperties->m_rtWidget.width = (FX_FLOAT)width; m_pProperties->m_rtWidget.height = (FX_FLOAT)height; GetClientRect(m_rtClient); FX_FLOAT fBoxTop = m_rtClient.top; FX_FLOAT fBoxLeft = m_rtClient.left; FX_FLOAT fTextLeft = 0.0, fTextRight = 0.0; FX_FLOAT fClientRight = m_rtClient.right(); FX_FLOAT fClientBottom = m_rtClient.bottom(); if (!m_pProperties->m_pDataProvider) return; IFWL_CheckBoxDP* pData = static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); FX_FLOAT fCheckBox = pData->GetBoxSize(m_pInterface); switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) { case FWL_STYLEEXT_CKB_Top: { fBoxTop = m_rtClient.top; break; } case FWL_STYLEEXT_CKB_Bottom: { fBoxTop = fClientBottom - fCheckBox; break; } case FWL_STYLEEXT_CKB_VCenter: default: { fBoxTop = m_rtClient.top + (m_rtClient.height - fCheckBox) / 2; fBoxTop = FXSYS_floor(fBoxTop); } } if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) { fBoxLeft = fClientRight - fCheckBox; fTextLeft = m_rtClient.left; fTextRight = fBoxLeft; } else { fTextLeft = fBoxLeft + fCheckBox; fTextRight = fClientRight; } m_rtBox.Set(fBoxLeft, fBoxTop, fCheckBox, fCheckBox); m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, m_rtClient.height); m_rtCaption.Inflate(-FWL_CKB_CaptionMargin, -FWL_CKB_CaptionMargin); CFX_RectF rtFocus; rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, m_rtCaption.height); CFX_WideString wsCaption; m_pProperties->m_pDataProvider->GetCaption(m_pInterface, wsCaption); if (wsCaption.IsEmpty()) { m_rtFocus.Set(0, 0, 0, 0); } else { CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles, m_iTTOAlign, rtFocus); if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); FX_FLOAT fLeft = m_rtCaption.left; FX_FLOAT fTop = m_rtCaption.top; if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == FWL_STYLEEXT_CKB_Center) { fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == FWL_STYLEEXT_CKB_Right) { fLeft = m_rtCaption.right() - fWidth; } if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == FWL_STYLEEXT_CKB_VCenter) { fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2; } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == FWL_STYLEEXT_CKB_Bottom) { fTop = m_rtCaption.bottom() - fHeight; } m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); } else { m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height); } m_rtFocus.Inflate(1, 1); } }
CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, SymbolShapeHint shape, CBC_Dimension* minSize, CBC_Dimension* maxSize, int32_t& e) { CBC_EncoderContext context(msg, ecLevel, e); BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)""); context.setSymbolShape(shape); context.setSizeConstraints(minSize, maxSize); if ((msg.Mid(0, 6) == MACRO_05_HEADER) && (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) { context.writeCodeword(MACRO_05); context.setSkipAtEnd(2); context.m_pos += 6; } else if ((msg.Mid(0, 6) == MACRO_06_HEADER) && (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) { context.writeCodeword(MACRO_06); context.setSkipAtEnd(2); context.m_pos += 6; } CFX_PtrArray encoders; encoders.Add(new CBC_ASCIIEncoder()); encoders.Add(new CBC_C40Encoder()); encoders.Add(new CBC_TextEncoder()); encoders.Add(new CBC_X12Encoder()); encoders.Add(new CBC_EdifactEncoder()); encoders.Add(new CBC_Base256Encoder()); int32_t encodingMode = ASCII_ENCODATION; while (context.hasMoreCharacters()) { ((CBC_Encoder*)encoders.GetAt(encodingMode))->Encode(context, e); if (e != BCExceptionNO) { for (int32_t i = 0; i < encoders.GetSize(); i++) { delete (CBC_Encoder*)encoders.GetAt(i); } encoders.RemoveAll(); return (FX_WCHAR*)""; } if (context.m_newEncoding >= 0) { encodingMode = context.m_newEncoding; context.resetEncoderSignal(); } } int32_t len = context.m_codewords.GetLength(); context.updateSymbolInfo(e); if (e != BCExceptionNO) { for (int32_t i = 0; i < encoders.GetSize(); i++) { delete (CBC_Encoder*)encoders.GetAt(i); } encoders.RemoveAll(); return (FX_WCHAR*)""; } int32_t capacity = context.m_symbolInfo->m_dataCapacity; if (len < capacity) { if (encodingMode != ASCII_ENCODATION && encodingMode != BASE256_ENCODATION) { context.writeCodeword(0x00fe); } } CFX_WideString codewords = context.m_codewords; if (codewords.GetLength() < capacity) { codewords += PAD; } while (codewords.GetLength() < capacity) { codewords += (randomize253State(PAD, codewords.GetLength() + 1)); } for (int32_t i = 0; i < encoders.GetSize(); i++) { delete (CBC_Encoder*)encoders.GetAt(i); } encoders.RemoveAll(); return codewords; }
FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type, CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDFSDK_Annot* pScreen, CFX_PtrList& list) { ASSERT(pDocument != NULL); if (list.Find((CPDF_Dictionary*)action)) return FALSE; list.AddTail((CPDF_Dictionary*)action); CPDFDoc_Environment* pEnv = pDocument->GetEnv(); ASSERT(pEnv); if (action.GetType() == CPDF_Action::JavaScript) { if(pEnv->IsJSInitiated()) { CFX_WideString swJS = action.GetJavaScript(); if (!swJS.IsEmpty()) { IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); ASSERT(pRuntime != NULL); pRuntime->SetReaderDocument(pDocument); IFXJS_Context* pContext = pRuntime->NewContext(); ASSERT(pContext != NULL); // switch (type) // { // case CPDF_AAction::CursorEnter: // pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::CursorExit: // pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::ButtonDown: // pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::ButtonUp: // pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::GetFocus: // pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::LoseFocus: // pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::PageOpen: // pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::PageClose: // pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::PageVisible: // pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // case CPDF_AAction::PageInvisible: // pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen); // break; // default: // ASSERT(FALSE); // break; // } CFX_WideString csInfo; FX_BOOL bRet = pContext->RunScript(swJS, csInfo); if (!bRet) { //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); } pRuntime->ReleaseContext(pContext); } } } else { DoAction_NoJs(action, pDocument/*, pDocView*/); } // if (!IsValidDocView(pDocument, pDocView)) // return FALSE; for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++) { CPDF_Action subaction = action.GetSubAction(i); if (!ExecuteScreenAction(subaction, type, pDocument,/* pDocView,*/ pScreen, list)) return FALSE; } return TRUE; }
void CXFA_ResolveProcessor::XFA_ResolveNode_ConditionArray( int32_t iCurIndex, CFX_WideString wsCondition, int32_t iFoundCount, CXFA_ResolveNodesData& rnd) { CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; int32_t iLen = wsCondition.GetLength(); FX_BOOL bRelative = FALSE; FX_BOOL bAll = FALSE; int32_t i = 1; for (; i < iLen; ++i) { FX_WCHAR ch = wsCondition[i]; if (ch == ' ') { continue; } if (ch == '+' || ch == '-') { bRelative = TRUE; break; } else if (ch == '*') { bAll = TRUE; break; } else { break; } } if (bAll) { if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { if (rnd.m_dwStyles & XFA_RESOLVENODE_Bind) { m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); m_pNodeHelper->m_iCreateCount = 1; findNodes.RemoveAll(); m_pNodeHelper->m_iCurAllStart = -1; m_pNodeHelper->m_pAllStartParent = NULL; } else { if (m_pNodeHelper->m_iCurAllStart == -1) { m_pNodeHelper->m_iCurAllStart = m_iCurStart; m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurNode); } } } else if (rnd.m_dwStyles & XFA_RESOLVENODE_BindNew) { if (m_pNodeHelper->m_iCurAllStart == -1) { m_pNodeHelper->m_iCurAllStart = m_iCurStart; } } return; } if (iFoundCount == 1 && !iLen) { return; } CFX_WideString wsIndex; wsIndex = wsCondition.Mid(i, iLen - 1 - i); int32_t iIndex = wsIndex.GetInteger(); if (bRelative) { iIndex += iCurIndex; } if (iFoundCount <= iIndex || iIndex < 0) { if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); m_pNodeHelper->m_iCreateCount = iIndex - iFoundCount + 1; } findNodes.RemoveAll(); } else { CXFA_Node* ret = findNodes[iIndex]; findNodes.RemoveAll(); findNodes.Add(ret); } }
CFX_WideString CBC_PDF417HighLevelEncoder::encodeHighLevel( CFX_WideString wideMsg, Compaction compaction, int32_t& e) { CFX_ByteString bytes; CBC_UtilCodingConvert::UnicodeToUTF8(wideMsg, bytes); CFX_WideString msg; int32_t len = bytes.GetLength(); for (int32_t i = 0; i < len; i++) { FX_WCHAR ch = (FX_WCHAR)(bytes.GetAt(i) & 0xff); if (ch == '?' && bytes.GetAt(i) != '?') { e = BCExceptionCharactersOutsideISO88591Encoding; return CFX_WideString(); } msg += ch; } CFX_ByteArray byteArr; for (int32_t k = 0; k < bytes.GetLength(); k++) { byteArr.Add(bytes.GetAt(k)); } CFX_WideString sb; len = msg.GetLength(); int32_t p = 0; int32_t textSubMode = SUBMODE_ALPHA; if (compaction == TEXT) { encodeText(msg, p, len, sb, textSubMode); } else if (compaction == BYTES) { encodeBinary(&byteArr, p, byteArr.GetSize(), BYTE_COMPACTION, sb); } else if (compaction == NUMERIC) { sb += (FX_WCHAR)LATCH_TO_NUMERIC; encodeNumeric(msg, p, len, sb); } else { int32_t encodingMode = LATCH_TO_TEXT; while (p < len) { int32_t n = determineConsecutiveDigitCount(msg, p); if (n >= 13) { sb += (FX_WCHAR)LATCH_TO_NUMERIC; encodingMode = NUMERIC_COMPACTION; textSubMode = SUBMODE_ALPHA; encodeNumeric(msg, p, n, sb); p += n; } else { int32_t t = determineConsecutiveTextCount(msg, p); if (t >= 5 || n == len) { if (encodingMode != TEXT_COMPACTION) { sb += (FX_WCHAR)LATCH_TO_TEXT; encodingMode = TEXT_COMPACTION; textSubMode = SUBMODE_ALPHA; } textSubMode = encodeText(msg, p, t, sb, textSubMode); p += t; } else { int32_t b = determineConsecutiveBinaryCount(msg, &byteArr, p, e); BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' '); if (b == 0) { b = 1; } if (b == 1 && encodingMode == TEXT_COMPACTION) { encodeBinary(&byteArr, p, 1, TEXT_COMPACTION, sb); } else { encodeBinary(&byteArr, p, b, encodingMode, sb); encodingMode = BYTE_COMPACTION; textSubMode = SUBMODE_ALPHA; } p += b; } } } } return sb; }