home *** CD-ROM | disk | FTP | other *** search
- REM Automatically formats the selection [CorelSCRIPT 8]
- REM RTFFormatter.csc March, 1998
- REM ⌐ 1998 Corel Corporation. All rights reserved.
-
- REM ***********************************************************************
- REM This script automatically applies formatting to the current text selection.
- REM If there is no selection, formatting is applied to the current text file.
- REM ***********************************************************************
-
- REM ***********************************************************************
- REM MAIN HEADING definition
- REM - a paragraph with only one line
- REM - the next line is a paragraph return (ie. a para with width=0)
- REM - no punctuation at end of line (ie. period, question mark, etc)
- REM - no number or special character at start of line
- REM ***********************************************************************
-
- REM ***********************************************************************
- REM MINOR HEADING definition
- REM - a paragraph with only one line
- REM - text is bold
- REM - no punctuation at end of line (ie. period, question mark, etc)
- REM - no number or special character at start of line
- REM ***********************************************************************
-
- REM ***********************************************************************
- REM SUB HEADING definition
- REM - a paragraph with only one line
- REM - no punctuation at end of line (ie. period, question mark, etc)
- REM - no number or special character at start of line
- REM ***********************************************************************
-
- REM ***********************************************************************
- REM NUMBERED LIST definition
- REM - first character of first line of paragraph is a number
- REM - paragraph can be one or more lines
- REM ***********************************************************************
-
- REM ***********************************************************************
- REM BULLET definition
- REM - paragraph can be one or more lines
- REM - first line of paragraph is indented
- REM - first character of first line of paragraph is a special character (ie. not a letter or a number)
- REM ***********************************************************************
-
- REM ***********************************************************************
- REM BODY TEXT definition
- REM - anything that doesn't fall into one of the other tag definitions
- REM ***********************************************************************
-
- #addfol "..\..\Scripts" ' create a tmporary folder to provide a path for the include files
- #include "ScpConst.csi" ' this enables the include files to be located
- #include "VPConst.csi"
-
- #DEFINE SUB_HEADING 1
- #DEFINE MINOR_HEADING 2
- #DEFINE MAIN_HEADING 3
- #DEFINE BULLET 4
- #DEFINE NUMBERED_LIST 5
-
- DECLARE FUNCTION ISPunctuated() AS BOOLEAN
- DECLARE FUNCTION ISTitleCase() AS BOOLEAN
- DECLARE FUNCTION ISMainHeading() AS BOOLEAN
- DECLARE FUNCTION ListType(TagScore%) AS INTEGER
- DECLARE SUB ApplyTag(TagType%)
-
- WITHOBJECT "CorelVentura.Automation.8"
- .PageFirstLine
- WHILE NOT(.IsCaretAtEndOfText())
- TagScore% = 0
-
- 'Get current para info
- .TextLineInfoGet CurrentLineCount&, LineNumber&, ColumnNumber&, LineLeft&, LineTop&, Width&, Height&, BaseLineY&
-
- IF CurrentLineCount& = 1 THEN
- 'check for punctuation at end of line
- IF ISPunctuated() = FALSE THEN TagScore% = SUB_HEADING 'tag para with sub heading
- IF ISTitleCase() = TRUE THEN TagScore% = TagScore% + 1
- IF ISMainHeading() = TRUE THEN TagScore% = TagScore% + 1 'tag para with main heading
- ENDIF
-
- IF TagScore% <= 1 THEN TagScore% = TagScore% + ListType%(TagScore%)
-
- ApplyTag TagScore%
- .TextParaDown 1, TRUE 'activate next paragraph
- WEND
- END WITHOBJECT
-
-
- ' This function will apply the tag specified by TagType to the current paragraph
- SUB ApplyTag(TagType%)
- WITHOBJECT "CorelVentura.Automation.8"
- SELECT CASE(TagType%)
- CASE SUB_HEADING
- .FormatSetParaTag "Subheading"
- CASE MINOR_HEADING
- .FormatSetParaTag "Minor Heading"
- CASE MAIN_HEADING
- .FormatSetParaTag "Main Heading"
- .TextParaDown 1, FALSE
- .TextParaDown 1, TRUE
- .EditDelete
- .TextParaUp 1, FALSE
- CASE BULLET
- .FormatSetParaTag "Bullet"
- CASE NUMBERED_LIST
- .FormatSetParaTag "Numbered List"
- CASE ELSE
- .FormatSetParaTag "Body Text"
- END SELECT
- END WITHOBJECT
- END SUB
-
- ' This function checks the current line for title case (ie. First letter of each word is uppercase
- FUNCTION ISTitleCase() AS BOOLEAN
- WITHOBJECT "CorelVentura.Automation.8"
- UpperCnt% = 0
- LowerCnt% = 0
-
- .TextStartOfLine
- DO
- .TextWordRight 1, FALSE 'select word
- CurrentText$ = .SelectedText()
- SELECT CASE ASC(CurrentText$)
- CASE 65 TO 90 ' word begins with an uppercase letter
- UpperCnt% = UpperCnt% + 1
- CASE ELSE
- LowerCnt% = LowerCnt% + 1
- END SELECT
- LOOP UNTIL ASC(CurrentText$) = 0
-
- IF UpperCnt% > LowerCnt% THEN
- ISTitleCase = TRUE
- ELSE
- ISTitleCase = FALSE
- ENDIF
-
- END WITHOBJECT
- END FUNCTION
-
-
- ' This function checks the current line for punctuation at the end of the line
- FUNCTION ISPunctuated() AS BOOLEAN
- WITHOBJECT "CorelVentura.Automation.8"
- .TextEndOfLine FALSE
- .TextWordLeft 1, TRUE
- LastChar& = ASC(.SelectedText())
-
- IF LastChar& = 33 OR LastChar& = 46 OR LastChar& = 63 THEN
- ISPunctuated = TRUE
- ELSE
- ISPunctuated = FALSE
- ENDIF
- .TextStartOfLine FALSE
- END WITHOBJECT
- END FUNCTION
-
- ' This function determines whether to apply the Main Heading tag to the current line
- ' If the current line is a Main Heading, the function returns TRUE
- ' The current line is a Main Heading IF the next line is a para return
- FUNCTION ISMainHeading() AS BOOLEAN
- WITHOBJECT "CorelVentura.Automation.8"
- ' is the next line a para return
- .TextParaDown 1, FALSE
- .TextLineInfoGet NextLineCount&, LineNumber&, ColumnNumber&, LineLeft&, LineTop&, NextWidth&, Height&, BaseLineY&
- IF NextWidth& = 0 THEN
- ISMainHeading = TRUE
- .TextParaUp 1, FALSE
- EXIT FUNCTION
- ENDIF
- .TextParaUp 1, FALSE
- ISMainHeading = FALSE
- END WITHOBJECT
- END FUNCTION
-
-
- ' This function determines whether to apply the numbered List tag to the current line
- ' If the current line is a numbered List, the function returns TRUE
- ' The current line is a numbered List IF the first character of the current line is a number
- FUNCTION ListType(TagScore%) AS INTEGER
- WITHOBJECT "CorelVentura.Automation.8"
- ' is first character a number
- .TextStartOfLine
- TextType& = .TextSpecialItemType(CharCode&)
- DO WHILE TextType& <> 0
- .TextCharRight 1
- TextType& = .TextSpecialItemType(CharCode&)
- LOOP
-
- SELECT CASE CharCode&
- CASE 48 TO 57 ' a number from 0 to 9
- ListType = NUMBERED_LIST - TagScore%
- CASE 65 TO 90 ' upper case letters
- ListType = 0
- CASE 97 TO 122 ' lower case letters
- ListType = 0
- CASE 183 ' bullet char
- .TextCharRight 1, TRUE
- .EditDelete
- ListType = BULLET - TagScore%
- CASE 9 ' tab
- ListType = BULLET - TagScore%
- CASE 32 ' space
- ListType = BULLET - TagScore%
- CASE ELSE
- ListType = 0
- END SELECT
- END WITHOBJECT
- END FUNCTION
-