Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

space under a font

Posted on 2010-01-11
5
Medium Priority
?
262 Views
Last Modified: 2013-11-20
Is there a way I can determine the space under a font in MFC?

John
0
Comment
Question by:IssacJones
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:js-profi
ID: 26285547
what do you mean by determine? if you have a CString you could spot a space by Find function (for example).
 
   CString sHello = "Hello World";
   int spcpos = sHello.Find(' ');

it is regardless what font you were using.

the space char is always ascii code 32 (0x20) for any font.
0
 

Author Comment

by:IssacJones
ID: 26285972
Hi

No, sorry, you've misunderstood. What I need to know is the various dimensions for a given font e.g. if the font sits in some kind of cell (rectangle) how do I find the spacing from the bottom of the cell to the bottom of the font (assuming that is that there is a space).

Similarly, find the space from the top of the font to the top of the rectangle.

John
0
 
LVL 7

Expert Comment

by:js-profi
ID: 26286057
call
   CClient dc(this);
   TEXTMETRIC tm = { 0 };
   dc.GetTextMetrics(&tm);

then the you can retrieve the info from tm structure (think it is tmInternalLeading),

if it some control which has the font required use CWnd pointer of that control instead of this.
if  you have only the font do

      CFont newFont;
      newFont.Create...();
      CClient dc(this);
      CFont * pOldFont = dc.SelectObject(&newFont);

before calling GetTextMetrics.
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 1000 total points
ID: 26286295
GetTextExtendPoint32, like:

SelectObject(hDC, hFont);
GetTextExtentPoint32(bla-bla-bla);

MSDN:
http://msdn.microsoft.com/en-us/library/ms901137.aspx

Example
http://msdn.microsoft.com/en-us/library/dd162491(VS.85).aspx

Another example:
http://www.ucancode.net/Visual_C_Codes/Calculate-width-text-GetTextExtentPoint32-DT_CALCRECT-GetCharABCWidths-VC-Article.htm

The simplest way is just to use DT_CALCRECT in DrawText:
CRect rc(0,0,0,0);
CFont* pOldFont = dc.SelectObject(&font);
dc.DrawText(str, &rc, DT_CALCRECT);

0
 

Author Closing Comment

by:IssacJones
ID: 31675589
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question