ReactOS 0.4.15-dev-8138-g1e75ea8
mk_font.cpp
Go to the documentation of this file.
1
2// ------------------------------------------------------------------
3// Windows 2000 Graphics API Black Book
4// Chapter 4 - Utility functions
5//
6// Created by Damon Chandler <dmc27@ee.cornell.edu>
7// Updates can be downloaded at: <www.coriolis.com>
8//
9// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10// if you have any questions about this code.
11// ------------------------------------------------------------------
12
13//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
14#include <windows.h>
15#include <cassert>
16
17#include "mk_font.h"
18//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
19
20namespace font {
21
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
29 )
30{
31 //
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.
35 //
36 XFORM xf = {0, 0, 0, 1.0, 0, 0};
37 GetWorldTransform(hDestDC, &xf);
38 int pixels_per_inch = GetDeviceCaps(hDestDC, LOGPIXELSY);
39
40 POINT PSize = {
41 0,
42 -MulDiv(static_cast<int>(xf.eM22 * point_size + 0.5),
43 pixels_per_inch, 72)
44 };
45
46 HFONT hResult = NULL;
47 if (DPtoLP(hDestDC, &PSize, 1))
48 {
49 LOGFONT lf;
50 memset(&lf, 0, sizeof(LOGFONT));
51
52 lf.lfHeight = PSize.y;
53 lf.lfCharSet = charset;
54 lstrcpyn(reinterpret_cast<LPTSTR>(&lf.lfFaceName),
55 typeface_name, LF_FACESIZE);
56
58 lf.lfItalic = (style & FS_ITALIC) ? true : false;
59 lf.lfUnderline = (style & FS_UNDERLINE) ? true : false;
60 lf.lfStrikeOut = (style & FS_STRIKEOUT) ? true : false;
61
62 // create the logical font
63 hResult = CreateFontIndirect(&lf);
64 }
65 return hResult;
66}
67//-------------------------------------------------------------------------
68
69} // namespace font
Arabic default style
Definition: afstyles.h:94
CFF_Charset charset
Definition: cffcmap.c:138
#define LF_FACESIZE
Definition: dimm.idl:39
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
INT WINAPI MulDiv(INT nNumber, INT nNumerator, INT nDenominator)
Definition: muldiv.c:25
Definition: mk_font.cpp:20
static const ULONG FS_ITALIC
Definition: mk_font.h:26
static const ULONG FS_BOLD
Definition: mk_font.h:25
HFONT MakeFont(IN HDC hDestDC, IN LPCSTR typeface_name, IN int point_size, IN const BYTE charset, IN const DWORD style)
Definition: mk_font.cpp:23
static const ULONG FS_STRIKEOUT
Definition: mk_font.h:28
static const ULONG FS_UNDERLINE
Definition: mk_font.h:27
#define memset(x, y, z)
Definition: compat.h:39
BYTE lfStrikeOut
Definition: dimm.idl:49
BYTE lfUnderline
Definition: dimm.idl:48
BYTE lfItalic
Definition: dimm.idl:47
LONG lfHeight
Definition: dimm.idl:42
BYTE lfCharSet
Definition: dimm.idl:50
LONG lfWeight
Definition: dimm.idl:46
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
FLOAT eM22
Definition: wingdi.h:1724
long y
Definition: polytest.cpp:48
#define IN
Definition: typedefs.h:39
#define lstrcpyn
Definition: winbase.h:3875
#define FW_DONTCARE
Definition: wingdi.h:368
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define FW_BOLD
Definition: wingdi.h:378
#define LOGPIXELSY
Definition: wingdi.h:719
BOOL WINAPI DPtoLP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
BOOL WINAPI GetWorldTransform(_In_ HDC, _Out_ LPXFORM)
Definition: coord.c:278
#define CreateFontIndirect
Definition: wingdi.h:4444
const char * LPCSTR
Definition: xmlstorage.h:183
CHAR * LPTSTR
Definition: xmlstorage.h:192
unsigned char BYTE
Definition: xxhash.c:193