Microsoft KB Archive/177796

{|
 * width="100%"|

BUG: GetCharacterPlacement Returns Incorrect Kerning Values

 * }

Q177796

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API)
 * Microsoft Win32 Software Development Kit (SDK), on platform(s):
 * Microsoft Windows 95

-

SYMPTOMS
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.

CAUSE
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.

RESOLUTION
To reliably calculate the correct character placement (with kerning) for all strings, call GetKerningPairs and calculate the character spacing yourself.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION
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.

Steps to Reproduce Behavior
The following code demonstrates the problem. After executing the code, observe the dx[] array. The first two values are different from the rest:

Sample Code
  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 kbOSWin95 kbDSupport

Issue type : kbbug

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch kbWin32API