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
}
};
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();
int nCount = pList->GetCount();
......@@ -429,14 +429,13 @@ namespace NSCommon
}
}
// -------------------------------------------
CFontManager* pManager = applicationFonts.GenerateFontManager();
CFontsCache* pCache = new CFontsCache();
pCache->SetStreams(applicationFonts.GetStreams());
pManager->SetOwnerCache(pCache);
if (L"" != strFolderThumbnails)
{
CFontManager* pManager = applicationFonts.GenerateFontManager();
CFontsCache* pCache = new CFontsCache();
pCache->SetStreams(applicationFonts.GetStreams());
pManager->SetOwnerCache(pCache);
for (int iX = 1; iX <= 2; ++iX)
{
// создаем картинку для табнейлов
......@@ -538,11 +537,13 @@ namespace NSCommon
oFrame.SaveFile(strThumbnailPath, 4);
}
RELEASEOBJECT(pManager);
}
// и самое главное. Здесь должен скидываться скрипт для работы со всеми шрифтами.
// все объекты, которые позволят не знать о существующих фонтах
if (TRUE)
if (0 != strFile.length())
{
CStringWriter oWriterJS;
......@@ -608,7 +609,7 @@ namespace NSCommon
{
BYTE* pData = NULL;
LONG lLen = 0;
applicationFonts.GetList()->ToBuffer(&pData, &lLen);
applicationFonts.GetList()->ToBuffer(&pData, &lLen, L"", true);
char* cData64 = NULL;
int nData64Dst = 0;
......@@ -629,6 +630,20 @@ namespace NSCommon
oFile.WriteStringUTF8(oWriterJS.GetCString(), true);
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)
wcout << "]";
#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;
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;
}
......@@ -10,6 +10,7 @@
#if defined(WIN32) || defined(_WIN32_WCE)
#include <wchar.h>
#include <windows.h>
#endif
//#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
......@@ -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
{
public:
......
......@@ -366,7 +366,8 @@ CFontInfo* CFontInfo::FromBuffer(BYTE*& pBuffer, std::wstring strDir)
SHORT shCapHeight = *((SHORT*)pBuffer);
pBuffer += sizeof(SHORT);
strPath = strDir + strPath;
if (strPath.find(wchar_t('/')) == std::wstring::npos && strPath.find(wchar_t('\\')) == std::wstring::npos)
strPath = strDir + strPath;
CFontInfo* pInfo = new CFontInfo(strName,
L"",
......@@ -396,7 +397,7 @@ CFontInfo* CFontInfo::FromBuffer(BYTE*& pBuffer, std::wstring strDir)
return pInfo;
}
LONG CFontInfo::GetBufferLen(std::wstring strDirectory)
LONG CFontInfo::GetBufferLen(std::wstring strDirectory, bool bIsOnlyFileName)
{
std::wstring sPath = m_wsFontPath;
if (0 != strDirectory.length())
......@@ -406,6 +407,28 @@ LONG CFontInfo::GetBufferLen(std::wstring strDirectory)
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;
if (2 == sizeof(wchar_t))
{
......@@ -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;
}
void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory)
void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory, bool bIsOnlyFileName)
{
// name
int lLen = 0;
......@@ -444,6 +467,28 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory)
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;
......@@ -475,6 +520,28 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory)
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::CUtf8Converter::GetUtf16StringFromUnicode_4bytes2(sPath.c_str(), sPath.length(), s2);
......@@ -991,13 +1058,13 @@ EFontFormat CFontList::GetFontFormat(FT_Face pFace)
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);
size_t nFontsCount = (size_t)m_pList.GetCount();
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];
......@@ -1008,7 +1075,7 @@ void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory)
for (size_t i = 0; i < nFontsCount; ++i)
{
m_pList[i]->ToBuffer(pDataMem, strDirectory);
m_pList[i]->ToBuffer(pDataMem, strDirectory, bIsOnlyFileName);
}
*pDstData = pData;
......@@ -1468,15 +1535,28 @@ CApplicationFontStreams* CApplicationFonts::GetStreams()
return &m_oStreams;
}
void CApplicationFonts::InitializeFromFolder(std::wstring strFolder)
void CApplicationFonts::InitializeFromFolder(std::wstring strFolder, bool bIsCheckSelection)
{
if (!m_oList.CheckLoadFromFolderBin(strFolder))
m_oList.LoadFromFolder(strFolder);
if (bIsCheckSelection)
{
if (m_oList.CheckLoadFromFolderBin(strFolder))
return;
m_oCache.m_pApplicationFontStreams = &m_oStreams;
if (m_oList.CheckLoadFromFolderBin(NSFile::GetProcessDirectory()))
return;
}
m_oList.LoadFromFolder(strFolder);
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
//m_oList.LoadFromFolder(L"C:/Windows/Fonts");
InitFromReg();
......
......@@ -92,8 +92,8 @@ public:
INT Equals(const CFontInfo *pFontInfo);
static CFontInfo* FromBuffer(BYTE*& pBuffer, std::wstring strDir);
LONG GetBufferLen(std::wstring strDirectory = L"");
void ToBuffer(BYTE*& pBuffer, std::wstring strDirectory = L"");
LONG GetBufferLen(std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
void ToBuffer(BYTE*& pBuffer, std::wstring strDirectory = L"", bool bIsOnlyFileName = false);
public:
std::wstring m_wsFontName; // Имя шрифта
......@@ -181,7 +181,7 @@ private:
public:
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:
void LoadFromArrayFiles(CArray<std::wstring>& arrFiles);
......@@ -209,8 +209,8 @@ public:
CFontList* GetList();
CApplicationFontStreams* GetStreams();
void InitializeFromFolder(std::wstring strFolder);
void Initialize();
void InitializeFromFolder(std::wstring strFolder, bool bIsCheckSelection = true);
void Initialize(bool bIsCheckSelection = true);
#ifdef WIN32
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