diff --git a/src/sys/graphics/main.cpp b/src/sys/graphics/main.cpp index 519a4c9..a4aabe3 100755 --- a/src/sys/graphics/main.cpp +++ b/src/sys/graphics/main.cpp @@ -9,22 +9,28 @@ #include int main() { - UInt32 foo; + // UInt32 foo; UInt8 r, g, b; r=0; g=0; b=0; + bool result; TGfx0* buf=0; TGfx0* buf2=0; TDPFont* font=0; buf = new TGfx0(); buf2 = new TGfx0(); font = new TDPFont(buf); - buf->create(400,400,(TPixelFmt *)&def_pixfmt_32bpp); + buf->create(400,400,(TPixelFmt *)&def_pixfmt_8bpp); buf2->create(400,400,(TPixelFmt *)&def_pixfmt_15bpp); - buf->putpixel(11,10,10169); - foo=buf->getpixel(11,10); - printf("%d\n",(int)foo); + result = font->Load("ROM8X8.DPF"); + font->SetColor(1); + font->PutText(0,0,"H"); + for (r=0; r<=7; r++) { + for (g=0; g<=7; g++) + if (buf->getpixel(g,r)) printf("*"); else printf(" "); + printf("\n"); + } if (buf) delete buf; if (buf2) delete buf2; if (font) delete font; diff --git a/src/sys/graphics/objfont.cpp b/src/sys/graphics/objfont.cpp index a84dca9..6088201 100755 --- a/src/sys/graphics/objfont.cpp +++ b/src/sys/graphics/objfont.cpp @@ -52,7 +52,7 @@ PutText(x,y,TextString); return; } // TFont::JustifyText -/* + bool TFont::Load(const char* FontFile) { return LoadFrom(FontFile,0); } // TFont::Load @@ -60,7 +60,7 @@ bool TFont::Save(const char* FontFile) { return SaveTo(FontFile,0); } // TFont::Save -*/ + UInt32 TFont::TextHeight(const char * TextString) { UInt32 size, tmpsize; size = 0; @@ -107,7 +107,7 @@ while (*TextString) { ch = *TextString++; if ((CharWidthTable[ch]) && (ch!=' ')) { - offset=(UInt8 *)((UInt32)FontData+(UInt32)FontDataIdx[ch]); + offset=(UInt8 *)(FontData); for (yy=0; yy<=(UInt32)(CharHeightTable[ch]-1); yy++) for (xx=0; xx<=(UInt32)(CharWidthTable[ch]-1); xx++) { pix = *offset++; @@ -131,21 +131,24 @@ UInt8 bits; char ch; if (!FontData) return; - if (TextString) 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 + if ((CharWidthTable[ch]) && (ch!=' ')) { + offset=(UInt8 *)(FontData); + offset+=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]); + xx++; + bits+=bits; + } while (xcount--); + } // for + } // if x+=CharWidthTable[ch]; } // while } // TDPFont::PutText @@ -153,7 +156,7 @@ bool TDPFont::LoadFrom(const char * FontFile, UInt32 Offset) { FILE * infile; TDPFHeader header; - UInt32 lresult; + UInt32 lresult, size; if (FontData) free(FontData); infile = fopen(FontFile,"r"); fseek(infile,Offset,SEEK_SET); @@ -163,7 +166,21 @@ NumOfChars = header.NumOfChars; if (!NumOfChars) NumOfChars = 256; StartingChar = header.StartingChar; - fclose(infile); + + memset(FontDataIdx,0,sizeof(FontDataIdx)); + memset(CharWidthTable,0,sizeof(CharWidthTable)); + memset(CharHeightTable,0,sizeof(CharHeightTable)); + size = ((Width+7) / 8)*Height; + FontDataSize = size*NumOfChars; + + for (int tmp=StartingChar; tmp<=StartingChar+NumOfChars-1; tmp++) { + CharWidthTable[tmp]=Width; + CharHeightTable[tmp]=Height; + FontDataIdx[tmp]=(size*(tmp-StartingChar)); + } // for + FontData = malloc(FontDataSize); + lresult = fread(FontData,1,FontDataSize,infile); + fclose(infile); return TRUE; } // TDPFont::LoadFrom diff --git a/src/sys/graphics/objfont.h b/src/sys/graphics/objfont.h index e7265ed..9f6b5b8 100755 --- a/src/sys/graphics/objfont.h +++ b/src/sys/graphics/objfont.h @@ -36,7 +36,7 @@ class TFont : public TFont_abstract { protected: - void * FontDataIdx[256]; + UInt32 FontDataIdx[256]; UInt16 CharWidthTable[256]; UInt16 CharHeightTable[256]; TGfx0* Buf; @@ -66,7 +66,6 @@ void SetColor(UInt32); void SetIdxColor(UInt8, UInt32); void PutText(Int32, Int32, const char *); - }; class TDPFont : public TBMFont {