1
/*******************************************************************
3
* gw_win32.c graphics driver for Win32 platform. 0.1
5
* This is the driver for displaying inside a window under Win32,
6
* used by the graphics utility of the FreeType test suite.
8
* Written by Antoine Leca.
9
* Copyright 1999 by Antoine Leca,
10
* David Turner, Robert Wilhelm, and Werner Lemberg.
12
* Borrowing liberally from the other FreeType drivers.
14
* This file is part of the FreeType project, and may only be used
15
* modified and distributed under the terms of the FreeType project
16
* license, LICENSE.TXT. By continuing to use, modify or distribute
17
* this file you indicate that you have read the license and
18
* understand and accept it fully.
20
******************************************************************/
26
#define WIN32_LEAN_AND_MEAN
34
/* Size of the window. */
35
#define WIN_WIDTH 640u
36
#define WIN_HEIGHT 450u
38
/* These values can be changed, but WIN_WIDTH should remain for now a */
39
/* multiple of 32 to avoid padding issues. */
42
typedef struct _Translator
49
#define NUM_Translators 20
51
static const Translator trans[NUM_Translators] =
53
{ (char)27, event_Quit, 0 },
54
{ 'q', event_Quit, 0 },
56
{ 'x', event_Rotate_Glyph, -1 },
57
{ 'c', event_Rotate_Glyph, 1 },
58
{ 'v', event_Rotate_Glyph, -16 },
59
{ 'b', event_Rotate_Glyph, 16 },
61
{ '{', event_Change_Glyph, -10000 },
62
{ '}', event_Change_Glyph, 10000 },
63
{ '(', event_Change_Glyph, -1000 },
64
{ ')', event_Change_Glyph, 1000 },
65
{ '9', event_Change_Glyph, -100 },
66
{ '0', event_Change_Glyph, 100 },
67
{ 'i', event_Change_Glyph, -10 },
68
{ 'o', event_Change_Glyph, 10 },
69
{ 'k', event_Change_Glyph, -1 },
70
{ 'l', event_Change_Glyph, 1 },
72
{ '+', event_Scale_Glyph, 10 },
73
{ '-', event_Scale_Glyph, -10 },
74
{ 'u', event_Scale_Glyph, 1 },
75
{ 'j', event_Scale_Glyph, -1 }
78
/* handle of the window. */
79
static HWND hwndGraphic;
81
/* bitmap information */
82
static LPBITMAPINFO pbmi;
85
/* local event to pass on */
86
static TEvent ourevent = { event_Quit, 0 };
87
static int eventToProcess = 0;
89
/* array defined in the test programs */
93
/* restores screen to its original state */
95
int Driver_Restore_Mode()
97
/* The graphical window has perhaps already destroyed itself */
99
DestroyWindow ( hwndGraphic );
100
PostMessage( hwndGraphic, WM_QUIT, 0, 0 );
103
if ( pbmi ) free ( pbmi );
111
* and create the window class and the message handling.
114
/* Declarations of the Windows-specific functions that are below. */
115
static BOOL RegisterTheClass ( void );
116
static BOOL CreateTheWindow ( int width, int height );
119
int Driver_Set_Graphics ( int mode )
122
static RGBQUAD gray_scale[5] = {
123
{ 0xFF, 0xFF, 0xFF, 0 }, /* white */
124
{ 0xC0, 0xC0, 0xC0, 0 },
125
{ 0x80, 0x80, 0x80, 0 },
126
{ 0x40, 0x40, 0x40, 0 },
127
{ 0, 0, 0, 0 } }; /* black */
129
if( ! RegisterTheClass() ) return 0; /* if already running, fails. */
131
/* find some memory for the bitmap header */
132
if ( (pbmi = malloc ( sizeof ( BITMAPINFO ) + sizeof ( RGBQUAD ) * 256 ) )
133
/* 256 should really be 2 if not grayscale */
135
/* lack of memory; fails the process */
138
/* initialize the header to appropriate values */
139
memset( pbmi, 0, sizeof ( BITMAPINFO ) + sizeof ( RGBQUAD ) * 256 );
143
case Graphics_Mode_Mono:
144
pbmi->bmiHeader.biBitCount = 1;
145
pbmi->bmiColors[0] = gray_scale[0];
146
pbmi->bmiColors[1] = gray_scale[4];
148
vio_ScanLineWidth = WIN_WIDTH / 8;
149
vio_Width = WIN_WIDTH;
150
vio_Height = WIN_HEIGHT;
154
case Graphics_Mode_Gray:
155
pbmi->bmiHeader.biBitCount = 8;
156
pbmi->bmiHeader.biClrUsed = 5;
158
memcpy ( &pbmi->bmiColors[0], gray_scale, sizeof gray_scale );
160
vio_ScanLineWidth = WIN_WIDTH;
161
vio_Width = WIN_WIDTH;
162
vio_Height = WIN_HEIGHT;
164
for ( i = 0; i < 5; ++i )
171
return 0; /* Unknown mode */
174
pbmi->bmiHeader.biSize = sizeof ( BITMAPINFOHEADER );
175
pbmi->bmiHeader.biWidth = vio_Width;
176
pbmi->bmiHeader.biHeight = vio_Height;
177
pbmi->bmiHeader.biPlanes = 1;
179
if( ! CreateTheWindow(vio_Width, vio_Height) )
185
return 1; /* success even if the window was not built. */
189
int Driver_Display_Bitmap ( char* buffer, int lines, int cols )
193
if ( cols * 8 != pbmi->bmiHeader.biWidth * pbmi->bmiHeader.biBitCount )
194
pbmi->bmiHeader.biWidth = cols * 8 / pbmi->bmiHeader.biBitCount;
196
hDC = GetDC ( hwndGraphic );
197
SetDIBits ( hDC, hbm, 0, lines, buffer, pbmi, DIB_RGB_COLORS );
198
ReleaseDC ( hwndGraphic, hDC );
200
ShowWindow( hwndGraphic, SW_SHOW );
201
InvalidateRect ( hwndGraphic, NULL, FALSE );
202
UpdateWindow ( hwndGraphic );
204
return 1; /* success */
208
void Get_Event( TEvent* event )
214
SetWindowText ( hwndGraphic, Header );
218
while ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) {
219
TranslateMessage ( &msg );
220
DispatchMessage ( &msg );
222
if ( ! eventToProcess )
224
} while ( ! eventToProcess );
226
event->what = ourevent.what;
227
event->info = ourevent.info;
233
/* ---- Windows-specific stuff ------------------------------------------- */
235
LRESULT CALLBACK Message_Process( HWND, UINT, WPARAM, LPARAM );
238
BOOL RegisterTheClass ( void )
240
WNDCLASS ourClass = {
242
/* WNDPROC lpfnWndProc */ Message_Process,
243
/* int cbClsExtra */ 0,
244
/* int cbWndExtra */ 0,
245
/* HANDLE hInstance */ 0,
247
/* HCURSOR hCursor */ 0,
248
/* HBRUSH hbrBackground*/ 0,
249
/* LPCTSTR lpszMenuName */ NULL,
250
/* LPCTSTR lpszClassName*/ "FreeTypeTestGraphicDriver"
253
ourClass.hInstance = GetModuleHandle( NULL );
254
ourClass.hIcon = LoadIcon(0, IDI_APPLICATION);
255
ourClass.hCursor = LoadCursor(0, IDC_ARROW);
256
ourClass.hbrBackground= GetStockObject(BLACK_BRUSH);
258
return RegisterClass(&ourClass) != 0; /* return False if it fails. */
262
BOOL CreateTheWindow ( int width, int height )
265
if ( ! (hwndGraphic = CreateWindow(
266
/* LPCSTR lpszClassName; */ "FreeTypeTestGraphicDriver",
267
/* LPCSTR lpszWindowName; */ "FreeType Test Graphic Driver",
268
/* DWORD dwStyle; */ WS_OVERLAPPED | WS_SYSMENU,
269
/* int x; */ CW_USEDEFAULT,
270
/* int y; */ CW_USEDEFAULT,
271
/* int nWidth; */ width + 2*GetSystemMetrics(SM_CXBORDER),
272
/* int nHeight; */ height+ GetSystemMetrics(SM_CYBORDER)
273
+ GetSystemMetrics(SM_CYCAPTION),
274
/* HWND hwndParent; */ HWND_DESKTOP,
275
/* HMENU hmenu; */ 0,
276
/* HINSTANCE hinst; */ GetModuleHandle( NULL ),
277
/* void FAR* lpvParam; */ NULL))
279
/* creation failed... */
285
/* Message processing for our Windows class */
286
LRESULT CALLBACK Message_Process( HWND handle, UINT mess,
287
WPARAM wParam, LPARAM lParam )
293
/* warn the main thread to quit if it didn't know */
294
ourevent.what = event_Quit;
298
PostQuitMessage ( 0 );
299
DeleteObject ( hbm );
306
hDC = GetDC ( handle );
307
hbm = CreateDIBitmap (
308
/* HDC hdc; handle of device context */ hDC,
309
/* BITMAPINFOHEADER FAR* lpbmih; addr.of header*/ &pbmi->bmiHeader,
310
/* DWORD dwInit; CBM_INIT to initialize bitmap */ 0,
311
/* const void FAR* lpvBits; address of values */ NULL,
312
/* BITMAPINFO FAR* lpbmi; addr.of bitmap data */ pbmi,
313
/* UINT fnColorUse; RGB or palette indices */ DIB_RGB_COLORS);
314
ReleaseDC ( handle, hDC );
324
hDC = BeginPaint ( handle, &ps );
325
memDC = CreateCompatibleDC(hDC);
326
oldbm = SelectObject(memDC, hbm);
327
BitBlt ( hDC, 0, 0, vio_Width, vio_Height, memDC, 0, 0, SRCCOPY);
328
ReleaseDC ( handle, hDC );
329
SelectObject ( memDC, oldbm );
330
DeleteObject ( memDC );
331
EndPaint ( handle, &ps );
338
ourevent.what = event_Quit;
343
case VK_F1: /* bring up help and about dialog window */
353
for ( i = 0; i < NUM_Translators; i++ )
355
if ( c == trans[i].key )
357
ourevent.what = trans[i].event_class;
358
ourevent.info = trans[i].event_info;
364
/* unrecognized keystroke */
365
ourevent.what = event_Keyboard;
366
ourevent.info = (int)c;
372
return DefWindowProc( handle, mess, wParam, lParam );