[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1421
  • Last Modified:

Printing unicode Chinese from Delphi 7 app

I'm writing an app that reads unicode text files in Chinese and prints them out.

If I look at the files in HexEdit they all start FF FE followed by pairs of hex for each character ... so far, so good!

I can only find one Chinese charset in D7. (I thought there might be one called UNICODE that allowed me to send WideStrings!!!) So if I choose CHINESEBIG5_CHARSET, load a non-wide string s with a pair of hex, then send it to print, it does indeed print one Chinese character but not the right one.

  Printer.BeginDoc;
  s := #174 + #118;         // a Chinese unicode character
  Printer.Canvas.Font.Charset := CHINESEBIG5_CHARSET;
  Printer.Canvas.TextOut(100,  100, s);
  Printer.EndDoc;

The total project is now more than a million lines long so I don't really have the option to upgrade to a more recent version of Delphi without a fair bit of hassle.
0
ChrisJonesLycos
Asked:
ChrisJonesLycos
  • 2
  • 2
1 Solution
 
ebob42Commented:
If you are unable to migrate to Delphi 2009 or 2010 for true Unicode support, you may want to search for TNT controls (now part of TMS) for some controls with Unicode support. As for printing: the CHINESEBIGS_CHARSET uses simplified chinese, and is not suited for printing Unicode Chinese characters. The codepoints will not correspond to anything useful (as you noticed).

Why would 1 million lines of code keep you from moving to Delphi 2010? (I'm not joking - I've migrated projects with more lines of code, and only a small portion of the code may give you some Unicode migration issues - it may be simpler than you think).
0
 
ChrisJonesLycosAuthor Commented:
Actually I've just come across this in Google which does seem to work regardless of what charset you use:

  Printer.BeginDoc;
  s := #174 + #118;
  Printer.Canvas.Font.Charset := 1;          //CHINESEBIG5_CHARSET;
  Windows.TextOutW(Printer.Canvas.Handle, 100, 100, PWideChar(s), length(s));
  Printer.EndDoc;

I haven't tested it in live situations to know how well it will work but it DOES give the right characters.

BTW I wouldn't mind doing the migration if every problem appeared in the compile. I just remember earlier migrations (we actually started with D1 -> D2 ->D4 -> D7) and had some fairly horrific problems AFTER we had upgraded 300 customers. D2010 would have to give some massive advantage to make the risk worthwhile.


0
 
ebob42Commented:
That technique will work - using the "W" API of Windows. But Delphi 7 itself can only work with Unicode if you load it into WideStrings, and you will have a problem showing this content on screen (unless you look for the aforementioned TNT controls for example)...
0
 
ChrisJonesLycosAuthor Commented:
The documents only need to be printed, not displayed on screen. There's a chance we'll need to display at some later stage in the project (next year) so the info on the TNT controls is very useful thanks.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now