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 >
Wrap
BASIC Source File
|
1992-08-28
|
6KB
|
150 lines
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Conversion notes: ''
'' DEFINT means any untyped variable defaults to INT ''
'' GET #1,,IN$ means get from file #1 into IN$ for a length''
'' of however big IN$ already is. ''
'' COMMAND$ is the command line less the program name. Just''
'' rewrite the lousy BASIC interpretation of parameters.''
'' Type ! is a float, & is a long int, # is an 8-byte float''
'' STRING$(n,c) function returns a string containing 'n' ''
'' occurances of the character 'c'. ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
defint a-z
VERSION!=1.10
print using "FONT2DAT (c) Koehler 1991,1992 v##.## ";version!
def fnh$(x)=right$("0"+hex$(x),2)
TRUE= (1=1) : FALSE = (1=0)
dim TwoToThe%(7) : for k=0 to 7 : TwoToThe%(k)=2^k : next k
pixel=0 ' 0=Sphere 1=Dot 2=Square 3=Box
debug=1
cmd$=command$
if left$(cmd$,1)="-" then pixel=val(mid$(cmd$,2,1)):cmd$=mid$(cmd$,4)
if cmd$="" then gosub Usage:end
if pixel>3 then pixel=0
if pixel=0 then print "Generating Spheres"
if pixel=1 then print "Generating Squares"
if pixel=2 then print "Generating Dots"
if pixel=3 then print "Generating Boxes"
fl$=cmd$
if instr(fl$,".") then ext$=mid$(fl$,instr(fl$,".")) : fl$=left$(fl$,instr(fl$,".")-1)
if ext$="" then ext$=".fnt"
open fl$+ ext$ for BINARY as #1
open fl$+".inc" for output as #2
if debug then open fl$+".deb" for output as #3 ' graphic layout
'* Read font header
in$=chr$(0)
get #1,,in$
size&=asc(in$)
get #1,,in$
size&=asc(in$)*256+size&
get #1,,in$
numchars=asc(in$) : if numchars=0 then numchars=256
get #1,,in$
ascoff=asc(in$)
get #1,,in$
chxsize=asc(in$)
get #1,,in$
chysize=asc(in$)
get #1,,in$
chbytes=asc(in$)
print "'";fl$;ext$;"'";
print using " is ####, bytes long, ### characters, starting @ ###";size&;numchars;ascoff
print using " X-size=### , Y-size=### , ### bytes/char";chxsize;chysize;chbytes
print #2,"// '";fl$;ext$;"'";
print #2,using " is ####, bytes long, ### characters, starting @ ### ";size&;numchars;ascoff
print #2,using "// X-size=### , Y-size=### , ### bytes/char";chxsize;chysize;chbytes
'* Generate .INC
scale#=10/chysize
empty$=string$(chbytes/chysize,0)
print #2,"#declare TextTex = texture { Shiny colour Red }
in$=empty$
for char=ascoff to ascoff+numchars
if inkey$=chr$(27) then end ' ABORT
print #2,
print #2,"#declare Char_";fnh$(char);" = ";
if ((char and &h7F) >= 32) and ((char and &h7F) <= 127) then char$="// {"+chr$(char)+"}" else char$=""
if char$="{{}" then char$="{left-curly}"
if char$="{}}" then char$="{right-curly}"
if debug then print #3,char$
print #2,char$
print #2," object {"
print #2," union {"
previous.x$=empty$
MinX=9999 : MinY=9999 : MaxX=-1 : MaxY=-1
for bity= chysize-1 to 0 step -1
bitx=0
get #1,,in$
char.byte=0
previous.bit=FALSE
while bitx< chxsize
char.byte=char.byte+1
byte=asc(mid$(in$,char.byte,1))
previous.byte=asc(mid$(previous.x$,char.byte,1))
for bit=7 to 0 step -1
bitx=bitx+1
if byte and TwoToThe%(bit) then gosub WriteOn else gosub WriteOff
next bit
' if pixel=3 then if previous.bit then gosub WriteLeft
wend
previous.x$=in$
if debug then print #3,
next bity
if debug then print #3,string$(chxsize,"-")
print #2," }"
print #2," texture { TextTex }"
if MinX < MaxX then
print #2, " bounded_by {
print #2,using " box { <###.# ###.# -0.5> <###.# ###.# 0.5> }";MinX-.5;MinY-.5;MaxX+.5;MaxY+.5
print #2, " }"
end if
print #2,using " scale <#.####### #.####### #.#######>";scale#;scale#;scale#
print #2, " // Next Prop. Spaced chr @";(MaxX+1)*scale#
print #2, " }"
next char
close
end
WriteOn:
if MinX>bitx then MinX=bitx
if MaxX<bitx then MaxX=bitx
if MinY>bity then MinY=bity
if MaxY<bity then MaxY=bity
' if pixel=3 then if not previous.bit then gosub WriteLeft
' if pixel=3 then if (previous.byte and (2^bit))=0 then gosub WriteTop
if NOT previous.bit then StartX = bitx
if pixel=0 then print #2,using " sphere { <## ## 0> 0.5 }";bitx;bity
''if pixel=1 then print #2,using " triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";bitx-.5;bity-.5;bitx+.5;bity+.5;bitx+.5;bity-.5
''if pixel=1 then print #2,using " triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";bitx-.5;bity-.5;bitx+.5;bity+.5;bitx-.5;bity+.5
if pixel=2 then print #2,using " quadric { Sphere translate <## ## 0> scale <0.5 0.5 0.01> }";bitx;bity
''if pixel=3 then print #2,using " box { <###.# ###.# -0.5> <###.# ###.# 0.5> 0.5 }";(bitx-.5);(bity-.5);(bitx+.5);(bity+.5)
' if pixel=3 then if bity=0 then gosub WriteBottom
if debug then print #3,"#";
previous.bit=TRUE
return
WriteOff:
' if pixel=3 then if previous.bit then gosub WriteLeft
' if pixel=3 then if (previous.byte and (2^bit)) then gosub WriteTop
if previous.bit then
if pixel=1 then
print #2,using " triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";StartX-.5 ;bity+.5;bitx-1+.5 ;bity-.5;bitx-1+.5 ;bity+.5
print #2,using " triangle { <###.# ###.# 0> <###.# ###.# 0> <###.# ###.# 0> }";StartX-.5 ;bity+.5;bitx-1+.5 ;bity-.5;StartX-.5 ;bity+.5
end if
if pixel=3 then print #2,using " box { <###.# ###.# -0.5> <###.# ###.# 0.5> }";(StartX-.5);(bity-.5);(bitx-1+.5);(bity+.5)
end if
if debug then print #3," ";
previous.bit=FALSE
return
Usage:
print
print "Usage: FNT2POV [-123] filename[.fnt]"
print " -0 = Generate pixels as Spheres "
print " -1 = Generate pixels as Squares "
print " -2 = Generate pixels as Dots "
print " -3 = Generate pixels as Boxes "
return