Microsoft KB Archive/263536

{|
 * width="100%"|

HOWTO: Modify the Intercharacter Spacing Array for a String

 * }

Q263536

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), version 4.0
 * Microsoft Windows 95
 * Microsoft Windows 98
 * Microsoft Windows 98 Second Edition
 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional

-

SUMMARY
You can use the TextOut and ExtTextOut functions with a NULL intercharacter spacing (ICS) array to produce text with a default spacing. When it becomes necessary to change that default spacing, it is convenient to start with the original default spacing and modify it to suit the current need. This article describes how to obtain a default ICS array, and how to modify it to alter the spacing within a string.

MORE INFORMATION
The code below demonstrates how to use the GetCharABCWidths function to determine the default intercharacter spacing array for a string, and how to modify that array to alter the spacing of the text.

This code was designed to work with 8-bit ANSI strings or, when compiling for Unicode, with Unicode strings. Double-byte character set (DBCS) strings require more processing. Also, new applications should use Uniscribe, which is described in the MSJ article in the &quot;References&quot; section.

BOOL ModifiedTextOut( HDC hDC, int nX, int nY, LPTSTR szString ) {   int     i, nStringLength; BOOL   bResult; int    *pDx;

// How long is the string - we need this a couple times below nStringLength = lstrlen( szString );

// Allocate enough memory for the intercharacter spacing (ICS).array pDx = (int *)malloc( sizeof(int) * nStringLength ); // Initialize the ICS array with &quot;default&quot; values for(i=0;i<nStringLength;i++) {       ABC     abc; if( ! GetCharABCWidths( hDC, szString[i], szString[i], &abc ) ) {           free( pDx ); return FALSE; }       pDx[i] = abc.abcA + abc.abcB + abc.abcC; }

// To demonstrate the modification of the ICS array, just add // one logical unit to the spacing for each character. This is where // you'd do things like implement justification, etc. by modifying // this array to cause the string to have the extent you desire. for(i=0;i<nStringLength;i++) {       pDx[i] += 1; }   // ExtTextOut draws our text with our ICS array. bResult = ExtTextOut( hDC, nX, nY, ETO_OPAQUE, NULL, szString, nStringLength, pDx ); // clean up. free( pDx ); return bResult; }