RTF File Writer ( Was : RTF ) 
Author Message
 RTF File Writer ( Was : RTF )

This is a very dirty codes. But it works.
Font is Courrier-New as default. I choose it because it is fix in size
so making formating report more easy rather than a proportional one.
No coloring yet. Would love if other Clipperheads make enhancement.

*+22222222222222222222222222222222222222222222222222222222222222222222
*+
*+    Source Module => C:\TEMP\RTF.PRG
*+
*+    RTF File Generator By Andi Jahja
*+
*+    Functions: Procedure main()
*+               Function rtf_create()
*+               Function rtf_write()
*+               Function rtf_endcenter()
*+               Function rtf_close()
*+
*+    Reformatted by Click! 2.01 on Jan-20-1999 at  3:21 pm
*+
*+22222222222222222222222222222222222222222222222222222222222222222222

#define CRLF chr(13)+chr(10)
#define RTF_PLAIN                                                   1
#define RTF_BOLD                                                    2
#define RTF_BOLD_UNDERLINED                                         3
#define RTF_ITALIC_BOLD                                             4
#define RTF_ITALIC_BOLD_UNDERLINED                                  5
#define RTF_PLAIN_UNDERLINED                                        6
#define RTF_PLAIN_ITALIC                                            7
#define RTF_PLAIN_ITALIC_UNDERLINED                                 8
#define RTF_CENTERED                                                9
#define RTF_CENTERED_BOLD                                          10
#define RTF_CENTERED_BOLD_UNDERLINED                               11
#define RTF_CENTERED_ITALIC_BOLD                                   12
#define RTF_CENTERED_ITALIC_BOLD_UNDERLINED                        13
#define RTF_CENTERED_PLAIN_UNDERLINED                              14
#define RTF_CENTERED_PLAIN_ITALIC                                  15
#define RTF_CENTERED_PLAIN_ITALIC_UNDERLINED                       16

*+
*+
*+    Procedure main()
*+
*+
*+
proc main()
local nhandle
local c_text  := "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"

if ( nhandle := rtf_create( "MYRTF.RTF" ) ) <> - 1
   rtf_write( nhandle, "This is a test of RTF Generation" )
   rtf_write( nhandle, "RTF File Will Enable You To Print Nice Looking
Report" )
   rtf_write( nhandle )
   rtf_write( nhandle, c_text, RTF_PLAIN )
   rtf_write( nhandle, c_text, RTF_BOLD )
   rtf_write( nhandle, c_text, RTF_BOLD_UNDERLINED )
   rtf_write( nhandle, c_text, RTF_ITALIC_BOLD )
   rtf_write( nhandle, c_text, RTF_ITALIC_BOLD_UNDERLINED )
   rtf_write( nhandle, c_text, RTF_PLAIN_UNDERLINED )
   rtf_write( nhandle, c_text, RTF_PLAIN_ITALIC )
   rtf_write( nhandle, c_text, RTF_PLAIN_ITALIC_UNDERLINED )
   rtf_write( nhandle )
   rtf_write( nhandle, "Now We Make All Centered", RTF_PLAIN )
   rtf_write( nhandle )
   rtf_write( nhandle, c_text, RTF_CENTERED )
   rtf_write( nhandle, c_text, RTF_CENTERED_BOLD )
   rtf_write( nhandle, c_text, RTF_CENTERED_BOLD_UNDERLINED )
   rtf_write( nhandle, c_text, RTF_CENTERED_ITALIC_BOLD )
   rtf_write( nhandle, c_text, RTF_CENTERED_ITALIC_BOLD_UNDERLINED )
   rtf_write( nhandle, c_text, RTF_CENTERED_PLAIN_UNDERLINED )
   rtf_write( nhandle, c_text, RTF_CENTERED_PLAIN_ITALIC )
   rtf_write( nhandle, c_text, RTF_CENTERED_PLAIN_ITALIC_UNDERLINED )
   rtf_endcenter( nhandle )
   rtf_write( nhandle, "End Of Test" )
   rtf_close( nhandle )
endif
return

*+
*+
*+    Function rtf_create()
*+
*+    Called from ( rtf.prg      )   1 - procedure main()
*+
*+
*+
function rtf_create( cfile )
local nhandle := fcreate( cfile )
if nhandle <> - 1
   fwrite( nhandle, "{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss
"+;
      "MS Sans Serif;}{\f1\froman\fcharset2
Symbol;}{\f2\fmodern\fcharset1 "+;
      "Courier New;}{\f3\fmodern\fcharset1 Courier New;}}" + CRLF )
   fwrite( nhandle, "{\colortbl\red0\green0\blue0;}" + CRLF )
   fwrite( nhandle, "\deflang1033\pard\plain\f2\fs18\cf0" + CRLF )
endif
return nhandle

*+
*+
*+    Function rtf_write()
*+
*+    Called from ( rtf.prg      )  23 - procedure main()
*+
*+
*+
function rtf_write( nhandle, ctext, nstyle )
local astyle := ;
   { ;
     "\par \plain\f2\fs18\cf0",;
     "\par \plain\f2\fs18\cf0\b",;
     "\par \plain\f2\fs18\cf0\b\ul",;
     "\par \plain\f2\fs18\cf0\b\i",;
     "\par \plain\f2\fs18\cf0\b\i\ul",;
     "\par \plain\f2\fs18\cf0\ul",;
     "\par \plain\f2\fs18\cf0\i",;
     "\par \plain\f2\fs18\cf0\i\ul",;
     "\par \pard\qc\plain\f2\fs18\cf0",;
     "\par \pard\qc\plain\f2\fs18\cf0\b",;
     "\par \pard\qc\plain\f2\fs18\cf0\b\ul",;
     "\par \pard\qc\plain\f2\fs18\cf0\b\i",;
     "\par \pard\qc\plain\f2\fs18\cf0\b\i\ul",;
     "\par \pard\qc\plain\f2\fs18\cf0\ul",;
     "\par \pard\qc\plain\f2\fs18\cf0\i",;
     "\par \pard\qc\plain\f2\fs18\cf0\i\ul" }

if empty( ctext )
   fwrite( nhandle, "\par" + CRLF )
   return .t.
endif

if nstyle == nil
   nstyle := 1
endif
fwrite( nhandle, astyle[ nstyle ] + " " + ctext + CRLF )

return .t.

*+
*+
*+    Function rtf_endcenter()
*+
*+    Called from ( rtf.prg      )   1 - procedure main()
*+
*+
*+
function rtf_endcenter( nhandle )
fwrite( nhandle, "\par \pard\plain\f2\fs18\cf0" + CRLF )
return .t.

*+
*+
*+    Function rtf_close()
*+
*+    Called from ( rtf.prg      )   1 - procedure main()
*+
*+
*+
function rtf_close( nhandle )
fwrite( nhandle, "\par }" + CRLF )
return fclose( nhandle )

*+ EOF: RTF.PRG

--
Andi Jahja <see headers for my e-address>



Sun, 08 Jul 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. rtf reader\writer

2. How to convert WMF files to RTF files?

3. Need Objects that Parse RTF files!!!

4. RTF output to file

5. Create RTF file

6. Opinion: Memo or RTF files

7. help source file - ipf to rtf format

8. Write RTF File From CFD APP

9. CW-Report -----> RTF-File

10. Printing .RTF file in a report as detail

11. how do i make a rtf-file

12. Printing RTF Files From DOS ?

 

 
Powered by phpBB® Forum Software