ReactOS  0.4.14-dev-49-gfb4591c
font.c
Go to the documentation of this file.
1 #include <precomp.h>
2 
3 int CALLBACK
5  NEWTEXTMETRICEX *lpntme,
6  DWORD FontType,
8 {
9  static int ttsizes[] = { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
10  TCHAR ach[100];
11 
12  BOOL fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;
13 
14  HWND hwndCombo = (HWND)lParam;
15  INT i, idx;
16 
17  if (fTrueType)
18  {
19  for (i = 0; i < (sizeof(ttsizes) / sizeof(ttsizes[0])); i++)
20  {
21  wsprintf(ach, _T("%d"), ttsizes[i]);
22 
23  idx = (INT)SendMessage(hwndCombo,
25  0,
26  (LPARAM)ach);
27 
28  SendMessage(hwndCombo,
30  idx,
31  ttsizes[i]);
32  }
33 
34  return 0;
35  }
36 
37  return 1;
38 }
39 
40 
41 /* Font-enumeration callback */
42 int CALLBACK
44  NEWTEXTMETRICEX *lpntme,
45  DWORD FontType,
46  LPARAM lParam)
47 {
48  HWND hwndCombo = (HWND)lParam;
49  TCHAR *pszName = lpelfe->elfLogFont.lfFaceName;
50 
51  /* make sure font doesn't already exist in our list */
52  if(SendMessage(hwndCombo,
54  0,
55  (LPARAM)pszName) == CB_ERR)
56  {
57  INT idx;
58  BOOL fFixed;
59  BOOL fTrueType;
60 
61  /* add the font */
62  idx = (INT)SendMessage(hwndCombo,
64  0,
65  (LPARAM)pszName);
66 
67  /* record the font's attributes (Fixedwidth and Truetype) */
68  fFixed = (lpelfe->elfLogFont.lfPitchAndFamily & FIXED_PITCH) ? TRUE : FALSE;
69  fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;
70 
71  /* store this information in the list-item's userdata area */
72  SendMessage(hwndCombo,
74  idx,
75  MAKEWPARAM(fFixed, fTrueType));
76  }
77 
78  return 1;
79 }
80 
81 
82 VOID
84 {
85  LOGFONT lf = { 0 };
86  HDC hdc = GetDC(hwndCombo);
87 
88  /* default size */
89  INT cursize = 12;
90  INT i, count, nearest = 0;
91 
93 
94  SendMessage(hwndCombo,
95  WM_SETFONT,
96  (WPARAM)hFont,
97  0);
98 
100  lf.lfPitchAndFamily = 0;
101 
102  /* empty the list */
103  SendMessage(hwndCombo,
105  0,
106  0);
107 
108  /* enumerate font sizes */
110  &lf,
112  (LPARAM)hwndCombo,
113  0);
114 
115  /* set selection to first item */
116  count = (INT)SendMessage(hwndCombo,
117  CB_GETCOUNT,
118  0,
119  0);
120 
121  for(i = 0; i < count; i++)
122  {
123  INT n = (INT)SendMessage(hwndCombo,
125  i,
126  0);
127 
128  if (n <= cursize)
129  nearest = i;
130  }
131 
132  SendMessage(hwndCombo,
133  CB_SETCURSEL,
134  nearest,
135  0);
136 
137  ReleaseDC(hwndCombo,
138  hdc);
139 }
140 
141 
142 /* Initialize the font-list by enumeration all system fonts */
143 VOID
145 {
146  HDC hdc = GetDC(hwndCombo);
147  LOGFONT lf;
148 
149  /* FIXME: draw each font in its own style */
151  SendMessage(hwndCombo,
152  WM_SETFONT,
153  (WPARAM)hFont,
154  0);
155 
156  /* FIXME: set this in relation to the widest string */
157  SendMessage(hwndCombo, CB_SETDROPPEDWIDTH, 150, 0);
158 
159  lf.lfCharSet = ANSI_CHARSET; // DEFAULT_CHARSET;
160  lf.lfFaceName[0] = _T('\0'); // all fonts
161  lf.lfPitchAndFamily = 0;
162 
163  /* store the list of fonts in the combo */
165  &lf,
167  (LPARAM)hwndCombo, 0);
168 
169  ReleaseDC(hwndCombo,
170  hdc);
171 
172  /* set default to Arial */
173  SendMessage(hwndCombo,
175  -1,
176  (LPARAM)_T("Arial"));
177 
178 
179 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define CB_SETITEMDATA
Definition: winuser.h:1948
#define TRUE
Definition: types.h:120
#define MAKEWPARAM(l, h)
Definition: winuser.h:3948
HDC WINAPI GetDC(_In_opt_ HWND)
#define CB_SETDROPPEDWIDTH
Definition: winuser.h:1944
#define CB_GETITEMDATA
Definition: winuser.h:1932
GLuint GLuint GLsizei count
Definition: gl.h:1545
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
GLdouble n
Definition: glext.h:7729
HANDLE HWND
Definition: compat.h:13
BYTE lfCharSet
Definition: dimm.idl:50
UINT_PTR WPARAM
Definition: windef.h:207
#define DEFAULT_CHARSET
Definition: wingdi.h:383
int32_t INT
Definition: typedefs.h:56
HFONT hFont
Definition: main.c:53
BYTE lfOutPrecision
Definition: dimm.idl:51
VOID FillFontStyleComboList(HWND hwndCombo)
Definition: font.c:144
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXED_PITCH
Definition: wingdi.h:443
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
unsigned int idx
Definition: utils.c:41
#define CB_ADDSTRING
Definition: winuser.h:1918
LONG_PTR LPARAM
Definition: windef.h:208
BYTE lfPitchAndFamily
Definition: dimm.idl:54
#define CB_RESETCONTENT
Definition: winuser.h:1941
#define CB_ERR
Definition: winuser.h:2410
int CALLBACK EnumFontNames(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, DWORD FontType, LPARAM lParam)
Definition: font.c:43
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static UINT UINT count
Definition: font.c:44
VOID FillFontSizeComboList(HWND hwndCombo)
Definition: font.c:83
#define OUT_STROKE_PRECIS
Definition: wingdi.h:417
int CALLBACK EnumFontSizes(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, DWORD FontType, LPARAM lParam)
Definition: font.c:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DEFAULT_GUI_FONT
Definition: wingdi.h:908
HDC hdc
Definition: main.c:9
#define CB_SELECTSTRING
Definition: winuser.h:1942
#define CB_SETCURSEL
Definition: winuser.h:1943
static INT(WINAPI *pAddFontResourceExA)(LPCSTR
#define EnumFontFamiliesEx
Definition: wingdi.h:4446
#define WM_SETFONT
Definition: winuser.h:1632
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
FONTENUMPROCA FONTENUMPROC
Definition: wingdi.h:2897
#define SendMessage
Definition: winuser.h:5744
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
#define CB_GETCOUNT
Definition: winuser.h:1924
#define ANSI_CHARSET
Definition: wingdi.h:382
#define wsprintf
Definition: winuser.h:5766
LPARAM lParam
Definition: combotst.c:139
LOGFONTA elfLogFont
Definition: wingdi.h:2691
#define CB_FINDSTRINGEXACT
Definition: winuser.h:1922