#1 2012-07-05 10:05:49

laohw120
Member
Registered: 2012-07-05
Posts: 1

Problem in chinese words

As i want to convert the QuickReport to PDF and after reading this post: http://synopse.info/forum/viewtopic.php?id=138 and followed the steps, i found that it works great on the english words but the chinese words inside the report became garbled, so, is it the pdf engine doesn't support chinese words or i am missing something? Thank you!  Below is the code snippet i used to convert the report -

   pdf:=TPdfDocument.Create;
   try
       QRep.Prepare;
       for i:=1 to QRep.QRPrinter.PageCount do begin
           aMeta := QRep.QRPrinter.GetPage(i);
           try
               pdf.DefaultPageWidth := MulDiv(aMeta.Width, 72, pdf.ScreenLogPixels);
               pdf.DefaultPageHeight := MulDiv(aMeta.Height, 72, pdf.ScreenLogPixels);
               pdf.AddPage;
               pdf.Canvas.RenderMetaFile(aMeta,1,0,0);
           finally
               aMeta.Free;
           end;
       end;
       pdf.SaveToFile(fileName);
   finally
       pdf.Free;
   end; 

Offline

#2 2012-07-05 11:53:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,886
Website

Re: Problem in chinese words

As stated by the documentation, font fallback is not handled yet:

- the PDF engine don't handle Font Fallback yet: the font you use
must contain ALL glyphs necessary for the supplied unicode text - squares
or blanks will be drawn for any missing glyph/character 

This is a common issue with the current implementation.
If you search in the forum, you'll find out it is the case. See http://synopse.info/forum/viewtopic.php?id=530 and http://synopse.info/forum/viewtopic.php?id=309 and many other.

We should implement font fallback perhaps not with a TTF font or UniScribe (a very complex solution), but via built-in fonts of Acrobat Reader, i.e. the TPdfFontCIDFontType2 class.

  /// an embedded Composite CIDFontType2
  // - i.e. a CIDFont whose glyph descriptions are based on TrueType font technology
  // - typicaly handle Japan or Chinese standard fonts
  // - used with MBCS encoding, not WinAnsi
  TPdfFontCIDFontType2 = class(TPdfFont)
    { TODO: implement standard TPdfFontCIDFontType2 MBCS font }
  end;

So you did nothing wrong, it is just a current limitation of the unit.
Perhaps you may help fixing it?

Offline

#3 2012-07-10 09:42:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,886
Website

Re: Problem in chinese words

I've just added font fallback for:
- SynPDF unit (PDF file generation);
- SynGDIPlus unit (anti-aliased drawing).

Of course, both of these new features are handled by the SQlite3Pages unit, i.e. for report anti-aliased drawing preview and PDF generation.
By the way, the TGDIPages class handle now by default Unicode text, even with Delphi versions prior to 2009 (via the SynUnicode string type, which maps WideString before Delphi 2009, then UnicodeString starting with Delphi 2009).

See http://synopse.info/fossil/info/d51f063e76

This should fix your issue with Chinese characters.
They are now able to use a fallback font (by default, 'Arial Unicode MS') if some characters not included within the current font glyphs are encountered.

See http://blog.synopse.info/post/2012/07/1 … generation

Offline

#4 2013-05-15 07:38:28

Feng
Member
Registered: 2013-05-15
Posts: 28

Re: Problem in chinese words

Today, for the first time learning to use logging, found that the Chinese logging into a ? Symbol, Will need any special configuration?
Environment:
mORMot: 1.17
OS: Windows XP sp3
IDE : Delphi7

Last edited by Feng (2013-05-15 07:46:08)

Offline

#5 2013-05-15 08:11:23

Feng
Member
Registered: 2013-05-15
Posts: 28

Re: Problem in chinese words

Feng wrote:

Today, for the first time learning to use logging, found that the Chinese logging into a ? Symbol, Will need any special configuration?
Environment:
mORMot: 1.17
OS: Windows XP sp3
IDE : Delphi7

Download the latest version 1.18, the problem is still not resolved for help.

Offline

#6 2013-05-15 08:29:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,886
Website

Re: Problem in chinese words

Logs are created in UTF-8 format, but with no BOM prolog.

Offline

#7 2013-05-15 08:41:49

Feng
Member
Registered: 2013-05-15
Posts: 28

Re: Problem in chinese words

Eventually found the source of the problem:
The format of the log is written not in UTF-8 format, but the Logview open call UTF8ToString.

Offline

#8 2013-05-15 08:43:42

Feng
Member
Registered: 2013-05-15
Posts: 28

Re: Problem in chinese words

ab wrote:

Logs are created in UTF-8 format, but with no BOM prolog.

Indeed, this is the case.

Offline

#9 2013-05-15 08:47:54

Feng
Member
Registered: 2013-05-15
Posts: 28

Re: Problem in chinese words

Feng wrote:
ab wrote:

Logs are created in UTF-8 format, but with no BOM prolog.

Indeed, this is the case.

The feeling is not the lack of the BOM prolog.,Hexadecimal open the file to see the file is not Unicode-encoded.

Offline

#10 2013-05-15 10:00:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,886
Website

Re: Problem in chinese words

How do you write your Chinese content to the log?

Which version of Delphi are you using? (Unicode ready?)

Offline

#11 2013-05-16 00:39:31

Feng
Member
Registered: 2013-05-15
Posts: 28

Re: Problem in chinese words

ab wrote:

How do you write your Chinese content to the log?

Which version of Delphi are you using? (Unicode ready?)

I write this:
  with TSynLog.Family do
  begin
    Level := LOG_VERBOSE;
    OnArchive := EventArchiveSynLZ;
    ArchiveAfterDays := 1; // archive after one day
  end;
  TSynLog.Add.Log(sllInfo, '准备开始下载文件 ...');

My version of IDE is Delphi7(build 4.453)

Offline

#12 2013-05-16 08:03:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,886
Website

Re: Problem in chinese words

In Delphi 7, you have to explicitly encode your text constant as UTF-8.

E.g. with

TSynLog.Add.Log(sllInfo,StringToUTF8('准备开始下载文件 ...'));

Offline

#13 2013-05-16 15:49:39

Feng
Member
Registered: 2013-05-15
Posts: 28

Re: Problem in chinese words

Just because it is Delphi 7, does not support the unicode, right?

Offline

#14 2013-05-16 16:20:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,886
Website

Re: Problem in chinese words

In fact, Delphi 7 does not know that RawUTF8 is UTF-8 encoded... but Delphi 2009+ would be able to do the conversion to UTF-8 as expected.

So you can do this conversion via a StringToUTF8() call.
It will work for both Delphi 7 and Delphi 2009+.
And it will be faster than the default conversion code used in Delphi 2009+.

Our internal practice is to only log in English.
Some values can be in UTF-8/Unicode, but the log text is in English only, for coherency.
Of course, this is a matter of taste. But it explain why we did not make any specific handling of string here, since English text is the same in Delphi 7 after UTF-8 encoding.

Offline

Board footer

Powered by FluxBB