#1 2014-09-18 08:38:43

MDW
Member
Registered: 2014-09-18
Posts: 3

Problem embedding Chinese font

System: Windows 7
Delphi Version: 2010
SynPDF Version: 1.18

When creating PDF documents containing "SimSun" font (SimSun.ttc) or "MingLiu" font (MingLiu.ttc), a very large file is generated and the font appears to be incorrectly embedded and cannot be displayed by Adobe Reader. The sample code below generates a file containing one common Chinese character.

Having tested several fonts with the sample code, fonts contained in ".ttc" files all generated large files with display problems. Other fonts were fine. This issue could be related to http://synopse.info/forum/viewtopic.php?id=1528.

Resulting file sizes in my test were:
Fonts with problem:
MingLiu: 16.2MB
SimSun: 7.6MB

Fonts without problem:
KaiTi: 55KB
Microsoft YaHei: 17KB

procedure CreatePDFDoc();
var
  PDFDoc: TPDFDocumentGDI;
begin
  PDFDoc := TPdfDocumentGDI.Create;
  try
    PDFDoc.NewDoc;
    PDFDoc.AddPage;
    PDFDoc.EmbeddedTTF := True;
    PDFDoc.VCLCanvas.Font.Name := 'SimSun';
    PDFDoc.VCLCanvas.TextOut(100,100,#22909);
    PDFDoc.SaveToFile('PDFDoc_' + PDFDoc.VCLCanvas.Font.Name + '.pdf');
  finally
    PDFDoc.Free;
  end;
end;

Thanks for any help that can be given.

Offline

#2 2014-09-18 10:45:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,224
Website

Re: Problem embedding Chinese font

Could you use the debugger and find out what is the problem when embedding the font?

Also ensure you got the latest version of SynPDF from http://synopse.info/files/mORMotNightlyBuild.zip or https://github.com/synopse/SynPDF

Online

#3 2014-09-20 10:00:23

MDW
Member
Registered: 2014-09-18
Posts: 3

Re: Problem embedding Chinese font

The problem appears to be the call "CreateFontPackage" on line 7608 of SynPDF.pas (nightly build 19-Sep-2014). It does not correctly deal with fonts within ".ttc" rather than ".ttf" files.

For fonts within ".ttc" files:

  • The 6th parameter, "usFlags", needs to include the flag TTFCFP_FLAGS_TTC.

  • The 7th parameter, "usTTCIndex", needs to include the index of the font within the ttc collection

It appears that some additional code will be required to identify (1) whether a font is contained in a TTC collection and (2) if so, what is its index position.

Offline

#4 2014-09-20 13:46:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,224
Website

Re: Problem embedding Chinese font

Could you please create a ticket, and link to this forum thread?

Thanks a lot!
smile

Online

#5 2014-09-22 09:08:07

MDW
Member
Registered: 2014-09-18
Posts: 3

Re: Problem embedding Chinese font

Thanks. I have raised a ticket.

Offline

#6 2014-09-23 16:04:50

RenatoL
Member
Registered: 2014-09-19
Posts: 1

Re: Problem embedding Chinese font

I have the same problem with Cambria Windows font who is also TrueType Collection (TTC)

Offline

#7 2014-10-06 19:55:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,224
Website

Re: Problem embedding Chinese font

You can try http://synopse.info/fossil/info/d87f982164

Thanks a lot David Mead (MDW) for the patch !

Online

Board footer

Powered by FluxBB