Re: Algorithmics
On Fri, 17 Jan 2003 11:47:31 +1100, Patrick.Barnes at transgrid.com.au
wrote:
>Can anyone see what could be improved?
A quick hack at a binary chop
Code may need cleaning a bit but seems to work:
integer bsize, ssize
--#START OF CODE THAT IS TOO SLOW#--
fsize =3D 8 --starting font size
ssize =3D 1
bsize =3D 0
while 1 do
--find the size of that text
setFont(win, "Times New Roman", fsize, Normal)=09
tsize =3D getMlTextExtent(win, lines, 0)
--if it's bigger than the window...
if tsize[1] >=3D wsize[1] or tsize[2] >=3D wsize[2] then
bsize=3Dfsize
fsize=3Dssize+floor((fsize-ssize)/2)
if fsize=3Dssize then
exit
end if
else
ssize=3Dfsize
if bsize=3D0 then
fsize*=3D2
else
if fsize+1=3Dbsize then exit end if
fsize+=3Dfloor((bsize-fsize)/2)
end if
end if
end while
--#END OF CODE THAT IS TOO SLOW#--=09
Pete
|
Not Categorized, Please Help
|
|