check_font_widths returns TRUE if all glyphs in current console font * fit within the width of a single console cell. */
| 2094 | * fit within the width of a single console cell. |
| 2095 | */ |
| 2096 | boolean |
| 2097 | check_font_widths(void) |
| 2098 | { |
| 2099 | CONSOLE_FONT_INFOEX console_font_info; |
| 2100 | console_font_info.cbSize = sizeof(console_font_info); |
| 2101 | BOOL success = GetCurrentConsoleFontEx(console.hConOut, FALSE, |
| 2102 | &console_font_info); |
| 2103 | |
| 2104 | /* get console window and DC |
| 2105 | * NOTE: the DC from the console window does not have the correct |
| 2106 | * font selected at this point. |
| 2107 | */ |
| 2108 | console.hWnd = GetConsoleWindow(); |
| 2109 | HDC hDC = GetDC(console.hWnd); |
| 2110 | |
| 2111 | LOGFONTW logical_font; |
| 2112 | logical_font.lfCharSet = DEFAULT_CHARSET; |
| 2113 | wcscpy(logical_font.lfFaceName, console_font_info.FaceName); |
| 2114 | logical_font.lfPitchAndFamily = 0; |
| 2115 | |
| 2116 | /* getting matching console font */ |
| 2117 | LOGFONTW matching_log_font = { 0 }; |
| 2118 | EnumFontFamiliesExW(hDC, &logical_font, EnumFontCallback, |
| 2119 | (LPARAM) &matching_log_font, 0); |
| 2120 | |
| 2121 | if (matching_log_font.lfHeight == 0) { |
| 2122 | raw_print("Unable to enumerate system fonts\n"); |
| 2123 | return FALSE; |
| 2124 | } |
| 2125 | |
| 2126 | /* create font matching console font */ |
| 2127 | LOGFONTW console_font_log_font = matching_log_font; |
| 2128 | console_font_log_font.lfWeight = console_font_info.FontWeight; |
| 2129 | console_font_log_font.lfHeight = console_font_info.dwFontSize.Y; |
| 2130 | console_font_log_font.lfWidth = console_font_info.dwFontSize.X; |
| 2131 | HFONT console_font = CreateFontIndirectW(&console_font_log_font); |
| 2132 | |
| 2133 | if (console_font == NULL) { |
| 2134 | raw_print("Unable to create console font\n"); |
| 2135 | return FALSE; |
| 2136 | } |
| 2137 | |
| 2138 | /* select font */ |
| 2139 | HGDIOBJ saved_font = SelectObject(hDC, console_font); |
| 2140 | |
| 2141 | /* measure the set of used glyphs to ensure they fit */ |
| 2142 | boolean all_glyphs_fit = FALSE; |
| 2143 | |
| 2144 | /* determine whether it is a true type font */ |
| 2145 | TEXTMETRICA tm; |
| 2146 | success = GetTextMetricsA(hDC, &tm); |
| 2147 | |
| 2148 | if (!success) { |
| 2149 | raw_print("Unable to get console font text metrics\n"); |
| 2150 | goto clean_up; |
| 2151 | } |
| 2152 | |
| 2153 | boolean isTrueType = (tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0; |
no test coverage detected