Lazarus

Programming => LCL => Topic started by: -Caiman- on December 30, 2018, 04:20:02 pm

Title: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: -Caiman- on December 30, 2018, 04:20:02 pm
Code: Pascal  [Select][+][-]
  1. program greek;
  2.  
  3. uses LazUTF8;
  4.  
  5. var
  6. k: string;
  7.  
  8. begin
  9.  
  10. {
  11. Α α, Β β, Γ γ, Δ δ, Ε ε, Ζ ζ, Η η,
  12. Θ θ, Ι ι, Κ κ, Λ λ, Μ μ, Ν ν, Ξ ξ, Ο ο, Π π, Ρ ρ,
  13. Σ σ/ς, Τ τ, Υ υ, Φ φ, Χ χ, Ψ ψ, Ω ω.
  14. }
  15.  
  16. k:= AnsiToUtf8('ϟʹ ϟʹ ϟʹ ϟʹ ϟʹ ϟʹ ϟʹ ϟʹ') ;
  17. writeln(k);
  18. writeln(UTF8ToConsole('ξ π'));
  19. writeln(UTF8ToConsole(k));
  20. writeln(UTF8ToConsole('АаБбВвЫыЪъЭэГгЩщ'));
  21. writeln(UTF8ToConsole('Υ υ, Φ φ, Χ χ, Ψ ψ, Ω ω.'));
  22.  
  23. readln;
  24.  
  25. end.
  26.  
I tried to display greek numbers in console using LazUTF8 (+LCL package attached) but not working for me, even Rus letters are visible.
Could someone help pls?
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: jamie on December 30, 2018, 04:53:06 pm
lookup Code pages.
Example

 DefaultSystemCodePage := 1253 // Windows Greek

 850 for MS-DOS multilingual .

 Ect
 You also have other code page areas to set.

 DefaultUnicodePage := /////

 ect
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: lucamar on December 30, 2018, 05:02:40 pm
Are you sure your source is not UTF 8? If so, all those encoding conversions may be doing more harm than good.
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: Bart on December 30, 2018, 05:05:39 pm
Lazarus/fpc 3.0.4 won't output then correctly.
(The string is UTF8, the sourcode also, and contains a codepage utf8 directive)
writeln(s) nor writeln(utf8toconsole(s)) works (where s is the string with greek letters).

Bart
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: -Caiman- on December 30, 2018, 05:06:07 pm
Are you sure your source is not UTF 8? If so, all those encoding conversions may be doing more harm than good.
How can i check my source correctly?
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: lucamar on December 30, 2018, 05:09:29 pm
If you're using Lazarus and you didn't use any of the "change encoding" features then your source is UTF 8.
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: Bart on December 30, 2018, 05:10:23 pm
If you use Lazarus IDE: check file settings (codepage), if it says UTF8 and the source compiles, it is UTF8 (compiler will complaine if byte sequense is not valid UTF8).

Easier way: just copy the Greek text frome here (forum) fo Lazarus IDE.
It will be correct UTF8.

Bart
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: -Caiman- on December 30, 2018, 05:18:31 pm
So guys will it display those letters correctly somehow with LazUTF8 lib added? Otherwise which method should be used here?
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: -Caiman- on December 30, 2018, 05:26:02 pm
In general, did someone ever done similar program like Arabic, Roman, Greek numerals converter in pascal? Or at least smth with greek cuz i already have R to A and A to R.
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: lucamar on December 30, 2018, 05:43:09 pm
You shouldn't need LazUTF8, at least not for this. At most you may have to use SetConsoleCP or SetConsoleOutputCP if you're in Windows, although even that is debatable.
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: Bart on December 30, 2018, 05:44:40 pm
You can set the console codepage to UTF8.

From an old sample project (mostly not my code):
Code: Pascal  [Select][+][-]
  1. {$codepage utf8}
  2. uses
  3.   Windows;
  4.  
  5. Type
  6.   CONSOLE_FONT_INFOEX = record
  7.     cbSize      : ULONG;
  8.     nFont       : DWORD;
  9.     dwFontSizeX : SHORT;
  10.     dwFontSizeY : SHORT;
  11.     FontFamily  : UINT;
  12.     FontWeight  : UINT;
  13.     FaceName    : array [0..LF_FACESIZE-1] of WCHAR;
  14.   end;
  15.  
  16. function SetCurrentConsoleFontEx(hConsoleOutput: HANDLE; bMaximumWindow: BOOL;
  17.     var CONSOLE_FONT_INFOEX): BOOL; stdcall; external 'kernel32.dll' name 'SetCurrentConsoleFontEx';
  18.  
  19. var
  20.   New_CONSOLE_FONT_INFOEX : CONSOLE_FONT_INFOEX;
  21.   S: String;
  22.  
  23. begin
  24.   //writeln('SetDefaultCodepages unit initialization: DefaultSystemCodePage = ',DefaultSystemCodePage);
  25.   DefaultSystemCodepage := CP_UTF8;
  26.   SetConsoleOutputCP(cp_utf8);
  27.   SetTextCodepage(Output, cp_utf8);
  28.  
  29.   FillChar(New_CONSOLE_FONT_INFOEX, SizeOf(CONSOLE_FONT_INFOEX), 0);
  30.   New_CONSOLE_FONT_INFOEX.cbSize := SizeOf(CONSOLE_FONT_INFOEX);
  31. //  New_CONSOLE_FONT_INFOEX.FaceName := 'Lucida Console';
  32.   New_CONSOLE_FONT_INFOEX.FaceName := 'Consolas';
  33.   New_CONSOLE_FONT_INFOEX.dwFontSizeX := 8;
  34.   New_CONSOLE_FONT_INFOEX.dwFontSizeY := 16;
  35.  
  36.   SetCurrentConsoleFontEx(StdOutputHandle, False, New_CONSOLE_FONT_INFOEX);
  37.  
  38.  
  39.   S :=  'Α α, Β β, Γ γ, Δ δ, Ε ε, Ζ ζ, Η η,Θ θ, Ι ι, Κ κ, Λ λ, Μ μ, Ν ν, Ξ ξ, Ο ο, Π π, Ρ ρ,Σ σ/ς, Τ τ, Υ υ, Φ φ, Χ χ, Ψ ψ, Ω ω.';
  40.   writeln(S);
  41. end.

Outputs:
Code: [Select]
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
Α α, Β β, Γ γ, Δ δ, Ε ε, Ζ ζ, Η η,Θ θ, Ι ι, Κ κ, Λ λ, Μ μ, Ν ν, Ξ ξ, Ο ο, Π π, Ρ ρ,Σ σ/ς, Τ τ, Υ υ, Φ φ, Χ χ, Ψ ψ, Ω ω.

Bart
Title: Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
Post by: HeavyUser on December 30, 2018, 05:45:56 pm
So guys will it display those letters correctly somehow with LazUTF8 lib added? Otherwise which method should be used here?
no it will not. the problem is that the codepage that your console is using does not support the greek characters no matter how many conversion you add if the characters are not present in the codepage table they will never show on screen correctly. So the two questions you should be asking are
1) what is the codepage of your console? on windows use the functions https://docs.microsoft.com/en-us/windows/console/getconsolecp and https://docs.microsoft.com/en-us/windows/console/getconsoleoutputcp to find out.
2) how do you change the console's codepage to either utf8 or any other unicode encoding that  supports all the characters you need.

Everything else is pointless.
TinyPortal © 2005-2018