mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
- make fontview look closer to MS fontview, patch by roytam1, modified by me.
- Create fonts only once - Remove possibility to get page height without drawing See issue #2260 for more details. svn path=/trunk/; revision=26871
This commit is contained in:
parent
5cecf17b6f
commit
96b50f2d59
5 changed files with 124 additions and 65 deletions
|
@ -34,10 +34,17 @@ LRESULT CALLBACK DisplayProc(HWND, UINT, WPARAM, LPARAM);
|
|||
/* Internal data storage type */
|
||||
typedef struct
|
||||
{
|
||||
int nHeight;
|
||||
int nPageHeight;
|
||||
WCHAR szTypeFaceName[MAX_TYPEFACENAME];
|
||||
WCHAR szFormat[MAX_FORMAT];
|
||||
WCHAR szString[MAX_STRING];
|
||||
|
||||
HFONT hCaptionFont;
|
||||
HFONT hCharSetFont;
|
||||
HFONT hSizeFont;
|
||||
HFONT hFonts[MAX_SIZES];
|
||||
int nSizes[MAX_SIZES];
|
||||
int nHeights[MAX_SIZES];
|
||||
} DISPLAYDATA;
|
||||
|
||||
/* This is the only public function, it registers the class */
|
||||
|
@ -69,9 +76,9 @@ Display_InitClass(HINSTANCE hInstance)
|
|||
}
|
||||
|
||||
static int
|
||||
Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos, BOOL bDraw)
|
||||
Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos)
|
||||
{
|
||||
HFONT hOldFont, hFont, hFontNums;
|
||||
HFONT hOldFont;
|
||||
TEXTMETRIC tm;
|
||||
int i, y;
|
||||
const int nSizes[7] = {12, 18, 24, 36, 48, 60, 72};
|
||||
|
@ -81,65 +88,61 @@ Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos, BOOL bDraw)
|
|||
/* This is the location on the DC where we draw */
|
||||
y = -nYPos;
|
||||
|
||||
/* Draw font name */
|
||||
hFont = CreateFontW(50, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , L"Ms Shell Dlg");
|
||||
hOldFont = SelectObject(hDC, hFont);
|
||||
if (bDraw)
|
||||
hOldFont = SelectObject(hDC, pData->hCaptionFont);
|
||||
GetTextMetrics(hDC, &tm);
|
||||
|
||||
if (*pData->szFormat == 0)
|
||||
{
|
||||
swprintf(szCaption, pData->szTypeFaceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
swprintf(szCaption, L"%s (%s)", pData->szTypeFaceName, pData->szFormat);
|
||||
TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
|
||||
}
|
||||
GetTextMetrics(hDC, &tm);
|
||||
TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
|
||||
y += tm.tmHeight + SPACING1;
|
||||
SelectObject(hDC, hOldFont);
|
||||
DeleteObject(hFont);
|
||||
|
||||
/* Draw a seperation Line */
|
||||
if (bDraw)
|
||||
{
|
||||
SelectObject(hDC, GetStockObject(BLACK_PEN));
|
||||
MoveToEx(hDC, 0, y, NULL);
|
||||
LineTo(hDC, 10000, y);
|
||||
}
|
||||
SelectObject(hDC, GetStockObject(BLACK_PEN));
|
||||
MoveToEx(hDC, 0, y, NULL);
|
||||
LineTo(hDC, 10000, y);
|
||||
y += SPACING2;
|
||||
|
||||
/* Output font info */
|
||||
hFont = CreateFontW(12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , pData->szTypeFaceName);
|
||||
hOldFont = SelectObject(hDC, hFont);
|
||||
SelectObject(hDC, hOldFont);
|
||||
DeleteObject(hFont);
|
||||
/* TODO: Output font info */
|
||||
|
||||
/* Outout the lines for different sizes */
|
||||
hFontNums = CreateFontW(12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , L"Ms Shell Dlg");
|
||||
/* Output Character set */
|
||||
hOldFont = SelectObject(hDC, pData->hCharSetFont);
|
||||
GetTextMetrics(hDC, &tm);
|
||||
swprintf(szCaption, L"abcdefghijklmnopqrstuvwxyz");
|
||||
TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
|
||||
y += tm.tmHeight + 1;
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
swprintf(szCaption, L"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
|
||||
y += tm.tmHeight + 1;
|
||||
|
||||
swprintf(szCaption, L"0123456789.:,;(\"~!@#$%^&*')");
|
||||
TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
|
||||
y += tm.tmHeight + 1;
|
||||
|
||||
/* Draw a seperation Line */
|
||||
SelectObject(hDC, GetStockObject(BLACK_PEN));
|
||||
MoveToEx(hDC, 0, y, NULL);
|
||||
LineTo(hDC, 10000, y);
|
||||
y += SPACING2;
|
||||
|
||||
/* Output the strings for different sizes */
|
||||
for (i = 0; i < MAX_SIZES; i++)
|
||||
{
|
||||
hOldFont = SelectObject(hDC, hFontNums);
|
||||
if (bDraw)
|
||||
{
|
||||
swprintf(szSize, L"%d", nSizes[i]);
|
||||
TextOutW(hDC, 0, y, szSize, wcslen(szSize));
|
||||
}
|
||||
hFont = CreateFontW(nSizes[i], 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , pData->szTypeFaceName);
|
||||
SelectObject(hDC, hFont);
|
||||
if (bDraw)
|
||||
{
|
||||
TextOutW(hDC, 20, y, pData->szString, wcslen(pData->szString));
|
||||
}
|
||||
SelectObject(hDC, pData->hFonts[i]);
|
||||
TextOutW(hDC, 20, y, pData->szString, wcslen(pData->szString));
|
||||
GetTextMetrics(hDC, &tm);
|
||||
y += tm.tmHeight + 2;
|
||||
SelectObject(hDC, hOldFont);
|
||||
DeleteObject(hFont);
|
||||
y += tm.tmHeight + 1;
|
||||
SelectObject(hDC, pData->hSizeFont);
|
||||
swprintf(szSize, L"%d", nSizes[i]);
|
||||
TextOutW(hDC, 0, y - 13 - tm.tmDescent, szSize, wcslen(szSize));
|
||||
}
|
||||
DeleteObject(hFontNums);
|
||||
SelectObject(hDC, hOldFont);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
@ -148,14 +151,29 @@ static LRESULT
|
|||
Display_OnCreate(HWND hwnd)
|
||||
{
|
||||
DISPLAYDATA* pData;
|
||||
const int nSizes[7] = {12, 18, 24, 36, 48, 60, 72};
|
||||
int i;
|
||||
|
||||
/* Initialize data structure */
|
||||
pData = malloc(sizeof(DISPLAYDATA));
|
||||
pData->nHeight = 0;
|
||||
pData->nPageHeight = 0;
|
||||
swprintf(pData->szTypeFaceName, L"");
|
||||
swprintf(pData->szFormat, L"");
|
||||
swprintf(pData->szString, L"");
|
||||
|
||||
for (i = 0; i < MAX_SIZES; i++)
|
||||
{
|
||||
pData->nSizes[i] = nSizes[i];
|
||||
}
|
||||
|
||||
pData->hCaptionFont = CreateFontW(50, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , L"Ms Shell Dlg");
|
||||
|
||||
pData->hSizeFont = CreateFontW(12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , L"Ms Shell Dlg");
|
||||
|
||||
/* Set the window's GWLP_USERDATA to our data structure */
|
||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pData);
|
||||
|
||||
|
@ -182,7 +200,7 @@ Display_OnPaint(HWND hwnd)
|
|||
FillRect(ps.hdc, &ps.rcPaint, GetStockObject(WHITE_BRUSH));
|
||||
|
||||
/* Draw the text */
|
||||
Display_DrawText(ps.hdc, pData, si.nPos, TRUE);
|
||||
Display_DrawText(ps.hdc, pData, si.nPos);
|
||||
|
||||
EndPaint(hwnd, &ps);
|
||||
|
||||
|
@ -267,6 +285,7 @@ Display_OnVScroll(HWND hwnd, WPARAM wParam)
|
|||
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
|
||||
UpdateWindow(hwnd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -274,17 +293,42 @@ static LRESULT
|
|||
Display_SetTypeFace(HWND hwnd, LPARAM lParam)
|
||||
{
|
||||
DISPLAYDATA* pData;
|
||||
TEXTMETRIC tm;
|
||||
HDC hDC;
|
||||
RECT rect;
|
||||
SCROLLINFO si;
|
||||
int i;
|
||||
|
||||
/* Set the new type face name */
|
||||
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||
snwprintf(pData->szTypeFaceName, MAX_TYPEFACENAME, (WCHAR*)lParam);
|
||||
|
||||
/* Calculate new page dimensions */
|
||||
/* Create the new fonts */
|
||||
hDC = GetDC(hwnd);
|
||||
pData->nHeight = Display_DrawText(hDC, pData, 0, FALSE);
|
||||
pData->hCharSetFont = CreateFontW(-MulDiv(16, GetDeviceCaps(GetDC(NULL), LOGPIXELSY), 72), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , pData->szTypeFaceName);
|
||||
|
||||
/* Get font format */
|
||||
SelectObject(hDC, pData->hCharSetFont);
|
||||
GetTextMetrics(hDC, &tm);
|
||||
if ((tm.tmPitchAndFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE)
|
||||
{
|
||||
swprintf(pData->szFormat, L"TrueType");
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_SIZES; i++)
|
||||
{
|
||||
pData->hFonts[i] = CreateFontW(MulDiv(pData->nSizes[i], GetDeviceCaps(hDC, LOGPIXELSY), 72),
|
||||
0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
|
||||
CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
|
||||
DEFAULT_PITCH , pData->szTypeFaceName);
|
||||
SelectObject(hDC, pData->hFonts[i]);
|
||||
}
|
||||
|
||||
/* Calculate new page dimensions */
|
||||
pData->nPageHeight = Display_DrawText(hDC, pData, 0);
|
||||
ReleaseDC(hwnd, hDC);
|
||||
|
||||
/* Set the vertical scrolling range and page size */
|
||||
|
@ -292,7 +336,7 @@ Display_SetTypeFace(HWND hwnd, LPARAM lParam)
|
|||
si.cbSize = sizeof(si);
|
||||
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
|
||||
si.nMin = 0;
|
||||
si.nMax = pData->nHeight;
|
||||
si.nMax = pData->nPageHeight;
|
||||
si.nPage = rect.bottom;
|
||||
si.nPos = 0;
|
||||
si.nTrackPos = 0;
|
||||
|
@ -318,9 +362,21 @@ static LRESULT
|
|||
Display_OnDestroy(HWND hwnd)
|
||||
{
|
||||
DISPLAYDATA* pData;
|
||||
int i;
|
||||
|
||||
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||
|
||||
/* Delete the fonts */
|
||||
DeleteObject(pData->hCaptionFont);
|
||||
DeleteObject(pData->hCharSetFont);
|
||||
DeleteObject(pData->hSizeFont);
|
||||
|
||||
for (i = 0; i < MAX_SIZES; i++)
|
||||
{
|
||||
DeleteObject(pData->hFonts[i]);
|
||||
}
|
||||
|
||||
/* Free the data structure */
|
||||
pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||
free(pData);
|
||||
|
||||
return 0;
|
||||
|
@ -353,7 +409,7 @@ DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
return Display_OnDestroy(hwnd);
|
||||
|
||||
default:
|
||||
return DefWindowProc (hwnd, message, wParam, lParam);
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#define MAX_TYPEFACENAME 32
|
||||
#define MAX_FORMAT 20
|
||||
|
||||
#define MAX_SIZES 7
|
||||
|
||||
extern const WCHAR g_szFontDisplayClassName[];
|
||||
|
||||
/* Public function */
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "fontview.h"
|
||||
|
||||
HINSTANCE g_hInstance;
|
||||
WCHAR g_szTitle[MAX_LOADSTRING];
|
||||
WCHAR g_szTypeFaceName[MAX_TYPEFACENAME];
|
||||
static const WCHAR g_szFontViewClassName[] = L"FontViewWClass";
|
||||
|
||||
|
@ -130,7 +129,7 @@ WinMain (HINSTANCE hThisInstance,
|
|||
}
|
||||
|
||||
/* The main window class */
|
||||
wincl.cbSize = sizeof (WNDCLASSEX);
|
||||
wincl.cbSize = sizeof (WNDCLASSEXW);
|
||||
wincl.style = CS_DBLCLKS;
|
||||
wincl.lpfnWndProc = MainWndProc;
|
||||
wincl.cbClsExtra = 0;
|
||||
|
@ -154,7 +153,7 @@ WinMain (HINSTANCE hThisInstance,
|
|||
hMainWnd = CreateWindowExW(
|
||||
0, /* Extended possibilites for variation */
|
||||
g_szFontViewClassName, /* Classname */
|
||||
g_szTitle, /* Title Text */
|
||||
g_szTypeFaceName, /* Title Text */
|
||||
WS_OVERLAPPEDWINDOW, /* default window */
|
||||
CW_USEDEFAULT, /* Windows decides the position */
|
||||
CW_USEDEFAULT, /* where the window ends up on the screen */
|
||||
|
@ -165,7 +164,7 @@ WinMain (HINSTANCE hThisInstance,
|
|||
hThisInstance, /* Program Instance handler */
|
||||
NULL /* No Window Creation data */
|
||||
);
|
||||
ShowWindow (hMainWnd, nCmdShow);
|
||||
ShowWindow(hMainWnd, nCmdShow);
|
||||
|
||||
/* Main message loop */
|
||||
while (GetMessage (&msg, NULL, 0, 0))
|
||||
|
@ -203,11 +202,11 @@ MainWnd_OnCreate(HWND hwnd)
|
|||
NULL /* Window Creation data */
|
||||
);
|
||||
|
||||
/* Init the display window wit the font name */
|
||||
/* Init the display window with the font name */
|
||||
LoadStringW(g_hInstance, IDS_STRING, szString, MAX_STRING);
|
||||
|
||||
SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
|
||||
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)g_szTypeFaceName);
|
||||
|
||||
/* Create the quit button */
|
||||
LoadStringW(g_hInstance, IDS_QUIT, szQuit, MAX_BUTTONNAME);
|
||||
hButtonQuit = CreateWindowExW(
|
||||
|
@ -307,7 +306,7 @@ MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
break;
|
||||
|
||||
default: /* for messages that we don't deal with */
|
||||
return DefWindowProc (hwnd, message, wParam, lParam);
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
|
||||
#include "lang/en-US.rc"
|
||||
#include "lang/de-DE.rc"
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#include "windows.h"
|
||||
#include "../resource.h"
|
||||
|
||||
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
{
|
||||
IDS_QUIT, "Quit"
|
||||
IDS_PRINT, "Print"
|
||||
IDS_STRING, "Jackdaws love my big sphinx of quartz. 123456890"
|
||||
IDS_STRING, "Jackdaws love my big sphinx of quartz. 1234567890"
|
||||
IDS_ERROR, "Error"
|
||||
IDS_ERROR_NOMEM, "There's not enough memory to complete the operation."
|
||||
IDS_ERROR_NOFONT, "The file %1 ist not a valid font file."
|
||||
|
@ -16,3 +16,4 @@ STRINGTABLE DISCARDABLE
|
|||
IDS_ERROR_BADCMD, "No font file given.\nSyntax:\n fontview.exe <font file>"
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue