The Code Project View our sponsorsCodejock Software - Serious GUI CodeAdvertise on the CodeProject
Home >> Fonts, GDI, GUI >> Fonts

KanjiFont
By Eric Crahen

Display Chinese & Japanese characters on unicode & non-unicode systems 
 VC 4-6, Win95-98, NT4, W2K
 Posted 25 Aug 2000
 Updated 15 Feb 2001
Articles by this author
Send to a friend
Printer friendly version
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
10 users have rated this article. result:
3.9 out of 5.

  • Download source files - 51 Kb
  • Download demo project - 39 Kb
  • Sample Image - KanjiFont_Demo.jpg

    Introduction

    As you may know, Windows 2000 and Windows NT contain natural support Unicode, and can make use of the Windows API functions for displaying and using wide characters. However, the behavior of those API functions is not always completely the same between NT and 2000. Furthermore, under Windows 95 & 98 Unicode character functions are not supported at all.

    This makes it very frustrating for a developer to create an application that needs to display such characters. Recently, I needed to write a small Japanese dictionary for myself. This article contains the small set of classes that encapsulate some simple character translations and the methods for displaying Unicode characters reliably on Windows95/98/NT/2000 to solve this problem. I based my code on some older code done by Glen Rosenthal who wrote JWPce (a very nice Japanese text editor) and on an MSDN article that had some dated examples of a similar solution (Q241020).

    Basically, all TrueType fonts contain encoding tables based on the Unicode mappings for the characters those fonts contain. Microsoft distributes a few large fonts with MS Office and with newer version of Internet Explorer that contain characters or 'glyphs' for many different globale regions. Normally, a device context will do the translation from character code to glyph index for the systems locale when you call the TextOut or the ExtTextOut functions. This does not work on non-Unicode versions of Windows, and it does not work on some configurations for systems that are Unicode compatible. So in order to display the character you want on all version of windows you have to calculate the index of the 'glyph' within the true type font for the charcter code you want to display. Then a call to the ExtTextOut API function will allow you to display the 'glyph' you have selected; so long as it is present in the selected font.

    These classes provide a simple set of objects to easily use a true type font that contains glyphs foreign to your system locale, as well as some character code translation objects. To assist in debugging and just generally getting used to seeing Unicode character codes; most programmers are used to ASCII. I've included some iostream manipulators that allow you to easily translate character codes from one encoding format to another.

    If you have any enhancements or improvements, please let me know and the source can be updated here.
    -Eric

    [Top] Sign in to vote for this article:     PoorExcellent  
    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 8 of 8 (Total: 8)First Prev Next Last
    Subject 
    Author 
    Date 
      newbie question
    Arthur Chen 17:05 12 May 01 
      Why not simply use ExtTextOutW?
    Peter Kenyon 18:25 27 Aug 00 
      Re: Why not simply use ExtTextOutW?
    Eric Crahen 9:25 29 Aug 00 
      Re: Why not simply use ExtTextOutW?
    Peter 19:27 29 Aug 00 
      Re: Why not simply use ExtTextOutW?
    Brian Peterson 19:48 29 Aug 00 
      Good work, but we need more!
    Paul Selormey 15:40 26 Aug 00 
      Re: Good work, but we need more!
    Eric Crahen 9:23 29 Aug 00 
      Library Rocks!
    tyson 22:25 25 Aug 00 
    Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

    Home >> Fonts, GDI, GUI >> Fonts
    last updated 15 Feb 2001
    Article content copyright Eric Crahen, 2000
    everything else © CodeProject, 1999-2001.
    The Code Project View our sponsorsClick here for Dundas Software - 3D accelerated presentation quality ASP charting Advertise on the CodeProject