Fastreport3.14的中文PDF输出

2008-04-09 04:21:03来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

参考 《让Fastreport3.x支持中文PDF的输出》一文,确实可以支持中文。但是发现两个问题:

1、只能在Adobe Reader下打开,在Foxit Reader下空白。

2、用Adobe Acrobat或者Adobe Reader打开时提示rebuild,关闭时提示save

研究了一下Fastreport3.14和3.07的源代码,发现关于字体这部分重新调整了。在3.07下,每个type0的字体有三个obj表示,而在3.14下只用两个obj(把FontDescriptor放进实际字体中去了)。3.14中源代码中有个小bug,漏掉了实际字体obj的ref(原frxPDFfile.pas的985行和986行之间)。Foxit Reader应该是严格按照ref去找obj的,找不到obj,所以显示不出来。Adobe Reader应该不是按ref找的,能够正常显示汉字,但是它会重新ref,所以提示rebuild。

修改后的TfrxPDFFont.SaveToStream替换原来的即可。

镶入字体还不行。有时间再说。3.15的说明中有说增强了PDF导出的功能,期待中。

procedure TfrxPDFFont.SaveToStream(Stream: TStream);
var
s: string;
b: TBitmap;
pm: ^OUTLINETEXTMETRIC;
FontName: string;
i: Cardinal;
pfont: PChar;
FirstChar, LastChar: Integer;
MemStream: TMemoryStream;
MemStream1: TMemoryStream;
pwidths: PABC;
Charset: TFontCharSet;

// support DBCS font name encoding
function EncodeFontName(AFontName: string): string;
var
s: string;
Index, Len: Integer;
begin
// Add Begin by ijia 2004.12.20
// 修正在简体系统下繁体字体名的问题
// 只提供 MingLiU, PMingLiU --> 细明体, 新细明体的修正
s:=UpperCase(AFontName);
if Copy(s, 1, 7)=''''MINGLIU'''' then
AFontName:=''''细明体'''';

if Copy(s, 1, 8)=''''PMINGLIU'''' then
AFontName:=''''新细明体'''';
// Add end
s := '''''''';
Len := Length(AFontName);
Index := 0;
while Index < Len do
begin
Index := Index 1;
if Byte(AFontName[Index]) > $7F then
s := s ''''#'''' IntToHex(Byte(AFontName[Index]), 2)
else
s := s AFontname[Index];
end;
Result := s;
end;

begin
inherited SaveToStream(Stream);
b := TBitmap.Create;
b.Canvas.Font.Assign(Font);
b.Canvas.Font.PixelsPerInch := 96;
b.Canvas.Font.Size := 750;
i := GetOutlineTextMetrics(b.Canvas.Handle, 0, nil);
GetMem(pm, i);
try
try
GetOutlineTextMetrics(b.Canvas.Handle, i, pm);
FirstChar := Ord(pm.otmTextMetrics.tmFirstChar);
LastChar := Ord(pm.otmTextMetrics.tmLastChar);
FontName := StringReplace(Font.Name, '''' '''', ''''#20'''', [rfReplaceAll]);
s := '''''''';
if fsBold in Font.Style then
s := s ''''Bold'''';
if fsItalic in Font.Style then
s := s ''''Italic'''';
if s <> '''''''' then
FontName := FontName '''','''' s;

Charset := pm.otmTextMetrics.tmCharSet;
FontName := EncodeFontName(FontName);

Parent.XRefAdd(Stream);
WriteLn(Stream, IntToStr(Index Parent.FStartFonts) '''' 0 obj'''');
WriteLn(Stream, ''''<<'''');
WriteLn(Stream, ''''/Type /Font'''');
WriteLn(Stream, ''''/Name /F'''' IntToStr(Index - 1));
WriteLn(Stream, ''''/BaseFont /'''' FontName);

// Add by ijia 2004.12.20
//if Charset <> CHINESEBIG5_CHARSET then
if not (Charset in [CHINESEBIG5_CHARSET, GB2312_CHARSET]) then
WriteLn(Stream, ''''/Subtype /TrueType'''')
else
WriteLn(Stream, ''''/Subtype /Type0'''');

case Charset of
SYMBOL_CHARSET, ANSI_CHARSET:
WriteLn(Stream, ''''/Encoding /WinAnsiEncoding'''');

RUSSIAN_CHARSET: {1251}
begin
WriteLn(Stream, ''''/Encoding <</Type/Encoding /BaseEncoding /WinAnsiEncoding'''');
Write(Stream, ''''/Differences [129 /afii10052'''');
Write(Stream, ''''/quotesinglbase/afii10100/quotedblbase/ellipsis/dagger/daggerdbl/Euro/perthousand/afii10058/guilsinglleft/afii10059/afii10061/afii10060/afii10145/afii10099/quoteleft'''');
Write(Stream, ''''/quoteright/quotedblleft/quotedblright/bullet/endash/emdash/space/trademark/afii10106/guilsinglright/afii10107/afii10109/afii10108/afii10193/space/afii10062'''');
Write(Stream, ''''/afii10110/afii10057/currency/afii10050/brokenbar/section/afii10023/copyright/afii10053/guillemotleft/logicalnot/hyphen/registered/afii10056/degree/plusminus'''');
Write(Stream, ''''/afii10055/afii10103/afii10098/mu/paragraph/periodcentered/afii10071/afii61352/afii10101/guillemotright/afii10105/afii10054/afii10102/afii10104/afii10017/afii10018'''');
Write(Stream, ''''/afii10019/afii10020/afii10021/afii10022/afii10024/afii10025/afii10026/afii10027/afii10028/afii10029/afii10030/afii10031/afii10032/afii10033/afii10034/afii10035'''');
Write(Stream, ''''/afii10036/afii10037/afii10038/afii10039/afii10040/afii10041/afii10042/afii10043/afii10044/afii10045/afii10046/afii10047/afii10048/afii10049/afii10065/afii10066'''');

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:[函数]procedure SortDBGridEh(Sender: TObject; ACol: Integer;

下一篇:Delphi 中把文本文件装入资源文件中