bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 Delphi FreeReport 報表元件 FreeReport 中文折行及亂碼問題
查看: 8106|回復: 1
go

FreeReport 中文折行及亂碼問題 [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 2006-6-29 18:28 |只看該作者 |倒序瀏覽 |打印
修改 FR_Class.pas
  1. procedure TfrMemoView.WrapMemo;
  2. ...略
  3.   procedure WrapLine(const s: String);
  4.   begin
  5. ...略
  6.         if WCanvas.TextWidth(Copy(s, beg, cur - beg + 1)) > maxwidth then
  7.         begin
  8.           WasBreak := False;
  9. ...略  
  10.   end;
複製代碼

改為
  1. procedure TfrMemoView.WrapMemo;
  2. ...略
  3.   procedure WrapLine(const s: String);
  4.   begin
  5. ...略
  6.         if WCanvas.TextWidth(Copy(s, beg, cur - beg + 1)) > maxwidth then
  7.         begin

  8.           if ByteType(s, cur) = mbLeadByte  then cur := cur - 1;

  9.           WasBreak := False;
  10. ...略  
  11.   end;
複製代碼

使用此一方法,只有解決在計算最大顯示寬度時不會在中文字的中間問題。但是折行點的選擇還是使用英文格式,如果全部沒有空格字就都不會折行。
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw

Rank: 9Rank: 9Rank: 9

2#
發表於 2006-6-29 18:30 |只看該作者
將函數直接替換
  1. procedure WrapLine(const s:WideString);
  2. var
  3.   i, cur, beg, last, LoopPos: Integer;
  4.   WasBreak, CRLF: Boolean;
  5.   s1:string;
  6. begin
  7.   CRLF := False;
  8.   LoopPos := 0;
  9.   s1 := s;
  10.   for i := 1 to Length(s1) do
  11.     if s1[i] in [#10, #13] then
  12.     begin
  13.       CRLF := True;
  14.       break;
  15.     end;
  16.   last := 1; beg := 1;
  17.   if not CRLF and ((Length(s) <= 1) or (WCanvas.TextWidth(s) <= maxwidth)) then
  18.     OutLine(s + #1)
  19.   else
  20.   begin
  21.     cur := 1;
  22.     while cur <= Length(s) do
  23.     begin
  24.       if s1[cur] in [#10, #13] then
  25.       begin
  26.         OutLine(Copy(s1, beg, cur - beg) + #1);
  27.         while (cur < Length(s1)) and (s1[cur] in [#10, #13]) do Inc(cur);
  28.         beg := cur; last := beg;
  29.         if s1[cur] in [#13, #10] then
  30.           Exit else
  31.           continue;
  32.       end;
  33.       if s[cur] <> ' ' then
  34.       if WCanvas.TextWidth(Copy(s, beg, cur - beg + 1)) > maxwidth then
  35.       begin
  36.       
  37.       
  38.       
  39.         WasBreak := False;
  40.         if (Flags and flWordBreak) <> 0 then
  41.         begin
  42.           i := cur;
  43.           while (i <= Length(s1)) and not (s1[i] in spaces) do
  44.             Inc(i);
  45.           b := BreakWord(Copy(s, last + 1, i - last - 1));
  46.           if Length(b) > 0 then
  47.           begin
  48.             i := 1;
  49.             cur := last;
  50.             while (i <= Length(b)) and
  51.               (WCanvas.TextWidth(Copy(s, beg, last - beg + 1 + Ord(b[i])) + '-') <= maxwidth) do
  52.             begin
  53.               WasBreak := True;
  54.               cur := last + Ord(b[i]);
  55.               Inc(i);
  56.             end;
  57.             last := cur;
  58.           end;
  59.         end
  60.         else
  61.           if last = beg then last := cur;
  62.         if WasBreak then
  63.           OutLine(Copy(s, beg, last - beg + 1) + '-')
  64.         else if s[last] = ' ' then
  65.           OutLine(Copy(s, beg, last - beg)) else
  66.           OutLine(Copy(s, beg, last - beg + 1));
  67.         if ((Flags and flWordBreak) <> 0) and not WasBreak and (last = cur) then
  68.           if LoopPos = cur then
  69.           begin
  70.             beg := cur + 1;
  71.             cur := Length(s);
  72.             break;
  73.           end
  74.           else
  75.             LoopPos := cur;
  76.         beg := last + 1; last := beg;
  77.       end;
  78. //    if s[cur] in spaces then last := cur;
  79.       if s[cur] = ' ' then last := cur;
  80.       Inc(cur);
  81.     end;
  82.     if beg <> cur then OutLine(Copy(s, beg, cur - beg + 1) + #1);
  83.   end;
  84. end;
複製代碼


資料來源:http://www.delphibbs.com/delphibbs/dispq.asp?lid=2059269
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2025-5-2 09:53 , Processed in 0.020765 second(s), 14 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.