BUG: GetCharacterPlacement Returns Incorrect Kerning ValuesLast reviewed: December 8, 1997Article ID: Q177796 |
The information in this article applies to:
SYMPTOMSThe 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.
CAUSEOn 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.
RESOLUTIONTo reliably calculate the correct character placement (with kerning) for all strings, call GetKerningPairs and calculate the character spacing yourself.
STATUSMicrosoft 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 INFORMATIONMost 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 BehaviorThe 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 |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |