[CHARMAP][IMAGESOFT]
[reactos.git] / rosapps / applications / imagesoft / font.c
1 #include <precomp.h>
2
3 int CALLBACK
4 EnumFontSizes(ENUMLOGFONTEX *lpelfe,
5 NEWTEXTMETRICEX *lpntme,
6 DWORD FontType,
7 LPARAM lParam)
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,
24 CB_ADDSTRING,
25 0,
26 (LPARAM)ach);
27
28 SendMessage(hwndCombo,
29 CB_SETITEMDATA,
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
43 EnumFontNames(ENUMLOGFONTEX *lpelfe,
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,
53 CB_FINDSTRINGEXACT,
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,
63 CB_ADDSTRING,
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,
73 CB_SETITEMDATA,
74 idx,
75 MAKEWPARAM(fFixed, fTrueType));
76 }
77
78 return 1;
79 }
80
81
82 VOID
83 FillFontSizeComboList(HWND hwndCombo)
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
92 HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
93
94 SendMessage(hwndCombo,
95 WM_SETFONT,
96 (WPARAM)hFont,
97 0);
98
99 lf.lfCharSet = DEFAULT_CHARSET;
100 lf.lfPitchAndFamily = 0;
101
102 /* empty the list */
103 SendMessage(hwndCombo,
104 CB_RESETCONTENT,
105 0,
106 0);
107
108 /* enumerate font sizes */
109 EnumFontFamiliesEx(hdc,
110 &lf,
111 (FONTENUMPROC)EnumFontSizes,
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,
124 CB_GETITEMDATA,
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
144 FillFontStyleComboList(HWND hwndCombo)
145 {
146 HDC hdc = GetDC(hwndCombo);
147 LOGFONT lf;
148
149 /* FIXME: draw each font in its own style */
150 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
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 */
164 EnumFontFamiliesEx(hdc,
165 &lf,
166 (FONTENUMPROC)EnumFontNames,
167 (LPARAM)hwndCombo, 0);
168
169 ReleaseDC(hwndCombo,
170 hdc);
171
172 /* set default to Arial */
173 SendMessage(hwndCombo,
174 CB_SELECTSTRING,
175 -1,
176 (LPARAM)_T("Arial"));
177
178
179 }