1 /* Copyright (C) 2001 by Alex Kompel <shurikk@pacbell.net> */
2 /* NetHack may be freely redistributed. See license for details. */
4 /* font management and such */
10 /* font table - 64 fonts ought to be enough */
11 static struct font_table_entry {
14 } font_table[MAXFONTS] ;
15 static int font_table_size = 0;
16 HFONT version_splash_font;
17 HFONT extrainfo_splash_font;
19 #define NHFONT_CODE(win, attr) (((attr&0xFF)<<8)|(win_type&0xFF))
21 static void __cdecl font_table_cleanup(void);
23 /* create font based on window type, charater attributes and
24 window device context */
25 HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
31 static BOOL once = FALSE;
35 atexit(font_table_cleanup);
38 ZeroMemory( &lgfnt, sizeof(lgfnt) );
40 /* try find font in the table */
41 for(font_index=0; font_index<font_table_size; font_index++)
42 if(NHFONT_CODE(win_type, attr)==font_table[font_index].code)
45 if( !replace && font_index<font_table_size )
46 return font_table[font_index].hFont;
50 lgfnt.lfHeight = -iflags.wc_fontsiz_status*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
51 lgfnt.lfWidth = 0; // average character width
52 lgfnt.lfEscapement = 0; // angle of escapement
53 lgfnt.lfOrientation = 0; // base-line orientation angle
54 lgfnt.lfWeight = FW_NORMAL; // font weight
55 lgfnt.lfItalic = FALSE; // italic attribute option
56 lgfnt.lfUnderline = FALSE; // underline attribute option
57 lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
58 lgfnt.lfCharSet = mswin_charset(); // character set identifier
59 lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
60 lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
61 lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
62 if( iflags.wc_font_status &&
63 *iflags.wc_font_status ) {
64 lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
65 NH_A2W( iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE);
67 lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
72 lgfnt.lfHeight = -iflags.wc_fontsiz_menu*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
73 lgfnt.lfWidth = 0; // average character width
74 lgfnt.lfEscapement = 0; // angle of escapement
75 lgfnt.lfOrientation = 0; // base-line orientation angle
76 lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
77 lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
78 lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
79 lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
80 lgfnt.lfCharSet = mswin_charset(); // character set identifier
81 lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
82 lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
83 lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
84 if( iflags.wc_font_menu &&
85 *iflags.wc_font_menu ) {
86 lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
87 NH_A2W( iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE);
89 lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
94 font_size = (attr==ATR_INVERSE)? iflags.wc_fontsiz_message+1 : iflags.wc_fontsiz_message;
95 lgfnt.lfHeight = -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
96 lgfnt.lfWidth = 0; // average character width
97 lgfnt.lfEscapement = 0; // angle of escapement
98 lgfnt.lfOrientation = 0; // base-line orientation angle
99 lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
100 lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
101 lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
102 lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
103 lgfnt.lfCharSet = mswin_charset(); // character set identifier
104 lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
105 lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
106 lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
107 if( iflags.wc_font_message &&
108 *iflags.wc_font_message ) {
109 lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
110 NH_A2W( iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE);
112 lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family
117 lgfnt.lfHeight = -iflags.wc_fontsiz_text*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
118 lgfnt.lfWidth = 0; // average character width
119 lgfnt.lfEscapement = 0; // angle of escapement
120 lgfnt.lfOrientation = 0; // base-line orientation angle
121 lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
122 lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
123 lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
124 lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
125 lgfnt.lfCharSet = mswin_charset(); // character set identifier
126 lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
127 lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
128 lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
129 if( iflags.wc_font_text &&
130 *iflags.wc_font_text ) {
131 lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
132 NH_A2W( iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE);
134 lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
139 fnt = CreateFontIndirect(&lgfnt);
141 /* add font to the table */
142 if( font_index==font_table_size ) {
143 if( font_table_size>=MAXFONTS ) panic( "font table overflow!" );
146 DeleteObject(font_table[font_index].hFont);
149 font_table[font_index].code = NHFONT_CODE(win_type, attr);
150 font_table[font_index].hFont = fnt;
157 if( iflags.IBMgraphics )
158 if( TranslateCharsetInfo((DWORD*)GetOEMCP(), &cis, TCI_SRCCODEPAGE) )
159 return cis.ciCharset;
163 if( TranslateCharsetInfo((DWORD*)GetACP(), &cis, TCI_SRCCODEPAGE) )
164 return cis.ciCharset;
169 void __cdecl font_table_cleanup(void)
172 for(i=0; i<font_table_size; i++) {
173 DeleteObject(font_table[i].hFont);