Commit 07ff1a34 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

full realize windows AllFontsGen

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@60507 954022d7-b5bf-4e40-9824-e11837661b57
parent 2e5b3f77
...@@ -314,7 +314,7 @@ namespace NSCommon ...@@ -314,7 +314,7 @@ namespace NSCommon
} }
}; };
void SaveAllFontsJS(CApplicationFonts& applicationFonts, std::wstring strFile, std::wstring strFolderThumbnails = L"") void SaveAllFontsJS(CApplicationFonts& applicationFonts, std::wstring strFile, std::wstring strFolderThumbnails, std::wstring strFontSelectionBin)
{ {
CArray<CFontInfo*>* pList = applicationFonts.GetList()->GetFonts(); CArray<CFontInfo*>* pList = applicationFonts.GetList()->GetFonts();
int nCount = pList->GetCount(); int nCount = pList->GetCount();
...@@ -429,14 +429,13 @@ namespace NSCommon ...@@ -429,14 +429,13 @@ namespace NSCommon
} }
} }
// ------------------------------------------- // -------------------------------------------
if (L"" != strFolderThumbnails)
{
CFontManager* pManager = applicationFonts.GenerateFontManager(); CFontManager* pManager = applicationFonts.GenerateFontManager();
CFontsCache* pCache = new CFontsCache(); CFontsCache* pCache = new CFontsCache();
pCache->SetStreams(applicationFonts.GetStreams()); pCache->SetStreams(applicationFonts.GetStreams());
pManager->SetOwnerCache(pCache); pManager->SetOwnerCache(pCache);
if (L"" != strFolderThumbnails)
{
for (int iX = 1; iX <= 2; ++iX) for (int iX = 1; iX <= 2; ++iX)
{ {
// создаем картинку для табнейлов // создаем картинку для табнейлов
...@@ -538,11 +537,13 @@ namespace NSCommon ...@@ -538,11 +537,13 @@ namespace NSCommon
oFrame.SaveFile(strThumbnailPath, 4); oFrame.SaveFile(strThumbnailPath, 4);
} }
RELEASEOBJECT(pManager);
} }
// и самое главное. Здесь должен скидываться скрипт для работы со всеми шрифтами. // и самое главное. Здесь должен скидываться скрипт для работы со всеми шрифтами.
// все объекты, которые позволят не знать о существующих фонтах // все объекты, которые позволят не знать о существующих фонтах
if (TRUE) if (0 != strFile.length())
{ {
CStringWriter oWriterJS; CStringWriter oWriterJS;
...@@ -608,7 +609,7 @@ namespace NSCommon ...@@ -608,7 +609,7 @@ namespace NSCommon
{ {
BYTE* pData = NULL; BYTE* pData = NULL;
LONG lLen = 0; LONG lLen = 0;
applicationFonts.GetList()->ToBuffer(&pData, &lLen); applicationFonts.GetList()->ToBuffer(&pData, &lLen, L"", true);
char* cData64 = NULL; char* cData64 = NULL;
int nData64Dst = 0; int nData64Dst = 0;
...@@ -629,6 +630,20 @@ namespace NSCommon ...@@ -629,6 +630,20 @@ namespace NSCommon
oFile.WriteStringUTF8(oWriterJS.GetCString(), true); oFile.WriteStringUTF8(oWriterJS.GetCString(), true);
oFile.CloseFile(); oFile.CloseFile();
} }
if (0 != strFontSelectionBin.length())
{
BYTE* pData = NULL;
LONG lLen = 0;
applicationFonts.GetList()->ToBuffer(&pData, &lLen, L"", false);
NSFile::CFileBinary oFile;
oFile.CreateFileW(strFontSelectionBin);
oFile.WriteFile(pData, (DWORD)lLen);
oFile.CloseFile();
RELEASEARRAYOBJECTS(pData);
}
} }
} }
...@@ -645,11 +660,35 @@ int wmain(int argc, wchar_t** argv) ...@@ -645,11 +660,35 @@ int wmain(int argc, wchar_t** argv)
wcout << "]"; wcout << "]";
#endif #endif
std::wstring strFontsFolder = L"";
if (1 < argc)
strFontsFolder = std::wstring(argv[1]);
std::wstring strAllFontsJSPath = L"";
if (2 < argc)
strAllFontsJSPath = std::wstring(argv[2]);
std::wstring strThumbnailsFolder = L"";
if (3 < argc)
strThumbnailsFolder = std::wstring(argv[3]);
std::wstring strFontsSelectionBin = L"";
if (4 < argc)
strFontsSelectionBin = std::wstring(argv[4]);
#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; CApplicationFonts oApplicationF;
oApplicationF.InitializeFromFolder(L"C:/Windows/Fonts");
NSCommon::SaveAllFontsJS(oApplicationF, L"D:/AllFonts.js", L"D:/"); if (strFontsFolder.length() != 0)
oApplicationF.InitializeFromFolder(strFontsFolder, false);
else
oApplicationF.Initialize(false);
NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, strThumbnailsFolder, strFontsSelectionBin);
return 0; return 0;
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#if defined(WIN32) || defined(_WIN32_WCE) #if defined(WIN32) || defined(_WIN32_WCE)
#include <wchar.h> #include <wchar.h>
#include <windows.h>
#endif #endif
//#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h" //#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
...@@ -44,6 +45,54 @@ namespace NSFile ...@@ -44,6 +45,54 @@ 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;
}
class CUtf8Converter class CUtf8Converter
{ {
public: public:
......
...@@ -366,6 +366,7 @@ CFontInfo* CFontInfo::FromBuffer(BYTE*& pBuffer, std::wstring strDir) ...@@ -366,6 +366,7 @@ CFontInfo* CFontInfo::FromBuffer(BYTE*& pBuffer, std::wstring strDir)
SHORT shCapHeight = *((SHORT*)pBuffer); SHORT shCapHeight = *((SHORT*)pBuffer);
pBuffer += sizeof(SHORT); pBuffer += sizeof(SHORT);
if (strPath.find(wchar_t('/')) == std::wstring::npos && strPath.find(wchar_t('\\')) == std::wstring::npos)
strPath = strDir + strPath; strPath = strDir + strPath;
CFontInfo* pInfo = new CFontInfo(strName, CFontInfo* pInfo = new CFontInfo(strName,
...@@ -396,7 +397,7 @@ CFontInfo* CFontInfo::FromBuffer(BYTE*& pBuffer, std::wstring strDir) ...@@ -396,7 +397,7 @@ CFontInfo* CFontInfo::FromBuffer(BYTE*& pBuffer, std::wstring strDir)
return pInfo; return pInfo;
} }
LONG CFontInfo::GetBufferLen(std::wstring strDirectory) LONG CFontInfo::GetBufferLen(std::wstring strDirectory, bool bIsOnlyFileName)
{ {
std::wstring sPath = m_wsFontPath; std::wstring sPath = m_wsFontPath;
if (0 != strDirectory.length()) if (0 != strDirectory.length())
...@@ -406,6 +407,28 @@ LONG CFontInfo::GetBufferLen(std::wstring strDirectory) ...@@ -406,6 +407,28 @@ LONG CFontInfo::GetBufferLen(std::wstring strDirectory)
sPath = sPath.substr(strDirectory.length()); sPath = sPath.substr(strDirectory.length());
} }
} }
else if (bIsOnlyFileName)
{
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(pos + 1);
}
}
//return 4 * g_lSizeofLONG + 3 * g_lSizeofBOOL + (m_wsFontName.GetLength() + sPath.GetLength() + 2) * g_lSizeofWCHAR + 2 * g_lSizeofUSHORT + 6 * g_lSizeofULONG + 10 + 8 * g_lSizeofSHORT; //return 4 * g_lSizeofLONG + 3 * g_lSizeofBOOL + (m_wsFontName.GetLength() + sPath.GetLength() + 2) * g_lSizeofWCHAR + 2 * g_lSizeofUSHORT + 6 * g_lSizeofULONG + 10 + 8 * g_lSizeofSHORT;
if (2 == sizeof(wchar_t)) if (2 == sizeof(wchar_t))
{ {
...@@ -420,7 +443,7 @@ LONG CFontInfo::GetBufferLen(std::wstring strDirectory) ...@@ -420,7 +443,7 @@ LONG CFontInfo::GetBufferLen(std::wstring strDirectory)
return 4 * 4 + 3 * 4 + (s1.Length + s2.Length + 2) * 2 + 2 * 2 + 6 * 4 + 10 + 8 * 2; return 4 * 4 + 3 * 4 + (s1.Length + s2.Length + 2) * 2 + 2 * 2 + 6 * 4 + 10 + 8 * 2;
} }
void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory) void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory, bool bIsOnlyFileName)
{ {
// name // name
int lLen = 0; int lLen = 0;
...@@ -444,6 +467,28 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory) ...@@ -444,6 +467,28 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory)
sPath = sPath.substr(strDirectory.length()); sPath = sPath.substr(strDirectory.length());
} }
} }
else if (bIsOnlyFileName)
{
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(pos + 1);
}
}
lLen = (sPath.length() + 1) * 2; lLen = (sPath.length() + 1) * 2;
...@@ -475,6 +520,28 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory) ...@@ -475,6 +520,28 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory)
sPath = sPath.substr(strDirectory.length()); sPath = sPath.substr(strDirectory.length());
} }
} }
else if (bIsOnlyFileName)
{
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(pos + 1);
}
}
NSFile::CStringUtf16 s2; NSFile::CStringUtf16 s2;
NSFile::CUtf8Converter::GetUtf16StringFromUnicode_4bytes2(sPath.c_str(), sPath.length(), s2); NSFile::CUtf8Converter::GetUtf16StringFromUnicode_4bytes2(sPath.c_str(), sPath.length(), s2);
...@@ -991,13 +1058,13 @@ EFontFormat CFontList::GetFontFormat(FT_Face pFace) ...@@ -991,13 +1058,13 @@ EFontFormat CFontList::GetFontFormat(FT_Face pFace)
return fontUnknown; return fontUnknown;
} }
void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory) void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory, bool bIsOnlyFileName)
{ {
LONG lDataSize = sizeof(INT); LONG lDataSize = sizeof(INT);
size_t nFontsCount = (size_t)m_pList.GetCount(); size_t nFontsCount = (size_t)m_pList.GetCount();
for (size_t i = 0; i < nFontsCount; ++i) for (size_t i = 0; i < nFontsCount; ++i)
{ {
lDataSize += m_pList[i]->GetBufferLen(strDirectory); lDataSize += m_pList[i]->GetBufferLen(strDirectory, bIsOnlyFileName);
} }
BYTE* pData = new BYTE[lDataSize]; BYTE* pData = new BYTE[lDataSize];
...@@ -1008,7 +1075,7 @@ void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory) ...@@ -1008,7 +1075,7 @@ void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory)
for (size_t i = 0; i < nFontsCount; ++i) for (size_t i = 0; i < nFontsCount; ++i)
{ {
m_pList[i]->ToBuffer(pDataMem, strDirectory); m_pList[i]->ToBuffer(pDataMem, strDirectory, bIsOnlyFileName);
} }
*pDstData = pData; *pDstData = pData;
...@@ -1468,15 +1535,28 @@ CApplicationFontStreams* CApplicationFonts::GetStreams() ...@@ -1468,15 +1535,28 @@ CApplicationFontStreams* CApplicationFonts::GetStreams()
return &m_oStreams; return &m_oStreams;
} }
void CApplicationFonts::InitializeFromFolder(std::wstring strFolder) void CApplicationFonts::InitializeFromFolder(std::wstring strFolder, bool bIsCheckSelection)
{ {
if (!m_oList.CheckLoadFromFolderBin(strFolder)) if (bIsCheckSelection)
m_oList.LoadFromFolder(strFolder); {
if (m_oList.CheckLoadFromFolderBin(strFolder))
return;
if (m_oList.CheckLoadFromFolderBin(NSFile::GetProcessDirectory()))
return;
}
m_oList.LoadFromFolder(strFolder);
m_oCache.m_pApplicationFontStreams = &m_oStreams; m_oCache.m_pApplicationFontStreams = &m_oStreams;
} }
void CApplicationFonts::Initialize() void CApplicationFonts::Initialize(bool bIsCheckSelection)
{ {
if (bIsCheckSelection)
{
if (m_oList.CheckLoadFromFolderBin(NSFile::GetProcessDirectory()))
return;
}
#ifdef WIN32 #ifdef WIN32
//m_oList.LoadFromFolder(L"C:/Windows/Fonts"); //m_oList.LoadFromFolder(L"C:/Windows/Fonts");
InitFromReg(); InitFromReg();
......
...@@ -92,8 +92,8 @@ public: ...@@ -92,8 +92,8 @@ public:
INT Equals(const CFontInfo *pFontInfo); INT Equals(const CFontInfo *pFontInfo);
static CFontInfo* FromBuffer(BYTE*& pBuffer, std::wstring strDir); static CFontInfo* FromBuffer(BYTE*& pBuffer, std::wstring strDir);
LONG GetBufferLen(std::wstring strDirectory = L""); LONG GetBufferLen(std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
void ToBuffer(BYTE*& pBuffer, std::wstring strDirectory = L""); void ToBuffer(BYTE*& pBuffer, std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
public: public:
std::wstring m_wsFontName; // Имя шрифта std::wstring m_wsFontName; // Имя шрифта
...@@ -181,7 +181,7 @@ private: ...@@ -181,7 +181,7 @@ private:
public: public:
static EFontFormat GetFontFormat(FT_Face pFace); static EFontFormat GetFontFormat(FT_Face pFace);
void ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory = L""); void ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
public: public:
void LoadFromArrayFiles(CArray<std::wstring>& arrFiles); void LoadFromArrayFiles(CArray<std::wstring>& arrFiles);
...@@ -209,8 +209,8 @@ public: ...@@ -209,8 +209,8 @@ public:
CFontList* GetList(); CFontList* GetList();
CApplicationFontStreams* GetStreams(); CApplicationFontStreams* GetStreams();
void InitializeFromFolder(std::wstring strFolder); void InitializeFromFolder(std::wstring strFolder, bool bIsCheckSelection = true);
void Initialize(); void Initialize(bool bIsCheckSelection = true);
#ifdef WIN32 #ifdef WIN32
void InitFromReg(); void InitFromReg();
......
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