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.
ChrisJonesLycosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.