Advertisement

How do you calculate the size a character will take up when drawn?

Started by February 03, 2001 11:51 AM
0 comments, last by Fresh 23 years, 11 months ago
Using, the GDI, how do you find out the height and the width of the character in pixels?? So far I have:

	HDC hsurfacedc;
	TEXTMETRIC tm;

	if (!g_DirectXEngine.GetDirectDraw())
		return (0);

	LPDIRECTDRAWSURFACE lpddsworking = g_DirectXEngine.GetWorkingSurface();

	if (!lpddsworking)
		return (0);

	lpddsworking->GetDC(&hsurfacedc);

	if (!hsurfacedc) {
		g_ErrorLog.ProcessError(NULL, "CMetaform::UpdateCharHeightAndWidth: Error using lpddsworking->GetDC", 0);
		return (0);
	}

	HFONT hfont = CreateFontIndirect(&font);
	SelectObject(hsurfacedc, hfont);

	SetMapMode(hsurfacedc, MM_TEXT);
	GetTextMetrics(hsurfacedc, &tm);

	lpddsworking->ReleaseDC(hsurfacedc);
	
	DeleteObject(hfont);

	char_height = (MulDiv(tm.tmHeight, 96, g_DirectXEngine.GetLOGPIXELSY()));
	char_width = (MulDiv(tm.tmAveCharWidth, 128, g_DirectXEngine.GetLOGPIXELSX()));


	char buf[128];
	sprintf(buf, "UPDATE: height: %d, width: %d", char_height, char_width);
	g_Console.Message(buf);

	return (1);
 
What am I doing wrong? "The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."
It''s ok, I fixed it..
I was being more than usually stupid.

"The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."

This topic is closed to new replies.

Advertisement