Recent

Author Topic: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]  (Read 24385 times)

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #15 on: November 24, 2014, 10:35:17 pm »
I seriously doubt that showing Cyrillic, Latin and Greek characters at the same time in the Windows console is possible.
Try this

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #16 on: November 24, 2014, 10:42:09 pm »
http://screenshu.com/static/uploads/temporary/p2/c0/bn/oykwae.jpg
http://screenshu.com/static/uploads/temporary/zu/j3/r7/6oevg5.jpg

uses ....LConvEncoding'...
.....writeln(UTF8toCPxxx(yourtext));

The LConvEncoding uses doesn't work. Could you possibly make a simple program with the love heart symbol in?
You will have to dig codepage yourself to find one, containing the char you need.
LConvEncoding is probably a part of http://sourceforge.net/projects/lazarus-ccr/files/, so I suppose it has to be installed separately.
« Last Edit: November 24, 2014, 10:44:29 pm by paskal »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #17 on: November 24, 2014, 10:55:47 pm »
Afaik you need to:

1. use 2.7.1 and setdefaultcodepage to 65001 (UTF8 maybe available as symbolic constant CP_UTF8)
2. make sure the console only writes using -W functions. E.g. by writing a textdriver replacement.
3. Start the console with "cmd /u" with an appropriate unicode font set.
« Last Edit: November 24, 2014, 11:20:45 pm by marcov »

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #18 on: November 24, 2014, 11:03:54 pm »
I seriously doubt that showing Cyrillic, Latin and Greek characters at the same time in the Windows console is possible.
Try this

On your post it says change the console font, how do I change the font? What don't do I change it to? And why do I need to change the font? Sorry for all the questions

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #19 on: November 24, 2014, 11:11:36 pm »
I seriously doubt that showing Cyrillic, Latin and Greek characters at the same time in the Windows console is possible.
Try this

On your post it says change the console font, how do I change the font?
Not the font, but the codepage. It's midnight here, so I am done for today... or rather for yesterday. Maybe yopu should pay attention to *engkins proposal.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #20 on: November 24, 2014, 11:24:58 pm »
On your post it says change the console font, how do I change the font?
Use Alt+Space then choose properties - Font Tab.

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #21 on: November 24, 2014, 11:36:23 pm »
What font or code page do I change it to?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #22 on: November 24, 2014, 11:46:24 pm »
Courier New might be a good option if you have it.
Lots of websites offer instructions for changing the Windows console font, e.g.
http://www.techrepublic.com/blog/windows-and-office/quick-tip-add-fonts-to-the-command-prompt/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #23 on: November 24, 2014, 11:58:43 pm »
What font or code page do I change it to?
Unless you use the tip posted by howardpc, you have one other font available. Simply give it a try and see for yourself.

Code: [Select]
  PreviousValue := GetConsoleOutputCP;
  SetConsoleOutputCP(CP_UTF8);
  writeln('After calling SetConsoleOutputCP(CP_UTF8):');
  writeln('║ ☺ ☻ ☼ ♀ ♂ ♠ ♣ ♥ ♦ ♪ ♫ ║');
  SetConsoleOutputCP(PreviousValue);
« Last Edit: November 25, 2014, 12:06:42 am by engkin »

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #24 on: November 25, 2014, 10:15:32 am »
What font or code page do I change it to?
Unless you use the tip posted by howardpc, you have one other font available. Simply give it a try and see for yourself.

Code: [Select]
  PreviousValue := GetConsoleOutputCP;
  SetConsoleOutputCP(CP_UTF8);
  writeln('After calling SetConsoleOutputCP(CP_UTF8):');
  writeln('║ ☺ ☻ ☼ ♀ ♂ ♠ ♣ ♥ ♦ ♪ ♫ ║');
  SetConsoleOutputCP(PreviousValue);

