BUG: GetCharacterPlacement Returns Incorrect Kerning Values

Last reviewed: December 8, 1997
Article ID: Q177796
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API)
  • Microsoft Win32 Software Development Kit (SDK) on the following platform: - 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. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

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 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;
      }

Keywords          : GdiFnt
Platform          : Win95
Issue type        : kbbug


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.