diff options
-rw-r--r-- | core/fxcrt/fx_basic_util.cpp | 153 | ||||
-rw-r--r-- | core/fxcrt/fx_stream.h | 47 | ||||
-rw-r--r-- | core/fxge/android/fpf_skiafontmgr.cpp | 23 | ||||
-rw-r--r-- | core/fxge/ge/cfx_folderfontinfo.cpp | 6 | ||||
-rw-r--r-- | xfa/fgas/font/fgas_stdfontmgr.cpp | 24 | ||||
-rw-r--r-- | xfa/fgas/font/fgas_stdfontmgr.h | 2 |
6 files changed, 100 insertions, 155 deletions
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index ae3959bdb9..df22d4bf24 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -7,13 +7,6 @@ #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_ext.h" -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ -#include <dirent.h> -#include <sys/types.h> -#else -#include <direct.h> -#endif - #include <algorithm> #include <cctype> #include <limits> @@ -85,6 +78,7 @@ static const FX_FLOAT fraction_scales[] = { 0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, 0.000000001f, 0.0000000001f, 0.00000000001f}; + int FXSYS_FractionalScaleCount() { return FX_ArraySize(fraction_scales); } @@ -107,16 +101,14 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { cc++; } while (cc < len) { - if (strc[cc] != '+' && strc[cc] != '-') { + if (strc[cc] != '+' && strc[cc] != '-') break; - } cc++; } FX_FLOAT value = 0; while (cc < len) { - if (strc[cc] == '.') { + if (strc[cc] == '.') break; - } value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); cc++; } @@ -145,36 +137,15 @@ void FXSYS_snprintf(char* str, FXSYS_vsnprintf(str, size, fmt, ap); va_end(ap); } + void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap) { (void)_vsnprintf(str, size, fmt, ap); - if (size) { + if (size) str[size - 1] = 0; - } } #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -class CFindFileData { - public: - virtual ~CFindFileData() {} - HANDLE m_Handle; - FX_BOOL m_bEnd; -}; - -class CFindFileDataA : public CFindFileData { - public: - ~CFindFileDataA() override {} - WIN32_FIND_DATAA m_FindData; -}; - -class CFindFileDataW : public CFindFileData { - public: - ~CFindFileDataW() override {} - WIN32_FIND_DATAW m_FindData; -}; -#endif - -void* FX_OpenFolder(const FX_CHAR* path) { +FX_FileHandle* FX_OpenFolder(const FX_CHAR* path) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ std::unique_ptr<CFindFileDataA> pData(new CFindFileDataA); pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), @@ -183,101 +154,54 @@ void* FX_OpenFolder(const FX_CHAR* path) { if (pData->m_Handle == INVALID_HANDLE_VALUE) return nullptr; - pData->m_bEnd = FALSE; + pData->m_bEnd = false; return pData.release(); #else - DIR* dir = opendir(path); - return dir; + return opendir(path); #endif } -void* FX_OpenFolder(const FX_WCHAR* path) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - std::unique_ptr<CFindFileDataW> pData(new CFindFileDataW); - pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), - FindExInfoStandard, &pData->m_FindData, - FindExSearchNameMatch, nullptr, 0); - if (pData->m_Handle == INVALID_HANDLE_VALUE) - return nullptr; +bool FX_GetNextFile(FX_FileHandle* handle, + CFX_ByteString* filename, + bool* bFolder) { + if (!handle) + return false; - pData->m_bEnd = FALSE; - return pData.release(); -#else - DIR* dir = opendir(CFX_ByteString::FromUnicode(path).c_str()); - return dir; -#endif -} -FX_BOOL FX_GetNextFile(void* handle, - CFX_ByteString& filename, - FX_BOOL& bFolder) { - if (!handle) { - return FALSE; - } #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - CFindFileDataA* pData = (CFindFileDataA*)handle; - if (pData->m_bEnd) - return FALSE; - - filename = pData->m_FindData.cFileName; - bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) - pData->m_bEnd = TRUE; - return TRUE; -#elif defined(__native_client__) - abort(); - return FALSE; -#else - struct dirent* de = readdir((DIR*)handle); - if (!de) { - return FALSE; - } - filename = de->d_name; - bFolder = de->d_type == DT_DIR; - return TRUE; -#endif -} -FX_BOOL FX_GetNextFile(void* handle, - CFX_WideString& filename, - FX_BOOL& bFolder) { - if (!handle) { - return FALSE; - } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - CFindFileDataW* pData = (CFindFileDataW*)handle; - if (pData->m_bEnd) { - return FALSE; - } - filename = pData->m_FindData.cFileName; - bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { - pData->m_bEnd = TRUE; - } - return TRUE; + if (handle->m_bEnd) + return false; + + *filename = handle->m_FindData.cFileName; + *bFolder = + (handle->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + if (!FindNextFileA(handle->m_Handle, &handle->m_FindData)) + handle->m_bEnd = true; + return true; #elif defined(__native_client__) abort(); - return FALSE; + return false; #else - struct dirent* de = readdir((DIR*)handle); - if (!de) { - return FALSE; - } - filename = CFX_WideString::FromLocal(de->d_name); - bFolder = de->d_type == DT_DIR; - return TRUE; + struct dirent* de = readdir(handle); + if (!de) + return false; + *filename = de->d_name; + *bFolder = de->d_type == DT_DIR; + return true; #endif } -void FX_CloseFolder(void* handle) { - if (!handle) { + +void FX_CloseFolder(FX_FileHandle* handle) { + if (!handle) return; - } + #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - CFindFileData* pData = (CFindFileData*)handle; - FindClose(pData->m_Handle); - delete pData; + FindClose(handle->m_Handle); + delete handle; #else - closedir((DIR*)handle); + closedir(handle); #endif } + FX_WCHAR FX_GetFolderSeparator() { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ return '\\'; @@ -330,7 +254,8 @@ uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) { bitMask = (1 << std::min(bitOffset, nbits)) - 1; dstShift = nbits - bitOffset; } - uint32_t result = (uint32_t)(*dataPtr++ >> bitShift & bitMask) << dstShift; + uint32_t result = + static_cast<uint32_t>((*dataPtr++ >> bitShift & bitMask) << dstShift); while (dstShift >= 8) { dstShift -= 8; result |= *dataPtr++ << dstShift; diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h index 5a5a650650..047fedf9bb 100644 --- a/core/fxcrt/fx_stream.h +++ b/core/fxcrt/fx_stream.h @@ -10,22 +10,18 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -void* FX_OpenFolder(const FX_CHAR* path); -void* FX_OpenFolder(const FX_WCHAR* path); -FX_BOOL FX_GetNextFile(void* handle, - CFX_ByteString& filename, - FX_BOOL& bFolder); -FX_BOOL FX_GetNextFile(void* handle, - CFX_WideString& filename, - FX_BOOL& bFolder); -void FX_CloseFolder(void* handle); -FX_WCHAR FX_GetFolderSeparator(); - #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +#include <direct.h> + +class CFindFileDataA; + +typedef CFindFileDataA FX_FileHandle; #define FX_FILESIZE int32_t #else +#include <dirent.h> #include <fcntl.h> #include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> #ifndef O_BINARY @@ -36,9 +32,17 @@ FX_WCHAR FX_GetFolderSeparator(); #define O_LARGEFILE 0 #endif // O_LARGEFILE +typedef DIR FX_FileHandle; #define FX_FILESIZE off_t #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +FX_FileHandle* FX_OpenFolder(const FX_CHAR* path); +bool FX_GetNextFile(FX_FileHandle* handle, + CFX_ByteString* filename, + bool* bFolder); +void FX_CloseFolder(FX_FileHandle* handle); +FX_WCHAR FX_GetFolderSeparator(); + #define FX_GETBYTEOFFSET32(a) 0 #define FX_GETBYTEOFFSET40(a) 0 #define FX_GETBYTEOFFSET48(a) 0 @@ -159,4 +163,25 @@ class IFX_BufferRead : public IFX_StreamRead { virtual FX_FILESIZE GetBlockOffset() = 0; }; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +class CFindFileData { + public: + virtual ~CFindFileData() {} + HANDLE m_Handle; + bool m_bEnd; +}; + +class CFindFileDataA : public CFindFileData { + public: + ~CFindFileDataA() override {} + WIN32_FIND_DATAA m_FindData; +}; + +class CFindFileDataW : public CFindFileData { + public: + ~CFindFileDataW() override {} + WIN32_FIND_DATAW m_FindData; +}; +#endif + #endif // CORE_FXCRT_FX_STREAM_H_ diff --git a/core/fxge/android/fpf_skiafontmgr.cpp b/core/fxge/android/fpf_skiafontmgr.cpp index 9452c11747..3ecacd387c 100644 --- a/core/fxge/android/fpf_skiafontmgr.cpp +++ b/core/fxge/android/fpf_skiafontmgr.cpp @@ -399,36 +399,35 @@ FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, FXFT_Set_Pixel_Sizes(face, 0, 64); return face; } + void CFPF_SkiaFontMgr::ScanPath(const CFX_ByteString& path) { - void* handle = FX_OpenFolder(path.c_str()); + DIR* handle = FX_OpenFolder(path.c_str()); if (!handle) { return; } CFX_ByteString filename; - FX_BOOL bFolder = FALSE; - while (FX_GetNextFile(handle, filename, bFolder)) { + bool bFolder = false; + while (FX_GetNextFile(handle, &filename, &bFolder)) { if (bFolder) { - if (filename == "." || filename == "..") { + if (filename == "." || filename == "..") continue; - } } else { CFX_ByteString ext = filename.Right(4); ext.MakeLower(); - if (ext != ".ttf" && ext != ".ttc" && ext != ".otf") { + if (ext != ".ttf" && ext != ".ttc" && ext != ".otf") continue; - } } CFX_ByteString fullpath(path); fullpath += "/"; fullpath += filename; - if (bFolder) { + if (bFolder) ScanPath(fullpath); - } else { + else ScanFile(fullpath); - } } FX_CloseFolder(handle); } + void CFPF_SkiaFontMgr::ScanFile(const CFX_ByteString& file) { FXFT_Face face = GetFontFace(file.AsStringC()); if (face) { @@ -439,6 +438,7 @@ void CFPF_SkiaFontMgr::ScanFile(const CFX_ByteString& file) { FXFT_Done_Face(face); } } + static const uint32_t g_FPFSkiaFontCharsets[] = { FPF_SKIACHARSET_Ansi, FPF_SKIACHARSET_EeasternEuropean, @@ -473,6 +473,7 @@ static const uint32_t g_FPFSkiaFontCharsets[] = { FPF_SKIACHARSET_OEM, FPF_SKIACHARSET_Symbol, }; + static uint32_t FPF_SkiaGetFaceCharset(TT_OS2* pOS2) { uint32_t dwCharset = 0; if (pOS2) { @@ -485,6 +486,7 @@ static uint32_t FPF_SkiaGetFaceCharset(TT_OS2* pOS2) { dwCharset |= FPF_SKIACHARSET_Default; return dwCharset; } + void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, CFPF_SkiaFontDescriptor* pFontDesc) { if (!face || !pFontDesc) { @@ -519,5 +521,6 @@ void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, pFontDesc->m_iFaceIndex = face->face_index; pFontDesc->m_iGlyphNum = face->num_glyphs; } + void CFPF_SkiaFontMgr::OutputSystemFonts() {} #endif diff --git a/core/fxge/ge/cfx_folderfontinfo.cpp b/core/fxge/ge/cfx_folderfontinfo.cpp index 31608bdf3a..393f74bbd9 100644 --- a/core/fxge/ge/cfx_folderfontinfo.cpp +++ b/core/fxge/ge/cfx_folderfontinfo.cpp @@ -116,13 +116,13 @@ FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) { } void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) { - void* handle = FX_OpenFolder(path.c_str()); + FX_FileHandle* handle = FX_OpenFolder(path.c_str()); if (!handle) return; CFX_ByteString filename; - FX_BOOL bFolder; - while (FX_GetNextFile(handle, filename, bFolder)) { + bool bFolder; + while (FX_GetNextFile(handle, &filename, &bFolder)) { if (bFolder) { if (filename == "." || filename == "..") continue; diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp index de72628760..59bd272a93 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.cpp +++ b/xfa/fgas/font/fgas_stdfontmgr.cpp @@ -486,15 +486,13 @@ CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() { CFX_FontSourceEnum_File::~CFX_FontSourceEnum_File() {} CFX_ByteString CFX_FontSourceEnum_File::GetNextFile() { -Restart: - void* pCurHandle = + FX_FileHandle* pCurHandle = m_FolderQueue.GetSize() != 0 ? m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->pFileHandle : nullptr; if (!pCurHandle) { - if (m_FolderPaths.GetSize() < 1) { + if (m_FolderPaths.GetSize() < 1) return ""; - } pCurHandle = FX_OpenFolder(m_FolderPaths[m_FolderPaths.GetSize() - 1].c_str()); FX_HandleParentPath hpp; @@ -503,37 +501,31 @@ Restart: m_FolderQueue.Add(hpp); } CFX_ByteString bsName; - FX_BOOL bFolder; + bool bFolder; CFX_ByteString bsFolderSpearator = CFX_ByteString::FromUnicode(CFX_WideString(FX_GetFolderSeparator())); - while (TRUE) { - if (!FX_GetNextFile(pCurHandle, bsName, bFolder)) { + 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; - } + return m_FolderPaths.GetSize() != 0 ? GetNextFile() : ""; } pCurHandle = m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->pFileHandle; continue; } - if (bsName == "." || bsName == "..") { + 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) { + if (!hpp.pFileHandle) continue; - } m_FolderQueue.Add(hpp); pCurHandle = hpp.pFileHandle; continue; diff --git a/xfa/fgas/font/fgas_stdfontmgr.h b/xfa/fgas/font/fgas_stdfontmgr.h index 9d5cb68070..785a47f854 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.h +++ b/xfa/fgas/font/fgas_stdfontmgr.h @@ -122,7 +122,7 @@ struct FX_HandleParentPath { pFileHandle = x.pFileHandle; bsParentPath = x.bsParentPath; } - void* pFileHandle; + FX_FileHandle* pFileHandle; CFX_ByteString bsParentPath; }; |