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)
}
This diff is collapsed.
......@@ -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