Export (0) Print
Expand All

How to Use Font Linking

MLang implements a service called font linking to assist developers who must output strings that contain characters from a variety of character sets. This service creates a custom font that inherits from a specified source font. The IMLangFontLink interface contains the methods a client uses to perform font linking.

To use the font-linking functionality of MLang:

  1. Make sure the Component Object Library has been initialized.

    Before you can use any functionality provided by MLang, you must first initialize the Component Object Library through a call to CoInitialize. Every call to CoInitialize must be accompanied by a call to CoUninitialize when the application terminates. CoUninitialize ensures that the application does not quit until it has received all of its pending messages.

  2. Obtain a pointer to an IMLangFontLink interface.

    The IMLangFontLink interface is part of the MultiLanguage. If no such object exists, you must create one and obtain a pointer to the corresponding IMultiLanguage interface through a call to CoCreateInstance. Once this has been accomplished, call QueryInterface through IMultiLanguage for a pointer to an IMLangFontLink interface.

  3. Obtain handles to the default font you want to use to output the string and to the device context through which it will be displayed.

    Try to use a font that will display as many of the characters in the string as possible. This helps limit the number of times a custom font must be created.

  4. Use the IMLangCodePages and IMLangFontLink methods to determine if a custom font is needed for the string you want to output.

    Using the IMLangCodePages::GetCharCodePages, IMLangCodePages::GetStrCodePages, and IMLangFontLink::GetFontCodePages methods, you can determine if a custom font is needed to output the given string (or character). The following code sample demonstrates how to determine if a character (ch) can be output by a given font.

    
    // IMLangFontLink* pMLangFontLink;
    DWORD dwFontCodePages;
    DWORD dwCharCodePages;
    
    pMLangFontLink->GetFontCodePages(hDC, hFont, &dwFontCodePages);
    pMLangFontLink->GetCharCodePages(ch, &dwCharCodePages);
    
    if(dwCharCodePages & dwFontCodePages)
    {
        // Character ch can be output with hFont on hDC.
    }
    else
    {
        // Create a custom font to output the characters from
        // dwCharCodePages.
    }
    
    
  5. If a custom font is needed, call IMLangFontLink::MapFont to create a font.

    IMLangFontLink implements a font cache to store the custom fonts that are created. When a custom font is no longer being used, it must be released from the font cache through the IMLangFontLink::ReleaseFont method. This allows the font object to be deleted if the cache becomes full.

  6. Remember to release the interfaces and uninitialize the Component Object Library before your program terminates.

Related topics

MLang Reference

 

 

Build date: 11/17/2013

Show:
© 2014 Microsoft