BASIC

Author Topic: Font kerning - another try  (Read 3644 times)

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Font kerning - another try
« on: 2010-Mar-12 »
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]
« Last Edit: 2010-Mar-12 by Quentin »

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
Re: Font kerning - another try
« Reply #1 on: 2010-Mar-13 »
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]

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Font kerning - another try
« Reply #2 on: 2010-Mar-13 »
NICE!
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Zapp

  • Mc. Print
  • *
  • Posts: 37
  • Indie Developer - Final Boss Games
    • View Profile
Re: Font kerning - another try
« Reply #3 on: 2011-Nov-20 »
Link seems broken :/

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Font kerning - another try
« Reply #4 on: 2011-Nov-21 »
Kerning is now a core function of PRINT and LEN.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: Font kerning - another try
« Reply #5 on: 2011-Nov-21 »
Link seems broken :/

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

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard