Click here to Skip to main content
15,888,579 members
Articles / Multimedia / GDI

KanjiFont

Rate me:
Please Sign up or sign in to vote.
3.92/5 (9 votes)
14 Feb 2001 109.6K   3K   24  
Display Chinese & Japanese characters on unicode & non-unicode systems
#ifndef _KANJIFONT_H_
#define _KANJIFONT_H_

#include "KanjiInfo.h"
#include <windows.h>

/**
 * @class KanjiFont
 * 
 * Based on JWPce by Glenn Rosenthal
 */
class KanjiFont : protected KanjiInfo {

protected:

  short _width;
	short _height;
  short _leading;
  short _spacing;
  short _hshift;
  short _vshift;
  
public:

	virtual ~KanjiFont() {};

	virtual BOOL TextOut(HDC, int, int, LPCTSTR) = 0;
  virtual BOOL DrawGlyph(HDC hdc, int, int, int) = 0;                       
  virtual BOOL StretchGlyph(HDC hdc, int, const RECT&, bool) = 0;

};


/** 
 * @class TrueTypeKanjiFont
 *
 * Based on JWPce by Glenn Rosenthal
 */
class TrueTypeKanjiFont : public KanjiFont {

	unsigned long SWAPLONG(unsigned long);
	unsigned short SWAPSHORT(unsigned short);

public:

  TrueTypeKanjiFont ();
	virtual ~TrueTypeKanjiFont();

	BOOL CreateFont(HDC hdc,TCHAR *name,int size,bool bVertical = false);

	virtual BOOL TextOut(HDC, int, int, LPCTSTR);
  virtual BOOL DrawGlyph(HDC hdc,int,int,int);
  virtual BOOL StretchGlyph(HDC hdc,int,const RECT&,bool bVertical = false);

protected:

  int FindGlyph(int);
  
private:

  HFONT   font;                 // TrueType font structure.

  char   *cmap;                 // Copy of the cmap structure for this font.
  char   *gsub;                 // GSUB structre for this font, used for viertical glyph replacemnt
  unsigned short   count;                // Number of entries in the cmap subtable.
  unsigned short  *start;                // Start table for ranges                                
  unsigned short  *end;                  // End table for ranges
  unsigned short  *delta;                // Delta table for displacements
  unsigned short  *offset;               // Offest table for entriesinto the glyph table
  unsigned short  *glyph;                // Glyph table.
  unsigned short   vcount;               // Number of vertical replacement glyphs
  unsigned short  *from;                 // Glphys to be replaced.
  unsigned short  *to;                   // replacement glyphs.

};


#ifndef SHIFTJIS_CHARSET                            // This constaint is only defined in Win CE 2.11 and 
  #define SHIFTJIS_CHARSET 0x80                     //   up.  We support TrueType fonts for all versions, but
#endif  SHIFTJIS_CHARSET                            //   must check for Japanese fonts.

#endif jwp_font_h


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions