#include "objfont.h" #include "objgfx30.h" #include <string.h> #include <stdlib.h> #include <ubixfs/file.h> #include <ubixos/types.h> TFont::TFont(TGfx0* buffer) { Buf = buffer; memset(FontDataIdx,0,sizeof(FontDataIdx)); memset(CharWidthTable,0,sizeof(CharWidthTable)); memset(CharHeightTable,0,sizeof(CharHeightTable)); FontData = 0; FontDataSize = 0; return; } // TFont::TFont void TFont::CenterTextX(Int32 y, const char * TextString ) { Int32 x; x = ((Buf->getMaxX()+1)-TextWidth(TextString)) / 2; PutText(x,y,TextString); return; } // TFont::CenterTextX void TFont::JustifyText(UInt8 Horiz, UInt8 Vert, const char * TextString) { UInt32 x,y; switch (Horiz) { case LeftText: x = 0; break; case CenterText: x = ((Buf->getMaxX())-TextWidth(TextString)) / 2; break; case RightText: x = (Buf->getMaxX())-TextWidth(TextString); break; default: return; } // switch switch (Vert) { case TopText: y = 0; break; case CenterText: y = ((Buf->getMaxY())-TextHeight(TextString)) / 2; break; case BottomText: y = (Buf->getMaxY())-TextHeight(TextString); default: return; } // switch PutText(x,y,TextString); return; } // TFont::JustifyText bool TFont::Load(const char* FontFile) { return LoadFrom(FontFile,0); } // TFont::Load bool TFont::Save(const char* FontFile) { return SaveTo(FontFile,0); } // TFont::Save UInt32 TFont::TextHeight(const char * TextString) { UInt32 size, tmpsize; size = 0; if (TextString) while (*TextString) { tmpsize = CharHeightTable[*TextString++]; if (tmpsize>size) size = tmpsize; } return size; } // TFont::TextHeight UInt32 TFont::TextWidth(const char * TextString) { UInt32 size=0; if (TextString) while (*TextString) size+=CharWidthTable[*TextString++]; return size; } // TFont::TextWidth TFont::~TFont(void) { if (FontDataSize) free(FontData); return; } // TFont::~TFont /* TBMFont methods */ void TBMFont::SetColor(UInt32 colour) { ColourTable[1] = colour; return; } // TBMFont::SetColor void TBMFont::SetIdxColor(UInt8 idx, UInt32 colour) { ColourTable[idx] = colour; return; } // TBMFont::SetIdxColor void TBMFont::PutText(UInt32 x, UInt32 y, const char * TextString) { UInt32 xx, yy; UInt8 * offset; UInt8 pix; char ch; if (!FontData) return; if (!TextString) return; while (*TextString) { ch = *TextString++; if ((CharWidthTable[ch]) && (ch!=' ')) { offset=(UInt8 *)((UInt32)FontData+(UInt32)FontDataIdx[ch]); for (yy=0; yy<=(UInt32)(CharHeightTable[ch]-1); yy++) for (xx=0; xx<=(UInt32)(CharWidthTable[ch]-1); xx++) { pix = *offset++; if (pix) Buf->putpixel(x+xx,y+yy,ColourTable[pix]); } // for xx x+=CharWidthTable[ch]; } // if charwidthtable } // while return; } // TBMFont::PutText /* TDPFont methods */ void TDPFont::PutText(UInt32 x, UInt32 y, const char * TextString) { UInt32 xx, xcount, ycount; UInt8 * offset; UInt8 bits; char ch; if (!FontData) return; if (TextString) return; while (*TextString) { ch = *TextString++; if ((CharWidthTable[ch]) && (ch!=' ')) offset=(UInt8 *)((UInt32)FontData+(UInt32)FontDataIdx[ch]); for (ycount = 0; ycount<=(UInt32)(Height-1); ycount++) { xcount = CharWidthTable[ch]; xx = 0; do { if (xx & 7==0) bits = *offset++; if (bits & 128) Buf->putpixel(x+ xx++,y+ycount,ColourTable[1]); bits+=bits; } while (xcount--); } // for x+=CharWidthTable[ch]; } // while } // TDPFont::PutText bool TDPFont::LoadFrom(const char * FontFile, UInt32 Offset) { int infile; // TDPFHeader header; // UInt32 lresult; if (FontData) free(FontData); infile = fopen(FontFile,1); // fseek(infile,Offset,SEEK_SET); fclose(infile); return TRUE; } // TDPFont::LoadFrom