// // Copyright (c) 2019 Julian Hinxlage. All rights reserved. // #include "Font.h" #include Font::Font() { xOffset = 0; yOffset = 0; xSize = 0; ySize = 0; xCount = 0; yCount = 0; xStart = 0; yStart = 0; fillValue = 0; } Font::Font(const std::string &file, const std::string &configFile) : Font() { load(file, configFile); } void Font::load(const std::string &file, const std::string &configFile) { bitmap.load(file); auto config = cpptoml::parse_file(configFile); xOffset = config->get_as("xOffset").value_or(0); yOffset = config->get_as("yOffset").value_or(0); xSize = config->get_as("xSize").value_or(0); ySize = config->get_as("ySize").value_or(0); xCount = config->get_as("xCount").value_or(0); yCount = config->get_as("yOffset").value_or(0); xStart = config->get_as("xStart").value_or(0); yStart = config->get_as("yStart").value_or(0); fillValue = config->get_as("fillValue").value_or(0); } int Font::width() { return xSize; } int Font::height() { return ySize; } bool Font::getPixel(char character, int x, int y) { //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; return bitmap.getPixel(xPos + x, yPos + y) == fillValue; }