ReactOS  0.4.13-dev-698-g77671f0
font.c File Reference
#include "console.h"
#include <debug.h>
Include dependency graph for font.c:

Go to the source code of this file.

Classes

struct  _FONTSIZE_LIST_CTL
 
struct  _FACE_NAMES_PROC_PARAM
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _FONTSIZE_LIST_CTL FONTSIZE_LIST_CTL
 
typedef struct _FONTSIZE_LIST_CTLPFONTSIZE_LIST_CTL
 
typedef struct _FACE_NAMES_PROC_PARAM FACE_NAMES_PROC_PARAM
 
typedef struct _FACE_NAMES_PROC_PARAMPFACE_NAMES_PROC_PARAM
 

Functions

VOID RefreshFontPreview (IN FONT_PREVIEW *Preview, IN PCONSOLE_STATE_INFO pConInfo)
 
VOID UpdateFontPreview (IN FONT_PREVIEW *Preview, IN HFONT hFont, IN UINT CharWidth, IN UINT CharHeight)
 
static INT RasterSizeList_GetCount (IN PLIST_CTL ListCtl)
 
static ULONG_PTR RasterSizeList_GetData (IN PLIST_CTL ListCtl, IN INT Index)
 
INT LogicalSizeToPointSize (IN HDC hDC OPTIONAL, IN UINT LogicalSize)
 
INT PointSizeToLogicalSize (IN HDC hDC OPTIONAL, IN INT PointSize)
 
static VOID FontSizeList_SelectFontSize (IN PFONTSIZE_LIST_CTL SizeList, IN ULONG FontSize)
 
static LONG FontSizeList_GetSelectedFontSize (IN PFONTSIZE_LIST_CTL SizeList)
 
static VOID AddFontToList (IN HWND hWndList, IN LPCWSTR pszFaceName, IN DWORD FontType)
 
static BOOL CALLBACK EnumFaceNamesProc (IN PLOGFONTW lplf, IN PNEWTEXTMETRICW lpntm, IN DWORD FontType, IN LPARAM lParam)
 
static BOOL CALLBACK EnumFontSizesProc (IN PLOGFONTW lplf, IN PNEWTEXTMETRICW lpntm, IN DWORD FontType, IN LPARAM lParam)
 
static VOID FaceNameList_Initialize (IN HWND hWndList, IN UINT CodePage)
 
static VOID FaceNameList_SelectFont (IN HWND hDlg, IN HWND hWndList, IN PFONTSIZE_LIST_CTL SizeList, IN LPCWSTR FaceName, IN ULONG FontFamily, IN ULONG FontWeight, IN COORD FontSize)
 
static VOID UpdateFontSizeList (IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList)
 
static BOOL FontSizeChange (IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList, IN OUT PCONSOLE_STATE_INFO pConInfo)
 
static BOOL FontTypeChange (IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList, IN OUT PCONSOLE_STATE_INFO pConInfo)
 
INT_PTR CALLBACK FontProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Variables

FONT_PREVIEW FontPreview = {NULL, 0, 0}
 
static const SHORT TrueTypePoints []
 
static INT CurrentSelFont = LB_ERR
 
static DWORD CurrentFontType = (DWORD)-1
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file font.c.

Typedef Documentation

◆ FACE_NAMES_PROC_PARAM

◆ FONTSIZE_LIST_CTL

◆ PFACE_NAMES_PROC_PARAM

◆ PFONTSIZE_LIST_CTL

Function Documentation

◆ AddFontToList()

static VOID AddFontToList ( IN HWND  hWndList,
IN LPCWSTR  pszFaceName,
IN DWORD  FontType 
)
static

Definition at line 271 of file font.c.

