| View previous topic :: View next topic |
| Author |
Message |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Tue Sep 06, 2005 8:45 pm Post subject: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc. |
|
|
This code deletes all empty lines:
| Code: | procedure DeleteBlankLines(RVData: TCustomRVData);
var i,r,c: Integer;
table: TRVTableItemInfo;
begin
for i := RVData.ItemCount-1 downto 0 do
if RVData.IsParaStart(i) and (RVData.GetItemStyle(i)>=0) and
(RVData.GetItemText(i)='') and (RVData.ItemCount>1) then
RVData.DeleteItems(i,1)
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
DeleteBlankLines(table.Cells[r,c].GetRVData);
end;
end; |
This procedure cannot be undone/redone. If called for editor, the editor's undo buffer becomes incorrect, so call ClearUndo.
Call:
| Code: | DeleteBlankLines(RichViewEdit1.RVData);
RichViewEdit1.ClearUndo;
RichViewEdit1.Format; |
|
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Tue Sep 06, 2005 8:51 pm Post subject: |
|
|
This procedure removes all line breaks that can be removed:
| Code: | procedure RemoveParagraphBreaks(RVData: TCustomRVData);
var i,r,c: Integer;
table: TRVTableItemInfo;
begin
for i := 0 to RVData.ItemCount-1 do
if (i>0) and RVData.IsFromNewLine(i) and
not RVData.GetItem(i).GetBoolValue(rvbpFullWidth) and
not RVData.GetItem(i-1).GetBoolValue(rvbpFullWidth) and
(RVData.GetItemStyle(i)<>rvsListMarker) then
RVData.GetItem(i).SameAsPrev := True
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
RemoveParagraphBreaks(table.Cells[r,c].GetRVData);
end;
end; |
This function cannot be undone/redone. If it's called for editor, information in the editor's undo buffer becomes incorrect, so you need to call RichViewEdit.ClearUndo.
In some cases, documents after calling this functions do not conform to the rules of valid RichView document (see the help file, "Valid
Documents" topic).
In order to fix it, call NormalizeRichView procedure from RVNormalize.pas. This unit is included in RichViewActions.
Call:
| Code: | RemoveParagraphBreaks(RichViewEdit1.RVData);
NormalizeRichView(RichViewEdit1.RVData);
RichViewEdit1.ClearUndo;
RichViewEdit1.Format; |
|
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Wed Nov 02, 2005 9:19 pm Post subject: |
|
|
Modification of RemoveParagraphBreaks - removing blank lines only from the end of the document:
| Code: | procedure DeleteTrailingBlankLines(RVData: TCustomRVData);
var i: Integer;
begin
for i := RVData.ItemCount-1 downto 1 do
if RVData.IsParaStart(i) and (RVData.GetItemStyle(i)>=0) and
(RVData.GetItemText(i)='') then
RVData.DeleteItems(i,1)
else
break;
end; |
Call:
| Code: | DeleteBlankLines(RichViewEdit1.RVData);
RichViewEdit1.ClearUndo;
RichViewEdit1.Format; |
|
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Tue Dec 13, 2005 7:40 pm Post subject: |
|
|
This procedure converts all single line breaks to "soft" line breaks (which can be added by Shift+Return keys). Double line breaks remain paragraph breaks (which can be added by Return key), but empty line is removed (actually, all empty lines are removed)
| Code: | procedure NormalizeLineBreaks(RVData: TCustomRVData);
var i,r,c: Integer;
table: TRVTableItemInfo;
begin
for i := RVData.ItemCount-1 downto 0 do begin
if RVData.IsParaStart(i) then begin
// removing empty line
if RVData.IsParaStart(i) and (RVData.GetItemStyle(i)>=0) and
(RVData.ItemCount>0) then begin
RVData.DeleteItems(i,1);
continue;
end;
// converting "Return-linebreak" to "Shift+Return-linebreak", if
// there is no empty line before. Making sure that this conversion is
// not applied to tables and breaks, items after them, and the very first
// item
if (i>0) and not RVData.GetItem(i).GetBoolValue(rvbpFullWidth) and
not RVData.GetItem(i-1).GetBoolValue(rvbpFullWidth) and
(RVData.GetItemStyle(i)<>rvsListMarker) and
not ((RVData.GetItemStyle(i-1)>=0) and (RVData.GetItemText(i-1)='')) then
RVData.GetItem(i).BR := True;
continue;
end;
// recursive table traversal
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
NormalizeLineBreaks(table.Cells[r,c].GetRVData);
end;
end;
end; |
Modified 2007-May-31: added (RVData.GetItemStyle(i)<>rvsListMarker) check |
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Thu May 31, 2007 1:10 pm Post subject: |
|
|
Similar function: removing all single line breaks and empty lines.
| Code: | procedure NormalizeLineBreaks2(RVData: TCustomRVData);
var i,r,c: Integer;
table: TRVTableItemInfo;
begin
for i := RVData.ItemCount-1 downto 0 do begin
if RVData.IsParaStart(i) then begin
// removing empty line
if RVData.IsParaStart(i) and (RVData.GetItemStyle(i)>=0) and
(RVData.ItemCount>0) then begin
RVData.DeleteItems(i,1);
continue;
end;
// Removing line break if there is no empty line before it
// Making sure that this conversion is
// not applied to tables and breaks, items after them,
// the very first item and list marker
if (i>0) and not RVData.GetItem(i).GetBoolValue(rvbpFullWidth) and
not RVData.GetItem(i-1).GetBoolValue(rvbpFullWidth) and
(RVData.GetItemStyle(i)<>rvsListMarker) and
not ((RVData.GetItemStyle(i-1)>=0) and (RVData.GetItemText(i-1)='')) then
RVData.GetItem(i).SameAsPrev := True;
continue;
end;
// recursive table traversal
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
NormalizeLineBreaks2(table.Cells[r,c].GetRVData);
end;
end;
end; |
It's recommended to call NormalizeRichView (RVNormalize.pas, can be found in RichViewActions) after calling this procedure. |
|
| Back to top |
|
 |
palmeira
Joined: 12 Sep 2005 Posts: 127
|
Posted: Thu May 13, 2010 9:36 pm Post subject: |
|
|
| I am not sure if this is a bug, but at least for some documents when I use DeleteBlankLines to delete a line, and the next paragraph has a different format (a border), the border is lost. |
|
| Back to top |
|
 |
Sergey Tkachenko Site Admin
Joined: 27 Aug 2005 Posts: 6576
|
Posted: Fri May 14, 2010 8:51 pm Post subject: |
|
|
DeleteBlandLines assumes that document may have empty text items only as separate lines (paragraphs).
Do you generate your documents yourself?
Try calling NormalizeRichView procedure (RVNormalize.pas, included in RichViewActions) before DeleteBlandLines. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|