locked
GetKerningPairs returning wrong kerning value for Cambria font RRS feed

  • Question

  • Hi All,

    I am using GetKerningPairs to retrieve all kerning pairs for a font, it works very well in most cases but in case of Cambria font it gives me a kerning pair for the characters ('t' and 'a'), But when I open cambria font file in font explorer then there is no entry for this pair in the kern table. which means the tagKERNINGPAIR.iKernAmount should have been zero for this pair, which is not the case.
    Therefore wrong kerning is happening in my code. On searching on Internet I did find some clues saying "Cambria is opentype font and GetKerningPairs have some problems with  it" but I could not find much detailed information and how to get the correct kern values. 

    I am on windows XP SP3 build 2600, and my application is a native C++ app. The font I am using is "Cambria" regular. The cambria ttf & ttc files show their version as 5.96.
    Any help is greatly appreciated.

    Thanks in advance
    Rahul

    Rahul

    Tuesday, April 17, 2012 5:07 AM

Answers

  • Hi,

    I got the solution (Thanks to Microsoft support for this). 
    Since my project setting was "Use multi-byte" the call GetKerningPairs was resolved as GetKerningPairsA, By changing the call to GetKerningPairsW I am getting the correct kerning pairs (and no value for "ta" combination)

    Regards
    Rahul

    Rahul

    • Marked as answer by rsharma_champ Thursday, April 19, 2012 1:21 PM
    Thursday, April 19, 2012 1:21 PM

All replies

  • Do you have any codes to reproduce this issue?

    NEU_ShieldEdge

    Wednesday, April 18, 2012 2:35 AM
  • Hi Luke,

    Here is the code. I found one more thing while debugging, my VC++ project setting is "Character set" = "Use Multi-Byte ". 

    However if I change this setting to "Use Unicode Character Set" then the problem goes away and GetKerningPairs returns correct number of pairs (~ 29 k) as shown by font explorer or ttfdump.exe.

    But I don't know whay does char set affect kerning pairs?

    wchar_t firstChar = 't';
    wchar_t secondChar = 'a';
    HFONT  p_HFONT = ::CreateFontW(-2048, 0,0,0,400, 0,0,0,1, 7,0,2,2, L"Cambria");
    HDC p_dc = CreateDCW(L"DISPLAY", 0, 0, 0);

        ::SelectObject( p_dc, p_HFONT );
        ::SetMapMode( p_dc, MM_TEXT );

    KERNINGPAIR*   lpKp;
    DWORD          numKernPairs = GetKerningPairs( p_dc, 0, NULL );
    if(numKernPairs > 0)
    {
    lpKp = (KERNINGPAIR*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, numKernPairs * sizeof( KERNINGPAIR ) );
    GetKerningPairs( p_dc, numKernPairs, lpKp );// Retrieve the actual kerning pairs.

    for( int i = 0; i < (int)numKernPairs; i++ )
    {
    if( ((lpKp+i)->wFirst == firstChar) && ((lpKp+i)->wSecond== secondChar) )
    {
    printf("%d \n", (lpKp+i)->iKernAmount);
    break;
    }
    }
    }


    Rahul

    Wednesday, April 18, 2012 6:22 AM

  • Hi Rahul,

    Did your system up to date?

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 19, 2012 6:33 AM
  • Hi,

    I got the solution (Thanks to Microsoft support for this). 
    Since my project setting was "Use multi-byte" the call GetKerningPairs was resolved as GetKerningPairsA, By changing the call to GetKerningPairsW I am getting the correct kerning pairs (and no value for "ta" combination)

    Regards
    Rahul

    Rahul

    • Marked as answer by rsharma_champ Thursday, April 19, 2012 1:21 PM
    Thursday, April 19, 2012 1:21 PM