275 {
276  INT iItem;
277 
278  /* Make sure the font doesn't already exist in the list */
279  if (SendMessageW(hWndList, LB_FINDSTRINGEXACT, 0, (LPARAM)pszFaceName) != LB_ERR)
280  return;
281 
282  /* Add the font */
283  iItem = (INT)SendMessageW(hWndList, LB_ADDSTRING, 0, (LPARAM)pszFaceName);
284  if (iItem == LB_ERR)
285  {
286  DPRINT1("Failed to add font '%S'\n", pszFaceName);
287  return;
288  }
289 
290  DPRINT1("Add font '%S'\n", pszFaceName);
291 
292  /* Store this information in the list-item's userdata area */
293  // SendMessageW(hWndList, LB_SETITEMDATA, idx, MAKELPARAM(fFixed, fTrueType));
294  SendMessageW(hWndList, LB_SETITEMDATA, iItem, (LPARAM)FontType);
295 }
#define LB_FINDSTRINGEXACT
Definition: winuser.h:2017
#define LB_ADDSTRING
Definition: winuser.h:2013
static HWND hWndList[5+1]
Definition: SetParent.c:10
int32_t INT
Definition: typedefs.h:56
#define LB_ERR
Definition: winuser.h:2407
LONG_PTR LPARAM
Definition: windef.h:208
#define LB_SETITEMDATA
Definition: winuser.h:2047
static INT(WINAPI *pAddFontResourceExA)(LPCSTR
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define DPRINT1
Definition: precomp.h:8

Referenced by EnumFaceNamesProc(), and FaceNameList_Initialize().

◆ EnumFaceNamesProc()

static BOOL CALLBACK EnumFaceNamesProc ( IN PLOGFONTW  lplf,
IN PNEWTEXTMETRICW  lpntm,
IN DWORD  FontType,
IN LPARAM  lParam 
)
static

Definition at line 304 of file font.c.

309 {
311 
312  if (IsValidConsoleFont2(lplf, lpntm, FontType, Param->CodePage))
313  {
314  /* Add the font to the list */
315  AddFontToList(Param->hWndList, lplf->lfFaceName, FontType);
316  }
317 
318  /* Continue the font enumeration */
319  return TRUE;
320 }
#define TRUE
Definition: types.h:120
static VOID AddFontToList(IN HWND hWndList, IN LPCWSTR pszFaceName, IN DWORD FontType)
Definition: font.c:271
BOOL IsValidConsoleFont2(IN PLOGFONTW lplf, IN PNEWTEXTMETRICW lpntm, IN DWORD FontType, IN UINT CodePage)
Definition: font.c:182
LPARAM lParam
Definition: combotst.c:139
struct _FACE_NAMES_PROC_PARAM * PFACE_NAMES_PROC_PARAM

Referenced by FaceNameList_Initialize().

◆ EnumFontSizesProc()

static BOOL CALLBACK EnumFontSizesProc ( IN PLOGFONTW  lplf,
IN PNEWTEXTMETRICW  lpntm,
IN DWORD  FontType,
IN LPARAM  lParam 
)
static

Definition at line 323 of file font.c.

328 {
330  UINT iItem, iDupItem;
331  WCHAR szFontSize[100];
332 
333  if (FontType != TRUETYPE_FONTTYPE)
334  {
335  WPARAM FontSize;
336 
337  /*
338  * Format:
339  * Width = FontSize.X = LOWORD(FontSize);
340  * Height = FontSize.Y = HIWORD(FontSize);
341  */
342 
343  StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d x %d", lplf->lfWidth, lplf->lfHeight);
344  FontSize = MAKEWPARAM(lplf->lfWidth, lplf->lfHeight);
345 
346  /* Add the font size into the list, sorted by size value. Avoid any duplicates. */
347  /* Store this information in the list-item's userdata area */
348  iDupItem = LB_ERR;
349  iItem = BisectListSortedByValue(&SizeList->RasterSizeList, FontSize, &iDupItem, TRUE);
350  if (iItem == LB_ERR)
351  iItem = 0;
352  if (iDupItem == LB_ERR)
353  {
354  iItem = (UINT)SendMessageW(SizeList->RasterSizeList.hWndList, LB_INSERTSTRING, iItem, (LPARAM)szFontSize);
355  if (iItem != LB_ERR && iItem != LB_ERRSPACE)
356  iItem = SendMessageW(SizeList->RasterSizeList.hWndList, LB_SETITEMDATA, iItem, FontSize);
357  }
358 
359  return TRUE;
360  }
361  else
362  {
363  /* TrueType or vectored font: list all the hardcoded font points */
364  ULONG i;
365  for (i = 0; i < ARRAYSIZE(TrueTypePoints); ++i)
366  {
367  // _ultow(szFontSize, TrueTypePoints[i], 10);
368  StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", TrueTypePoints[i]);
369 
370  /* Add the font size into the list, sorted by size value (string). Avoid any duplicates. */
371  if (SendMessageW(SizeList->hWndTTSizeList, CB_FINDSTRINGEXACT, 0, (LPARAM)szFontSize) == CB_ERR)
372  iItem = (UINT)SendMessageW(SizeList->hWndTTSizeList, CB_INSERTSTRING, -1, (LPARAM)szFontSize);
373  }
374 
375  /* Stop the enumeration now */
376  return FALSE;
377  }
378 }
#define TRUE
Definition: types.h:120
#define MAKEWPARAM(l, h)
Definition: winuser.h:3948
HWND hWndTTSizeList
Definition: font.c:35
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
UINT_PTR WPARAM
Definition: windef.h:207
HWND hWndList
Definition: console.h:93
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
#define LB_ERR
Definition: winuser.h:2407
static const SHORT TrueTypePoints[]
Definition: font.c:27
struct _FONTSIZE_LIST_CTL * PFONTSIZE_LIST_CTL
#define CB_INSERTSTRING
Definition: winuser.h:1939
LONG_PTR LPARAM
Definition: windef.h:208
#define CB_ERR
Definition: winuser.h:2410
__wchar_t WCHAR
Definition: xmlstorage.h:180
LIST_CTL RasterSizeList
Definition: font.c:34
#define LB_SETITEMDATA
Definition: winuser.h:2047
#define LB_ERRSPACE
Definition: winuser.h:2408
static const WCHAR L[]
Definition: oid.c:1250
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
UINT BisectListSortedByValue(IN PLIST_CTL ListCtl, IN ULONG_PTR Value, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
Definition: utils.c:115
#define LB_INSERTSTRING
Definition: winuser.h:2035
LPARAM lParam
Definition: combotst.c:139
#define TRUETYPE_FONTTYPE
Definition: wingdi.h:1091
#define CB_FINDSTRINGEXACT
Definition: winuser.h:1922

Referenced by FontTypeChange().

◆ FaceNameList_Initialize()

static VOID FaceNameList_Initialize ( IN HWND  hWndList,
IN UINT  CodePage 
)
static

Definition at line 381 of file font.c.

384 {
385  FACE_NAMES_PROC_PARAM Param;
386  HDC hDC;
387  LOGFONTW lf;
388  INT idx;
389 
390  Param.hWndList = hWndList;
391  Param.CodePage = CodePage;
392 
393  ZeroMemory(&lf, sizeof(lf));
394  lf.lfCharSet = DEFAULT_CHARSET; // CodePageToCharSet(CodePage);
395  // lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
396 
397  hDC = GetDC(NULL);
399  ReleaseDC(NULL, hDC);
400 
402  if (idx != LB_ERR && idx != 0)
403  {
404  /* We have found some fonts and filled the list, we are fine! */
405  return;
406  }
407 
408  /* No fonts were found. Manually add default ones into the list. */
409  DPRINT1("The ideal console fonts were not found; manually add default ones.\n");
410 
412  AddFontToList(hWndList, L"Lucida Console", TRUETYPE_FONTTYPE);
413  if (CodePageToCharSet(CodePage) != DEFAULT_CHARSET)
414  AddFontToList(hWndList, L"Droid Sans Fallback", TRUETYPE_FONTTYPE);
415 }
int WINAPI EnumFontFamiliesExW(HDC hdc, LPLOGFONTW lpLogfont, FONTENUMPROCW lpEnumFontFamExProc, LPARAM lParam, DWORD dwFlags)
Definition: font.c:400
HDC WINAPI GetDC(_In_opt_ HWND)
BYTE lfCharSet
Definition: dimm.idl:67
static HDC
Definition: imagelist.c:92
BYTE CodePageToCharSet(IN UINT CodePage)
Definition: font.c:32
#define ZeroMemory
Definition: winbase.h:1635
static HWND hWndList[5+1]
Definition: SetParent.c:10
#define DEFAULT_CHARSET
Definition: wingdi.h:383
int32_t INT
Definition: typedefs.h:56
static VOID AddFontToList(IN HWND hWndList, IN LPCWSTR pszFaceName, IN DWORD FontType)
Definition: font.c:271
#define LB_ERR
Definition: winuser.h:2407
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
unsigned int idx
Definition: utils.c:41
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define LB_GETCOUNT
Definition: winuser.h:2020
#define RASTER_FONTTYPE
Definition: wingdi.h:1089
static const WCHAR L[]
Definition: oid.c:1250
static HDC hDC
Definition: 3dtext.c:33
static BOOL CALLBACK EnumFaceNamesProc(IN PLOGFONTW lplf, IN PNEWTEXTMETRICW lpntm, IN DWORD FontType, IN LPARAM lParam)
Definition: font.c:304
FARPROC FONTENUMPROCW
Definition: wingdi.h:2875
static INT(WINAPI *pAddFontResourceExA)(LPCSTR
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define DPRINT1
Definition: precomp.h:8
#define TRUETYPE_FONTTYPE
Definition: wingdi.h:1091

Referenced by FontProc().

◆ FaceNameList_SelectFont()

static VOID FaceNameList_SelectFont ( IN HWND  hDlg,
IN HWND  hWndList,
IN PFONTSIZE_LIST_CTL  SizeList,
IN LPCWSTR  FaceName,
IN ULONG  FontFamily,
IN ULONG  FontWeight,
IN COORD  FontSize 
)
static

Definition at line 418 of file font.c.

426 {
427  INT iItem;
428 
429  iItem = (INT)SendMessageW(hWndList, LB_FINDSTRINGEXACT, 0, (LPARAM)FaceName);
430  if (iItem == LB_ERR)
431  iItem = (INT)SendMessageW(hWndList, LB_FINDSTRINGEXACT, 0, (LPARAM)L"Terminal");
432  if (iItem == LB_ERR)
433  iItem = 0;
435 
436  if (FontWeight >= FW_BOLD)
438  else
440 
441  /* Select the current font size */
442  /*
443  * Format:
444  * Width = FontSize.X = LOWORD(FontSize);
445  * Height = FontSize.Y = HIWORD(FontSize);
446  */
447  SizeList->CurrentRasterSize = MAKELONG(FontSize.X, FontSize.Y);
448  SizeList->CurrentTTSize = FontSize.Y;
449  // FontSizeList_SelectFontSize(SizeList, SizeList->CurrentRasterSize);
450 
451  // return iItem;
452 }
#define LB_SETCURSEL
Definition: winuser.h:2045
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define LB_FINDSTRINGEXACT
Definition: winuser.h:2017
#define IDC_CHECK_BOLD_FONTS
Definition: resource.h:38
UINT_PTR WPARAM
Definition: windef.h:207
static HWND hWndList[5+1]
Definition: SetParent.c:10
int32_t INT
Definition: typedefs.h:56
#define LB_ERR
Definition: winuser.h:2407
#define MAKELONG(a, b)
Definition: typedefs.h:248
LONG_PTR LPARAM
Definition: windef.h:208
static const WCHAR L[]
Definition: oid.c:1250
#define BST_UNCHECKED
Definition: winuser.h:199
#define FW_BOLD
Definition: wingdi.h:377
static INT(WINAPI *pAddFontResourceExA)(LPCSTR
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BST_CHECKED
Definition: winuser.h:197

Referenced by FontProc().

◆ FontProc()

INT_PTR CALLBACK FontProc ( HWND  hDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 699 of file font.c.

703 {
704  PFONTSIZE_LIST_CTL SizeList;
705 
707 
708  switch (uMsg)
709  {
710  case WM_INITDIALOG:
711  {
712  HWND hFontList = GetDlgItem(hDlg, IDC_LBOX_FONTTYPE);
713 
714  SizeList = (PFONTSIZE_LIST_CTL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*SizeList));
715  if (!SizeList)
716  {
717  EndDialog(hDlg, 0);
718  return (INT_PTR)TRUE;
719  }
723  SizeList->hWndTTSizeList = GetDlgItem(hDlg, IDC_CBOX_FONTSIZE);
724  SizeList->bIsTTSizeDirty = FALSE;
725  SetWindowLongPtrW(hDlg, DWLP_USER, (LONG_PTR)SizeList);
726 
727  /* By default show the raster font size list */
728  SizeList->UseRasterOrTTList = TRUE;
729 
730  /* By default show the font sizes in pixel units */
732  SizeList->TTSizePixelUnit = TRUE;
733 
734  UpdateFontSizeList(hDlg, SizeList);
735 
736  /* Initialize the font list */
738 
739  /* Select the current font */
740  DPRINT1("ConInfo->FaceName = '%S'\n", ConInfo->FaceName);
741  FaceNameList_SelectFont(hDlg, hFontList,
742  SizeList,
743  ConInfo->FaceName,
746  ConInfo->FontSize);
747 
748  /* Refresh everything */
749  FontTypeChange(hDlg, SizeList, ConInfo);
750 
751  return TRUE;
752  }
753 
754  case WM_DESTROY:
755  {
756  if (SizeList)
757  HeapFree(GetProcessHeap(), 0, SizeList);
758  return (INT_PTR)TRUE;
759  }
760 
761  case WM_DRAWITEM:
762  {
764 
765  if (drawItem->CtlID == IDC_STATIC_SELECT_FONT_PREVIEW)
766  PaintText(drawItem, ConInfo, Screen);
767 
768  return TRUE;
769  }
770 
771  case WM_DISPLAYCHANGE:
772  {
773  /* Retransmit to the preview window */
775  WM_DISPLAYCHANGE, wParam, lParam);
776  break;
777  }
778 
779 #if 0
780  case PSM_QUERYSIBLINGS:
781  {
782  /*
783  * If this is a notification from the "Options" dialog because we
784  * changed the code page, treat it using the WM_FONTCHANGE case,
785  * otherwise ignore it.
786  */
787  if (wParam != IDL_CODEPAGE)
788  return FALSE;
789 
790  /* Fall through */
791  }
792 #endif
793 
794  case WM_FONTCHANGE:
795  {
796  /* The pool of font resources has changed, re-enumerate the fonts */
797  HWND hFontList = GetDlgItem(hDlg, IDC_LBOX_FONTTYPE);
798 
799  /* Initialize the font list */
801 
802  /* Select the current font */
803  FaceNameList_SelectFont(hDlg, hFontList,
804  SizeList,
805  ConInfo->FaceName,
808  ConInfo->FontSize);
809 
810  /* Refresh everything */
811  FontTypeChange(hDlg, SizeList, ConInfo);
812  break;
813  }
814 
815  case WM_NOTIFY:
816  {
817  switch (((LPNMHDR)lParam)->code)
818  {
819  case PSN_APPLY:
820  {
821  ApplyConsoleInfo(hDlg);
822  return TRUE;
823  }
824  }
825 
826  break;
827  }
828 
829  case WM_COMMAND:
830  {
831  if (HIWORD(wParam) == LBN_SELCHANGE /* || CBN_SELCHANGE */)
832  {
833  switch (LOWORD(wParam))
834  {
835  case IDC_LBOX_FONTTYPE:
836  {
837  /* Change the property sheet state only if the font has really changed */
838  if (FontTypeChange(hDlg, SizeList, ConInfo))
839  PropSheet_Changed(GetParent(hDlg), hDlg);
840  break;
841  }
842 
843  case IDC_LBOX_FONTSIZE:
844  case IDC_CBOX_FONTSIZE:
845  {
846  /* Change the property sheet state only if the font has really changed */
847  if (FontSizeChange(hDlg, SizeList, ConInfo))
848  PropSheet_Changed(GetParent(hDlg), hDlg);
849  break;
850  }
851  }
852  }
853  /* NOTE: CBN_EDITUPDATE is sent first, and is followed by CBN_EDITCHANGE */
855  {
856  ULONG FontSize;
857  PWCHAR pszNext = NULL;
858  WCHAR szFontSize[100];
859  WCHAR szMessage[260];
860 
861  /* Read the ComboBox edit string, as the user has entered a custom size */
862  GetWindowTextW(SizeList->hWndTTSizeList, szFontSize, ARRAYSIZE(szFontSize));
863 
864  /* Validate the font size */
865  FontSize = wcstoul(szFontSize, &pszNext, 10);
866  if ((FontSize == 0) || (*pszNext))
867  {
868  // FIXME: Localize!
869  StringCchPrintfW(szMessage, ARRAYSIZE(szMessage), L"\"%s\" is not a valid font size.", szFontSize);
870  MessageBoxW(hDlg, szMessage, L"Error", MB_ICONINFORMATION | MB_OK);
871  }
872  SizeList->bIsTTSizeDirty = TRUE;
873  }
875  {
876  /* Change the property sheet state only if the font has really changed */
877  if (FontSizeChange(hDlg, SizeList, ConInfo))
878  PropSheet_Changed(GetParent(hDlg), hDlg);
879  }
880  else
881  if (HIWORD(wParam) == BN_CLICKED)
882  {
883  switch (LOWORD(wParam))
884  {
886  {
889  else
891 
892  FontTypeChange(hDlg, SizeList, ConInfo);
893  PropSheet_Changed(GetParent(hDlg), hDlg);
894  break;
895  }
896 
899  {
901 
902  /* The call is valid only for TrueType fonts */
904  break;
905 
906  /* Change the property sheet state only if the font has really changed */
907  if (FontSizeChange(hDlg, SizeList, ConInfo))
908  PropSheet_Changed(GetParent(hDlg), hDlg);
909  break;
910  }
911  }
912  }
913 
914  break;
915  }
916 
917  default:
918  break;
919  }
920 
921  return FALSE;
922 }
#define IDC_RADIO_POINT_UNIT
Definition: resource.h:45
#define TRUE
Definition: types.h:120
#define IDC_RADIO_PIXEL_UNIT
Definition: resource.h:44
struct tagDRAWITEMSTRUCT * LPDRAWITEMSTRUCT
HWND hWndTTSizeList
Definition: font.c:35
#define IDC_CHECK_BOLD_FONTS
Definition: resource.h:38
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define GetWindowLongPtrW
Definition: winuser.h:4730
uint16_t * PWCHAR
Definition: typedefs.h:54
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:62
BOOL TTSizePixelUnit
Definition: font.c:38
#define LBN_SELCHANGE
Definition: winuser.h:2057
static INT RasterSizeList_GetCount(IN PLIST_CTL ListCtl)
Definition: font.c:75
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
HWND hWndList
Definition: console.h:93
#define IDC_CBOX_FONTSIZE
Definition: resource.h:43
#define CBN_KILLFOCUS
Definition: winuser.h:1960
struct _FONTSIZE_LIST_CTL * PFONTSIZE_LIST_CTL
smooth NULL
Definition: ftsmooth.c:416
VOID ApplyConsoleInfo(HWND hwndDlg)
Definition: console.c:88
static ULONG_PTR RasterSizeList_GetData(IN PLIST_CTL ListCtl, IN INT Index)
Definition: font.c:83
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define WM_DESTROY
Definition: winuser.h:1591
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
static BOOL FontSizeChange(IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList, IN OUT PCONSOLE_STATE_INFO pConInfo)
Definition: font.c:633
LIST_CTL RasterSizeList
Definition: font.c:34
#define IDC_STATIC_FONT_WINDOW_PREVIEW
Definition: resource.h:46
#define BN_CLICKED
Definition: winuser.h:1907
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
PLIST_GETDATA GetData
Definition: console.h:95
static VOID FaceNameList_Initialize(IN HWND hWndList, IN UINT CodePage)
Definition: font.c:381
#define WM_FONTCHANGE
Definition: winuser.h:1615
#define MB_ICONINFORMATION
Definition: winuser.h:796
PLIST_GETCOUNT GetCount
Definition: console.h:94
static const WCHAR L[]
Definition: oid.c:1250
WCHAR FaceName[LF_FACESIZE]
Definition: settings.h:39
#define DWLP_USER
Definition: winuser.h:866
#define WM_COMMAND
Definition: winuser.h:1722
#define IDL_CODEPAGE
Definition: resource.h:31
#define IDC_LBOX_FONTSIZE
Definition: resource.h:42
HWND WINAPI GetParent(_In_ HWND)
#define IDC_STATIC_SELECT_FONT_PREVIEW
Definition: resource.h:39
#define FW_BOLD
Definition: wingdi.h:377
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
#define IDC_LBOX_FONTTYPE
Definition: resource.h:47
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
PCONSOLE_STATE_INFO ConInfo
Definition: console.c:23
#define MB_OK
Definition: winuser.h:784
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define BST_CHECKED
Definition: winuser.h:197
#define FW_NORMAL
Definition: wingdi.h:372
BOOL bIsTTSizeDirty
Definition: font.c:36
#define DPRINT1
Definition: precomp.h:8
#define PSM_QUERYSIBLINGS
Definition: prsht.h:160
#define WM_DRAWITEM
Definition: winuser.h:1627
BOOL UseRasterOrTTList
Definition: font.c:37
#define CBN_EDITUPDATE
Definition: winuser.h:1958
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
Definition: console.h:34
static BOOL FontTypeChange(IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList, IN OUT PCONSOLE_STATE_INFO pConInfo)
Definition: font.c:520
static VOID UpdateFontSizeList(IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList)
Definition: font.c:455
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
#define SetWindowLongPtrW
Definition: winuser.h:5247
static VOID FaceNameList_SelectFont(IN HWND hDlg, IN HWND hWndList, IN PFONTSIZE_LIST_CTL SizeList, IN LPCWSTR FaceName, IN ULONG FontFamily, IN ULONG FontWeight, IN COORD FontSize)
Definition: font.c:418
static DWORD CurrentFontType
Definition: font.c:45
VOID PaintText(IN LPDRAWITEMSTRUCT drawItem, IN PCONSOLE_STATE_INFO pConInfo, IN TEXT_TYPE TextMode)
Definition: layout.c:471
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:394
#define WM_NOTIFY
Definition: richedit.h:61
#define TRUETYPE_FONTTYPE
Definition: wingdi.h:1091

Referenced by InitApplet().

◆ FontSizeChange()

static BOOL FontSizeChange ( IN HWND  hDlg,
IN PFONTSIZE_LIST_CTL  SizeList,
IN OUT PCONSOLE_STATE_INFO  pConInfo 
)
static

Definition at line 633 of file font.c.

637 {
638  LONG FontSize;
640  HFONT hFont;
641  WCHAR szFontSize[100];
642 
643  /*
644  * Retrieve the current selected font size.
645  * - If SizeList->UseRasterOrTTList is TRUE, or if it is FALSE but
646  * if SizeList->TTSizePixelUnit is TRUE, then the font size is in pixels;
647  * - If SizeList->TTSizePixelUnit is FALSE, then the font size is in points.
648  */
649  FontSize = FontSizeList_GetSelectedFontSize(SizeList);
650  if (FontSize == 0)
651  return FALSE; // We have got an invalid font size...
652 
653  /*
654  * For TrueType fonts we set the requested width to zero
655  * so as to obtain a default aspect-ratio width.
656  */
657  CharHeight = (UINT)(SizeList->UseRasterOrTTList ? HIWORD(FontSize) : FontSize);
658  CharWidth = (UINT)(SizeList->UseRasterOrTTList ? LOWORD(FontSize) : 0);
659 
661  if (hFont == NULL)
662  DPRINT1("FontSizeChange: CreateConsoleFont2() failed\n");
663 
664  /* Retrieve the real character size in pixels */
666 
667  /*
668  * Update the font preview as well, and store the font handle. It will be
669  * freed at later update or when the font preview is refreshed or reset.
670  * For TrueType fonts, the preview will show the actual character width.
671  */
673 
674  /*
675  * Format:
676  * Width = FontSize.X = LOWORD(FontSize);
677  * Height = FontSize.Y = HIWORD(FontSize);
678  */
679  pConInfo->FontSize.X = (SHORT)(SizeList->UseRasterOrTTList ? CharWidth : 0);
680  pConInfo->FontSize.Y = (SHORT)CharHeight;
681 
682  DPRINT("pConInfo->FontSize = (%d x %d) ; (CharWidth x CharHeight) = (%d x %d)\n",
683  pConInfo->FontSize.X, pConInfo->FontSize.Y, CharWidth, CharHeight);
684 
687 
688  StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", CharWidth);
689  SetDlgItemText(hDlg, IDC_FONT_SIZE_X, szFontSize);
690  StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", CharHeight);
691  SetDlgItemText(hDlg, IDC_FONT_SIZE_Y, szFontSize);
692 
693  return TRUE;
694 }
#define TRUE
Definition: types.h:120
VOID UpdateFontPreview(IN FONT_PREVIEW *Preview, IN HFONT hFont, IN UINT CharWidth, IN UINT CharHeight)
Definition: font.c:61
FONT_PREVIEW FontPreview
Definition: font.c:21
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
HFONT hFont
Definition: main.c:53
#define IDC_FONT_SIZE_X
Definition: resource.h:40
long LONG
Definition: pedump.c:60
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
HFONT CreateConsoleFont2(IN LONG Height, IN LONG Width OPTIONAL, IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
Definition: font.c:81
void DPRINT(...)
Definition: polytest.cpp:61
BOOL GetFontCellSize(IN HDC hDC OPTIONAL, IN HFONT hFont, OUT PUINT Height, OUT PUINT Width)
Definition: font.c:113
static int CharHeight
Definition: carets.c:8
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDC_FONT_SIZE_Y
Definition: resource.h:41
#define IDC_STATIC_FONT_WINDOW_PREVIEW
Definition: resource.h:46
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define SetDlgItemText
Definition: winuser.h:5747
static int CharWidth
Definition: carets.c:7
static const WCHAR L[]
Definition: oid.c:1250
#define IDC_STATIC_SELECT_FONT_PREVIEW
Definition: resource.h:39
static LONG FontSizeList_GetSelectedFontSize(IN PFONTSIZE_LIST_CTL SizeList)
Definition: font.c:191
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define HIWORD(l)
Definition: typedefs.h:246
#define LOWORD(l)
Definition: pedump.c:82

Referenced by FontProc(), and FontTypeChange().

◆ FontSizeList_GetSelectedFontSize()

static LONG FontSizeList_GetSelectedFontSize ( IN PFONTSIZE_LIST_CTL  SizeList)
static

Definition at line 191 of file font.c.

193 {
194  INT nSel;
195  LONG FontSize;
196  PWCHAR pszNext = NULL;
197  WCHAR szFontSize[100];
198 
199  if (SizeList->UseRasterOrTTList)
200  {
201  /* Raster font size (in pixels) */
202 
203  nSel = (INT)SendMessageW(SizeList->RasterSizeList.hWndList, LB_GETCURSEL, 0, 0);
204  if (nSel == LB_ERR) return 0;
205 
206  FontSize = (LONG)SizeList->RasterSizeList.GetData(&SizeList->RasterSizeList, nSel);
207  if (FontSize == LB_ERR) return 0;
208 
209  SizeList->CurrentRasterSize = FontSize;
210  }
211  else
212  {
213  /* TrueType font size (in pixels or points) */
214 
215  if (!SizeList->bIsTTSizeDirty)
216  {
217  /*
218  * The user just selected an existing size, read the ComboBox selection.
219  *
220  * See: https://support.microsoft.com/en-us/help/66365/how-to-process-a-cbn-selchange-notification-message
221  * for more details.
222  */
223  nSel = SendMessageW(SizeList->hWndTTSizeList, CB_GETCURSEL, 0, 0);
224  SendMessageW(SizeList->hWndTTSizeList, CB_GETLBTEXT, nSel, (LPARAM)szFontSize);
225 
226  /* Validate the font size */
227  FontSize = wcstoul(szFontSize, &pszNext, 10);
228  if ((FontSize == 0) || (*pszNext))
229  return 0;
230  }
231  else
232  {
233  /* Read the ComboBox edit string, as the user has entered a custom size */
234  // ComboBox_GetText(...)
235  GetWindowTextW(SizeList->hWndTTSizeList, szFontSize, ARRAYSIZE(szFontSize));
236 
237  /* Validate the font size */
238  FontSize = wcstoul(szFontSize, &pszNext, 10);
239  if ((FontSize == 0) || (*pszNext))
240  return 0;
241 
242  /* Find if the font size already exists in the list; if not, add it */
243  nSel = SendMessageW(SizeList->hWndTTSizeList, CB_FINDSTRINGEXACT, 0, (LPARAM)szFontSize);
244  if (nSel == CB_ERR)
245  {
246  nSel = (UINT)SendMessageW(SizeList->hWndTTSizeList, CB_ADDSTRING, -1, (LPARAM)szFontSize);
248  //SetWindowTextW(SizeList->hWndTTSizeList, szFontSize);
249  //SizeList->bIsTTSizeDirty = TRUE;
250  }
251  SendMessageW(SizeList->hWndTTSizeList, CB_SETCURSEL, (WPARAM)nSel, 0);
252  }
253 
254  SizeList->bIsTTSizeDirty = FALSE;
255 
256  SizeList->CurrentTTSize = FontSize;
257 
258  /*
259  * If the font size is given in points, instead of pixels,
260  * convert it into logical size.
261  */
262  if (!SizeList->TTSizePixelUnit)
263  FontSize = -PointSizeToLogicalSize(NULL, FontSize);
264  }
265 
266  return FontSize;
267 }
INT PointSizeToLogicalSize(IN HDC hDC OPTIONAL, IN INT PointSize)
Definition: font.c:112
static LONG(WINAPI *pGdiGetCharDimensions)(HDC hdc
#define CB_GETLBTEXT
Definition: winuser.h:1934
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
UINT_PTR WPARAM
Definition: windef.h:207
uint16_t * PWCHAR
Definition: typedefs.h:54
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
int32_t INT
Definition: typedefs.h:56
#define CB_GETCURSEL
Definition: winuser.h:1925
#define LB_ERR
Definition: winuser.h:2407
long LONG
Definition: pedump.c:60
#define CB_ADDSTRING
Definition: winuser.h:1918
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define CB_ERR
Definition: winuser.h:2410
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CB_SETCURSEL
Definition: winuser.h:1943
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
static INT(WINAPI *pAddFontResourceExA)(LPCSTR
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define LB_GETCURSEL
Definition: winuser.h:2021
unsigned int UINT
Definition: ndis.h:50
#define CB_FINDSTRINGEXACT
Definition: winuser.h:1922

Referenced by FontSizeChange().

◆ FontSizeList_SelectFontSize()

static VOID FontSizeList_SelectFontSize ( IN PFONTSIZE_LIST_CTL  SizeList,
IN ULONG  FontSize 
)
static

Definition at line 132 of file font.c.

135 {
136  INT nSel;
137  WCHAR szFontSize[100];
138 
139  //
140  // FIXME: Check whether FontSize == 0
141  // (or in the case of raster font maybe, whether HIWORD(FontSize) == Height == 0) ??
142  //
143 
144  /* Find and select the best font size in the list corresponding to the current size */
145  if (SizeList->UseRasterOrTTList)
146  {
147  INT idx;
148 
149  /* Raster font size (in pixels) */
150  SizeList->CurrentRasterSize = FontSize;
151 
152  nSel = BisectListSortedByValue(&SizeList->RasterSizeList, FontSize, NULL, FALSE);
153  idx = (INT)SendMessageW(SizeList->RasterSizeList.hWndList, LB_GETCOUNT, 0, 0);
154  if (nSel == LB_ERR)
155  {
156  /* Not found, select the first element of the list */
157  nSel = 0;
158  }
159  else if (nSel >= idx)
160  {
161  /*
162  * We got an index beyond the end of the list (as per Bisect* functionality),
163  * so instead, select the last element of the list.
164  */
165  nSel = idx-1;
166  }
167  SendMessageW(SizeList->RasterSizeList.hWndList, LB_SETCURSEL, (WPARAM)nSel, 0);
168  }
169  else
170  {
171  /* TrueType font size (in pixels or points) */
172  SizeList->CurrentTTSize = FontSize;
173 
174  // _ultow(szFontSize, FontSize, 10);
175  StringCchPrintfW(szFontSize, ARRAYSIZE(szFontSize), L"%d", FontSize);
176 
177  /* Find the font size in the list, or add it both in the ComboBox list, sorted by size value (string), and its edit box */
178  nSel = SendMessageW(SizeList->hWndTTSizeList, CB_FINDSTRINGEXACT, 0, (LPARAM)szFontSize);
179  if (nSel == CB_ERR)
180  {
181  nSel = (UINT)SendMessageW(SizeList->hWndTTSizeList, CB_ADDSTRING, -1, (LPARAM)szFontSize);
182  // ComboBox_SetText(...)
183  SetWindowTextW(SizeList->hWndTTSizeList, szFontSize);
184  SizeList->bIsTTSizeDirty = TRUE;
185  }
186  SendMessageW(SizeList->hWndTTSizeList, CB_SETCURSEL, (WPARAM)nSel, 0);
187  }
188 }
#define LB_SETCURSEL
Definition: winuser.h:2045
#define TRUE
Definition: types.h:120
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
int32_t INT
Definition: typedefs.h:56
#define LB_ERR
Definition: winuser.h:2407
unsigned int idx
Definition: utils.c:41
#define CB_ADDSTRING
Definition: winuser.h:1918
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define LB_GETCOUNT
Definition: winuser.h:2020
#define CB_ERR
Definition: winuser.h:2410
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250
#define CB_SETCURSEL
Definition: winuser.h:1943
static INT(WINAPI *pAddFontResourceExA)(LPCSTR
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
unsigned int UINT
Definition: ndis.h:50
UINT BisectListSortedByValue(IN PLIST_CTL ListCtl, IN ULONG_PTR Value, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
Definition: utils.c:115
#define CB_FINDSTRINGEXACT
Definition: winuser.h:1922

Referenced by FontTypeChange().

◆ FontTypeChange()

static BOOL FontTypeChange ( IN HWND  hDlg,
IN PFONTSIZE_LIST_CTL  SizeList,
IN OUT PCONSOLE_STATE_INFO  pConInfo 
)
static

Definition at line 520 of file font.c.

524 {
526  INT Length, nSel;
527  LPWSTR FaceName;
528  DWORD FontType;
529  LPCWSTR FontGrpBoxLabelTpl = NULL;
530  WCHAR FontGrpBoxLabel[260];
531 
532  nSel = (INT)SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
533  if (nSel == LB_ERR) return FALSE;
534 
535  /*
536  * This is disabled, because there can be external parameters
537  * that may have changed (e.g. ConInfo->FontWeight, code page, ...)
538  * and that we don't control here, and that need a font refresh.
539  */
540 #if 0
541  /* Check whether the selection has changed */
542  if (nSel == CurrentSelFont)
543  return FALSE;
544 #endif
545 
547  if (Length == LB_ERR) return FALSE;
548 
549  FaceName = HeapAlloc(GetProcessHeap(),
551  (Length + 1) * sizeof(WCHAR));
552  if (FaceName == NULL) return FALSE;
553 
554  Length = (INT)SendMessageW(hListBox, LB_GETTEXT, nSel, (LPARAM)FaceName);
555  FaceName[Length] = L'\0';
556 
557  StringCchCopyW(pConInfo->FaceName, ARRAYSIZE(pConInfo->FaceName), FaceName);
558  DPRINT("pConInfo->FaceName = '%S'\n", pConInfo->FaceName);
559 
560  /*
561  * Retrieve the read-only font group box label string template,
562  * and set the group box label to the name of the selected font.
563  */
564  Length = LoadStringW(hApplet, IDS_GROUPBOX_FONT_NAME, (LPWSTR)&FontGrpBoxLabelTpl, 0);
565  if (FontGrpBoxLabelTpl && Length > 0)
566  {
567  StringCchCopyNW(FontGrpBoxLabel, ARRAYSIZE(FontGrpBoxLabel), FontGrpBoxLabelTpl, Length);
568  StringCchCatW(FontGrpBoxLabel, ARRAYSIZE(FontGrpBoxLabel), FaceName);
569  SetDlgItemTextW(hDlg, IDC_GROUPBOX_FONT_NAME, FontGrpBoxLabel);
570  }
571 
572  HeapFree(GetProcessHeap(), 0, FaceName);
573 
574  /*
575  * Reset the font size list, only:
576  * - if we have changed the type of font, or
577  * - if the font type is the same and is RASTER but the font has changed.
578  * Otherwise, if the font type is not RASTER and has not changed,
579  * we always display the TrueType default sizes and we don't need to
580  * recreate the list when we change between different TrueType fonts.
581  */
582  FontType = SendMessageW(hListBox, LB_GETITEMDATA, nSel, 0);
583  if (FontType != LB_ERR)
584  {
585  SizeList->UseRasterOrTTList = (FontType == RASTER_FONTTYPE);
586 
587  /* Display the correct font size list (if needed) */
588  if (CurrentFontType != FontType)
589  UpdateFontSizeList(hDlg, SizeList);
590 
591  /* Enumerate the available sizes for the selected font */
592  if ((CurrentFontType != FontType) ||
593  (FontType == RASTER_FONTTYPE && CurrentSelFont != nSel))
594  {
595  LOGFONTW lf;
596  HDC hDC;
597 
598  if (SizeList->UseRasterOrTTList)
599  SendMessageW(SizeList->RasterSizeList.hWndList, LB_RESETCONTENT, 0, 0);
600  else
601  SendMessageW(SizeList->hWndTTSizeList, CB_RESETCONTENT, 0, 0);
602 
603  ZeroMemory(&lf, sizeof(lf));
604  lf.lfCharSet = DEFAULT_CHARSET; // CodePageToCharSet(pConInfo->CodePage);
605  // lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
606  StringCchCopyW(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), pConInfo->FaceName);
607 
608  hDC = GetDC(NULL);
610  ReleaseDC(NULL, hDC);
611 
612  /* Re-select the current font size */
613  if (SizeList->UseRasterOrTTList)
614  FontSizeList_SelectFontSize(SizeList, SizeList->CurrentRasterSize);
615  else
616  FontSizeList_SelectFontSize(SizeList, SizeList->CurrentTTSize);
617  }
618  }
619  else
620  {
621  /* We failed, display the raster fonts size list */
622  SizeList->UseRasterOrTTList = TRUE;
623  UpdateFontSizeList(hDlg, SizeList);
624  }
625  CurrentFontType = FontType;
626  CurrentSelFont = nSel;
627 
628  FontSizeChange(hDlg, SizeList, pConInfo);
629  return TRUE;
630 }
static BOOL CALLBACK EnumFontSizesProc(IN PLOGFONTW lplf, IN PNEWTEXTMETRICW lpntm, IN DWORD FontType, IN LPARAM lParam)
Definition: font.c:323
int WINAPI EnumFontFamiliesExW(HDC hdc, LPLOGFONTW lpLogfont, FONTENUMPROCW lpEnumFontFamExProc, LPARAM lParam, DWORD dwFlags)
Definition: font.c:400
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
#define TRUE
Definition: types.h:120
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
HDC WINAPI GetDC(_In_opt_ HWND)
#define LB_GETITEMDATA
Definition: winuser.h:2023
BYTE lfCharSet
Definition: dimm.idl:67
static HDC
Definition: imagelist.c:92
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
HINSTANCE hApplet
Definition: access.c:17
#define DEFAULT_CHARSET
Definition: wingdi.h:383
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define LB_RESETCONTENT
Definition: winuser.h:2037
#define LB_ERR
Definition: winuser.h:2407
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
void DPRINT(...)
Definition: polytest.cpp:61
#define LB_GETTEXTLEN
Definition: winuser.h:2032
#define CB_RESETCONTENT
Definition: winuser.h:1941
static VOID FontSizeList_SelectFontSize(IN PFONTSIZE_LIST_CTL SizeList, IN ULONG FontSize)
Definition: font.c:132
#define IDC_GROUPBOX_FONT_NAME
Definition: resource.h:48
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static BOOL FontSizeChange(IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList, IN OUT PCONSOLE_STATE_INFO pConInfo)
Definition: font.c:633
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define RASTER_FONTTYPE
Definition: wingdi.h:1089
#define LB_GETTEXT
Definition: winuser.h:2031
static const WCHAR L[]
Definition: oid.c:1250
#define IDS_GROUPBOX_FONT_NAME
Definition: resource.h:100
static HDC hDC
Definition: 3dtext.c:33
#define IDC_LBOX_FONTTYPE
Definition: resource.h:47
FARPROC FONTENUMPROCW
Definition: wingdi.h:2875
static INT(WINAPI *pAddFontResourceExA)(LPCSTR
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define LB_GETCURSEL
Definition: winuser.h:2021
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
static VOID UpdateFontSizeList(IN HWND hDlg, IN PFONTSIZE_LIST_CTL SizeList)
Definition: font.c:455
static INT CurrentSelFont
Definition: font.c:44
static DWORD CurrentFontType
Definition: font.c:45
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HWND hListBox
Definition: enumfonts.cpp:27
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by FontProc().

◆ LogicalSizeToPointSize()

INT LogicalSizeToPointSize ( IN HDC hDC  OPTIONAL,
IN UINT  LogicalSize 
)

Definition at line 92 of file font.c.

95 {
96  INT PointSize;
97  HDC hOrgDC = hDC;
98 
99  if (!hDC)
100  hDC = GetDC(NULL);
101 
102  // LogicalSize = tm.tmHeight - tm.tmInternalLeading;
103  PointSize = MulDiv(LogicalSize, 72, GetDeviceCaps(hDC, LOGPIXELSY));
104 
105  if (!hOrgDC)
106  ReleaseDC(NULL, hDC);
107 
108  return PointSize;
109 }
HDC WINAPI GetDC(_In_opt_ HWND)
static HDC
Definition: imagelist.c:92
int32_t INT
Definition: typedefs.h:56
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
static HDC hDC
Definition: 3dtext.c:33
#define LOGPIXELSY
Definition: wingdi.h:718
#define MulDiv(x, y, z)
Definition: gdifloat.h:86

◆ PointSizeToLogicalSize()

INT PointSizeToLogicalSize ( IN HDC hDC  OPTIONAL,
IN INT  PointSize 
)

Definition at line 112 of file font.c.

115 {
116  INT LogicalSize;
117  HDC hOrgDC = hDC;
118 
119  if (!hDC)
120  hDC = GetDC(NULL);
121 
122  LogicalSize = MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
123 
124  if (!hOrgDC)
125  ReleaseDC(NULL, hDC);
126 
127  return LogicalSize;
128 }
HDC WINAPI GetDC(_In_opt_ HWND)
static HDC
Definition: imagelist.c:92
int32_t INT
Definition: typedefs.h:56
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
static HDC hDC
Definition: 3dtext.c:33
#define LOGPIXELSY
Definition: wingdi.h:718
#define MulDiv(x, y, z)
Definition: gdifloat.h:86

Referenced by FontSizeList_GetSelectedFontSize().

◆ RasterSizeList_GetCount()

static INT RasterSizeList_GetCount ( IN PLIST_CTL  ListCtl)
static

Definition at line 75 of file font.c.

77 {
78  return (INT)SendMessageW(ListCtl->hWndList, LB_GETCOUNT, 0, 0);
79 }
int32_t INT
Definition: typedefs.h:56
#define LB_GETCOUNT
Definition: winuser.h:2020
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by FontProc().

◆ RasterSizeList_GetData()

static ULONG_PTR RasterSizeList_GetData ( IN PLIST_CTL  ListCtl,
IN INT  Index 
)
static

Definition at line 83 of file font.c.

86 {
87  return (ULONG_PTR)SendMessageW(ListCtl->hWndList, LB_GETITEMDATA, (WPARAM)Index, 0);
88 }
#define LB_GETITEMDATA
Definition: winuser.h:2023
UINT_PTR WPARAM
Definition: windef.h:207
uint32_t ULONG_PTR
Definition: typedefs.h:63
static const UCHAR Index[8]
Definition: usbohci.c:18
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by FontProc().

◆ RefreshFontPreview()

VOID RefreshFontPreview ( IN FONT_PREVIEW Preview,
IN PCONSOLE_STATE_INFO  pConInfo 
)

Definition at line 49 of file font.c.

52 {
53  if (Preview->hFont) DeleteObject(Preview->hFont);
54  Preview->hFont = CreateConsoleFont(pConInfo);
55  if (Preview->hFont == NULL)
56  DPRINT1("RefreshFontPreview: CreateConsoleFont() failed\n");
57  GetFontCellSize(NULL, Preview->hFont, &Preview->CharHeight, &Preview->CharWidth);
58 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
smooth NULL
Definition: ftsmooth.c:416
BOOL GetFontCellSize(IN HDC hDC OPTIONAL, IN HFONT hFont, OUT PUINT Height, OUT PUINT Width)
Definition: font.c:113
#define DPRINT1
Definition: precomp.h:8
HFONT CreateConsoleFont(IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
Definition: font.c:95

Referenced by InitApplet(), PaintText(), and WinPrev_OnDraw().

◆ UpdateFontPreview()

VOID UpdateFontPreview ( IN FONT_PREVIEW Preview,
IN HFONT  hFont,
IN UINT  CharWidth,
IN UINT  CharHeight 
)

Definition at line 61 of file font.c.

66 {
67  if (Preview->hFont) DeleteObject(Preview->hFont);
68  Preview->hFont = hFont;
69  Preview->CharWidth = CharWidth;
70  Preview->CharHeight = CharHeight;
71 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HFONT hFont
Definition: main.c:53
static int CharHeight
Definition: carets.c:8
static int CharWidth
Definition: carets.c:7

Referenced by FontSizeChange().

◆ UpdateFontSizeList()

static VOID UpdateFontSizeList ( IN HWND  hDlg,
IN PFONTSIZE_LIST_CTL  SizeList 
)
static

Definition at line 455 of file font.c.

458 {
459  HWND hDlgItem;
460 
461  if (SizeList->UseRasterOrTTList)
462  {
463  /*
464  * Raster font: show the Raster size list, and
465  * hide the TrueType size list and the units.
466  */
467 
468  // EnableDlgItem(hDlg, IDC_CHECK_BOLD_FONTS, FALSE);
469 
470  hDlgItem = GetDlgItem(hDlg, IDC_RADIO_PIXEL_UNIT);
471  ShowWindow(hDlgItem, SW_HIDE);
472  EnableWindow(hDlgItem, FALSE);
473 
474  hDlgItem = GetDlgItem(hDlg, IDC_RADIO_POINT_UNIT);
475  ShowWindow(hDlgItem, SW_HIDE);
476  EnableWindow(hDlgItem, FALSE);
477 
478  hDlgItem = SizeList->hWndTTSizeList;
479  ShowWindow(hDlgItem, SW_HIDE);
480  EnableWindow(hDlgItem, FALSE);
481 
482  hDlgItem = SizeList->RasterSizeList.hWndList;
483  EnableWindow(hDlgItem, TRUE);
484  ShowWindow(hDlgItem, SW_SHOW);
485  }
486  else
487  {
488  /*
489  * TrueType font: show the TrueType size list
490  * and the units, and hide the Raster size list.
491  */
492 
493  // EnableDlgItem(hDlg, IDC_CHECK_BOLD_FONTS, TRUE);
494 
495  hDlgItem = SizeList->RasterSizeList.hWndList;
496  ShowWindow(hDlgItem, SW_HIDE);
497  EnableWindow(hDlgItem, FALSE);
498 
499  hDlgItem = SizeList->hWndTTSizeList;
500  EnableWindow(hDlgItem, TRUE);
501  ShowWindow(hDlgItem, SW_SHOW);
502 
503  hDlgItem = GetDlgItem(hDlg, IDC_RADIO_PIXEL_UNIT);
504  EnableWindow(hDlgItem, TRUE);
505  ShowWindow(hDlgItem, SW_SHOW);
506 
507  hDlgItem = GetDlgItem(hDlg, IDC_RADIO_POINT_UNIT);
508  EnableWindow(hDlgItem, TRUE);
509  ShowWindow(hDlgItem, SW_SHOW);
510  }
511 }
#define IDC_RADIO_POINT_UNIT
Definition: resource.h:45
#define TRUE
Definition: types.h:120
#define IDC_RADIO_PIXEL_UNIT
Definition: resource.h:44
#define SW_HIDE
Definition: winuser.h:762
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define SW_SHOW
Definition: winuser.h:769
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)

Referenced by FontProc(), and FontTypeChange().

Variable Documentation

◆ CurrentFontType

DWORD CurrentFontType = (DWORD)-1
static

Definition at line 45 of file font.c.

Referenced by FontProc(), and FontTypeChange().

◆ CurrentSelFont

INT CurrentSelFont = LB_ERR
static

Definition at line 44 of file font.c.

Referenced by FontTypeChange().

◆ FontPreview

FONT_PREVIEW FontPreview = {NULL, 0, 0}

Definition at line 21 of file font.c.

Referenced by FontSizeChange(), InitApplet(), OptionsProc(), PaintText(), and WinPrev_OnDraw().

◆ TrueTypePoints

const SHORT TrueTypePoints[]
static
Initial value:
=
{
5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72
}

Definition at line 27 of file font.c.

Referenced by EnumFontSizesProc().