~ fixed second font

This commit is contained in:
Julian Hinxlage 2019-10-29 13:24:09 +01:00
parent 71d3861ebc
commit 01c825a2f8
6 changed files with 26 additions and 6 deletions

View File

@ -12,7 +12,7 @@
* Currently only to test.
*/
int main() {
Font font("../res/font1.bmp","../res/font1.toml");
Font font("../res/font2.bmp","../res/font2.toml");
std::string str;
std::cout << "string to draw: ";

View File

@ -5,6 +5,7 @@ ySize = 7
xCount = 18
yCount = 4
xStart = 1
yStart = 2
yStart = 1
fillValue = 0xffffff
firstChar = 32
pixelSize = 1

View File

@ -1,10 +1,13 @@
xOffset = 1
xOffset = 0
yOffset = 0
xSize = 8
ySize = 8
xCount = 16
yCount = 6
xStart = 2
xStart = 0
yStart = 16
fillValue = 0xffffff
firstChar = 33
pixelSize = 4
#gap is a character that will get skipped
gap = 63

View File

@ -52,7 +52,7 @@ int Bitmap::getBitsPerPixel() {
unsigned int Bitmap::getPixel(int x, int y) {
unsigned int pixel = 0;
char *ptr = getData() + ((getHeight() - y) * getWidth() + x) * getBitsPerPixel() / 8;
char *ptr = getData() + ((getHeight() - 1 - y) * getWidth() + x) * (getBitsPerPixel() / 8);
for(int i = 0; i < getBitsPerPixel() / 8;i++){
*((char*)&pixel+i) = ptr[i];
}

View File

@ -35,6 +35,8 @@ void Font::load(const std::string &file, const std::string &configFile) {
yStart = config->get_as<int>("yStart").value_or(0);
fillValue = config->get_as<unsigned int>("fillValue").value_or(0);
firstChar = (char)config->get_as<int>("firstChar").value_or(0);
pixelSize = config->get_as<int>("pixelSize").value_or(0);
gap = config->get_as<int>("gap").value_or(-1);
}
int Font::width() {
@ -48,13 +50,25 @@ int Font::height() {
bool Font::getPixel(char character, int x, int y) {
//index of character(x and y)
int index = (character - firstChar);
if(gap != -1){
if (index >= gap){
index++;
}
}
int xIndex = index % xCount;
int yIndex = index / xCount;
if(index < 0){
yIndex--;
xIndex += xCount;
}
//character index to pixel index conversion
int xPos = xIndex * (xSize + xOffset) + xStart;
int yPos = yIndex * (ySize + yOffset) + yStart;
return bitmap.getPixel(xPos + x, yPos + y) == fillValue;
return bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue;
}

View File

@ -35,6 +35,8 @@ public:
unsigned int fillValue;
char firstChar;
int pixelSize;
int gap;
Font();
explicit Font(const std::string &file, const std::string &configFile);