home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / ttf_text.zip / ttf_text.cmd < prev   
OS/2 REXX Batch file  |  1999-03-17  |  9KB  |  360 lines

  1. /*  Michal Necasek  <mike@mendelu.cz>
  2.     Daniel Hellerstein (danielh@econ.ag.gov)
  3. Create a big-text banner using TTF fonts. 
  4. */
  5.  
  6. /********** Begin user changable parameters (used as defaults ******/
  7.  
  8. /* The "foreground" character                    */
  9. forechar='+'
  10.  
  11. /* and the background character                  */
  12. backchar=' '
  13.  
  14. /* Instead of a single foreground character, you can use the characters
  15.   from a message. To enable this, set:
  16.       use_filler_message=1
  17.       filler_message=character_string_to_fill_with
  18.    If you set filler_message='', then the message (supplied by
  19.    the user) will be used as the filler_message.   */
  20. use_filler_message=0
  21. filler_message=''
  22.  
  23. /* Use ansi for bold, reverse, etc. when displaying prompts 
  24.      use_ansi=1  : use ansi 
  25.      use_ansi=0  : do not use ansi 
  26.    Note:
  27.       If you see a lot of [,$, and other such junk on screen, then you do
  28.       NOT have ansi support installed. To install ansi support, 
  29.       add the following line to config.sys  
  30.           device=x:\os2\mdos\ansi.sys
  31.       where x: is your boot drive               */
  32. use_ansi=1
  33.  
  34.  
  35. /* default "ttf-fonts root directory". If the requested font is not
  36.    found in the current directory, it will be searched for in all directories under
  37.    this default_ttfdir. Set default_ttfdir='' to suppress this */
  38. default_ttfdir='d:\os2\mdos\winos2'
  39.  
  40.  
  41. /* default output file. Leave blank to output to screen
  42.    Note: this is NOT used when command line parameters are specified;
  43.          in which case the default is output to stdout, which
  44.          can be easily redirected (using >) to a file */
  45. outfile='ttf_text.out'
  46.  
  47. /* ============= End of user changeable parameters =============== */
  48.  
  49.  
  50. call init               /* initialize some stuff */
  51.  
  52.  
  53. parse arg ttfont psize as_landscape  message 
  54. wastt=ttfont
  55.  
  56. if ttfont='?' then  do          /* a request for help ? */
  57.  call show_intro
  58.  exit
  59. end
  60.  
  61. /* ask user to supply them, and/or check command line parameters. */
  62. call get_params
  63.  
  64. /* ---  THIS DOES THE WORK!!!!  ---- */
  65.  
  66. rc = rxttf_image(message,ttfont,psize, data)
  67.  
  68.  
  69. /* Check for an error */
  70. if rc<>0 then do
  71.     say "Error in rxttf_image: "rc
  72.     exit
  73. end /* do */
  74.  
  75.  
  76. /* Note: data.!rows and data.!cols are the dimensions of the image */
  77.  
  78. say data.!rows 'rows x' data.!cols 'cols'
  79.  
  80. /* Now, convert the "bitmap" to printable characters */
  81.  
  82. call convert_data
  83.  
  84. /* And, finally, display the big-text "image" */
  85.  
  86. if as_landscape<>1 then do              /* portrait orientation */
  87.    do i = 0 to data.!rows - 1                      /* for each row of the image */
  88.       aline=data.i
  89.       if wastt='' & outfile<>'' then do
  90.          call lineout outfile,aline
  91.       end
  92.       else do
  93.          say aline
  94.       end
  95.    end
  96. end
  97. else do                         /* landscape */
  98.    do icol=1 to data.!cols
  99.       aline=''
  100.       do irow=data.!rows-1 to 0 by -1
  101.          aline=aline||substr(data.irow,icol,1)
  102.       end 
  103.       if wastt='' & outfile<>'' then do
  104.          call lineout outfile,aline
  105.       end
  106.       else do
  107.          say aline
  108.       end
  109.    end 
  110. end                     /* as_landscape */
  111.  
  112. if wastt='' & outfile<>'' then do
  113.   call lineout outfile
  114.   say " Output appended to: " bold ||outfile||normal
  115. end
  116.  
  117. exit
  118.  
  119.  
  120. /**************************/
  121. /* convert data to printable characters */
  122. convert_data:
  123.  
  124. /* this is needed if use_filler_message=1 */
  125. if filler_message='' then filler_message=message 
  126. len_filler=length(filler_message)
  127.  
  128. do i = 0 to data.!rows - 1                      /* for each row of the image */
  129.   iat=1
  130.  
  131. /* convert ascii 0 & 1 to back and fore ground characters */
  132.   aline=translate(data.i, backchar||forechar, '0001'x)  
  133.  
  134. /* Display the big-text using characters from a message? */
  135.   if use_filler_message=1 then do        
  136.      achar=substr(filler_message,iat,1)                  
  137.      do kk=1 to data.!cols                     /* substitute in cyclical fashion */
  138.         if substr(aline,kk,1)=forechar then do
  139.            aline=overlay(achar,aline,kk,1)
  140.            iat=iat+1 ; if iat>len_filler then iat=1
  141.            achar=substr(filler_message,iat,1)
  142.         end
  143.      end /* do */
  144.   end /* do */
  145.   data.i=aline                  /* save it */
  146. end
  147.  
  148. return 1
  149.  
  150.  
  151. /***************/
  152. show_intro:
  153.    say "Create a text banner using a TTF font"
  154.    say
  155.    say "Usage: TTF_TEXT ttf_file  point_size landscape message"
  156.    say ' Where:'
  157.    say '   TTF_FILE = name of a TTF font file '
  158.    say '  POINT_SIZE= Point size '
  159.    say '   LANDSCAPE= Orientation: 0 for portrait, 1 for landscape'
  160.    say '     MESSAGE= The message to write (it may contain multiple words)'
  161.    say ' '
  162.    say " Or, run TTF_TEXT without arguments to be prompted."
  163.    say
  164.    say "Hint: To create long messages, use > to redirect output to a file"
  165. return 1
  166.  
  167.  
  168. /*********************/
  169. /* ask user for some input parameters */
  170. get_params:
  171.  
  172.  
  173. if ttfont='' then do
  174.   say cy_ye"   >>> Create a text banner using TTF fonts  <<< "normal
  175.   say
  176. end 
  177.  
  178. if message='' then do
  179.   call charout,bold'Enter a message string:'normal
  180.   parse pull message
  181.   if message='' then message='Hello!'
  182. end
  183.  
  184.  
  185. do forever
  186.   if psize='' then do
  187.     call charout,bold"Choose the point size: "normal
  188.     pull psize
  189.   end
  190.   if psize='' then psize=12
  191.   if datatype(psize)<>'NUM' then do
  192.      say reverse"   Please enter an integer point size "normal
  193.      psize=''     
  194.      iterate
  195.   end /* do */
  196.   leave
  197. end
  198.  
  199.  
  200. do forever
  201.    if ttfont='' then do
  202.      call charout,bold'Select a TTF font (? to list .TTF files): 'normal  
  203.      pull ttfont ; ttfont=strip(ttfont)
  204.    end
  205.    if left(ttfont,1)="?" then do
  206.      call showttfs
  207.      ttfont=''
  208.      iterate
  209.    end
  210.  
  211.    if ttfont='' then ttfont='bisque'
  212.    if pos('.',ttfont)=0 then ttfont=ttfont'.ttf'
  213.    foo=stream(ttfont,'c','query exists')
  214.    if foo='' then do
  215.       ttfont=lookfont(ttfont)
  216.       if ttfont='' then do
  217.           say "Sorry, could not find "ttfont
  218.           ttfont=''
  219.          iterate
  220.       end
  221.    end
  222.    leave
  223. end /* do */
  224.  
  225. do forever
  226.     if as_landscape<>' ' then leave
  227.     call charout,bold'Orientation:'normal' 0 (or ENTER) for portrait, 1 for Lanscape: '
  228.     pull foo
  229.     if foo='' then foo=0
  230.     foo=strip(foo)
  231.     if wordpos(foo,'0 1')=0 then do
  232.        as_landscape=''
  233.        iterate
  234.     end
  235.     as_landscape=foo
  236.     leave
  237. end
  238.  
  239. return 1
  240.  
  241.  
  242. /***************************************/
  243. /* show ttf fonts in current and under default directory */
  244. showttfs:
  245.       lookdef=0
  246.       parse var ttfont . thisdir
  247.       if thisdir='' then lookdef=1
  248.  
  249.       if thisdir="" then    thisdir=directory()
  250.       say 
  251.       say  cy_ye' List of .TTF files in: ' normal bold thisdir normal
  252.       do while queued()>0
  253.          pull .
  254.       end 
  255.       '@DIR /b  '||strip(thisdir,'t','\')'\*.ttf  | rxqueue'
  256.       foo=show_dir_queue('.TTF')
  257.       say
  258.  
  259. if lookdef<>1 |  default_ttfdir='' then return 0
  260.       thisdir=default_ttfdir
  261.       say  cy_ye' List of .TTF files under: ' normal bold thisdir normal
  262.       do while queued()>0
  263.          pull .
  264.       end 
  265.       '@DIR /b /s '||strip(thisdir,'t','\')'\*.ttf  | rxqueue'
  266.       foo=show_dir_queue('.TTF')
  267.       say
  268.       ttfont=''
  269. return 1
  270.  
  271. /***********************************************/
  272. /* look for font using sysfiletree */
  273. /* Load up advanced REXX functions */
  274. lookfont:procedure expose default_ttfdir
  275. parse arg ttfont
  276. foo=rxfuncquery('sysloadfuncs')
  277. if foo=1 then do
  278.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  279.   call SysLoadFuncs
  280. end
  281. if rxfuncquery('sysloadfuncs')=1 then return ''      /* give up */
  282. if default_ttfdir='' then return ''
  283.  
  284. aa=strip(default_ttfdir,'t','\')'\'ttfont
  285. foo=sysfiletree(aa,'goo','FSO')
  286. if goo.0=0 then return ''
  287. return goo.1
  288.  
  289.  
  290.  
  291.  
  292. /***********************************************/
  293. /* initialize some stuff */
  294. init:
  295.  
  296. isis=rxfuncquery('rxttf_image')
  297. if isis=1 then do
  298.   call RxFuncAdd 'rxttf_image', 'RXTTF', 'rxttf_image'
  299.   isis=rxfuncquery('rxttf_image')
  300.   if isis<>0 then do
  301.       say "Sorry, RXTTF.DLL is not available."
  302.       exit
  303.   end
  304. end 
  305.  
  306. /* Enable these character if you want to use some ansi screen controls   */
  307. if use_ansi=1 then do
  308.    aesc='1B'x
  309.    cy_ye=aesc||'[37;46;m'
  310.    cyanon=cy_ye
  311.    normal=aesc||'[0;m'
  312.    bold=aesc||'[1;m'
  313.    re_wh=aesc||'[31;47;m'
  314.    reverse=aesc||'[7;m'
  315. end
  316. else do
  317.    cy_ye=' '; cyanon=' ';normal=' '; bold=' '; re_wh=' ';reverse=' ' 
  318. end
  319. return 1
  320.  
  321. /*********/
  322. /* show stuff in queue as a list */
  323. show_dir_queue:procedure expose qlist.
  324. parse arg lookfor
  325.     ibs=0 ;mxlen=0
  326.     if lookfor<>1 then
  327.        nq=queued()
  328.      else
  329.         nq=qlist.0
  330.     do ii=1 to nq
  331.        if lookfor=1 then do
  332.           aa=qlist.ii
  333.           ii2=lastpos('\',aa) ; anam=substr(aa,ii2+1)
  334.        end /* do */
  335.        else do
  336.           pull aa
  337.           if pos(lookfor,aa)=0 then iterate
  338.           parse var aa anam (lookfor) .
  339.           if strip(anam)='.' | strip(anam)='..' then iterate
  340.        end
  341.        ibs=ibs+1
  342.        anam=filespec('n',anam)
  343.        blist.ibs=anam
  344.        mxlen=max(length(anam),mxlen)
  345.     end /* do */
  346. arf=""
  347. do il=1 to ibs
  348.    anam=blist.il
  349.    arf=arf||left(anam,mxlen+2)
  350.    if length(arf)+mxlen+2>75  then do
  351.         say arf
  352.         arf=""
  353.    end /* do */
  354. end /* do */
  355. if length(arf)>1 then say arf
  356. say
  357. return 1
  358.  
  359.  
  360.