Author: tkreuzer
Date: Wed May 23 04:25:31 2007
New Revision: 26871
URL:
http://svn.reactos.org/svn/reactos?rev=26871&view=rev
Log:
- 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.
Modified:
trunk/rosapps/fontview/display.c
trunk/rosapps/fontview/display.h
trunk/rosapps/fontview/fontview.c
trunk/rosapps/fontview/fontview.rc
trunk/rosapps/fontview/lang/en-US.rc
Modified: trunk/rosapps/fontview/display.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/fontview/display.c?rev=268…
==============================================================================
--- trunk/rosapps/fontview/display.c (original)
+++ trunk/rosapps/fontview/display.c Wed May 23 04:25:31 2007
@@ -34,10 +34,17 @@
/* 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 @@
}
static int
-Display_DrawText(HDC hDC, DISPLAYDATA* pData, int nYPos, BOOL bDraw)
-{
- HFONT hOldFont, hFont, hFontNums;
+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};
@@ -81,65 +88,61 @@
/* 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));
- }
+ }
+ TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
+ y += tm.tmHeight + SPACING1;
+
+ /* Draw a seperation Line */
+ SelectObject(hDC, GetStockObject(BLACK_PEN));
+ MoveToEx(hDC, 0, y, NULL);
+ LineTo(hDC, 10000, y);
+ y += SPACING2;
+
+ /* TODO: Output font info */
+
+ /* Output Character set */
+ hOldFont = SelectObject(hDC, pData->hCharSetFont);
GetTextMetrics(hDC, &tm);
- y += tm.tmHeight + SPACING1;
+ swprintf(szCaption, L"abcdefghijklmnopqrstuvwxyz");
+ TextOutW(hDC, 0, y, szCaption, wcslen(szCaption));
+ y += tm.tmHeight + 1;
+
+ 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++)
+ {
+ SelectObject(hDC, pData->hFonts[i]);
+ TextOutW(hDC, 20, y, pData->szString, wcslen(pData->szString));
+ GetTextMetrics(hDC, &tm);
+ y += tm.tmHeight + 1;
+ SelectObject(hDC, pData->hSizeFont);
+ swprintf(szSize, L"%d", nSizes[i]);
+ TextOutW(hDC, 0, y - 13 - tm.tmDescent, szSize, wcslen(szSize));
+ }
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);
- }
- 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);
-
- /* 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");
-
- for (i = 0; i < 7; 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));
- }
- GetTextMetrics(hDC, &tm);
- y += tm.tmHeight + 2;
- SelectObject(hDC, hOldFont);
- DeleteObject(hFont);
- }
- DeleteObject(hFontNums);
return y;
}
@@ -148,13 +151,28 @@
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 @@
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 @@
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
UpdateWindow(hwnd);
}
+
return 0;
}
@@ -274,17 +293,42 @@
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);
+ /* Create the new fonts */
+ hDC = GetDC(hwnd);
+ 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 */
- hDC = GetDC(hwnd);
- pData->nHeight = Display_DrawText(hDC, pData, 0, FALSE);
+ pData->nPageHeight = Display_DrawText(hDC, pData, 0);
ReleaseDC(hwnd, hDC);
/* Set the vertical scrolling range and page size */
@@ -292,7 +336,7 @@
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 @@
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 @@
return Display_OnDestroy(hwnd);
default:
- return DefWindowProc (hwnd, message, wParam, lParam);
+ return DefWindowProcW(hwnd, message, wParam, lParam);
}
return 0;
Modified: trunk/rosapps/fontview/display.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/fontview/display.h?rev=268…
==============================================================================
--- trunk/rosapps/fontview/display.h (original)
+++ trunk/rosapps/fontview/display.h Wed May 23 04:25:31 2007
@@ -10,6 +10,8 @@
#define MAX_TYPEFACENAME 32
#define MAX_FORMAT 20
+#define MAX_SIZES 7
+
extern const WCHAR g_szFontDisplayClassName[];
/* Public function */
Modified: trunk/rosapps/fontview/fontview.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/fontview/fontview.c?rev=26…
==============================================================================
--- trunk/rosapps/fontview/fontview.c (original)
+++ trunk/rosapps/fontview/fontview.c Wed May 23 04:25:31 2007
@@ -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 @@
}
/* 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 @@
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 @@
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 @@
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 @@
break;
default: /* for messages that we don't deal with */
- return DefWindowProc (hwnd, message, wParam, lParam);
+ return DefWindowProcW(hwnd, message, wParam, lParam);
}
return 0;
Modified: trunk/rosapps/fontview/fontview.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/fontview/fontview.rc?rev=2…
==============================================================================
--- trunk/rosapps/fontview/fontview.rc (original)
+++ trunk/rosapps/fontview/fontview.rc Wed May 23 04:25:31 2007
@@ -1,5 +1,6 @@
+#include "lang/en-US.rc"
#include "lang/de-DE.rc"
STRINGTABLE DISCARDABLE
Modified: trunk/rosapps/fontview/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/fontview/lang/en-US.rc?rev…
==============================================================================
--- trunk/rosapps/fontview/lang/en-US.rc (original)
+++ trunk/rosapps/fontview/lang/en-US.rc Wed May 23 04:25:31 2007
@@ -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 @@
IDS_ERROR_BADCMD, "No font file given.\nSyntax:\n fontview.exe <font
file>"
}
+