Page 1 of 1
Converting indentations to spaces when saving as .TXT?
Posted: Thu Nov 15, 2012 7:51 pm
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?
Posted: Fri Nov 16, 2012 12:01 pm
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.
Posted: Fri Nov 16, 2012 2:33 pm
by PeterPanino
Is there any example on how to do this in the OnSaveItemToFile event-handler?
Posted: Sat Nov 17, 2012 9:19 am
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.