You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
72 lines
1.7 KiB
#include "bitfont.h"
|
|
|
|
Bitfont::Bitfont(TQString fontname, uchar firstChar, uchar lastChar)
|
|
{
|
|
if (!fontname.isEmpty())
|
|
font.load(fontname);
|
|
if (font.width() == font.height()) {
|
|
fontWidth = fontHeight = font.width() / 16;
|
|
fontFirstChar = 1;
|
|
fontLastChar = 255;
|
|
} else {
|
|
fontWidth = font.width()/(lastChar-firstChar+1);
|
|
fontHeight = font.height();
|
|
fontFirstChar = firstChar;
|
|
fontLastChar = lastChar;
|
|
}
|
|
}
|
|
|
|
TQRect Bitfont::rect(TQString str)
|
|
{
|
|
return TQRect(0, 0, str.length()*fontWidth, fontHeight);
|
|
}
|
|
|
|
TQPixmap Bitfont::text(TQString str, TQColor fg, TQColor bg)
|
|
{
|
|
TQPixmap FG(str.length()*fontWidth, fontHeight);
|
|
TQBitmap MASK(str.length()*fontWidth, fontHeight, TRUE);
|
|
|
|
const uchar *s = reinterpret_cast<const unsigned char *>(str.latin1());
|
|
for (uint i = 0; i < str.length(); i++) {
|
|
if (font.width() == font.height())
|
|
bitBlt(&MASK, i*fontWidth, 0, &font,
|
|
(*s%16)*fontWidth, (*s/16)*fontWidth, fontWidth, fontHeight);
|
|
else
|
|
if (*s >= fontFirstChar && *s <= fontLastChar)
|
|
bitBlt(&MASK, i*fontWidth, 0, &font,
|
|
(*s-fontFirstChar)*fontWidth, 0, fontWidth, fontHeight);
|
|
s++;
|
|
}
|
|
|
|
FG.fill(fg);
|
|
FG.setMask(MASK);
|
|
|
|
if (bg.isValid()) {
|
|
TQPixmap BG(str.length()*fontWidth, fontHeight);
|
|
BG.fill(bg);
|
|
bitBlt(&BG, 0, 0, &FG);
|
|
return BG;
|
|
} else
|
|
return FG;
|
|
}
|
|
|
|
uchar Bitfont::firstChar()
|
|
{
|
|
return fontFirstChar;
|
|
}
|
|
|
|
uchar Bitfont::lastChar()
|
|
{
|
|
return fontLastChar;
|
|
}
|
|
|
|
int Bitfont::width()
|
|
{
|
|
return fontWidth;
|
|
}
|
|
|
|
int Bitfont::height()
|
|
{
|
|
return fontHeight;
|
|
}
|