CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, const FX_WCHAR* text) { CFX_WideString swText = text; CPVT_WordPlace wp = place; for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { CPVT_WordPlace oldwp = wp; uint16_t word = swText.GetAt(i); switch (word) { case 0x0D: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0A) i += 1; wp = InsertSection(wp, nullptr, nullptr); } break; case 0x0A: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0D) i += 1; wp = InsertSection(wp, nullptr, nullptr); } break; case 0x09: word = 0x20; default: wp = InsertWord(wp, word, FXFONT_DEFAULT_CHARSET, nullptr); break; } if (wp == oldwp) break; } return wp; }
CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb, int32_t startPos, int32_t& e) { int32_t len = sb.GetLength() - startPos; if (len == 0) { e = BCExceptionNoContents; return (FX_WCHAR*)""; } FX_WCHAR c1 = sb.GetAt(startPos); FX_WCHAR c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0; FX_WCHAR c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0; FX_WCHAR c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0; int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4; FX_WCHAR cw1 = (FX_WCHAR)((v >> 16) & 255); FX_WCHAR cw2 = (FX_WCHAR)((v >> 8) & 255); FX_WCHAR cw3 = (FX_WCHAR)(v & 255); CFX_WideString res; res += cw1; if (len >= 2) { res += cw2; } if (len >= 3) { res += cw3; } return res; }
int32_t CBC_PDF417HighLevelEncoder::determineConsecutiveTextCount( CFX_WideString msg, int32_t startpos) { int32_t len = msg.GetLength(); int32_t idx = startpos; while (idx < len) { FX_WCHAR ch = msg.GetAt(idx); int32_t numericCount = 0; while (numericCount < 13 && isDigit(ch) && idx < len) { numericCount++; idx++; if (idx < len) { ch = msg.GetAt(idx); } } if (numericCount >= 13) { return idx - startpos - numericCount; } if (numericCount > 0) { continue; } ch = msg.GetAt(idx); if (!isText(ch)) { break; } idx++; } return idx - startpos; }
FX_BOOL CXFA_NodeHelper::ResolveNodes_CreateNode( CFX_WideString wsName, CFX_WideString wsCondition, FX_BOOL bLastNode, CXFA_ScriptContext* pScriptContext) { if (!m_pCreateParent) { 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) { CreateNode_ForCondition(wsCondition); } if (bIsClassName) { XFA_Element eType = XFA_GetElementTypeForName(wsName.AsStringC()); if (eType == XFA_Element::Unknown) return FALSE; for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eType); 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.AsStringC()); pNewNode->CreateXMLMappingNode(); m_pCreateParent->InsertChild(pNewNode); if (iIndex == m_iCreateCount - 1) { m_pCreateParent = pNewNode; } bResult = TRUE; } } } if (!bResult) { m_pCreateParent = nullptr; } return bResult; }
void CPDF_VariableText::SetText(const FX_WCHAR* text, int32_t charset, const CPVT_SecProps* pSecProps, const CPVT_WordProps* pWordProps) { DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); CFX_WideString swText = text; CPVT_WordPlace wp(0, 0, -1); CPVT_SectionInfo secinfo; if (m_bRichText) { if (pSecProps) secinfo.pSecProps = new CPVT_SecProps(*pSecProps); if (pWordProps) secinfo.pWordProps = new CPVT_WordProps(*pWordProps); } if (CSection* pSection = m_SectionArray.GetAt(0)) pSection->m_SecInfo = secinfo; int32_t nCharCount = 0; for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) break; if (m_nCharArray > 0 && nCharCount >= m_nCharArray) break; uint16_t word = swText.GetAt(i); switch (word) { case 0x0D: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0A) i += 1; wp.nSecIndex++; wp.nLineIndex = 0; wp.nWordIndex = -1; AddSection(wp, secinfo); } break; case 0x0A: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0D) i += 1; wp.nSecIndex++; wp.nLineIndex = 0; wp.nWordIndex = -1; AddSection(wp, secinfo); } break; case 0x09: word = 0x20; default: wp = InsertWord(wp, word, charset, pWordProps); break; } nCharCount++; } }
int FPDFText_ProcessInterObj(const CPDF_TextObject* pPrevObj, const CPDF_TextObject* pObj) { if(FPDFText_IsSameTextObject(pPrevObj, pObj)) { return -1; } CPDF_TextObjectItem item; int nItem = pPrevObj->CountItems(); pPrevObj->GetItemInfo(nItem - 1, &item); FX_WCHAR preChar = 0, curChar = 0; CFX_WideString wstr = pPrevObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); if(wstr.GetLength()) { preChar = wstr.GetAt(0); } FX_FLOAT last_pos = item.m_OriginX; int nLastWidth = GetCharWidth(item.m_CharCode, pPrevObj->GetFont()); FX_FLOAT last_width = nLastWidth * pPrevObj->GetFontSize() / 1000; last_width = FXSYS_fabs(last_width); pObj->GetItemInfo(0, &item); wstr = pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); if(wstr.GetLength()) { curChar = wstr.GetAt(0); } int nThisWidth = GetCharWidth(item.m_CharCode, pObj->GetFont()); FX_FLOAT this_width = nThisWidth * pObj->GetFontSize() / 1000; this_width = FXSYS_fabs(this_width); FX_FLOAT threshold = last_width > this_width ? last_width / 4 : this_width / 4; CFX_AffineMatrix prev_matrix, prev_reverse; pPrevObj->GetTextMatrix(&prev_matrix); prev_reverse.SetReverse(prev_matrix); FX_FLOAT x = pObj->GetPosX(), y = pObj->GetPosY(); prev_reverse.Transform(x, y); if (FXSYS_fabs(y) > threshold * 2) { return 2; } threshold = (FX_FLOAT)(nLastWidth > nThisWidth ? nLastWidth : nThisWidth); threshold = threshold > 400 ? (threshold < 700 ? threshold / 4 : threshold / 5) : (threshold / 2); threshold *= nLastWidth > nThisWidth ? FXSYS_fabs(pPrevObj->GetFontSize()) : FXSYS_fabs(pObj->GetFontSize()); threshold /= 1000; if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && preChar != L' ') if(curChar != L' ' && preChar != L' ') { if((x - last_pos - last_width) > threshold || (last_pos - x - last_width) > threshold) { return 1; } if(x < 0 && (last_pos - x - last_width) > threshold) { return 1; } if((x - last_pos - last_width) > this_width || (x - last_pos - this_width) > last_width ) { return 1; } } if(last_pos + last_width > x + this_width && curChar == L' ') { return 3; } return 0; }
CFX_WideString CBC_C40Encoder::encodeToCodewords(CFX_WideString sb, int32_t startPos) { FX_WCHAR c1 = sb.GetAt(startPos); FX_WCHAR c2 = sb.GetAt(startPos + 1); FX_WCHAR c3 = sb.GetAt(startPos + 2); int32_t v = (1600 * c1) + (40 * c2) + c3 + 1; FX_WCHAR cw1 = (FX_WCHAR)(v / 256); FX_WCHAR cw2 = (FX_WCHAR)(v % 256); CFX_WideString b1(cw1); CFX_WideString b2(cw2); return b1 + b2; }
int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_AnyChild( CXFA_ResolveNodesData& rnd) { CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); CFX_WideString wsCondition = rnd.m_wsCondition; CXFA_Node* findNode = NULL; CXFA_NodeArray siblings; FX_BOOL bClassName = FALSE; if (wsName.GetAt(0) == '#') { bClassName = TRUE; wsName = wsName.Right(wsName.GetLength() - 1); } findNode = m_pNodeHelper->XFA_ResolveNodes_GetOneChild(ToNode(rnd.m_CurNode), wsName, bClassName); if (findNode == NULL) { return 0; } if (wsCondition.IsEmpty()) { rnd.m_Nodes.Add(findNode); return rnd.m_Nodes.GetSize(); } m_pNodeHelper->XFA_CountSiblings(findNode, XFA_LOGIC_Transparent, (CXFA_NodeArray*)&rnd.m_Nodes, bClassName); XFA_ResolveNode_FilterCondition(rnd, wsCondition); return rnd.m_Nodes.GetSize(); }
CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection( CFX_WideString dataCodewords, int32_t errorCorrectionLevel, int32_t& e) { int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e); if (e != BCExceptionNO) return L" "; FX_WCHAR* ech = FX_Alloc(FX_WCHAR, k); FXSYS_memset(ech, 0, k * sizeof(FX_WCHAR)); int32_t sld = dataCodewords.GetLength(); for (int32_t i = 0; i < sld; i++) { int32_t t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929; int32_t t2; int32_t t3; for (int32_t j = k - 1; j >= 1; j--) { t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][j]) % 929; t3 = 929 - t2; ech[j] = (FX_WCHAR)((ech[j - 1] + t3) % 929); } t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][0]) % 929; t3 = 929 - t2; ech[0] = (FX_WCHAR)(t3 % 929); } CFX_WideString sb; for (int32_t j = k - 1; j >= 0; j--) { if (ech[j] != 0) { ech[j] = (FX_WCHAR)(929 - ech[j]); } sb += (FX_WCHAR)ech[j]; } FX_Free(ech); return sb; }
CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, CBC_SymbolInfo* symbolInfo, int32_t& e) { if (codewords.GetLength() != symbolInfo->m_dataCapacity) { e = BCExceptionIllegalArgument; return (FX_WCHAR*)""; } CFX_WideString sb; sb += codewords; int32_t blockCount = symbolInfo->getInterleavedBlockCount(); if (blockCount == 1) { CFX_WideString ecc = createECCBlock(codewords, symbolInfo->m_errorCodewords, e); BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)""); sb += ecc; } else { CFX_Int32Array dataSizes; dataSizes.SetSize(blockCount); CFX_Int32Array errorSizes; errorSizes.SetSize(blockCount); CFX_Int32Array startPos; startPos.SetSize(blockCount); for (int32_t i = 0; i < blockCount; i++) { dataSizes[i] = symbolInfo->getDataLengthForInterleavedBlock(i + 1); errorSizes[i] = symbolInfo->getErrorLengthForInterleavedBlock(i + 1); startPos[i] = 0; if (i > 0) { startPos[i] = startPos[i - 1] + dataSizes[i]; } } for (int32_t block = 0; block < blockCount; block++) { CFX_WideString temp; for (int32_t d = block; d < symbolInfo->m_dataCapacity; d += blockCount) { temp += (FX_WCHAR)codewords.GetAt(d); } CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e); BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR*)""); int32_t pos = 0; for (int32_t l = block; l < errorSizes[block] * blockCount; l += blockCount) { sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++)); } } } return sb; }
int32_t CBC_HighLevelEncoder::determineConsecutiveDigitCount(CFX_WideString msg, int32_t startpos) { int32_t count = 0; int32_t len = msg.GetLength(); int32_t idx = startpos; if (idx < len) { FX_WCHAR ch = msg.GetAt(idx); while (isDigit(ch) && idx < len) { count++; idx++; if (idx < len) { ch = msg.GetAt(idx); } } } return count; }
CFX_WideString CPDF_TextPageFind::MakeReverse(const CFX_WideString& str) { CFX_WideString str2; str2.clear(); int nlen = str.GetLength(); for (int i = nlen - 1; i >= 0; i--) str2 += str.GetAt(i); return str2; }
int32_t CBC_PDF417HighLevelEncoder::determineConsecutiveBinaryCount( CFX_WideString msg, CFX_ByteArray* bytes, int32_t startpos, int32_t& e) { int32_t len = msg.GetLength(); int32_t idx = startpos; while (idx < len) { FX_WCHAR ch = msg.GetAt(idx); int32_t numericCount = 0; while (numericCount < 13 && isDigit(ch)) { numericCount++; int32_t i = idx + numericCount; if (i >= len) { break; } ch = msg.GetAt(i); } if (numericCount >= 13) { return idx - startpos; } int32_t textCount = 0; while (textCount < 5 && isText(ch)) { textCount++; int32_t i = idx + textCount; if (i >= len) { break; } ch = msg.GetAt(i); } if (textCount >= 5) { return idx - startpos; } ch = msg.GetAt(idx); if (bytes->GetAt(idx) == 63 && ch != '?') { e = BCExceptionNonEncodableCharacterDetected; return -1; } idx++; } return idx - startpos; }
FX_BOOL Document::documentFileName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { CJS_Context* pContext = static_cast<CJS_Context*>(cc); sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); return FALSE; } CFX_WideString wsFilePath = m_pDocument->GetPath(); FX_INT32 i = wsFilePath.GetLength() - 1; for ( ; i >= 0; i-- ) { if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' ) break; } if ( i >= 0 && i < wsFilePath.GetLength() - 1 ) { vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 ); }else{ vp << L""; } return TRUE; }
void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue, const CFX_ByteStringC& szPropName, CFXJSE_Value* pReturnValue) { CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); if (!pOriginalObject) return; CXFA_ScriptContext* lpScriptContext = pOriginalObject->GetDocument()->GetScriptContext(); CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( pObject->GetElementType(), wsPropName.AsStringC()); if (lpAttributeInfo) { (pObject->*(lpAttributeInfo->lpfnCallback))( pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); } else { if (pObject->IsNode()) { if (wsPropName.GetAt(0) == '#') { wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); } CXFA_Node* pNode = ToNode(pObject); CXFA_Node* pPropOrChild = nullptr; XFA_Element eType = XFA_GetElementTypeForName(wsPropName.AsStringC()); if (eType != XFA_Element::Unknown) pPropOrChild = pNode->GetProperty(0, eType); else pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); if (pPropOrChild) { CFX_WideString wsDefaultName(L"{default}"); const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = XFA_GetScriptAttributeByName(pPropOrChild->GetElementType(), wsDefaultName.AsStringC()); if (lpAttrInfo) { (pPropOrChild->*(lpAttrInfo->lpfnCallback))( pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute); return; } } } CXFA_Object* pScriptObject = lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); if (pScriptObject) { lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, pReturnValue, FALSE); } } }
CFX_WideString CBC_OnedCode128Writer::FilterContents( const CFX_WideStringC& contents) { CFX_WideString filterChineseChar; FX_WCHAR ch; for (int32_t i = 0; i < contents.GetLength(); i++) { ch = contents.GetAt(i); if (ch > 175) { i++; continue; } filterChineseChar += ch; } CFX_WideString filtercontents; if (m_codeFormat == BC_CODE128_B) { for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) { ch = filterChineseChar.GetAt(i); if (ch >= 32 && ch <= 126) { filtercontents += ch; } else { continue; } } } else if (m_codeFormat == BC_CODE128_C) { for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) { ch = filterChineseChar.GetAt(i); if (ch >= 32 && ch <= 106) { filtercontents += ch; } else { continue; } } } else { filtercontents = contents; } return filtercontents; }
FX_BOOL CPDF_TextPageFind::FindFirst(const CFX_WideString& findwhat, int flags, int startPos) { if (!m_pTextPage) return FALSE; if (m_strText.IsEmpty() || m_bMatchCase != (flags & FPDFTEXT_MATCHCASE)) m_strText = m_pTextPage->GetPageText(); CFX_WideString findwhatStr = findwhat; m_findWhat = findwhatStr; m_flags = flags; m_bMatchCase = flags & FPDFTEXT_MATCHCASE; if (m_strText.IsEmpty()) { m_IsFind = FALSE; return TRUE; } FX_STRSIZE len = findwhatStr.GetLength(); if (!m_bMatchCase) { findwhatStr.MakeLower(); m_strText.MakeLower(); } m_bMatchWholeWord = flags & FPDFTEXT_MATCHWHOLEWORD; m_findNextStart = startPos; if (startPos == -1) m_findPreStart = m_strText.GetLength() - 1; else m_findPreStart = startPos; m_csFindWhatArray.clear(); int i = 0; while (i < len) { if (findwhatStr.GetAt(i) != ' ') break; i++; } if (i < len) ExtractFindWhat(findwhatStr); else m_csFindWhatArray.push_back(findwhatStr); if (m_csFindWhatArray.empty()) return FALSE; m_IsFind = TRUE; m_resStart = 0; m_resEnd = -1; return TRUE; }
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 CBC_Base256Encoder::Encode(CBC_EncoderContext& context, int32_t& e) { CFX_WideString buffer; buffer += (FX_WCHAR)'\0'; while (context.hasMoreCharacters()) { FX_WCHAR c = context.getCurrentChar(); buffer += c; context.m_pos++; int32_t newMode = CBC_HighLevelEncoder::lookAheadTest( context.m_msg, context.m_pos, getEncodingMode()); if (newMode != getEncodingMode()) { context.signalEncoderChange(newMode); break; } } int32_t dataCount = buffer.GetLength() - 1; FX_CHAR buf[128]; FXSYS_itoa(dataCount, buf, 10); buffer.SetAt(0, FX_WCHAR(*buf) - '0'); int32_t lengthFieldSize = 1; int32_t currentSize = context.getCodewordCount() + dataCount + lengthFieldSize; context.updateSymbolInfo(currentSize, e); if (e != BCExceptionNO) { return; } FX_BOOL mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0; if (context.hasMoreCharacters() || mustPad) { if (dataCount <= 249) { buffer.SetAt(0, (FX_WCHAR)dataCount); } else if (dataCount > 249 && dataCount <= 1555) { buffer.SetAt(0, (FX_WCHAR)((dataCount / 250) + 249)); buffer.Insert(1, (FX_WCHAR)(dataCount % 250)); } else { e = BCExceptionIllegalStateMessageLengthInvalid; return; } } for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) { context.writeCodeword( randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1)); } }
CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, int32_t start, int32_t len, int32_t numECWords, int32_t& e) { int32_t table = -1; for (int32_t i = 0; i < sizeof(FACTOR_SETS) / sizeof(int32_t); i++) { if (FACTOR_SETS[i] == numECWords) { table = i; break; } } if (table < 0) { e = BCExceptionIllegalArgument; return (FX_WCHAR*)""; } FX_WORD* ecc = FX_Alloc(FX_WORD, numECWords); FXSYS_memset(ecc, 0, numECWords * sizeof(FX_WORD)); for (int32_t l = start; l < start + len; l++) { FX_WORD m = ecc[numECWords - 1] ^ codewords.GetAt(l); for (int32_t k = numECWords - 1; k > 0; k--) { if (m != 0 && FACTORS[table][k] != 0) { ecc[k] = (FX_WORD)(ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]); } else { ecc[k] = ecc[k - 1]; } } if (m != 0 && FACTORS[table][0] != 0) { ecc[0] = (FX_WORD)ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255]; } else { ecc[0] = 0; } } CFX_WideString strecc; for (int32_t j = 0; j < numECWords; j++) { strecc += (FX_WCHAR)ecc[numECWords - j - 1]; } FX_Free(ecc); return strecc; }
FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( CFX_WideString& wsCondition) { int32_t iLen = wsCondition.GetLength(); CFX_WideString wsIndex = FX_WSTRC(L"0"); ; FX_BOOL bAll = FALSE; if (iLen == 0) { m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; return FALSE; } if (wsCondition.GetAt(0) == '[') { int32_t i = 1; for (; i < iLen; ++i) { FX_WCHAR ch = wsCondition[i]; if (ch == ' ') { continue; } if (ch == '+' || ch == '-') { break; } else if (ch == '*') { bAll = TRUE; break; } else { break; } } if (bAll) { wsIndex = FX_WSTRC(L"1"); m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeAll; } else { m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; wsIndex = wsCondition.Mid(i, iLen - 1 - i); } int32_t iIndex = wsIndex.GetInteger(); m_iCreateCount = iIndex; return TRUE; } return FALSE; }
void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords, int32_t c, int32_t r, int32_t errorCorrectionLevel, CBC_BarcodeMatrix* logic) { int32_t idx = 0; for (int32_t y = 0; y < r; y++) { int32_t cluster = y % 3; logic->startRow(); encodeChar(START_PATTERN, 17, logic->getCurrentRow()); int32_t left; int32_t right; if (cluster == 0) { left = (30 * (y / 3)) + ((r - 1) / 3); right = (30 * (y / 3)) + (c - 1); } else if (cluster == 1) { left = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3); right = (30 * (y / 3)) + ((r - 1) / 3); } else { left = (30 * (y / 3)) + (c - 1); right = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3); } int32_t pattern = CODEWORD_TABLE[cluster][left]; encodeChar(pattern, 17, logic->getCurrentRow()); for (int32_t x = 0; x < c; x++) { pattern = CODEWORD_TABLE[cluster][fullCodewords.GetAt(idx)]; encodeChar(pattern, 17, logic->getCurrentRow()); idx++; } if (m_compact) { encodeChar(STOP_PATTERN, 1, logic->getCurrentRow()); } else { pattern = CODEWORD_TABLE[cluster][right]; encodeChar(pattern, 17, logic->getCurrentRow()); encodeChar(STOP_PATTERN, 18, logic->getCurrentRow()); } } }
void CBC_PDF417HighLevelEncoder::encodeNumeric(CFX_WideString msg, int32_t startpos, int32_t count, CFX_WideString& sb) { int32_t idx = 0; BigInteger num900 = 900; while (idx < count) { CFX_WideString tmp; int32_t len = 44 < count - idx ? 44 : count - idx; CFX_ByteString part = ((FX_WCHAR)'1' + msg.Mid(startpos + idx, len)).UTF8Encode(); BigInteger bigint = stringToBigInteger(part.c_str()); do { int32_t c = (bigint % num900).toInt(); tmp += (FX_WCHAR)(c); bigint = bigint / num900; } while (!bigint.isZero()); for (int32_t i = tmp.GetLength() - 1; i >= 0; i--) { sb += tmp.GetAt(i); } idx += len; } }
void CRF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO & info) const { if(index >= CountChars() || index < 0 || !m_pDataList) { return; } CRF_CharData* pData = (*m_pDataList)[index]; FX_FLOAT ReltiveCorddDs = pData->m_pCharState->m_fDescent; FX_FLOAT ReltiveCorddAs = pData->m_pCharState->m_fAscent; info.m_Flag = CHAR_NORMAL; info.m_pTextObj = pData->m_pCharState->m_pTextObj; info.m_OriginX = pData->m_PosX; info.m_OriginY = pData->m_PosY - ReltiveCorddDs; info.m_FontSize = pData->m_pCharState->m_fFontSize; CFX_FloatRect FloatRectTmp(pData->m_PosX, pData->m_PosY, pData->m_PosX + pData->m_Width, pData->m_PosY + ReltiveCorddAs - ReltiveCorddDs); info.m_CharBox = FloatRectTmp; CFX_WideString str = pData->m_pCharState->m_pFont->UnicodeFromCharCode(pData->m_CharCode); if(!str.IsEmpty()) { info.m_Unicode = str.GetAt(0); } else { info.m_Unicode = -1; } info.m_Charcode = (FX_WCHAR)pData->m_CharCode; info.m_Matrix = CFX_Matrix(1, 0, 0, 1, 0, 0); }
void CXFA_FFPasswordEdit::UpdateWidgetProperty() { CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget; if (!pWidget) { return; } uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; dwExtendedStyle |= UpdateUIProperty(); CFX_WideString wsPassWord; m_pDataAcc->GetPasswordChar(wsPassWord); if (!wsPassWord.IsEmpty()) { pWidget->SetAliasChar(wsPassWord.GetAt(0)); } if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; } if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; } dwExtendedStyle |= GetAlignment(); m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); }
FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText, int startPos, int endPos) { FX_WCHAR char_left = 0; FX_WCHAR char_right = 0; int char_count = endPos - startPos + 1; if (char_count < 1) return FALSE; if (char_count == 1 && csPageText.GetAt(startPos) > 255) return TRUE; if (startPos - 1 >= 0) char_left = csPageText.GetAt(startPos - 1); if (startPos + char_count < csPageText.GetLength()) char_right = csPageText.GetAt(startPos + char_count); if ((char_left > 'A' && char_left < 'a') || (char_left > 'a' && char_left < 'z') || (char_left > 0xfb00 && char_left < 0xfb06) || std::iswdigit(char_left) || (char_right > 'A' && char_right < 'a') || (char_right > 'a' && char_right < 'z') || (char_right > 0xfb00 && char_right < 0xfb06) || std::iswdigit(char_right)) { return FALSE; } if (!(('A' > char_left || char_left > 'Z') && ('a' > char_left || char_left > 'z') && ('A' > char_right || char_right > 'Z') && ('a' > char_right || char_right > 'z'))) { return FALSE; } if (char_count > 0) { if (csPageText.GetAt(startPos) >= L'0' && csPageText.GetAt(startPos) <= L'9' && char_left >= L'0' && char_left <= L'9') { return FALSE; } if (csPageText.GetAt(endPos) >= L'0' && csPageText.GetAt(endPos) <= L'9' && char_right >= L'0' && char_right <= L'9') { return FALSE; } } return TRUE; }
void NormalizeString(CFX_WideString& str) { if (str.GetLength() <= 0) { return; } CFX_WideString sBuffer; IFX_BidiChar* BidiChar = IFX_BidiChar::Create(); if (NULL == BidiChar) { return; } CFX_WordArray order; FX_BOOL bR2L = FALSE; FX_INT32 start = 0, count = 0, i = 0; int nR2L = 0, nL2R = 0; for (i = 0; i < str.GetLength(); i++) { if(BidiChar->AppendChar(str.GetAt(i))) { FX_INT32 ret = BidiChar->GetBidiInfo(start, count); order.Add(start); order.Add(count); order.Add(ret); if(!bR2L) { if(ret == 2) { nR2L++; } else if (ret == 1) { nL2R++; } } } } if(BidiChar->EndChar()) { FX_INT32 ret = BidiChar->GetBidiInfo(start, count); order.Add(start); order.Add(count); order.Add(ret); if(!bR2L) { if(ret == 2) { nR2L++; } else if(ret == 1) { nL2R++; } } } if(nR2L > 0 && nR2L >= nL2R) { bR2L = TRUE; } if(bR2L) { int count = order.GetSize(); for(int j = count - 1; j > 0; j -= 3) { int ret = order.GetAt(j); int start = order.GetAt(j - 2); int count1 = order.GetAt(j - 1); if(ret == 2 || ret == 0) { for(int i = start + count1 - 1; i >= start; i--) { NormalizeCompositeChar(str[i], sBuffer); } } else { i = j; FX_BOOL bSymbol = FALSE; while(i > 0 && order.GetAt(i) != 2) { bSymbol = !order.GetAt(i); i -= 3; } int end = start + count1 ; int n = 0; if(bSymbol) { n = i + 6; } else { n = i + 3; } if(n >= j) { for(int m = start; m < end; m++) { sBuffer += str[m]; } } else { i = j; j = n; for(; n <= i; n += 3) { int start = order.GetAt(n - 2); int count1 = order.GetAt(n - 1); int end = start + count1 ; for(int m = start; m < end; m++) { sBuffer += str[m]; } } } } } } else { int count = order.GetSize(); FX_BOOL bL2R = FALSE; for(int j = 0; j < count; j += 3) { int ret = order.GetAt(j + 2); int start = order.GetAt(j); int count1 = order.GetAt(j + 1); if(ret == 2 || (j == 0 && ret == 0 && !bL2R)) { int i = j + 3; while(bR2L && i < count) { if(order.GetAt(i + 2) == 1) { break; } else { i += 3; } } if(i == 3) { j = -3; bL2R = TRUE; continue; } int end = str.GetLength() - 1; if(i < count) { end = order.GetAt(i) - 1; } j = i - 3; for(int n = end; n >= start; n--) { NormalizeCompositeChar(str[i], sBuffer); } } else { int end = start + count1 ; for(int i = start; i < end; i++) { sBuffer += str[i]; } } } } str.Empty(); str += sBuffer; BidiChar->Release(); }
int32_t CBC_PDF417HighLevelEncoder::encodeText(CFX_WideString msg, int32_t startpos, int32_t count, CFX_WideString& sb, int32_t initialSubmode) { CFX_WideString tmp; int32_t submode = initialSubmode; int32_t idx = 0; while (true) { FX_WCHAR ch = msg.GetAt(startpos + idx); switch (submode) { case SUBMODE_ALPHA: if (isAlphaUpper(ch)) { if (ch == ' ') { tmp += (FX_WCHAR)26; } else { tmp += (FX_WCHAR)(ch - 65); } } else { if (isAlphaLower(ch)) { submode = SUBMODE_LOWER; tmp += (FX_WCHAR)27; continue; } else if (isMixed(ch)) { submode = SUBMODE_MIXED; tmp += (FX_WCHAR)28; continue; } else { tmp += (FX_WCHAR)29; tmp += PUNCTUATION[ch]; break; } } break; case SUBMODE_LOWER: if (isAlphaLower(ch)) { if (ch == ' ') { tmp += (FX_WCHAR)26; } else { tmp += (FX_WCHAR)(ch - 97); } } else { if (isAlphaUpper(ch)) { tmp += (FX_WCHAR)27; tmp += (FX_WCHAR)(ch - 65); break; } else if (isMixed(ch)) { submode = SUBMODE_MIXED; tmp += (FX_WCHAR)28; continue; } else { tmp += (FX_WCHAR)29; tmp += PUNCTUATION[ch]; break; } } break; case SUBMODE_MIXED: if (isMixed(ch)) { tmp += MIXED[ch]; } else { if (isAlphaUpper(ch)) { submode = SUBMODE_ALPHA; tmp += (FX_WCHAR)28; continue; } else if (isAlphaLower(ch)) { submode = SUBMODE_LOWER; tmp += (FX_WCHAR)27; continue; } else { if (startpos + idx + 1 < count) { FX_WCHAR next = msg.GetAt(startpos + idx + 1); if (isPunctuation(next)) { submode = SUBMODE_PUNCTUATION; tmp += (FX_WCHAR)25; continue; } } tmp += (FX_WCHAR)29; tmp += PUNCTUATION[ch]; } } break; default: if (isPunctuation(ch)) { tmp += PUNCTUATION[ch]; } else { submode = SUBMODE_ALPHA; tmp += (FX_WCHAR)29; continue; } } idx++; if (idx >= count) { break; } } FX_WCHAR h = 0; int32_t len = tmp.GetLength(); for (int32_t i = 0; i < len; i++) { bool odd = (i % 2) != 0; if (odd) { h = (FX_WCHAR)((h * 30) + tmp.GetAt(i)); sb += h; } else { h = tmp.GetAt(i); } } if ((len % 2) != 0) { sb += (FX_WCHAR)((h * 30) + 29); } return submode; }
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; }
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; } } } } }