2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/console/font.c
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
18 * Current active font, corresponding to the active console font,
19 * and used for painting the text samples.
21 HFONT hCurrentFont
= NULL
;
25 * Standard font pixel/point heights for TrueType fonts
27 static const SHORT TrueTypePoints
[] =
29 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72
32 typedef struct _FONTSIZE_LIST_CTL
34 LIST_CTL RasterSizeList
; // ListBox for Raster font sizes; needs to handle bisection.
35 HWND hWndTTSizeList
; // ComboBox for TrueType font sizes.
36 BOOL bIsTTSizeDirty
; // TRUE or FALSE depending on whether we have edited the edit zone.
37 BOOL UseRasterOrTTList
; // TRUE: Use the Raster size list; FALSE: Use the TrueType size list.
38 BOOL TTSizePixelUnit
; // TRUE: Size in pixels (default); FALSE: Size in points.
39 LONG CurrentRasterSize
;
40 LONG CurrentTTSize
; // In whatever unit (pixels or points) currently selected.
41 } FONTSIZE_LIST_CTL
, *PFONTSIZE_LIST_CTL
;
43 /* Used by FontTypeChange() only */
44 static INT CurrentSelFont
= LB_ERR
;
45 static DWORD CurrentFontType
= (DWORD
)-1; // Invalid font type
50 RasterSizeList_GetCount(
53 return (INT
)SendMessageW(ListCtl
->hWndList
, LB_GETCOUNT
, 0, 0);
58 RasterSizeList_GetData(
62 return (ULONG_PTR
)SendMessageW(ListCtl
->hWndList
, LB_GETITEMDATA
, (WPARAM
)Index
, 0);
67 LogicalSizeToPointSize(
77 // LogicalSize = tm.tmHeight - tm.tmInternalLeading;
78 PointSize
= MulDiv(LogicalSize
, 72, GetDeviceCaps(hDC
, LOGPIXELSY
));
87 PointSizeToLogicalSize(
97 LogicalSize
= MulDiv(PointSize
, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
100 ReleaseDC(NULL
, hDC
);
107 FontSizeList_SelectFontSize(
108 IN PFONTSIZE_LIST_CTL SizeList
,
112 WCHAR szFontSize
[100];
115 // FIXME: Check whether FontSize == 0
116 // (or in the case of raster font maybe, whether HIWORD(FontSize) == Height == 0) ??
119 /* Find and select the best font size in the list corresponding to the current size */
120 if (SizeList
->UseRasterOrTTList
)
124 /* Raster font size (in pixels) */
125 SizeList
->CurrentRasterSize
= FontSize
;
127 nSel
= BisectListSortedByValue(&SizeList
->RasterSizeList
, FontSize
, NULL
, FALSE
);
128 idx
= (INT
)SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_GETCOUNT
, 0, 0);
131 /* Not found, select the first element of the list */
134 else if (nSel
>= idx
)
137 * We got an index beyond the end of the list (as per Bisect* functionality),
138 * so instead, select the last element of the list.
142 SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_SETCURSEL
, (WPARAM
)nSel
, 0);
146 /* TrueType font size (in pixels or points) */
147 SizeList
->CurrentTTSize
= FontSize
;
149 // _ultow(szFontSize, FontSize, 10);
150 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", FontSize
);
152 /* Find the font size in the list, or add it both in the ComboBox list, sorted by size value (string), and its edit box */
153 nSel
= SendMessageW(SizeList
->hWndTTSizeList
, CB_FINDSTRINGEXACT
, 0, (LPARAM
)szFontSize
);
156 nSel
= (UINT
)SendMessageW(SizeList
->hWndTTSizeList
, CB_ADDSTRING
, -1, (LPARAM
)szFontSize
);
157 // ComboBox_SetText(...)
158 SetWindowTextW(SizeList
->hWndTTSizeList
, szFontSize
);
159 SizeList
->bIsTTSizeDirty
= TRUE
;
161 SendMessageW(SizeList
->hWndTTSizeList
, CB_SETCURSEL
, (WPARAM
)nSel
, 0);
166 FontSizeList_GetSelectedFontSize(
167 IN PFONTSIZE_LIST_CTL SizeList
)
171 PWCHAR pszNext
= NULL
;
172 WCHAR szFontSize
[100];
174 if (SizeList
->UseRasterOrTTList
)
176 /* Raster font size (in pixels) */
178 nSel
= (INT
)SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_GETCURSEL
, 0, 0);
179 if (nSel
== LB_ERR
) return 0;
181 FontSize
= (LONG
)SizeList
->RasterSizeList
.GetData(&SizeList
->RasterSizeList
, nSel
);
182 if (FontSize
== LB_ERR
) return 0;
184 SizeList
->CurrentRasterSize
= FontSize
;
188 /* TrueType font size (in pixels or points) */
190 if (!SizeList
->bIsTTSizeDirty
)
193 * The user just selected an existing size, read the ComboBox selection.
195 * See: https://support.microsoft.com/en-us/help/66365/how-to-process-a-cbn-selchange-notification-message
198 nSel
= SendMessageW(SizeList
->hWndTTSizeList
, CB_GETCURSEL
, 0, 0);
199 SendMessageW(SizeList
->hWndTTSizeList
, CB_GETLBTEXT
, nSel
, (LPARAM
)szFontSize
);
201 /* Validate the font size */
202 FontSize
= wcstoul(szFontSize
, &pszNext
, 10);
203 if ((FontSize
== 0) || (*pszNext
))
208 /* Read the ComboBox edit string, as the user has entered a custom size */
209 // ComboBox_GetText(...)
210 GetWindowTextW(SizeList
->hWndTTSizeList
, szFontSize
, ARRAYSIZE(szFontSize
));
212 /* Validate the font size */
213 FontSize
= wcstoul(szFontSize
, &pszNext
, 10);
214 if ((FontSize
== 0) || (*pszNext
))
217 /* Find if the font size already exists in the list; if not, add it */
218 nSel
= SendMessageW(SizeList
->hWndTTSizeList
, CB_FINDSTRINGEXACT
, 0, (LPARAM
)szFontSize
);
221 nSel
= (UINT
)SendMessageW(SizeList
->hWndTTSizeList
, CB_ADDSTRING
, -1, (LPARAM
)szFontSize
);
222 //// ComboBox_SetText(...)
223 //SetWindowTextW(SizeList->hWndTTSizeList, szFontSize);
224 //SizeList->bIsTTSizeDirty = TRUE;
226 SendMessageW(SizeList
->hWndTTSizeList
, CB_SETCURSEL
, (WPARAM
)nSel
, 0);
229 SizeList
->bIsTTSizeDirty
= FALSE
;
231 SizeList
->CurrentTTSize
= FontSize
;
234 * If the font size is given in points, instead of pixels,
235 * convert it into logical size.
237 if (!SizeList
->TTSizePixelUnit
)
238 FontSize
= -PointSizeToLogicalSize(NULL
, FontSize
);
248 IN LPCWSTR pszFaceName
,
253 /* Make sure the font doesn't already exist in the list */
254 if (SendMessageW(hWndList
, LB_FINDSTRINGEXACT
, 0, (LPARAM
)pszFaceName
) != LB_ERR
)
258 iItem
= (INT
)SendMessageW(hWndList
, LB_ADDSTRING
, 0, (LPARAM
)pszFaceName
);
261 DPRINT1("Failed to add font '%S'\n", pszFaceName
);
265 DPRINT1("Add font '%S'\n", pszFaceName
);
267 /* Store this information in the list-item's userdata area */
268 // SendMessageW(hWndList, LB_SETITEMDATA, idx, MAKELPARAM(fFixed, fTrueType));
269 SendMessageW(hWndList
, LB_SETITEMDATA
, iItem
, (LPARAM
)FontType
);
272 typedef struct _FACE_NAMES_PROC_PARAM
276 } FACE_NAMES_PROC_PARAM
, *PFACE_NAMES_PROC_PARAM
;
281 IN PNEWTEXTMETRICW lpntm
,
285 PFACE_NAMES_PROC_PARAM Param
= (PFACE_NAMES_PROC_PARAM
)lParam
;
288 * To install additional TrueType fonts to be available for the console,
289 * add entries of type REG_SZ named "0", "00" etc... in:
290 * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
291 * The names of the fonts listed there should match those in:
292 * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts
294 if (IsValidConsoleFont2(lplf
, lpntm
, FontType
, Param
->CodePage
))
296 /* Add the font to the list */
297 AddFontToList(Param
->hWndList
, lplf
->lfFaceName
, FontType
);
300 /* Continue the font enumeration */
307 IN PNEWTEXTMETRICW lpntm
,
311 PFONTSIZE_LIST_CTL SizeList
= (PFONTSIZE_LIST_CTL
)lParam
;
312 UINT iItem
, iDupItem
;
313 WCHAR szFontSize
[100];
315 if (FontType
!= TRUETYPE_FONTTYPE
)
321 * Width = FontSize.X = LOWORD(FontSize);
322 * Height = FontSize.Y = HIWORD(FontSize);
325 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d x %d", lplf
->lfWidth
, lplf
->lfHeight
);
326 FontSize
= MAKEWPARAM(lplf
->lfWidth
, lplf
->lfHeight
);
328 /* Add the font size into the list, sorted by size value. Avoid any duplicates. */
329 /* Store this information in the list-item's userdata area */
331 iItem
= BisectListSortedByValue(&SizeList
->RasterSizeList
, FontSize
, &iDupItem
, TRUE
);
334 if (iDupItem
== LB_ERR
)
336 iItem
= (UINT
)SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_INSERTSTRING
, iItem
, (LPARAM
)szFontSize
);
337 if (iItem
!= LB_ERR
&& iItem
!= LB_ERRSPACE
)
338 iItem
= SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_SETITEMDATA
, iItem
, FontSize
);
345 /* TrueType or vectored font: list all the hardcoded font points */
347 for (i
= 0; i
< ARRAYSIZE(TrueTypePoints
); ++i
)
349 // _ultow(szFontSize, TrueTypePoints[i], 10);
350 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", TrueTypePoints
[i
]);
352 /* Add the font size into the list, sorted by size value (string). Avoid any duplicates. */
353 if (SendMessageW(SizeList
->hWndTTSizeList
, CB_FINDSTRINGEXACT
, 0, (LPARAM
)szFontSize
) == CB_ERR
)
354 iItem
= (UINT
)SendMessageW(SizeList
->hWndTTSizeList
, CB_INSERTSTRING
, -1, (LPARAM
)szFontSize
);
357 /* Stop the enumeration now */
363 FaceNameList_Initialize(
367 FACE_NAMES_PROC_PARAM Param
;
372 Param
.hWndList
= hWndList
;
373 Param
.CodePage
= CodePage
;
375 ZeroMemory(&lf
, sizeof(lf
));
376 lf
.lfCharSet
= DEFAULT_CHARSET
; // CodePageToCharSet(CodePage);
377 // lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
380 EnumFontFamiliesExW(hDC
, &lf
, (FONTENUMPROCW
)EnumFaceNamesProc
, (LPARAM
)&Param
, 0);
381 ReleaseDC(NULL
, hDC
);
383 idx
= (INT
)SendMessageW(hWndList
, LB_GETCOUNT
, 0, 0);
384 if (idx
!= LB_ERR
&& idx
!= 0)
386 /* We have found some fonts and filled the list, we are fine! */
390 /* No fonts were found. Manually add default ones into the list. */
391 DPRINT1("The ideal console fonts were not found; manually add default ones.\n");
393 AddFontToList(hWndList
, L
"Terminal", RASTER_FONTTYPE
);
394 AddFontToList(hWndList
, L
"Lucida Console", TRUETYPE_FONTTYPE
);
395 if (CodePageToCharSet(CodePage
) != DEFAULT_CHARSET
)
396 AddFontToList(hWndList
, L
"Droid Sans Fallback", TRUETYPE_FONTTYPE
);
400 FaceNameList_SelectFaceName(
406 iItem
= (INT
)SendMessageW(hWndList
, LB_FINDSTRINGEXACT
, 0, (LPARAM
)FaceName
);
408 iItem
= (INT
)SendMessageW(hWndList
, LB_FINDSTRINGEXACT
, 0, (LPARAM
)L
"Terminal");
411 SendMessageW(hWndList
, LB_SETCURSEL
, (WPARAM
)iItem
, 0);
419 IN PFONTSIZE_LIST_CTL SizeList
)
423 if (SizeList
->UseRasterOrTTList
)
426 * Raster font: show the Raster size list, and
427 * hide the TrueType size list and the units.
430 // EnableDlgItem(hDlg, IDC_CHECK_BOLD_FONTS, FALSE);
432 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_PIXEL_UNIT
);
433 ShowWindow(hDlgItem
, SW_HIDE
);
434 EnableWindow(hDlgItem
, FALSE
);
436 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_POINT_UNIT
);
437 ShowWindow(hDlgItem
, SW_HIDE
);
438 EnableWindow(hDlgItem
, FALSE
);
440 hDlgItem
= SizeList
->hWndTTSizeList
;
441 ShowWindow(hDlgItem
, SW_HIDE
);
442 EnableWindow(hDlgItem
, FALSE
);
444 hDlgItem
= SizeList
->RasterSizeList
.hWndList
;
445 EnableWindow(hDlgItem
, TRUE
);
446 ShowWindow(hDlgItem
, SW_SHOW
);
451 * TrueType font: show the TrueType size list
452 * and the units, and hide the Raster size list.
455 // EnableDlgItem(hDlg, IDC_CHECK_BOLD_FONTS, TRUE);
457 hDlgItem
= SizeList
->RasterSizeList
.hWndList
;
458 ShowWindow(hDlgItem
, SW_HIDE
);
459 EnableWindow(hDlgItem
, FALSE
);
461 hDlgItem
= SizeList
->hWndTTSizeList
;
462 EnableWindow(hDlgItem
, TRUE
);
463 ShowWindow(hDlgItem
, SW_SHOW
);
465 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_PIXEL_UNIT
);
466 EnableWindow(hDlgItem
, TRUE
);
467 ShowWindow(hDlgItem
, SW_SHOW
);
469 hDlgItem
= GetDlgItem(hDlg
, IDC_RADIO_POINT_UNIT
);
470 EnableWindow(hDlgItem
, TRUE
);
471 ShowWindow(hDlgItem
, SW_SHOW
);
478 IN PFONTSIZE_LIST_CTL SizeList
,
479 IN OUT PCONSOLE_STATE_INFO pConInfo
);
484 IN PFONTSIZE_LIST_CTL SizeList
,
485 IN OUT PCONSOLE_STATE_INFO pConInfo
)
487 HWND hListBox
= GetDlgItem(hDlg
, IDC_LBOX_FONTTYPE
);
492 LPCWSTR FontGrpBoxLabelTpl
= NULL
;
493 WCHAR FontGrpBoxLabel
[260];
495 nSel
= (INT
)SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
496 if (nSel
== LB_ERR
) return FALSE
;
499 * This is disabled, because there can be external parameters
500 * that may have changed (e.g. ConInfo->FontWeight, code page, ...)
501 * and that we don't control here, and that need a font refresh.
504 /* Check whether the selection has changed */
505 if (nSel
== CurrentSelFont
)
509 Length
= (INT
)SendMessageW(hListBox
, LB_GETTEXTLEN
, nSel
, 0);
510 if (Length
== LB_ERR
) return FALSE
;
512 FaceName
= HeapAlloc(GetProcessHeap(),
514 (Length
+ 1) * sizeof(WCHAR
));
515 if (FaceName
== NULL
) return FALSE
;
517 Length
= (INT
)SendMessageW(hListBox
, LB_GETTEXT
, nSel
, (LPARAM
)FaceName
);
518 FaceName
[Length
] = L
'\0';
520 StringCchCopyW(pConInfo
->FaceName
, ARRAYSIZE(pConInfo
->FaceName
), FaceName
);
521 DPRINT1("pConInfo->FaceName = '%S'\n", pConInfo
->FaceName
);
523 ZeroMemory(&lf
, sizeof(lf
));
524 lf
.lfCharSet
= DEFAULT_CHARSET
; // CodePageToCharSet(pConInfo->CodePage);
525 // lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
526 StringCchCopyW(lf
.lfFaceName
, ARRAYSIZE(lf
.lfFaceName
), FaceName
);
529 * Retrieve the read-only font group box label string template,
530 * and set the group box label to the name of the selected font.
532 Length
= LoadStringW(hApplet
, IDS_GROUPBOX_FONT_NAME
, (LPWSTR
)&FontGrpBoxLabelTpl
, 0);
533 if (FontGrpBoxLabelTpl
&& Length
> 0)
535 StringCchCopyNW(FontGrpBoxLabel
, ARRAYSIZE(FontGrpBoxLabel
), FontGrpBoxLabelTpl
, Length
);
536 StringCchCatW(FontGrpBoxLabel
, ARRAYSIZE(FontGrpBoxLabel
), FaceName
);
537 SetDlgItemTextW(hDlg
, IDC_GROUPBOX_FONT_NAME
, FontGrpBoxLabel
);
540 HeapFree(GetProcessHeap(), 0, FaceName
);
543 * Reset the font size list, only:
544 * - if we have changed the type of font, or
545 * - if the font type is the same and is RASTER but the font has changed.
546 * Otherwise, if the font type is not RASTER and has not changed,
547 * we always display the TrueType default sizes and we don't need to
548 * recreate the list when we change between different TrueType fonts.
550 FontType
= SendMessageW(hListBox
, LB_GETITEMDATA
, nSel
, 0);
551 if (FontType
!= LB_ERR
)
553 SizeList
->UseRasterOrTTList
= (FontType
== RASTER_FONTTYPE
);
555 /* Display the correct font size list (if needed) */
556 if (CurrentFontType
!= FontType
)
557 UpdateFontSizeList(hDlg
, SizeList
);
559 /* Enumerate the available sizes for the selected font */
560 if ((CurrentFontType
!= FontType
) ||
561 (FontType
== RASTER_FONTTYPE
&& CurrentSelFont
!= nSel
))
565 if (SizeList
->UseRasterOrTTList
)
566 SendMessageW(SizeList
->RasterSizeList
.hWndList
, LB_RESETCONTENT
, 0, 0);
568 SendMessageW(SizeList
->hWndTTSizeList
, CB_RESETCONTENT
, 0, 0);
571 EnumFontFamiliesExW(hDC
, &lf
, (FONTENUMPROCW
)EnumFontSizesProc
, (LPARAM
)SizeList
, 0);
572 ReleaseDC(NULL
, hDC
);
574 /* Re-select the current font size */
575 if (SizeList
->UseRasterOrTTList
)
576 FontSizeList_SelectFontSize(SizeList
, SizeList
->CurrentRasterSize
);
578 FontSizeList_SelectFontSize(SizeList
, SizeList
->CurrentTTSize
);
583 /* We failed, display the raster fonts size list */
584 SizeList
->UseRasterOrTTList
= TRUE
;
585 UpdateFontSizeList(hDlg
, SizeList
);
587 CurrentFontType
= FontType
;
588 CurrentSelFont
= nSel
;
590 FontSizeChange(hDlg
, SizeList
, pConInfo
);
597 IN PFONTSIZE_LIST_CTL SizeList
,
598 IN OUT PCONSOLE_STATE_INFO pConInfo
)
601 LONG CharWidth
, CharHeight
, FontSize
;
602 WCHAR szFontSize
[100];
605 * Retrieve the current selected font size.
606 * - If SizeList->UseRasterOrTTList is TRUE, or if it is FALSE but
607 * if SizeList->TTSizePixelUnit is TRUE, then the font size is in pixels;
608 * - If SizeList->TTSizePixelUnit is FALSE, then the font size is in points.
610 FontSize
= FontSizeList_GetSelectedFontSize(SizeList
);
612 return FALSE
; // We have got an invalid font size...
614 CharHeight
= (SizeList
->UseRasterOrTTList
? (LONG
)HIWORD(FontSize
) : FontSize
);
615 CharWidth
= (SizeList
->UseRasterOrTTList
? (LONG
)LOWORD(FontSize
) : 0);
617 if (hCurrentFont
) DeleteObject(hCurrentFont
);
618 hCurrentFont
= CreateConsoleFont2(CharHeight
, CharWidth
, pConInfo
);
619 if (hCurrentFont
== NULL
)
620 DPRINT1("FontSizeChange: CreateConsoleFont2 failed\n");
622 /* Retrieve the real character size in pixels */
624 GetFontCellSize(hDC
, hCurrentFont
, (PUINT
)&CharHeight
, (PUINT
)&CharWidth
);
625 ReleaseDC(NULL
, hDC
);
629 * Width = FontSize.X = LOWORD(FontSize);
630 * Height = FontSize.Y = HIWORD(FontSize);
632 pConInfo
->FontSize
.X
= (SHORT
)(SizeList
->UseRasterOrTTList
? CharWidth
: 0);
633 pConInfo
->FontSize
.Y
= (SHORT
)CharHeight
;
635 DPRINT1("pConInfo->FontSize = (%d x %d) ; (CharWidth x CharHeight) = (%d x %d)\n",
636 pConInfo
->FontSize
.X
, pConInfo
->FontSize
.Y
, CharWidth
, CharHeight
);
638 InvalidateRect(GetDlgItem(hDlg
, IDC_STATIC_FONT_WINDOW_PREVIEW
), NULL
, TRUE
);
639 InvalidateRect(GetDlgItem(hDlg
, IDC_STATIC_SELECT_FONT_PREVIEW
), NULL
, TRUE
);
641 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", CharWidth
);
642 SetDlgItemText(hDlg
, IDC_FONT_SIZE_X
, szFontSize
);
643 StringCchPrintfW(szFontSize
, ARRAYSIZE(szFontSize
), L
"%d", CharHeight
);
644 SetDlgItemText(hDlg
, IDC_FONT_SIZE_Y
, szFontSize
);
657 PFONTSIZE_LIST_CTL SizeList
;
659 SizeList
= (PFONTSIZE_LIST_CTL
)GetWindowLongPtrW(hDlg
, DWLP_USER
);
665 HWND hFontList
= GetDlgItem(hDlg
, IDC_LBOX_FONTTYPE
);
667 SizeList
= (PFONTSIZE_LIST_CTL
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*SizeList
));
671 return (INT_PTR
)TRUE
;
673 SizeList
->RasterSizeList
.hWndList
= GetDlgItem(hDlg
, IDC_LBOX_FONTSIZE
);
674 SizeList
->RasterSizeList
.GetCount
= RasterSizeList_GetCount
;
675 SizeList
->RasterSizeList
.GetData
= RasterSizeList_GetData
;
676 SizeList
->hWndTTSizeList
= GetDlgItem(hDlg
, IDC_CBOX_FONTSIZE
);
677 SizeList
->bIsTTSizeDirty
= FALSE
;
678 SetWindowLongPtrW(hDlg
, DWLP_USER
, (LONG_PTR
)SizeList
);
680 /* By default show the raster font size list */
681 SizeList
->UseRasterOrTTList
= TRUE
;
683 /* By default show the font sizes in pixel units */
684 CheckRadioButton(hDlg
, IDC_RADIO_PIXEL_UNIT
, IDC_RADIO_POINT_UNIT
, IDC_RADIO_PIXEL_UNIT
);
685 SizeList
->TTSizePixelUnit
= TRUE
;
687 UpdateFontSizeList(hDlg
, SizeList
);
689 /* Initialize the font list */
690 FaceNameList_Initialize(hFontList
, ConInfo
->CodePage
);
692 /* Select the current font */
693 DPRINT1("ConInfo->FaceName = '%S'\n", ConInfo
->FaceName
);
694 FaceNameList_SelectFaceName(hFontList
, ConInfo
->FaceName
);
696 if (ConInfo
->FontWeight
>= FW_BOLD
)
697 CheckDlgButton(hDlg
, IDC_CHECK_BOLD_FONTS
, BST_CHECKED
);
699 CheckDlgButton(hDlg
, IDC_CHECK_BOLD_FONTS
, BST_UNCHECKED
);
701 /* Select the current font size */
704 * Width = FontSize.X = LOWORD(FontSize);
705 * Height = FontSize.Y = HIWORD(FontSize);
707 SizeList
->CurrentRasterSize
= MAKELONG(ConInfo
->FontSize
.X
, ConInfo
->FontSize
.Y
);
708 SizeList
->CurrentTTSize
= ConInfo
->FontSize
.Y
;
709 // FontSizeList_SelectFontSize(SizeList, SizeList->CurrentRasterSize);
711 /* Refresh everything */
712 FontTypeChange(hDlg
, SizeList
, ConInfo
);
720 HeapFree(GetProcessHeap(), 0, SizeList
);
721 return (INT_PTR
)TRUE
;
726 LPDRAWITEMSTRUCT drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
728 if (drawItem
->CtlID
== IDC_STATIC_SELECT_FONT_PREVIEW
)
729 PaintText(drawItem
, ConInfo
, Screen
);
734 case WM_DISPLAYCHANGE
:
736 /* Retransmit to the preview window */
737 SendDlgItemMessageW(hDlg
, IDC_STATIC_FONT_WINDOW_PREVIEW
,
738 WM_DISPLAYCHANGE
, wParam
, lParam
);
744 switch (((LPNMHDR
)lParam
)->code
)
748 ApplyConsoleInfo(hDlg
);
758 if (HIWORD(wParam
) == LBN_SELCHANGE
/* || CBN_SELCHANGE */)
760 switch (LOWORD(wParam
))
762 case IDC_LBOX_FONTTYPE
:
764 /* Change the property sheet state only if the font has really changed */
765 if (FontTypeChange(hDlg
, SizeList
, ConInfo
))
766 PropSheet_Changed(GetParent(hDlg
), hDlg
);
770 case IDC_LBOX_FONTSIZE
:
771 case IDC_CBOX_FONTSIZE
:
773 /* Change the property sheet state only if the font has really changed */
774 if (FontSizeChange(hDlg
, SizeList
, ConInfo
))
775 PropSheet_Changed(GetParent(hDlg
), hDlg
);
780 /* NOTE: CBN_EDITUPDATE is sent first, and is followed by CBN_EDITCHANGE */
781 else if (HIWORD(wParam
) == CBN_EDITUPDATE
&& LOWORD(wParam
) == IDC_CBOX_FONTSIZE
)
784 PWCHAR pszNext
= NULL
;
785 WCHAR szFontSize
[100];
786 WCHAR szMessage
[260];
788 /* Read the ComboBox edit string, as the user has entered a custom size */
789 GetWindowTextW(SizeList
->hWndTTSizeList
, szFontSize
, ARRAYSIZE(szFontSize
));
791 /* Validate the font size */
792 FontSize
= wcstoul(szFontSize
, &pszNext
, 10);
793 if ((FontSize
== 0) || (*pszNext
))
796 StringCchPrintfW(szMessage
, ARRAYSIZE(szMessage
), L
"\"%s\" is not a valid font size.", szFontSize
);
797 MessageBoxW(hDlg
, szMessage
, L
"Error", MB_ICONINFORMATION
| MB_OK
);
799 /**/SizeList
->bIsTTSizeDirty
= TRUE
;/**/
801 else if (HIWORD(wParam
) == CBN_KILLFOCUS
&& LOWORD(wParam
) == IDC_CBOX_FONTSIZE
)
803 /* Change the property sheet state only if the font has really changed */
804 if (FontSizeChange(hDlg
, SizeList
, ConInfo
))
805 PropSheet_Changed(GetParent(hDlg
), hDlg
);
808 if (HIWORD(wParam
) == BN_CLICKED
)
810 switch (LOWORD(wParam
))
812 case IDC_CHECK_BOLD_FONTS
:
814 if (IsDlgButtonChecked(hDlg
, IDC_CHECK_BOLD_FONTS
) == BST_CHECKED
)
815 ConInfo
->FontWeight
= FW_BOLD
;
817 ConInfo
->FontWeight
= FW_NORMAL
;
819 FontTypeChange(hDlg
, SizeList
, ConInfo
);
820 PropSheet_Changed(GetParent(hDlg
), hDlg
);
824 case IDC_RADIO_PIXEL_UNIT
:
825 case IDC_RADIO_POINT_UNIT
:
827 SizeList
->TTSizePixelUnit
= (LOWORD(wParam
) == IDC_RADIO_PIXEL_UNIT
);
829 /* The call is valid only for TrueType fonts */
830 if (CurrentFontType
!= TRUETYPE_FONTTYPE
)
833 /* Change the property sheet state only if the font has really changed */
834 if (FontSizeChange(hDlg
, SizeList
, ConInfo
))
835 PropSheet_Changed(GetParent(hDlg
), hDlg
);