Link to home
Start Free TrialLog in
Avatar of marakr
marakr

asked on

font size

Hi!
I draw a text with a specific height with TextOut routine but, after a mouse action, I want this text size (font size) to fit inside a specific rectangle; so, I should know the font height that should be set according to this rectangle width.  Do anyone know how to do it (this routine will be inserted or called from a mouse click event handle).
Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of jhattingh
jhattingh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of marakr
marakr

ASKER

Thanks for your answer. I was just wondering how would I really change it (I meant pDC->SelectObject(...)).  I really don't know how to work with those device contexts.
Could you give me bit more details?
1] set a (bool m_bMouseDown) to true when LMB is down and to false when LMB is released.

2] When the mouse is down, set a member CSize variable to equal the current CPoint variable passed in the override.

3] When the "LMB Up" is fired, check the difference between the CSize variable and the now-supplied CPoint variable

4] Apply the following pseudo code:

for (int n = 1; n < MAXSIZE; n++)
{
  Create a CFont object
 
  Get the LOGFONT structure and
  increment it's size

  Use the CDC::SelectObject to use
  the font

  Use GetOutputTextExtent() to compare
  the new size of the text with the
  CSize that you got from the user's
  mouse drag movements

  If either the new height or new
  width reaches the relative dimensions
  of the user-specified CSize, then go
  ahead and use CDC::DrawText to do
  it's thang, and 'continue' to leave
  the for-loop...!
}

I hope this helps.

LWJason