Recent

Author Topic: Console in/output utf in lazarus 2.0.0  (Read 4121 times)

benohb

  • Full Member
  • ***
  • Posts: 213
Console in/output utf in lazarus 2.0.0
« on: February 15, 2019, 12:10:06 am »
linux 64 gtk laz 2.0.0

I have tried
Code: Pascal  [Select][+][-]
  1. Writeln('لازاروس');

The result
Code: Pascal  [Select][+][-]
  1. ??????????????

I change output style to hex
Code: Pascal  [Select][+][-]
  1. d9 84 d8 a7 d8 b2 d8 a7 d8 b1 d9 88 d8 b3

So .. its utf8 ..
Does it Console in/output  support UTF  ???  and how back to old behavior

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Console in/output utf in lazarus 2.0.0
« Reply #1 on: February 15, 2019, 12:03:09 pm »
Your console font must support outputting those characters as well.

I got this unit from a discussion on the forum here:

Code: Pascal  [Select][+][-]
  1. unit setdefaultcodepages;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows;
  7.  
  8. implementation
  9.  
  10. Const
  11.   LF_FACESIZE = 32;
  12.  
  13. Type
  14.   CONSOLE_FONT_INFOEX = record
  15.     cbSize      : ULONG;
  16.     nFont       : DWORD;
  17.     dwFontSizeX : SHORT;
  18.     dwFontSizeY : SHORT;
  19.     FontFamily  : UINT;
  20.     FontWeight  : UINT;
  21.     FaceName    : array [0..LF_FACESIZE-1] of WCHAR;
  22.   end;
  23.  
  24. { Only supported in Vista and onwards!}
  25.  
  26. function SetCurrentConsoleFontEx(hConsoleOutput: HANDLE; bMaximumWindow: BOOL; var CONSOLE_FONT_INFOEX): BOOL; stdcall; external 'kernel32.dll' name 'SetCurrentConsoleFontEx';
  27. var
  28.   New_CONSOLE_FONT_INFOEX : CONSOLE_FONT_INFOEX;
  29.  
  30. initialization
  31.   writeln('SetDefaultCodepages unit initialization: DefaultSystemCodePage = ',DefaultSystemCodePage);
  32.   {$ifdef DisableUTF8RTL}
  33.   SetConsoleOutputCP(DefaultSystemCodePage);
  34.   SetTextCodepage(Output, DefaultSystemCodePage);
  35.   {$else}
  36.   SetConsoleOutputCP(cp_utf8);
  37.   SetTextCodepage(Output, cp_utf8);
  38.   {$endif}
  39.  
  40.   FillChar(New_CONSOLE_FONT_INFOEX, SizeOf(CONSOLE_FONT_INFOEX), 0);
  41.   New_CONSOLE_FONT_INFOEX.cbSize := SizeOf(CONSOLE_FONT_INFOEX);
  42. //  New_CONSOLE_FONT_INFOEX.FaceName := 'Lucida Console';
  43.   New_CONSOLE_FONT_INFOEX.FaceName := 'Consolas';
  44.   New_CONSOLE_FONT_INFOEX.dwFontSizeX := 8;
  45.   New_CONSOLE_FONT_INFOEX.dwFontSizeY := 16;
  46.  
  47.   SetCurrentConsoleFontEx(StdOutputHandle, False, New_CONSOLE_FONT_INFOEX);
  48. end.

IIRC that does the trick.

Bart


Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Console in/output utf in lazarus 2.0.0
« Reply #2 on: February 15, 2019, 12:43:31 pm »
Bart, that's windows centric and not Linux....

Note the code from the question  works in my RPi terminal.
Specialize a type, not a var.

benohb

  • Full Member
  • ***
  • Posts: 213
Re: Console in/output utf in lazarus 2.0.0
« Reply #3 on: February 16, 2019, 12:55:07 am »

@Bart It is linux

http://wiki.freepascal.org/Lazarus_with_FPC3.0_without_UTF-8_mode#Problem_System_encoding_and_Console_encoding_.28Windows.29

Code: Pascal  [Select][+][-]
  1. Console output codepage: 0
  2. System codepage: 65001
  3. ????????


SetTextCodePage(Output, 65001);



Code: Pascal  [Select][+][-]
  1. Console output codepage: 65001
  2. System codepage: 65001
  3. ????????
  4.  


Nothing has changed
Also I can not use the debugger with the external xtrem ..  There is also a problem
« Last Edit: February 16, 2019, 12:56:50 am by benohb »

benohb

  • Full Member
  • ***
  • Posts: 213
Re: Console in/output utf in lazarus 2.0.0
« Reply #4 on: February 16, 2019, 01:58:22 am »
Solved in svn .. I wish to update the Linux stable package :D :D

Mr. George

  • New Member
  • *
  • Posts: 21
Re: Console in/output utf in lazarus 2.0.0
« Reply #5 on: June 04, 2021, 12:09:19 am »
How you did solved this issue?

 

TinyPortal © 2005-2018