GetAllText WordWrap Returns?

General TRichView support forum. Please post your questions here
Post Reply
ThYpHoOn
Posts: 21
Joined: Fri Jul 16, 2010 1:56 pm
Location: Germany

GetAllText WordWrap Returns?

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
ThYpHoOn
Posts: 21
Joined: Fri Jul 16, 2010 1:56 pm
Location: Germany

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This function uses undocumented methods.

1) Include RV_Defs.inc in your unit, it contains RVUNICODESTR define:

Code: Select all

{$I RV_Defs.inc}
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)
ThYpHoOn
Posts: 21
Joined: Fri Jul 16, 2010 1:56 pm
Location: Germany

Post by ThYpHoOn »

Thanks alot, this works fine :)

Gz, ThYpHoOn
ThYpHoOn
Posts: 21
Joined: Fri Jul 16, 2010 1:56 pm
Location: Germany

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not understand, what do you mean by "GetAllText has converted the text (if it was RichEdit) to plaintext"
ThYpHoOn
Posts: 21
Joined: Fri Jul 16, 2010 1:56 pm
Location: Germany

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
ThYpHoOn
Posts: 21
Joined: Fri Jul 16, 2010 1:56 pm
Location: Germany

Post 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.
Post Reply