home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / gif_text.zip / ext_gif.cmd < prev    next >
OS/2 REXX Batch file  |  1998-12-09  |  7KB  |  237 lines

  1. /* */
  2. /* Load up advanced REXX functions */
  3. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  4. call SysLoadFuncs
  5.  
  6. foo=rxfuncquery('rxgdloadfuncs')
  7. if foo=1 then do
  8.   Call RxFuncAdd 'RxgdLoadFuncs', 'RXGDUTIL', 'RxgdLoadFuncs'
  9.   Call RxgdLoadFuncs
  10. end
  11.  
  12. say " This utility is meant to be used in conjunction with the gif_text utility "
  13. say
  14. say " Given a grid of fonts in a .GIF file, and a .IND file containing some "
  15. say " basic info, this utility will create an 'alphabyte' -- "
  16. say "      it will extract seperate .GIF files for each  character referenced "
  17. say "      in the .IND file.   "
  18. say " (this can be useful for debugging the .IND file)"
  19. say
  20.  
  21. call charout , " Enter ind file (that contains info on the Grid Of Fonts) ? "
  22. pull anind
  23.  
  24. if pos('.',anind)=0 then anind=anind'.ind'
  25. parse var anind anind0 '.' .
  26.  
  27. afile=anind
  28. if afile=' ' then exit
  29. ii=0
  30. if stream(afile,'c','query exists')=' ' then do
  31.  say " no such file: " afile
  32.  exit
  33. end
  34. do until lines(afile)=0
  35.   ii=ii+1
  36.   tmp.ii=linein(afile)
  37. end
  38. tmp.0=ii
  39. lines.0=ii
  40. do iii=1 to lines.0
  41.    lines.iii=tmp.iii
  42. end /* do */
  43. foo=stream(afile,'c','close')
  44.  
  45. textcolor='000000' ; backcolor='ffffff'
  46. defgifs=' '; xoffset=0 ; yoffset=0 ; inrow=16 ; hchar=47  ; wchar=35 ;isbw=1
  47. charset=' !"'||"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
  48.  
  49. /* default names for odd characters */
  50. namelist.0='!@#$%^&*()_+{}|:"<>?/.,;\][`~'||"'=-"
  51. namelist.1='exclam'
  52. namelist.2='amp'
  53. namelist.3='hash'
  54. namelist.4='dollar'
  55. namelist.5='percent'
  56. namelist.6='caret'
  57. namelist.7='amp'
  58. namelist.8='ast'
  59. namelist.9='lparen'
  60. namelist.10='rparen'
  61. namelist.11 ='under'
  62. namelist.12='plus'
  63. namelist.13='lcurly'
  64. namelist.14='rcurly'
  65. namelist.15='vbar'
  66. namelist.16='colon'
  67. namelist.17='dquote'
  68. namelist.18='lt'
  69. namelist.19='gt'
  70. namelist.20='quest'
  71. namelist.21='fslash'
  72. namelist.22='period'
  73. namelist.23='comma'
  74. namelist.24='semic'
  75. namelist.25='bslash'
  76. namelist.26='rsqparen'
  77. namelist.27='lsqparen'
  78. namelist.28='lquote'
  79. namelist.29='squigle'
  80. namelist.30='quote'
  81. namelist.31='equal'
  82. namelist.32='dash'
  83.  
  84.  
  85. do mm=1 to lines.0
  86.    foo=strip(lines.mm)
  87.    if abbrev(foo,';')=1 | foo="" then iterate
  88.    if pos('=',foo)=0 then iterate
  89.    parse var foo athing '=' stuff ; athing=strip(translate(athing))
  90.    select
  91.       when athing='DEFAULTS' then  defgifs=strip(stuff)
  92.       when athing='TEXT' then do
  93.                stuff2=get_from_hex(stuff)
  94.               if stuff2<>' ' then textcolor=strip(stuff)
  95.       end
  96.       when athing='BACK' then do
  97.          stuff2=get_from_hex(stuff)
  98.          if stuff2<>' ' then backcolor=strip(stuff)
  99.       end
  100.       when athing='DEF_OFFSET' then do
  101.              stuff=translate(stuff,' ',',')
  102.              parse var stuff a1 a2
  103.              if datatype(a1)='NUM'  then xoffset=a1
  104.              if datatype(a2)='NUM'  then yoffset=a2
  105.       end  /* Do */
  106.       when athing='DEF_CHARSIZE' then do
  107.              stuff=translate(stuff,' ',',')
  108.              parse var stuff a1 a2
  109.              if datatype(a1)='NUM'  then wchar=a1
  110.              if datatype(a2)='NUM'  then hchar=a2
  111.       end  /* Do */
  112.       when athing='DEF_CHARS' then charset=stuff
  113.       when athing='DEF_BW' then isbw=pos(strip(translate(stuff)),'Y YES 1')
  114.       when athing='DEF_INROW' then
  115.               if datatype(strip(stuff))='NUM' then inrow=strip(stuff)
  116.       otherwise nop
  117.    end  /* select */
  118. end /* do */
  119. say "DefChars: " charset
  120. say "GIF file: "defgifs
  121. im = RxgdImageCreateFromGIF(defgifs)
  122. if im=1 | im=0 then  do
  123.  say "Error, could not process " defgifs 
  124.  say " Are you running EXT_GIFS from the font's own directory?"
  125.   exit
  126. end
  127.  
  128. say " Reading from fonts displayed in: " defgifs 
  129. say " The following characters will be produced: " charset
  130.  
  131. hlist.0=0
  132. backcolor=get_from_hex(backcolor)
  133.    parse var backcolor bdefr bdefg bdefb
  134. textcolor=get_from_hex(textcolor)
  135.    parse var textcolor tdefr tdefg tdefb
  136. ido=0
  137. /* for each character in the charset ... */
  138. /*do ic=1 to length(charset)*/
  139. do ic=1 to length(charset)
  140.      achar=substr(charset,ic,1)
  141.      if achar=' ' then iterate
  142.  
  143. /* determine x offset: */
  144.    irow=1+((ic-0.1)%inrow)
  145.    icol=ic-((irow-1)*inrow)
  146.  
  147. /* upper left is 0,0 */
  148.    xat=xoffset + ((icol-1)*wchar)
  149.    yat=yoffset+ ((irow-1)*hchar)
  150.  
  151.    cim=rxgdimagecreate(wchar,hchar)
  152.  
  153.    foo=rxgdimagecopy(cim,im,0,0,xat,yat,wchar,hchar)
  154.  
  155.  
  156.    foo=rxgdimagecolordeallocate(cim,0)
  157.    oy1=rxgdimagecolorallocate(cim,bdefr,bdefg,bdefb)
  158.    foo=rxgdimagecolordeallocate(cim,1)
  159.    oy2=rxgdimagecolorallocate(cim,tdefr,tdefg,tdefb)
  160.  
  161.    acharg=achar
  162.    if translate(achar)<>achar then acharg=achar'lc'
  163.  
  164.    if pos(translate(achar),'1234567890ABCDEFGHIJKLMNOPQRSTUVXWYZ#-_%$')=0 then DO
  165.         ACHARg=a_defname(achar)
  166.         call charout," For: "achar ": enter name (ENTER="ACHARG"):"
  167.         pull acharg0
  168.         if acharg0<>'' then do 
  169.             acharg=acharg0
  170.         end /* do */
  171.         iih=hlist.0+1
  172.         hlist.iih=achar ; hlist.iih.!ascii=c2d(achar)
  173.         parse var acharg acharg '.' .
  174.         hlist.iih.!file=acharg'.GIF'
  175.         hlist.0=iih
  176.    end  /* Do */
  177.    acharg=acharg'.GIF'
  178.   foo=rxgdimagegif(cim,acharG)
  179.    say  " Writing character " achar "(@ offset "  xat yat ") to : " acharg
  180.    ido=ido+1
  181.   foo= RxgdImageDestroy(cim)
  182.  
  183.  
  184. end /* do */
  185. say " Total files written= " ido '(' hlist.0 ' with non-standard names)'
  186.  
  187. if hlist.0>0 then do
  188.   anind1=systempfilename(anind0'.???')
  189.   say "Note: you should add the contents of "anind1 " to "anind
  190.   foo=stream(anind1,'c','open write')
  191.   do ii=1 to hlist.0
  192.     call lineout anind1,'##'||hlist.ii.!ascii' 'hlist.ii.!file'   'hlist.ii
  193.   end /* do */
  194.   call lineout anind1
  195.   foo=stream(anind1,'c','close')
  196. end
  197.  
  198. foo= RxgdImageDestroy(im)
  199.  
  200. exit
  201.  
  202.  
  203.  
  204.  
  205. /**************************/
  206. /* convert ff21b3 "hex" color code to decimal r g b values
  207.   If bad value, return ' /' */
  208. get_from_hex:procedure
  209. parse arg hval
  210.  
  211. hval=strip(strip(hval),,'"')
  212. hval=strip(hval,,'#')
  213. select 
  214.   when length(hval)<>6 then return ' '
  215.   when verify(translate(hval),'0123456789ABCDEF')>0 then return ' '
  216.   otherwise do
  217.     a1=left(hval,2)
  218.     a2=substr(hval,3,2)
  219.     a3=substr(hval,5,2)
  220.     r=x2d(a1)
  221.     g=x2d(a2)
  222.     b=x2d(a3)
  223.   end
  224. end /* do */
  225. return r ' ' g ' ' b
  226.  
  227. /***********************/
  228. /* some default names */
  229. a_defname:procedure expose  namelist.
  230. parse arg achar
  231. ii=pos(achar,namelist.0)
  232. if ii>0 then do
  233.    return translate(namelist.ii)||'.GIF'
  234. end
  235. return 'ASC_'||c2d(achar)||'.GIF'
  236.  
  237.