home *** CD-ROM | disk | FTP | other *** search
/ ftp.alaska-software.com / 2014.06.ftp.alaska-software.com.tar / ftp.alaska-software.com / acsn / RTF100.TXT < prev    next >
Text File  |  2000-01-02  |  14KB  |  288 lines

  1. Notes on RichText() Class for Xbase++
  2. 12/16/1999
  3. Version 1.00
  4.  
  5. Author:     Paul C. Laney
  6. Internet:     pclaney@compuserve.com
  7.  
  8. Original idea: Tom Marchione, Internet: tmarchione@compuserve.com
  9.  
  10. RIGHTS/RESTRICTIONS
  11.  
  12. 1. All source code is Copyright c 1999 Paul C. Laney and Tom Marchione.  All rights 
  13. reserved, except as specifically indicated in this document.
  14. 2. As a Xbase++ user, you are granted the right to modify, compile and link the code for end-
  15. user application work, under the following conditions:
  16. a.    You do not redistribute the code without permission from the author.
  17. b.    All file headers are kept intact.
  18. c.    The source code and/or object modules are not offered for sale.
  19. d.    You do not port the code to another language, for other than personal use.
  20. e.    You do not offer a substantially competitive language product for sale or distribution.
  21. f.    You do not use the code in any kind of general purpose database management, reporting or 
  22. computer language application.
  23. g.    You do not use the code in any type of auditing or emergency response application (NOTE: 
  24. This restriction is based on the fact that the author has business interests in these markets.  If 
  25. you have an application in one of these markets, but would still like to use the RichText() 
  26. class, please contact the author.  Depending on the application and the market, it may be 
  27. possible to make alternate arrangements).
  28. h.    You accept complete responsibility for the use of the code and any effects that it might have.
  29. I.    You understand that future versions of the code may not be offered for free (although you 
  30. may continue to use this version for as long as you like).
  31.  
  32. CONTENTS OF VERSION 1.00
  33.  
  34. System Files:
  35.  
  36. README.RTF    This file
  37. README.TXT    Plain text version of this file
  38. ALASKRTF.PRG    Source code for RichText() class
  39. RICHTEXT.CH    Header file for RichText() class
  40. ADDON.PRG    Some extra functions which are used by the RichText()-class
  41.  
  42. Sample Files:
  43.  
  44. DEMRTF.PRG    Sample application to add to the TopDown-Demo
  45. FLOWERS.DBF    Database file used by sample application
  46. FLOWERS.DBT    Memo file associated with FLOWERS.DBF
  47. VEGGIES.DBF     Database file used by sample application
  48. RTFDEMO.RTF    Output file from sample application
  49. MERGEIN.RTF    Input file for sample application mailmerge 
  50. MERGEOUT.RTF    Output file from sample application mailmerge
  51.  
  52.  
  53. GETTING STARTED
  54.  
  55. If you're really curious about what this thing does, add the files to the Tddemo and compile and run 
  56. the application  Then open the output file (RTFDEMO.RTF and MERGEOUT.RTF) in an RTF-
  57. capable word processor.  If you don't have time to compile and run the app, I've included unedited 
  58. copies of the output files in the package.
  59. Which files you have to add to the TopDown-Demo.  Those files are:
  60.  
  61.     demRtf.prg
  62.     alaskrtf.prg
  63.     addon.prg
  64.     richtext.ch
  65.  
  66. and to the DATA subdirectory:
  67.  
  68.     flowers.dbf
  69.     flowers.dbt
  70.     veggies.dbf
  71.     rtfdemo.rtf
  72.     mergein.rtf
  73.     mergeout.rtf
  74.  
  75. Furthermore add the following lines to the bottom of your Project.xpj:
  76.  
  77.     // Richtext
  78.     demRtf.prg
  79.     alaskrtf.prg
  80.     addon.prg
  81.  
  82. Last, but not least, add the following lines to demoMenu.prg before the HELP section:
  83.  
  84.     ********** RICHTEXT **********
  85.     oSubMenu := XbpMenu():New( oMenuBar ):Create()
  86.     oSubMenu:title := "~Richtext"
  87.  
  88.     oSubmenu:AddItem( { "~RichText", {|| demRtf() } } )
  89.     oMenuBar:addItem( { oSubMenu, NIL } )
  90.  
  91. That's all
  92.  
  93. NOTE: As indicated in the RTFDEMO.RTF file, this file includes support for an automated table of 
  94. contents.  However, to see it, you need to insert it.  Consult your word processor documentation for 
  95. instructions, if you have never generated an automated table of contents.
  96.  
  97. REQUIREMENTS
  98.  
  99. RichText() was written for use in Xbase++ applications, in combination with the TopDown library.  
  100. Although it can also run without the TopDown-library (see WITHOUT TopDown).  To use the 
  101. class, you need to have a functional Xbase++ installation.  Thanks to the Xbase++ pre-processor, you 
  102. don't need to understand object-oriented programming to use the code.  However, if you decide to 
  103. fiddle with the source code of the underlying class, you will need to have a basic understanding of 
  104. object-orientation.
  105.  
  106. NOTE: By changing one or two user interface functions (TdMsg() and TdYesNo()), it should be 
  107. possible to use the class in pure DOS-based Xbase++ applications.  You have to change it into:
  108.  
  109. FUNCTION tdYesNo( cTxt )
  110. RETURN ( Alert( cTxt, { "Yes", "No" } ) == 1 )
  111.  
  112. FUNCTION TdMsg( cTxt )
  113.    Alert( cTxt )
  114. RETURN (NIL)
  115.  
  116. WITHOUT TopDown
  117.  
  118. The RichText-class can perfectly run without the TopDown-library.  You only need to rewrite the 
  119. functions tdYesNo() and tdMsg().  The DOS-based functions are shown above.
  120.  
  121. OVERVIEW
  122.  
  123. RichText() is a class written for Xbase++, designed to export formatted data directly to Rich Text 
  124. Format (RTF) files from within an application.  RichText() allows you to leverage the power of 
  125. common word processors as report formatting engines.
  126.  
  127. Version 1.0 of the class includes: (1) the source code, build and README files, (2) Xbase++ 
  128. directives for xBASE-style command implementation, and (3) a small sample prg.  Version 1.0 of 
  129. the class is being offered at no charge.  This version implements a small subset of the RTF 
  130. specification, as taken from Microsoft documentation.    RTF is a very detailed specification, and the 
  131. intent of Version 1.0 is to provide easy access to the most basic and useful features of RTF, 
  132. including attributes such as page setup, fonts, paragraph formatting, character formatting, headers & 
  133. footers, tables, etc.  To date, most of my testing has been done with Microsoft Word.
  134.  
  135. WHAT IS RTF?
  136.  
  137. RTF is an open Microsoft file specification for transferring formatted text between applications.  As 
  138. such, it it's a great way to move formatted database information into word processors, in a true 
  139. word processing format.
  140.  
  141. HOW CAN RTF HELP ME?
  142.  
  143. RTF is a great solution in at least three situations:
  144.  
  145. 1. When there is a need to manipulate output in word processors, or integrate database 
  146. information into other formatted documents.
  147. 2. When there is a requirement to build a custom report that must meet strict, detailed 
  148. formatting guidelines.
  149. 3. When there is a need to publish a "turnkey" report that might include different formats, page 
  150. orientations, fonts, etc. in a single document (my personal favorite_).
  151.  
  152. The RichText() class is a simple, low-overhead solution for any of these situations.  You can 
  153. produce one-of-a kind, free-form word-processing documents (for a good example, see the sample 
  154. provided with the class).  The class is inherently oriented toward paragraphs, bullets, hanging 
  155. indents, page orientation, etc., not standard database reporting fare such as column headers, 
  156. subtotals, etc. (although you can easily dump data into nicely-formatted tables).  Moreover, the 
  157. output files are true word-processing files, without extraneous spaces, carriage returns, and other 
  158. "lint" that makes life difficult in a word processing context.  If you have ever tried to pass off a flat 
  159. text output file (or even some RTF files produced by third party report generators) as "word 
  160. processor compatible", you'll know what I mean.  Compatible? Yes.  Usable? Hardly.
  161.  
  162.  
  163. ESSENTIAL FEATURES OF RTF
  164.  
  165. For detailed information about RTF, consult the Microsoft specification, which is available on the 
  166. Internet.  It is also helpful to analyze the contents of RTF files generated from word processors.  
  167. Although the xBASE layer of RichText() makes many of the technical details transparent, it will be 
  168. helpful to clarify a few issues here.
  169.  
  170. Like many "open" file formats, RTF files are text files.  RTF uses 7-bit ASCII characters (0-127) to 
  171. represent formatting codes and data (higher-order ASCII characters must be represented in 
  172. hexadecimal, which is handled transparently by RichText()).  The two essential formatting characters 
  173. in RTF are "\" (backslash) and "{}" (curly braces).  All formatting commands are preceded by a 
  174. backslash, and all "groups" are enclosed in curly braces.  Groups delineate portions of a document to 
  175. which combinations of formatting information may apply.  Groups can be nested; the RTF file itself 
  176. is considered a group, so all RTF files have at least one pair of curly braces, which encloses the 
  177. entire contents of the file.
  178.  
  179. All RTF files have an RTF header (which is to be distinguished from the headers and footers that 
  180. you may place in an RTF document).  The RTF header appears at the top of the file and contains 
  181. information about fonts, colors, styles, etc.  For example, the font table within the RTF header 
  182. contains a list of all of the fonts that are used in the document.  To switch fonts later the document, 
  183. an index into this font table must be used.  A similar system is used for colors.  The RichText() class 
  184. creates a basic RTF header for you.
  185.  
  186. An application that reads RTF files is called an "RTF viewer", which, for our purposes, is usually a 
  187. word processor.  For the most part, data items that you write to an RTF file appear within RTF 
  188. viewers in the sequence that you write them.  However certain RTF commands implement alternate 
  189. "destinations", such as headers and footers.  RTF also supports the "sections" that are found in 
  190. Microsoft Word, with section-specific layouts and formats. 
  191.  
  192.  
  193. FINAL NOTES
  194.  
  195. As I use the class more and more, it has become obvious to me that the class is more useful than I 
  196. had originally imagined.  As a result, I have spent a lot more time developing it than I had originally 
  197. imagined_ <g>.  In deference to the costs of adding new features, and improving the usability of 
  198. existing ones, I probably will not be able to distribute future versions of the class for free.  However, 
  199. the cost should be insignificant relative to the benefits that you can offer to your end users, and your 
  200. improved ability to give them exactly what they want for output.
  201.  
  202. Some additional features that are either planned for the future, or that are partially implemented 
  203. already, include.
  204.  
  205. Improved Control Over Table Output
  206. Improved Control Over Paragraph Formatting
  207. Improved Application-Level Components
  208. Colors
  209. Lines and graphic objects
  210. Pictures
  211. Styles
  212. Language Support
  213. Footnotes/Endnotes
  214. Positioned Objects and Frames
  215. Index Entries
  216. Bookmarks
  217. Anything else in the RTF spec that seems useful_
  218.  
  219. If all goes well, Version 2.0 will effectively become a complete database publishing tool, and we  
  220. will all become custom documentation gurus to our end users ...<g>.  In addition, I may develop a 
  221. companion class for use with Delphi (so far, in my limited use of Delphi, I have not come across a 
  222. class that generates comprehensive rich text output, although Delphi does provide an RTF-aware 
  223. control).
  224.  
  225. I greatly appreciate the feedback that I have received to date.  If you have any ideas or suggestions, 
  226. I'd love to hear them. 
  227.  
  228. Have fun!
  229.  
  230. Paul C. Laney
  231.  
  232. VERSION 1.00 FEATURE ADDITIONS
  233.  
  234. 1.    Page Number Support
  235.  
  236. You can add a simple page number via the INSERT PAGENUMBER command.  
  237. Typically, this is most useful when defined within a header or footer.
  238.  
  239. 2. File Checking
  240.  
  241.  When defining the RTF, the WARNOVERWRITE clause will cause the class to generate a 
  242. warning message if an existing file will be over-written.  In addition, you can use the 
  243. GETFILENAME and FORCEPATH clauses to allow the user to specify a file name, as 
  244. well as to force the file to be written to a specific path.
  245.  
  246. 3. Table of Contents Support
  247.  
  248. You can generate an automated table of contents.  You can mark any paragraph for inclusion 
  249. in a table of contents at a particular level by specifying the TOCLEVEL clause.  Refer to 
  250. the sample application for a simple example.
  251.  
  252.  
  253. VERSION 0.91 FEATURE ADDITIONS
  254.  
  255. Merge Away!
  256.  
  257. I added a crude subsystem and demonstration of how one could exploit RTF files for defining report 
  258. formats and merging database information into them.  With this system, you can embed Xbase++ 
  259. expressions throughout the "primary" merge file (which can be any old RTF), and then run a 
  260. relatively tiny Xbase++ program to merge your database info into it.  It's very much like a standard 
  261. "mail-merge" that you might do from a word processor, but with the sophistication and flexibility of 
  262. Xbase++.
  263.  
  264. For a simple, silly example, see files MERGEIN.RTF and MERGEOUT.RTF.  MERGEIN.RTF is a 
  265. "primary" merge file, and MERGEOUT.RTF is the actual file that is produced by the example 
  266. program.  Notice that MERGEIN.RTF contains a number of delimited Xbase++ expressions.  Most 
  267. of these are intended to return text, but I also threw in a couple examples to demonstrate how you 
  268. might control the record pointer from the merge file itself.  In other words, any valid, macro-
  269. compilable Xbase++ expression is fair game.  Of course, any functions that you call in the primary 
  270. merge file must be linked into your program (if this doesn't ring a bell, see the Xbase++ 
  271. documentation regarding "REQUEST").
  272.  
  273. The wonderful advantage of this approach is that you can effectively use a word processor (!) to 
  274. design a report format (for certain types of applications).  If you need to tweak the look of the 
  275. output, or even change it drastically, you just load up MS-Word and make the change to the primary 
  276. file -- no clumsy report writer, and no code changes.  And, of course, you get all of the power of a 
  277. true, word-processor based report.
  278.  
  279. The downside of the system, as it currently exists, is that it is very slow.  My algorithm is not 
  280. particularly efficient, and there are inherent speed limitations.  Not only does it have to macro 
  281. compile every Xbase++ expression that it encounters, it does it repeatedly for each record.  Arrrgh!  
  282. In addition, I have not yet included an error handler to trap bad Xbase++ expressions, though this 
  283. would be simple to do.
  284.  
  285. The system seems to work OK with the example, but be warned that I have not tested it with 
  286. anything else yet.  I imagine that it would be easy to make it self-destruct in its current incarnation...
  287.  
  288.