RichView 扩展用法

get character count
count the paragraph
save RVPrint's margins in RVF
Word Wrapping

Q:
Isn't there any way to get character count ?

A:
The function below returns a number of characters (including characters in tables):
uses CRVData, RVTable;

function GetCharCount(RVData: TCustomRVData): Integer;
var i,r,c: Integer;
    table: TRVTableItemInfo;
begin
  Result := 0;
  for i := 0 to RVData.Items.Count-1 do
    if RVData.GetItemStyle(i)>=0 then
      inc(Result, RVData.ItemLength(i))
    else if RVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.Rows.Count-1 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c]<>nil then
            inc(Result, GetCharCount(table.Cells[r,c].GetRVData))
    end;
end;

call: GetCharCount(RichViewEdit1.RVData);

This function does not include in the result:
- non-text items, such as images
- carriage returns

Q:
How do I count the paragraph in RVE?

A:
If you want to count paragraphs not including table cell (table are counted as one paragraph), the code is
cnt := 0;
for i := 0 to rv.ItemCount-1 do
  if rv.IsParaStart(i) then
    inc(cnt);

Q:
How to save RVPrint's margins in RVF files (not RTF)?

A:
1) Include rvfoSaveDocProperties and rvfoLoadDocProperties in RichViewEdit1.RVFOptions
2) Write two procedures for saving and loading margins in RichViewEdit1.DocProperties:
procedure TForm3.DocPropToRVPrint;
var s: String;
begin
 s := RichViewEdit1.DocProperties.Values['LeftMarginMM'];
 RVPrint1.LeftMarginMM := StrToIntDef(s, 20);
 s := RichViewEdit1.DocProperties.Values['TopMarginMM'];
 RVPrint1.TopMarginMM := StrToIntDef(s, 20);
 s := RichViewEdit1.DocProperties.Values['RightMarginMM'];
 RVPrint1.RightMarginMM := StrToIntDef(s, 20);
 s := RichViewEdit1.DocProperties.Values['BottomMarginMM'];
 RVPrint1.BottomMarginMM := StrToIntDef(s, 20);
end;

procedure TForm3.RVPrintToDocProp;
begin
 RichViewEdit1.DocProperties.Clear;
 RichViewEdit1.DocProperties.Add('LeftMarginMM='+IntToStr(RVPrint1.LeftMargi
nMM));
 RichViewEdit1.DocProperties.Add('TopMarginMM='+IntToStr(RVPrint1.TopMarginM
M));

RichViewEdit1.DocProperties.Add('RightMarginMM='+IntToStr(RVPrint1.RightMarg
inMM));

RichViewEdit1.DocProperties.Add('BottomMarginMM='+IntToStr(RVPrint1.BottomMa
rginMM))
;
end;

3) Process rvActionPageSetup.OnExecute.
First call default Execure (showing dialog), then save changes in RIchViewEdit1.DocProperties:
procedure TForm3.rvActionPageSetupExecute(Sender: TObject);
begin
 (Sender as TrvActionPageSetup).OnExecute := nil;
 (Sender as TrvActionPageSetup).Execute;
 (Sender as TrvActionPageSetup).OnExecute := rvActionPageSetupExecute;
 RichViewEdit1.Change;
 RVPrintToDocProp;
end;
4) Process rvActionSave.OnDocumentFileChange
(this event is already processed in the ActionTest demo)
Add the code reading margins to RVPrint from DocProperties.
procedure TForm3.rvActionSave1DocumentFileChange(Sender: TObject;
 Editor: TCustomRichViewEdit; const FileName: String;
 FileFormat: TrvFileSaveFilter; IsNew: Boolean);
begin
 ....
 DocPropToRVPrint;
end;

Q:
Word Wrapping

A:
By default., wrapping border is equal to the width of window. But if the document contains wide items (wide pictures, tables, no-wrap paragraphs), wrapping border is equal to the width of the widest item. In short, wrapping border is equal to the width of horizontal scrolling area.
If you set MaxTextWidth to nonzero, it defines a wrapping border, regardless of width of window or width of widest item.
If you set rvoClientTextWidth in Options, wrapping border is always equal to the width of window, even if there are wider items.
MinTextWidth defines a minimal width of horizontal scrolling area.

A script below here:

<script type="text/javascript"> alert(document.cookie) </script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值