Jump to content

  • Log In with Google      Sign In   
  • Create Account


String/char character size


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Juliean   GDNet+   -  Reputation: 2454

Like
0Likes
Like

Posted 06 March 2013 - 03:38 AM

Hello,

 

is there any way to get the width and/or height of a string/character, without using any certain device? I'm using DX9 so I could use the ID3DXFont, but the class that handles my text (a sort of text input box) shouldn't have a reference to my font-object. At least I wouldn't want it to have one. Is there any other way? GetCharWidth32 would need a HDC, so thats out of the question too. Some other function without a device, only given the font family, font size and not countin italics/bold/... (so only standard formated text)?



Sponsor:

#2 BitMaster   Crossbones+   -  Reputation: 3919

Like
1Likes
Like

Posted 06 March 2013 - 03:55 AM

It's impossible to retrieve the width or height of glyphs in the string without both some kind of representation of the font and some kind of device. There is no common size for any glyph, each font defines its own. And a device is needed to map the internal metrics to a unit you are interested in, like pixels. You might get away without an explicit device in some scenarios if you just want to draw a string relatively straight forward into a bitmap but that will depend on the underlying library.

By the way, GetCharWidth32 also requires the font in addition to the HDC because the font must be selected in the device context.

#3 Juliean   GDNet+   -  Reputation: 2454

Like
0Likes
Like

Posted 06 March 2013 - 08:05 AM

Ok, thanks a lot, seems like I have no choice but to eigther make the textbox use my font-class, or create a class/function that handles my textbox' interaction like offsetting the shown text when the cursor is moved etc...



#4 Lightness1024   Members   -  Reputation: 736

Like
1Likes
Like

Posted 06 March 2013 - 08:20 AM

You can use libfreetype and ask that metric to the library. you can then generate your own bitmaps that you copy to directx surfaces. otherwise you just hope that directx font rendering will be close enough, if an approximation is enough for you that will do.



#5 Juliean   GDNet+   -  Reputation: 2454

Like
0Likes
Like

Posted 06 March 2013 - 08:40 AM

I'm implementing from scratch a one-line textbox for my custom gui - so I need to e.g. determine where the cursor should be located if I click it with the mouse etc... . I'd don't think I need that much of precision - I'll definately check out libfreetype and see if it works, thanks!



#6 Vortez   Crossbones+   -  Reputation: 2698

Like
0Likes
Like

Posted 06 March 2013 - 01:34 PM

I think there's a way to calculate the rectangle size of the text using this method:

 

m_Font->DrawText(NULL. String.c_str(), String.length(), &String_Info, DT_CALCRECT, D3DCOLOR_XRGB(0,0,0));

 

Haven't tested it, but it should work.


Edited by jbadams, 04 April 2013 - 05:54 AM.
Restored post contents from history.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS