From 01c825a2f89e24ab262cb3e00a2d509d06826c4b Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 29 Oct 2019 13:24:09 +0100 Subject: [PATCH] ~ fixed second font --- main/main.cpp | 2 +- res/font1.toml | 3 ++- res/font2.toml | 7 +++++-- src/Bitmap.cpp | 2 +- src/Font.cpp | 16 +++++++++++++++- src/Font.h | 2 ++ 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 6e06b4e..e7b311b 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -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: "; diff --git a/res/font1.toml b/res/font1.toml index f0eabc5..fb5c1e4 100644 --- a/res/font1.toml +++ b/res/font1.toml @@ -5,6 +5,7 @@ ySize = 7 xCount = 18 yCount = 4 xStart = 1 -yStart = 2 +yStart = 1 fillValue = 0xffffff firstChar = 32 +pixelSize = 1 \ No newline at end of file diff --git a/res/font2.toml b/res/font2.toml index 372c065..22be04b 100644 --- a/res/font2.toml +++ b/res/font2.toml @@ -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 diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp index 49968c1..a264e50 100644 --- a/src/Bitmap.cpp +++ b/src/Bitmap.cpp @@ -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]; } diff --git a/src/Font.cpp b/src/Font.cpp index 83d7dc7..f0d6318 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -35,6 +35,8 @@ void Font::load(const std::string &file, const std::string &configFile) { yStart = config->get_as("yStart").value_or(0); fillValue = config->get_as("fillValue").value_or(0); firstChar = (char)config->get_as("firstChar").value_or(0); + pixelSize = config->get_as("pixelSize").value_or(0); + gap = config->get_as("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; } diff --git a/src/Font.h b/src/Font.h index fbe0786..30789d5 100644 --- a/src/Font.h +++ b/src/Font.h @@ -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);