BUG: GetCharacterPlacement Returns Incorrect Kerning ValuesID: Q177796
|
The GetCharacterPlacement function retrieves information about a character string, such as character widths and caret positioning. You can calculate the widths with kerning pairs if you use the GCP_USEKERNING flag when calling GetCharacterPlacement. On Windows 95, when calling GetCharacterPlacement with GCP_USEKERNING to kern a "repetitive" string (for example, "AVAVAVAVAVA"), the string correctly kerns the first two gaps (that is, "AVA") but nothing else. This happens with a range of repetitive strings.
On Windows 95, the GetCharacterPlacement function is not properly calculating the "lpDx" array in the GCP_RESULTS structure when filling in the distances between adjacent character cells for some strings.
To reliably calculate the correct character placement (with kerning) for all strings, call GetKerningPairs and calculate the character spacing yourself.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
Most TrueType fonts have a kerning table, but you do not have to use it. To
find out whether the current font supports kerning pairs, call
GetFontLanguageInfo. When you call GetCharacterPlacement with
GCP_USEKERNING to kern the string "AVAVAVAVAVAV", the GetCharacterPlacement function correctly
kerns the first two character widths only. If you examine the lpDx array
filled by the GetCharacterPlacement API, it confirms this. The first two
values are different from and slightly smaller than the rest of the values
(which are all identical). Only the first two gaps between characters are
kerned. The values should all be the same.
It is recommended that you calculate character placement with kerning pairs
manually by calling GetKerningPairs.
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
GCP_RESULTS gcp;
static char szOut[40];
int dx[13];
int pos;
int order[13];
UINT glyphs;
HFONT hPrevFont;
ZeroMemory(&gcp,sizeof(GCP_RESULTS));
gcp.lStructSize = sizeof(GCP_RESULTS);
gcp.lpOutString = szOut;
gcp.lpDx = &dx[0];
gcp.lpCaretPos = &pos;
gcp.lpOrder = &order[0];
gcp.lpGlyphs = (unsigned short *)&glyphs;
gcp.nGlyphs = 12;
hdc = BeginPaint(hWnd, &ps);
hPrevFont = SelectObject(hdc, hFont);
GetCharacterPlacement(hdc, "AVAVAVAVAVAV", 12, 0,
&gcp, GCP_USEKERNING);
DeleteObject(SelectObject(hdc, hPrevFont));
EndPaint(hWnd, &ps);
break;
}
Additional query words:
Keywords : kbSDKWin32 kbWinOS95 kbDSupport
Version : WINDOWS:95; winnt:
Platform : WINDOWS winnt
Issue type : kbbug
Last Reviewed: June 25, 1999