Based on Gernot's kerning function in DDGui I tried to implement a more flexible variant of using font kerning. The result is a couple of functions to manage fonts within your applications.
IMHO there are some advantages to the DDGui version:
- you can handle more than only one font at a time
- you can define the spacing for each font (number of pixel between the single characters of a string, even with negative values). Spacing can be changed at any time
- you can use different background colors for your fonts
How to use it:
just add the file Font_Kerning.gbas to your project. Use function kf_LoadFont to load a font and kf_Print to output your text. With kf_SetTransparency you define the background color of the font. Switch the spacing between the characters with kf_SetSpacing. Toggle between your font with kf_SetFont. Finally kf_DeleteFont to delete fonts not used any more.
see attached the complete little project with an example
[attachment deleted by admin]
both, proportional and non pro. (First half screen is an example of non proportional)
Guess I should have used the same font for both :)
here's another example on how to use it, once without, once with kerning
LOCAL font1%, font2%
font1 = kf_LoadFont("arial.png", FALSE, -4) // load font without kerning
font2 = kf_LoadFont("arial.png", TRUE,2) // same font with kerning
WHILE TRUE
kf_SetFont(font1)
kf_Print("Example for non proportial font", 0, 0)
kf_Print("They're better used to display numbers", 0, 20)
kf_Print(" 1,000.40", 0, 50)
kf_Print(" 12.443.78", 0, 70)
kf_Print("-----------", 0, 90)
kf_Print(" 13,444.18", 0, 110)
kf_SetFont(font2)
kf_Print("This is an example for a proportional font", 0, 140)
kf_Print("Each character uses differnt space depending on its width", 0, 160)
kf_Print("In most cases this kind of text is better readable", 0, 180)
SHOWSCREEN
WEND
END
[attachment deleted by admin]
NICE!
Link seems broken :/
Kerning is now a core function of PRINT and LEN.
Quote from: Zapp on 2011-Nov-20
Link seems broken :/
Not broken, its a "Firefox in combination with this Forum" bug...