CFGAS_GEFont* CFGAS_FontMgr::GetFontByUnicode(FX_WCHAR wUnicode, uint32_t dwFontStyles, const FX_WCHAR* pszFontFamily) { CFGAS_GEFont* pFont = nullptr; if (m_FailedUnicodes2Nullptr.Lookup(wUnicode, pFont)) return nullptr; const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; uint16_t wBitField = x ? x->wBitField : 0x03E7; CFX_ByteString bsHash; if (wCodePage == 0xFFFF) bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); else bsHash.Format("%d, %d", wCodePage, dwFontStyles); bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { if (!pFonts) return nullptr; for (int32_t i = 0; i < pFonts->GetSize(); ++i) { if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) return pFonts->GetAt(i)->Retain(); } } if (!pFonts) pFonts = new CFX_ArrayTemplate<CFGAS_GEFont*>; m_Hash2Fonts.SetAt(dwHash, pFonts); CFX_FontDescriptorInfos* sortedFonts = nullptr; if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { sortedFonts = new CFX_FontDescriptorInfos; MatchFonts(*sortedFonts, wCodePage, dwFontStyles, CFX_WideString(pszFontFamily), wUnicode); m_Hash2CandidateList.SetAt(dwHash, sortedFonts); } for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; if (!VerifyUnicode(pDesc, wUnicode)) continue; pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); if (!pFont) continue; pFont->SetLogicalFontStyle(dwFontStyles); pFonts->Add(pFont); return pFont; } if (!pszFontFamily) m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); return nullptr; }
FX_BOOL util::printx(OBJ_METHOD_PARAMS) { int iSize = params.size(); if (iSize<2) return FALSE; CFX_WideString sFormat = params[0].operator CFX_WideString(); CFX_WideString sSource = params[1].operator CFX_WideString(); std::string cFormat = (FX_LPCSTR)CFX_ByteString::FromUnicode(sFormat); std::string cSource = (FX_LPCSTR)CFX_ByteString::FromUnicode(sSource); std::string cDest; printx(cFormat,cSource,cDest); vRet = cDest.c_str(); return TRUE; }
CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) const { CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); if (!pArray) return CFX_WideString(); CPDF_Object* pOption = pArray->GetDirectObjectAt(index); if (!pOption) return CFX_WideString(); if (CPDF_Array* pOptionArray = pOption->AsArray()) pOption = pOptionArray->GetDirectObjectAt(sub_index); CPDF_String* pString = ToString(pOption); return pString ? pString->GetUnicodeText() : CFX_WideString(); }
int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX_UINT Icon) { if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon); bsMsg.ReleaseBuffer(); bsTitle.ReleaseBuffer(); return ret; } return -1; }
CFX_WideString CPDF_CIDFont::UnicodeFromCharCode(uint32_t charcode) const { CFX_WideString str = CPDF_Font::UnicodeFromCharCode(charcode); if (!str.IsEmpty()) return str; FX_WCHAR ret = GetUnicodeFromCharCode(charcode); return ret ? ret : CFX_WideString(); }
CFX_ByteString CFX_FontSourceEnum_File::GetNextFile() { Restart: void* pCurHandle = m_FolderQueue.GetSize() != 0 ? m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->pFileHandle : nullptr; if (!pCurHandle) { if (m_FolderPaths.GetSize() < 1) { return ""; } pCurHandle = FX_OpenFolder(m_FolderPaths[m_FolderPaths.GetSize() - 1].c_str()); FX_HandleParentPath hpp; hpp.pFileHandle = pCurHandle; hpp.bsParentPath = m_FolderPaths[m_FolderPaths.GetSize() - 1]; m_FolderQueue.Add(hpp); } CFX_ByteString bsName; FX_BOOL bFolder; CFX_ByteString bsFolderSpearator = CFX_ByteString::FromUnicode(CFX_WideString(FX_GetFolderSeparator())); while (TRUE) { if (!FX_GetNextFile(pCurHandle, bsName, bFolder)) { FX_CloseFolder(pCurHandle); m_FolderQueue.RemoveAt(m_FolderQueue.GetSize() - 1); if (m_FolderQueue.GetSize() == 0) { m_FolderPaths.RemoveAt(m_FolderPaths.GetSize() - 1); if (m_FolderPaths.GetSize() == 0) { return ""; } else { goto Restart; } } pCurHandle = m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->pFileHandle; continue; } if (bsName == "." || bsName == "..") { continue; } if (bFolder) { FX_HandleParentPath hpp; hpp.bsParentPath = m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + bsFolderSpearator + bsName; hpp.pFileHandle = FX_OpenFolder(hpp.bsParentPath.c_str()); if (!hpp.pFileHandle) { continue; } m_FolderQueue.Add(hpp); pCurHandle = hpp.pFileHandle; continue; } bsName = m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + bsFolderSpearator + bsName; break; } return bsName; }
static CFX_WideString FILESPEC_DecodeFileName(const CFX_WideStringC& filepath) { if (filepath.GetLength() <= 1) { return CFX_WideString(); } #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ if (filepath.Left(sizeof("/Mac") - 1) == CFX_WideStringC(L"/Mac")) { return ChangeSlashToPlatform(filepath.GetPtr() + 1); } return ChangeSlashToPlatform(filepath.GetPtr()); #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ if (filepath.GetAt(0) != '/') { return ChangeSlashToPlatform(filepath.GetPtr()); } if (filepath.GetAt(1) == '/') { return ChangeSlashToPlatform(filepath.GetPtr() + 1); } if (filepath.GetAt(2) == '/') { CFX_WideString result; result += filepath.GetAt(1); result += ':'; result += ChangeSlashToPlatform(filepath.GetPtr() + 2); return result; } CFX_WideString result; result += '\\'; result += ChangeSlashToPlatform(filepath.GetPtr()); return result; #else return filepath; #endif }
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 CFX_WideString(); } 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; }
CFX_WideString Document::CutString(CFX_WideString cbFrom) { size_t iLength = cbFrom.GetLength(); pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t); iSize *= (iLength + 1); wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie()); wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength); for (int i = 0; i < iLength; i++) { if (pFrom[i] == L'\\' || pFrom[i] == L'/') { pResult[i] = L'\0'; break; } pResult[i] = pFrom[i]; } pResult[iLength] = L'\0'; cbFrom.ReleaseBuffer(); CFX_WideString cbRet = CFX_WideString(pResult); free(pResult); pResult = NULL; return cbRet; }
IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadHTMLStandardStyleSheet() { static const FX_WCHAR* s_pStyle = L"html,address,blockquote,body,dd,div,dl,dt,fieldset,form,frame,frameset," L"h1,h2,h3,h4,h5,h6,noframes,ol,p,ul,center,dir,hr,menu,pre{display:" L"block}" L"li{display:list-item}head{display:none}table{display:table}tr{display:" L"table-row}thead{display:table-header-group}tbody{display:table-row-" L"group}tfoot{display:table-footer-group}" L"col{display:table-column}colgroup{display:table-column-group}td,th{" L"display:table-cell}caption{display:table-caption}th{font-weight:bolder;" L"text-align:center}caption{text-align:center}" L"body{margin:0}h1{font-size:2em;margin:.67em " L"0}h2{font-size:1.5em;margin:.75em 0}h3{font-size:1.17em;margin:.83em " L"0}h4,p,blockquote,ul,fieldset,form,ol,dl,dir,menu{margin:1.12em 0}" L"h5{font-size:.83em;margin:1.5em 0}h6{font-size:.75em;margin:1.67em " L"0}h1,h2,h3,h4,h5,h6,b,strong{font-weight:bolder}blockquote{margin-left:" L"40px;margin-right:40px}i,cite,em,var,address{font-style:italic}" L"pre,tt,code,kbd,samp{font-family:monospace}pre{white-space:pre}button," L"textarea,input,select{display:inline-block}big{font-size:1.17em}small," L"sub,sup{font-size:.83em}sub{vertical-align:sub}" L"sup{vertical-align:super}table{border-spacing:2px}thead,tbody,tfoot{" L"vertical-align:middle}td,th,tr{vertical-align:inherit}s,strike,del{" L"text-decoration:line-through}hr{border:1px inset silver}" L"ol,ul,dir,menu,dd{margin-left:40px}ol{list-style-type:decimal}ol ul,ul " L"ol,ul ul,ol " L"ol{margin-top:0;margin-bottom:0}u,ins{text-decoration:underline}center{" L"text-align:center}" L"ruby{display:ruby}rt{display:ruby-text;font-size:.5em}rb{display:ruby-" L"base}rbc{display:ruby-base-group}rtc{display:ruby-text-group}" L"q:before{content:open-quote}q:after{content:close-quote}" L"rp{display:none}"; return IFDE_CSSStyleSheet::LoadFromBuffer( CFX_WideString(), s_pStyle, FXSYS_wcslen(s_pStyle), FX_CODEPAGE_UTF8); }
CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { if (full_name == L"") return nullptr; CFieldNameExtractor name_extractor(full_name); const FX_WCHAR* pName; FX_STRSIZE nLength; name_extractor.GetNext(pName, nLength); Node* pNode = &m_Root; Node* pLast = nullptr; while (nLength > 0 && pNode) { pLast = pNode; CFX_WideString name = CFX_WideString(pName, nLength); pNode = Lookup(pLast, name); name_extractor.GetNext(pName, nLength); } if (pNode && pNode != &m_Root) { for (int i = 0; i < pLast->children.GetSize(); i++) { if (pNode == pLast->children[i]) { pLast->children.RemoveAt(i); break; } } CPDF_FormField* pField = pNode->field_ptr; RemoveNode(pNode); return pField; } return nullptr; }
CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_CharMap* pCharMap) const { CPDF_Object* p = GetElement(key); if (CPDF_Reference* pRef = ToReference(p)) p = pRef->GetDirect(); return p ? p->GetUnicodeText(pCharMap) : CFX_WideString(); }
CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { if (full_name == L"") { return NULL; } CFieldNameExtractor name_extractor(full_name); const FX_WCHAR* pName; FX_STRSIZE nLength; name_extractor.GetNext(pName, nLength); _Node *pNode = &m_Root, *pLast = NULL; while (nLength > 0 && pNode) { pLast = pNode; CFX_WideString name = CFX_WideString(pName, nLength); pNode = _Lookup(pLast, name); name_extractor.GetNext(pName, nLength); } if (pNode && pNode != &m_Root) { CFX_PtrArray& ptr_array = pLast->children; for (int i = 0; i < ptr_array.GetSize(); i++) { if (pNode == (_Node*)ptr_array[i]) { ptr_array.RemoveAt(i); break; } } CPDF_FormField* pField = pNode->field_ptr; RemoveNode(pNode); return pField; } return NULL; }
v8::Handle<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* PropertyName, int Len = -1) { CFX_WideString ws = CFX_WideString(PropertyName,Len); CFX_ByteString bs = ws.UTF8Encode(); if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent(); return v8::String::NewFromUtf8(pJSRuntime, bs.c_str()); }
CFX_WideString CFPF_SkiaFont::GetPsName() { if (!m_Face) { return CFX_WideString(); } return CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m_Face)); }
int FXJS_Execute(v8::Isolate* pIsolate, IJS_Context* pJSContext, const wchar_t* script, FXJSErr* pError) { v8::Isolate::Scope isolate_scope(pIsolate); v8::TryCatch try_catch(pIsolate); CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); v8::Local<v8::Script> compiled_script; if (!v8::Script::Compile( context, v8::String::NewFromUtf8( pIsolate, bsScript.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked()) .ToLocal(&compiled_script)) { v8::String::Utf8Value error(try_catch.Exception()); // TODO(tsepez): return error via pError->message. return -1; } v8::Local<v8::Value> result; if (!compiled_script->Run(context).ToLocal(&result)) { v8::String::Utf8Value error(try_catch.Exception()); // TODO(tsepez): return error via pError->message. return -1; } return 0; }
CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { if (this == NULL) { return CFX_WideString(); } if (m_Type == PDFOBJ_STRING) { return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); } else if (m_Type == PDFOBJ_STREAM) { CPDF_StreamAcc stream; stream.LoadAllData((CPDF_Stream*)this, FALSE); CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); return result; } else if (m_Type == PDFOBJ_NAME) { return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); } return CFX_WideString(); }
TEST_F(FXJSV8EmbedderTest, Getters) { v8::Isolate::Scope isolate_scope(isolate()); v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope(GetV8Context()); ExecuteInCurrentContext(CFX_WideString(kScript1)); CheckAssignmentInCurrentContext(kExpected1); }
CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { return CFX_WideString(); } CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index); if (pOption == NULL) { return CFX_WideString(); } if (pOption->GetType() == PDFOBJ_ARRAY) { pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index); } if (pOption == NULL || pOption->GetType() != PDFOBJ_STRING) { return CFX_WideString(); } return ((CPDF_String*)pOption)->GetUnicodeText(); }
CFX_WideString CPWL_ComboBox::GetText() const { if (m_pEdit) { return m_pEdit->GetText(); } return CFX_WideString(); }
CFX_WideString CXML_Element::GetContent(uint32_t index) const { if (index < m_Children.size() && m_Children[index].type == Content) { CXML_Content* pContent = static_cast<CXML_Content*>(m_Children[index].child); if (pContent) return pContent->m_Content; } return CFX_WideString(); }
FX_BOOL CXML_Element::GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const { const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); if (pValue) { attribute = CFX_WideString((FX_LPCWSTR)pValue, pValue->GetLength()); return TRUE; } return FALSE; }
void CFXJS_Engine::DefineObjConst(int nObjDefnID, const wchar_t* sConstName, v8::Local<v8::Value> pDefault) { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); CFX_ByteString bsConstName = CFX_WideString(sConstName).UTF8Encode(); CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(m_isolate, nObjDefnID); pObjDef->GetInstanceTemplate()->Set(m_isolate, bsConstName.c_str(), pDefault); }
void CPDFDoc_Environment::JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL) { if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm) { CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength()); m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination); bsDestination.ReleaseBuffer(); } }
CFX_WideString CPDF_Bookmark::GetTitle() { if (!m_pDict) { return CFX_WideString(); } CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); if (pString == NULL || pString->GetType() != PDFOBJ_STRING) { return CFX_WideString(); } CFX_WideString title = pString->GetUnicodeText(); FX_LPWSTR buf = title.LockBuffer(); int len = title.GetLength(), i; for (i = 0; i < len; i ++) if (buf[i] < 0x20) { buf[i] = 0x20; } title.ReleaseBuffer(len); return title; }
v8::Local<v8::String> FXJS_WSToJSString(v8::Isolate* pIsolate, const wchar_t* PropertyName, int Len) { CFX_WideString ws = CFX_WideString(PropertyName, Len); CFX_ByteString bs = ws.UTF8Encode(); if (!pIsolate) pIsolate = v8::Isolate::GetCurrent(); return v8::String::NewFromUtf8(pIsolate, bs.c_str(), v8::NewStringType::kNormal).ToLocalChecked(); }
CFX_WideString CFX_Font::GetPsName() const { if (m_Face == NULL) { return CFX_WideString(); } CFX_WideString psName = CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m_Face)); if (psName.IsEmpty()) { psName = CFX_WideString::FromLocal("Untitled"); } return psName; }
CFX_WideString CFX_WideString::FromUTF8(const char* str, FX_STRSIZE len) { if (!str || 0 == len) { return CFX_WideString(); } CFX_UTF8Decoder decoder; for (FX_STRSIZE i = 0; i < len; i++) { decoder.Input(str[i]); } return decoder.GetResult(); }
void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall) { v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode(); GetGlobalObjectTemplate(pIsolate)->Set( v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(), v8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(pIsolate, pMethodCall), v8::ReadOnly); }
void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, const wchar_t* sConstName, v8::Local<v8::Value> pDefault) { v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode(); GetGlobalObjectTemplate(pIsolate)->Set( v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), v8::NewStringType::kNormal).ToLocalChecked(), pDefault, v8::ReadOnly); }