home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / pcmag / v14n05 / ppv14n.exe / RTF.BAS < prev   
BASIC Source File  |  1994-12-04  |  6KB  |  168 lines

  1. Option Compare Database   'Use database order for string comparisons
  2. Option Explicit
  3.  
  4.  
  5. Sub EmitRTFFootnote (FileNum As Integer, FootnoteChar As String, 
  6.                      FootnoteBody As String)
  7.  
  8.   ' Routine to emit an RTF footnote record.
  9.   ' Assumes output file has been previously opened as #FileNum.
  10.   ' Superscripting of FootnoteChar is not really necessary
  11.   ' but looks nicer if RTF file is read into WinWord later.
  12.  
  13.   Print #FileNum, FootnoteChar + "{\footnote ";
  14.   Print #FileNum, "{\fs16\up6 " + FootnoteChar + "} ";
  15.   Print #FileNum, FootnoteBody + "}"
  16.  
  17. End Sub
  18.  
  19.  
  20. Sub EmitRTFHeader (FileNum As Integer)
  21.  
  22.   ' Generate RTF file header using passed file number
  23.   ' Assumes that the file has been previously opened successfully
  24.  
  25.   ' First emit RTF file identifier, default character set, etc.
  26.   Print #FileNum, "{\rtf1\ansi \deff0\deflang1024"
  27.  
  28.   ' Generate a minimal font table containing just enough
  29.   ' fonts to support Windows and Macintosh viewing
  30.   Print #FileNum, "{\fonttbl"
  31.   Print #FileNum, "{\f0\froman Times New Roman;}"
  32.   Print #FileNum, "{\f1\froman Symbol;}"
  33.   Print #FileNum, "{\f2\fswiss Arial;}"
  34.   Print #FileNum, "{\f3\fswiss Helvetica;}"
  35.   Print #FileNum, "{\f4\fswiss Hel;}"
  36.   Print #FileNum, "}"
  37.  
  38.   ' Generate a minimal color table consisting of black,
  39.   ' blue, green, red, and white.
  40.   Print #FileNum, "{\colortbl;"
  41.   Print #FileNum, "\red0\green0\blue0;"
  42.   Print #FileNum, "\red0\green0\blue255;"
  43.   Print #FileNum, "\red0\green255\blue0;"
  44.   Print #FileNum, "\red255\green0\blue0;"
  45.   Print #FileNum, "\red255\green255\blue255;"
  46.   Print #FileNum, "\red0\green127\blue0;"
  47.   Print #FileNum, "}"
  48.  
  49.   ' Set the default font to Times New Roman
  50.   Print #FileNum, "\deff0"
  51.  
  52.   ' Generate an initial topic separator
  53.   Print #FileNum, "\page"
  54.  
  55. End Sub
  56.  
  57.  
  58. Sub EmitRTFHotLink (FileNum As Integer, HotLinkString As String, 
  59.                     TargetString As String)
  60.  
  61.   ' Routine to emit RTF hotlink to the specified file.
  62.   ' The RTF encoding for a hotlink is double-underlined text
  63.   ' followed by hidden text. The double-underlined text is the
  64.   ' visible portion of the hotlink to be clicked on by the user.
  65.   ' The hidden text is the "context string" for the target topic.
  66.   ' Note: Prefixing the hidden text with "%" suppresses visible
  67.   ' underlining of the hotlink. We assume that the color of the
  68.   ' text will be set to something other than black elsewhere.
  69.  
  70.   Print #FileNum, "{\uldb " & HotLinkString & "}{\v %" & TargetString & "}"
  71.  
  72. End Sub
  73.  
  74.  
  75. Sub EmitRTFTabStopInches (FileNum As Integer, TabStop As Variant)
  76.  
  77.   ' Called with tab stop in fractional or integer inches.
  78.   ' Converts inches to Twips and calls EmitRTFTabStopTwips to
  79.   ' generate the RTF command.
  80.  
  81.   Call EmitRTFTabStopTwips(FileNum, Int(TabStop * 1440))
  82.  
  83. End Sub
  84.  
  85.  
  86. Sub EmitRTFTabStopTwips (FileNum As Integer, TabStop As Integer)
  87.  
  88.   ' Generates the RTF command to set a tab stop.
  89.   ' The RTF \tx command parameter and thus the TabStop parameter for
  90.   ' this subroutine is given in twips. 1440 twips = one inch.
  91.  
  92.   Dim Str1 As String
  93.  
  94.   Str1 = "\tx" & LTrim$(Str$(TabStop)) & " "
  95.   Print #FileNum, Str1
  96.  
  97. End Sub
  98.  
  99.  
  100. Sub EmitRTFTopicDivider (FileNum As Integer, TopicTitle As String, 
  101.                          ContextString As String, KeywordString As String, 
  102.                          TitleFootnote As String, BrowseSequence as String)
  103.  
  104.   ' This routine emits the RTF code to begin a new "topic".
  105.   ' The code consists of a "page break" command followed by
  106.   ' footnotes for the topic's context string, title footnote
  107.   ' for history list, keyword list, and browse sequence, followed
  108.   ' by the topic heading which appears in a nonscrolling region
  109.   ' in 14 pt. type. The default paragraph formatting and font are
  110.   ' then restored.
  111.  
  112.   ' signal start of new viewer topic
  113.   Print #FileNum, "\page"
  114.   
  115.   ' write context string footnote as label for this topic
  116.   Call EmitRTFFootnote(FileNum, "#", ContextString)
  117.   
  118.   ' write title footnote to be used in history window
  119.   ' and (for multimedia viewer) in search dialogs
  120.   Call EmitRTFFootnote(FileNum, "$", TitleFootnote)
  121.  
  122.   ' write keyword footnote iff keyword string was supplied
  123.   If KeywordString <> "" Then
  124.  
  125.     ' write keyword string footnote for use with Search button
  126.     Call EmitRTFFootnote(FileNum, "K", KeywordString)
  127.  
  128.   End If
  129.   
  130.   ' write browse sequence footnote iff browse sequence was supplied
  131.   If BrowseSequence <> "" Then
  132.  
  133.     ' write browse sequence number footnote
  134.     Call EmitRTFFootnote(FileNum, "+", BrowseSequence)
  135.  
  136.   End If
  137.  
  138.   ' Write the topic header text, using the "keep with next"
  139.   ' attribute to put the header in a nonscrolling window
  140.   Print #FileNum, "\keepn \f2\fs28 ";
  141.   Print #FileNum, TopicTitle
  142.   Print #FileNum, "\par "
  143.   
  144.   ' Restore default paragraph formatting and font.
  145.   ' The {dtype} command is needed for the multimedia compiler's
  146.   ' full-text indexing, but does no harm if the WinHelp
  147.   ' compiler is used instead.
  148.   Print #FileNum, "\pard \f2\fs20 {\dtype}"
  149.  
  150. End Sub
  151.  
  152.  
  153. Sub EmitRTFTrailer (FileNum As Integer)
  154.  
  155.   ' Routine to generate RTF file trailer.
  156.   ' Just emits RTF codes to close out the current
  157.   ' paragraph if any and then close out the current
  158.   ' topic, following all with a closing brace to
  159.   ' balance the initial brace written by the
  160.   ' EmitRTFHeader routine.
  161.  
  162.   Print #FileNum, "\par"
  163.   Print #FileNum, "\page"
  164.   Print #FileNum, "}"
  165.  
  166. End Sub
  167.  
  168.