home *** CD-ROM | disk | FTP | other *** search
/ ftp.alaska-software.com / 2014.06.ftp.alaska-software.com.tar / ftp.alaska-software.com / acsn / RTF100.ZIP / Richtext.ch < prev   
Text File  |  1999-12-16  |  9KB  |  230 lines

  1. /*
  2. ┌──────────────────────────────────────────────────────────────────────────┐
  3. │        Class: RichText                                                   │
  4. │  Description: System for generating RTF output files                     │
  5. │     Language: Xbase++                                                    │
  6. │      Version: 1.00                                                       │
  7. │         Date: 12/16/1999                                                 │
  8. │       Author: Paul C. Laney, based on the work of Tom Marchione          │
  9. │               (tmarchione@compuserve.com )                               │
  10. │     Internet: pclaney@compuserve.com                                     │
  11. │                                                                          │
  12. │    Copyright: (C) 1999, Paul C. Laney                                    │
  13. │       Rights: There are some restrictions to the use of this code.       │
  14. │               Please read the README file that accompanied this code     │
  15. │               before using it or modifying it.                           │
  16. │                                                                          │
  17. │   Warranties: None. The code has not been rigorously tested in a formal  │
  18. │               development environment, and is offered as-is.  The author │
  19. │               assumes no responsibility for its use, or for any          │
  20. │               consequences that may arise from its use.                  │
  21. │                                                                          │
  22. │    Revisions:                                                            │
  23. │                                                                          │
  24. │    DATE       AUTHOR  COMMENTS                                           │
  25. │──────────────────────────────────────────────────────────────────────────│
  26. │    (see class code for change summary)                                   │
  27. └──────────────────────────────────────────────────────────────────────────┘
  28. */
  29.  
  30.  
  31. #define INCH_TO_TWIP 1440
  32.  
  33. // Text Styles
  34. // These are special cases, defined with the RTF backslash, so that
  35. // they can be easily concatenated at the application level.
  36.  
  37. #define BOLD_ON       "\b"
  38. #define ITALIC_ON     "\i"
  39. #define UNDERLINE_ON  "\ul"
  40. #define CAPS_ON       "\caps"
  41.  
  42. #define STYLE_OFF     "0"
  43. #define BOLD_OFF      BOLD_ON + STYLE_OFF
  44. #define ITALIC_OFF    ITALIC_ON + STYLE_OFF
  45. #define UNDERLINE_OFF UNDERLINE_ON + STYLE_OFF
  46. #define CAPS_OFF      CAPS_ON + STYLE_OFF
  47.  
  48.  
  49. // DEFAULTS:
  50.  
  51. // Font:        Courier New
  52. // Font Size:   12 Point
  53. // Units:       Inches (i.e., same as "TWIPFACTOR INCH_TO_TWIP")
  54. // Page Setup:  Standard RTF file format defaults
  55.  
  56.  
  57. #xcommand DEFINE RTF [<oRTF>] ;
  58.         [ <filename: FILE, FILENAME> <cFileName> ] ;
  59.         [ <fontname: FONTS, FONTNAMES> <aFontData,...> ] ;
  60.         [ FONTSIZE <nFontSize> ] ;
  61.         [ TWIPFACTOR <nScale> ] ;
  62.         [ HIGHORDERMAP <aHigh> ] ;
  63.         [ <lWarn: WARNOVERWRITE> ] ; // added 10/8/97
  64.         [ <lGetFile: GETFILENAME> FORCEPATH <cPath> ] ; // added 10/8/97
  65.     => ;
  66.         [ <oRTF> := ] RichText():New( <cFileName>, [\{<aFontData>\}], ;
  67.                     <nFontSize>, <nScale>, <aHigh>, <.lWarn.>, ;
  68.                     <.lGetFile.>, <cPath> )
  69.  
  70. #xcommand CLOSE RTF <oRTF> => <oRTF>:xEnd()
  71.  
  72.  
  73. // If used, DEFINE PAGESETUP should come immediately after DEFINE RTF
  74. // NOTE: Page numbering is not supported yet in base class
  75.  
  76. #xcommand DEFINE PAGESETUP <oRTF> ;
  77.         [ MARGINS <nLeft>, <nRight>, <nTop>, <nBottom> ] ;
  78.         [ PAGEWIDTH <nWidth> ] ;
  79.         [ PAGEHEIGHT <nHeight> ] ;
  80.         [ TABWIDTH <nTabWidth> ] ;
  81.         [ <landscape: LANDSCAPE> ] ;
  82.         [ <lNoWidow: NOWIDOW> ] ;
  83.         [ ALIGN <vertalign: TOP, BOTTOM, CENTER, JUSTIFY> ] ;
  84.         [ PAGENUMBERS <cPgnumPos: LEFT, RIGHT, CENTER> ] ; // not supported
  85.         [ <lPgnumTop: PAGENUMBERTOP> ] ; // not supported
  86.     => ;
  87.         <oRTF>:PageSetup( <nLeft>, <nRight>, <nTop>, <nBottom>, ;
  88.                  <nWidth>, <nHeight>, <nTabWidth>, <.landscape.>, <.lNoWidow.>, ;
  89.                  <"vertalign"> , <cPgnumPos>, <.lPgnumTop.> )
  90.  
  91.  
  92. // Use these to enclose data to be included in headers & footers
  93. #xcommand BEGIN HEADER <oRTF> => <oRTF>:BeginHeader()
  94. #xcommand END HEADER <oRTF> => <oRTF>:EndHeader()
  95.  
  96. #xcommand BEGIN FOOTER <oRTF> => <oRTF>:BeginFooter()
  97. #xcommand END FOOTER <oRTF> => <oRTF>:EndFooter()
  98.  
  99.  
  100.  
  101. // Use this to write formatted text within a paragraph
  102. #xcommand WRITE TEXT <oRTF> ;
  103.         [ TEXT <cText> ] ;
  104.         [ FONTNUMBER <nFontNumber> ] ;
  105.         [ FONTSIZE <nFontSize> ] ;
  106.         [ APPEARANCE <cAppear> ] ;
  107.         [ <lDefault: SETDEFAULT > ] ; // This is very quirky in this version...
  108.     => ;
  109.         <oRTF>:Paragraph( <cText>, <nFontNumber>, <nFontSize>, <cAppear>, ;
  110.                 ,,,,,,,,,,,,,, <.lDefault.>, .T. )
  111.  
  112. // Use this to write an entire paragraph, with optional formatting.
  113. #xcommand NEW PARAGRAPH <oRTF> ;
  114.         [ TEXT <cText> ] ;
  115.         [ FONTNUMBER <nFontNumber> ] ;
  116.         [ FONTSIZE <nFontSize> ] ;
  117.         [ APPEARANCE <cAppear> ] ;
  118.         [ ALIGN <cHorzAlign: LEFT, RIGHT, CENTER, JUSTIFY> ] ;
  119.         [ TABSTOPS <aTabPos,...> ] ;
  120.         [ <indent: INDENT, LEFTINDENT> <nIndent> ] ;
  121.         [ FIRSTINDENT <nFIndent> ] ;
  122.         [ RIGHTINDENT <nRIndent> ] ;
  123.         [ LINESPACE <nSpace> [ <lSpExact: ABSOLUTE>] ] ;
  124.         [ SPACEBEFORE <nBefore> ] ;
  125.         [ SPACEAFTER <nAfter> ] ;
  126.         [ <lNoWidow: NOWIDOW> ] ;
  127.         [ <lBreak: NEWPAGE > ] ;
  128.         [ <lBullet: BULLET, BULLETED > [ BULLETCHAR <cBulletChar> ];
  129.             [ HANGING <lHang> ] ] ;
  130.         [ <lDefault: SETDEFAULT > ] ;
  131.         [ <lNoPar: NORETURN> ] ; // This can have uneven results.
  132.         [ TOCLEVEL <nTCLevel> ] ;
  133.     => ;
  134.         <oRTF>:Paragraph( <cText>, <nFontNumber>, <nFontSize>, <cAppear>, ;
  135.                 <"cHorzAlign">, [\{<aTabPos>\}], <nIndent>, ;
  136.                 <nFIndent>, <nRIndent>, <nSpace>, <.lSpExact.>, ;
  137.                 <nBefore>, <nAfter> , <.lNoWidow.>, <.lBreak.>, ;
  138.                 <.lBullet.>, <cBulletChar>, <.lHang.>, <.lDefault.>, <.lNoPar.>, ;
  139.                 <nTCLevel> )
  140.  
  141.  
  142. // Use this to begin a new table
  143. #xcommand DEFINE TABLE <oRTF> ;
  144.         [ ALIGN <cHorzAlign: LEFT, RIGHT, CENTER> ] ;
  145.         [ FONTNUMBER <nFontNumber> ] ;
  146.         [ FONTSIZE <nFontSize> ] ;
  147.         [ CELLAPPEAR <cCellAppear> ] ;
  148.         [ CELLHALIGN <cCellHAlign: LEFT, RIGHT, CENTER> ] ;
  149.         [ ROWS <nRows> ] ;
  150.         [ COLUMNS <nColumns> ] ;
  151.         [ CELLWIDTHS <aColWidths,...> ] ;
  152.         [ ROWHEIGHT <nHeight> ] ;
  153.         [ ROWBORDERS <cRowBorder: SINGLE, DOUBLETHICK, SHADOW, DOUBLE, ;
  154.             DOTTED, DASHED, HAIRLINE > ] ;
  155.         [ CELLBORDERS <cCellBorder: SINGLE, DOUBLETHICK, SHADOW, DOUBLE, ;
  156.             DOTTED, DASHED, HAIRLINE > ] ;
  157.         [ CELLSHADE <nCellPct> ] ;
  158.         [ <lNoSplit: NOSPLIT> ] ;
  159.         [ HEADERROWS <nHeadRows> ;
  160.             [ HEADERHEIGHT <nHeadHgt> ] ;
  161.             [ HEADERSHADE <nHeadPct> ] ;
  162.             [ HEADERFONT <nHeadFont> ] ;
  163.             [ HEADERFONTSIZE <nHFontSize> ] ;
  164.             [ HEADERAPPEAR <cHeadAppear> ] ;
  165.             [ HEADERHALIGN <cHeadHAlign: LEFT, RIGHT, CENTER> ] ;
  166.         ] ;
  167.     => ;
  168.         <oRTF>:DefineTable( <"cHorzAlign">, <nFontNumber>, <nFontSize>, ;
  169.                 <cCellAppear>, <"cCellHAlign">, <nRows>, ;
  170.                 <nColumns>, <nHeight>, [\{<aColWidths>\}], <"cRowBorder">, ;
  171.                 <"cCellBorder">, <nCellPct>, <.lNoSplit.>, <nHeadRows>, ;
  172.                 <nHeadHgt>, <nHeadPct>, <nHeadFont>, <nHFontSize>, ;
  173.                 <cHeadAppear>, <"cHeadHAlign"> )
  174.  
  175.  
  176. #xcommand CLOSE TABLE oRTF => oRTF:EndRow() ; oRTF:TextCode("pard")
  177.  
  178.  
  179. // Use this to begin/end a row of the table
  180. // NOTE: After the first row, the class will automatically
  181. // start new rows as necessary, based on # of columns
  182.  
  183. #xcommand BEGIN ROW oRTF => oRTF:BeginRow()
  184. #xcommand END ROW oRTF => oRTF:EndRow()
  185.  
  186.  
  187. // Use this to write the next cell in a table
  188. #xcommand WRITE CELL <oRTF> ;
  189.         [ TEXT <cText> ] ;
  190.         [ FONTNUMBER <nFontNumber> ] ;
  191.         [ FONTSIZE <nFontSize> ] ;
  192.         [ APPEARANCE <cAppear> ] ;
  193.         [ ALIGN <cHorzAlign: LEFT, RIGHT, CENTER, JUSTIFY> ] ;
  194.         [ LINESPACE <nSpace> [ <lSpExact: ABSOLUTE>] ] ;
  195.         [ CELLBORDERS <cCellBorder: SINGLE, DOUBLETHICK, SHADOW, DOUBLE, ;
  196.             DOTTED, DASHED, HAIRLINE > ] ;
  197.         [ CELLSHADE <nCellPct> ] ;
  198.         [ <lDefault: SETDEFAULT > ] ;
  199.     => ;
  200.         <oRTF>:WriteCell( <cText>, <nFontNumber>, <nFontSize>, <cAppear>, ;
  201.                 <"cHorzAlign">, <nSpace>, <lSpExact>, <"cCellBorder">, ;
  202.                 <nCellPct>, <.lDefault.> )
  203.  
  204.  
  205. // Use this to begin a new section -- for example, to change the page
  206. // orientation, or the paper size, or the number of columns.
  207.  
  208. #xcommand NEW SECTION oRTF ;
  209.         [ <landscape: LANDSCAPE> ] ;
  210.         [ COLUMNS <nColumns> ] ;
  211.         [ MARGINS <nLeft>, <nRight>, <nTop>, <nBottom> ] ;
  212.         [ PAGEWIDTH <nWidth> ] ;
  213.         [ PAGEHEIGHT <nHeight> ] ;
  214.         [ ALIGN <vertalign: TOP, BOTTOM, CENTER, JUSTIFY> ] ;
  215.         [ <lDefault: SETDEFAULT > ] ;
  216.     => ;
  217.         oRTF:NewSection( <.landscape.>, <nColumns>, ;
  218.                 <nLeft>, <nRight>, <nTop>, <nBottom>, ;
  219.                 <nWidth>, <nHeight>, <"vertalign">, <.lDefault.> )
  220.  
  221.  
  222. // Use this to insert a page number (a "field" in MS-Word)
  223. // Good for use within headers and footers
  224. // NOTE: alignment not supported yet.
  225. #xcommand INSERT PAGENUMBER <oRTF> ;
  226.         [ ALIGN <cHorzAlign: LEFT, RIGHT, CENTER> ] ;
  227.     => ;
  228.         <oRTF>:PageNumber(<"cHorzAlign">)
  229.  
  230.