home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ftnote1.zip / FOOTNOTE < prev    next >
Text File  |  1993-11-07  |  13KB  |  264 lines

  1. !filename    FOOTNOTE  11/06/93
  2. VAR currentPageString
  3. VAR footName
  4. VAR footnoteNumber
  5. VAR rightMargin
  6. VAR leftMargin
  7. VAR bottomMargin
  8. VAR bottomStartPoint
  9. VAR lineSpacing
  10. VAR minFrameHeight
  11. VAR footnoteBody
  12. VAR startBlock
  13. VAR endblock
  14. VAR readCharAtCursor
  15. VAR currentFrameName
  16. VAR placeMarker
  17. VAR beginMacroPoint
  18. VAR frameHoldValue
  19. VAR frameHoldName
  20. VAR preserveSnapToGrid
  21. VAR holdFrameName
  22. VAR separatorLineStyle
  23. VAR pageOver100Flag
  24. VAR pageOver10Flag
  25. VAR sepLineVisibleCheck
  26. PROCEDURE DrawInitialFootnoteFrame
  27. !This subroutine draws the initial oversized frame. It isn't critical where this gets placed really, as long as it is
  28. !on the right page! Also it must not start below the bottom margin of the main text body's page definition, so I used "7"
  29. !below as a place to start. I had some problems with incorrect units when I tried to calculate a safe number so...
  30. !I punted on this one for now. Hopefully, no one will want to use a bottom margin greater than 4 inches!
  31.         CancelDefinedBlock
  32.         Set CursorPosition TO placeMarker
  33.         EndnoteJump
  34.         FrameCreateStart
  35.         SET a TO 72.29pt
  36.         SET DocPrefSnapToGrid TO FALSE
  37.         CONVERT CursorPageNumber TOSTRING currentPageString
  38.         CONVERT footnoteNumber TOSTRING footnoteNumber
  39.         SET footName TO footnoteNumber
  40.         SET footName TO footname+currentpagestring
  41.         SET FrameName TO footName
  42.         CreateLinkTag footName
  43.         FrameTypeText
  44.         FrameSkipSkip
  45.         SET FrameAutomaticFlow TO FALSE
  46.         SET FrameOpaque TO FALSE
  47.         SET FrameStartingPage TO CursorPageNumber
  48.         SET FrameRightPageMarginRight TO rightMargin
  49.         SET FrameRightPageMarginLeft TO leftMargin 
  50.         SET FrameRightPageMarginBottom TO bottomMargin
  51.         SET b TO bottomStartPoint + a 
  52.         SET FrameRightPageMarginTop TO 7
  53.         FrameProcessChanges
  54.         DefineToParagraphEnd
  55.         DefineRight
  56.         StyleCreateVariation
  57.         StyleApplyNamed "Footnotes"
  58.         StyleApplyVariation
  59.         PasteFromClipboard
  60.         ParagraphUp
  61.         DefineToParagraphEnd
  62.         DefineRight
  63.         StyleCreateVariation
  64.         PasteRulerStyle
  65.         SET StyleLeading TO StyleLeading - Env0
  66.         StyleApplyVariation
  67. !       The following inserts the footnote separator line that was defined before starting the macro. It's still in the
  68. !       experimental stage, but I think it works properly now.
  69.         StyleCreateVariation
  70.         CancelDefinedBlock
  71.         CursorHome
  72.         IF Env9 = "*" THEN
  73.         ELSE
  74.         PUT Env9
  75.         DefineToLineBegin
  76.         SET AttributeUnderline TO TRUE
  77.         SET StylePointSize TO Env6
  78.         SET UnderlineSize TO Env7
  79.         SET sepLineVisibleCheck TO Env8
  80.         SET sepLineVisibleCheck TO -sepLineVisibleCheck
  81.         IF sepLineVisibleCheck > Env6 THEN
  82.                 SET Env8 TO Env6
  83.                 SET Env8 TO -Env8
  84.         ELSE
  85.         END IF
  86.         SET UnderlinePosition TO Env8
  87.         StyleApplyVariation
  88.         CancelDefinedBlock
  89. END IF  
  90.         SET a TO "footnote" + footnoteNumber
  91.         CreateLinkTag a                         !This creates a tag inside the footnote frame used in finding frames 
  92.                                                         !and tags to delete during the execution of FOOTSTRT macro.
  93. END PROCEDURE
  94.  
  95. PROCEDURE ResizeFootnoteFrame
  96. !This subroutine resizes the footnote frame based on the final style and length of the
  97. !footnote text block. The height of the frame is based on the number of lines in the 
  98. !frame , multiplied by the number of points used for the leading of the text. 
  99. !Then the Env5 variable is also read to add some (variable) 'padding' to the end of the frame.
  100. !The Env5 variable was originally intended to allow the spacing to be decreased AND increased, but
  101. !if the spacing is decreased more than what is already determined by minFrameHeight, the text in the footnote
  102. !frame will be shoved down below where it is visible. To avoid this I disabled the option to allow the user to
  103. !decrease the spacing. It was not useful, but increasing the spacing still is.
  104. !The result is a frame that has an extra line at the beginning which, at this point, still has an underline
  105. !attribute (if this option was used). The underline attribute gets turned off later, during the TestForExistingFootnote
  106. !procedure, if, and only if, there is a footnote frame already placed before it. So, this line serves double-duty, both
  107. !as a means to add some space between the footnotes, and also to provide the separator line if it is used.
  108.         FrameModifyStart footName
  109.         CursorHome
  110.         SET f TO StylePointSize
  111.         CursorDown
  112.         SET a TO NumberFrameLines
  113.         SET lineSpacing TO StyleLeading
  114.         SET minFrameHeight TO a * lineSpacing
  115.         SET f TO f - StyleLeading
  116. !       The next three lines set the left, right and bottom margins
  117.         SET FrameRightPageMarginLeft TO leftMargin 
  118.         SET FrameRightPageMarginRight TO rightMargin
  119.         SET FrameRightPageMarginBottom TO bottomMargin
  120. !       The following lines actually define the height of the frame, indirectly, by basing
  121. !       the margin setpoints on the "minFrameHeight" determined above.
  122.         SET a TO bottomStartPoint
  123.         SET b TO minFrameHeight
  124.         SET b TO b + Env5
  125.         SET b TO b + f
  126.         SET c TO a - b
  127.         SET FrameRightPageMarginTop TO c
  128.         SET FrameRightPageMarginBottom TO  PageSizeHeight - a
  129.         SET d TO NumberFrameChars
  130.         SET e TO StylePointSize
  131.         FrameProcessChanges
  132.         SET holdFrameName TO FrameName
  133.         SET SelectedFrame TO "footnote data"
  134. !       The next series of 'puts' writes data to the footnote data database
  135. !       InsertMode is used to over-write the previous data
  136.         SET InsertMode TO FALSE
  137.         PUT footnotenumber              ! this is the 1st column in footnote data
  138.         TableCellTab
  139.         PUT currentPageString           !  this is the 2nd column
  140.         TableCellTab
  141.         PUT footname                    !  this is the 3rd column
  142.         TableCellTab
  143.         PUT d                           !  this is the 4th column and is a count of the characters in the footnote.
  144.         TableCellTab
  145.         PUT e                           !  this is the 5th column and is the last recorded Point size   
  146.         TableCellTab
  147.         SET SelectedFrame TO holdFrameName
  148.         SET InsertMode TO TRUE
  149. !       That's it, the footnote frame now has its final dimensions.
  150. END PROCEDURE
  151.  
  152. PROCEDURE MoveFootnoteFrame
  153. !This subroutine moves the footnote frame based on the dimension of the newly inserted footnote text block..
  154. !This procedure is only used when more than one footnote frame is on a single page.
  155.         FrameModifyStart  d
  156.         SET FrameRightPageMarginBottom TO FrameRightPageMarginBottom + m
  157.         SET FrameRightPageMarginTop TO FrameRightPageMarginTop - m
  158.         FrameProcessChanges
  159. END PROCEDURE
  160.  
  161. PROCEDURE TestForExistingFootnote
  162.         REPEAT
  163.                 SET a TO FrameName
  164.                 SET SelectedFrame TO "footnote data"
  165.                 SET z TO CursorPosition         ! record where cursor was so I can return before  I leave
  166.                 CursorHome                                      ! move to beginning of footnote data table
  167.                 SearchClear
  168.                 SET SearchSearch1 TO a                  ! search for the frame currently being created
  169.                 SearchForward
  170.                 CancelDefinedBlock
  171.                 TableCellLeft                           ! move to the left to read page number of this frame
  172.                 DefineToWordEnd
  173.                 CopyToClipboard
  174.                 SET b TO PastedClipboard                ! save page number read above
  175.                 CancelDefinedBlock
  176.                 SET h TO TableCurrentRow
  177.                 IF h = 0 THEN                           ! if current row in table is 0 (the first row) then exit
  178.                         SET SelectedFrame TO "footnote data"
  179.                         SET CursorPosition TO z ! reset cursor position before exiting
  180.                         EXIT
  181.                 ELSE
  182.                 END IF
  183.                 CursorWordLeft
  184.                 TableCellUp
  185.                 DefineToWordEnd
  186.                 CopyToClipBoard
  187.                 SET g TO PastedClipboard                ! read page number of preceding footnote recorded in the table
  188.                 CancelDefinedBlock
  189.                 IF b = g THEN                           !  if the page numbers read above are the same, then we need to move one
  190.                         TableCellTab                    !  tab over to the linktag name for this footnote
  191.                         DefineToWordEnd
  192.                         CopyToClipboard
  193.                         SET d TO PastedClipboard        !  and record it
  194.                         CancelDefinedBlock 
  195.                         SET SelectedFrame TO a          !  switch back to the frame that is being created first 
  196.                         CursorHome
  197.                         DefineToLineEnd
  198.                         StyleCreateVariation
  199.                         SET AttributeUnderline TO FALSE                 !  since this frame will not be the first on this page, turn off the separator line
  200.                         StyleApplyVariation
  201.                         CancelDefinedBlock
  202.                         SET SelectedFrame TO "footnote data"            !  switch back to the database and move the cursor to where we started
  203.                         SET CursorPosition TO z
  204.                         SET SelectedFrame TO d                                  !  switch to the frame that needs to be moved
  205.                         SET m TO bottomStartPoint - c                   !  pass the distance the frame needs to be moved to the next CALL
  206.                         CALL  MoveFootnoteFrame                         !  call on this procedure to slide the frame up the page by distance 'm'
  207.                 ELSE
  208.                         SET CursorPosition TO z                         !  if the page numbers aren't equal we still need to reset the curosr position
  209.                         EXIT                                                            !  before exiting so the next series of data entries get properly placed.
  210.                 END IF
  211.         END REPEAT
  212. END PROCEDURE
  213.  
  214. MACRO DoFootnote
  215.         SET preserveSnapToGrid TO DocPrefSnapToGrid
  216.         CursorWordRight
  217.         PUT " "
  218.         CursorWordLeft
  219.         CopyRulerStyle
  220.         SET placeMarker TO CursorPosition
  221.         DefineRight
  222.         SET readCharAtCursor TO CursorCharacter
  223.         REPEAT
  224.                 IF readCharAtCursor=" " THEN
  225.                         EXIT
  226.                 ELSE
  227.                         DefineRight
  228.                         SET readCharAtCursor TO CursorCharacter
  229.                 END IF
  230.         END REPEAT
  231.         CopyToClipboard
  232.         CancelDefinedBlock
  233.         DeleteText
  234.         SET footnoteNumber TO PastedClipboard
  235.         SET CursorPosition TO placeMarker
  236.         DefineToParagraphEnd
  237.         DefineLeft
  238.         SET currentFrameName TO SelectedFrame
  239.         CopyToClipboard
  240.         CancelDefinedBlock
  241.         SET rightMargin TO FrameRightPageMarginRight
  242.         SET leftMargin TO FrameRightPageMarginLeft
  243.         SET bottomMargin TO FrameRightPageMarginBottom
  244.         SET bottomStartPoint TO PageSizeHeight - FrameRightPageMarginBottom
  245. !       Now that all the proper things have been read, the footnote frame can be created.
  246. !       This Procedure draws an initial frame with no set of any significance) dimension yet.
  247.  
  248. CALL DrawInitialFootnoteFrame
  249.  
  250. !       This next step resizes the footnote frame that was just created so that it snugs up against the footnote text.
  251. CALL ResizeFootnoteFrame
  252.  
  253. !       This next Procedure is the key to making footnoting work easily. It, and the MoveFootNoteFrame procedure that it calls
  254. !       is responsible for getting the footnote frames placed in the right order on the page, and also for determing whether
  255. !       or not to draw the 'separator' line. It was also the hardest part of the macro(s) to write. The lack of a direct way
  256. !       to test to see if a specifc frame exists drove me nuts until I discovered I could get around it by using 'Tags' to echo the
  257. !       footnote's framename. There IS a way to test for an existing Tag Name.!!!!
  258. CALL TestForExistingFootnote
  259.  
  260. !       The next  step gets ready to end the macro by switching back to where it all started and resetting some of the
  261. !       Preferences that were changed during the execution of the macro from what they were to begin with.
  262.         SET SelectedFrame TO currentFrameName
  263.         SET DocPrefSnapToGrid TO preserveSnapToGrid
  264. END MACRO