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.
Convert TextItem with text styles to html text
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Convert TextItem with text styles to html text
Do you want to save all text properties (font, color, etc.)?
Re: Convert TextItem with text styles to html text
only font, color and backcolorSergey Tkachenko wrote: ↑Wed Aug 02, 2017 3:43 pm Do you want to save all text properties (font, color, etc.)?
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Convert TextItem with text styles to html text
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;
Re: Convert TextItem with text styles to html text
Thank you very much.