From 1b70c2f495a7afc25851f2329a7cc869d0ec3121 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Mon, 11 Jun 2007 20:38:55 +0000 Subject: [PATCH] - use LOGFONTW structure from GetFontResourceInfo for face name - use LF_FULLFACESIZE - some cleanup svn path=/trunk/; revision=27148 --- rosapps/fontview/display.c | 11 +++++------ rosapps/fontview/display.h | 2 -- rosapps/fontview/fontview.c | 29 +++++++++++++++++++---------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/rosapps/fontview/display.c b/rosapps/fontview/display.c index 217903d0a2e..f9121f05260 100644 --- a/rosapps/fontview/display.c +++ b/rosapps/fontview/display.c @@ -35,7 +35,7 @@ LRESULT CALLBACK DisplayProc(HWND, UINT, WPARAM, LPARAM); typedef struct { int nPageHeight; - WCHAR szTypeFaceName[MAX_TYPEFACENAME]; + WCHAR szTypeFaceName[LF_FULLFACESIZE]; WCHAR szFormat[MAX_FORMAT]; WCHAR szString[MAX_STRING]; @@ -81,9 +81,8 @@ Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos) HFONT hOldFont; TEXTMETRIC tm; int i, y; - const int nSizes[7] = {12, 18, 24, 36, 48, 60, 72}; WCHAR szSize[5]; - WCHAR szCaption[MAX_TYPEFACENAME + 20]; + WCHAR szCaption[LF_FULLFACESIZE + 20]; /* This is the location on the DC where we draw */ y = -nYPos; @@ -132,7 +131,7 @@ Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos) GetTextMetrics(hDC, &tm); y += tm.tmHeight + 1; SelectObject(hDC, pData->hSizeFont); - swprintf(szSize, L"%d", nSizes[i]); + swprintf(szSize, L"%d", pData->nSizes[i]); TextOutW(hDC, 0, y - 13 - tm.tmDescent, szSize, wcslen(szSize)); } SelectObject(hDC, hOldFont); @@ -152,7 +151,7 @@ Display_SetTypeFace(HWND hwnd, LPARAM lParam) /* Set the new type face name */ pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA); - snwprintf(pData->szTypeFaceName, MAX_TYPEFACENAME, (WCHAR*)lParam); + snwprintf(pData->szTypeFaceName, LF_FULLFACESIZE, (WCHAR*)lParam); /* Create the new fonts */ hDC = GetDC(hwnd); @@ -217,7 +216,7 @@ static LRESULT Display_OnCreate(HWND hwnd) { DISPLAYDATA* pData; - const int nSizes[7] = {12, 18, 24, 36, 48, 60, 72}; + const int nSizes[MAX_SIZES] = {12, 18, 24, 36, 48, 60, 72}; int i; /* Create data structure */ diff --git a/rosapps/fontview/display.h b/rosapps/fontview/display.h index 5ba9d53a962..6180cf71f24 100644 --- a/rosapps/fontview/display.h +++ b/rosapps/fontview/display.h @@ -7,9 +7,7 @@ /* Size restrictions */ #define MAX_STRING 100 -#define MAX_TYPEFACENAME 32 #define MAX_FORMAT 20 - #define MAX_SIZES 7 extern const WCHAR g_szFontDisplayClassName[]; diff --git a/rosapps/fontview/fontview.c b/rosapps/fontview/fontview.c index 70bb0f5df2b..54a6ed67333 100644 --- a/rosapps/fontview/fontview.c +++ b/rosapps/fontview/fontview.c @@ -23,11 +23,13 @@ #include "fontview.h" HINSTANCE g_hInstance; -WCHAR g_szTypeFaceName[MAX_TYPEFACENAME]; +WCHAR g_szTypeFaceName[LF_FULLFACESIZE]; +LOGFONTW g_LogFontW; + static const WCHAR g_szFontViewClassName[] = L"FontViewWClass"; /* Tye definition for the GetFontResourceInfo function */ -typedef BOOL (WINAPI *PGFRI)(LPCWSTR, DWORD *, LPWSTR, DWORD); +typedef BOOL (WINAPI *PGFRI)(LPCWSTR, DWORD *, LPVOID, DWORD); DWORD FormatString( @@ -122,6 +124,13 @@ WinMain (HINSTANCE hThisInstance, return -1; } + dwSize = sizeof(LOGFONTW); + if (!GetFontResourceInfoW(argv[1], &dwSize, &g_LogFontW, 2)) + { + ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, argv[1]); + return -1; + } + if (!Display_InitClass(hThisInstance)) { ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOCLASS); @@ -206,7 +215,7 @@ MainWnd_OnCreate(HWND hwnd) SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString); /* Init the display window with the font name */ - SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)g_szTypeFaceName); + SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_LogFontW.lfFaceName); ShowWindow(hDisplay, SW_SHOWNORMAL); /* Create the quit button */ @@ -303,15 +312,15 @@ MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } break; - case WM_DESTROY: - PostQuitMessage (0); /* send a WM_QUIT to the message queue */ - break; + case WM_DESTROY: + PostQuitMessage (0); /* send a WM_QUIT to the message queue */ + break; - default: /* for messages that we don't deal with */ - return DefWindowProcW(hwnd, message, wParam, lParam); - } + default: /* for messages that we don't deal with */ + return DefWindowProcW(hwnd, message, wParam, lParam); + } - return 0; + return 0; } /* EOF */