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"Ctrl+\u2192" ;
This works fine on Windows 7, the application uses font 'Segoe UI'.
On XP I get a square instead of the arrows, I use font 'Tahoma' on XP. In other words mentioned Unicode characters are not present in Tahoma on XP.
Is there an easy and fast way to simply check if the requested Unicode character is supported in the currently used font ? If so I could, for instance, replace the arrow with '>' or '<'. Not perfect, but good enough. I don't want to start changing fonts at this stage.
Your help appreciated.
Right-click your font and select Properties . Select the tab "CharSet/Unicode". If the Font Encoding Type is not Symbol and the Supported Unicode Ranges list anything besides or in addition to Basic Latin and Latin-1 Supplement, your font is a Unicode font or is compatible with Unicode.
A Unicode font is a computer font that maps glyphs to code points defined in the Unicode Standard. The vast majority of modern computer fonts use Unicode mappings, even those fonts which only include glyphs for a single writing system, or even only support the basic Latin alphabet.
Yes indeed, Arial, Times New Roman, and some other fonts are Unicode encoded fonts because they surpass the limit of ASCII encoded fonts. To paraphrase, Unicode fonts are named after the Unicode standard that stipulates a Unicode character code for each character.
Windows' Character Map (found in the Programs > Accessories > System Tools menu) shows all the characters in a font in the form of a scrollable grid. From here you can select and copy a character or group of characters into your document.
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<GLYPHSET*>(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.
Just for reference and the Google Gods:
bool UnicodeCharSupported(HWND Handle, wchar_t Char)
{
if (Handle)
{
DWORD dwSize = GetFontUnicodeRanges(Handle, NULL);
if (dwSize)
{
bool Supported = false ;
BYTE* bBuffer = new BYTE[dwSize];
GLYPHSET* pGlyphSet = reinterpret_cast<GLYPHSET*>(bBuffer);
if (GetFontUnicodeRanges(Handle, pGlyphSet))
{
for (DWORD x = 0 ; x < pGlyphSet->cRanges && !Supported ; x++)
{
Supported = (Char >= pGlyphSet->ranges[x].wcLow &&
Char < (pGlyphSet->ranges[x].wcLow + pGlyphSet->ranges[x].cGlyphs)) ;
}
}
delete[] bBuffer;
return Supported ;
}
}
return false ;
}
Example, relating to my Question:
if (!UnicodeCharSupported(Canvas->Handle, 0x2190))
{ /* Character not supported in current Font, use different character */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With