home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / WordProcessors / slt-pgs3.lzx / PageStream3 / Scripts / FontSpec.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-10-20  |  9.5 KB  |  328 lines

  1. /* $VER: FontSpec.rexx 3.1 (15.10.96)
  2.    Copyright 1996 SoftLogik Publishing Corporation
  3.    May not be distributed without SoftLogik Publishing Corporation's express written permission */
  4.  
  5. OPTIONS RESULTS
  6. TRACE OFF
  7.  
  8. /* Make sure rexx support is opened */
  9. IF ~SHOW('L','rexxsupport.library') THEN
  10.    CALL ADDLIB('rexxsupport.library',0,-30)
  11.  
  12. ADDRESS 'PAGESTREAM'
  13.  
  14. /* DEFINES      */
  15.     pfontcount=0
  16.     totalfonts=0
  17.     cancel=9
  18. /* specsize   */
  19.     big=0
  20.     small=1
  21. /* whichfonts */
  22.     all=0
  23.     select=1
  24.  
  25. /* MAIN LOOP  */
  26. choice=INSTRUCT()                                        /* find out what to print */
  27. if choice~=cancel then do
  28.         call FINDFONTS()
  29.         call SORTIFONTS()
  30.         if whichfonts=select then call CHOOSEFONTS()    /* choose which fonts to print */
  31.         else do
  32.             do i=1 to ifontcount
  33.                 pfonts.i=ifonts.i
  34.             end
  35.             pfontcount=ifontcount
  36.         end
  37.         if specsize=small then 'opendocument file "pagestream3:scripts/fontspec6.doc"'
  38.         else 'opendocument file "pagestream3:scripts/fontspec1.doc"'
  39.         call PRINTFONTS()
  40. end
  41. EXIT
  42.  
  43. INSTRUCT:
  44. /* GIVE INSTRUCTIONS */
  45.     allocarexxlist
  46.         hSpecSizeList=result
  47.     addarexxlist hSpecSizeList '"One font per page"'
  48.     addarexxlist hSpecSizeList '"Six fonts per page"'
  49.     allocarexxlist
  50.         hWhichFontsList=result
  51.     addarexxlist hWhichFontsList '"All fonts"'
  52.     addarexxlist hWhichFontsList '"Selected fonts"'
  53.  
  54.     allocarexxrequester '"Create Font Specimen Sheets"' 552 109
  55.         hInstructReq=result
  56.     addarexxgadget hInstructReq EXIT 12 92 70 label "Print"
  57.         hPrintGadget=result
  58.     addarexxgadget hInstructReq EXIT 470 92 70 label "Cancel"
  59.         hCancelGadget=result
  60.     addarexxgadget hInstructReq TEXT 8 10 536 border none string "'This script will print font specimen sheets to help select fonts'"
  61.     addarexxgadget hInstructReq TEXT 8 20 536 border none string "'to use. You can choose to print detailed specimens with one font'"
  62.     addarexxgadget hInstructReq TEXT 8 30 536 border none string "'per page or small specimens with 6 fonts per page. You can also'"
  63.     addarexxgadget hInstructReq TEXT 8 40 536 border none string "'choose to print All installed fonts or Selected fonts only.'"
  64.     addarexxgadget hInstructReq CYCLE 64 64 188 label '"_Number"' labelpos left
  65.         hSpecSizeGadget=result
  66.     addarexxgadget hInstructReq CYCLE 384 64 156 label '"_Which Fonts"' labelpos left
  67.         hWhichFontsGadget=result
  68.     setarexxgadget hInstructReq hSpecSizeGadget list hSpecSizeList current 0
  69.     setarexxgadget hInstructReq hWhichFontsGadget list hWhichFontsList current 0
  70.  
  71.     doarexxrequester hInstructReq
  72.         action=result
  73.     if action=hCancelGadget then RETURN cancel
  74.  
  75.     getarexxgadget hInstructReq hSpecSizeGadget current
  76.         specsize=result
  77.  
  78.     getarexxgadget hInstructReq hWhichFontsGadget current
  79.         whichfonts=result
  80.  
  81.     freearexxrequester hInstructReq
  82.     freearexxlist hInstalledFontsList
  83.     freearexxlist hPrintFontsList
  84. RETURN 0
  85.  
  86. FINDFONTS:
  87. /* GET THE NAMES AND NUMBER OF FACES */
  88.     getfontlist ifonts
  89.     ifontcount=result
  90.  
  91.     /* Shuffle 0 to end to work with sort routine */
  92.     ifonts.ifontcount=ifonts.0
  93. RETURN
  94.  
  95. SORTIFONTS:
  96. /* SORT THE LIST ALPHABETICALLY */
  97.     DO tick = 1 to ifontcount-1
  98.         nexttick=tick+1
  99.         IF ifonts.tick > ifonts.nexttick THEN DO
  100.             store=ifonts.nexttick
  101.             ifonts.nexttick=ifonts.tick
  102.             DO bubpos = tick-1 to 1 by -1 WHILE (store < ifonts.bubpos)
  103.                 nexttick=bubpos+1
  104.                 ifonts.nexttick = ifonts.bubpos
  105.             END bubpos
  106.             bubpos=bubpos+1
  107.             ifonts.bubpos=store
  108.         END
  109.     END tick
  110. RETURN
  111.  
  112. SORTPFONTS:
  113. /* SORT THE LIST ALPHABETICALLY */
  114.         DO tick = 1 to pfontcount-1
  115.         nexttick=tick+1
  116.         IF pfonts.tick > pfonts.nexttick THEN DO
  117.             store=pfonts.nexttick
  118.             pfonts.nexttick=pfonts.tick
  119.             DO bubpos = tick-1 to 1 by -1 WHILE (store < pfonts.bubpos)
  120.                 nexttick=bubpos+1
  121.                 pfonts.nexttick = pfonts.bubpos
  122.             END bubpos
  123.             bubpos=bubpos+1
  124.             pfonts.bubpos=store
  125.         END
  126.     END tick
  127. RETURN
  128.  
  129. CHOOSEFONTS:
  130. /* FIND OUT WHICH FONTS TO PRINT */
  131.  
  132.     call alloclists()
  133.  
  134.     /* Initialize the installed font list */
  135.     do i=1 to ifontcount
  136.         'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  137.     end i
  138.  
  139.     /* Allocate and build the requester */
  140.     allocarexxrequester '"Create Font Specimen Sheets"' 528 211
  141.         hChooseReq=result
  142.     addarexxgadget hChooseReq TEXT 12 10 250 border none string "'Select the typefaces to print:'"
  143.     addarexxgadget hChooseReq EXIT 12 194 70 label "Print"
  144.         hPrintGadget=result
  145.     addarexxgadget hChooseReq EXIT 446 194 70 label "Cancel"
  146.         hCancelGadget=result
  147.     addarexxgadget hChooseReq EXIT 224 42 80 label '"_Add    ->"'
  148.         hAddGadget=result
  149.     addarexxgadget hChooseReq EXIT 224 62 80 label '"_Remove <-"'
  150.         hRemoveGadget=result
  151.     addarexxgadget hChooseReq SCROLLIST 12 42 200 139 label '"Installed Typefaces"' labelpos aboveleft
  152.         hInstalledFontsGadget=result
  153.     addarexxgadget hChooseReq SCROLLIST 316 42 200 139 label '"Typefaces to Print"' labelpos aboveleft
  154.         hPrintFontsGadget=result
  155.  
  156.     /* FONT SELECTION LOOP */
  157.     exitflag=0
  158.     do until exitflag=1
  159.  
  160.         /* Do the font selection requester */
  161.         setarexxgadget hChooseReq hInstalledFontsGadget list hInstalledFontsList current 0
  162.         setarexxgadget hChooseReq hPrintFontsGadget list hPrintFontsList current 0
  163.         doarexxrequester hChooseReq
  164.             action=result
  165.  
  166.         select
  167.             when action=hCancelGadget then do      /* THE USER CANCELLED   */
  168.                 call freelists()
  169.                 retvalue=9
  170.                 exitflag=1
  171.                 end
  172.             when action=hPrintGadget then do      /* PRINT THE FONTS!     */
  173.                 call freelists()
  174.                 retvalue=1
  175.                 exitflag=1
  176.                 end
  177.             when action=hAddGadget then do          /* ADD A FONT TO PRINT  */
  178.                 getarexxgadget hChooseReq hInstalledFontsGadget current
  179.                 cfont=result+1
  180.                 pfontcount=pfontcount+1
  181.                 pfonts.pfontcount=ifonts.cfont
  182.                 call sortpfonts()                  /* sort the to print list  */
  183.                 call freelists()                  /* free the arexx lists    */
  184.                 call alloclists()                  /* alloc the lists again   */
  185.                 do i=1 to pfontcount              /* fill the to print list  */
  186.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  187.                 end i
  188.                 do i=cfont to ifontcount          /* remove from ifonts      */
  189.                     nexti=i+1
  190.                     ifonts.i=ifonts.nexti
  191.                 end
  192.                 ifontcount=ifontcount-1
  193.                 do i=1 to ifontcount              /* fill the installed list */
  194.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  195.                 end i
  196.                 end
  197.             when action=hRemoveGadget then do       /* REMOVE A FONT TO PRINT */
  198.                 getarexxgadget hChooseReq hPrintFontsGadget current
  199.                 cfont=result+1
  200.                 ifontcount=ifontcount+1
  201.                 ifonts.ifontcount=pfonts.cfont
  202.                 call sortifonts()                  /* sort the installed list */
  203.                 call freelists()                  /* free the arexx lists    */
  204.                 call alloclists()                  /* alloc the lists again   */
  205.                 do i=1 to ifontcount              /* fill the installed list */
  206.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  207.                 end i
  208.                 do i=cfont to pfontcount          /* remove from pfonts      */
  209.                     nexti=i+1
  210.                     pfonts.i=pfonts.nexti
  211.                 end
  212.                 pfontcount=pfontcount-1
  213.                 do i=1 to pfontcount              /* fill the to print list  */
  214.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  215.                 end i
  216.                 end
  217.         end
  218.     end
  219.     freearexxrequester hChooseReq
  220.  
  221.     if retvalue=9 then EXIT
  222.     if retvalue=1 & pfontcount=0 then do
  223.         call doalert("No fonts selected to print!")
  224.         EXIT
  225.     end
  226.  
  227. RETURN
  228.  
  229. ALLOCLISTS:
  230. /* Allocate lists for the installed fonts and the fonts to print */
  231.     allocarexxlist
  232.         hInstalledFontsList=result     /* list of installed fonts */
  233.     allocarexxlist
  234.         hPrintFontsList=result         /* list of fonts to print */
  235. RETURN
  236.  
  237. FREELISTS:
  238. /* Free lists for the installed fonts and the fonts to print */
  239.     freearexxlist hInstalledFontsList
  240.     freearexxlist hPrintFontsList
  241. RETURN
  242.  
  243. PRINTFONTS:
  244. /* PRINT LOOP */
  245.     openbusyrequester message "'Creating Font Specimens...'" thermometer enabled abort enabled total 100 current 0
  246.         hBusyReq=result
  247.  
  248.     /* Count the pages to print */
  249.     if specsize=small then do
  250.         pagecount=trunc(pfontcount/6)
  251.         lastpage=(pfontcount/6-pagecount)*6            /* how many fonts on the last page?  */
  252.         if lastpage>0 then pagecount=pagecount+1    /* add a page if there's a remainder */
  253.         end
  254.     else pagecount=pfontcount
  255.  
  256.     /* Repeat for each page to print */
  257.     j=0
  258.     do i=1 to pagecount
  259.         j=j+1
  260.  
  261.         if specsize=small then do            /* Layout for 6 to a page */
  262.             do ii=1 to 6
  263.                 k=ii+(ii-1)*0.5             /* this gives us the correct offset */
  264.  
  265.                 if lastpage>0 & i=pagecount & ii>lastpage then do
  266.                     /* Change the title(s) to blank */
  267.                     'setvariablevalue "' '" variable FontName'ii
  268.                     /* Set the text color to white */
  269.                     'beginstyletag styletag FontSample'ii
  270.                     'setcolor text white styletag FontSample'ii
  271.                     'endstyletag styletag FontSample'ii
  272.                     end
  273.                 else do
  274.                     /* Change the title(s) */
  275.                     'setvariablevalue "'pfonts.j'" variable FontName'ii
  276.                     /* Change the font style */
  277.                     'beginstyletag styletag FontSample'ii
  278.                     'setfont 'pfonts.j' styletag FontSample'ii
  279.                     'endstyletag styletag FontSample'ii
  280.                 end
  281.                 j=j+1
  282.             end ii
  283.             j=j-1
  284.             end
  285.         else do
  286.             /* Change the title */
  287.             'setvariablevalue "'pfonts.j'" variable FontName'
  288.  
  289.             /* Change the font and style */
  290.             'beginstyletag styletag FontSample'
  291.             'setfont 'pfonts.j' styletag FontSample'
  292.             'endstyletag styletag FontSample'
  293.         end
  294.  
  295.         /* Print the font sample page */
  296.         'printdocument copies 1 page 1 sides both scale actual output grayscale printermarks off mirror off negative off'
  297.         call setbusy(i/pagecount*100)
  298.     end i
  299.  
  300.     'closebusyrequester 'hBusyReq
  301.     'closedocument force'
  302. RETURN
  303.  
  304. DOALERT:
  305. parse arg astring
  306. /* Display an alert requester */
  307.         allocarexxrequester '"Script Alert"' 334 55
  308.             hAlertReq=result
  309.         addarexxgadget hAlertReq TEXT 8 12 268 border none string '"'astring'"'
  310.         addarexxgadget hAlertReq EXIT 252 38 70 label "Exit"
  311.         doarexxrequester hAlertReq
  312.         freearexxrequester hAlertReq
  313. RETURN
  314.  
  315. SETBUSY:
  316.     parse arg value
  317.     ADDRESS PAGESTREAM
  318.     setbusyrequester hBusyReq current value
  319.     getbusyrequester hBusyReq
  320.     if result=1 then call CLEANUP(1)
  321.     ADDRESS COMMAND
  322. RETURN
  323.  
  324. CLEANUP:
  325.     'closebusyrequester 'hBusyReq
  326.     'closedocument force'
  327. EXIT
  328.