#2 Re: PDF Engine » Problem embedding Chinese font » 2014-09-20 10:00:23

MDW

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.

#3 PDF Engine » Problem embedding Chinese font » 2014-09-18 08:38:43

MDW
Replies: 6

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.

Board footer

Powered by FluxBB