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>