home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / AutoDoc / lib / perl5 / Autodoc / GenerateRTF.pm < prev    next >
Encoding:
Perl POD Document  |  1995-11-02  |  23.4 KB  |  831 lines

  1. package Autodoc::GenerateRTF;
  2.  
  3. ###############################################################################
  4. ###############################################################################
  5. ##
  6. ##    Written by Adam Swift (c) 1995 by Friday Software and Consulting
  7. ##                           All rights reserved.
  8. ##
  9. ##      This notice may not be removed from this source code.
  10. ##
  11. ##    This program is included in the MiscKit by permission from the author
  12. ##    and its use is governed by the MiscKit license, found in the file
  13. ##    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  14. ##    for a list of all applicable permissions and restrictions.
  15. ##
  16. ##    Because AutoDoc is licensed free of charge, there is no warranty 
  17. ##    for the program.  Copyright holder, Friday Software and Consulting, 
  18. ##    is providing this program "as is" and this program is distributed in 
  19. ##    the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
  20. ##    even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
  21. ##    PARTICULAR PURPOSE.
  22. ##
  23. ###############################################################################
  24. ###############################################################################
  25.  
  26. require 5.000;
  27.  
  28. ##########################
  29. # load required packages #
  30. ##########################
  31. use Exporter;
  32. # use Autodoc::DumpDocs;
  33.  
  34. @ISA      = qw(Exporter);
  35. @EXPORT   = qw(rtf_fileheader
  36.                rtf_filefooter
  37.                rtf_fonttable
  38.                rtf_stylesheet
  39.                rtf_spacer
  40.                rtf_head
  41.                rtf_title
  42.                rtf_subtitle
  43.                rtf_paragraph
  44.                rtf_synopsis
  45.                rtf_majorheading
  46.                rtf_minorheading
  47.                rtf_synopsis
  48.                rtf_keyvalue
  49.                rtf_methodline
  50.                rtf_format_words
  51.                rtf_format_method
  52.                rtf_boldify
  53.                rtf_italicize
  54.                rtf_copyright
  55.                rtf_emdash
  56.                rtf_setfont_times
  57.                rtf_setfont_helvetica
  58.                rtf_newline
  59.                rtf_newline_small
  60.                rtf_newline_micro
  61.               );
  62.  
  63. $module_version = '$Revision: 1.3 $';
  64. $module_version =~ s!(\$\w+: | \$)!!g;
  65. $module_id        = '$Id: GenerateRTF.pm,v 1.3 1995/10/20 22:16:26 aswift Exp $';
  66. $module_id      =~ s!(\$\w+: | \$)!!g;
  67. $module_name    = $module_id;
  68. $module_name    =~ s!^([^\,]+).*$!$1!;
  69.  
  70. ############################################################################
  71. # Purpose: Module that encapsulates generation of RTF specific syntax to 
  72. #          produce different paragraph and text styles for documentation
  73. #
  74. # HISTORY: START
  75. # $Log: GenerateRTF.pm,v $
  76. # Revision 1.3  1995/10/20  22:16:26  aswift
  77. # Added DevMan style changes Log support
  78. #
  79. #
  80. # HISTORY: END
  81. ############################################################################
  82.  
  83.  
  84. #############################################################################
  85. #
  86. # NAME:       module_version
  87. #
  88. # ACTION:     returns the version number of this module
  89. #
  90. # RETURN:     the module version
  91. #
  92. #############################################################################
  93. sub module_version
  94. {
  95.     return $module_version;
  96. }
  97.  
  98. sub module_versionstamp
  99. {
  100.     return "$module_name (rev-$module_version)";
  101. }
  102.  
  103.  
  104. #############################################################################
  105. #
  106. # NAME:      rtf_paragraph
  107. #
  108. # ACTION:    Takes a string argument and formats it for rtf formatted output
  109. #            as the basic format style.
  110. #
  111. #            This includes calling rtf_format_words to boldify & italicize
  112. #            words.
  113. #
  114. #            Reformat the text passed to this subroutine to turn the newline 
  115. #            markers into real newlines, and generally make paragraphs 
  116. #            look better.
  117. #
  118. # RETURN:    Returns the formatted string
  119. #
  120. #############################################################################
  121. sub rtf_paragraph
  122.   {    
  123.     my ($paragraph)        = $_[0];
  124.     my ($rtf_paragraph)    = "";
  125.     my ($listRTF)    = "";
  126.  
  127.     $rtf_paragraph = '\fs36 \pard \s0 \li2116 \fi0 \ri1007 \ql \tx2494 ';
  128.     $rtf_paragraph .= '\tx2872 \tx3250 ';
  129.     $rtf_paragraph .= rtf_setfont_times();
  130.  
  131.     $listRTF = '\pard \s11 \li7648 \fi-5131 \ri1007 \ql \tx7648 ';
  132.     $listRTF .= "\\tx10180 \\fs16 \\\n \\fs28 ";
  133.  
  134.     # Make all space-runs into single spaces
  135.     $paragraph =~ s/ +/ /g;
  136.  
  137.     # make all spaces following a period (+ end paren) double spaces
  138.     $paragraph =~ s/\.(\)?) /\.$1  /g;
  139.  
  140.     # Make newline markers into rtf compatible newlines
  141.     $paragraph =~ s/\\n\s*/\\\n\\fs16 \\\n\\fs28 /g;
  142.  
  143.     # Boldify and Italicize the words, THIS REFORMATS '}' CURLY BRACES as '\}'
  144.     $paragraph = rtf_format_words ($paragraph); 
  145.  
  146.     # Find List encodings and format the lines THE CURLY IS REPLACED WITH ' '
  147.     $paragraph =~ 
  148.       s/\_\{\s*([^\}\s]+)\s*([^\}]*)\}\s*/\{$listRTF $1\t$2 \}\n /g;
  149.  
  150.     $rtf_paragraph .= $paragraph;
  151.     $rtf_paragraph .= " " . rtf_newline();
  152.  
  153.     return "$rtf_paragraph";
  154.   }
  155.  
  156.  
  157. #############################################################################
  158. #
  159. # NAME:       rtf_majorheading
  160. #
  161. # ACTION:     takes a string and wraps it into an rtf formatted string in the
  162. #             major heading style
  163. #
  164. # RETURN:     returns the rtf formatted string
  165. #
  166. #############################################################################
  167. sub rtf_majorheading
  168.   {
  169.     my ($majhead)     = $_[0];
  170.     my ($rtf_majhead) = "";
  171.  
  172.     $rtf_majhead = rtf_spacer();
  173.     $rtf_majhead .= rtf_setfont_helvetica(18);
  174.     $rtf_majhead .= rtf_boldify($majhead);
  175.     $rtf_majhead .= rtf_newline() . rtf_newline_small();
  176.  
  177.     return $rtf_majhead;
  178.   }
  179.  
  180.  
  181. #############################################################################
  182. #
  183. # NAME:       rtf_minorheading
  184. #
  185. # ACTION:     takes a string and wraps it into an rtf formatted string in the
  186. #             minor heading style
  187. #
  188. # RETURN:     returns the rtf formatted string
  189. #
  190. #############################################################################
  191. sub rtf_minorheading
  192.   {
  193.     my ($minhead)     = $_[0];
  194.     my ($rtf_minhead) = "";
  195.  
  196.     $rtf_minhead = '\pard \tx2116 \tx6148 \tx6794 \tx7440 \tx8086 \tx9378';
  197.     $rtf_minhead .= '\li6148 \fi-4421 \fc0 \cf0 ';
  198.     $rtf_minhead .= rtf_setfont_helvetica(10);
  199.     $rtf_minhead .= rtf_boldify($minhead) . rtf_newline();
  200.  
  201.     return $rtf_minhead;
  202.   }
  203.  
  204.  
  205. #############################################################################
  206. #
  207. # NAME:       rtf_synopsis
  208. #
  209. # ACTION:     returns the text passed in (if any) prepended with the
  210. #             rtf formatting to set text into the sysnopsis style.
  211. #
  212. #############################################################################
  213. sub rtf_synopsis
  214.   {
  215.     my ($synopsis) = "";
  216.     my ($rtf_synopsis) = "";
  217.     
  218.     $synopsis = $_[0]
  219.       if (scalar @_);
  220.     $rtf_synopsis = '\pard \s11 \li6148 \fi-4031 \ri1007 \ql ';
  221.     $rtf_synopsis .= '\tx7440 \tx8086 \tx8732 \tx9378 \tx10024 \tx10670';
  222.     $rtf_synopsis .= rtf_setfont_times();
  223.     $rtf_synopsis .= "\n" . $synopsis . rtf_newline()
  224.       if ($synopsis);
  225.     
  226.     return $rtf_synopsis;
  227.   }
  228.  
  229. #############################################################################
  230. #
  231. # NAME:       rtf_keyvalue
  232. #
  233. # ACTION:     returns the text passed in (if any) prepended with the
  234. #             rtf formatting to set text into the keyvalue style.
  235. #
  236. #############################################################################
  237. sub rtf_keyvalue
  238.   {
  239.     my ($keyvalue) = "";
  240.     my ($rtf_keyvalue) = "";
  241.     
  242.     $keyvalue = $_[0]
  243.       if (scalar @_);
  244.     $rtf_keyvalue = '\pard \s11 \li6148 \fi-4031 \ri1007 \ql \tx6148 ';
  245.     $rtf_keyvalue .= rtf_setfont_times();
  246.     $rtf_keyvalue .= "\n" . $keyvalue . rtf_newline()
  247.       if ($keyvalue);
  248.     
  249.     return $rtf_keyvalue;
  250.   }
  251.  
  252. #############################################################################
  253. #
  254. # NAME:       rtf_methodline
  255. #
  256. # ACTION:     returns the text passed in (if any) prepended with the
  257. #             rtf formatting to set text into the methodline style.
  258. #
  259. #############################################################################
  260. sub rtf_methodline
  261.   {
  262.     my ($methodline) = "";
  263.     my ($rtf_methodline) = "";
  264.     
  265.     $methodline = $_[0]
  266.       if (scalar @_);
  267.  
  268.     $rtf_methodline = '\pard \tx3240 \li2100 \fi-760 \li3240';
  269.     $rtf_methodline .= rtf_setfont_times();
  270.     $rtf_methodline .= "\n" . $methodline . rtf_newline_small()
  271.       if ($methodline);
  272.     
  273.     return $rtf_methodline;
  274.   }
  275.  
  276. #############################################################################
  277. #
  278. # NAME:      rtf_subtitle
  279. #
  280. # ACTION:    takes a string and wraps it into a rtf formatted string in the 
  281. #            subtitle style (bold helvetica).  
  282. #            If more than one string is passed as an argument,
  283. #            a tab is inserted before each of the following strings,
  284. #            and they are set in plain times-roman, with no two on one line.
  285. #
  286. # RETURN:    returns the rtf formatted string
  287. #
  288. #############################################################################
  289. sub rtf_subtitle
  290.   {
  291.     my ($subtitle)       = shift (@_);
  292.     my (@substrings)   = @_;
  293.     my ($string)       = "";
  294.     my ($rtf_subtitle) = "";
  295.     
  296.     $rtf_subtitle = '\pard \s17 \li4888 \fi-2771 \ri1007 \ql \tx4888 ';
  297.     $rtf_subtitle .= rtf_setfont_helvetica();
  298.     $rtf_subtitle .= rtf_boldify($subtitle);
  299.     $rtf_subtitle .= rtf_setfont_times();
  300.  
  301.     foreach $string (@substrings) {
  302.       $rtf_subtitle .= "\t" . $string;
  303.       $rtf_subtitle .= rtf_newline()
  304.     }
  305.     $rtf_subtitle .= rtf_newline()
  306.       if (!(scalar (@substrings)));
  307.     
  308.     return $rtf_subtitle;
  309.   }
  310.  
  311. #############################################################################
  312. #
  313. # NAME:      rtf_title
  314. #
  315. # ACTION:    Takes a string and wraps it into a rtf formatted string in the 
  316. #            title style
  317. #
  318. # RETURN:    returns the rtf formatted string
  319. #
  320. #############################################################################
  321. sub rtf_title
  322.   {
  323.     my ($title)        = $_[0];
  324.     my ($rtf_title)    = "";
  325.  
  326.     $rtf_title = rtf_newline_small(3);
  327.     $rtf_title .= '\pard \s5 \li2116 \fi0 \ri1007 \ql ';
  328.     $rtf_title .= rtf_setfont_helvetica(28);
  329.     $rtf_title .= rtf_boldify($title) . rtf_newline();
  330.     $rtf_title .= rtf_newline_small(5);
  331.  
  332.     return $rtf_title;
  333.   }
  334.  
  335.  
  336. #############################################################################
  337. #
  338. # NAME:      rtf_head
  339. #
  340. # ACTION:    Takes a string and wraps it into a rtf formatted string in the
  341. #            head style.
  342. #
  343. # RETURN:    returns the rtf formatted string.
  344. #
  345. #############################################################################
  346. sub rtf_head
  347.   {
  348.     my ($head) = $_[0];
  349.     my ($rtf_head);
  350.  
  351.     $rtf_head = '\li0 \fi0 \ri0 \ql \sb0 ' . rtf_setfont_times(12);
  352.     $rtf_head .= "\n$head" . rtf_newline();
  353.     
  354.     return $rtf_head;
  355.   }
  356.  
  357.  
  358. #############################################################################
  359. #
  360. # NAME:      rtf_spacer
  361. #
  362. # ACTION:    returns a standard 5 line rtf spacer  
  363. #
  364. # RETURN:    a string representation of the spacer
  365. #
  366. #############################################################################
  367. sub rtf_spacer
  368.   {
  369.     my ($spacer) = "";
  370.  
  371.     $spacer = '\pard \s13 \li1360 \fi0 \ri1007 \ql \fs16 ';
  372.     $spacer .= rtf_newline(4);
  373.     return $spacer;
  374.   }
  375.  
  376. #############################################################################
  377. #
  378. # NAME:       rtf_fileheader
  379. #
  380. # ACTION:     Returns the text group that defines a rtf file header suitible
  381. #             for the documentation format specified by autodoc
  382. #
  383. # RETURN:     The string containing the RTF group defining the file header
  384. #
  385. #############################################################################
  386. sub rtf_fileheader
  387. {
  388.     local ($header);
  389.  
  390.     $header = '{\rtf0\ansi';
  391.     $header .= '\paperw16228 \paperh18648 \margl-907 \margr0 \margt0 \margb0';
  392.  
  393.     return $header;
  394. }
  395.  
  396.  
  397. #############################################################################
  398. #
  399. # NAME:       rtf_filefooter
  400. #
  401. # ACTION:     Returns the text group that defines a rtf file footer suitible
  402. #             for the documentation format specified by autodoc
  403. #
  404. # RETURN:     The string containing the RTF group defining the file footer
  405. #
  406. #############################################################################
  407. sub rtf_filefooter
  408. {
  409.     local ($footer);
  410.  
  411.     $footer = '}';
  412.  
  413.     return $footer;
  414. }
  415.  
  416.  
  417. #############################################################################
  418. #
  419. # NAME:       rtf_fonttable
  420. #
  421. # ACTION:     Returns the text group that defines a font table suitible for
  422. #             documentation in Rich Text Format
  423. #
  424. # RETURN:     The string containing the RTF group defining the font table
  425. #
  426. #############################################################################
  427. sub rtf_fonttable
  428. {
  429.     local ($fonttbl);
  430.     
  431.     $fonttbl = '{\fonttbl';
  432.     $fonttbl .= '\f0\fswiss Helvetica;';
  433.     $fonttbl .= '\f1\froman Times;';
  434.     $fonttbl .= '\f2\fmodern Courier;';
  435.     $fonttbl .= '\f3\ftech Symbol;}';
  436.     
  437.     return $fonttbl;
  438. }
  439.  
  440.  
  441. #############################################################################
  442. #
  443. # NAME:       rtf_stylesheet
  444. #
  445. # ACTION:     Returns the text group that defines a style sheet suitible for
  446. #             documentation in Rich Text Format
  447. #
  448. # RETURN:     The string containing the RTF group defining the style sheet
  449. #
  450. #############################################################################
  451. sub rtf_stylesheet
  452. {
  453.     local ($ss);
  454.  
  455.     $ss = '{\stylesheet';
  456.     $ss .= '{\s0 \li2116 \fi0 \ri1007 \ql \tx2494 \tx2872 \tx3250   ';
  457.     $ss .= 'Body;}';
  458.     $ss .= '{\s1 \li2493 \fi0 \ri1007 \ql \tx2872 \tx3250 \tx3642   ';
  459.     $ss .= 'BodyIndented;}';
  460.     $ss .= '{\s2 \li2493 \fi-376 \ri1007 \ql \tx2494 \tx2872 \tx3250   ';
  461.     $ss .= 'BulletLong;}';
  462.     $ss .= '{\s3 \li2494 \fi-378 \ri1007 \ql   ';
  463.     $ss .= 'BulletShort;}';
  464.     $ss .= '{\s4 \li4888 \fi-2771 \ri1007 \ql \tx4888   ';
  465.     $ss .= 'CategoryOf;}';
  466.     $ss .= '{\s5 \li2116 \fi0 \ri1007 \ql   ';
  467.     $ss .= 'ClassName;}';
  468.     $ss .= '{\s6 \li2494 \fi0 \ri1007 \ql   ';
  469.     $ss .= 'CodeExamp;}';
  470.     $ss .= '{\s7 \li2872 \fi0 \ri1007 \ql   ';
  471.     $ss .= 'CodeExamp2;}';
  472.     $ss .= '{\s8 \li2116 \fi0 \ri1007 \ql   ';
  473.     $ss .= 'CodeExampNoInd;}';
  474.     $ss .= '{\s9 \li4888 \fi-2771 \ri1007 \ql \tx4888   ';
  475.     $ss .= 'ConformsTo;}';
  476.     $ss .= '{\s10 \li4888 \fi-2771 \ri1007 \ql   ';
  477.     $ss .= 'DeclaredIn;}';
  478.     $ss .= '{\s11 \li6148 \fi-4031 \ri1007 \ql \tx6148 \tx9676 \tx10180   ';
  479.     $ss .= 'FirstVar/TypeLine1;}';
  480.     $ss .= '{\s12 \li0 \fi0 \ri0 \ql \tx-25 \tx8290 \tx9172   ';
  481.     $ss .= 'Footer;}';
  482.     $ss .= '{\s13 \li1360 \fi0 \ri1007 \ql   ';
  483.     $ss .= 'Heading;}';
  484.     $ss .= '{\s14 \li4888 \fi-2771 \ri1007 \ql \tx4888   ';
  485.     $ss .= 'ImplementedBy;}';
  486.     $ss .= '{\s15 \li2116 \fi0 \ri1007 \ql   ';
  487.     $ss .= 'Important;}';
  488.     $ss .= '{\s16 \li4888 \fi-2771 \ri1007 \ql \tx4888   ';
  489.     $ss .= 'Incorporates;}';
  490.     $ss .= '{\s17 \li4888 \fi-2771 \ri1007 \ql   ';
  491.     $ss .= 'InheritsFrom;}';
  492.     $ss .= '{\s18 \li2116 \fi0 \ri1007 \ql \tx2872   ';
  493.     $ss .= 'InstanceVar;}';
  494.     $ss .= '{\s19 \li2493 \fi-376 \ri1007 \ql   ';
  495.     $ss .= 'Method;}';
  496.     $ss .= '{\s20 \li3249 \fi-756 \ri1007 \ql   ';
  497.     $ss .= 'MethodDesc;}';
  498.     $ss .= '{\s21 \li2493 \fi-376 \ri1007 \ql   ';
  499.     $ss .= 'MethodFirst;}';
  500.     $ss .= '{\s22 \li2116 \fi0 \ri1007 \ql   ';
  501.     $ss .= 'Note;}';
  502.     $ss .= '{\s23 \li2493 \fi-376 \ri1007 \ql \tx2494 \tx2872 \tx3250   ';
  503.     $ss .= 'Num1Long;}';
  504.     $ss .= '{\s24 \li2494 \fi-378 \ri1007 \ql   ';
  505.     $ss .= 'Num1Short;}';
  506.     $ss .= '{\s25 \li2493 \fi-376 \ri1007 \ql   ';
  507.     $ss .= 'NumLong;}';
  508.     $ss .= '{\s26 \li2494 \fi-378 \ri1007 \ql   ';
  509.     $ss .= 'NumShort;}';
  510.     $ss .= '{\s27 \li2116 \fi0 \ri1007 \ql   ';
  511.     $ss .= 'SeeAlso;}';
  512.     $ss .= '{\s28 \li2493 \fi-376 \ri1007 \ql   ';
  513.     $ss .= 'Step;}';
  514.     $ss .= '{\s29 \li2493 \fi-376 \ri1007 \ql   ';
  515.     $ss .= 'Step1;}';
  516.     $ss .= '{\s30 \li2116 \fi0 \ri1007 \ql   ';
  517.     $ss .= 'SubHeading;}';
  518.     $ss .= '{\s31 \li2494 \fi0 \ri1007 \ql \tx6148 \tx10180   ';
  519.     $ss .= 'TableBody1;}';
  520.     $ss .= '{\s32 \li6148 \fi-3654 \ri1007 \ql \tx6148 \tx10432   ';
  521.     $ss .= 'TableBody2;}';
  522.     $ss .= '{\s33 \li2493 \fi0 \ri1007 \ql \tx6148 \tx10180   ';
  523.     $ss .= 'TableHead;}';
  524.     $ss .= '{\s34 \li6652 \fi-503 \ri1007 \ql \tx9676 \tx10180   ';
  525.     $ss .= 'Var/Type;}';
  526.     $ss .= '{\s35 \li6148 \fi-4031 \ri1007 \ql \tx6148 \tx9676 \tx10180   ';
  527.     $ss .= 'Var/TypeLine1;}';
  528.     $ss .= '{\s36 \li2116 \fi-2015 \ri1007 \ql \tx806 \tx2116   ';
  529.     $ss .= 'Warning;}';
  530.     $ss .= '}';
  531.     return $ss;
  532. }
  533.  
  534.  
  535. #############################################################################
  536. #
  537. # NAME:       rtf_format_method
  538. #
  539. # ACTION:     Process the method string passed in to format it with bold and 
  540. #             italics.  Return the converted method string and a space 
  541. #             separated list of arguments to the method.
  542. #
  543. # RETURN:     An array of two elements, the method as a formatted rtf string 
  544. #             and a string with all of the arguments to the method separated
  545. #             with spaces.
  546. #
  547. #############################################################################
  548. sub rtf_format_method
  549.   {
  550.     my ($method)         = $_[0];
  551.     my ($rtf_method)     = "";
  552.     my ($marg)             = "";
  553.     my ($method_args)     = "";
  554.     my ($marg_separator) = " ";
  555.     
  556.     if ($method =~ m!^\-!) {
  557.       $rtf_method = rtf_emdash() . " ";
  558.     } else {
  559.       $rtf_method = "+ ";
  560.     }
  561.  
  562.     # check if the method line is so long it should be broken accross lines
  563.     if (length($method) > 60) {
  564.       $marg_separator = rtf_newline() . "\t";
  565.     }
  566.  
  567.     # remove the + or -
  568.     $method =~ s!^[\+\-]!!;
  569.  
  570.     # boldify the method name AFTER the return value type casting (if any)
  571.     if ($method =~ m!^\(!) {
  572.       $method =~ s!^(\([^\)]+\))\s*!!;
  573.       $rtf_method .= $1;
  574.     }
  575.     $method =~ s!^[^\:]*!!;
  576.     $rtf_method .= rtf_boldify ($&);
  577.  
  578.     # format the method arguments, their types, and titles
  579.     while ($method =~ m!^:!) {
  580.       
  581.       # extract the colon - oww!
  582.       $method =~ s!:!!;    
  583.       $rtf_method .= rtf_boldify (":");
  584.       
  585.       # extract the type casting (if any)
  586.       if ($method =~ m!^\s*\(!) {
  587.         $method =~ s!\s*(\([^\)]+\))\s*!!;
  588.         $rtf_method .= "$1";
  589.       }
  590.  
  591.       # extract the argument and add it to the list of method arguments
  592.       $method =~ s!\s*(\S*)!!;
  593.       $marg = $1;
  594.       $method_args .= "$marg ";
  595.       $rtf_method .= rtf_italicize ($marg);
  596.       
  597.       # check for a title for the next argument
  598.       if ($method =~ m!:!) {
  599.         $method =~ s!([^:]*)!!;
  600.         $rtf_method .= $marg_separator . rtf_boldify ($1);
  601.       }        
  602.     } 
  603.     $rtf_method .= rtf_newline();
  604.     
  605.     return ($rtf_method, $method_args);
  606.   }
  607.  
  608.  
  609. #############################################################################
  610. #
  611. # NAME:       rtf_format_words
  612. #
  613. # ACTION:     Process string passed in to format special words as bold or 
  614. #             italics.  Return the converted string.
  615. #
  616. # RETURN:     The formatted rtf string
  617. #
  618. #############################################################################
  619. sub rtf_format_words
  620.   {
  621.     my ($text) = " $_[0] ";        # Add spaces to help with matching 
  622.     my (@bold_words, @italic_words);
  623.  
  624.     @bold_words      = Autodoc::DumpDocs::doc_bold_words();
  625.     @italic_words = Autodoc::DumpDocs::doc_italic_words();
  626.  
  627.     # boldify text of the form #{the text}
  628.     $text =~ s/\#\{([^\}]+)\}/\\b $1\\b0 /g;
  629.  
  630.     # italicize text of the form %{the text}
  631.     $text =~ s/\%\{([^\}]+)\}/\\i $1\\i0 /g;
  632.  
  633.     # boldify words which start with a "#" in front of them
  634.     $text =~ s/([^\\])\#([\w\:]+)/$1\\b $2\\b0 /g
  635.       while ($text =~ m/[^\\]\#[\w\:]+/);
  636.  
  637.     # italicize words which start with a "%" in front of them
  638.     $text =~ s/([^\\])\%([\w]+)/$1\\i $2\\i0 /g
  639.       while ($text =~ m/[^\\]\%[\w]+/);
  640.     
  641.     # italicize words in the $format_italicwords array
  642.     foreach $word (@italic_words) {
  643.       $text =~ s/(\W)$word(\W)/$1\\i $word\\i0 $2/g;
  644.     }
  645.     
  646.     # boldify words in the $format_boldwords array
  647.     foreach $word (@bold_words) {
  648.       $text =~ s/(\W)$word(\W)/$1\\b $word\\b0 $2/g;
  649.     }
  650.  
  651.     # Reformat curly braces so they don't prematurely end the rtf doc.
  652.     $text =~ s/\}/\\\}/g;
  653.  
  654.     # Reformat '\%' and '\#' to just '%' and '#'
  655.     $text =~ s/\\([\#\%])/$1/g;
  656.     
  657.     # Remove the spaces we added before.
  658.     $text =~ s/^\s+//;
  659.     $text =~ s/\s+$//;
  660.     return $text;
  661.   }
  662.  
  663.  
  664. #############################################################################
  665. #
  666. # NAME:       rtf_boldify
  667. #
  668. # ACTION:     Takes a string as input, and adds rtf formatting to set the 
  669. #             string in bold. 
  670. #
  671. # RETURN:     Returns the rtf bold formatted string
  672. #
  673. #############################################################################
  674. sub rtf_boldify
  675.   {
  676.     my ($string) = $_[0];
  677.     return ("\\b " . $string . "\\b0 ");
  678.   }
  679.  
  680.  
  681. #############################################################################
  682. #
  683. # NAME:       rtf_italicize
  684. #
  685. # ACTION:     Takes a string as input, and adds rtf formatting to set the 
  686. #             string in italics. 
  687. #
  688. # RETURN:     Returns the rtf italic formatted string
  689. #
  690. #############################################################################
  691. sub rtf_italicize
  692.   {
  693.     my ($string) = $_[0];
  694.     return ("\\i " . $string . "\\i0 ");
  695.   }
  696.  
  697.  
  698. #############################################################################
  699. #
  700. # NAME:       rtf_setfont_times
  701. #
  702. # ACTION:     Returns a string to change the rtf font to times-roman 14pt
  703. #
  704. #############################################################################
  705. sub rtf_setfont_times
  706.   {
  707.     my ($fontsize) = 28;
  708.     
  709.     if (scalar (@_)) {
  710.       $fontsize = $_[0] * 2;
  711.     }
  712.     return ("\\f1 \\fs" . $fontsize . " ");
  713.   }
  714.  
  715.  
  716. #############################################################################
  717. #
  718. # NAME:       rtf_setfont_helvetica
  719. #
  720. # ACTION:     Returns a string to change the rtf font to helvetica 14pt
  721. #             If an argument is passed, we set the font size to that point
  722. #             size (which appears as double that font size in 'rtf-land')
  723. #
  724. #############################################################################
  725. sub rtf_setfont_helvetica
  726.   {
  727.     my ($fontsize) = 28;
  728.     
  729.     if (scalar (@_)) {
  730.       $fontsize = $_[0] * 2;
  731.     }
  732.     return ("\\f0 \\fs" . $fontsize . " ");
  733.   }
  734.  
  735.  
  736.  
  737. #############################################################################
  738. #
  739. # NAME:       rtf_copyright
  740. #
  741. # ACTION:     Returns the rtf string which produces a copyright symbol
  742. #
  743. #############################################################################
  744. sub rtf_copyright
  745.   {
  746.     return "\\f3 \\'e3\\f1 ";
  747.   }
  748.  
  749.  
  750. #############################################################################
  751. #
  752. # NAME:       rtf_emdash
  753. #
  754. # ACTION:     Returns the rtf string which produces a em-dash symbol
  755. #
  756. #############################################################################
  757. sub rtf_emdash
  758.   {
  759.     return "{\\f3 -}";
  760.   }
  761.  
  762.  
  763. #############################################################################
  764. #
  765. # NAME:       rtf_newline_micro
  766. #
  767. # ACTION:     Returns the rtf string which produces a 4pt font size newline
  768. #             if a numerical argument is passed, that number of newlines is
  769. #             output.
  770. #
  771. #############################################################################
  772. sub rtf_newline_micro
  773.   {
  774.     my ($num) = "";
  775.     my ($out) = "\\\n";
  776.  
  777.     if (scalar (@_) > 0) {
  778.       for ($num = $_[0]; $num > 1; $num --) {
  779.         $out .= "\\\n";
  780.       }
  781.     }
  782.     return ("\{\\fs8 " . $out . "\}");
  783.   }
  784.  
  785. #############################################################################
  786. #
  787. # NAME:       rtf_newline_small
  788. #
  789. # ACTION:     Returns the rtf string which produces a 8pt font size newline
  790. #             if a numerical argument is passed, that number of newlines is
  791. #             output.
  792. #
  793. #############################################################################
  794. sub rtf_newline_small
  795.   {
  796.     my ($num) = "";
  797.     my ($out) = "\\\n";
  798.  
  799.     if (scalar (@_) > 0) {
  800.       for ($num = $_[0]; $num > 1; $num --) {
  801.         $out .= "\\\n";
  802.       }
  803.     }
  804.     return ("\{\\fs16 " . $out . "\}");
  805.   }
  806.  
  807. #############################################################################
  808. #
  809. # NAME:       rtf_newline
  810. #
  811. # ACTION:     Returns the rtf string which produces a rtf formatted newline
  812. #             if a numerical argument is passed, that number of newlines is
  813. #             output.
  814. #
  815. #############################################################################
  816. sub rtf_newline
  817.   {
  818.     my ($num) = "";
  819.     my ($out) = "\\\n";
  820.  
  821.     if (scalar (@_) > 0) {
  822.       for ($num = $_[0]; $num > 1; $num --) {
  823.         $out .= "\\\n";
  824.       }
  825.     }
  826.     return ($out);
  827.   }
  828.  
  829. 1;
  830.