Fonts

General FreeBASIC programming questions.
Post Reply
jbiddle
Posts: 5
Joined: Aug 25, 2005 21:00

Fonts

Post by jbiddle »

Does anyone know how to get different font sizes and different fonts in FreeBASIC? I know there's a library in SDL but I didn't know if there was an easier way. Thanks!
marzec
Posts: 225
Joined: Jun 06, 2005 23:17

Post by marzec »

there's no real easy way if you want to do fonts, espeically not if you plan on supporting more than just latin-1 or plain old 7-bit ascii. have a look at freetype2, it#s pretty good and performant.
SSC
Posts: 319
Joined: May 29, 2005 4:47
Location: Around
Contact:

Post by SSC »

It depends on how you want to do it, you could create your own font and check for ascii codes in the string you want to show, then display the appropriate font image. Or since you mentioned SDL I'll provide an example which is actually pretty easy to do and uses TTF fonts.

Code: Select all

'$Include once: "sdl/SDL.bi"
'$Include once: "sdl/SDL_TTF.bi"

declare sub display_text_solid(font as TTF_Font, text as String,x as integer,y as integer, colour as SDL_Color)

Dim video as SDL_Surface ptr
Dim colour_1 as SDL_Color
    colour_1.R=0
    colour_1.G=0
    colour_1.B=255

Dim shared display_x = 800
Dim shared display_y = 600
Dim shared display_bpp = 32

SDL_Init(SDL_INIT_EVERYTHING) 
video = SDL_SetVideoMode(display_x, display_y, display_bpp, SDL_SWSURFACE or SDL_FULLSCREEN) 
TTF_init

font=TTF_OpenFont ("Arial.ttf", 18)

display_text_solid(video, font, "Place you text here", 0, 0, colour_1)
SDL_Flip(video)
SDL_Delay 5000 'delay 5 seconds before end

TTF_CloseFont (font)
SDL_QUIT
End

Sub display_text_solid(video as SDL_Surface ptr, font as TTF_Font, text as String, x as integer, y as integer, colour as SDL_Color)
   Redim surface as SDL_Surface ptr
   Redim rect As SDL_Rect
   surface=TTF_RenderText_Solid(font, text, colour)
   If x=-1 Then x=(display_x/2)-((surface->w)/2)
   rect.x = x
   rect.y = y
   rect.w = Surface->w
   rect.h = Surface->h
   
   SDL_BlitSurface(surface, 0, video, @rect)
   SDL_FreeSurface(surface)
End Sub
jofers
Posts: 1525
Joined: May 27, 2005 17:18

Post by jofers »

This might be a little easier for beginners:
http://www.freebasic.net/forum/viewtopi ... hlight=ttf
Eastler_dart
Posts: 27
Joined: Dec 07, 2005 22:30
Location: germany
Contact:

Post by Eastler_dart »

If you understand the german Language, you can use my FreeFontEdit under http://www.eastler.de/freebasic/

With this, you can easyly paint your own font by activating every letter, klicking on the related Pixels of this letter to set or unset the pixel, save this in the FreeFont-Fileformat and load it later in your programm.

Also, in this programm you can save a sample Basic-Listing, in which you'll find the SUBs, for using your font, writing it on (graphical) screen in transparent mode.

Also you can save in this programm a sample FreeBasic-Listing, in which your font is implemented as "Source-Code-filling the Array" with the Fonts-datas (fonts hardcoded in the source, so your programm could stay as one-file when you give it to others) .

Just take the saved samples to start your new Programm or copy and paste the Subs and the Dims in your existing Programm.

But sorry, the documentation is (at the moment?) only in German.

The Download is a zip-File with FreeFont-Edit in sourcecode, FreeFontEdit compiled for windows, some example-Font-Files etc.

look at http://www.eastler.de/freebasic/ click on "FreeFontEdit", there you find the dokumentation of FreeFontEdit and in this online-documentation go down to "Installation". In this part you'll see in red the downloadlink for the zip-file.

hints: Allthoug a lot of users wrote me, FreeFontEdit is perfect, the prog isnt really ready, there are some little little bugs in the code to the mouse-use, so you have sometime to klick twice instead of one time (Thats why i had want to do a programm, which is also fully to use only with the keyboard, not ever have to change between mouse and keyboard)

hope this helps

Eastler
Post Reply