Skip to main content
gamedev.net
🔒 Locked

creating bitmap fonts

Started by TheMatrixXXX 9 replies 250+ views
Original Post
TheMatrixXXX
TheMatrixXXX
hi can anyone tell me how to get a character of a truetype font from windows into a bitmap? i want to create a font tool for my engine which can use any font installed in windows to create a bitmap with all characters on it thx for help --=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
Drazgal
Drazgal
Well using windows GDI just load the font up as the size you want, then get the line height and the average character width, using that make a new bitmap in memory large enough to hold the font then fill it with the background colour that you want then using GDI write the characters you want. There is a program that someone wrote that does this but I can''t remember the url, when I get home from college (if nobody has already posted it) I''ll post the url if you want.

Ballistic Programs
IndirectX
IndirectX
Why settle for average width when you can use GetCharABCWidths and get exact width?
---visit #directxdev on afternet <- not just for directx, despite the name
TheMatrixXXX
TheMatrixXXX
thx for your answers

is there some sample code in the net? or can you give me an example cause i never used the GDI before

thx
--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
jakerrz
jakerrz
hey that is a good idea you got there...
sorry i dont know how to do it
TheMatrixXXX
TheMatrixXXX
hi thx for the link but i want source code to build my own tool
i just need to know how to get the font pixels into the bitmap pixel data array

thx
--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
TheMatrixXXX
TheMatrixXXX
does nobody know how to do this?

--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
Mark Duffill
Mark Duffill
This is what I use:-


  

//-------------------------- Structures/Classes -----------------------------

struct FNTBMP
{
HDC hdc;
BITMAPINFO info;
HBITMAP Bmp;
BYTE *Bits;
};

//---------------------------------------------------------------------------------------------------------

// creates a bitmap and selects into hdc

//---------------------------------------------------------------------------------------------------------

int FntCreateBitmap( int Width, int Height, FNTBMP &BmpInfo )
{
BmpInfo.hdc = 0;
////////////////////////////////////////////////////////////////

// Initialize the fields in the BITMAPINFO structure.

BmpInfo.hdc = CreateCompatibleDC(NULL);
BmpInfo.info.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
BmpInfo.info.bmiHeader.biWidth = Width;
BmpInfo.info.bmiHeader.biHeight= Height;
BmpInfo.info.bmiHeader.biPlanes= 1;
BmpInfo.info.bmiHeader.biBitCount=24;
BmpInfo.info.bmiHeader.biCompression=BI_RGB;
BmpInfo.info.bmiHeader.biSizeImage=Width*Height *3;
BmpInfo.info.bmiHeader.biXPelsPerMeter= 0;
BmpInfo.info.bmiHeader.biYPelsPerMeter= 0;
BmpInfo.info.bmiHeader.biClrUsed = 0;
BmpInfo.info.bmiHeader.biClrImportant = 0;


////////////////////////////////////////////////////////////////

// Create an offscreen device context:

BmpInfo.Bmp = CreateDIBSection(BmpInfo.hdc,&BmpInfo.info,DIB_RGB_COLORS,(void**)&BmpInfo.Bits,NULL,NULL);
if (!BmpInfo.Bmp)
return(0);

SelectObject(BmpInfo.hdc, BmpInfo.Bmp);
SelectObject(BmpInfo.hdc, GetStockObject(BLACK_BRUSH));
SetStretchBltMode( BmpInfo.hdc, STRETCH_HALFTONE );

////////////////////////////////////////////////////////////////

// clear image to black

Rectangle(BmpInfo.hdc, 0, 0, Width, Height);
return(1);
}

//---------------------------------------------------------------------------------------------------------

// deletes a created bitmap and hdc

//---------------------------------------------------------------------------------------------------------

int FntBmpDelete( FNTBMP &Info )
{
if( Info.Bmp ) DeleteObject( Info.Bmp ); Info.Bmp = 0;
if( Info.hdc ) DeleteDC( Info.hdc ); Info.hdc = 0;
return(1);
}

//---------------------------------------------------------------------------------------------------------

// does a clear rect,and draws text

//---------------------------------------------------------------------------------------------------------

int FntBmpTextOut( FNTBMP &Info, int x, int y, LPCTSTR str )
{
return(TextOutA(Info.hdc, x,y, str, 1));
}

//---------------------------------------------------------------------------------------------------------

// does a clear rect,and draws text

//---------------------------------------------------------------------------------------------------------

int FntBmpSetFont( FNTBMP &Info , HFONT &fnt )
{
SelectObject(Info.hdc, fnt);
SetBkMode(Info.hdc, TRANSPARENT); // do not fill character background

SetTextColor(Info.hdc, RGB(255, 255, 255)); // text color white

return(1);
}
TheMatrixXXX
TheMatrixXXX
thx for your source code
i will try it

--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
TheMatrixXXX
TheMatrixXXX
ok your code works fine
big thx
but i need to get the HFONT object without using the font-selection-box (i assign all font names to a combo-box)
is there a function to get the HFONT by the name string?

thx
--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.