#1 Re: PDF Engine » Chinese Font bold style does not work, when EmbeddedTTF is true » 2021-02-04 09:13:12

I used a terrible method to show bold fonts.

{SynPdf version 1.18}
procedure TPdfEnum.TextOut(var R: TEMRExtTextOut);
……
       if Canvas.FDoc.EmbeddedTTF then //如果需要嵌入字体
          with Canvas do
          begin
          if FContents<>nil then
            if isBold then
            begin
              begin
                FContents.Writer.Add('2 Tr'#10);
//                FContents.Writer.Add('0 g'#10);
                FContents.Writer.Add('0.5 w'#10);
              end;
            end else
              begin
                  FContents.Writer.Add('0 Tr'#10);
              end
          end;
        Canvas.ShowText(pointer(tmp));
      end;
    Canvas.EndText;
……

I found another problem.
The generated file cannot display the character of '∅' correctly, when I set font.name to 'Simsun'. I suspect the function named 'TPdfTTF.Create(aUnicodeTTF: TPdfFontTrueType)' can't get the Correct glyph accurately.

{SynPdf version 1.18}
{ TPdfTTF }

constructor TPdfTTF.Create(aUnicodeTTF: TPdfFontTrueType);
……
 for i := 0 to n-1 do begin
    idDeltai := idDelta[i];
    glyphi := idRangeOffset[i];
    if glyphi<>0 then
      glyphi := glyphi shr 1+i-n-startCode[i];
    for code := startCode[i] to endCode[i] do begin
      aUnicodeTTF.fUsedWideChar.Values[ndx] := code;
      if glyphi=0 then
        glyphIndex := code+idDeltai else begin
        glyphIndex := glyphIndexArray[glyphi+code];
        if glyphIndex<>0 then
          inc(glyphIndex,idDeltai);
      end;
      aUnicodeTTF.fUsedWide[ndx].Glyph := glyphIndex;
      inc(ndx);
    end;
  end;
……

#2 Re: PDF Engine » Chinese Font bold style does not work, when EmbeddedTTF is true » 2021-02-02 08:16:52

ab wrote:

I suspect it works on non-Chinese fonts, right?

Could you debug a little more, and try to find out why the main font, not the bold font is referred and embedded?

Yes, the bold style works on non-Chinese fonts. I heard that Song Ti(SimSun) does not have the original bold font, but I find this in the generated file :

……
6 0 obj
<</Type/Font/BaseFont/SimSun,Bold/Subtype/TrueType/Encoding/WinAnsiEncoding/FontDescriptor 7 0 R/Name/F0>>
endobj
7 0 obj
<</Type/FontDescriptor/FontName/SimSun,Bold/Ascent 859/CapHeight 666/Descent -141/ItalicAngle 0/StemV 105/StemH 45/FontWeight 700/Flags 262178/FontBBox[-8 -141 1000 859]/FontFile2 9 0 R>>
endobj
8 0 obj
<</Type/Font/BaseFont/SimSun,Bold/Subtype/Type0/Encoding/Identity-H/Name/F1/DescendantFonts[10 0 R]/ToUnicode 11 0 R>>
endobj
……

It seems that the bold style has been selected in the file, but the bold style does not take effect.
By the way, my computers don't have a font named 'SimSun,Bold'. Even so, if I don't embed the font, I can still see the bold style in the generated file.
I tracked the PrepareForSaving function, but this function uses the WinApi function to embed fonts. I have no way of knowing whether it has embedded bold formatting.

{synpdf.pas version 1.18; }
……
procedure TPdfFontTrueType.PrepareForSaving;
var
  ……
begin
      ……
           if CreateFontPackage(pointer(ttf),ttfSize,
                    SubSetData,SubSetMem,SubSetSize,
                    usFlags,ttcIndex,TTFMFP_SUBSET,0,
                    TTFCFP_MS_PLATFORMID,TTFCFP_UNICODE_CHAR_SET,
                    pointer(Used.Values),Used.Count,
                    @lpfnAllocate,@lpfnReAllocate,@lpfnFree,nil)=0 then begin
                  // subset was created successfully -> save to PDF file
                  SetString(ttf,SubSetData,SubSetSize);
                  FreeMem(SubSetData);
                end;
              end;
            end;
            fFontFile2.Writer.Add(ttf);
            fFontFile2.FAttributes.AddItem('Length1',length(ttf));
            // /FontDescriptor is common to WinAnsi and Unicode fonts
            fFontDescriptor.AddItem('FontFile2',fFontFile2);
    ……
end;

Thanks.

#3 Re: PDF Engine » Chinese Font bold style does not work, when EmbeddedTTF is true » 2021-02-02 07:03:27

Sorry, I can't see your photo, and the site is unavailable. Can you describe it in words? Thank you.(Please forgive me for reporting your post by mistake. I just want to reply to you, but the first time I use this forum and my English is not good.)

#4 PDF Engine » Chinese Font bold style does not work, when EmbeddedTTF is true » 2021-02-01 08:09:34

Alalaki
Replies: 6

Hello


As stated in the code, I set the font to bold, but it doesn't work. If I comment out the code "lPDF.EmbeddedTTF:= True;", it does work. But I do need to be bold. Here, I sincerely hope to get your help.

{ Delphi 2010;
synpdf version 1.18; }

procedure TForm1.Button3Click(Sender: TObject);
var
  lPdf: TPdfDocumentGDI;
begin
  lPdf := TPdfDocumentGDI.Create;
  try
    lPdf.ScreenLogPixels := 96;
    lPdf.DefaultPaperSize := TPDFPaperSize.psA4;
    lPDF.EmbeddedTTF := True;
    lPDF.AddPage;

    lPdf.VCLCanvas.Brush.Style := bsClear;
    lPdf.VCLCanvas.Font.Size := 32;
    lPdf.VCLCanvas.Font.Name := '宋体';
    //lPdf.VCLCanvas.TextOut(20, 60, '中文宋体');
    lPdf.VCLCanvas.Font.Style := [fsBold];
    lPdf.VCLCanvas.TextOut(20, 110, '中文宋体');

    lPdf.SaveToFile('C:\test\ttest.pdf');
  finally
    lPdf.Free;
  end;
end;

Thanks very much.

Board footer

Powered by FluxBB