Easy way to tell if unicode character is supported in current font?

后端 未结 2 739
忘了有多久
忘了有多久 2020-12-30 14:08

I\'m using Borland C++ Builder 2009 and I display the right and left pointing arrows like so:

Button2->Hint = L\"Ctrl+\\u2190\" ;
Button3->Hint = L\"Ct         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 14:41

    You can use GetFontUnicodeRanges() to see which characters are supported by the font currently selected into the DC. Note that this API requires you to call it once to find out how big the buffer needs to be, and a second time to actually get the data.

    DWORD dwSize = GetFontUnicodeRanges(hDC, nullptr);
    BYTE* bBuffer = new BYTE[dwSize];
    GLYPHSET* pGlyphSet = reinterpret_cast(bBuffer);
    GetFontUnicodeRanges(hDC, pGlyphSet);
    // use data in pGlyphSet, then free the buffer
    delete[] bBuffer;
    

    The GLYPHSET structure has a member array called ranges which lets you determine the range of characters supported by the font.

提交回复
热议问题