RAVE导出中文乱码解决方法修改代码{********************************************************** ***************}
{ Rave Reports version 5.1 }
{ Copyright (c), 1995-2002, Nevrona Designs, all rights reserved } {********************************************************** ***************}
unit RpRende...
{********************************************************** ***************}
{ Rave Reports version 5.1 }
{ Copyright (c), 1995-2002, Nevrona Designs, all rights reserved } {********************************************************** ***************}
unit RpRenderPDF;
function TRvRenderPDF.IsCJKFont: boolean;
begin
case ConvertCharset((Converter.Font.Charset)) of
Windows.SHIFTJIS_CHARSET, // Japan
Windows.HANGEUL_CHARSET, // Korea
Windows.GB2312_CHARSET, // Simplified Chinese (People's Rep ublic of China)
Windows.CHINESEBIG5_CHARSET, // Traditional Chinese (Taiwan) Windows.JOHAB_CHARSET:
begin
Result := true;
end
else
begin
Result := false;
end
end; { case }
end;
procedure TRPPDFFontDescendant.InitData;
//!!!CJK
procedure PrintWidths;
var
i1: integer;
begin
RvRenderPDF.PrintLn('/W [');
if Descriptor.Panose.bProportion = PAN_PROP_MONOSPACED then
begin
if CharSet = SHIFTJIS_CHARSET {Japanese} then
begin
RvRenderPDF.PrintLnF('%d [', [231]);
end
else if CharSet = HANGEUL_CHARSET {Korea} then
begin
RvRenderPDF.PrintLnF('%d [', [8094]);
end
else if CharSet = CHINESEBIG5_CHARSET {Traditional Chinese (Taiw an)} then
begin
RvRenderPDF.PrintLnF('%d [', [13648]);
end
else
begin //SCYANGYU
RvRenderPDF.PrintLnF('%d [', [814]); //Simplified Chinese (People' s Republic of China)
end;
end
else
begin
RvRenderPDF.PrintLnF('%d [', [1]);
end; { else }
i1 := 32;
while i1 <= 126 do begin
RvRenderPDF.Print(IntToStr(FontWidths[i1]) + ' ');
if i1 mod 10 = 9 then begin
RvRenderPDF.PrintLn;
end;
Inc(i1);
end; // while
RvRenderPDF.PrintLn(']');
RvRenderPDF.PrintLn(']');
end;
begin { InitData }
RvRenderPDF.ActiveStream := DataStream;
RvRenderPDF.PrintLnF('%d 0 obj',[GetID]);
RvRenderPDF.PrintLn('<<');
RvRenderPDF.PrintLn('/Type /Font');
RvRenderPDF.PrintLn('/Subtype /CIDFontType2');
RvRenderPDF.PrintLnF('/BaseFont /%s',[PDFFontName]);
RvRenderPDF.PrintLnF('/FontDescriptor %d 0 R',[Descriptor.GetID]);
RvRenderPDF.PrintLnF('/WinCharSet /%d',[CharSet]);//!!!CJK
RvRenderPDF.PrintLnF('/CIDSystemInfo << /Registry (%s)/Ordering (% s)/Supplement %d >>', [Registry, Ordering, Supplement]);
RvRenderPDF.PrintLnF('/DW %d',[MaxCharWidth]);
PrintWidths;
RvRenderPDF.PrintLn('>>');
RvRenderPDF.PrintLn('endobj');
RvRenderPDF.PrintLn;
RvRenderPDF.ActiveStream.Position := 0;
end; { InitData }
procedure TRPPDFFontComposite.SetFontData;
type
TABCArray = array[0..255] of TABC;
var
OutlineTextMetric: POutlineTextMetric;
Panose: TPanose;
nSize: longint;
lpABC: TABCArray;
procedure SetWidths;
var
i1: integer;
begin
i1 := 0;
while i1 < LastChar - FirstChar + 1 do begin
FontWidths[i1 + FirstChar] := lpABC[i1].abcA + word(lpABC[i1].abcB) + lpABC[i1].abcC;
Inc(i1);
end; // while
end;
begin
if RvRenderPDF.IsCJKFont then
begin
with RvRenderPDF.FontBitmap.Canvas do
begin
Font.Name := FontName;
Font.Style := FontStyles;
Font.Charset := FontCharset;
end; { with }
nSize := GetOutlineTextMetrics((RvRenderPDF.FontBitmap.Canvas.Han dle),
sizeof(OutlineTextMetric),
nil);
GetMem(OutlineTextMetric, nSize);
try
if GetOutlineTextMetrics((RvRenderPDF.FontBitmap.Canvas.Handle), nSize,
OutlineTextMetric) > 0 then
begin
Panose := OutlineTextMetric.otmPanoseNumber;
if Panose.bProportion = PAN_PROP_MONOSPACED then
begin
if FontCharSet = SHIFTJIS_CHARSET then // Japan
begin
CompositeFontEncoding := '90ms-RKSJ-H';
end
else if FontCharSet = HANGEUL_CHARSET then // Korea
begin
CompositeFontEncoding := 'KSCms-UHC-HW-H';
end
else if FontCharSet = CHINESEBIG5_CHARSET then // Traditional Chinese (Taiwan)
begin
CompositeFontEncoding := 'ETenms-B5-H';
end
else
Begin //SCYANGYU
CompositeFontEncoding := 'GBK-EUC-H'; //cc_simplified_chin ese
End;{ else }
end
else
begin
if FontCharSet = SHIFTJIS_CHARSET then // Japan
begin
CompositeFontEncoding := '90msp-RKSJ-H';
end
else if FontCharSet = HANGEUL_CHARSET then // Korea
begin
CompositeFontEncoding := 'KSCms-UHC-H';
end
else if FontCharSet =CHINESEBIG5_CHARSET then // Traditional C hinese (Taiwan)
begin
CompositeFontEncoding := 'CNS-EUC-H';
end
else
begin //SCYANGYU
CompositeFontEncoding := 'GBpc-EUC-H'; //cc_simplified_chi nese
end; { else }
end; { else }
Descriptor.PDFFontName := PDFFontName;
Descriptor.Set value s(OutlineTextMetric, FontWidths[32]);
Descendant.PDFFontName := PDFFontName;
Descendant.Descriptor := Descriptor;
Descendant.Registry := 'Adobe';
if FontCharSet = SHIFTJIS_CHARSET then // Japan
begin
Descendant.Ordering := 'Japan1';
end
else if FontCharSet = HANGEUL_CHARSET then // Korea
begin
Descendant.Ordering := 'Korea1';
end
else if FontCharSet = CHINESEBIG5_CHARSET then // Traditional Chinese (Taiwan)
begin
Descendant.Ordering := 'CNS1';
end
else
begin //SCYANGYU
Descendant.Ordering := 'GB1'; // cc_simplified_chinese end; { else }
if FontCharSet = SHIFTJIS_CHARSET then // Japan
begin
Descendant.Supplement := 2;
end
else if FontCharSet = HANGEUL_CHARSET then // Korea
begin
Descendant.Supplement := 1;
end
else if FontCharSet = CHINESEBIG5_CHARSET then // Traditional C hinese (Taiwan)
begin
Descendant.Supplement := 1;
end
else
begin //SCYANGYU
Descendant.Supplement := 0; // cc_simplified_chinese end; { else }
Descendant.MaxCharWidth := OutlineTextMetric.otmTextMetrics.tm MaxCharWidth;
Descendant.AveCharWidth := OutlineTextMetric.otmTextMetrics.tmA veCharWidth;
Descendant.Charset := RvRenderPDF.FontBitmap.Canvas.Font.Chars et;
FirstChar := cardinal(OutlineTextMetric.otmTextMetrics.tmFirstChar); LastChar := cardinal(OutlineTextMetric.otmTextMetrics.tmLastChar); if GetCharABCWidths((RvRenderPDF.FontBitmap.Canvas.Handle),
FirstChar,
LastChar,
lpABC) then
begin
SetWidths;
Descendant.FirstChar := FirstChar;
Descendant.LastChar := LastChar;
Descendant.FontWidths := FontWidths;
end; { if }
end; { if }
finally
FreeMem(OutlineTextMetric, nSize);
end; { tryf }
end;
end;