home *** CD-ROM | disk | FTP | other *** search
/ ftp.alaska-software.com / 2014.06.ftp.alaska-software.com.tar / ftp.alaska-software.com / acsn / Rtf150.txt < prev    next >
Text File  |  2003-06-01  |  15KB  |  323 lines

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