summaryrefslogtreecommitdiffstats
path: root/kpacman/bitfont.cpp
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2020-08-17 18:58:43 +0200
committerSlávek Banko <slavek.banko@axis.cz>2020-08-17 18:58:43 +0200
commit6f2c87870081718731cccee678e1e89869826de2 (patch)
tree942f97a4b9d4126d385e8bdc0aee30ff3dc6ed6d /kpacman/bitfont.cpp
downloadtdepacman-6f2c87870081718731cccee678e1e89869826de2.tar.gz
tdepacman-6f2c87870081718731cccee678e1e89869826de2.zip
Initial import of version 0.3.2 from the source package.
https://sourceforge.net/projects/kpacman/files/kpacman/0.3.2/kpacman-0.3.2.tar.gz Original package is licenced under GPL 2.0. Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'kpacman/bitfont.cpp')
-rw-r--r--kpacman/bitfont.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/kpacman/bitfont.cpp b/kpacman/bitfont.cpp
new file mode 100644
index 0000000..40581c8
--- /dev/null
+++ b/kpacman/bitfont.cpp
@@ -0,0 +1,71 @@
+#include "bitfont.h"
+
+Bitfont::Bitfont(QString 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;
+ }
+}
+
+QRect Bitfont::rect(QString str)
+{
+ return QRect(0, 0, str.length()*fontWidth, fontHeight);
+}
+
+QPixmap Bitfont::text(QString str, QColor fg, QColor bg)
+{
+ QPixmap FG(str.length()*fontWidth, fontHeight);
+ QBitmap MASK(str.length()*fontWidth, fontHeight, TRUE);
+
+ const uchar *s = (const uchar *) str.data();
+ 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()) {
+ QPixmap 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;
+}