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

AllFontsGen on desktopeditor engine

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@60500 954022d7-b5bf-4e40-9824-e11837661b57
parent 9c4020d1
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
DEFINES += \
_QT \
FT2_BUILD_LIBRARY \
EXCLUDE_JPG_SUPPORT \
MNG_SUPPORT_DISPLAY \
MNG_SUPPORT_READ \
MNG_SUPPORT_WRITE \
MNG_ACCESS_CHUNKS \
MNG_STORE_CHUNKS\
MNG_ERROR_TELLTALE
linux-g++ | linux-g++-64 | linux-g++-32 {
DEFINES += \
HAVE_UNISTD_H \
_LINUX \
_LINUX_QT
message(linux)
}
mac {
DEFINES += \
HAVE_UNISTD_H \
_LINUX \
_LINUX_QT \
_MAC \
QT_MAC
message(mac)
}
win32 {
DEFINES += \
JAS_WIN_MSVC_BUILD \
WIN32
DEFINES -= UNICODE
DEFINES -= _DEBUG
message(windows)
LIBS += -lAdvapi32
LIBS += -lShell32
LIBS += -lGdi32
LIBS += -lUser32
}
SOURCES += main.cpp
INCLUDEPATH += \
../agg-2.4/include \
../freetype-2.5.2/include \
CONFIG(debug, debug|release) {
LIBS += -L../../Qt_build/graphics/Debug/debug -lgraphics
message(debug)
} else {
LIBS += -L../../Qt_build/graphics/Release/release -lgraphics
message(release)
}
#include <iostream>
#include <set>
#include "../fontengine/ApplicationFonts.h"
#include "../graphics/GraphicsRenderer.h"
#include "../common/File.h"
using namespace std;
namespace NSCommon
{
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
{
size_t posn = 0;
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
{
text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length();
}
}
class CTextItem
{
protected:
wchar_t* m_pData;
size_t m_lSize;
wchar_t* m_pDataCur;
size_t m_lSizeCur;
public:
CTextItem()
{
m_pData = NULL;
m_lSize = 0;
m_pDataCur = m_pData;
m_lSizeCur = m_lSize;
}
CTextItem(const CTextItem& oSrc)
{
m_pData = NULL;
*this = oSrc;
}
CTextItem& operator=(const CTextItem& oSrc)
{
RELEASEMEM(m_pData);
m_lSize = oSrc.m_lSize;
m_lSizeCur = oSrc.m_lSizeCur;
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
memcpy(m_pData, oSrc.m_pData, m_lSizeCur * sizeof(wchar_t));
m_pDataCur = m_pData + m_lSizeCur;
return *this;
}
CTextItem(const size_t& nLen)
{
m_lSize = nLen;
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
m_lSizeCur = 0;
m_pDataCur = m_pData;
}
CTextItem(wchar_t* pData, const size_t& nLen)
{
m_lSize = nLen;
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
m_lSizeCur = m_lSize;
m_pDataCur = m_pData + m_lSize;
}
CTextItem(wchar_t* pData, BYTE* pUnicodeChecker = NULL)
{
size_t nLen = GetStringLen(pData);
m_lSize = nLen;
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
m_lSizeCur = m_lSize;
m_pDataCur = m_pData + m_lSize;
if (NULL != pUnicodeChecker)
{
wchar_t* pMemory = m_pData;
while (pMemory < m_pDataCur)
{
if (!pUnicodeChecker[*pMemory])
*pMemory = wchar_t(' ');
++pMemory;
}
}
}
virtual ~CTextItem()
{
RELEASEMEM(m_pData);
}
inline void AddSize(const size_t& nSize)
{
if (NULL == m_pData)
{
m_lSize = max(nSize, 1000);
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
m_lSizeCur = 0;
m_pDataCur = m_pData;
return;
}
if ((m_lSizeCur + nSize) > m_lSize)
{
while ((m_lSizeCur + nSize) > m_lSize)
{
m_lSize *= 2;
}
wchar_t* pRealloc = (wchar_t*)realloc(m_pData, m_lSize * sizeof(wchar_t));
if (NULL != pRealloc)
{
// реаллок сработал
m_pData = pRealloc;
m_pDataCur = m_pData + m_lSizeCur;
}
else
{
wchar_t* pMalloc = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(wchar_t));
free(m_pData);
m_pData = pMalloc;
m_pDataCur = m_pData + m_lSizeCur;
}
}
}
public:
inline void operator+=(const std::wstring& oTemp)
{
WriteString(oTemp.c_str(), oTemp.length());
}
inline wchar_t operator[](const size_t& nIndex)
{
if (nIndex < m_lSizeCur)
return m_pData[nIndex];
return 0;
}
inline void AddSpace()
{
AddSize(1);
*m_pDataCur = wchar_t(' ');
++m_lSizeCur;
++m_pDataCur;
}
inline void CorrectUnicode(const BYTE* pUnicodeChecker)
{
if (NULL != pUnicodeChecker)
{
wchar_t* pMemory = m_pData;
while (pMemory < m_pDataCur)
{
if (!pUnicodeChecker[*pMemory])
*pMemory = wchar_t(' ');
++pMemory;
}
}
}
inline void RemoveLastSpaces()
{
wchar_t* pMemory = m_pDataCur - 1;
while ((pMemory > m_pData) && (wchar_t(' ') == *pMemory))
{
--pMemory;
--m_lSizeCur;
--m_pDataCur;
}
}
inline bool IsSpace()
{
if (1 != m_lSizeCur)
return false;
return (wchar_t(' ') == *m_pData);
}
public:
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);
m_pDataCur += nLen;
m_lSizeCur += nLen;
}
inline size_t GetCurSize()
{
return m_lSizeCur;
}
inline size_t GetSize()
{
return m_lSize;
}
inline void Clear()
{
RELEASEMEM(m_pData);
m_pData = NULL;
m_lSize = 0;
m_pDataCur = m_pData;
m_lSizeCur = 0;
}
inline void ClearNoAttack()
{
m_pDataCur = m_pData;
m_lSizeCur = 0;
}
inline size_t GetStringLen(wchar_t* pData)
{
wchar_t* s = pData;
for (; *s != 0; ++s);
return (size_t)(s - pData);
}
inline std::wstring GetCString()
{
std::wstring str(m_pData, (int)m_lSizeCur);
return str;
}
inline wchar_t* GetBuffer()
{
return m_pData;
}
};
class CStringWriter : public CTextItem
{
public:
CStringWriter() : CTextItem()
{
}
virtual ~CStringWriter()
{
}
public:
inline void Write(CStringWriter& oWriter)
{
CTextItem::WriteString(oWriter.m_pData, oWriter.m_lSizeCur);
}
};
class CFontInfoJS
{
public:
std::wstring m_sName;
int m_lIndexR;
int m_lFaceIndexR;
int m_lIndexI;
int m_lFaceIndexI;
int m_lIndexB;
int m_lFaceIndexB;
int m_lIndexBI;
int m_lFaceIndexBI;
CFontInfoJS()
{
m_sName = L"";
m_lIndexR = -1;
m_lFaceIndexR = -1;
m_lIndexI = -1;
m_lFaceIndexI = -1;
m_lIndexB = -1;
m_lFaceIndexB = -1;
m_lIndexBI = -1;
m_lFaceIndexBI = -1;
}
CFontInfoJS(const CFontInfoJS& oSrc)
{
*this = oSrc;
}
CFontInfoJS& operator=(const CFontInfoJS& oSrc)
{
m_sName = oSrc.m_sName;
m_lIndexR = oSrc.m_lIndexR;
m_lIndexI = oSrc.m_lIndexI;
m_lIndexB = oSrc.m_lIndexB;
m_lIndexBI = oSrc.m_lIndexBI;
m_lFaceIndexR = oSrc.m_lFaceIndexR;
m_lFaceIndexI = oSrc.m_lFaceIndexI;
m_lFaceIndexB = oSrc.m_lFaceIndexB;
m_lFaceIndexBI = oSrc.m_lFaceIndexBI;
return *this;
}
};
void SaveAllFontsJS(CFontList& fonts, std::wstring strFile, std::wstring strFolderThumbnails = L"")
{
CArray<CFontInfo*>* pList = fonts.GetFonts();
int nCount = pList->GetCount();
// сначала строим массив всех файлов шрифтов
std::map<std::wstring, LONG> mapFontFiles;
std::map<LONG, std::wstring> mapFontFiles2;
LONG lFontFiles = 0;
for (int i = 0; i < nCount; ++i)
{
CFontInfo* pInfo = pList->operator [](i);
if (mapFontFiles.find(pInfo->m_wsFontPath) == mapFontFiles.end())
{
mapFontFiles.insert(std::pair<std::wstring, LONG>(pInfo->m_wsFontPath, lFontFiles));
mapFontFiles2.insert(std::pair<LONG, std::wstring>(lFontFiles, pInfo->m_wsFontPath));
++lFontFiles;
}
}
// -----------------------------------------
// теперь строим массив всех шрифтов по имени
std::map<std::wstring, CFontInfoJS> mapFonts;
CArray<std::wstring> arrFonts;
for (int i = 0; i < nCount; ++i)
{
CFontInfo* pInfo = (CFontInfo*)pList->operator [](i);
std::wstring strPath = pInfo->m_wsFontPath;
std::wstring strName = pInfo->m_wsFontName;
int lFontIndex = 0;
int lFaceIndex = 0;
std::map<std::wstring, LONG>::iterator it = mapFontFiles.find(strPath);
lFontIndex = it->second;
if (pInfo->m_lIndex >= 0)
lFaceIndex = (int)pInfo->m_lIndex;
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(pInfo->m_wsFontName);
if (mapFonts.end() != pPair)
{
pPair->second.m_sName = pInfo->m_wsFontName;
if (pInfo->m_bBold && pInfo->m_bItalic)
{
pPair->second.m_lIndexBI = lFontIndex;
pPair->second.m_lFaceIndexBI = lFaceIndex;
}
else if (pInfo->m_bBold)
{
pPair->second.m_lIndexB = lFontIndex;
pPair->second.m_lFaceIndexB = lFaceIndex;
}
else if (pInfo->m_bItalic)
{
pPair->second.m_lIndexI = lFontIndex;
pPair->second.m_lFaceIndexI = lFaceIndex;
}
else
{
pPair->second.m_lIndexR = lFontIndex;
pPair->second.m_lFaceIndexR = lFaceIndex;
}
}
else
{
CFontInfoJS fontInfo;
fontInfo.m_sName = pInfo->m_wsFontName;
if (pInfo->m_bBold && pInfo->m_bItalic)
{
fontInfo.m_lIndexBI = lFontIndex;
fontInfo.m_lFaceIndexBI = lFaceIndex;
}
else if (pInfo->m_bBold)
{
fontInfo.m_lIndexB = lFontIndex;
fontInfo.m_lFaceIndexB = lFaceIndex;
}
else if (pInfo->m_bItalic)
{
fontInfo.m_lIndexI = lFontIndex;
fontInfo.m_lFaceIndexI = lFaceIndex;
}
else
{
fontInfo.m_lIndexR = lFontIndex;
fontInfo.m_lFaceIndexR = lFaceIndex;
}
mapFonts.insert(std::pair<std::wstring, CFontInfoJS>(fontInfo.m_sName, fontInfo));
arrFonts.Add(fontInfo.m_sName);
}
}
// -------------------------------------------
// теперь сортируем шрифты по имени ----------
int nCountFonts = arrFonts.GetCount();
for (int i = 0; i < nCountFonts; ++i)
{
for (int j = i + 1; j < nCountFonts; ++j)
{
if (arrFonts[i] > arrFonts[j])
{
std::wstring temp = arrFonts[i];
arrFonts[i] = arrFonts[j];
arrFonts[j] = temp;
}
}
}
// -------------------------------------------
CApplicationFonts oApplicationFonts;
oApplicationFonts.InitializeFromFolder(L"C:/Windows/Fonts");
CFontManager* pManager = oApplicationFonts.GenerateFontManager();
CFontsCache* pCache = new CFontsCache();
pCache->SetStreams(oApplicationFonts.GetStreams());
pManager->SetOwnerCache(pCache);
if (L"" != strFolderThumbnails)
{
for (int iX = 1; iX <= 2; ++iX)
{
// создаем картинку для табнейлов
double dDpi = 96 * iX;
double dW_mm = 80;
LONG lH1_px = LONG(7 * dDpi / 25.4);
LONG lWidthPix = (LONG)(dW_mm * dDpi / 25.4);
LONG lHeightPix = (LONG)(nCountFonts * lH1_px);
LONG lCountPixels = 4 * lWidthPix * lHeightPix;
BYTE* pImageData = new BYTE[lCountPixels];
memset(pImageData, 0xFF, lCountPixels);
CBgraFrame oFrame;
oFrame.put_Data(pImageData);
oFrame.put_Width((int)lWidthPix);
oFrame.put_Height((int)lHeightPix);
oFrame.put_Stride(4 * (int)lWidthPix);
for (LONG i = 3; i < lWidthPix * lHeightPix * 4; i += 4)
{
pImageData[i] = 0;
}
CGraphicsRenderer oRenderer;
oRenderer.CreateFromBgraFrame(&oFrame);
oRenderer.SetFontManager(pManager);
oRenderer.put_Width(lWidthPix * 25.4 / dDpi);
oRenderer.put_Height(lHeightPix * 25.4 / dDpi);
for (int index = 0; index < nCountFonts; ++index)
{
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(arrFonts[index]);
// thumbnail
LONG lFontIndex = 0;
LONG lFaceIndex = 0;
if (pPair->second.m_lIndexR != -1)
{
lFontIndex = pPair->second.m_lIndexR;
lFaceIndex = pPair->second.m_lFaceIndexR;
}
else if (pPair->second.m_lIndexI != -1)
{
lFontIndex = pPair->second.m_lIndexI;
lFaceIndex = pPair->second.m_lFaceIndexI;
}
else if (pPair->second.m_lIndexB != -1)
{
lFontIndex = pPair->second.m_lIndexB;
lFaceIndex = pPair->second.m_lFaceIndexB;
}
else if (pPair->second.m_lIndexBI != -1)
{
lFontIndex = pPair->second.m_lIndexBI;
lFaceIndex = pPair->second.m_lFaceIndexBI;
}
std::map<LONG, std::wstring>::iterator pPair2 = mapFontFiles2.find(lFontIndex);
std::wstring strFontPath = L"";
if (mapFontFiles2.end() != pPair2)
strFontPath = pPair2->second;
oRenderer.put_FontPath(strFontPath);
pManager->LoadFontFromFile(strFontPath, lFaceIndex, 14, dDpi, dDpi);
BOOL bIsSymbol = FALSE;
if (pManager->m_pFont)
bIsSymbol = (-1 != (pManager->m_pFont->m_nSymbolic)) ? TRUE : FALSE;
if (bIsSymbol)
{
CFontSelectFormat oSelectFormat;
oSelectFormat.wsName = new std::wstring(L"Courier New");
CFontInfo* pInfoCur = pManager->GetFontInfoByParams(oSelectFormat);
if (NULL != pInfoCur)
{
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, lFaceIndex, 14, dDpi, dDpi);
}
oRenderer.put_FontPath(pInfoCur->m_wsFontPath);
}
oRenderer.put_FontStringGID(FALSE);
oRenderer.put_FontCharSpace(0);
oRenderer.put_FontSize(14);
oRenderer.CommandDrawText(pPair->second.m_sName, 5, 25.4 * (index * lH1_px + lH1_px) / dDpi - 2, 0, 0, 0);
}
std::wstring strThumbnailPath = strFolderThumbnails + L"/fonts_thumbnail";
if (iX == 1)
strThumbnailPath += L".png";
else
strThumbnailPath += L"@2x.png";
oFrame.SaveFile(strThumbnailPath, 4);
}
}
// и самое главное. Здесь должен скидываться скрипт для работы со всеми шрифтами.
// все объекты, которые позволят не знать о существующих фонтах
if (TRUE)
{
CStringWriter oWriterJS;
// сначала все файлы
size_t nCountFiles = mapFontFiles.size();
if (nCountFiles == 0)
oWriterJS += (L"window[\"__fonts_files\"] = []; \n\n");
else
{
std::wstring* pMassFiles = new std::wstring[nCountFiles];
for ( std::map<std::wstring, LONG>::iterator pos = mapFontFiles.begin(); pos != mapFontFiles.end(); ++pos)
{
std::wstring strFontId = pos->first;
string_replace(strFontId, L"\\\\", L"\\");
string_replace(strFontId, L"/", L"\\");
int nStart = strFontId.find_last_of(wchar_t('\\'));
strFontId = strFontId.substr(nStart + 1);
pMassFiles[pos->second] = strFontId;
}
oWriterJS += (L"window[\"__fonts_files\"] = [\n");
for (size_t nIndex = 0; nIndex < nCountFiles; ++nIndex)
{
oWriterJS += (L"\"");
oWriterJS += (pMassFiles[nIndex]);
if (nIndex != (nCountFiles - 1))
oWriterJS += (L"\",\n");
else
oWriterJS += (L"\"");
}
oWriterJS += (L"\n];\n\n");
delete [] pMassFiles;
}
oWriterJS += L"window[\"__fonts_infos\"] = [\n";
for (int index = 0; index < nCountFonts; ++index)
{
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,
pPair->second.m_lIndexI, pPair->second.m_lFaceIndexI,
pPair->second.m_lIndexB, pPair->second.m_lFaceIndexB,
pPair->second.m_lIndexBI, pPair->second.m_lFaceIndexBI);
oWriterJS += L"[\"";
oWriterJS += pPair->second.m_sName;
oWriterJS += std::wstring(buffer);
if (index != (nCountFonts - 1))
oWriterJS += (L",\n");
else
oWriterJS += (L"\n");
}
oWriterJS += (L"];\n\n");
if (true)
{
BYTE* pData = NULL;
LONG lLen = 0;
fonts.ToBuffer(&pData, &lLen);
char* cData64 = NULL;
int nData64Dst = 0;
NSFile::CBase64Converter::Encode(pData, (int)lLen, cData64, nData64Dst, NSBase64::B64_BASE64_FLAG_NOCRLF);
std::wstring sData64 = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(cData64, (LONG)nData64Dst, FALSE);
oWriterJS += (L"window[\"g_fonts_selection_bin\"] = \"");
oWriterJS += sData64;
oWriterJS += L"\";\n";
RELEASEARRAYOBJECTS(pData);
RELEASEARRAYOBJECTS(cData64);
}
NSFile::CFileBinary oFile;
oFile.CreateFileW(strFile);
oFile.WriteStringUTF8(oWriterJS.GetCString(), true);
oFile.CloseFile();
}
}
}
int wmain(int argc, wchar_t** argv)
{
#if 0
char buf[10];
wcout << "[\n";
wcout << itoa(argc, buf, 10) << "\n";
for (int i = 0; i < argc; ++i)
wcout << argv[i] << "\n";
wcout << "]";
#endif
CFontList oList;
oList.LoadFromFolder(L"C:/Windows/Fonts");
NSCommon::SaveAllFontsJS(oList, L"D:/AllFonts.js", L"D:/");
return 0;
}
......@@ -26,6 +26,24 @@ namespace NSFile
*p++ = 0xDC00 | (code & 0x03FF); \
}
class CStringUtf16
{
public:
BYTE* Data;
int Length;
public:
CStringUtf16()
{
Data = NULL;
Length = 0;
}
~CStringUtf16()
{
RELEASEARRAYOBJECTS(Data);
}
};
class CUtf8Converter
{
public:
......@@ -393,6 +411,61 @@ namespace NSFile
RELEASEARRAYOBJECTS(pData);
return s;
}
// utf16
static void GetUtf16StringFromUnicode_4bytes(const wchar_t* pUnicodes, LONG lCount, BYTE*& pData, int& lOutputCount, bool bIsBOM = false)
{
if (NULL == pData)
{
pData = new BYTE[2 * lCount + 3 + 1];
}
BYTE* pCodesCur = pData;
if (bIsBOM)
{
pCodesCur[0] = 0xEF;
pCodesCur[1] = 0xBB;
pCodesCur[2] = 0xBF;
pCodesCur += 3;
}
const wchar_t* pEnd = pUnicodes + lCount;
const wchar_t* pCur = pUnicodes;
while (pCur < pEnd)
{
unsigned int code = (unsigned int)*pCur++;
if (code <= 0xFFFF)
{
USHORT usCode = (USHORT)(code & 0xFFFF);
memcpy(pCodesCur, &usCode, 2);
pCodesCur += 2;
}
else
{
code -= 0x10000;
code &= 0xFFFFF;
USHORT us1 = 0xD800 | ((code >> 5) & 0x1F);
USHORT us2 = 0xDC00 | (code & 0x1F);
memcpy(pCodesCur, &us1, 2);
pCodesCur += 2;
memcpy(pCodesCur, &us2, 2);
pCodesCur += 2;
}
}
lOutputCount = (LONG)(pCodesCur - pData);
*pCodesCur++ = 0;
}
static void GetUtf16StringFromUnicode_4bytes2(const wchar_t* pUnicodes, LONG lCount, CStringUtf16& data)
{
GetUtf16StringFromUnicode_4bytes(pUnicodes, lCount, data.Data, data.Length);
}
};
class CFileBinary
......
......@@ -396,6 +396,188 @@ CFontInfo* CFontInfo::FromBuffer(BYTE*& pBuffer, std::wstring strDir)
return pInfo;
}
LONG CFontInfo::GetBufferLen(std::wstring strDirectory)
{
std::wstring sPath = m_wsFontPath;
if (0 != strDirectory.length())
{
if (0 == sPath.find(strDirectory))
{
sPath = sPath.substr(strDirectory.length());
}
}
//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))
{
return 4 * 4 + 3 * 4 + (m_wsFontName.length() + sPath.length() + 2) * 2 + 2 * 2 + 6 * 4 + 10 + 8 * 2;
}
NSFile::CStringUtf16 s1;
NSFile::CUtf8Converter::GetUtf16StringFromUnicode_4bytes2(m_wsFontName.c_str(), m_wsFontName.length(), s1);
NSFile::CStringUtf16 s2;
NSFile::CUtf8Converter::GetUtf16StringFromUnicode_4bytes2(sPath.c_str(), sPath.length(), s2);
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)
{
// name
int lLen = 0;
if (2 == sizeof(wchar_t))
{
lLen = (m_wsFontName.length() + 1) * 2;
*((int*)(pBuffer)) = lLen;
pBuffer += 4;
memcpy(pBuffer, m_wsFontName.c_str(), lLen);
pBuffer += lLen;
// path
std::wstring sPath = m_wsFontPath;
if (0 != strDirectory.length())
{
if (0 == sPath.find(strDirectory))
{
sPath = sPath.substr(strDirectory.length());
}
}
lLen = (sPath.length() + 1) * 2;
*((INT*)(pBuffer)) = lLen;
pBuffer += sizeof(INT);
memcpy(pBuffer, sPath.c_str(), lLen);
pBuffer += lLen;
}
else
{
NSFile::CStringUtf16 s1;
NSFile::CUtf8Converter::GetUtf16StringFromUnicode_4bytes2(m_wsFontName.c_str(), m_wsFontName.length(), s1);
lLen = (s1.Length + 1) * 2;
*((int*)(pBuffer)) = lLen;
pBuffer += 4;
memcpy(pBuffer, s1.Data, lLen);
pBuffer += lLen;
// path
std::wstring sPath = m_wsFontPath;
if (0 != strDirectory.length())
{
if (0 == sPath.find(strDirectory))
{
sPath = sPath.substr(strDirectory.length());
}
}
NSFile::CStringUtf16 s2;
NSFile::CUtf8Converter::GetUtf16StringFromUnicode_4bytes2(sPath.c_str(), sPath.length(), s2);
lLen = (s2.Length + 1) * 2;
*((INT*)(pBuffer)) = lLen;
pBuffer += sizeof(INT);
memcpy(pBuffer, s2.Data, lLen);
pBuffer += lLen;
}
// index
*((INT*)(pBuffer)) = (INT)m_lIndex;
pBuffer += sizeof(INT);
// italic
*((INT*)(pBuffer)) = m_bItalic;
pBuffer += sizeof(INT);
// bold
*((INT*)(pBuffer)) = m_bBold;
pBuffer += sizeof(INT);
// FixedWidth
*((INT*)pBuffer) = m_bIsFixed;
pBuffer += sizeof(INT);
// Panose
lLen = 10;
*((INT*)(pBuffer)) = lLen;
pBuffer += sizeof(INT);
memcpy( (void *)pBuffer, (const void *)m_aPanose, lLen );
pBuffer += lLen;
// ulUnicodeRange1
*((UINT*)pBuffer) = (UINT)m_ulUnicodeRange1;
pBuffer += sizeof(UINT);
// ulUnicodeRange2
*((UINT*)pBuffer) = (UINT)m_ulUnicodeRange2;
pBuffer += sizeof(UINT);
// ulUnicodeRange3
*((UINT*)pBuffer) = (UINT)m_ulUnicodeRange3;
pBuffer += sizeof(UINT);
// ulUnicodeRange4
*((UINT*)pBuffer) = (UINT)m_ulUnicodeRange4;
pBuffer += sizeof(UINT);
// ulCodePageRange1
*((UINT*)pBuffer) = (UINT)m_ulCodePageRange1;
pBuffer += sizeof(UINT);
// ulCodePageRange2
*((UINT*)pBuffer) = (UINT)m_ulCodePageRange2;
pBuffer += sizeof(UINT);
// usWeightClass
*((USHORT*)pBuffer) = m_usWeigth;
pBuffer += sizeof(USHORT);
// usWidthClass
*((USHORT*)pBuffer) = m_usWidth;
pBuffer += sizeof(USHORT);
// sFamilyClass
*((SHORT*)pBuffer) = m_sFamilyClass;
pBuffer += sizeof(SHORT);
// FontFormat
*((SHORT*)pBuffer) = (SHORT)m_eFontFormat;
pBuffer += sizeof(SHORT);
// AvgCharWidth
*((SHORT*)pBuffer) = (SHORT)m_shAvgCharWidth;
pBuffer += sizeof(SHORT);
// Ascent
*((SHORT*)pBuffer) = (SHORT)m_shAscent;
pBuffer += sizeof(SHORT);
// Descent
*((SHORT*)pBuffer) = (SHORT)m_shDescent;
pBuffer += sizeof(SHORT);
// LineGap
*((SHORT*)pBuffer) = (SHORT)m_shLineGap;
pBuffer += sizeof(SHORT);
// XHeight
*((SHORT*)pBuffer) = (SHORT)m_shXHeight;
pBuffer += sizeof(SHORT);
// CapHeight
*((SHORT*)pBuffer) = (SHORT)m_shCapHeight;
pBuffer += sizeof(SHORT);
}
///////////////////////////////////////////////////////////////////////////////////
namespace NSCharsets
{
......@@ -809,6 +991,30 @@ EFontFormat CFontList::GetFontFormat(FT_Face pFace)
return fontUnknown;
}
void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory)
{
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);
}
BYTE* pData = new BYTE[lDataSize];
BYTE* pDataMem = pData;
*(INT*)pDataMem = (INT)nFontsCount;
pDataMem += sizeof(INT);
for (size_t i = 0; i < nFontsCount; ++i)
{
m_pList[i]->ToBuffer(pDataMem, strDirectory);
}
*pDstData = pData;
*pLen = lDataSize;
}
CFontInfo* CFontList::GetByParams(CFontSelectFormat& oSelect)
{
int nFontsCount = m_pList.GetCount();
......
......@@ -92,6 +92,9 @@ 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"");
public:
std::wstring m_wsFontName; // Имя шрифта
std::wstring m_wsFontPath; // Путь к файлу с шрифтом
......@@ -153,6 +156,7 @@ public:
}
m_pList.RemoveAll();
}
CArray<CFontInfo*>* GetFonts() { return &m_pList; }
private:
int GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset);
......@@ -177,6 +181,8 @@ private:
public:
static EFontFormat GetFontFormat(FT_Face pFace);
void ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory = L"");
public:
void LoadFromArrayFiles(CArray<std::wstring>& arrFiles);
void LoadFromFolder(const std::wstring& strDirectory);
......
#include "GraphicsRenderer.h"
#include <algorithm>
////////////////////////////////////////////////////////////////////////////////
......
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