Re: [Q]How to display Tahoma italic font
- From: "Johnny" <johnny194@xxxxxxxxxxx>
- Date: 17 May 2006 02:27:23 -0700
Thanks, John. I've got the root cause~~ Ya, you are right, it's the
matter of the cWidth. What a shame that I didn't realize the effect of
its negative value. Thanks again for your comments, not only on the key
point but also on some other points.
Besides. In my list of buggy fonts, there are two non-TT fonts:
"Haettenschweiler" and "Times New Roman MT Extra Bold". Sorry for my
ignorance again.
Regards,
Johnny
John Carson wrote:
"Johnny" <johnny194@xxxxxxxxxxx> wrote in message
news:1147831149.757831.274410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I can get the proper display using Arial or Times New Roman. Why you
can't? BTW. I used win32 application project instead of MFC project, is
that the matter?
I suspect it is an issue of different screen resolutions or font size.
Adding is will shift the following text to the left? er, i mean, add2. Instead of substracting the cWidth from the Xincrement, if I add
the cWidth, it will ok,
For what font?
but for other TT fonts, there are additional
spaces on the canvas. And I can't find anything to support adding the
cWidth, most of them suggest substracting like yours.
The C width for d is going to be negative with any italic font, so adding
it
means that you shift the following text to the left, which will worsen
any
overlap.
the cWidth to the XIncrement
On my computer, the C widths for italic 'd' for selected fonts are as
follows:
Arial -1
Times New Roman -1
Tahoma -4
Impact -4
Thus adding any of these to XIncrement reduces XIncrement, so that the final
normal text begins further to the left. On the other hand, subtracting them
shifts the text to the right.
Besids John, this is the updated code according to your advice, I'm not
sure whether we two have the same codes running...
Yes, running the following code (with optional insertion of an adjustment
for the C width) gives the results I have been talking about.
typedef enum _FontType{
ITALIC_FONT = 1,
BOLD_FONT = 2,
NORMAL_FONT = 3,
}FontType;
HFONT MyCreateFont(FontType ftype)
{
LOGFONTW logfont = {0};
wcscpy(logfont.lfFaceName, L"Arial");
switch (ftype)
{
case ITALIC_FONT:
logfont.lfItalic = TRUE;
break;
case BOLD_FONT:
logfont.lfWeight = FW_BOLD;
break;
case NORMAL_FONT:
break;
default:
assert(0);
break;
}
return CreateFontIndirectW(&logfont);
}
void demoFunc(HDC hdc)
{
int XIncrement;
int YStart;
HFONT hfntDefault;
HFONT hfntItalic;
HFONT hfntNormal;
LPWSTR wString = L"dd";
int stringLen = wcslen(wString);
SIZE sz;
// Create a normal and an italic logical font
hfntItalic = MyCreateFont(ITALIC_FONT);
hfntNormal = MyCreateFont(NORMAL_FONT);
// Select the normal font and draw the first string
// beginning at the specified point (XIncrement, YStart).
XIncrement = 10;
YStart = 50;
hfntDefault = (HFONT)SelectObject(hdc, hfntNormal);
TextOutW(hdc, XIncrement, YStart, (LPCWSTR)wString, stringLen);
GetTextExtentPoint32W(hdc, (LPCWSTR)wString, stringLen, &sz);
XIncrement += sz.cx;
// Select an italic font and draw the second string
// beginning at the point (XIncrement, YStart).
hfntNormal = (HFONT)SelectObject(hdc, hfntItalic);
TextOutW(hdc, XIncrement, YStart, (LPCWSTR)wString, stringLen);
// Compute the length of the second string and add
// this value to the x-increment that is used for the
// text-output operation.
GetTextExtentPoint32W(hdc, (LPCWSTR)wString, stringLen, &sz);
XIncrement += sz.cx;
// Reselect the normal font and draw the third string
// beginning at the point (XIncrement, YStart).
SelectObject(hdc, hfntNormal);
TextOutW(hdc, XIncrement, YStart, (LPCWSTR)wString, stringLen);
// Reselect the original font.
SelectObject(hdc, hfntDefault);
// Delete the bold and italic fonts.
DeleteObject(hfntItalic);
DeleteObject(hfntNormal);
}
Regards,
Johnny
--
John Carson
.
- References:
- [Q]How to display Tahoma italic font
- From: Johnny
- Re: [Q]How to display Tahoma italic font
- From: John Carson
- Re: [Q]How to display Tahoma italic font
- From: Johnny
- Re: [Q]How to display Tahoma italic font
- From: John Carson
- Re: [Q]How to display Tahoma italic font
- From: Johnny
- Re: [Q]How to display Tahoma italic font
- From: John Carson
- [Q]How to display Tahoma italic font
- Prev by Date: Re: Size problem with CreateCompatilbeDC on specific hardware
- Next by Date: Desktop pixel manipulation
- Previous by thread: Re: [Q]How to display Tahoma italic font
- Next by thread: Re: [Q]How to display Tahoma italic font
- Index(es):
Relevant Pages
|