Plurk

Rave Reports 7.0.x轉PDF中文亂碼, 解決部分問題

這是從5.x就一直存在的問題, 原本使用BDS2006中的內建版本, 困擾一直無法解決, 後來找了包含source code 的7.0.2來玩, 參考了scyangyu 公佈的方法, 加上一點運氣, 好不容易終於讓中文正確出現在PDF上了, 第一階段到此, 試了一堆字型, 只有AR MingtiM BIG-5字型可以達到預覽/轉RTF/轉PDF的需求.

後來因為不同字型的需求, 只好硬著頭皮去google找解決方法, 原本第一階段的中文字型問題解決了一半, 當報表中存在兩種以上字型時, 一跑報表, 程式就出錯, 後來竟然發現一年以前scyangyu 已經解決了, 之前找資料竟然沒發現, 連前一階段困擾的字型重疊一直沒解決的問題scyangyu也show出已解決的圖片, 可惜, 沒把方法公佈出來, 發了信去問, 還沒接到回信, 也許對方沒空, 只好自己硬著頭皮trace程式, 竟然讓我解決了一些, 至少常用字型可以正常轉PDF了! 真是一個高興!

Rave Reports還有一些Memo上亂碼的問題, 可以參考scyangyu的blog.

列一下轉PDF問題的重點程式(繁體中文可用)
RpRenderPDF.pas

1. procedure TRPPDFFontComposite.InitData;

//這兩行改成這樣
PrintLn('/Encoding /' + CompositeFontEncoding);
//PrintLn('/Encoding /Identity-H');


2. procedure TRPPDFFontComposite.SetFontData;

procedure SetWidths; //稍稍改寫一下
var
 i1: integer;
 WidthScale: smallint;
begin
 i1 := 0;
 // ShowMessage(Format('firstchar, lastchar = %d,%d', [FirstChar, LastChar]));
 while i1 < name =" '新細明體')">

3. procedure TRPPDFFontComposite.SetFontData;

//這是參考scyangyu的程式來的
 if Panose.bProportion = PAN_PROP_MONOSPACED then
 begin
  if FontCharSet = CHINESEBIG5_CHARSET then
  begin
   CompositeFontEncoding := 'ETen-B5-H';
  end
  else if FontCharSet = GB2312_CHARSET then
  begin
   CompositeFontEncoding := 'GBK-EUC-H';
  end else if FontCharSet = SHIFTJIS_CHARSET then
  begin
   CompositeFontEncoding := '90ms-RKSJ-H';
  end else
  begin
   CompositeFontEncoding := 'KSCms-UHC-HW-H';
  end;
 end
 else
 begin
  if FontCharSet = CHINESEBIG5_CHARSET then
  begin
   CompositeFontEncoding := 'ETen-B5-H';//'CNS-EUC-H';
  end else if FontCharSet = GB2312_CHARSET then
  begin
   CompositeFontEncoding := 'GBpc-EUC-H';
  end else if FontCharSet = SHIFTJIS_CHARSET then
  begin
   CompositeFontEncoding := '90msp-RKSJ-H';
  end else
  begin
   CompositeFontEncoding := 'KSCms-UHC-H';
  end;
 end;
 Descriptor.PDFFontName := PDFFontName;
 Descriptor.FontName := FontName;
 Descriptor.SetValues(OutlineTextMetric, FontWidths[32]);
 Descendant.PDFFontName := PDFFontName;
 Descendant.Descriptor := Descriptor;
 Descendant.Registry := 'Adobe';
 if FontCharSet = CHINESEBIG5_CHARSET then
 begin
  Descendant.Ordering := 'CNS1';
 end else if FontCharSet = GB2312_CHARSET then
 begin
  Descendant.Ordering := 'GB1';
 end else if FontCharSet = SHIFTJIS_CHARSET then
 begin
  Descendant.Ordering := 'Japan1';
 end else
 begin
  Descendant.Ordering := 'Korea1';
 end;

 if FontCharSet = CHINESEBIG5_CHARSET then
 begin
  Descendant.Supplement := 1;
 end
 else if FontCharSet = GB2312_CHARSET then
 begin
  Descendant.Supplement := 0;
 end
 else if FontCharSet = SHIFTJIS_CHARSET then
 begin
  Descendant.Supplement := 2;
 end else
 begin
  Descendant.Supplement := 1;
 end;


4. procedure TRPPDFFontComposite.SetFontData;

//mark下兩行程式
//Descendant.Ordering := 'Identity';
//Descendant.Supplement := 0;


應該沒忘了甚麼!!

0 意見:

Designed by Posicionamiento Web | Bloggerized by GosuBlogger | Blue Business Blogger