Click here to Skip to main content
16,012,843 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Memory Leakage Pin
Magnus Westin27-Aug-03 3:02
Magnus Westin27-Aug-03 3:02 
Questionhow i can retrieved thread handle from ID one Pin
El'Cachubrey26-Aug-03 22:26
El'Cachubrey26-Aug-03 22:26 
AnswerRe: how i can retrieved thread handle from ID one Pin
Mike Dimmick26-Aug-03 22:44
Mike Dimmick26-Aug-03 22:44 
GeneralRe: how i can retrieved thread handle from ID one Pin
El'Cachubrey26-Aug-03 23:42
El'Cachubrey26-Aug-03 23:42 
GeneralCryptAcquireContext error Pin
devvvy26-Aug-03 22:24
devvvy26-Aug-03 22:24 
GeneralRe: CryptAcquireContext error Pin
Mike Dimmick26-Aug-03 22:56
Mike Dimmick26-Aug-03 22:56 
GeneralRe: CryptAcquireContext error Pin
devvvy26-Aug-03 23:03
devvvy26-Aug-03 23:03 
Generalsetting truetype font height in a special way Pin
JP GOBLET26-Aug-03 22:06
JP GOBLET26-Aug-03 22:06 
For a technical drafting program, i need to draw truetype fonts with total control on their height : for example i want a text of exactly 10mm high.

The problem is in interpretation of height; for truetype fonts, this height is made of 3
parts : Descent (part under the baseline), Ascent (part over the baseline), InternalLeading (some space above the character). All these values are returned by
pDC->GetTextMetrics() when you have selected a font in the pDC.

In my case the height includes only the ascent part : when i say i want a font 10 mm high, it means a font whose characters above the baseline (such as digits) will be 10 mm high. This convention is used by programs such as Autocad, MicroStation, ...

For creating a CFont object, you have to fill a LOGFONT struct with the properties of the font, such as font name, height, weight, ... But as said before, the height here include descent + ascent + leading. Here is how i try to get what i want :

CFont *pOldFont, newfont;<br />
TEXTMETRIC Metrics;<br />
LOGFONT lf;<br />
memset(&lf, 0, sizeof(LOGFONT));<br />
strcpy(lf.lfFaceName, "Arial");<br />
lf.lfHeight = - (long)FontSizeInPixels; // set the height - this is just a first try<br />
// FontSizeInPixels (a double) is the required height (say 10 mm) converted in pixels;<br />
// the height must be specified in logical units, which are pixels because the<br />
// the current mapMode is MM_TEXT. Note also the minus sign, this is normal (see doc. for LOGFONT)<br />
<br />
...  // set others font properties<br />
newfont.CreateFontIndirect(&lf);<br />
pOldFont = pDC->SelectObject(&newfont);<br />
pDC->GetTextMetrics(&Metrics); // get metrics (in pixels) for the font just created<br />
<br />
// here is the trick : the height of the ascent part is of course smaller than the required height;<br />
//so i correct the total height (lf.lfHeight) so that the ascent part grows up to the required height : <br />
<br />
lf.lfHeight = -(long) FontSizeInPixels * (FontSizeInPixels / (Metrics.tmAscent - Metrics.tmInternalLeading));<br />
<br />
// note that the real ascent height is (Metrics.tmAscent - Metrics.tmInternalLeading)<br />
// (this is not explicitly said in the doc. about TEXTMETRIC, but this is what i concluded by looking at the values in TEXTMETRIC)<br />
<br />
// example : let's say that FontSizeInPixels is 100 pixels and that GetTextMetrics <br />
// returned (Metrics.tmAscent - Metrics.tmInternalLeading) = 60;<br />
// so the new lf.lfHeight is 100 * 100/60 = 166<br />
<br />
newfont.Detach();<br />
newfont.DeleteObject();<br />
newfont.CreateFontIndirect(&lf); // recreate the font with the corrected height<br />
pDC->SelectObject(&newfont);<br />
// the following lines just check that the new height of the ascent part is very near of the required height :<br />
pDC->GetTextMetrics(&Metrics);<br />
ASSERT(fabs(Metrics.tmAscent - Metrics.tmInternalLeading - FontSizeInPixels) < 2);<br />


Problem : although the ASSERT above is ok for all the fonts i tried, the resulting height on screen is near the required height but there is still an error up to 20 %; for a same specified height, some fonts are smaller, some are bigger.

JPG
GeneralCPropertyPage Pin
hph26-Aug-03 21:54
hph26-Aug-03 21:54 
GeneralRe: CPropertyPage Pin
Member 42425926-Aug-03 22:05
Member 42425926-Aug-03 22:05 
Generalrestricting to type in CEdit Pin
Ph@ntom26-Aug-03 21:30
Ph@ntom26-Aug-03 21:30 
GeneralRe: restricting to type in CEdit Pin
iceage26-Aug-03 21:53
iceage26-Aug-03 21:53 
GeneralRe: restricting to type in CEdit Pin
Member 42425926-Aug-03 22:10
Member 42425926-Aug-03 22:10 
GeneralRe: restricting to type in CEdit Pin
henchook26-Aug-03 22:11
henchook26-Aug-03 22:11 
GeneralRe: restricting to type in CEdit Pin
David Crow27-Aug-03 4:24
David Crow27-Aug-03 4:24 
GeneralProgramatically copying files Pin
Scozturk26-Aug-03 21:16
professionalScozturk26-Aug-03 21:16 
GeneralRe: Programatically copying files Pin
Johnny ²26-Aug-03 21:25
Johnny ²26-Aug-03 21:25 
GeneralRe: Programatically copying files Pin
henchook26-Aug-03 22:21
henchook26-Aug-03 22:21 
GeneralGenerate Ctrl-Alt-Del programmatically Pin
Chintan26-Aug-03 20:58
Chintan26-Aug-03 20:58 
GeneralRe: Generate Ctrl-Alt-Del programmatically Pin
David Crow27-Aug-03 4:33
David Crow27-Aug-03 4:33 
GeneralAdd/Remove Programs under XP Pin
HeiniBlad26-Aug-03 20:48
HeiniBlad26-Aug-03 20:48 
GeneralRe: Add/Remove Programs under XP Pin
Michael P Butler27-Aug-03 1:42
Michael P Butler27-Aug-03 1:42 
GeneralUse VS .Net to Write &amp; Compile old MFC42 code Pin
HeiniBlad26-Aug-03 20:38
HeiniBlad26-Aug-03 20:38 
GeneralRe: Use VS .Net to Write &amp; Compile old MFC42 code Pin
igor196026-Aug-03 21:14
igor196026-Aug-03 21:14 
Generalstatic const data member -&gt; Compiler error C2057. Pin
Neville Franks26-Aug-03 20:37
Neville Franks26-Aug-03 20:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.