RM报表 文本框 自动换行 相关代码

procedure TRMCustomMemoView.WrapMemo1(aAddChar: Boolean);
var
lCurHeight, lOneLineHeight, lMaxWidth: Integer;
lWCanvas: TCanvas; procedure _OutLine(const lStr: WideString);
begin
FSMemo.Add(lStr);
Inc(lCurHeight, lOneLineHeight);
end; procedure _WrapOutMemo;
var
h, oldh: HFont;
i: Integer;
begin
h := RMCreateAPIFont(lWCanvas.Font, , FFontScaleWidth);
oldh := SelectObject(lWCanvas.Handle, h); try
lCurHeight := ;
lOneLineHeight := -lWCanvas.Font.Height + LineSpacing; //每一行高度;
lMaxWidth := spWidth - spGapLeft * - _CalcHFrameWidth(LeftFrame.spWidth, RightFrame.spWidth);
if (DocMode = rmdmDesigning) and (FParentReport.FDesigner.Factor <> ) then
lMaxWidth := Round(lMaxWidth * / FParentReport.FDesigner.Factor); if (DocMode = rmdmDesigning) and (FMemo1.Count = ) and
(RMWideCanvasTextWidth(lWCanvas, FMemo1[]) > lMaxWidth) and
(FMemo1[] <> '') and (FMemo1[][] = '[') then
_OutLine(FMemo1[])
else
begin
if not FNeedWrapped then //不需要换行
begin
for i := to FMemo1.Count - do
_OutLine(FMemo1[i]);
end
else if WordWrap or AllowHtmlTag then //自动换行
begin
lCurHeight := lCurHeight + RMWrapStrings(FMemo1, FSMemo, lWCanvas, lMaxWidth, LineSpacing {lOneLineHeight},
WordBreak, CharWrap, AllowHtmlTag, True, aAddChar); FSMemo.Add(#);
end
else //不自动换行
begin
for i := to FMemo1.Count - do
begin
_OutLine(FMemo1[i]);
end; FSMemo.Add(#);
end;
end;
finally
FVHeight := lCurHeight - LineSpacing;
LineHeight := lOneLineHeight;
SelectObject(lWCanvas.Handle, oldh);
DeleteObject(h);
end;
end; procedure _WrapOutMemo90;
var
h, oldh: HFont;
i: Integer;
begin
h := RMCreateAPIFont(lWCanvas.Font, , FFontScaleWidth);
oldh := SelectObject(lWCanvas.Handle, h);
try
lCurHeight := ;
lOneLineHeight := -lWCanvas.Font.Height + LineSpacing;
lMaxWidth := spHeight - spGapTop * - _CalcVFrameWidth(TopFrame.spWidth, BottomFrame.spWidth);
if not FNeedWrapped then
begin
for i := to FMemo1.Count - do
_Outline(FMemo1[i]);
end
else if WordWrap then
lCurHeight := lCurHeight + RMWrapStrings(FMemo1, FSMemo, lWCanvas, lMaxWidth, LineSpacing {lOneLineHeight},
WordBreak, CharWrap, AllowHtmlTag, True, aAddChar)
else
begin
for i := to FMemo1.Count - do
_Outline(FMemo1[i]);
end;
finally
FVHeight := lCurHeight - LineSpacing;
LineHeight := lOneLineHeight;
SelectObject(lWCanvas.Handle, oldh);
DeleteObject(h);
end;
end; procedure _WrapOutMemo180;
var
i: Integer;
begin
lCurHeight := ;
lOneLineHeight := -lWCanvas.Font.Height + LineSpacing; //每一行高度;
lMaxWidth := spHeight - spGapTop * - _CalcVFrameWidth(TopFrame.spWidth, BottomFrame.spWidth); if (DocMode = rmdmDesigning) and (FMemo1.Count = ) and
(RMWideCanvasTextWidth(lWCanvas, FMemo1[]) > lMaxWidth) and
(FMemo1[] <> '') and (FMemo1[][] = '[') then
_OutLine(FMemo1[])
else
begin
if not FNeedWrapped then //已经换行
begin
for i := to FMemo1.Count - do
_OutLine(FMemo1[i]);
end
else if WordWrap then //自动换行
begin
lCurHeight := lCurHeight + RMWrapStrings(FMemo1, FSMemo, lWCanvas, lMaxWidth, LineSpacing {lOneLineHeight},
WordBreak, CharWrap, AllowHtmlTag, False, aAddChar);
end
else //不自动换行
begin
for i := to FMemo1.Count - do
begin
_OutLine(FMemo1[i]);
end;
end;
end;
FVHeight := lCurHeight - LineSpacing;
LineHeight := lOneLineHeight;
end; procedure _ChangeFontSize;
var
i: Integer;
lStr: string;
lMaxWidth: Integer;
begin
lMaxWidth := spWidth - spGapLeft * - _CalcHFrameWidth(LeftFrame.spWidth, RightFrame.spWidth);
if lMaxWidth < then Exit; for i := to FMemo1.Count - do
begin
lStr := FMemo1[i];
while (RMWideCanvasTextWidth(lWCanvas, lStr) > lMaxWidth) and (lWCanvas.Font.Size > ) do
lWCanvas.Font.Size := lWCanvas.Font.Size - ;
end; Font.Size := lWCanvas.Font.Size;
end; begin
if not AutoAddBlank then
aAddChar := False;
if RotationType <> rmrtNone then
AllowHtmlTag := False; FParentReport.DrawCanvas.LockCanvas;
try
lWCanvas := FParentReport.DrawCanvas.Canvas;
lWCanvas.Font.Assign(Font);
lWCanvas.Font.Height := -Round(Font.Size * / );
SetTextCharacterExtra(lWCanvas.Handle, CharacterSpacing);
case FScaleFontType of
rmstByWidth:
begin
if DocMode <> rmdmDesigning then
_ChangeFontSize;
end;
rmstByHeight:
begin
end;
end; FSMemo.Clear;
case RotationType of
rmrt90, rmrt270: _WrapOutMemo90;
rmrt180: _WrapOutMemo180;
else
_WrapOutMemo;
end; SetTextCharacterExtra(lWCanvas.Handle, );
finally
FNeedWrapped := False;
FParentReport.DrawCanvas.UnLockCanvas;
end;
end;
上一篇:SpringMVC Controller 介绍及常用注解


下一篇:改变textField的placeholder的颜色和位置