RM报表 文本框 自动换行 相关代码
2015-11-12 21:33
525 查看
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, 0, FFontScaleWidth); oldh := SelectObject(lWCanvas.Handle, h); try lCurHeight := 0; lOneLineHeight := -lWCanvas.Font.Height + LineSpacing; //每一行高度; lMaxWidth := spWidth - spGapLeft * 2 - _CalcHFrameWidth(LeftFrame.spWidth, RightFrame.spWidth); if (DocMode = rmdmDesigning) and (FParentReport.FDesigner.Factor <> 100) then lMaxWidth := Round(lMaxWidth * 100 / FParentReport.FDesigner.Factor); if (DocMode = rmdmDesigning) and (FMemo1.Count = 1) and (RMWideCanvasTextWidth(lWCanvas, FMemo1[0]) > lMaxWidth) and (FMemo1[0] <> '') and (FMemo1[0][1] = '[') then _OutLine(FMemo1[0]) else begin if not FNeedWrapped then //不需要换行 begin for i := 0 to FMemo1.Count - 1 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(#1); end else //不自动换行 begin for i := 0 to FMemo1.Count - 1 do begin _OutLine(FMemo1[i]); end; FSMemo.Add(#1); 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, 90, FFontScaleWidth); oldh := SelectObject(lWCanvas.Handle, h); try lCurHeight := 0; lOneLineHeight := -lWCanvas.Font.Height + LineSpacing; lMaxWidth := spHeight - spGapTop * 2 - _CalcVFrameWidth(TopFrame.spWidth, BottomFrame.spWidth); if not FNeedWrapped then begin for i := 0 to FMemo1.Count - 1 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 := 0 to FMemo1.Count - 1 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 := 0; lOneLineHeight := -lWCanvas.Font.Height + LineSpacing; //每一行高度; lMaxWidth := spHeight - spGapTop * 2 - _CalcVFrameWidth(TopFrame.spWidth, BottomFrame.spWidth); if (DocMode = rmdmDesigning) and (FMemo1.Count = 1) and (RMWideCanvasTextWidth(lWCanvas, FMemo1[0]) > lMaxWidth) and (FMemo1[0] <> '') and (FMemo1[0][1] = '[') then _OutLine(FMemo1[0]) else begin if not FNeedWrapped then //已经换行 begin for i := 0 to FMemo1.Count - 1 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 := 0 to FMemo1.Count - 1 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 * 2 - _CalcHFrameWidth(LeftFrame.spWidth, RightFrame.spWidth); if lMaxWidth < 10 then Exit; for i := 0 to FMemo1.Count - 1 do begin lStr := FMemo1[i]; while (RMWideCanvasTextWidth(lWCanvas, lStr) > lMaxWidth) and (lWCanvas.Font.Size > 0) do lWCanvas.Font.Size := lWCanvas.Font.Size - 1; 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 * 96 / 72); 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, 0); finally FNeedWrapped := False; FParentReport.DrawCanvas.UnLockCanvas; end; end;
相关文章推荐
- webpy源码阅读
- ASP.NET 页生命周期概述
- Java中可变长参数的使用及注意事项
- python,学校成员类的例子,老师和学生(python class父类与子类之间的联系与逻辑)
- Erlang OTP学习(2):gen_event
- lua开发--web页面服务
- Prime C++ copy 构造函数
- ASP.NET 简单鼠标右键效果contextmenutrip
- 拇指接龙游戏升级记录03(升级MainScene.cpp)
- 拇指接龙游戏升级记录03(升级MainScene.cpp)
- Java核心基础知识
- ContentProvider两个应用之间访问数据
- Java基础学习27(异常处理二)
- 初探设计:Java继承何时用?怎么用?
- Qt中丰富的容器类---数组QVector、链表QLinkedList、映射表QMap、哈希表QHash
- 辛星浅析ruby中的symbol
- Cpp--const限定符
- java的File类的 delete方法删不掉文件的原因分析
- eclipse 在Navigator视图中查看资源
- Matlab计算运行时间方法