#ifndef _XFONT
#define _XFONT
#include "xwindow.h"

class fontK
{
  Pixmap                TheBitmap;
  GC                    TheGC;
  uint                  Width;
  uint                  Height;
  XFontStruct*          KFontStruct;
  int                   CharAscent;
  int                   CharDescent;
  int                   CharLeft;
  int                   CharRight;
  int                   CharSize;
  inline  void          fontTranspose(XImage* Src,XImage* Dest,int OX,int OY)
  {
    for(int X=0;X<CharSize;++X) for(int Y=0;Y<CharSize;++Y)
      {	ulong Pixel=XGetPixel(Src,OX+X,OY+Y);XPutPixel(Dest,OX+Y,OY+X,Pixel);}
  }
  inline  void          fontRotate(XImage* Src,XImage* Dest,int OX,int OY)
  {
    for(int X=0;X<CharSize;++X) for(int Y=0;Y<CharSize;++Y)
      {
	ulong Pixel=XGetPixel(Src,OX+X,OY+Y);
	XPutPixel(Dest,OX+(CharLeft+CharRight-Y),OY+X,Pixel);
      }
  }
  inline  void          fontRTShift(XImage* Src,XImage* Dest,int OX,int OY)
  {
    for(int X=0;X<CharSize/2;++X) for(int Y=CharSize/2;Y<CharSize;++Y)
      {
	ulong Pixel=XGetPixel(Src,OX+X,OY+Y);
	XPutPixel(Dest,OX+(X+(CharLeft+CharRight)/2),OY+Y-CharSize/2,Pixel);
      }
  }
  inline  void          fontLBShift(XImage* Src,XImage* Dest,int OX,int OY)
  {
    for(int X=CharSize/2;X<CharSize;++X) for(int Y=0;Y<CharSize/2;++Y)
      {
	ulong Pixel=XGetPixel(Src,OX+X,OY+Y);
	XPutPixel(Dest,OX+(X-(CharLeft+CharRight)/2),OY+Y+CharSize/2,Pixel);
      }
  }
  inline  void          fontRBShift(XImage* Src,XImage* Dest,int OX,int OY)
  {
    for(int X=0;X<CharSize/2;++X) for(int Y=0;Y<CharSize/2;++Y)
      {
	ulong Pixel=XGetPixel(Src,OX+X,OY+Y);
	XPutPixel(Dest,OX+X+(CharLeft+CharRight)/2,OY+Y+CharSize/2,Pixel);
      }
  }
public:
                        fontK(char* FontName);
          void          drawChar
	  (Drawable Dest,GC DestGC,XChar2b KChar,        int X,int Y);
          void          drawHorString
	  (Drawable Dest,GC DestGC,XChar2b*KString,int N,int X,int Y);
  inline  void          drawChar
	  (Drawable Dest,GC DestGC,uchar B1,uchar B2,int X,int Y)
  {
    XChar2b Char2b; Char2b.byte1=B1; Char2b.byte2=B2;
    drawChar(Dest,DestGC,Char2b,X,Y);
  }
  inline  XFontStruct*  fontStruct (void){ return KFontStruct;}
  inline  int           fontAscent (void){ return CharAscent;}
  inline  int           fontDescent(void){ return CharDescent;}
  inline  int           fontWidth  (void){ return CharLeft  +CharRight;}
  inline  int           fontLeft   (void){ return CharLeft;}
  inline  int           fontRight  (void){ return CharRight;}
  inline  int           fontHeight (void){ return CharAscent+CharDescent;}
  inline  void          fontCopy(XImage* Src,XImage* Dest,int OX,int OY)
  {
    for(int X=0;X<CharSize;++X) for(int Y=0;Y<CharSize;++Y)
      { ulong Pixel=XGetPixel(Src,OX+X,OY+Y);XPutPixel(Dest,OX+X,OY+Y,Pixel);}
  }
  inline  void          copy       (Drawable Dest,GC DestGC)
  { XCopyPlane(TheDisplay,TheBitmap,Dest,DestGC,0,0,Width,Height,0,0,1);}
};

class fontA
{
  Pixmap                TheBitmap;
  GC                    TheGC;
  uint                  Width;
  uint                  Height;
  XFontStruct*          AFontStruct;
  int                   CharAscent;
  int                   CharDescent;
  int                   CharLeft;
  int                   CharRight;
  int                   CharSize;
public:
                        fontA(char* FontName);
          void          drawChar(Drawable Dest,GC DestGC,char Ch,int X,int Y);
          void          drawHorString
	  (Drawable Dest,GC DestGC,char* String,int N,int X,int Y);
	  void          drawHorChar
          (Drawable Dest,GC DestGC,char Ch,int X,int Y);
  inline  int           fontLeft   (void){ return CharLeft;}
  inline  int           fontRight  (void){ return CharRight;}
  inline  int           fontWidth  (void){ return CharLeft   +CharRight;}
  inline  int           fontAscent (void){ return CharAscent;}
  inline  int           fontDescent(void){ return CharDescent;}
  inline  int           fontHeight (void){ return CharDescent+CharAscent;}
  inline  void          copy       (Drawable Dest,GC DestGC)
  { XCopyPlane(TheDisplay,TheBitmap,Dest,DestGC,0,0,Width,Height,0,0,1);}
};

#endif





