Re: [Q]How to display Tahoma italic font




John Carson wrote:
"Johnny" <johnny194@xxxxxxxxxxx> wrote in message
news:1147769172.639645.43300@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks John and sorry that i forgot to describe more clearly.
First, the improper display is not that the middle italic letters
overlap the right hand normal letters, instead, it is that the middle
right hand normal letters overlap the last italic letter.

I can't follow. What are the "middle right hand normal letters"? You have

dd(normal)dd(italic)dd(normal)

where the bracketed descriptions are, of course, not displayed. Since the
final dd(normal) is written last, it will write over the top of the
dd(italic) to the extent that they overlap. When I run the code, I see the
first d of the final dd overwriting the last italic d.
yes, that's what i want to describe for you. Sorry for my poor english

And what troubles me is that:
1. this program works well for other TT fonts except for the
following: "Arial Black"
"Comic Sans MS"
"Haettenschweiler"
"Impact"
"Lucida Console"
"Microsoft Sans Serif"
"Symbol"
"Tahoma"
"Times New Roman MT Extra Bold"

If it works well for other fonts (which you don't name), then I can only
assume that is because the italic versions of those fonts have less slant. I
tried Arial and Times New Roman and they both have the same problem. As
previously indicated, you shouldn't be expecting it to work.
other fonts, here i mean any font i've tried. what surprised me is that
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?

2. 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.
Adding is will shift the following text to the left? er, i mean, add
the cWidth to the XIncrement

Thank you again and please find my comments inlined.

John Carson wrote:
"Johnny" <johnny194@xxxxxxxxxxx> wrote in message
*snip*
LPSTR lpszString = "dd";
int stringLen = strlen(lpszString);
LPWSTR wString = (LPWSTR)malloc(WCHAR_STRING_LENGTH *
sizeof(LPWSTR));

So what is WCHAR_STRING_LENGTH? This doesn't make sense on several
levels. First, I don't know why you are converting from ANSI to
Unicode instead of starting out with Unicode. Second sizeof(LPWSTR)
is just the size of a pointer which has nothing to do with how much
space you need for the string. Third, you have not made any
allowance for the terminating NUL. The following makes more sense:

LPWSTR wString = (LPWSTR)malloc(sizeof(WCHAR) * (stringLen+1));

In fact, I don't know how to start out with Unicode. :( would you mind
to give me a brief example?

LPWSTR wString = L"dd";

will do it. You will need to remove

free(wString);

Incidentally, your MyCreateFont could also be changed to use

LOGFONTW

and

CreateFontIndirectW

Great thanks for your suggestions.

--
John Carson

Besids John, this is the updated code according to your advice, I'm not
sure whether we two have the same codes running...

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

.



Relevant Pages

  • Re: [Q]How to display Tahoma italic font
    ... I can't display Tahoma font in italic properly using ... string and incrementing XIncrement, you should do a second increment as ... character of the non-italic string that follows). ... // beginning at the specified point (XIncrement, YStart). ...
    (microsoft.public.win32.programmer.gdi)
  • Re: [Q]How to display Tahoma italic font
    ... I suspect it is an issue of different screen resolutions or font size. ... Thus adding any of these to XIncrement reduces XIncrement, ... // Select the normal font and draw the first string ... // beginning at the specified point (XIncrement, YStart). ...
    (microsoft.public.win32.programmer.gdi)
  • Re: [Q]How to display Tahoma italic font
    ... I suspect it is an issue of different screen resolutions or font size. ... Thus adding any of these to XIncrement reduces XIncrement, ... // Select the normal font and draw the first string ... // beginning at the specified point (XIncrement, YStart). ...
    (microsoft.public.win32.programmer.gdi)
  • [Q]How to display Tahoma italic font
    ... I can't display Tahoma font in italic properly using ... // translate the LPSTR string to LPWSTR string ... // beginning at the specified point (XIncrement, YStart). ...
    (microsoft.public.win32.programmer.gdi)
  • Re: screen.fonts again
    ... As far as I know in a single font file ... Private Declare Function RegCloseKey Lib "advapi32.dll" _ ... ByVal lpSubKey As String, ... Dim Buffer As String, FontName As String ...
    (microsoft.public.vb.general.discussion)