Newer
Older
Scratch / objgfx / ogFont.h
#ifndef OGFONT_H
#define OGFONT_H

#include "objgfx30.h"

#define LeftText   0
#define CenterText 1
#define RightText  2
#define BottomText 0
#define TopText    2

enum ogFontType {BMF, DPF};

typedef 
  struct {
    char  ID[4];
    uInt8 BPP;
    uInt8 paddington[10];
  } ogFontHeader;

typedef 
  struct {
    char  ID[3];
    uInt8 Version;
    uInt8 Width, Height;
    uInt8 NumOfChars;
    uInt8 StartingChar;
    uInt8 ColourType;
    uInt8 paddington[7];
  } ogDPFHeader;

class ogAbstractFont {
       public:
        virtual void putText(ogSurface&, int32, int32, const char *)=0;
        virtual bool loadFrom(const char *, uInt32)=0;
        virtual bool saveTo(const char *, int32)=0;
};

class ogFont : public ogAbstractFont {
       protected:
        uInt32 FontDataIdx[256];
        uInt16 CharWidthTable[256];
        uInt16 CharHeightTable[256];
        ogSurface* Buf;
        uInt32 FontDataSize;
        void * FontData;
       public:
        ogFont();
      //  virtual void PutText(int32, int32,const char *);
        void centerTextX(ogSurface&, int32, const char *);
        void justifyText(ogSurface&, uInt8, uInt8, const char *);
        bool load(const char *);
        virtual bool loadFrom(const char *, uInt32);
        bool save(const char *);
      //  virtual bool SaveTo(const char *, int32) = 0;
        uInt32 textHeight(const char *);
        uInt32 textWidth(const char *);
        virtual ~ogFont(void);
}; // TFont

class ogBMFont : public ogFont {
       protected:
        ogRGB ColourTable[32];
       public:
        ogBMFont(void): ogFont() {
          for (uInt32 tmp=0; tmp<=31; tmp++) {
            ColourTable[tmp].red = 255;
            ColourTable[tmp].green = 255;
            ColourTable[tmp].blue = 255;
          } // for
        } 
        void setColor(uInt8, uInt8, uInt8);
        void setIdxColor(uInt8, uInt8, uInt8, uInt8);
        virtual void putText(ogSurface&, int32, int32, const char *);
};

class ogDPFont : public ogBMFont {
       protected:
        uInt8 Width, Height;
        uInt16 NumOfChars;
        uInt8 StartingChar;
       public:
        ogDPFont(void) : ogBMFont() {
          Width = 0;
          Height = 0;
          NumOfChars = 0;
          StartingChar = 0;
        }
        virtual void putText(ogSurface&, int32, int32, const char *);
        virtual bool loadFrom(const char *, uInt32);
        virtual bool saveTo(const char *, int32);
};

#endif