Windows console raster font

_ _ Структура сведений о ШРИФТе консоли CONSOLE_FONT_INFO structure

В этом документе описываются функциональные возможности платформы консоли, которые больше не являются частью нашего плана экосистемы . This document describes console platform functionality that is no longer a part of our ecosystem roadmap . Мы не советуем использовать это содержимое в новых продуктах, но мы будем продолжать поддерживать существующие случаи использования в течение неопределенного будущего. We do not recommend using this content in new products, but we will continue to support existing usages for the indefinite future. Наше рекомендуемое современное решение посвящено виртуальным последовательностью терминалов для обеспечения максимальной совместимости в межплатформенных сценариях. Our preferred modern solution focuses on virtual terminal sequences for maximum compatibility in cross-platform scenarios. Дополнительные сведения об этом решении по проектированию можно найти в классической консоли и в виртуальном документе терминала . You can find more information about this design decision in our classic console vs. virtual terminal document.

Содержит сведения о шрифте консоли. Contains information for a console font.

Синтаксис Syntax

Члены Members

нфонт nFont
Индекс шрифта в системной таблице шрифтов консоли. The index of the font in the system’s console font table.

двфонтсизе dwFontSize
Структура курд , которая содержит ширину и высоту каждого символа в шрифте в логических единицах. A COORD structure that contains the width and height of each character in the font, in logical units. Элемент X содержит ширину, а элемент Y содержит высоту. The X member contains the width, while the Y member contains the height.

Комментарии Remarks

Чтобы получить размер шрифта, передайте индекс шрифта в функцию жетконсолефонтсизе . To obtain the size of the font, pass the font index to the GetConsoleFontSize function.

Adding fonts to the PowerShell and cmd.exe consoles

The default font options for the PowerShell console are limited: raster fonts and Lucida Console. Raster fonts are the default, though Lucida Console is an improvement. In my opinion, Consolas is even better, but it’s not on the list of options.

Mastering PowerShell by Tobias Weltner explains how to expand the list of font options for the PowerShell console. The same trick increases the list of font options in the Windows command prompt cmd.exe as well. The book is free for download. See page 16 for details. However, I have two comments about the instructions it gives.

First, the book says “The name must be exactly the same as the official font name, just the way it’s stated under [registry key].” However, the Consolas font is listed in the registry as “Consolas (True Type)”. You should enter “Consolas” and leave out the parenthetical description.

Second, the book says “the new font will work only after you either log off at least once or restart your computer.” When I tried it, logging off was not sufficient; I had to reboot my computer before the font change would work.

Update: In order to make this post self-contained, I’ve added below the necessary information from Mastering PowerShell.

Run regedit.exe and navigate to HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionConsoleTrueTypeFont .

Читайте также:  Arch linux за firewall

Right-click in the panel on the right side and create a new string value. Name that value “0” or “00” or however many zeros you need to create a new key. That string’s value is the name of the font to add.

How to customize Console’s fonts in Windows 10

Hi team,
I scanned through all the forum categories and forums but found no proper place to put such a question. So i searched some windows 10 relevant problems and it turned out other users put here, so I just did a simple following.

I am upgrading to windows 10 just now and i am excited to try the new features of Console. But i found that i can’t customize the fonts i want.

I’ve changed the registry accordingly shown in below figure as told on Internet

But as you can see from the second screenshot, there are no choices in the properties window of the Console.

Any ideas where i am missing?

Replies (5) 

Thank you for contacting Microsoft Community.

I would like to inform you that It is not recommended make changes in the registry, if you still want to make changes then you proceed with this but at your own risk. You may refer to the following MSDN article to know more about making changes in the registry:
http://blogs.msdn.com/b/powershell/archive/2006/10/16/windows-powershell-font-customization.aspx

Important: This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:

You may post you query on MSDN forum for further help. Here is the link:

Let us know if you need further assistance and we’ll be glad to help.

How to draw raster console fonts in GDI?

How do I draw the raster fonts used by the Windows console in a GDI application? For instance, the 8×8 fixed font as shown in this screenshot.

Can these fonts be used via the CreateFont() API, or is there some special way that Windows loads these fonts?

2 Answers 2

The console uses «fixed width fonts» , such as «Courier New» (available in all Windows version) or «Consolas» (available since Vista).

Fixed width fonts are not necessarily raster. To use raster fonts, enumerate fonts to find a raster font such as «Terminal» or «Fixedsys» . You have to use the right size (example, 18 for «Terminal» font) otherwise Windows may substitute a different font and resize. There are also issues with DPI settings. If program is not DPI aware then magnification will occur if work station has high DPI settings.

