• Advertisement

Archived

This topic is now archived and is closed to further replies.

DirectX fonts

This topic is 6551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can i retrieve the pixel length of drawn text in DirectX? I need it to determine the minimum length of a "menu".

Share this post


Link to post
Share on other sites
Advertisement
just continuing my last post, sorry, I realized that the other post needed to bee added on to. My question is, do you want to retrieve the pixel leangth of one charecter, or the entire thing?

Share this post


Link to post
Share on other sites
Are you using the GDI to blit to a direct draw surface? or bliting a graphic of each letter?

Share this post


Link to post
Share on other sites
I write text like this-
surfacename.Drawtext(xpos,ypos,"TEXT",False)
(the last false just makes the text stay in its x,y location and doesn''t go to upper left corner).

Share this post


Link to post
Share on other sites
draw all the letters to the screen, take a screenshot, open it up in a paint app, and count the pixel widths and heights for whatever letters you want. this shoud work regardless oh how you are drawing this text


Share this post


Link to post
Share on other sites
Just looked up the function and it looks like it updates the current position if you use TRUE for the last parameter.

Perhaps you can read the current position after printing the text and compare it to the position before.

Share this post


Link to post
Share on other sites
You can use the GetTextExtentPoint32 function to get the size of string with selected font.

Share this post


Link to post
Share on other sites
trixter-
I have to be more specific next time - of course I meant
runtime check.

Share this post


Link to post
Share on other sites
I assume that you are using Visual Basic since DrawText is a VB only function. You must declare GetTextExtentPoint32 like this:

Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As SIZE) As Long

Then call it. Since I never used it, look it up somewhere.

Share this post


Link to post
Share on other sites
You can get the device context of DirectDrawSurface:

void GetTextSize(char* text, HFONT hFont, SIZE& size)
{
HDC hdc;
HFONT oldfont;
gDDSurface->GetDC(&hdc);
// Try with GDI functions
oldfont = (HFONT) SelectObject(hdc, hFont);
//SetBkMode(hdc, TRANSPARENT);
//SetTextAlign(hdc, TA_LEFT / TA_TOP / TA_NOUPDATECP);
GetTextExtentPoint32(hdc, text, strlen(text), &size);
SelectObject(hdc, oldfont);
gDDSurface->ReleaseDC(hdc);
}

Goodluck.

Share this post


Link to post
Share on other sites
Yes, I''m using and don''t understand anything about that C code. I have the declaration too (api viewer is for that), but I have no idea how to get it working. To what i should use the SIZE?

Share this post


Link to post
Share on other sites

  • Advertisement