Thread: How to determine if a font support a Unicode?

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    42

    How to determine if a font support a Unicode?

    Hi there,

    We know the font Ariel Unicode MS support Unicode U+5929 and Ariel not. Can any one tell:

    1. How do we determine if the font Ariel Unicode MS is installed?

    2. How can we determine if a font support Unicode U+5929?

    I appreciate any help,

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I made a couple of functions:
    Code:
    #define _WIN32_WINNT 0x0500 /* GetGlyphIndices requires Windows 2000 or later. */ 
    #include <windows.h>
    #include <stdio.h>
    
    static
    int CALLBACK EnumFontFamProc( CONST ENUMLOGFONT *lpelf,    // logical-font data
                                  CONST NEWTEXTMETRIC *lpntm,  // physical-font data
                                  DWORD FontType,        // type of font
                                  LPARAM lParam          // application-defined data
                                 )
    {
        *((BOOL*)lParam) = TRUE;
        return 0;
    }
    
    /*
     * Checks if a font is installed.
     * Based on OpenOffice code from:
     * http://sourceforge.krugle.com/examples/p-CsDwK3y6Lb7A3V1s/winos.cxx
     */
    BOOL IsFontInstalled( LPCTSTR szFontName )
    {
        BOOL    bIsInstalled = FALSE;
        HDC     hDC = GetDC( NULL );
    
        EnumFontFamilies( hDC, szFontName, (FONTENUMPROC) EnumFontFamProc, (LPARAM) &bIsInstalled );
    
        ReleaseDC( NULL, hDC );
    
        return bIsInstalled;
    }
    
    /*
     * Checks if a character glyph is available for the currently selected font
     * in the given HDC.
     * Note: Does not support unicode surrogates.
     */
    BOOL IsCharacterAvailableInHDC( HDC hdc, WORD character )
    {
    	WORD indice;
    
    	return (GetGlyphIndicesW( hdc, &character, 1,
    	                          &indice, GGI_MARK_NONEXISTING_GLYPHS ) != GDI_ERROR &&
    	        indice != 0xffff);
    }
    
    /*
     * Checks if a character glyph is available in a given font.
     * Note: Does not support unicode surrogates.
     */
    BOOL IsCharacterAvailableInFont( LPCTSTR szFontName, WORD character )
    {
    	HDC   hdc;
    	HFONT hFontOld;
    	HFONT hFontNew;
    	BOOL  bResult;
    
    	/* Create the given font with default parameters. */
    	hFontNew = CreateFont( 0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, 
    	                       DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
    	                       DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, 
    	                       szFontName ); 
    	if (hFontNew == NULL) return FALSE;
    
    	/* Create a screen compatible DC and select our new font. */
    	hdc = GetDC( NULL );
    	hFontOld = (HFONT) SelectObject( hdc, hFontNew );
    
    	/* Check if the character is available. */
    	bResult = IsCharacterAvailableInHDC( hdc, character );
    
    	/* Cleanup. */
    	SelectObject( hdc, hFontOld);
    	DeleteObject( hFontNew );
    	ReleaseDC( NULL, hdc );
    
    	return bResult;
    }
    
    int main(void)
    {
    	if (IsFontInstalled( TEXT("Arial") ) )
    	{
    		printf("Arial is installed!\n");
    	}
    
    	if (IsFontInstalled( TEXT("Arial Unicode MS") ))
    	{
    		printf("Arial Unicode MS is installed!\n");
    	}
    
    	if (IsCharacterAvailableInFont( TEXT("Arial"), 0x01FD ))
    	{
    		printf("Character is available!\n");
    	}
    
    	getchar();
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  3. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM