summaryrefslogtreecommitdiffstats
path: root/src/windows/wintel/font.c
blob: 9224c41f7ba056bd6fd542047f5669c5e72ca2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* font.c */

#include <windows.h>
#include <commdlg.h>
#include <assert.h>
#include "screen.h"
#include "ini.h"

void ProcessFontChange(
		       HWND hWnd)
{
  static DWORD dwFontColor;  /* Color of font if one has been selected */
  CHOOSEFONT cf;
  HDC hDC;
  SCREEN *pScr;
  TEXTMETRIC tm;
  char buf[16];
  char szStyle[LF_FACESIZE];

  pScr = (SCREEN *) GetWindowLong(hWnd, SCREEN_HANDLE);
  assert(pScr != NULL);

  cf.lStructSize = sizeof(cf);
  cf.hwndOwner = hWnd;
  cf.lpLogFont = (LPLOGFONT) &(pScr->lf);
  cf.lpszStyle = szStyle;
  cf.Flags = CF_INITTOLOGFONTSTRUCT; /* | CF_USESTYLE; */
  cf.Flags |= CF_SCREENFONTS;
#if 0
  cf.Flags |= CF_ANSIONLY;
#endif
  cf.Flags |= CF_FORCEFONTEXIST;
  cf.Flags |= CF_FIXEDPITCHONLY;
  cf.Flags |= CF_NOSIMULATIONS;

  if (ChooseFont(&cf)) {
    if (pScr->hSelectedFont)
      DeleteObject(pScr->hSelectedFont);

    pScr->hSelectedFont = CreateFontIndirect(&(pScr->lf));
    pScr->lf.lfUnderline = TRUE;
    pScr->hSelectedULFont = CreateFontIndirect(&(pScr->lf));
    pScr->lf.lfUnderline = FALSE;
    hDC = GetDC(hWnd);
    SelectObject(hDC, pScr->hSelectedFont);
    GetTextMetrics(hDC, &tm);
    pScr->cxChar = tm.tmAveCharWidth;
    pScr->cyChar = tm.tmHeight + tm.tmExternalLeading;
    ReleaseDC(hWnd, hDC);
    SetWindowPos(hWnd, NULL, 0, 0, pScr->cxChar * pScr->width +
		 FRAME_WIDTH, pScr->cyChar * pScr->height +
		 FRAME_HEIGHT, SWP_NOMOVE | SWP_NOZORDER);

    dwFontColor = RGB(255, 255, 255);
    InvalidateRect(hWnd, NULL, TRUE);
  }

  WritePrivateProfileString(INI_FONT, "FaceName", pScr->lf.lfFaceName, TELNET_INI);
  wsprintf(buf, "%d", (int) pScr->lf.lfHeight);
  WritePrivateProfileString(INI_FONT, "Height", buf, TELNET_INI);
  wsprintf(buf, "%d", (int) pScr->lf.lfWidth);
  WritePrivateProfileString(INI_FONT, "Width", buf, TELNET_INI);
  wsprintf(buf, "%d", (int) pScr->lf.lfEscapement);
  WritePrivateProfileString(INI_FONT, "Escapement", buf, TELNET_INI);
  wsprintf(buf, "%d", (int) pScr->lf.lfCharSet);
  WritePrivateProfileString(INI_FONT, "CharSet", buf, TELNET_INI);
  wsprintf(buf, "%d", (int) pScr->lf.lfPitchAndFamily);
  WritePrivateProfileString(INI_FONT, "PitchAndFamily", buf, TELNET_INI);

  return;

} /* ProcessFontChange */


void InitializeStruct(
			   WORD wCommDlgType,
			   LPSTR lpStruct,
			   HWND hWnd)
{
  LPCHOOSEFONT lpFontChunk;

  if (wCommDlgType == IDC_FONT) {
    lpFontChunk = (LPCHOOSEFONT) lpStruct;

    lpFontChunk->lStructSize = sizeof(CHOOSEFONT);
    lpFontChunk->hwndOwner = hWnd;
    lpFontChunk->Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY
      | CF_INITTOLOGFONTSTRUCT | CF_APPLY;
    lpFontChunk->rgbColors = RGB(0, 0, 255);
    lpFontChunk->lCustData = 0L;
    lpFontChunk->lpfnHook = NULL;
    lpFontChunk->lpTemplateName = NULL;
    lpFontChunk->hInstance = NULL;
    lpFontChunk->lpszStyle = NULL;
    lpFontChunk->nFontType = SCREEN_FONTTYPE;
    lpFontChunk->nSizeMin = 0;
    lpFontChunk->nSizeMax = 0;
  }

} /* InitialiseStruct */