Recent

Author Topic: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)  (Read 2058 times)

-Caiman-

  • New Member
  • *
  • Posts: 10
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?
« Last Edit: January 02, 2019, 05:36:11 pm by -Caiman- »

jamie

  • Hero Member
  • *****
  • Posts: 3664
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #1 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
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 3079
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #2 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Bart

  • Hero Member
  • *****
  • Posts: 3943
    • Bart en Mariska's Webstek
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #3 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

-Caiman-

  • New Member
  • *
  • Posts: 10
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #4 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?

lucamar

  • Hero Member
  • *****
  • Posts: 3079
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #5 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Bart

  • Hero Member
  • *****
  • Posts: 3943
    • Bart en Mariska's Webstek
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #6 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

-Caiman-

  • New Member
  • *
  • Posts: 10
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #7 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?

-Caiman-

  • New Member
  • *
  • Posts: 10
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #8 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.

lucamar

  • Hero Member
  • *****
  • Posts: 3079
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #9 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Bart

  • Hero Member
  • *****
  • Posts: 3943
    • Bart en Mariska's Webstek
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #10 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

HeavyUser

  • Sr. Member
  • ****
  • Posts: 310
Re: Cannot display Greek numbers in console (Ε ε, Ζ ζ, Η η, Θ θ, etc.)
« Reply #11 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