~ fixed second font
This commit is contained in:
parent
71d3861ebc
commit
01c825a2f8
|
@ -12,7 +12,7 @@
|
||||||
* Currently only to test.
|
* Currently only to test.
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
Font font("../res/font1.bmp","../res/font1.toml");
|
Font font("../res/font2.bmp","../res/font2.toml");
|
||||||
|
|
||||||
std::string str;
|
std::string str;
|
||||||
std::cout << "string to draw: ";
|
std::cout << "string to draw: ";
|
||||||
|
|
|
@ -5,6 +5,7 @@ ySize = 7
|
||||||
xCount = 18
|
xCount = 18
|
||||||
yCount = 4
|
yCount = 4
|
||||||
xStart = 1
|
xStart = 1
|
||||||
yStart = 2
|
yStart = 1
|
||||||
fillValue = 0xffffff
|
fillValue = 0xffffff
|
||||||
firstChar = 32
|
firstChar = 32
|
||||||
|
pixelSize = 1
|
|
@ -1,10 +1,13 @@
|
||||||
xOffset = 1
|
xOffset = 0
|
||||||
yOffset = 0
|
yOffset = 0
|
||||||
xSize = 8
|
xSize = 8
|
||||||
ySize = 8
|
ySize = 8
|
||||||
xCount = 16
|
xCount = 16
|
||||||
yCount = 6
|
yCount = 6
|
||||||
xStart = 2
|
xStart = 0
|
||||||
yStart = 16
|
yStart = 16
|
||||||
fillValue = 0xffffff
|
fillValue = 0xffffff
|
||||||
firstChar = 33
|
firstChar = 33
|
||||||
|
pixelSize = 4
|
||||||
|
#gap is a character that will get skipped
|
||||||
|
gap = 63
|
||||||
|
|
|
@ -52,7 +52,7 @@ int Bitmap::getBitsPerPixel() {
|
||||||
|
|
||||||
unsigned int Bitmap::getPixel(int x, int y) {
|
unsigned int Bitmap::getPixel(int x, int y) {
|
||||||
unsigned int pixel = 0;
|
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++){
|
for(int i = 0; i < getBitsPerPixel() / 8;i++){
|
||||||
*((char*)&pixel+i) = ptr[i];
|
*((char*)&pixel+i) = ptr[i];
|
||||||
}
|
}
|
||||||
|
|
16
src/Font.cpp
16
src/Font.cpp
|
@ -35,6 +35,8 @@ void Font::load(const std::string &file, const std::string &configFile) {
|
||||||
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);
|
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() {
|
int Font::width() {
|
||||||
|
@ -48,13 +50,25 @@ 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 - firstChar);
|
int index = (character - firstChar);
|
||||||
|
|
||||||
|
if(gap != -1){
|
||||||
|
if (index >= gap){
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int xIndex = index % xCount;
|
int xIndex = index % xCount;
|
||||||
int yIndex = index / xCount;
|
int yIndex = index / xCount;
|
||||||
|
|
||||||
|
if(index < 0){
|
||||||
|
yIndex--;
|
||||||
|
xIndex += xCount;
|
||||||
|
}
|
||||||
|
|
||||||
//character index to pixel index conversion
|
//character index to pixel index conversion
|
||||||
int xPos = xIndex * (xSize + xOffset) + xStart;
|
int xPos = xIndex * (xSize + xOffset) + xStart;
|
||||||
int yPos = yIndex * (ySize + yOffset) + yStart;
|
int yPos = yIndex * (ySize + yOffset) + yStart;
|
||||||
|
|
||||||
return bitmap.getPixel(xPos + x, yPos + y) == fillValue;
|
return bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ public:
|
||||||
|
|
||||||
unsigned int fillValue;
|
unsigned int fillValue;
|
||||||
char firstChar;
|
char firstChar;
|
||||||
|
int pixelSize;
|
||||||
|
int gap;
|
||||||
|
|
||||||
Font();
|
Font();
|
||||||
explicit Font(const std::string &file, const std::string &configFile);
|
explicit Font(const std::string &file, const std::string &configFile);
|
||||||
|
|
Loading…
Reference in New Issue