1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| AnsiString TForm1::ConvertRtf2HTML()
{
Memo->SelStart = 0;
Memo->SelLength = 1;
AnsiString precFont = Memo->SelAttributes->Name;
int precSize = Memo->SelAttributes->Size;
TColor precColor = Memo->SelAttributes->Color;
bool isBold=false;
bool isItalic=false;
bool isUnderline=false;
bool isFont=false;
AnsiString chaine_html = "";
int i;
if(Memo->Text == ""){
}else{
for(i=1;i<=Memo->Text.Length();i++)
{
Memo->SelStart = i-1;
Memo->SelLength = 1;
if(precFont != Memo->SelAttributes->Name || precSize != Memo->SelAttributes->Size || precColor != Memo->SelAttributes->Color || i==1){
if(isFont){
chaine_html+="</font>";
}
isFont=true;
chaine_html+= "<font face=\"" + Memo->SelAttributes->Name + "\" style=\"font-size:" + AnsiString(Memo->SelAttributes->Size) + "px\" color=\"#" + ConvertColor(Memo->SelAttributes->Color) + "\">";
}
if(!(Memo->SelAttributes->Style == (TFontStyles() << fsBold)) && isBold){
chaine_html+="</b>";
}
if(!(Memo->SelAttributes->Style == (TFontStyles() << fsItalic)) && isItalic){
chaine_html+="</i>";
}
if(!(Memo->SelAttributes->Style == (TFontStyles() << fsUnderline)) && isUnderline){
chaine_html+="</u>";
}
if((Memo->SelAttributes->Style == (TFontStyles() << fsBold)) && !isBold){
chaine_html+="<b>";
}
if((Memo->SelAttributes->Style == (TFontStyles() << fsItalic)) && !isItalic){
chaine_html+="<i>";
}
if((Memo->SelAttributes->Style == (TFontStyles() << fsUnderline)) && !isUnderline){
chaine_html+="<u>";
}
precFont = Memo->SelAttributes->Name;
precSize = Memo->SelAttributes->Size;
precColor = Memo->SelAttributes->Color;
isBold = Memo->SelAttributes->Style == (TFontStyles() << fsBold);
isItalic = Memo->SelAttributes->Style == (TFontStyles() << fsItalic);
isUnderline = Memo->SelAttributes->Style == (TFontStyles() << fsUnderline);
chaine_html += Memo->Text[i];
}
}
if(isFont){
chaine_html+="</font>";
}
if(isBold){
chaine_html+="</b>";
}
if(isItalic){
chaine_html+="</i>";
}
if(isUnderline){
chaine_html+="</u>";
}
return chaine_html;
} |