有些字划掉并非删除线而是右斜线,在ReportMachine报表的实现

  最近项目中,由于有个字是删除的意思,但不像Word排版给设置删除线样式就能够达到的,而是要求从左上角划一直线穿过这个字到右下角。最开始想到用造字的办法,但是造字不只麻烦,并且要为不一样字体造字,而且,若是机器系统不同,字体之间还有差别,最关键的是,造出来的字,输出为pdf打开来看时,pdf并不能显示这个造的字出来。在报表中,这个字,有多是从数据库中出来的,输入与输出在不一样机器间共享,表达就会有很大的损失,形成错漏。因此造字是行不通的办法。数据库

  报表是采用ReportMachine 6.5,这是网上流传很广的源码版。经过分析发现,能够针对出现这个字的状况下,进行特殊处理。找到RM_Class.pas文件, TRMCustomMemoView.ShowMemo就是输出处理,找到文本绘制的处理 _DrawOneStr,修改代码:ide

 1 procedure _DrawOneStr;
 2 var
 3   i: Integer;
 4   lWidth: Integer;
 5   str1,str2 : string; /// add 2014/9/19
 6 begin
 7 {/// 在有补字上画一个右斜线 }
 8   str1 := aStr;
 9   while true do
10   begin
11     str2 := '(补';
12     i := Pos(str2, str1);
13     if i = 0 then begin str2 := '(补'; i := Pos(str2, str1); end;
14     if i = 0 then begin str2 := '补)';  i := Pos(str2, str1); end;
15     if i = 0 then begin str2 := '补)'; i := Pos(str2, str1); end;
16     if i = 0 then break;
17     if str2 = '(补' then
18     begin
19       str2 := copy(str1,1,i);  // 补前的字符
20       str1 := str2 + '@@' + copy(str1,i+3,Length(str1)); // 将找到的"补"字用两个@替换
21     end
22     else if str2 = '(补' then
23     begin
24       str2 := copy(str1,1,i+1);
25       str1 := str2 + '@@' + copy(str1,i+4,Length(str1)); // 将找到的"补"字用两个@替换
26     end
27     else if str2 = '补)' then
28     begin
29       str2 := copy(str1,1,i-1);
30       str1 := Str2 + '@@' + copy(str1,i+2,Length(str1)); // 将找到的"补"字用两个@替换
31     end
32     else if str2 = '补)' then
33     begin
34       str2 := copy(str1,1,i-1);
35       str1 := str2 + '@@' + copy(str1,i+2,Length(str1)); // 将找到的"补"字用两个@替换
36     end;
37 
38     lStrLen := Length(str2);
39     GetTextExtentPoint32A(Canvas.Handle, PAnsiChar(str2), lStrLen, lSize);
40     Canvas.MoveTo(aCurx + lSize.cx + (lCurLineHeight div 6), lCury);
41     Canvas.LineTo(aCurx + lSize.cx + lCurLineHeight - (lCurLineHeight div 6), lCury + lSize.cy);
42   end;
43 {\\\ end add 2014/9/19}
44   lStrLen := Length(aStr);
45   GetTextExtentPoint32W(Canvas.Handle, PWideChar(aStr), lStrLen, lSize);
46   ......
47 end;

 

经过增长上面的代码,导出pdf后的效果很是好。凡是用括号(不管全角仍是半角)括起来的“补”字,均有右斜线划去。字体

相关文章
相关标签/搜索