Y
ymqpc
Unregistered / Unconfirmed
GUEST, unregistred user!
ReportBuiler9 开始加入对PDF文件的支持,但是导出如果有中文,则中文为乱码!不知有没有人使用ReportBuiler9?
在网上找到一个改写RAVE报表,使其能正下常输出中文PDF的文章,有没有人可以改一下?
==============================================================================
RAVE生成PDF文件中文乱码问题的解决
这个问题困扰了我将近两个星期了,今天在 季昌丰 先生的帮助下,取得的重大突破!
RAVE在处理中文时没有正确判断中文为双字节,所以在编码时出了问题!
现在把修改后的源代码贴出,供感兴趣的同志们参考:
{*************************************************************************}
{ 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 Republic 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 (Taiwan)} 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 <= 126do
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 + 1do
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.Canvasdo
begin
Font.Name := FontName;
Font.Style := FontStyles;
Font.Charset := FontCharset;
end;
{ with }
nSize := GetOutlineTextMetrics((RvRenderPDF.FontBitmap.Canvas.Handle),
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_chinese
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 Chinese (Taiwan)
begin
CompositeFontEncoding := 'CNS-EUC-H';
end
else
begin
//SCYANGYU
CompositeFontEncoding := 'GBpc-EUC-H';
//cc_simplified_chinese
end;
{ else
}
end;
{ else
}
Descriptor.PDFFontName := PDFFontName;
Descriptor.Setvalues(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 Chinese (Taiwan)
begin
Descendant.Supplement := 1;
end
else
begin
//SCYANGYU
Descendant.Supplement := 0;
// cc_simplified_chinese
end;
{ else
}
Descendant.MaxCharWidth := OutlineTextMetric.otmTextMetrics.tmMaxCharWidth;
Descendant.AveCharWidth := OutlineTextMetric.otmTextMetrics.tmAveCharWidth;
Descendant.Charset := RvRenderPDF.FontBitmap.Canvas.Font.Charset;
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;
在网上找到一个改写RAVE报表,使其能正下常输出中文PDF的文章,有没有人可以改一下?
==============================================================================
RAVE生成PDF文件中文乱码问题的解决
这个问题困扰了我将近两个星期了,今天在 季昌丰 先生的帮助下,取得的重大突破!
RAVE在处理中文时没有正确判断中文为双字节,所以在编码时出了问题!
现在把修改后的源代码贴出,供感兴趣的同志们参考:
{*************************************************************************}
{ 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 Republic 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 (Taiwan)} 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 <= 126do
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 + 1do
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.Canvasdo
begin
Font.Name := FontName;
Font.Style := FontStyles;
Font.Charset := FontCharset;
end;
{ with }
nSize := GetOutlineTextMetrics((RvRenderPDF.FontBitmap.Canvas.Handle),
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_chinese
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 Chinese (Taiwan)
begin
CompositeFontEncoding := 'CNS-EUC-H';
end
else
begin
//SCYANGYU
CompositeFontEncoding := 'GBpc-EUC-H';
//cc_simplified_chinese
end;
{ else
}
end;
{ else
}
Descriptor.PDFFontName := PDFFontName;
Descriptor.Setvalues(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 Chinese (Taiwan)
begin
Descendant.Supplement := 1;
end
else
begin
//SCYANGYU
Descendant.Supplement := 0;
// cc_simplified_chinese
end;
{ else
}
Descendant.MaxCharWidth := OutlineTextMetric.otmTextMetrics.tmMaxCharWidth;
Descendant.AveCharWidth := OutlineTextMetric.otmTextMetrics.tmAveCharWidth;
Descendant.Charset := RvRenderPDF.FontBitmap.Canvas.Font.Charset;
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;