2 // ------------------------------------------------------------------
3 // Windows 2000 Graphics API Black Book
4 // Chapter 4 - Utility functions
6 // Created by Damon Chandler <dmc27@ee.cornell.edu>
7 // Updates can be downloaded at: <www.coriolis.com>
9 // Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10 // if you have any questions about this code.
11 // ------------------------------------------------------------------
13 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
18 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
22 // creates a logical font
24 IN HDC hDestDC, // handle to target DC
25 IN LPCSTR typeface_name, // font's typeface name
26 IN int point_size, // font's point size
27 IN const BYTE charset, // font's character set
28 IN const DWORD style // font's styles
32 // NOTE: On Windows 9x/Me, GetWorldTransform is not
33 // supported. For compatibility with these platforms you
34 // should initialize the XFORM::eM22 data member to 1.0.
36 XFORM xf = {0, 0, 0, 1.0};
37 GetWorldTransform(hDestDC, &xf);
38 int pixels_per_inch = GetDeviceCaps(hDestDC, LOGPIXELSY);
42 -MulDiv(static_cast<int>(xf.eM22 * point_size + 0.5),
47 if (DPtoLP(hDestDC, &PSize, 1))
50 memset(&lf, 0, sizeof(LOGFONT));
52 lf.lfHeight = PSize.y;
53 lf.lfCharSet = charset;
54 lstrcpyn(reinterpret_cast<LPTSTR>(&lf.lfFaceName),
55 typeface_name, LF_FACESIZE);
57 lf.lfWeight = (style & FS_BOLD) ? FW_BOLD : FW_DONTCARE;
58 lf.lfItalic = (style & FS_ITALIC) ? true : false;
59 lf.lfUnderline = (style & FS_UNDERLINE) ? true : false;
60 lf.lfStrikeOut = (style & FS_STRIKEOUT) ? true : false;
62 // create the logical font
63 hResult = CreateFontIndirect(&lf);
67 //-------------------------------------------------------------------------