|
source code not updated!
a lot of update has changed in lib file.I had to update the code according to discussions.I hope you could update your source code.
since your lib is compiled in single thread,while my project used mutil thread.so,I need compile it myself.
|
|
|
|
|
this lib is not able to create table embeded in table .this's really a pitty! course this is really important.
I tried to add this function to lib, Failed since I don't know much about rtf marks
|
|
|
|
|
Hi
I was just looking for such a tool, i.e. an engine which can drive the creation of an RTF file from source, i.e. without user interaction via CRichEditCtrl.
Please let me know if I may use this in order to embed the lib into a commercial sw or not and which is the cost if there is one.
Best regards and many thanks
Paolo
|
|
|
|
|
Hello,
thanks for the interest on control.
On the CodeProject web site all source code is free to download and modify according to your needs. The CPOL (Code Project Open Licence) is described here:
http://www.codeproject.com/info/cpol10.aspx[^]
So, the software (or the source code) is free to be used in any type of application: free or commercial.
If you feel you would like to make a donation, you are free to contact me directly on the following e-mail:
darko1978@open.telekom.rs
Best regards,
Darkoman
"Avaritia est radix omnium malorum..."
|
|
|
|
|
Very simple, clear and usefull!
|
|
|
|
|
I want add to the rtf file.
Like:
BOOL MergeRtf(CStrint strPath1,CString strPath2,CString strOutPath);
thanks for you reply !
|
|
|
|
|
I would like to understand how to set table width, table row width and paper width.
For paper width I have tried this, but there is no effect:
RTF_DOCUMENT_FORMAT * df = rtf_get_documentformat();
df->gt;marginLeft = 10;
df->gt;marginRight = 10;
df->gt;paperWidth= 850;
rtf_open( fileNameChar, font_list, color_list );
Thanks in advance.
|
|
|
|
|
I modified a copy to support the Chinese language,
I modified funciton rtf_write_header,change language
strcpy( rtfText, "{\\rtf1\\ansi\\ansicpg936\\deff0\\deflang1033\\deflangfe2052{\\fonttbl" );
modiyed fuciton rtf_init,to add chinese fonts
strcat( rtfFontTable, "{\\f0\\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}" );
strcat( rtfFontTable, "{\\f13\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'cb\\'ce\\'cc\\'e5{\\*\\falt SimSun};}" );
strcat( rtfFontTable, "{\\f17\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'ba\\'da\\'cc\\'e5{\\*\\falt SimHei};}" );
strcat( rtfFontTable, "{\\f109\\froman\\fcharset238\\fprq2 Times New Roman CE;}" );
strcat( rtfFontTable, "{\\f110\\froman\\fcharset204\\fprq2 Times New Roman Cyr;}" );
strcat( rtfFontTable, "{\\f55\\fmodern\\fcharset134\\fprq1{\\*\\panose 02010609030101010101}\\'bf\\'ac\\'cc\\'e5_GB2312;}" );
strcat( rtfFontTable, "{\\f621\\fnil\\fcharset0\\fprq2 @\\'cb\\'ce\\'cc\\'e5 Western;}" );
Add a funciton to translate chinese string to ascii string
string StrToASC(char* text)
{
string strResult;
int iLen = strlen(text);
for(int i = 0; i<iLen; i++)
{
BYTE chData = text[i];
if(chData > 0xa0 && chData != 0)
{
char szHex[12]={0};
wsprintf(szHex,"\\'%2.2x", chData);
strResult += szHex;
}
else
{
strResult += (char) chData;
}
}
return strResult;
}
then modified fuction rtf_start_paragraph,
int rtf_start_paragraph(char* text, bool newPar)
{
string strText = StrToASC(text);
int error = RTF_SUCCESS;
if(rtfParFormat.paragraphText)
{
delete[]rtfParFormat.paragraphText;
rtfParFormat.paragraphText = NULL;
}
rtfParFormat.paragraphText = new char[strText.size()+1];
strcpy( rtfParFormat.paragraphText, strText.c_str() );
rtfParFormat.newParagraph = newPar;
if( !rtf_write_paragraphformat() )
error = RTF_PARAGRAPHFORMAT_ERROR;
return error;
}
almost thoese are what i did,sorry for my pool English
PS,there are many memory leaks......
|
|
|
|
|
你好 我看了你那个支持中文显示的代码 发现StrToASC函数中for(int i = 0; i<iLen; i++)
和if(chData > 0xa0 && chData != 0)不明白什么意思 能不能解释一下
我现在正在作者方面的东西
|
|
|
|
|
这个是由于网页显示问题,实际上你要是懂html的话,你就懂了,比如>这个代表的是大于号,其它慢慢查吧,在html相关的符号说明有的
This is the web page display problems, in fact, if you know html, then you will understand, such as> this represents a greater-than symbol, the other you can check the book about html and you can find it
-- modified 20-Jul-12 2:12am.
|
|
|
|
|
你改编的能支持中文的工程能发给我学习一下吗 谢谢!
|
|
|
|
|
#include <SSTREAM>
#include <WINDOWS.H>
inline std::string InputToRTFstream(const char* input)
{
DWORD dwNum = ::MultiByteToWideChar (CP_ACP, 0, input, -1, NULL, 0);
wchar_t* wpstr = new wchar_t[::strlen(input) + 1];
::MultiByteToWideChar(CP_ACP, 0, input, -1, wpstr, dwNum);
std::wstring str(wpstr);
std::ostringstream sstr;
for(int i = 0; i < str.length(); i++)
{
sstr << "\\u" << wpstr[i] << " ";
}
delete[] wpstr;
return sstr.str();
}
|
|
|
|
|
Great!
Thanks.
Now supports Cyrillics!
|
|
|
|
|
I am using vst2005.
rebuilt the sample with the library as part of the source and got a stack corruption error around variable tblrw
int rtf_start_tablerow()
{
// Set error flag
int error = RTF_SUCCESS;
char tblrw[] = "";
tblrw is only allocated with 1 byte of storage in the original code
char tblrw[1024] = "";
fixes the stack.
|
|
|
|
|
IE, my application supports czech, polish and other european languages. I notice the API calls are all char*. Will it cope with these other languages?
|
|
|
|
|
I modified a copy to support the Chinese language,
I modified funciton rtf_write_header,change language
strcpy( rtfText, "{\\rtf1\\ansi\\ansicpg936\\deff0\\deflang1033\\deflangfe2052{\\fonttbl" );
modiyed fuciton rtf_init,to add chinese fonts
strcat( rtfFontTable, "{\\f0\\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}" );
strcat( rtfFontTable, "{\\f13\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'cb\\'ce\\'cc\\'e5{\\*\\falt SimSun};}" );
strcat( rtfFontTable, "{\\f17\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'ba\\'da\\'cc\\'e5{\\*\\falt SimHei};}" );
strcat( rtfFontTable, "{\\f109\\froman\\fcharset238\\fprq2 Times New Roman CE;}" );
strcat( rtfFontTable, "{\\f110\\froman\\fcharset204\\fprq2 Times New Roman Cyr;}" );
strcat( rtfFontTable, "{\\f55\\fmodern\\fcharset134\\fprq1{\\*\\panose 02010609030101010101}\\'bf\\'ac\\'cc\\'e5_GB2312;}" );
strcat( rtfFontTable, "{\\f621\\fnil\\fcharset0\\fprq2 @\\'cb\\'ce\\'cc\\'e5 Western;}" );
Add a funciton to translate chinese string to ascii string
string StrToASC(char* text)
{
string strResult;
int iLen = strlen(text);
for(int i = 0; i<iLen; i++)
{
BYTE chData = text[i];
if(chData > 0xa0 && chData != 0)
{
char szHex[12]={0};
wsprintf(szHex,"\\'%2.2x", chData);
strResult += szHex;
}
else
{
strResult += (char) chData;
}
}
return strResult;
}
almost thoese are what i did,sorry for my pool English
|
|
|
|
|
你好! 我也想让RTFLib支持中文 你说的 modiyed fuciton rtf_init,to add chinese fonts 是这样的形式
strcpy( rtfFontTable, "" );
strcat( rtfFontTable, "{\\f0\\froman\\fcharset0\\cpg1252 Times New Roman}" );
strcat( rtfFontTable, "{\\f1\\fswiss\\fcharset0\\cpg1252 Arial}" );
strcat( rtfFontTable, "{\\f2\\fmodern\\fcharset0\\cpg1252 Courier New}" );
strcat( rtfFontTable, "{\\f3\\fscript\\fcharset0\\cpg1252 Cursive}" );
strcat( rtfFontTable, "{\\f4\\fdecor\\fcharset0\\cpg1252 Old English}" );
strcat( rtfFontTable, "{\\f5\\ftech\\fcharset0\\cpg1252 Symbol}" );
strcat( rtfFontTable, "{\\f6\\fbidi\\fcharset0\\cpg1252 Miriam}" );
strcat( rtfFontTable, "{\\f13\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'cb\\'ce\\'cc\\'e5{\\*\\falt SimSun};}" );
strcat( rtfFontTable, "{\\f17\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'ba\\'da\\'cc\\'e5{\\*\\falt SimHei};}" );
strcat( rtfFontTable, "{\\f109\\froman\\fcharset238\\fprq2 Times New Roman CE;}" );
strcat( rtfFontTable, "{\\f110\\froman\\fcharset204\\fprq2 Times New Roman Cyr;}" );
strcat( rtfFontTable, "{\\f55\\fmodern\\fcharset134\\fprq1{\\*\\panose 02010609030101010101}\\'bf\\'ac\\'cc\\'e5_GB2312;}" );
strcat( rtfFontTable, "{\\f621\\fnil\\fcharset0\\fprq2 @\\'cb\\'ce\\'cc\\'e5 Western;}" );
还是这样的形式
strcat( rtfFontTable, "{\\f0\\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}" );
strcat( rtfFontTable, "{\\f13\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'cb\\'ce\\'cc\\'e5{\\*\\falt SimSun};}" );
strcat( rtfFontTable, "{\\f17\\fnil\\fcharset134\\fprq2{\\*\\panose 02010600030101010101}\\'ba\\'da\\'cc\\'e5{\\*\\falt SimHei};}" );
strcat( rtfFontTable, "{\\f109\\froman\\fcharset238\\fprq2 Times New Roman CE;}" );
strcat( rtfFontTable, "{\\f110\\froman\\fcharset204\\fprq2 Times New Roman Cyr;}" );
strcat( rtfFontTable, "{\\f55\\fmodern\\fcharset134\\fprq1{\\*\\panose 02010609030101010101}\\'bf\\'ac\\'cc\\'e5_GB2312;}" );
strcat( rtfFontTable, "{\\f621\\fnil\\fcharset0\\fprq2 @\\'cb\\'ce\\'cc\\'e5 Western;}" );
|
|
|
|
|
Nice work!
It's a pity there are so many memory leaks though.
I found an other one in rtf_load_image, near the end of the function there's:
char* str = rtf_bin_hex_convert( buffer, size );<br />
delete []buffer;
but str is never deleted. So add (at the end of the code block):
delete []str;
after:
strcpy( rtfText, "}" );<br />
fwrite( rtfText, 1, strlen(rtfText), rtfFile );
BTW: The code by MRSilver features the same leak
|
|
|
|
|
delete []str; //this is not enought for a good coder.
uselly, we set the pointer to null point,after we delete the memory. so it's best to be like this:
delte []str;
str=NULL;//"NULL" is for visual studio compiler.standarded C is "null"
|
|
|
|
|
Gday,
The rtflib was of great help for me. Nevertheless i met some quicks but these have been solved. Additionally i found one not yet discussed in this forum, so i want to share it with you.
In function rtf_write_paragraphformat -rather at the end of the function-, the actual writing to rtfFile takes place. All information is stored into the variable rtfText, which is an array of char of length 4096. When writing long texts, the upper bounds of rtfText are exceeded, which causes nasty errors. Therefore i propose to split the meta information and the actual text and write them separatedly:
<br />
if ( rtfParFormat.tabbedText == false )<br />
{<br />
sprintf( rtfText, "\n%s\\fi%d\\li%d\\ri%d\\sb%d\\sa%d\\sl%d%s ", text, <br />
rtfParFormat.firstLineIndent, rtfParFormat.leftIndent, <br />
rtfParFormat.rightIndent, rtfParFormat.spaceBefore, <br />
rtfParFormat.spaceAfter, rtfParFormat.lineSpacing, font );<br />
}<br />
else<br />
sprintf( rtfText, "\\tab " );<br />
<br />
if ( fwrite( rtfText, 1, strlen(rtfText), rtfFile ) < strlen(rtfText) )<br />
result = false;<br />
<br />
if ( fwrite( rtfParFormat.paragraphText, 1, <br />
strlen(rtfParFormat.paragraphText), rtfFile) < <br />
strlen(rtfParFormat.paragraphText))<br />
result = false;<br />
<br />
return result;<br />
<br />
21 cm, Hydrogens universal wavelength
|
|
|
|
|
First thanks for sharing your work.
You can load images with less memory and less code:
IPicture* pPic;<br />
HRESULT hr = OleLoadPicturePath(const_cast<LPOLESTR>(pszImagePath),<br />
NULL,<br />
0,<br />
0,<br />
IID_IPicture,<br />
reinterpret_cast<LPVOID *>(&pPic));<br />
if(SUCCEEDED(hr) && pPic!= NULL)<br />
{<br />
....<br />
}
instead of:
int imageFile = _open( image, _O_RDONLY | _O_BINARY );<br />
struct _stat st;<br />
_fstat( imageFile, &st );<br />
DWORD nSize = st.st_size;<br />
BYTE* pBuff = new BYTE[nSize];<br />
_read( imageFile, pBuff, nSize );<br />
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);<br />
void* pData = GlobalLock(hGlobal);<br />
memcpy(pData, pBuff, nSize);<br />
GlobalUnlock(hGlobal);<br />
IStream* pStream = NULL;<br />
if ( CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK )<br />
{<br />
HRESULT hr;<br />
if ((hr = OleLoadPicture( pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&rtfPicture)) != S_OK)<br />
error = RTF_IMAGE_ERROR;<br />
<br />
pStream->Release();<br />
}<br />
delete []pBuff;<br />
_close(imageFile);
Thanks again,
Abbas
|
|
|
|
|
Is there a way to set the document to be in landscape instead of protrait mode?
Thanks
|
|
|
|
|
thanks for share although haven't read the code thoroughly, i want to know if it can show jpg files directly in that rtf file.
|
|
|
|
|
I love it extremely, thanks
|
|
|
|
|
Hi, I have a template named hf.dot in which I have defined a header. I want to generate a RTF file that shows that header. Inside the RTF file, I can link to the template and use it's styles with a code like this:
{\template c:\\hf.dot}\linkstyles
but I don't know how to use the header. Any idea ?
|
|
|
|
|