From 0bc1edfb956bec94811da7cafd1d6fba898dba07 Mon Sep 17 00:00:00 2001 From: Andi Jahja Date: Sat, 17 Jul 1999 00:47:46 +0000 Subject: [PATCH] Bug Fix --- harbour/tests/working/rtfclass.prg | 75 ++++++++++++++++-------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/harbour/tests/working/rtfclass.prg b/harbour/tests/working/rtfclass.prg index 735e5bb155..607beb9a7a 100644 --- a/harbour/tests/working/rtfclass.prg +++ b/harbour/tests/working/rtfclass.prg @@ -3,11 +3,15 @@ // /* -harbour rtfclass demo -notes : - raw enough but it works - - using hb_f*() - - rtf is assumed to have association -initial release : 23 June 1999 Andi Jahja + * harbour rtfclass demo + * notes : - raw enough but it works + - using hb_f*() - some compilers are not friendly with this :( + - rtf is assumed to have association + * initial release : 23 June 1999 Andi Jahja + * this program compiles fine on Borland C/C++ 5.0 + * tested under Windows 98 only with RTF associated to Winword + * works with printable ascii only + * placed in the public domain */ #define CRLF CHR(13) + CHR(10) @@ -16,15 +20,18 @@ function main() local ortf := trtf():new("test.rtf") local htest := fcreate( "rtf_test.txt") +local ctest := "" // create a plain text file -fwrite( htest, "This is +bHarbour © RTF Class-b" + CRLF ) -fwrite( htest, "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" + CRLF ) -fwrite( htest, "+bTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-b" + CRLF ) -fwrite( htest, "+iTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-i" + CRLF ) -fwrite( htest, "+buTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-bu" + CRLF ) -fwrite( htest, "+buiTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-bui" + CRLF ) -fwrite( htest, "THE +bQUICK-b +buBROWN-bu +buiFOX-bui +iJUMPS-i +uOVER-u +ilTHE-il +uLAZY-u +buDOG-bu" + CRLF ) +ctest += "This is +bHarbour © RTF Class-b" + CRLF +ctest += "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" + CRLF +ctest += "+bTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-b" + CRLF +ctest += "+iTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-i" + CRLF +ctest += "+buTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-bu" + CRLF +ctest += "+buiTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG-bui" + CRLF +ctest += "THE +bQUICK-b +buBROWN-bu +buiFOX-bui +iJUMPS-i +uOVER-u +ilTHE-il +uLAZY-u +buDOG-bu" + CRLF + +fwrite( htest, ctest ) fclose( htest ) // convert text file to rtf @@ -43,7 +50,6 @@ static oclass if oclass == nil oclass = tclass():new( "trtf" ) - oclass:adddata( "filename" ) oclass:adddata( "nhandle" ) oclass:addmethod( "new", @new() ) oclass:addmethod( "write", @write() ) @@ -54,10 +60,9 @@ return oclass:instance() static function new( cfilename ) local self := qself() -::filename = cfilename ::nhandle = fcreate( cfilename ) fwrite( ::nhandle,; - "{\rtf1\ansi\deff0{\fonttbl {\f0\fnil\fcharset0 Courier New;}{\f1\fnil\fcharset0 Arial;}}"+CRLF +; + "{\rtf1\ansi\deff0{\fonttbl {\f0\fnil\fcharset0 Courier New;}{\f1\fnil\fcharset0 Arial;}}"+; "\uc1\pard\lang1033\ulnone\f0\fs20"+CRLF) return self @@ -65,22 +70,24 @@ static function write( csource ) local self := qself() local cchar, cline, xatt, i, _xatt local n, nchar, xchar, y -// These are character attributes +// These are character attributes, self-defined +// + means a turn-on +// - means a turn-off local attrib := {; - { "+b" , "\b " },; - { "+bu" , "\ul\b " },; - { "+bi" , "\b\i " },; - { "+bui", "\ul\b\i " },; - { "+i" , "\i " },; - { "+il" , "\ul\i " },; - { "+u" , "\ul " },; - { "-b" , "\b0 " },; - { "-bu" , "\b0\ulnone " },; - { "-bi" , "\b0\i0 " },; - { "-bui", "\b0\i0\ulnone " },; - { "-i" , "\i0 " },; - { "-il" , "\ulnone\i0 " },; - { "-u" , "\ulnone " } } + { "+b" , "\b " } /* turn bold on*/ ,; + { "+bu" , "\ul\b " } /* turn bold_underline on */ ,; + { "+bi" , "\b\i " } /* turn bold_italic on */ ,; + { "+bui", "\ul\b\i " } /* turn bold_underline_italic on */ ,; + { "+i" , "\i " } /* turn italic on */ ,; + { "+il" , "\ul\i " } /* turn italic_underline on */ ,; + { "+u" , "\ul " } /* turn underline on */ ,; + { "-b" , "\b0 " } /* turn bold off */ ,; + { "-bu" , "\b0\ulnone " } /* turn bold_underline off */ ,; + { "-bi" , "\b0\i0 " } /* turn bold_italic off */ ,; + { "-bui", "\b0\i0\ulnone " } /* turn bold_underline_italic off */,; + { "-i" , "\i0 " } /* turn italic off */ ,; + { "-il" , "\ulnone\i0 " } /* turn italic_underline off */ ,; + { "-u" , "\ulnone " } /* turn underline off */ } hb_fuse( csource ) // open source file while !hb_feof() // read the file line by line @@ -89,9 +96,9 @@ while !hb_feof() // read the file line by line for nchar := 1 to y cchar := substr( cline, nchar, 1 ) - // TODO : I Need Function DEC2HEX() - // To Convert Numeric To 2-Characters HEX - // ie : DEC2HEX( "H" ) -> 48 + // todo : i need function dec2hex() + // to convert ascii to 2-characters hex + // ie : dec2hex( "H" ) -> 48 if cchar == "+" .or. cchar == "-" xatt := cchar + ; substr( cline, nchar + 1, 1 ) + ; @@ -122,7 +129,7 @@ while !hb_feof() // read the file line by line endif next fwrite( ::nhandle, CRLF ) - hb_fskip() // next line + hb_fskip() // read next line enddo hb_fuse() return ( self )