środa, 28 października 2009

Konwersja string na RTF

CString StrToRTF(CString str)
{

CString szRtfEnd = "}";
CString szRtfEnter = "\\par \\pard\\fi0\\li0\\ql\\ri0\\sb0\\sa0\\itap0 ";
CString szOut =
"{\\rtf1\\ansi\\ansicpg0\\uc1\\deff0\\deflang0\\deflangfe0{\\fonttbl{\\f0\\fnil\\fcharset1 Times New Roman;}{\\f1\\fnil\\fcharset1 Arial;}{\\f2\\fnil\\fcharset1 Verdana;}{\\f3\\fnil\\fcharset1 Courier New;}}\n"
"{\\colortbl;\\red0\\green0\\blue0;\\red0\\green0\\blue255;\\red0\\green255\\blue255;\\red0\\green255\\blue0;\\red255\\green0\\blue255;\\red255\\green0\\blue0;\\red255\\green255\\blue0;\\red255\\green255\\blue255;\n"
"\\red0\\green0\\blue128;\\red0\\green128\\blue128;\\red0\\green128\\blue0;\\red128\\green0\\blue128;\\red128\\green0\\blue0;\\red128\\green128\\blue0;\\red128\\green128\\blue128;\\red192\\green192\\blue192;}\n"
"\n\r"
"\\uc1\n\r"
"\\pard\\fi0\\li0\\ql\\ri0\\sb0\\sa0\\itap0 \\plain \\f3\\fs20\n\r";

str.Replace("\r\n",szRtfEnter);


CString szHex;
CString szBuf;

char buffer[10];// w tej tablicy znakowej będzie umieszczony wynik konwersji
for (int i=128; i<=256 ;i++)
 {
  itoa(i, buffer, 16);// konwersja na system szesnastkowy
  szHex = "0x";
  szHex += buffer;  
  szBuf = "\\'";
  szBuf +=buffer;    
  str.Replace((CString)(char)i,szBuf);  
 }

 szOut +=str;
 szOut +=szRtfEnd;

 return szOut;
}

Brak komentarzy:

Prześlij komentarz