Page 1 of 1
GetAllText WordWrap Returns?
Posted: Wed Mar 02, 2011 3:20 pm
by ThYpHoOn
Hi folks,
i've a problem with the GetAllText function if i want only the plain-text of a document. If i'm tipping a long text with the property wordwrap = true then ther will be carriage return(line feeds)'s shown but if i'm getting the text with GetAllText they won't be exportet. Is there a clue to get them?
Greetings, ThY
Posted: Wed Mar 02, 2011 5:51 pm
by Sergey Tkachenko
All TRichView text exporting functions ignore line wrapping, the inserts #13#10 only in places of paragraph breaks.
I'll post a function with line wrapping tomorrow.
Posted: Thu Mar 03, 2011 8:04 am
by ThYpHoOn
Sergey Tkachenko wrote:All TRichView text exporting functions ignore line wrapping, the inserts #13#10 only in places of paragraph breaks.
I'll post a function with line wrapping tomorrow.
Thanks for the quick answer and for the solution, i'm waiting
Gz, ThYpHoOn
Posted: Thu Mar 03, 2011 8:48 pm
by Sergey Tkachenko
This function uses undocumented methods.
1) Include RV_Defs.inc in your unit, it contains RVUNICODESTR define:
Include in uses: CRVFData, DLines, RVTable, RVItem.
2) A helper function
Code: Select all
// Converting text from internal representation to String
function ConvertItemTextToString(const ItemText: TRVRawByteString;
UnicodeItem: Boolean; CodePage: Cardinal): String;
begin
{$IFDEF RVUNICODESTR} // <-- declared in RV_Defs.inc
// Delphi 2009+: String is Unicode
if UnicodeItem then
Result := RVU_RawUnicodeToWideString(ItemText)
else
Result := RVU_RawUnicodeToWideString(
RVU_AnsiToUnicode(CodePage, ItemText));
{$ELSE}
// Delphi 4-2007: String is ANSI
if UnicodeItem then
Result := RVU_UnicodeToAnsi(CodePage, ItemText)
else
Result := ItemText;
{$ENDIF}
end;
3) Main function
Code: Select all
function GetFormattedText(RVData: TCustomRVFormattedData): String;
var i, r, c, ItemNo, StyleNo: Integer;
table: TRVTableItemInfo;
begin
Result := '';
for i := 0 to RVData.DrawItems.Count-1 do begin
if (i>0) and RVData.DrawItems[i].FromNewLine then
Result := Result+#13#10;
ItemNo := RVData.DrawItems[i].ItemNo;
StyleNo := RVData.GetItemStyle(ItemNo);
if StyleNo=rvsTab then
Result := Result+#9
else if StyleNo=rvsTable then begin
table := TRVTableItemInfo(RVData.GetItem(ItemNo));
for r := 0 to table.RowCount-1 do
for c := 0 to table.ColCount-1 do begin
if table.Cells[r,c]<>nil then
Result := Result + GetFormattedText(TCustomRVFormattedData(table.Cells[r,c].GetRVData));
if not ((r=table.RowCount-1) and (c=table.ColCount-1)) then
Result := Result+#13#10;
end;
end
else if StyleNo>=0 then
Result := Result+ConvertItemTextToString(
RVData.DrawItems.GetString(i, RVData.Items),
RVData.GetRVStyle.TextStyles[StyleNo].Unicode,
RVData.GetItemCodePage(ItemNo));
end;
end;
How to use:
Code: Select all
Memo1.Lines.Text := GetFormattedText(RichViewEdit1.RVData)
Posted: Mon Mar 07, 2011 8:07 am
by ThYpHoOn
Thanks alot, this works fine
Gz, ThYpHoOn
Posted: Tue Mar 08, 2011 11:58 am
by ThYpHoOn
A little note on this, GetAllText has converted the text (if it was RichEdit) to plaintext, but the new function did not do this. Any idea for this?
This isn't so bad, i could check the text if its RichText... but if there is a easy tweak for this i'm glad to hear from it.
Gz, ThYpHoOn
Posted: Tue Mar 08, 2011 2:10 pm
by Sergey Tkachenko
Sorry, I do not understand, what do you mean by "GetAllText has converted the text (if it was RichEdit) to plaintext"
Posted: Tue Mar 08, 2011 3:23 pm
by ThYpHoOn
The result of GetAllText is completely unformatted and non-rtf, but the function "GetFormattedText" give's the RTF-Formatted text as a result.
Gz, ThYpHoOn
Posted: Tue Mar 08, 2011 3:59 pm
by Sergey Tkachenko
?
GetFormattedText, like GetAllText, returns a plain text.
The only differences
- GetFormattedText adds more line break characters in places of line wrapping;
- GetFormattedText does not include text representation of non-text items (except for tabs and tables)
Posted: Thu Mar 10, 2011 8:21 am
by ThYpHoOn
Sergey Tkachenko wrote:?
GetFormattedText, like GetAllText, returns a plain text.
The only differences
- GetFormattedText adds more line break characters in places of line wrapping;
- GetFormattedText does not include text representation of non-text items (except for tabs and tables)
Uh, sorry there was a mistake/bug in my code.