changing code pages
changing code pages
hello.
i have a question... is there any way to change the code page of the console window so it can print and display hebrew?
thank you...
ron77
i have a question... is there any way to change the code page of the console window so it can print and display hebrew?
thank you...
ron77
Re: changing code pages
Yes, that can be done with Open Pipe.ron77 wrote:is there any way to change the code page of the console window ...
However, I don't know whether 'hebrew' also works (not tested, CP unkown to me).
See: Code Page - the way you want it! (in Tips & Tricks section, about 3 years ago)
It even goes a step further, by saving current CP first and restores it again, before
the program quits.
Re: changing code pages
thank you very much MrSwiss :)
this sure helps alot...
ron77
this sure helps alot...
ron77
Re: changing code pages
Code: Select all
#include "Windows.bi"
Print "Current codepage is ";GetConsoleOutputCP()
SetConsoleOutputCP(862)
Print "The new codepage is ";GetConsoleOutputCP()
Print "Put Hebrew text here"
sleep
Re: changing code pages
The console font must be changed to one that has Hebrew glyphs.jj2007 wrote:Code: Select all
#include "Windows.bi" Print "Current codepage is ";GetConsoleOutputCP() SetConsoleOutputCP(862) Print "The new codepage is ";GetConsoleOutputCP() Print "Put Hebrew text here" sleep
There are few, Courier New, Miriam are two. Even so, only letters, not vowel-points or cantillation marks are in fonts that support code page 862.
Unicode would be much better way to go.
Code: Select all
#include "Windows.bi"
dim as _CONSOLE_FONT_INFOEX x
with x
.cbsize=sizeof(_CONSOLE_FONT_INFOEX)
.nfont=0
.dwfontsize=type(16,32)'new font size
.fontfamily=0
.fontweight=100
.facename="Courier New"
end with
setcurrentconsolefontex(GetStdHandle(STD_OUTPUT_HANDLE),1, @x )
Print "Current codepage is ";GetConsoleOutputCP()
SetConsoleOutputCP(862)
Print "The new codepage is ";GetConsoleOutputCP()
Print CHR(128,129,130,131.132,133,134,135,136)
print "Press a key"
sleep
Re: changing code pages
Don't expect miracles. The console should produce the same output with Utf8 (65001) or Utf16 (65000) but, as you wrote above, you need a font that supports the codepage.robert wrote:Unicode would be much better way to go
Anyway, it's a can of worms. Print "This is Russian: Добро пожаловать" used to work fine, now it doesn't, and I don't have the faintest idea why it stopped working (it still works fine in other programming languages, and under the hood I see that codepage is Utf8 and a Utf8 string is being passed to the print function).
Code: Select all
#include "Windows.bi"
#include "crt.bi"
SetConsoleOutputCP(65001)
Print "The new codepage is ";GetConsoleOutputCP()
Print "FB: this is Russian: Добро пожаловать"
Printf("Crt: this is Russian: Добро пожаловать"+chr(10))
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), @"WC: this is Russian: Добро пожаловать", 53, 0, 0)
sleep
Code: Select all
The new codepage is 65001
FB: this is Russian: ���������� ��������������������
Crt: this is Russian: �"�����?�� �����������������'�O
WC: this is Russian: Добро пожаловать
Re: changing code pages
IIRC for some locales you had to start your command box with "cmd /w"
In Free Pascal I use the following API call to set the font to consolas, since it is mostly API calls, it should be easily translatable. Or just google them in MSDN
P.s. there is also a way to change to utf8 by manifest in recent Windows 10s. This means that all -A apis also accept utf8:
https://docs.microsoft.com/en-us/window ... -code-page
In Free Pascal I use the following API call to set the font to consolas, since it is mostly API calls, it should be easily translatable. Or just google them in MSDN
Code: Select all
unit setdefaultcodepages;
interface
uses
Windows;
implementation
Const
LF_FACESIZE = 32;
Type
CONSOLE_FONT_INFOEX = record
cbSize : ULONG;
nFont : DWORD;
dwFontSize : COORD;
FontFamily : UINT;
FontWeight : UINT;
FaceName : array [0..LF_FACESIZE-1] of WCHAR;
end;
{ Only supported in Vista and onwards!}
function SetCurrentConsoleFontEx(hConsoleOutput: HANDLE; bMaximumWindow: BOOL; var CONSOLE_FONT_INFOEX): BOOL; stdcall; external kernel32;
var
New_CONSOLE_FONT_INFOEX: CONSOLE_FONT_INFOEX;
initialization
FillChar(New_CONSOLE_FONT_INFOEX, SizeOf(CONSOLE_FONT_INFOEX), 0);
New_CONSOLE_FONT_INFOEX.cbSize := SizeOf(CONSOLE_FONT_INFOEX);
New_CONSOLE_FONT_INFOEX.FaceName := 'Consolas';
// New_CONSOLE_FONT_INFOEX.FaceName := 'Lucida Console'; //use Lucida Console for Win XP
New_CONSOLE_FONT_INFOEX.FontWeight := 400;
New_CONSOLE_FONT_INFOEX.dwFontSize.Y := 16;
SetCurrentConsoleFontEx(StdOutputHandle, False, New_CONSOLE_FONT_INFOEX);
end.
https://docs.microsoft.com/en-us/window ... -code-page
Re: changing code pages
No problems using my own quick run program
I save the file via wordpad (write.exe) then run the saved file.
Code: Select all
This is Russian: Добро пожаловать
Free basic version 1.07-(08).0
Re: changing code pages
I'm not sure if I understand. Did you mean you save the *.bas file with Wordpad, then you build and run using this file?dodicat wrote:No problems using my own quick run programI save the file via wordpad (write.exe) then run the saved file.Code: Select all
This is Russian: Добро пожаловать Free basic version 1.07-(08).0
Re: changing code pages
I saved it as russian.txt and compiled and ran (through my own quick run ide/editor, which is basically command line via a little gui).
fbide doesn't handle these characters.
Notepad on this machine also curupts the characters.
Win 10.
fbide doesn't handle these characters.
Notepad on this machine also curupts the characters.
Win 10.
Re: changing code pages
Notepad probably scans for bom. Emit a BOM if you want to let it autoguess utf8.dodicat wrote:I saved it as russian.txt and compiled and ran (through my own quick run ide/editor, which is basically command line via a little gui).
fbide doesn't handle these characters.
Notepad on this machine also curupts the characters.
Win 10.
Re: changing code pages
In my case it's not the IDE (I use my own editor, it does emit Utf8).
The problem is another one: in all three cases, standard FB print, Printf(), and WriteConsole, a Utf8 String is passed correctly (checked in the debugger at assembly level). But only WriteFile and WriteConsole produce the correct output. What does FB use for its default Print? I debugged print but so far I could not find the call to the Windows API. The last one I see is a call to GetConsoleScreenBufferInfo, afterwards it returns in an unusual way. Note that the Ansi part of the string gets printed correctly - it's just the cyrillic bit that misbehaves...
Output:
P.S.: I suspect it stopped working after I updated to FB 1.07. With version 1.05, print definitely displayed Russian correctly.
Code: Select all
The new codepage is 65001
FB: this is Russian: ���������� ��������������������
Crt: this is Russian: �"�����?�� �����������������'�O
WC: this is Russian: Добро пожаловать
Code: Select all
#include "Windows.bi"
#include "crt.bi"
SetConsoleOutputCP(65001) ' Utf8
Print "Print: Добро пожаловать"
Printf("Printf: Добро пожаловать")
Print
Dim As integer hOut=GetStdHandle(STD_OUTPUT_HANDLE)
WriteFile(hOut, @"WriteFile: Добро пожаловать", 42, 0, 0)
Print
WriteConsole(hOut, @"WriteConsole: Добро пожаловать", 45, 0, 0)
sleep
Code: Select all
Print: ���������� ��������������������
Printf: �"�����?�� �����������������'�O
WriteFile: Добро пожаловать
WriteConsole: Добро пожаловать
Re: changing code pages
My result
Code: Select all
Print: Добро пожаловать
Printf: ????? ??????????
W r i t e F i l e : >1@> ?>
W r i t e C o n s o l e : >1@> ?
Re: changing code pages
The source file must have a BOM header to allow literal unicode strings to be correctly parsed.
See: https://github.com/freebasic/fbc/tree/m ... es/unicode
See: https://github.com/freebasic/fbc/tree/m ... es/unicode
Re: changing code pages
@jj2007
With gas64 only WriteFile and WriteConsole displays the right string however the lenght should be respectively 44 et 47 otherwise the last character is lost. I counted effectively 2 more. eg for writeconsole 17 ascii + 15 x 2 unicodes.
Just curious, did you really get all the characters with 42 and 45 ?
With gas64 only WriteFile and WriteConsole displays the right string however the lenght should be respectively 44 et 47 otherwise the last character is lost. I counted effectively 2 more. eg for writeconsole 17 ascii + 15 x 2 unicodes.
Just curious, did you really get all the characters with 42 and 45 ?