Page 1 of 1

Convert TextItem with text styles to html text

Posted: Wed Aug 02, 2017 3:22 pm
by saeid2016
Hello support,
Is there a method to convert a Text Item with styles to a html text?

SaveHTML function exports TRichView document to HTML or XHTML file, but I want to convert a text to html text.

Re: Convert TextItem with text styles to html text

Posted: Wed Aug 02, 2017 3:43 pm
by Sergey Tkachenko
Do you want to save all text properties (font, color, etc.)?

Re: Convert TextItem with text styles to html text

Posted: Wed Aug 02, 2017 3:47 pm
by saeid2016
Sergey Tkachenko wrote: Wed Aug 02, 2017 3:43 pm Do you want to save all text properties (font, color, etc.)?
only font, color and backcolor

Re: Convert TextItem with text styles to html text

Posted: Wed Aug 02, 2017 4:50 pm
by Sergey Tkachenko

Code: Select all

uses
  RVTypes, CRVData;

type
  TCustomRVDataAccess = class (TCustomRVData)
  end;

function GetTextItemHTML(RVData: TCustomRVData; ItemNo: Integer): TRVUnicodeString;
var
  Span: TRVRawByteString;
  FontName: TRVUnicodeString;
  TextStyle: TFontInfo;
begin
  Result := UTF8ToString(TCustomRVDataAccess(RVData).GetTextForHTML('', ItemNo, True, [rvsoUTF8]));
  TextStyle := RVData.GetRVStyle.TextStyles[RVData.GetItemStyle(ItemNo)];
  FontName := UTF8ToString(StringToHTMLString3(TextStyle.FontName, True, CP_ACP));
  if (AnsiCompareText(FontName, RVFONT_SYMBOL) = 0) or
     (AnsiCompareText(FontName, RVFONT_WINGDINGS) = 0) then
    FontName := '''Arial Unicode MS'', ''Lucida Sans Unicode'', ''Arial'', ''Helvetica'', sans-serif'
  else
    FontName := '''' + FontName + '''';
  Span := '<span style="font-family : ' + Utf8Encode(FontName);
  if (TextStyle.Color <> clBlack) and (TextStyle.Color <> clWindowText) then
   Span := Span + '; color : ' + RV_GetHTMLRGBStr(TextStyle.Color, False);
  if TextStyle.BackColor <> clNone then
    Span := Span + '; background-color : ' + RV_GetCSSBkColor(TextStyle.BackColor);
  Span := Span + '">';
  Result := UTF8ToString(Span) + Result + '</span>';
end;
I had to use a hack (accessing protected method of TCustomRVData).

Re: Convert TextItem with text styles to html text

Posted: Wed Aug 02, 2017 8:34 pm
by saeid2016
Thank you very much.