The answer was similar to Barmak’s answer, with the difference that both width and height are specified, so to create a font for the 8×8 raster font I use the following code:

Specifically, both the height and width must be specified, and the OEM_CHARSET charset must be specified, in order to select one of the Raster Fonts.

My intent is to render to a DirectDraw surface ( IDirectDrawSurface7::GetDC() ) then subsequently paint that surface to the primary, as shown here:

With a bit of trickery involving multiple passes I added a bit of a shadow effect to the text, however that is outside the scope of my original question.

Windows 10 1809/19H1/20H1 breaks Powershell’s console settings. Keeps opening with raster fonts. #280

Comments

Borkason commented Oct 11, 2018 •

Windows 10 1809 breaks Powershell’s console settings. Powershell keeps opening with raster fonts. You can change the settings and see the result, but when you open the settings again (with or without closing the powershell inbetween) the font has reset to raster fonts in size 12.

Edit: Upgraded from 1803. German Locale.

The text was updated successfully, but these errors were encountered:

50Wliu commented Oct 14, 2018

The same happens to me only when using the Consolas font. If I use anything else — Courier New, Lucida Console, etc. — the settings are retained.

Читайте также:  Нет такого файла или каталога astra linux

Borkason commented Oct 15, 2018

@50Wliu I can confirm that behaviour. Consolas resets to raster font. Lucida Console stays Lucida Console.

zadjii-msft commented Oct 15, 2018

I’m almost certain this has to do with the fact that the new version of PSReadline is using the UTF8 codepage for displaying it’s prompt, and when it does that, the console tries to recalculate the font.

I thought we had some issues tracking this previously, but I can’t seem to find them. @bitcrazed do you remember where they were? Or was it an internal mail thread with @lzybkr and @SteveL-MSFT?

SteveL-MSFT commented Oct 15, 2018

Can someone provide an exact repro? Like what font are you setting to the shortcut. What font is it being set to?

Borkason commented Oct 15, 2018

  • Win-R and run powershell .
  • It starts with raster font.
  • Go into settings and set the font to Consolas. Click OK.
  • Consolas is being applied.
  • Close Powershell.
  • Reopen powershell like before.
  • Font is raster font again.
  • Go into default settings and set the font to Consolas. Click OK.
  • Close Powershell.
  • Reopen powershell like before.
  • Font is raster font again.

miniksa commented Oct 15, 2018

I don’t think this was even Powershell’s fault. I have a note sitting around here somewhere that one of the most recent .NET Frameworks (4.7something) suddenly decides to use 65001 as the default code page for all apps and when that flips back and forth with other tools and codepages as they start and exit, we recalculate the font.

I have a bug on me to try to make that less painful, but it’s really the sudden flipping between codepages that is making this be a problem.

doctordns commented Oct 17, 2018

I can’t reproduce this here. Both Windows PowerShell and Powershell both start up in the font I set.

cloudhan commented Oct 17, 2018

bitcrazed commented Oct 17, 2018

@borakson — what locale is your Windows configured to use?

50Wliu commented Oct 17, 2018

@bitcrazed I’m not @Borkason but since I’m experiencing this issue I’ll answer as well.

My display language is Spanish (Spain), and so is my regional format. The language for programs that don’t support Unicode is English (United States), and I have the beta checkbox selected for UTF-8 Unicode. (Hope that’s what you’re looking for. let me know if you were asking for something else)

Borkason commented Oct 19, 2018

@bitcrazed German. And I upgraded from 1803. Forgot to meantion that.

Borkason commented Oct 19, 2018

doctordns commented Oct 19, 2018

I use Lucida Console (18 pt). But I’ve tested others and they too work after a restart of Windows PowerShell.

Borkason commented Oct 19, 2018

The same happens to me only when using the Consolas font. If I use anything else — Courier New, Lucida Console, etc. — the settings are retained.

bitcrazed commented Nov 12, 2018

This was likely fixed by @lzybkr’s recent work: PowerShell/PSReadLine#542

@Borkason & @doctordns — can you please confirm and close if fixed?

50Wliu commented Nov 13, 2018

@bitcrazed it looks like the issue you’re referencing was fixed back in 2017 and as far as I can tell is included in the version of PSReadLine that 1809 ships with. Additionally, this issue is still occuring for me as of Windows Insiders build 18277.

Borkason commented Nov 15, 2018

@bitcrazed That’s one year older then the 1809 release. I wouldn’t call that «recent».

And for me nothing changed. I’m on Windows 10 build 17763.107

But as @50Wliu already sayd, it’s not even fixed in the current preview.

Borkason commented Nov 15, 2018

Here is a link to the Feedback: https://aka.ms/AA37kk1

lzybkr commented Nov 15, 2018

@bitcrazed linked to the issue that caused the problem.

Borkason commented Nov 15, 2018

Fair enough. Is it known with what build the fix will ship?

lzybkr commented Nov 15, 2018

I’ll try to release another beta to the PowerShell Gallery before the end of the year, but I don’t know about Windows (I don’t work on Windows).

@SteveL-MSFT owns the bits that ship in Windows, so maybe he can comment.

Читайте также:  Как обновить nokia lumia 535 до windows 10

kid1412621 commented Nov 29, 2018

PSVersion 5.1.17763.134
PSEdition Desktop
PSCompatibleVersions <1.0, 2.0, 3.0, 4.0. >
BuildVersion 10.0.17763.134
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

same here. ready to re-install windows, REALLY painful!

ghost commented Dec 13, 2018 •

This problem seems links to fonts. I got the problem in Powershell with windows(cmd and Powershell core don’t have this problem) when I set the font as ‘Console’, but when I change the font as ‘Sarasa Mono SC’, all work perfectly. I use ‘Sarasa Mono SC’ to show UTF-8 character, Windows 10 doesn’t have a default font can show enough UTF-8 characters.

xhxgit commented Dec 26, 2018

Same here. Both my Surface & desktop PC.

offero commented Jan 13, 2019 •

Strangely I think I am experiencing this same issue but from a different way. Whenever a subprocess is opened to run powershell.exe, the console font changes to raster from Consolas.

Example 1: I have vim running (WSL) and it runs a powershell sub command to get the system clipboard. Every time I run that command, it resets the console font to raster fonts.

Example 2: I have a shell script that runs powershell as a subprocess to get the system nameservers. It causes the same thing to happen to the console, a switch to raster fonts. Nothing is output to the console. Everything happens in the subprocess.

The really strange part is that if I run powershell manually from the console (WSL), then it’s fine and the font does not change.

kkm000 commented Jan 13, 2019 •

@bitcrazed, @SteveL-MSFT, @lzybkr: I have a good minimal repro. This started happening right after I upgraded the machine to Windows 1809. I had the font and console CP set before, as below, to Consolas and 65001 respectively, and everything worked just fine. I work with UTF-8 files, so the CP 65001 has been essential to me. My locale is plain old en-US, English language Windows 10 x64 Pro, and the OEM CP is the default 437.

  1. Set the following registry keys (save as .reg and import). For some reason, it i important to change FontFamily, as the default may be different, and the font won’t be applied.
  1. Win+R cmd.exe ENTER . Console starts with the correct font and code page. Type chcp ; it prints 65001 (if does not, run chcp 65001 ).
  2. in the console, type powershell -noprof (‘-noprof’ to confirm that the issue is not related to anything I load in my profile).

As PowerShell starts, the console font immediately changes to a raster font, and the window resizes to accommodate. The raster font selected is Terminal, and does not even even have WGL4 characters (no Cyrillic or Greek). So this is certainly a bug.

The behavior reproduces even if running a non-interactive command, so it’s rather doubtful that the bug is related to PSReadLine:

Also, the console font changes similarly (essentially, the console opens in a raster font) if PowerShell is ran via a shortcut, or from the Win+R dialog, or by double-clicking in Explorer.

Also, some negatives. The font is not changed if either:

  • I run chcp 437 before invoking powershell from cmd.
  • The console font is set in the registry to «Lucida Console» (everything else stays same as above). That this font is somehow «special» has been already noted in the comments in this ticket.

The common theme in the comments in this issue has been, I believe, a non-US, European locale (German ans Spanish were mentioned). So i tried the following:

  1. Start cmd.exe
  2. Set console code page with chcp NNN (see below):
  3. Run powershell -noprof .
  • With NNN = 437, 1252, 1251, 1253, 850, 852, 869, 857, 737 — no font change
  • With NNN = 65001, 858, and non-WGL4 Hebrew 862, Arabic 864 — font does change.

What sets the CP 858 apart? My guess is this may be the key. The CP name is «OEM Multilingual Latin 1 + Euro symbol».

Also notable is that chcp 1255 and chcp 1266 (Hebrew and Arabic) change font to «Courier New» even in cmd.exe. So PowerShell may be only somehow more susceptible, not the main culprit?

Obligatory version info:

Also, I should mention, although this is most likely irrelevant: I have a high-DPI display with the display scale set to 150%.

Оцените статью