Font kerning - another try

Previous topic - Next topic

Quentin

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]

Quentin

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

Code (glbasic) Select

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]

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Zapp


Kitty Hello

Kerning is now a core function of PRINT and LEN.

Schranz0r

Quote from: Zapp on 2011-Nov-20
Link seems broken :/

Not broken, its a "Firefox in combination with this Forum" bug...
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard