Nice looking imagefonts?

BlitzMax Forums/BlitzMax Programming/Nice looking imagefonts?

Warpy(Posted 2009) [#1]
I'm doing clever things with typesetting again, but I don't know how to render good-looking text. I'm using Blitz's built in TImageFont at the moment and with style=SMOOTHFONT it's very blurry, especially when scaled.

Is there a better method about? It would have to allow me to use truetype fonts, no way I'm drawing my own.


Brucey(Posted 2009) [#2]
Draw them *much* larger and scale them down ?


GfK(Posted 2009) [#3]
Doesn't much answer your question but I'm using Fontext (free), with my own code to draw text using Fontext-generated PNG/INI files. Works much faster than DrawText does, plus I can add outlines, gradients, drop-shadows and stuff directly into the font image.

I *think* there's some Blitzmax code for Fontext somewhere doing the rounds so I guess you could use that instead of making your own.


Warpy(Posted 2009) [#4]
Draw them *much* larger and scale them down ?

That's what I'm doing at the moment, and I assume why they're so blurry.

I've just had a look at fontext, and I think it's going to have the same problem as native BMax.

I think I'm going to have to load each font multiple times, at different sizes, to minimise the amount of scaling.


Grey Alien(Posted 2009) [#5]
I think I'm going to have to load each font multiple times, at different sizes, to minimise the amount of scaling.
That's what I do. I dislike scaled fonts due to the blurring. Works OK sometimes but only when scaling down. Mind you I use Bitmap fonts now made with Bitmap Font Generator (the old version gives better anti-aliasing in my opinion but I've asked the author to add the old method back in the new version as an option).


Warpy(Posted 2009) [#6]
Interesting... do you use style=SMOOTHFONT?

have a look at this:
(requires fedprm27p.ttf from here

Graphics 600,600,0
SetBlend ALPHABLEND

Local fonts:timagefont[5]

style=SMOOTHFONT
tf:tfont=tfont.Create("fonts/FeDPrm27P.ttf",.94,.1,style)
While 1
	y#=0
	txt$="hello there, you"
	For c=1 To 10
		size#=c*(1+10.0*MouseX()/600.0)
		y:+tf.height(size)
		tf.draw txt,0,y,size
		DrawLine 0,y,tf.width(txt,size),y
	Next
	Flip
	Cls
	
	If MouseHit(1)
		style=SMOOTHFONT-style
		tf:tfont=tfont.Create("fonts/FeDPrm27P.ttf",.94,.1,style)
	EndIf
	
	If AppTerminate() Or KeyHit(KEY_ESCAPE)
		End
	EndIf
Wend
WaitKey

Function gety()
	While Not MouseHit(1)
		DrawText "hello there, you",0,0
		DrawLine 0,MouseY(),600,MouseY()
		Flip
		Cls
	Wend
	Return MouseY()
End Function

Type tfont
	Field h#
	Field jiggle#
	Field images:timagefont[5]
	Field scale#
	Field i
	
	Function Create:tfont(fname$,height#,jiggle#,style)
		tf:tfont=New tfont
		tf.h=height
		tf.jiggle=jiggle
		tf.makesizes fname,style
		Return tf
	End Function
	
	Method makesizes(fname$,style)
		For x=1 To 5
			images[x-1]=LoadImageFont(fname,2^(x+3),style)
		Next
	End Method
	
	Method setfont(size#)
		'i=(size-5)/10
		i=Int((Log(size)/Log(2))-3)
		If i>4 i=4
		If i<0 i=0
		SetImageFont images[i]
		scale#=size/(2^(i+4))
		SetScale scale,scale
	End Method
	
	Method draw(txt$,x,y,size#)
		setfont size
		DrawText txt+i+" ("+scale+") "+size,x,y-height(size)-jiggle*size
		SetScale 1,1
	End Method
	
	Method height#(size#)
		Return h*size
	End Method
	
	Method width#(txt$,size#)
		setfont size
		w#=TextWidth(txt)*scale
		SetScale 1,1
		Return w
	End Method
End Type

Left click to toggle smoothfont.

It looks like the blurriness is caused by (tri/bi)linear filtering. Is there any way to get bmax to do more complicated filtering? I suppose the text looks ok with smoothfont turned off, I'm not sure which I prefer.

I'm planning on having a good amount of text around the 20-30 pixel height mark, which is where text looks the worst with both methods, but is at least legible with smoothfont turned on.


Grey Alien(Posted 2009) [#7]
Other filtering would no doubt require a fancy mod tweak.

It may well be worth trying a bitmap font especially as they are faster than DrawText and you have complete control over how it looks because it will have been scaled by a paint program with bi-cubic or similar.