home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK2 / MULTI_04 / FNT2PO.ZIP / FNT2POV1.BAS next >
BASIC Source File  |  1992-08-28  |  6KB  |  150 lines

  1. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  2. ''  Conversion notes:                                          ''
  3. ''     DEFINT means any untyped variable defaults to INT       ''
  4. ''     GET #1,,IN$ means get from file #1 into IN$ for a length''
  5. ''        of however big IN$ already is.                       ''
  6. ''     COMMAND$ is the command line less the program name. Just''
  7. ''        rewrite the lousy BASIC interpretation of parameters.''
  8. ''     Type ! is a float, & is a long int, # is an 8-byte float''
  9. ''     STRING$(n,c) function returns a string containing 'n'   ''
  10. ''        occurances of the character 'c'.                     ''
  11. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  12. defint a-z
  13. VERSION!=1.10
  14. print using "FONT2DAT (c) Koehler 1991,1992 v##.## ";version!
  15. def fnh$(x)=right$("0"+hex$(x),2)
  16. TRUE= (1=1) : FALSE = (1=0)
  17. dim TwoToThe%(7) : for k=0 to 7 : TwoToThe%(k)=2^k : next k
  18. pixel=0      ' 0=Sphere  1=Dot  2=Square  3=Box
  19. debug=1
  20. cmd$=command$
  21. if left$(cmd$,1)="-" then pixel=val(mid$(cmd$,2,1)):cmd$=mid$(cmd$,4)
  22. if cmd$="" then gosub Usage:end
  23. if pixel>3 then pixel=0
  24. if pixel=0 then print "Generating Spheres"
  25. if pixel=1 then print "Generating Squares"
  26. if pixel=2 then print "Generating Dots"
  27. if pixel=3 then print "Generating Boxes"
  28. fl$=cmd$
  29. if instr(fl$,".") then ext$=mid$(fl$,instr(fl$,".")) : fl$=left$(fl$,instr(fl$,".")-1)
  30. if ext$="" then ext$=".fnt"
  31.  
  32.   open fl$+ ext$  for BINARY as #1
  33.   open fl$+".inc" for output as #2
  34.   if debug then open fl$+".deb" for output as #3 ' graphic layout
  35.  
  36.   '* Read font header
  37.   in$=chr$(0)
  38.   get #1,,in$
  39.   size&=asc(in$)
  40.   get #1,,in$
  41.   size&=asc(in$)*256+size&
  42.   get #1,,in$
  43.   numchars=asc(in$) : if numchars=0 then numchars=256
  44.   get #1,,in$
  45.   ascoff=asc(in$)
  46.   get #1,,in$
  47.   chxsize=asc(in$)
  48.   get #1,,in$
  49.   chysize=asc(in$)
  50.   get #1,,in$
  51.   chbytes=asc(in$)
  52.   print "'";fl$;ext$;"'";
  53.   print using " is ####, bytes long, ### characters, starting  @ ###";size&;numchars;ascoff
  54.   print using "                     X-size=### , Y-size=### , ### bytes/char";chxsize;chysize;chbytes
  55.   print #2,"// '";fl$;ext$;"'";
  56.   print #2,using " is ####, bytes long, ### characters, starting  @ ### ";size&;numchars;ascoff
  57.   print #2,using "//                    X-size=### , Y-size=### , ### bytes/char";chxsize;chysize;chbytes
  58.  
  59.   '* Generate .INC
  60.   scale#=10/chysize
  61.   empty$=string$(chbytes/chysize,0)
  62.   print #2,"#declare TextTex  = texture { Shiny  colour Red  }
  63.   in$=empty$
  64.   for char=ascoff to ascoff+numchars
  65.     if inkey$=chr$(27) then end ' ABORT
  66.     print #2,
  67.     print #2,"#declare Char_";fnh$(char);" = ";
  68.     if ((char and &h7F) >= 32) and ((char and &h7F) <= 127) then char$="// {"+chr$(char)+"}" else char$=""
  69.     if char$="{{}" then char$="{left-curly}"
  70.     if char$="{}}" then char$="{right-curly}"
  71.     if debug then print #3,char$
  72.     print #2,char$
  73.     print #2,"   object {"
  74.     print #2,"       union {"
  75.     previous.x$=empty$
  76.     MinX=9999 : MinY=9999 : MaxX=-1 : MaxY=-1
  77.     for bity= chysize-1 to 0 step -1
  78.       bitx=0
  79.       get #1,,in$
  80.       char.byte=0
  81.       previous.bit=FALSE
  82.       while bitx< chxsize
  83.     char.byte=char.byte+1
  84.     byte=asc(mid$(in$,char.byte,1))
  85.     previous.byte=asc(mid$(previous.x$,char.byte,1))
  86.     for bit=7 to 0 step -1
  87.       bitx=bitx+1
  88.       if byte and TwoToThe%(bit) then gosub WriteOn else gosub WriteOff
  89.     next bit
  90. '       if pixel=3 then if previous.bit then gosub WriteLeft
  91.       wend
  92.       previous.x$=in$
  93.       if debug then print #3,
  94.     next bity
  95.     if debug then print #3,string$(chxsize,"-")
  96.     print #2,"       }"
  97.     print #2,"       texture { TextTex }"
  98.     if MinX < MaxX then
  99.       print #2,      "       bounded_by {
  100.       print #2,using "         box { <###.# ###.# -0.5> <###.# ###.# 0.5> }";MinX-.5;MinY-.5;MaxX+.5;MaxY+.5
  101.       print #2,      "       }"
  102.     end if
  103.     print #2,using "       scale <#.####### #.####### #.#######>";scale#;scale#;scale#
  104.     print #2,       "       // Next Prop. Spaced chr @";(MaxX+1)*scale#
  105.     print #2,       "   }"
  106.   next char
  107.   close
  108.   end
  109.  
  110. WriteOn:
  111.   if MinX>bitx then MinX=bitx
  112.   if MaxX<bitx then MaxX=bitx
  113.   if MinY>bity then MinY=bity
  114.   if MaxY<bity then MaxY=bity
  115. ' if pixel=3 then if not previous.bit then gosub WriteLeft
  116. ' if pixel=3 then if (previous.byte and (2^bit))=0 then gosub WriteTop
  117.   if NOT previous.bit then StartX = bitx
  118.   if pixel=0 then print #2,using "          sphere { <## ## 0> 0.5 }";bitx;bity
  119. ''if pixel=1 then print #2,using "          triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";bitx-.5;bity-.5;bitx+.5;bity+.5;bitx+.5;bity-.5
  120. ''if pixel=1 then print #2,using "          triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";bitx-.5;bity-.5;bitx+.5;bity+.5;bitx-.5;bity+.5
  121.   if pixel=2 then print #2,using "          quadric { Sphere translate <## ## 0> scale <0.5 0.5 0.01> }";bitx;bity
  122. ''if pixel=3 then print #2,using "          box { <###.# ###.# -0.5> <###.# ###.# 0.5> 0.5 }";(bitx-.5);(bity-.5);(bitx+.5);(bity+.5)
  123. ' if pixel=3 then if bity=0 then gosub WriteBottom
  124.   if debug then print #3,"#";
  125.   previous.bit=TRUE
  126. return
  127.  
  128. WriteOff:
  129. ' if pixel=3 then if previous.bit then gosub WriteLeft
  130. ' if pixel=3 then if (previous.byte and (2^bit)) then gosub WriteTop
  131.   if previous.bit then
  132.     if pixel=1 then
  133.       print #2,using "          triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";StartX-.5 ;bity+.5;bitx-1+.5   ;bity-.5;bitx-1+.5   ;bity+.5
  134.       print #2,using "          triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";StartX-.5 ;bity+.5;bitx-1+.5   ;bity-.5;StartX-.5 ;bity+.5
  135.     end if
  136.     if pixel=3 then print #2,using "          box { <###.# ###.# -0.5> <###.# ###.# 0.5> }";(StartX-.5);(bity-.5);(bitx-1+.5);(bity+.5)
  137.   end if
  138.   if debug then print #3," ";
  139.   previous.bit=FALSE
  140. return
  141.  
  142. Usage:
  143.   print
  144.   print "Usage:  FNT2POV [-123] filename[.fnt]"
  145.   print "          -0 = Generate pixels as Spheres "
  146.   print "          -1 = Generate pixels as Squares "
  147.   print "          -2 = Generate pixels as Dots    "
  148.   print "          -3 = Generate pixels as Boxes   "
  149. return
  150.