rendered paste body// FontToolLib.cpp : Defines the exported functions for the DLL application.//#include "stdafx.h"#define MAGIC_NUM 0x00464345struct FntHeader{ DWORD magic;};struct KerningPair{ WORD previous; WORD kerning;};struct CharDesc{ wchar_t c; WORD numKernPairs; int x, y, w, h; std::vector<KerningPair> charPairs;};void writeCharDesc( CharDesc *pDesc, FILE *pFile ){ fwrite(pDesc, 20, 1, pFile); for (int i = 0; i < pDesc->numKernPairs; i++) { fwrite(&pDesc->charPairs[i], sizeof(KerningPair), 1, pFile); }}bool createFontFile(const wchar_t *lpcFileName, const wchar_t *lpcFontName, int size){ CharDesc chTable[128]; wchar_t chars[128]; FILE* pFile = _wfopen(lpcFileName, L"wb"); if (!pFile) return false; HDC hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); if (!hdc) return false; HDC hdcMem = CreateCompatibleDC(hdc); if (!hdcMem) { DeleteDC(hdc); return false; } HFONT hFont = CreateFontW(-MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72), 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH, lpcFontName); if (!hFont) { DeleteDC(hdcMem); DeleteDC(hdc); return false; } HBITMAP hBmp = CreateCompatibleBitmap(hdc, 256, 256); if (!hBmp) { DeleteDC(hdcMem); DeleteDC(hdc); DeleteObject(hFont); return false; } for (int i = 0; i < 128; i++) { chars[i] = i; } LOGBRUSH lbrush; lbrush.lbColor = RGB(0,0,0); lbrush.lbHatch = 0; lbrush.lbStyle = BS_SOLID; HBRUSH hBrush = CreateBrushIndirect(&lbrush); HPEN hPen = CreatePen(PS_NULL, 0, 0); SelectObject(hdcMem, hBmp); SelectObject(hdcMem, hFont); SelectObject(hdcMem, hPen); SelectObject(hdcMem, hBrush); SetTextColor(hdcMem, RGB(255,255,255)); Rectangle(hdcMem, 0, 0, 256, 256); SetBkMode(hdcMem, TRANSPARENT); KerningPair kp; DWORD numPairs = GetKerningPairs(hdcMem, 0, NULL); KERNINGPAIR *kernPairs = new KERNINGPAIR[numPairs]; GetKerningPairs(hdcMem, 0, kernPairs); for (int i = 0; i < numPairs; i++) { kp.kerning = kernPairs[i].iKernAmount; kp.previous = kernPairs[i].wFirst; chTable[kernPairs[i].wSecond].charPairs.push_back(kp); } delete kernPairs; SIZE chSize; DWORD magic = MAGIC_NUM; int x = 0, y = 0, rowHeight = 0, blockSize = 0; fwrite(&magic, 4, 1, pFile); for (int i = 0; i < 128; i++) { GetTextExtentPoint32(hdcMem, &chars[i], 1, &chSize); chTable[i].c = chars[i]; chTable[i].w = chSize.cx; chTable[i].h = chSize.cy; chTable[i].numKernPairs = chTable[i].charPairs.size(); if ((x + chSize.cx + 1) >= 256) { x = 0; y += rowHeight; rowHeight = 0; chTable[i].x = x; chTable[i].y = y; } else { chTable[i].x = x; chTable[i].y = y; x += chSize.cx + 1; } blockSize += (20 + 4*chTable[i].numKernPairs); if (rowHeight < chSize.cy) rowHeight = chSize.cy; TextOut(hdcMem, x, y, &chars[i], 1); } fwrite(&blockSize, 4, 1, pFile); for (int i = 0; i < 128; i++) { writeCharDesc(&chTable[i], pFile); } blockSize = 256 * 256; fwrite(&blockSize, 4, 1, pFile); BYTE r; COLORREF col; BYTE fontData[256 * 256]; for (int j = 0; j < 256; j++) { for (int i = 0; i < 256; i++) { col = GetPixel(hdc, i, j); r = GetRValue(col); fontData[i * (j+1)] = r; } } fwrite(fontData, blockSize, 1, pFile); fclose(pFile); DeleteObject(hBrush); DeleteObject(hPen); DeleteObject(hFont); DeleteObject(hBmp); DeleteDC(hdcMem); DeleteDC(hdc);}