home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Patch / Programs / PGS3ITU3.LHA / FontSpec.rexx next >
Encoding:
OS/2 REXX Batch file  |  1996-05-03  |  10.3 KB  |  359 lines

  1. /* $VER: FontSpec.rexx 3.0 (03.05.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 'open "pagestream3:macros/fontspec6.doc"'
  38.         else 'open "pagestream3:macros/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 12 64 240 label '"_Number"' labelpos left
  65.         hSpecSizeGadget=result
  66.     addarexxgadget hInstructReq CYCLE 292 64 248 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.     getfontfamilies ifonts
  89.     ifontcount=result
  90.  
  91.     /* Count Fonts */
  92.     fontcount=0
  93.     do i=0 to ifontcount-1
  94.         getfontstyles ifonts.i styles
  95.         stylecount=result
  96.         /* Repeat for each style */
  97.         do ii=0 to stylecount-1
  98.             fontcount=fontcount+1
  99.         end ii
  100.     end i
  101.     /* Shuffle 0 to end to work with sort routine */
  102.     ifonts.ifontcount=ifonts.0
  103. RETURN
  104.  
  105. SORTIFONTS:
  106. /* SORT THE LIST ALPHABETICALLY */
  107.     DO tick = 1 to ifontcount-1
  108.         nexttick=tick+1
  109.         IF ifonts.tick > ifonts.nexttick THEN DO
  110.             store=ifonts.nexttick
  111.             ifonts.nexttick=ifonts.tick
  112.             DO bubpos = tick-1 to 1 by -1 WHILE (store < ifonts.bubpos)
  113.                 nexttick=bubpos+1
  114.                 ifonts.nexttick = ifonts.bubpos
  115.             END bubpos
  116.             bubpos=bubpos+1
  117.             ifonts.bubpos=store
  118.         END
  119.     END tick
  120. RETURN
  121.  
  122. SORTPFONTS:
  123. /* SORT THE LIST ALPHABETICALLY */
  124.         DO tick = 1 to pfontcount-1
  125.         nexttick=tick+1
  126.         IF pfonts.tick > pfonts.nexttick THEN DO
  127.             store=pfonts.nexttick
  128.             pfonts.nexttick=pfonts.tick
  129.             DO bubpos = tick-1 to 1 by -1 WHILE (store < pfonts.bubpos)
  130.                 nexttick=bubpos+1
  131.                 pfonts.nexttick = pfonts.bubpos
  132.             END bubpos
  133.             bubpos=bubpos+1
  134.             pfonts.bubpos=store
  135.         END
  136.     END tick
  137. RETURN
  138.  
  139. CHOOSEFONTS:
  140. /* FIND OUT WHICH FONTS TO PRINT */
  141.  
  142.     call alloclists()
  143.  
  144.     /* Initialize the installed font list */
  145.     do i=1 to ifontcount
  146.     'getfontstyles "'ifonts.i'" 'styles
  147.         stylecount=result
  148.         'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  149.     end i
  150.  
  151.         /* Allocate and build the requester */
  152.         allocarexxrequester '"Create Font Specimen Sheets"' 528 201
  153.             hChooseReq=result
  154.         addarexxgadget hChooseReq TEXT 8 10 250 border none string "'Select the typefaces to print:'"
  155.         addarexxgadget hChooseReq EXIT 12 184 70 label "_Print"
  156.             hPrintGadget=result
  157.         addarexxgadget hChooseReq EXIT 224 42 80 label '"_Add    ->"'
  158.             hAddGadget=result
  159.         addarexxgadget hChooseReq EXIT 224 62 80 label '"_Remove <-"'
  160.             hRemoveGadget=result
  161.         addarexxgadget hChooseReq EXIT 446 184 70 label "_Cancel"
  162.             hCancelGadget=result
  163.         addarexxgadget hChooseReq SCROLLIST 12 32 200 139 label '"Installed Typefaces"' labelpos aboveleft
  164.             hInstalledFontsGadget=result
  165.         addarexxgadget hChooseReq SCROLLIST 316 32 200 139 label '"Typefaces to Print"' labelpos aboveleft
  166.             hPrintFontsGadget=result
  167.  
  168.     /* FONT SELECTION LOOP */
  169.     exitflag=0
  170.     do until exitflag=1
  171.  
  172.         /* Do the font selection requester */
  173.         setarexxgadget hChooseReq hInstalledFontsGadget list hInstalledFontsList current 0
  174.         setarexxgadget hChooseReq hPrintFontsGadget list hPrintFontsList current 0
  175.         doarexxrequester hChooseReq
  176.             action=result
  177.  
  178.         select
  179.             when action=hCancelGadget then do      /* THE USER CANCELLED   */
  180.                 call freelists()
  181.                 retvalue=9
  182.                 exitflag=1
  183.                 end
  184.             when action=hPrintGadget then do      /* PRINT THE FONTS!     */
  185.                 call freelists()
  186.                 retvalue=1
  187.                 exitflag=1
  188.                 end
  189.             when action=hAddGadget then do          /* ADD A FONT TO PRINT  */
  190.                 getarexxgadget hChooseReq hInstalledFontsGadget current
  191.                 cfont=result+1
  192.                 pfontcount=pfontcount+1
  193.                 pfonts.pfontcount=ifonts.cfont
  194.                 call sortpfonts()                  /* sort the to print list  */
  195.                 call freelists()                  /* free the arexx lists    */
  196.                 call alloclists()                  /* alloc the lists again   */
  197.                 do i=1 to pfontcount              /* fill the to print list  */
  198.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  199.                 end i
  200.                 do i=cfont to ifontcount          /* remove from ifonts      */
  201.                     nexti=i+1
  202.                     ifonts.i=ifonts.nexti
  203.                 end
  204.                 ifontcount=ifontcount-1
  205.                 do i=1 to ifontcount              /* fill the installed list */
  206.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  207.                 end i
  208.                 end
  209.             when action=hRemoveGadget then do       /* REMOVE A FONT TO PRINT */
  210.                 getarexxgadget hChooseReq hPrintFontsGadget current
  211.                 cfont=result+1
  212.                 ifontcount=ifontcount+1
  213.                 ifonts.ifontcount=pfonts.cfont
  214.                 call sortifonts()                  /* sort the installed list */
  215.                 call freelists()                  /* free the arexx lists    */
  216.                 call alloclists()                  /* alloc the lists again   */
  217.                 do i=1 to ifontcount              /* fill the installed list */
  218.                     'addarexxlist 'hInstalledFontsList' "'ifonts.i'"'
  219.                 end i
  220.                 do i=cfont to pfontcount          /* remove from pfonts      */
  221.                     nexti=i+1
  222.                     pfonts.i=pfonts.nexti
  223.                 end
  224.                 pfontcount=pfontcount-1
  225.                 do i=1 to pfontcount              /* fill the to print list  */
  226.                     'addarexxlist 'hPrintFontsList' "'pfonts.i'"'
  227.                 end i
  228.                 end
  229.         end
  230.     end
  231.     freearexxrequester hChooseReq
  232.  
  233.     if retvalue=9 then EXIT
  234.     if retvalue=1 & pfontcount=0 then do
  235.         call doalert("No fonts selected to print!")
  236.         EXIT
  237.     end
  238.  
  239. RETURN
  240.  
  241. ALLOCLISTS:
  242. /* Allocate lists for the installed fonts and the fonts to print */
  243.     allocarexxlist
  244.         hInstalledFontsList=result     /* list of installed fonts */
  245.     allocarexxlist
  246.         hPrintFontsList=result         /* list of fonts to print */
  247. RETURN
  248.  
  249. FREELISTS:
  250. /* Free lists for the installed fonts and the fonts to print */
  251.     freearexxlist hInstalledFontsList
  252.     freearexxlist hPrintFontsList
  253. RETURN
  254.  
  255. PRINTFONTS:
  256. /* PRINT LOOP */
  257.     openbusyrequester message "'Creating Font Specimens...'" thermometer enabled abort enabled total 100 current 0
  258.         hBusyReq=result
  259.  
  260.     /* Build one master stem variable from the fonts */
  261.     do i=1 to pfontcount
  262.  
  263.         /* Get the type styles for the font */
  264.         getfontstyles pfonts.i styles
  265.         stylecount=result
  266.  
  267.         /* Repeat for each type style */
  268.         do ii=0 to stylecount-1
  269.  
  270.             /* Fill the master stem variable */
  271.             totalfonts=totalfonts+1
  272.             mfonts.totalfonts=pfonts.i
  273.             mstyles.totalfonts=styles.ii
  274.         end ii
  275.     end i
  276.  
  277.     /* Count the pages to print */
  278.     if specsize=small then do
  279.         pagecount=trunc(totalfonts/6)
  280.         lastpage=(totalfonts/6-pagecount)*6            /* how many fonts on the last page?  */
  281.         if lastpage>0 then pagecount=pagecount+1    /* add a page if there's a remainder */
  282.         end
  283.     else pagecount=totalfonts
  284.  
  285.     /* Repeat for each page to print */
  286.     j=0
  287.     do i=1 to pagecount
  288.         j=j+1
  289.  
  290.         if specsize=small then do            /* Layout for 6 to a page */
  291.             do ii=1 to 6
  292.                 k=ii+(ii-1)*0.5             /* this gives us the correct offset */
  293.  
  294.                 if lastpage>0 & i=pagecount & ii>lastpage then do
  295.                     /* Change the title(s) to blank */
  296.                     'setvariablevalue "' '" variable FontName'ii
  297.                     /* Set the text color to white */
  298.                     'beginstyletag styletag FontSample'ii
  299.                     'setcolor text white styletag FontSample'ii
  300.                     'endstyletag styletag FontSample'ii
  301.                     end
  302.                 else do
  303.                     /* Change the title(s) */
  304.                     'setvariablevalue "'mfonts.j'-'mstyles.j'" variable FontName'ii
  305.                     /* Change the font and style */
  306.                     'beginstyletag styletag FontSample'ii
  307.                     'setfont 'mfonts.j' styletag FontSample'ii
  308.                     'settypestyle 'mstyles.j' styletag FontSample'ii
  309.                     'endstyletag styletag FontSample'ii
  310.                 end
  311.                 j=j+1
  312.             end ii
  313.             j=j-1
  314.             end
  315.         else do
  316.             /* Change the title */
  317.             'setvariablevalue "'mfonts.j'-'mstyles.j'" variable FontName'
  318.  
  319.             /* Change the font and style */
  320.             'beginstyletag styletag FontSample'
  321.             'setfont 'mfonts.j' styletag FontSample'
  322.             'settypestyle 'mstyles.j' styletag FontSample'
  323.             'endstyletag styletag FontSample'
  324.         end
  325.  
  326.         /* Print the font sample page */
  327.         'printdocument copies 1 page 1 sides both scale actual output grayscale printermarks off mirror off negative off'
  328.         call setbusy(i/pagecount*100)
  329.     end i
  330.  
  331.     'closebusyrequester 'hBusyReq
  332.     'closedocument force'
  333. RETURN
  334.  
  335. DOALERT:
  336. parse arg astring
  337. /* Display an alert requester */
  338.         allocarexxrequester '"Script Alert"' 334 55
  339.             hAlertReq=result
  340.         addarexxgadget hAlertReq TEXT 8 12 268 border none string '"'astring'"'
  341.         addarexxgadget hAlertReq EXIT 252 38 70 label "_Exit"
  342.         doarexxrequester hAlertReq
  343.         freearexxrequester hAlertReq
  344. RETURN
  345.  
  346. SETBUSY:
  347.     parse arg value
  348.     ADDRESS PAGESTREAM
  349.     setbusyrequester hBusyReq current value
  350.     getbusyrequester hBusyReq
  351.     if result=1 then call CLEANUP(1)
  352.     ADDRESS COMMAND
  353. RETURN
  354.  
  355. CLEANUP:
  356.     'closebusyrequester 'hBusyReq
  357.     'closedocument force'
  358. EXIT
  359.