ALT SPACE Doesn't change the text font. Where is the setting??

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #25 on: November 25, 2014, 10:28:39 am »
Try right-clicking on the console window title bar and choose Properties (or Default if you want to change all console windows). Then use the Font tab in the Console Windows Properties dialog.

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #26 on: November 25, 2014, 10:31:11 am »
Try right-clicking on the console window title bar and choose Properties (or Default if you want to change all console windows). Then use the Font tab in the Console Windows Properties dialog.

Nope, it still isn't working even with that other text font

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #27 on: November 25, 2014, 10:33:59 am »
What font or code page do I change it to?
Unless you use the tip posted by howardpc, you have one other font available. Simply give it a try and see for yourself.

Code: [Select]
  PreviousValue := GetConsoleOutputCP;
  SetConsoleOutputCP(CP_UTF8);
  writeln('After calling SetConsoleOutputCP(CP_UTF8):');
  writeln('║ ☺ ☻ ☼ ♀ ♂ ♠ ♣ ♥ ♦ ♪ ♫ ║');
  SetConsoleOutputCP(PreviousValue);
Even using that it still manages to not work... I used your code and everything

nobodyknowsme

  • Full Member
  • ***
  • Posts: 114
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #28 on: November 25, 2014, 10:49:37 am »
What font or code page do I change it to?
Unless you use the tip posted by howardpc, you have one other font available. Simply give it a try and see for yourself.

Code: [Select]
  PreviousValue := GetConsoleOutputCP;
  SetConsoleOutputCP(CP_UTF8);
  writeln('After calling SetConsoleOutputCP(CP_UTF8):');
  writeln('║ ☺ ☻ ☼ ♀ ♂ ♠ ♣ ♥ ♦ ♪ ♫ ║');
  SetConsoleOutputCP(PreviousValue);

You said there was one other type of font available. I have 3? What console text font are you using? Did you use howardpc's link to add a new text font??
« Last Edit: November 25, 2014, 10:51:49 am by nobodyknowsme »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: [HELP!!] - Pacal - Displaying Unicode [Showing UTF8 in console pascal]
« Reply #29 on: November 25, 2014, 07:36:08 pm »
Your pictures show that your console window is not using UTF8.
A call to SetConsoleOutputCP(CP_UTF8) should do that, if succeeded. Check that it does not return zero/false.

If it did fail, I'm not sure why. Maybe you need to check your:
Control Panel - Regional Settings - Advanced tab.
Notice that CP_UTF8 is 65001 and see the attached image.

Here is another test program that does not use any unit or define:
Code: [Select]
program project2;

{$mode objfpc}{$H+}
{$APPTYPE CONSOLE}

type
  UINT   = cardinal;
  WINBOOL = longbool;
  BOOL = WINBOOL;

var
  PreviousValue: UINT;
  i: integer;
  c: LongWord;
  Heart: String;

const
  CP_UTF8 = 65001;

  {$calling stdcall}
  function GetConsoleOutputCP:UINT; external 'kernel32' name 'GetConsoleOutputCP';
  function SetConsoleOutputCP(wCodePageID:UINT):WINBOOL; external 'kernel32' name 'SetConsoleOutputCP';
  function WriteFile(hFile: THandle; const Buffer; nNumberOfBytesToWrite: DWORD; var lpNumberOfBytesWritten: DWORD; lpOverlapped: pointer): BOOL; external 'kernel32' name 'WriteFile';

begin
  PreviousValue := GetConsoleOutputCP;
  if SetConsoleOutputCP(CP_UTF8) then
  begin
    Heart := '♥';
    if not WriteFile(StdOutputHandle,Heart[1],3,c,nil) then
      WriteLn('WriteFile Failed: Sorry, no hearts for you! ');
    SetConsoleOutputCP(PreviousValue);
  end
  else
    WriteLn('SetConsoleOutputCP Failed: Sorry, no hearts for you! ');
end.

Edit:
The font I'm using is Lucida Console.
« Last Edit: November 25, 2014, 07:42:05 pm by engkin »

 

TinyPortal © 2005-2018