+ second font

This commit is contained in:
Julian Hinxlage 2019-10-23 13:39:51 +02:00
parent 4b1afac94d
commit 566bfee91e
8 changed files with 20 additions and 3 deletions

View File

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

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

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

BIN
res/font2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 KiB

10
res/font2.toml Normal file
View File

@ -0,0 +1,10 @@
xOffset = 2
yOffset = 16
xSize = 6
ySize = 6
xCount = 16
yCount = 6
xStart = 1
yStart = 2
fillValue = 0xffffff
firstChar = 33

View File

@ -56,5 +56,8 @@ unsigned int Bitmap::getPixel(int x, int y) {
for(int i = 0; i < getBitsPerPixel() / 8;i++){ for(int i = 0; i < getBitsPerPixel() / 8;i++){
*((char*)&pixel+i) = ptr[i]; *((char*)&pixel+i) = ptr[i];
} }
if(pixel != 0){
return pixel;
}
return pixel; return pixel;
} }

View File

@ -15,6 +15,7 @@ Font::Font() {
xStart = 0; xStart = 0;
yStart = 0; yStart = 0;
fillValue = 0; fillValue = 0;
firstChar = ' ';
} }
Font::Font(const std::string &file, const std::string &configFile) : Font() { Font::Font(const std::string &file, const std::string &configFile) : Font() {
@ -33,6 +34,7 @@ void Font::load(const std::string &file, const std::string &configFile) {
xStart = config->get_as<int>("xStart").value_or(0); xStart = config->get_as<int>("xStart").value_or(0);
yStart = config->get_as<int>("yStart").value_or(0); yStart = config->get_as<int>("yStart").value_or(0);
fillValue = config->get_as<unsigned int>("fillValue").value_or(0); fillValue = config->get_as<unsigned int>("fillValue").value_or(0);
firstChar = (char)config->get_as<int>("firstChar").value_or(0);
} }
int Font::width() { int Font::width() {
@ -45,7 +47,7 @@ int Font::height() {
bool Font::getPixel(char character, int x, int y) { bool Font::getPixel(char character, int x, int y) {
//index of character(x and y) //index of character(x and y)
int index = (character - ' '); int index = (character - firstChar);
int xIndex = index % xCount; int xIndex = index % xCount;
int yIndex = index / xCount; int yIndex = index / xCount;

View File

@ -29,6 +29,7 @@ public:
int yStart; int yStart;
unsigned int fillValue; unsigned int fillValue;
char firstChar;
Font(); Font();
explicit Font(const std::string &file, const std::string &configFile); explicit Font(const std::string &file, const std::string &configFile);