From b920c95c8c580225bc70fdf6ec7a703173f26417 Mon Sep 17 00:00:00 2001 From: my Date: Tue, 19 Nov 2019 13:30:39 +0100 Subject: [PATCH] String Umsetzung und DriiteFont finished. --- src/Block.cpp | 65 ------------------ src/Block.h | 35 ---------- src/Config.cpp | 66 ------------------ src/Config.h | 42 ------------ src/DritteFont.cpp | 162 --------------------------------------------- 5 files changed, 370 deletions(-) delete mode 100644 src/Block.cpp delete mode 100644 src/Block.h delete mode 100644 src/Config.cpp delete mode 100644 src/Config.h delete mode 100644 src/DritteFont.cpp diff --git a/src/Block.cpp b/src/Block.cpp deleted file mode 100644 index ee07787..0000000 --- a/src/Block.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// -// Created by my on 2019/11/14. -// - -#include "Block.h" - -void Block::clear() { - -} - -void Block::addString(std::string str) { - -} - -void Block::addChar(unsigned char character) { - -} - -void Block::newLine() { - -} - -void Block::setBackgroundWithSingleColor(Color color) { - -} - -void Block::setBackground(Color *) { - -} - -void Block::setBackgroundWithSlowChangedColor(Color color1, Color color2, int modul) { - -} - -void Block::setNowX() { - -} - -void Block::setNowY() { - -} - -void Block::addNowX() { - -} - -void Block::addNowY() { - -} - -int Block::getNowx() { - return 0; -} - -int Block::getNowY() { - return 0; -} - -void Block::addString(std::string str, Font font) { - -} - -unsigned char *Block::getDisplayColor() { - return nullptr; -} diff --git a/src/Block.h b/src/Block.h deleted file mode 100644 index c0c9fc3..0000000 --- a/src/Block.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// Created by my on 2019/11/13. -// - -#ifndef TRE_BLOCK_H -#define TRE_BLOCK_H - -#include -#include -#include "Font.h" - -class Block { -public: - virtual void clear(); - virtual void addString(std::string str); - virtual void addString(std::string str, Font font); - virtual void addChar(unsigned char character); - virtual void newLine(); - virtual unsigned char * getDisplayColor(); - - - virtual void setBackgroundWithSingleColor(Color color); - virtual void setBackground(Color[]); - virtual void setBackgroundWithSlowChangedColor(Color color1, Color color2, int modul); - - - virtual void setNowX(); - virtual void setNowY(); - virtual void addNowX(); - virtual void addNowY(); - virtual int getNowx(); - virtual int getNowY(); -}; - -#endif //TRE_BLOCK_H diff --git a/src/Config.cpp b/src/Config.cpp deleted file mode 100644 index adfbc26..0000000 --- a/src/Config.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// -// Created by my on 2019/11/12. -// - -#include "Config.h" - - -Config::Config() { - init(); -} - -void Config::init() { - std::ifstream infile(CONFIG_FILE_PATH); - std::string line; - - std::getline(infile, line); - line = line.substr(BORDER_COLOR_STARTPOSITION); - border_color = readColor(line); - - std::getline(infile, line); - line = line.substr(BACKGROUND_COLOR_STARTPOSITION); - background_color = readColor(line); - - std::getline(infile, line); - line = line.substr(FONT_COLOR_STARTPOSITION); - font_color = readColor(line); - - std::getline(infile, line); - line = line.substr(BORDER_WIDTH_STARTPOSITION); - border_width = readInteger(line); - - std::getline(infile, line); - line = line.substr(ROW_STARTPOSITION); - row = readInteger(line); - - std::getline(infile, line); - line = line.substr(COLUMN_STARTPOSITION); - column = readInteger(line); - - std::getline(infile, line); - line = line.substr(COLUMN_OF_FINAL_ROW_STARTPOSITION); - column_of_finalRow = readInteger(line); -} - -int Config::readInteger(std::string line) { - int value; - std::istringstream iss(line); - - if(!(iss >> value)) { - std::cout << "failed when read interger from config" << std::endl; - } - - return value; -} - -Color Config::readColor(std::string line) { - int red, green, blue; - std::istringstream iss(line); - - if(!(iss >> red >> green >> blue)) { - std::cout << "failed when read color from config" << std::endl; - } - - Color color(red, green, blue); - return color; -} diff --git a/src/Config.h b/src/Config.h deleted file mode 100644 index a890ae4..0000000 --- a/src/Config.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// Created by my on 2019/11/13. -// - -#ifndef TRE_CONFIG_H -#define TRE_CONFIG_H - -#include -#include -#include -#include "Color.h" - -#define CONFIG_FILE_PATH "../res/font4.config" -#define BORDER_COLOR_STARTPOSITION 13 -#define BACKGROUND_COLOR_STARTPOSITION 16 -#define FONT_COLOR_STARTPOSITION 11 -#define BORDER_WIDTH_STARTPOSITION 13 -#define ROW_STARTPOSITION 4 -#define COLUMN_STARTPOSITION 7 -#define COLUMN_OF_FINAL_ROW_STARTPOSITION 17 - -class Config { -public: - Color border_color = Color(0, 0, 0); - Color background_color = Color(0, 0, 0); - Color font_color = Color(0, 0, 0); - int border_width; - int row; - int column; - int column_of_finalRow; - - Config(); - -private: - void init(); - - Color readColor(std::string line); - int readInteger(std::string line); -}; - - -#endif //TRE_CONFIG_H diff --git a/src/DritteFont.cpp b/src/DritteFont.cpp deleted file mode 100644 index 5b2466b..0000000 --- a/src/DritteFont.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// -// Created by my on 2019/11/11. -// - -#include "DritteFont.h" - -DritteFont::DritteFont(){ - readFont(); -} - -std::vector DritteFont::test() { - return loadBitmap(); -} - -std::vector> DritteFont::getCharacter(unsigned char character) { - return characters[character - FIRST_CHARACTER_INDEX]; -} - -void DritteFont::readFont() { - std::vector data = loadBitmap(); - Config config; - - int offset = DATA_OFFSET; - int row; - int column; - int i; - int j; - int size = getBitmapSize(data); // size = width * 10000 + height - int width = size / 10000; - int characterSize = getCharacterSize(data, config, width); // characterSize = width * 10000 + height - int characterWidth = characterSize / 10000; - int characterHeight = characterSize % 10000; - -// characters->resize(NUMBER_OF_CHARACTERS); - - for(i = 0; i < NUMBER_OF_CHARACTERS; i++) { - characters[i].resize(characterHeight); - for(j = 0; j < characterHeight; j++) { - characters[i][j].resize(characterWidth); - } - } - - offset = findNextStartOffset(data, offset, config); - for(row = 0; row < config.row - 1; row++) { - for(column = 0; column < config.column; column++) { - for(i = 0; i < characterHeight; i++) { - for(j = 0; j < characterWidth; j++) { - characters[row * config.column + column][i][j] = - data[offset + (i * width + j) * PIXEL_SIZE] != (char)config.background_color.red; - } - } - offset = findNextStartOffset(data, offset, config); - } - offset += characterHeight * width * PIXEL_SIZE; - offset = findNextStartOffset(data, offset, config); - } - - for(column = 0; column < config.column_of_finalRow; column++) { - for(i = 0; i < characterHeight; i++) { - for(j = 0; j < characterWidth; j++) { - characters[config.row * config.column + column][i][j] = - data[offset + (i * width + j) * PIXEL_SIZE] != (char)config.background_color.red; - } - } - offset = findNextStartOffset(data, offset, config); - } -} - -std::vector DritteFont::loadBitmap() { - std::ifstream ifstream; - ifstream.open(PATH_OF_FONT_BITMAP); - if(ifstream.is_open()) { - std::string str((std::istreambuf_iterator(ifstream)), std::istreambuf_iterator()); - std::vector data; - data.resize(str.size()); - for(int i = 0; i < str.size(); i++){ - data[i] = str[i]; - } - return data; - } - - std::cout << "read failed" << std::endl; - return std::vector(); -} - -int DritteFont::getBitmapSize(std::vector data) { - int width = 0; - int height = 0; - int offset = WIDTH_OFFSET; - - while(data[offset] != WIDTH_END_SIGNAL) { - width = width * 10 + data[offset++] - '0'; - } - offset++; - - while(data[offset] != HEIGHT_END_SIGNAL) { - height = height * 10 + data[offset++] - '0'; - } - - return width * 10000 + height; -} - -int DritteFont::getCharacterSize(std::vector data, Config config, int width) { - int characterWidth = 0; - int characterHeight = 0; - int tempOffset; - - int offset = DATA_OFFSET; - int counter = 0; - - // because the red green blue values of border color is equal, - // so i simple the method, falls the values is different, - // the method must be modified - for(; offset < data.size(); offset++) { - - if(((unsigned int)data[offset] & 0xff) == config.border_color.red) // only use red value because the red, green and blue values are equal. - counter++; - - if(((unsigned int)data[offset] & 0xff) != config.border_color.red) { - if(counter > 0 && counter < config.border_width * 3 + DEVIATION_NUMBER) { // mal 3 because color has 3 values, red, green and blue values. - tempOffset = offset; - while (((unsigned int)data[tempOffset++] & 0xff) != config.border_color.red) { - characterWidth++; - } - tempOffset = offset; - while (((unsigned int)data[tempOffset] & 0xff) != config.border_color.red) { - characterHeight++; - tempOffset += width * PIXEL_SIZE; - } - - return characterWidth / PIXEL_SIZE * 10000 + characterHeight; - } - - counter = 0; - } - } - - std::cout << "not get chacter size\n" << std::endl; - return 0; -} - - -int DritteFont::findNextStartOffset(std::vector data, int offset, Config config) { - - int counter = 0; - - for(; offset < data.size(); offset += PIXEL_SIZE) { - - if(((unsigned int)data[offset] & 0xff) == config.border_color.red) // only use red value because the red, green and blue values are equal. - counter++; - - if(((unsigned int)data[offset] & 0xff) != config.border_color.red) { - if(counter > 0 && counter < config.border_width + DEVIATION_NUMBER) { // mal 3 because color has 3 values, red, green and blue values. - return offset; - } - - counter = 0; - } - } - std::cout << "not find offset\n" << std::endl; - return 0; -} \ No newline at end of file