PureBasic console characters

Just starting out? Need help? Post your questions and find answers here.
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

PureBasic console characters

Post by ElementE »

The character set displayed in a PureBasic Console window are different than displayed in a Debug Window.

Does anyone know what character set is used for Console Window output?
Is it the classic OEM code page 437?

And, importantly, can the character set, or code page, used by PureBasic's console window be changed?
Think Unicode!
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic console characters

Post by infratec »

Hi,

I think PB has no 'console window' it opens a windows console.
You also can run the exe in a cmd window, which is also a 'console window'.

I think it's only possible if you change the windows default console font.

Bernd
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: PureBasic console characters

Post by ElementE »

Hi infratec,

I have read that the windows console window displays the OEM code page, which is usually 437, at least in North America.

That means only single byte characters would be displayed with codes from 0 to 255.

But, in Unicode mode when using the PB Print or PrintN commands to write to the console, a UCS-2 sting of two byte characters is sent to the console, and the characters are displayed properly.

So there are two possibilities, (1) the Windows cmd console can handle UCS-2 two byte characters and display them properly, or (2) the PB compiler will convert the two byte UCS-2 characters to one byte OEM characters which will then be sent to the windows console.

I think a test program will have to be created to help answer this question.

And I haven't figured out how the windows code page 1252 set of characters comes into play with PureBasic!
Think Unicode!
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic console characters

Post by infratec »

User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PureBasic console characters

Post by netmaestro »

Some fooling around (win8.1):

Code: Select all

; HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
;   NT\CurrentVersion\
;   Console\RasterFonts
;    -and- \TrueTypeFont
;          
Structure CONSOLE_FONT_INFOEX
  cbSize.l
  nFont.l
  dwFontSize.COORD
  FontFamily.l
  FontWeight.l
  FaceName.u[#LF_FACESIZE]
EndStructure

Prototype SetConsoleFont(handle, index)
Prototype GetNumberOfConsoleFonts()
Prototype SetCurrentConsoleFontEx(handle, bool, *cfi.CONSOLE_FONT_INFOEX)

OpenLibrary(0, "kernel32.dll")
Global SetConsoleFont_.SetConsoleFont                   = GetFunction(0, "SetConsoleFont")
Global GetNumberOfConsoleFonts_.GetNumberOfConsoleFonts = GetFunction(0, "GetNumberOfConsoleFonts")
Global SetCurrentConsoleFontEx_.SetCurrentConsoleFontEx = GetFunction(0, "SetCurrentConsoleFontEx")

OpenConsole()
n = GetNumberOfConsoleFonts_()
hnd = GetStdHandle_(#STD_OUTPUT_HANDLE)

For i = 0 To n-1
  SetConsoleFont_(hnd, i)
  PrintN("Font "+Str(i)+": The quick brown fox jumped over the lazy dog.")
  Delay(1000)
  CloseConsole()
  OpenConsole()
  hnd = GetStdHandle_(#STD_OUTPUT_HANDLE)
Next

; Set font size and weight
With cfi.CONSOLE_FONT_INFOEX
  \cbSize = SizeOf(CONSOLE_FONT_INFOEX)
  \dwFontSize\X = 0
  \dwFontSize\Y = 48
  \FontWeight = #FW_BOLD
EndWith
PokeS(@cfi\FaceName, "Lucida Console", -1, #PB_Unicode)

SetCurrentConsoleFontEx_(GetStdHandle_(#STD_OUTPUT_HANDLE), 1, @cfi)
PrintN("The quick brown fox jumped over the lazy dog.")
PrintN("The quick brown fox jumped over the lazy dog.")
PrintN("The quick brown fox jumped over the lazy dog.")
PrintN("The quick brown fox jumped over the lazy dog.")
PrintN("The quick brown fox jumped over the lazy dog.")
Input()

CloseLibrary(0)
End
Some of the console fonts on my machine (there are 10, 5 raster and 5 truetype) are unicode fonts, which the OS will automatically switch to if it can't find a character in the current font.
BERESHEIT
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: PureBasic console characters

Post by ElementE »

This might prove very useful in experimenting with changing fonts in a console.

Console
http://sourceforge.net/projects/console/

Description

Console is a Windows console window enhancement. Console features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles

The idea is to configure a font, run Console, then run a PureBasic console exe from withing the window and see what happens when the font is changed.
Think Unicode!
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: PureBasic console characters

Post by ElementE »

Here is some info about the Lucida Console font.
From this we can see why only a limited number of Unicode characters can be displayed in Console Window

From:
http://www.microsoft.com/typography/fon ... ?fmid=1262

Font Name: Lucida Console
Version: 5.00

Unicode Ranges:
Basic Latin
Latin-1 Supplement
Latin Extended-A
Latin Extended-B
Greek and Coptic
Cyrillic,
Cyrillic Supplementary
General Punctuation
Box Drawing
Block Elements

Code Pages:
1252 Latin 1
1250 Latin 2: Eastern Europe
1251 Cyrillic
1253 Greek
1254 Turkish
869 IBM Greek
866 MS-DOS Russian
865 MS-DOS Nordic
863 MS-DOS Canadian French
861 MS-DOS Icelandic
860 MS-DOS Portuguese
857 IBM Turkish
855 IBM Cyrillic; primarily Russian
852 Latin 2
737 Greek; former 437 G
850 WE/Latin 1
437 US
Think Unicode!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PureBasic console characters

Post by netmaestro »

http://en.wikipedia.org/wiki/Fallback_font

Ten console fonts on my computer, several are unicode. All are fallbacks.
Last edited by netmaestro on Thu Mar 05, 2015 10:00 am, edited 1 time in total.
BERESHEIT
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: PureBasic console characters

Post by ElementE »

Thank you netmaestro for mentioning Fallback fonts. I had never heard of them before.

When I look at Fonts in the properties of a cmd window, I only see Lucida Console and Raster Fonts listed.
Think Unicode!
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: PureBasic console characters

Post by ElementE »

This might be useful for reference.

Code Page Identifiers
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

Usually the console is set to cp437 (OEM).

Code page 65001 will allow the console to display UTF-8 encoded text.

Another useful page is:

https://msdn.microsoft.com/en-us/goglobal/ff678782.aspx

that gives the default code pages for older versions of Windows and MS-DOS.
Think Unicode!
Post Reply