#1 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2020-03-07 02:14:35

yes, my windows is Simplified Chinese, code page(936) and GBK for ANSI API,so I use MultiByteToWideChar modified it to
TSynAnsiFixedWidth.Create
...
  SetLength(fWideToAnsi, 65536);
  for i := 1 to 126 do
    fWideToAnsi[ii] := i;

  FillcharFast(fWideToAnsi[127], 65536 - 127, ord('?')); // '?' for unknown char
  GetMem(vPWideChar, SizeOf(WideChar));
  try
    for i := 127 to 255 do
      if (fAnsiToWide[ii] <> 0) and (fAnsiToWide[ii] <> ord('?')) then
      begin
        vLen := MultiByteToWideChar(DefaultSystemCodePage, 0, @AnsiChar(i), 1, nil, 0);
        if vLen > 0 then
        begin
          vLen := MultiByteToWideChar(DefaultSystemCodePage, 0, @AnsiChar(i), 1, vPWideChar, vLen);

          fWideToAnsi[fAnsiToWide[ii]] := Ord(vPWideChar^);
        end;
      end;
  finally
    FreeMem(vPWideChar);
  end;

  // fixed width Ansi will never be bigger than UTF-8
  fAnsiCharShift := 0;

Is this the most appropriate way to modify it?

#2 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2020-03-06 15:51:09

sorry,I did not notice WinAnsi #147 is not “  (Unicode #8220) in chinese font,
i test in Delphi7(because it's use ANSI) and Delphi2010(unicode),i set edit1's font name 宋体(a chinese font alias simsun)
Delphi7
edit1.Text := Char(#147);  i get empty
edit1.Text := Char(#34); i get "
Delphi2010
edit1.Text := Char(#147);  i get ?
edit1.Text := Char(#34); i get "
edit1.Text := Char(#8220); i get “
I haven't found the cause of this phenomenon yet

#3 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2020-03-06 15:23:34

WinAnsi #147 is "
Unicode #8220 is “
“ should not be equal to ", but becomes equal by fWideToAnsi[fAnsiToWide[ii]] := i where i = 147

#4 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2020-03-06 14:56:21

because “ and " are different in unicode,“ unicode is #8220, " ansi is 147
TSynAnsiFixedWidth.Create
for i := 127 to 255 do
    if (fAnsiToWide[ii]<>0) and (fAnsiToWide[ii]<>ord('?')) then
      fWideToAnsi[fAnsiToWide[ii]] := i;  // i = 147, fAnsiToWide[147] = 8220, fWideToAnsi[8220] = 147, ”="

“ and " are different in unicode, In the same font, “ is wider than ",So it should not be the same

#5 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2020-03-06 03:11:21

the problem of chinese symbols(E.g “ unicode #8220) is:
TSynAnsiFixedWidth.Create
  for i := 127 to 255 do
    if (fAnsiToWide[ii]<>0) and (fAnsiToWide[ii]<>ord('?')) then
      fWideToAnsi[fAnsiToWide[ii]] := i;
     // fAnsiToWide[147] = 8220, fWideToAnsi[8220] = 147, witch “(chinese symbol) becomes "(english symbol),but ” and " display widths are different,causes display problems after generating pdf,so i remove three lines
The above are the problems and solutions I found, which may be inaccurate. If there is a better way, you can notify me, thank you, thank you synpdf.

#6 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2020-03-06 02:52:33

I found the cause of the problem(i'm poor english),the reason for the font style failure is:
in function TPdfDocument.TTFFontPostcriptName

Result := TrueTypeFontName(aFontName,AStyle);  // get font name and style

// if chinese font (CJK font?)
Rec := @name^.FirstNameRecord;
  for i := 0 to name^.count-1 do
    if (Rec^.nameID=NAME_POSTCRIPT) and (Rec^.platformID=TTFCFP_MS_PLATFORMID)
        and (Rec^.encodingID=1) and (Rec^.languageID=$409) then
    begin
      ...
      SetLength(Result,L);  // here,L is font name length,lost above style
      // so i add rejudging style after to solve this problem
      if pfsItalic in AStyle then
        if pfsBold in AStyle then
          Result := Result + ',BoldItalic'
        else
          Result := Result + ',Italic'
      else
      if pfsBold in AStyle then
        Result := Result + ',Bold';

#7 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2018-08-10 08:39:53

@5c4f394a,Thank you, I've tried your code, the symbol is correct, but the font is not SimSun
abcjingtong_2018810162344.png

#8 Re: PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2018-08-08 14:15:52

thanks,I tried it, but the problem still exists.

var
  lPdf: TPdfDocumentGDI;
begin
  lPdf := TPdfDocumentGDI.Create;
  try
    lPdf.UseUniscribe := True;  // 
    lPdf.ScreenLogPixels := 96;
    lPdf.DefaultPaperSize := TPDFPaperSize.psA4;
    lPDF.AddPage;

    lPdf.VCLCanvas.Brush.Style := bsClear;
    lPdf.VCLCanvas.Font.Name := '宋体';  // 注释掉正常
    lPdf.VCLCanvas.TextOut(20, 20, '发现双引号不正确“问题”');

    lPdf.SaveToFile('c:\Syntest.pdf');
  finally
    lPdf.Free;
  end;

#9 PDF Engine » Chinese symbols and fonts are incorrectly displayed » 2018-08-08 01:53:33

18114532@qq.com
Replies: 15

I used SynPdf to create my document in PDF format, but found that the Chinese symbol output was incorrect。

var
  lPdf: TPdfDocumentGDI;
begin
  lPdf := TPdfDocumentGDI.Create;
  try
    lPdf.ScreenLogPixels := 96;
    lPdf.DefaultPaperSize := TPDFPaperSize.psA4;
    lPDF.AddPage;

    lPdf.VCLCanvas.Brush.Style := bsClear;
    lPdf.VCLCanvas.Font.Name := '宋体';  // 注释掉正常
    lPdf.VCLCanvas.TextOut(20, 20, '发现双引号不正确“问题”');

    lPdf.SaveToFile('c:\Syntest.pdf');
  finally
    lPdf.Free;
  end;
end;

Chinese symbols

Board footer

Powered by FluxBB