🔒 Locked
creating bitmap fonts
Advertisement
Original Post
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]]=--
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
Ballistic Programs
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]]=--
is there some sample code in the net? or can you give me an example cause i never used the GDI before
thx
--=[[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]]=--
i just need to know how to get the font pixels into the bitmap pixel data array
thx
--=[[TheMatrixXXX]]=--
does nobody know how to do this?
--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
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);
}
thx for your source code
i will try it
--=[[TheMatrixXXX]]=--
i will try it
--=[[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]]=--
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]]=--
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement