- Code: Select all Expand view RUN
#include "FiveWin.ch"
FUNCTION Main()
LOCAL cRtf, oDlg
LOCAL cString := ""
// Insert the HTML code directly into the cString variable
cString += "This is a complex text, colored and formatted by Fivewin. <br><br>"
cString += "<font color=#FF0000>RED</font><br>"
cString += "<font color=#008800>GREEN</font><br>"
cString += "<font color=#0000FF>BLUE</font><br><br>"
cString += "<b>Bold Text</b> <br>"
cString += "<i>Italic Text</i> <br>"
cString += "<u>Underlined Text</u> <br>"
// Add a Table 2 row 2 columns
cString += "<table border='1'>"
cString += "<tr><td>Header 1</td><td>Header 2</td></tr>"
cString += "<tr><td>Cella 1</td><td>Cella 2</td></tr>"
cString += "</table><br>"
// add a link
cString += "<a href='http://www.example.com'>Link</a><br>"
// Convert HTML code to RTF format
cRtf := HtmlToRtf(cString)
//Create a dialog box to show formatted text
TestRtfM(cRtf)
RETURN NIL
FUNCTION HtmlToRtf(cString)
LOCAL cRtf := ""
LOCAL cTemp := cString
cTemp := StrTran(cTemp, "<html>", "")
cTemp := StrTran(cTemp, "<body>", "")
cTemp := StrTran(cTemp, "</html>", "")
cTemp := StrTran(cTemp, "</body>", "")
// Sostituisci i tag HTML con codici RTF corrispondenti
cTemp := StrTran(cTemp, "<br>", "\line ")
cTemp := StrTran(cTemp, "<b>", "{\b ")
cTemp := StrTran(cTemp, "</b>", "\b0}")
cTemp := StrTran(cTemp, "<i>", "{\i ")
cTemp := StrTran(cTemp, "</i>", "\i0}")
cTemp := StrTran(cTemp, "<u>", "{\ul ")
cTemp := StrTran(cTemp, "</u>", "\ulnone}")
cTemp := StrTran(cTemp, "<font color=#FF0000>", "{\cf1 ")
cTemp := StrTran(cTemp, "<font color=#008800>", "{\cf2 ")
cTemp := StrTran(cTemp, "<font color=#0000FF>", "{\cf3 ")
cTemp := StrTran(cTemp, "</font>", "}")
// Aggiungi il supporto per le tabelle
cTemp := StrTran(cTemp, "<table border='1'>", "\pard\intbl\itap0\plain\ltrpar{\trowd\trgaph70\trleft-70")
cTemp := StrTran(cTemp, "<tr>", "\trbrdrt\brdrdb\cell ")
cTemp := StrTran(cTemp, "</tr>", "\cell\cell\row}")
cTemp := StrTran(cTemp, "<td>", "")
cTemp := StrTran(cTemp, "</td>", "\cell")
cTemp := StrTran(cTemp, "border='1'", "\brdrw10\brdrs")
cTemp := StrTran(cTemp, "</table>", "\par}")
// Aggiungi il supporto per i link
cTemp := StrTran(cTemp, "<a href=", " {\field{\*\fldinst{HYPERLINK ")
cTemp := StrTran(cTemp, "</a>", "}}{\fldrslt ")
cTemp := StrTran(cTemp, ">", "")
// Altri tag HTML supportati
cTemp := StrTran(cTemp, "<h1>", "{\fs40 ")
cTemp := StrTran(cTemp, "</h1>", "\line }")
cTemp := StrTran(cTemp, "<h2>", "{\fs32 ")
cTemp := StrTran(cTemp, "</h2>", "\line }")
cTemp := StrTran(cTemp, "<h3>", "{\fs24 ")
cTemp := StrTran(cTemp, "</h3>", "\line }")
cTemp := StrTran(cTemp, "<p>", "\line ")
cTemp := StrTran(cTemp, "</p>", "\line ")
cTemp := StrTran(cTemp, "<div>", "\line ")
cTemp := StrTran(cTemp, "</div>", "\line ")
cTemp := StrTran(cTemp, "<span>", "")
cTemp := StrTran(cTemp, "</span>", "")
cTemp := StrTran(cTemp, "<em>", "{\i ") //Italic
cTemp := StrTran(cTemp, "</em>", "\i0")
cTemp := StrTran(cTemp, "<strong>", "{\b ") //bold
cTemp := StrTran(cTemp, "</strong>", "\b0")
cTemp := StrTran(cTemp, "<sup>", "{\super ") // Superscript
cTemp := StrTran(cTemp, "</sup>", "\nosupersub")
cTemp := StrTran(cTemp, "<sub>", "{\sub ") // SubScript
cTemp := StrTran(cTemp, "</sub>", "\nosupersub")
// Costruisci la stringa RTF finale
cRtf := "{\rtf1\ansi\deff0{\fonttbl\f0\fcharset0 Courier;}{\colortbl;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;}"
cRtf += cTemp
cRtf += "}"
RETURN cRtf
FUNCTION TestRtfM(cRtf)
local oWnd
// logfile("silvio.txt", cRtf )
DEFINE WINDOW ownd
oWnd:bPainted := { || oWnd:SayText( cRtf ) }
ACTIVATE WINDOW oWnd CENTERED
return nil
Run all but on Rtf the table is not created good,also the link tag not run ok