Text-Renderer/src/Font.cpp

48 lines
889 B
C++
Raw Normal View History

2019-10-22 15:34:51 +02:00
//
// Copyright (c) 2019 Julian Hinxlage. All rights reserved.
//
#include "Font.h"
Font::Font() {
xOffset = 2;
yOffset = 2;
xSize = 5;
ySize = 7;
xCount = 18;
yCount = 4;
xStart = 1;
yStart = 2;
2019-10-23 11:42:32 +02:00
fillValue = 0xffffff;
2019-10-22 15:34:51 +02:00
}
Font::Font(const std::string &file) : Font() {
bitmap.load(file);
}
void Font::load(const std::string &file) {
bitmap.load(file);
}
int Font::width() {
return xSize;
}
int Font::height() {
return ySize;
}
2019-10-23 11:42:32 +02:00
bool Font::getPixel(char character, int x, int y) {
2019-10-22 15:34:51 +02:00
//index of character(x and y)
int index = (character - ' ');
int xIndex = index % xCount;
int yIndex = index / xCount;
//character index to pixel index conversion
int xPos = xIndex * (xSize + xOffset) + xStart;
int yPos = yIndex * (ySize + yOffset) + yStart;
2019-10-23 11:42:32 +02:00
return bitmap.getPixel(xPos + x, yPos + y) == fillValue;
2019-10-22 15:34:51 +02:00
}