If you need the same kerning as Win32 TextOut I might have what you need.
This litte test-code generates the same output. You can use it to extract the kerning tables from ttf-fonts. Note that most fonts have different kerning tables for different font sizes, so you can't just extract one table and use it for scaled fonts (it will look like shit).
char * img;
void putpixel (int x, int y, int a) { img[1024*y+x] = a; }
void PlacingTest (void)
{
HDC dc = CreateCompatibleDC(0);
int size = 32;
img = new char[1024*1024];
memset (img, 0, 1024*1024);
wchar_t * string = L"This is a test";
GLYPHMETRICS gm;
MAT2 mat;
mat.eM11.fract = 0; mat.eM11.value = 1; mat.eM21.fract = 0; mat.eM21.value = 0;
mat.eM12.fract = 0; mat.eM12.value = 0; mat.eM22.fract = 0; mat.eM22.value = 1;
HFONT fnt = CreateFont(size,0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,FF_DONTCARE,"Arial");
SelectObject (dc, fnt);
int nKerningPairs = GetKerningPairs(dc, 0, 0);
KERNINGPAIR * kerningpairs = new KERNINGPAIR[nKerningPairs];
GetKerningPairs(dc, nKerningPairs, kerningpairs);
int xpos = 0; int ypos = 40;
wchar_t last = 0;
for (int i=0; i<wcslen(string); i++) {
// get image from gdi
DWORD BytesReq = GetGlyphOutlineW(dc, string[i], GGO_GRAY8_BITMAP, &gm, 0, 0, &mat);
sU8 * glyphImg= new sU8[BytesReq];
DWORD r = GetGlyphOutlineW(dc, string[i], GGO_GRAY8_BITMAP, &gm, BytesReq, glyphImg, &mat);
for (int j=0; j<BytesReq; j++) glyphImg[j]= 255*int(glyphImg[j])/65;
// apply kerning
for (int k=0; k<nKerningPairs; k++) {
if ((kerningpairs[k].wFirst == last) && (kerningpairs[k].wSecond == string[i])) {
xpos += kerningpairs[k].iKernAmount;
break;
}
}
// blit glyph onto bitmap:
if (string[i]!= ' ') {
int w = (gm.gmBlackBoxX+3)&~3;
int h = gm.gmBlackBoxY;
for (int y=0; y<gm.gmBlackBoxY; y++)
for (int x=0; x<gm.gmBlackBoxX; x++)
putpixel (x+xpos+gm.gmptGlyphOrigin.x, y+ypos-gm.gmptGlyphOrigin.y, glyphImg[y*w+x]);
}
delete [] glyphImg;
xpos += gm.gmCellIncX;
last = string[i];
}
delete [] kerningpairs;
// save the image (so you can test it)
FILE *f = fopen ("c://test.raw","wb");
if (f) {
fwrite (img, 1024,1024,f);
fclose (f);
}
delete [] img;
}