Commit b9329651 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov
parent 59895cdf
......@@ -17,10 +17,14 @@ DEFINES += \
linux-g++ | linux-g++-64 | linux-g++-32 {
DEFINES += \
HAVE_UNISTD_H \
LINUX \
_LINUX \
_LINUX_QT
message(linux)
QMAKE_CXXFLAGS += -std=c++0x -pthread
LIBS += -pthread
}
mac {
......
......@@ -107,7 +107,10 @@ namespace NSCommon
{
if (NULL == m_pData)
{
m_lSize = max(nSize, 1000);
m_lSize = 1000;
if (nSize > m_lSize)
m_lSize = nSize;
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
m_lSizeCur = 0;
......@@ -198,8 +201,7 @@ namespace NSCommon
inline void WriteString(const wchar_t* pString, const size_t& nLen)
{
AddSize(nLen);
//memcpy(m_pDataCur, pString, nLen * sizeof(wchar_t));
memcpy(m_pDataCur, pString, nLen << 1);
memcpy(m_pDataCur, pString, nLen * sizeof(wchar_t));
m_pDataCur += nLen;
m_lSizeCur += nLen;
}
......@@ -507,8 +509,24 @@ namespace NSCommon
BOOL bIsSymbol = FALSE;
if (pManager->m_pFont)
{
bIsSymbol = (-1 != (pManager->m_pFont->m_nSymbolic)) ? TRUE : FALSE;
if (!bIsSymbol)
{
TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pManager->m_pFont->m_pFace, ft_sfnt_os2);
int y = 0;
++y;
if (NULL != pOS2)
{
if (0 == (pOS2->ulCodePageRange1 & 0xF0000000))
bIsSymbol = TRUE;
}
}
}
if (bIsSymbol)
{
CFontSelectFormat oSelectFormat;
......@@ -517,7 +535,7 @@ namespace NSCommon
if (NULL != pInfoCur)
{
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, lFaceIndex, 14, dDpi, dDpi);
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, 0, 14, dDpi, dDpi);
}
oRenderer.put_FontPath(pInfoCur->m_wsFontPath);
}
......@@ -588,15 +606,17 @@ namespace NSCommon
{
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(arrFonts[index]);
wchar_t buffer[1000];
swprintf(buffer, L"\",%d,%d,%d,%d,%d,%d,%d,%d]", pPair->second.m_lIndexR, pPair->second.m_lFaceIndexR,
char buffer[1000];
sprintf(buffer, "\",%d,%d,%d,%d,%d,%d,%d,%d]", pPair->second.m_lIndexR, pPair->second.m_lFaceIndexR,
pPair->second.m_lIndexI, pPair->second.m_lFaceIndexI,
pPair->second.m_lIndexB, pPair->second.m_lFaceIndexB,
pPair->second.m_lIndexBI, pPair->second.m_lFaceIndexBI);
std::string sBuffer(buffer);
oWriterJS += L"[\"";
oWriterJS += pPair->second.m_sName;
oWriterJS += std::wstring(buffer);
oWriterJS += NSFile::CUtf8Converter::GetUnicodeFromCharPtr(sBuffer);
if (index != (nCountFonts - 1))
oWriterJS += (L",\n");
......@@ -647,7 +667,11 @@ namespace NSCommon
}
}
#ifdef WIN32
int wmain(int argc, wchar_t** argv)
#else
int main(int argc, char** argv)
#endif
{
#if 0
char buf[10];
......@@ -660,6 +684,9 @@ int wmain(int argc, wchar_t** argv)
wcout << "]";
#endif
#if 0
#ifdef WIN32
std::wstring strFontsFolder = L"";
if (1 < argc)
strFontsFolder = std::wstring(argv[1]);
......@@ -672,12 +699,38 @@ int wmain(int argc, wchar_t** argv)
std::wstring strFontsSelectionBin = L"";
if (4 < argc)
strFontsSelectionBin = std::wstring(argv[4]);
#else
std::wstring strFontsFolder = L"";
if (1 < argc)
strFontsFolder = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)argv[1], (LONG)strlen(argv[1]));
std::wstring strAllFontsJSPath = L"";
if (2 < argc)
strAllFontsJSPath = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)argv[2], (LONG)strlen(argv[2]));
std::wstring strThumbnailsFolder = L"";
if (3 < argc)
strThumbnailsFolder = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)argv[3], (LONG)strlen(argv[3]));
std::wstring strFontsSelectionBin = L"";
if (4 < argc)
strFontsSelectionBin = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)argv[4], (LONG)strlen(argv[4]));
#endif
#endif
#if 1
#ifdef WIN32
std::wstring strFontsFolder = L"C:/Windows/Fonts";
std::wstring strAllFontsJSPath = L"D:/AllFontsGenTest/AllFonts.js";
std::wstring strThumbnailsFolder = L"D:/AllFontsGenTest";
std::wstring strFontsSelectionBin = L"D:/AllFontsGenTest/font_selection.bin";
#endif
#ifdef _LINUX
std::wstring strFontsFolder = L"";
std::wstring strAllFontsJSPath = L"/home/oleg/AllFontsGen/AllFonts.js";
std::wstring strThumbnailsFolder = L"/home/oleg/AllFontsGen/";
std::wstring strFontsSelectionBin = L"/home/oleg/AllFontsGen/font_selection.bin";
#endif
#if 0
strFontsFolder = L"C:/Windows/Fonts";
strAllFontsJSPath = L"D:/AllFontsGenTest/AllFonts.js";
strThumbnailsFolder = L"D:/AllFontsGenTest";
strFontsSelectionBin = L"D:/AllFontsGenTest/font_selection.bin";
#endif
CApplicationFonts oApplicationF;
......
......@@ -184,6 +184,8 @@ public:
int nNewAllocSize = nAllocSize;
m_aT = (T*)::calloc(nNewAllocSize, sizeof(T));
for (int i = 0; i < nNewAllocSize; i++)
::new(m_aT + i) T;
if (NULL == m_aT)
return FALSE;
......@@ -199,9 +201,10 @@ public:
{
if (m_nSize == m_nAllocSize)
{
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
T* newT = (T*)::calloc(nNewAllocSize, sizeof(T));
T* newT = (T*)::calloc(nNewAllocSize, sizeof(T));
//T* newT = (T*)malloc(nNewAllocSize * sizeof(T));
if (NULL == newT)
return FALSE;
......@@ -216,6 +219,7 @@ public:
m_aT = newT;
}
::new(m_aT + m_nSize) T;
m_nSize++;
return TRUE;
}
......
......@@ -19,54 +19,75 @@
namespace NSDirectory
{
static CArray<std::wstring> GetFiles(std::wstring strDirectory)
{
CArray<std::wstring> oArray;
static void GetFiles2(std::wstring strDirectory, CArray<std::wstring>& oArray, bool bIsRecursion = false)
{
#ifdef WIN32
WIN32_FIND_DATAW oFD;
std::wstring sSpec = strDirectory + L"\\*.*";
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
if( INVALID_HANDLE_VALUE == hRes )
return oArray;
do
{
sSpec = oFD.cFileName;
if (sSpec != L"." && sSpec != L"..")
{
sSpec = strDirectory + L"\\" + sSpec;
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
oArray.Add(sSpec);
}
}
} while( FindNextFileW( hRes, &oFD ) );
FindClose( hRes );
#elif LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
WIN32_FIND_DATAW oFD;
std::wstring sSpec = strDirectory + L"\\*.*";
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
if( INVALID_HANDLE_VALUE == hRes )
return;
do
{
sSpec = oFD.cFileName;
if (sSpec != L"." && sSpec != L"..")
{
sSpec = strDirectory + L"\\" + sSpec;
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
oArray.Add(sSpec);
}
else if (bIsRecursion)
{
GetFiles2(sSpec, oArray, bIsRecursion);
}
}
} while( FindNextFileW( hRes, &oFD ) );
FindClose( hRes );
#endif
#ifdef LINUX
BYTE* pUtf8 = NULL;
LONG lLen = 0;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
DIR *dp;
struct dirent *dirp;
if((dp = opendir((char*)pUtf8)) != NULL)
{
while ((dirp = readdir(dp)) != NULL)
{
if(DT_REG == dirp->d_type)
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
oArray.Add(strDirectory + L"/" + sName);
}
}
closedir(dp);
}
delete [] pUtf8;
#elif MAC
DIR *dp;
struct dirent *dirp;
if((dp = opendir((char*)pUtf8)) != NULL)
{
while ((dirp = readdir(dp)) != NULL)
{
if(DT_REG == dirp->d_type)
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
oArray.Add(strDirectory + L"/" + sName);
}
if (bIsRecursion && DT_DIR == dirp->d_type)
{
if(dirp->d_name[0] != '.')
{
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
}
}
}
closedir(dp);
}
delete [] pUtf8;
#endif
#ifdef MAC
#endif
}
static CArray<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion = false)
{
CArray<std::wstring> oArray;
GetFiles2(strDirectory, oArray, bIsRecursion);
return oArray;
}
static CArray<std::wstring> GetDirectories(std::wstring strDirectory)
{
CArray<std::wstring> oArray;
......
......@@ -13,6 +13,10 @@
#include <windows.h>
#endif
#if defined(_LINUX) || defined(_MAC) && !defined(_IOS)
#include <unistd.h>
#endif
//#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
//перенесено выше
namespace NSFile
......@@ -43,55 +47,7 @@ namespace NSFile
{
RELEASEARRAYOBJECTS(Data);
}
};
#define NS_FILE_MAX_PATH 32768
static std::wstring GetProcessPath()
{
#ifdef WIN32
wchar_t buf[NS_FILE_MAX_PATH];
GetModuleFileNameW(GetModuleHandleW(NULL), buf, NS_FILE_MAX_PATH);
return std::wstring(buf);
#else
#if defined(_LINUX) || defined(_MAC) && !defined(_IOS)
char buf[NS_FILE_MAX_PATH];
if (readlink ("/proc/self/exe", buf, NS_FILE_MAX_PATH) <= 0)
return L"";
std::string sUTF8(buf);
std::wstring sRet = CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sUTF8.c_str(), sUTF8.length());
return sRet;
#endif
#endif
return L"";
}
static std::wstring GetProcessDirectory()
{
std::wstring sPath = GetProcessPath();
size_t pos1 = sPath.find_last_of(wchar_t('/'));
size_t pos2 = sPath.find_last_of(wchar_t('\\'));
size_t pos = std::wstring::npos;
if (pos1 != std::wstring::npos)
pos = pos1;
if (pos2 != std::wstring::npos)
{
if (pos == std::wstring::npos)
pos = pos2;
else if (pos2 > pos)
pos = pos2;
}
if (pos != std::wstring::npos)
{
sPath = sPath.substr(0, pos);
}
return sPath;
}
};
class CUtf8Converter
{
......@@ -769,4 +725,55 @@ namespace NSFile
};
}
namespace NSFile
{
#define NS_FILE_MAX_PATH 32768
static std::wstring GetProcessPath()
{
#ifdef WIN32
wchar_t buf[NS_FILE_MAX_PATH];
GetModuleFileNameW(GetModuleHandleW(NULL), buf, NS_FILE_MAX_PATH);
return std::wstring(buf);
#else
#if defined(_LINUX) || defined(_MAC) && !defined(_IOS)
char buf[NS_FILE_MAX_PATH];
if (readlink ("/proc/self/exe", buf, NS_FILE_MAX_PATH) <= 0)
return L"";
std::string sUTF8(buf);
std::wstring sRet = CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sUTF8.c_str(), sUTF8.length());
return sRet;
#endif
#endif
return L"";
}
static std::wstring GetProcessDirectory()
{
std::wstring sPath = GetProcessPath();
size_t pos1 = sPath.find_last_of(wchar_t('/'));
size_t pos2 = sPath.find_last_of(wchar_t('\\'));
size_t pos = std::wstring::npos;
if (pos1 != std::wstring::npos)
pos = pos1;
if (pos2 != std::wstring::npos)
{
if (pos == std::wstring::npos)
pos = pos2;
else if (pos2 > pos)
pos = pos2;
}
if (pos != std::wstring::npos)
{
sPath = sPath.substr(0, pos);
}
return sPath;
}
}
#endif //_BUILD_FILE_CROSSPLATFORM_H_
......@@ -1417,6 +1417,12 @@ void CFontList::LoadFromArrayFiles(CArray<std::wstring>& oArray)
EFontFormat eFormat = GetFontFormat( pFace );
if (eFormat != fontTrueType)
{
FT_Done_Face( pFace );
continue;
}
std::string sFamilyName = "";
if (NULL != pFace->family_name)
sFamilyName = pFace->family_name;
......@@ -1464,7 +1470,7 @@ void CFontList::LoadFromArrayFiles(CArray<std::wstring>& oArray)
}
void CFontList::LoadFromFolder(const std::wstring& strDirectory)
{
CArray<std::wstring> oArray = NSDirectory::GetFiles(strDirectory);
CArray<std::wstring> oArray = NSDirectory::GetFiles(strDirectory, true);
this->LoadFromArrayFiles(oArray);
}
......@@ -1560,9 +1566,13 @@ void CApplicationFonts::Initialize(bool bIsCheckSelection)
#ifdef WIN32
//m_oList.LoadFromFolder(L"C:/Windows/Fonts");
InitFromReg();
#elif LINUX
#endif
#if defined(_LINUX) && !defined(_MAC)
m_oList.LoadFromFolder(L"/usr/share/fonts");
#elif MAC
#endif
#if defined(_MAC) && !defined(_IOS)
m_oList.LoadFromFolder(L"/Library/Fonts/");
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment