- Aug
- 2,799
- 144
A PowerShell .ps1 script to determine the current fontname in use;
Output from TCC;
Output from PowerShell 5.1 in Windows Terminal;
Output from TCC in Windows Terminal;
Joe
Code:
if (-not ('Win32test.ConsoleTest' -as [type])) {
$defConsoleTest = @'
using System.Runtime.InteropServices;
using System;
namespace Win32test
{
public static class ConsoleTest
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
extern static bool GetCurrentConsoleFontEx(
IntPtr hConsoleOutput,
bool bMaximumWindow,
ref CONSOLE_FONT_INFOEX lpConsoleCurrentFont);
private enum StdHandle
{
OutputHandle = -11
}
[DllImport("kernel32")]
private static extern IntPtr GetStdHandle(StdHandle index);
public static string GetFontInfo()
{
CONSOLE_FONT_INFOEX ConsoleFontInfo = new CONSOLE_FONT_INFOEX();
ConsoleFontInfo.cbSize = (uint)Marshal.SizeOf(ConsoleFontInfo);
GetCurrentConsoleFontEx(GetStdHandle(StdHandle.OutputHandle), false, ref ConsoleFontInfo);
return string.Format("FaceName: {0}, FontFamily: {1}, FontWeight: {2}, FontSize: {3}x{4}",
ConsoleFontInfo.FaceName,
ConsoleFontInfo.FontFamily,
ConsoleFontInfo.FontWeight,
ConsoleFontInfo.dwFontSize.X,
ConsoleFontInfo.dwFontSize.Y);
}
[StructLayout(LayoutKind.Sequential)]
private struct COORD
{
public short X;
public short Y;
public COORD(short x, short y) { X = x; Y = y; }
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct CONSOLE_FONT_INFOEX
{
public uint cbSize;
public uint nFont;
public COORD dwFontSize;
public int FontFamily;
public int FontWeight;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string FaceName;
}
}
}
'@
Add-Type -TypeDefinition $defConsoleTest
}
[Win32test.ConsoleTest]::GetFontInfo()
Output from TCC;
Code:
R:\>pshell fontname.ps1
FaceName: IBM 3270, FontFamily: 54, FontWeight: 700, FontSize: 16x34
Output from PowerShell 5.1 in Windows Terminal;
Code:
PS R:\> .\FontName.ps1
FaceName: Consolas, FontFamily: 4, FontWeight: 0, FontSize: 0x16
Output from TCC in Windows Terminal;
Code:
R:\>pshell FontName.ps1
FaceName: Consolas, FontFamily: 4, FontWeight: 0, FontSize: 0x16
Joe