Converting indentations to spaces when saving as .TXT?

General TRichView support forum. Please post your questions here
Post Reply
PeterPanino
Posts: 57
Joined: Tue Jul 13, 2010 10:50 pm

Converting indentations to spaces when saving as .TXT?

Post by PeterPanino »

Hi! I have a RichViewEdit where some paragraphs are indented. Now, when I export the document to plain text (.TXT), the paragraph indentations should automatically be converted to spaces. Is there an option to do this automatically or do I have to write an OnSaveItemToFile event-handler?
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

There is no automatic conversion of indentation to spaces.
You can either use OnSaveItemToFile, or create a copy of this document in a hidden TRichView, add spaces, and save.
PeterPanino
Posts: 57
Joined: Tue Jul 13, 2010 10:50 pm

Post by PeterPanino »

Is there any example on how to do this in the OnSaveItemToFile event-handler?
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This code adds 3 spaces at the beginning of paragraphs having the first line indented.

Code: Select all

procedure TForm3.RichViewEdit1SaveItemToFile(Sender: TCustomRichView;
  const Path: string; RVData: TCustomRVData; ItemNo: Integer;
  SaveFormat: TRVSaveFormat; Unicode: Boolean; var OutStr: TRVRawByteString;
  var DoDefault: Boolean);
begin
  if SaveFormat<>rvsfText then
    exit;
  if not RVData.IsParaStart(ItemNo) or
    (RVData.GetRVStyle.ParaStyles[RVData.GetItemPara(ItemNo)].FirstIndent<=0) then
    exit;
 DoDefault := False;
 if Sender.Style.TextStyles[RVData.GetItemStyle(ItemNo)].Unicode then begin
   OutStr := ' '#0' '#0' '#0+OutStr;
   if not Unicode then
     OutStr := RVU_UnicodeToAnsi(CP_ACP, OutStr);
   end
 else begin
   OutStr := '   '+OutStr;
   if Unicode then
     OutStr := RVU_AnsiToUnicode(RVData.GetItemCodePage(ItemNo), OutStr);
 end;
end;
Problems:
1) This code does not add spaces for paragraphs started from a non-text item.
2) Unlike the standard text saving procedure, this code does not make a special processing when saving text of SYMBOL_CHARSET's font, like "Symbol" or "Windgdings"
3) This code ignores CodePage parameter of SaveText. You can store this code page in a global variable, and use it instead of CP_ACP.

Actually, I think that creating a modified copy is a better approach.
Post Reply