fastreport 自动缩小字体以填充

遇到一个新需求当FastReport的Memo框中的文字大于Memo的长度,则自动缩小字体来适应Memo的宽度。找了多种办法,最终选择直接改FastReport的源码一劳永逸。

要修改frxClass单元源码,步骤如下:

1、增加字体调整模式

TfrxScaleFontSize = (sfsWidth, sfsHeight, sfsNone);

2、为TfrxMemoView添加一个属性ScaleFontSize

property ScaleFontSize;

3、为TfrxCustomMemoView增加FScaleFontSize和ScaleFontSize属性

FScaleFontSize:TfrxScaleFontSize;

property ScaleFontSize: TfrxScaleFontSize read FScaleFontSize write FScaleFontSize default sfsNone;

4、修改
TfrxCustomMemoView.BeforePrint过程代码如下:

procedure TfrxCustomMemoView.BeforePrint;

begin

inherited;

if not IsDataField then

FTempMemo := FMemo.Text;

case FScaleFontSize of

sfsNone: ;

sfsWidth:

if not WordWrap and not AutoWidth then //按宽度调整时–自动换行时不可用 ; 自动宽度时不可用

while (CalcWidth – Width > 0) do

Font.Size := Font.Size – 1;

sfsHeight:

if (StretchMode = smDontStretch) then //伸展时不能按高度调整

while ((CalcHeight – LineSpacing) – Height > 0) do

Font.Size := Font.Size – 1;

end;

end;

最终效果图如下:

fastreport 自动缩小字体以填充,fastreport 自动缩小字体以填充,第1张

关于作者:

生活百科常识网