void CFX_FolderFontInfo::ScanPath(CFX_ByteString& path) { void* handle = FX_OpenFolder(path); if (handle == NULL) { return; } CFX_ByteString filename; FX_BOOL bFolder; while (FX_GetNextFile(handle, filename, bFolder)) { if (bFolder) { if (filename == "." || filename == "..") { continue; } } else { CFX_ByteString ext = filename.Right(4); ext.MakeUpper(); if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC") { continue; } } CFX_ByteString fullpath = path; #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ fullpath += "\\"; #else fullpath += "/"; #endif fullpath += filename; if (bFolder) { ScanPath(fullpath); } else { ScanFile(fullpath); } } FX_CloseFolder(handle); }
void CFPF_SkiaFontMgr::ScanPath(FX_BSTR path) { void *handle = FX_OpenFolder(path.GetCStr()); if (!handle) { return; } CFX_ByteString filename; FX_BOOL bFolder = FALSE; while (FX_GetNextFile(handle, filename, bFolder)) { if (bFolder) { if (filename == FX_BSTRC(".") || filename == FX_BSTRC("..")) { continue; } } else { CFX_ByteString ext = filename.Right(4); ext.MakeLower(); if (ext != FX_BSTRC(".ttf") && ext != FX_BSTRC(".ttc")) { continue; } } CFX_ByteString fullpath = path; fullpath += "/"; fullpath += filename; if (bFolder) { ScanPath(fullpath); } else { ScanFile(fullpath); } } FX_CloseFolder(handle); }
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; }
IFX_LocaleMgr* FX_LocaleMgr_Create(const FX_WCHAR* pszLocalPath, FX_WORD wDefaultLCID) { void* pPathHandle = FX_OpenFolder(pszLocalPath); if (!pPathHandle) { return NULL; } CFX_LocaleMgr* pLocaleMgr = new CFX_LocaleMgr(wDefaultLCID); CFX_WideString wsFileName; FX_BOOL bFolder = FALSE; while (FX_GetNextFile(pPathHandle, wsFileName, bFolder)) { if (!bFolder) { if (wsFileName.GetLength() < 4) { continue; } CFX_WideString wsExt = wsFileName.Right(4); wsExt.MakeLower(); if (wsExt != L".xml") { continue; } CFX_WideString wsFullPath(pszLocalPath); wsFullPath += L"\\" + wsFileName; IFX_FileRead* pRead = FX_CreateFileRead(wsFullPath); if (!pRead) { continue; } CXML_Element* pXmlLocale = CXML_Element::Parse(pRead); pRead->Release(); CFX_ByteString bssp = pXmlLocale->GetNamespace(); if (bssp == "http://www.foxitsoftware.com/localization") { CFX_WideString wsLCID = pXmlLocale->GetAttrValue("", "lcid"); wchar_t* pEnd = NULL; FX_DWORD dwLCID = wcstol(wsLCID, &pEnd, 16); if (pLocaleMgr->m_lcid2xml.GetValueAt((void*)(uintptr_t)dwLCID)) { delete pXmlLocale; } else { pLocaleMgr->m_lcid2xml.SetAt((void*)(uintptr_t)dwLCID, pXmlLocale); } } else { delete pXmlLocale; } } } FX_CloseFolder(pPathHandle); return pLocaleMgr; }