String Umsetzung und DriiteFont finished.
This commit is contained in:
parent
79d2f91ef7
commit
b920c95c8c
|
@ -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;
|
||||
}
|
35
src/Block.h
35
src/Block.h
|
@ -1,35 +0,0 @@
|
|||
//
|
||||
// Created by my on 2019/11/13.
|
||||
//
|
||||
|
||||
#ifndef TRE_BLOCK_H
|
||||
#define TRE_BLOCK_H
|
||||
|
||||
#include <string>
|
||||
#include <Color.h>
|
||||
#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
|
|
@ -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;
|
||||
}
|
42
src/Config.h
42
src/Config.h
|
@ -1,42 +0,0 @@
|
|||
//
|
||||
// Created by my on 2019/11/13.
|
||||
//
|
||||
|
||||
#ifndef TRE_CONFIG_H
|
||||
#define TRE_CONFIG_H
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#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
|
|
@ -1,162 +0,0 @@
|
|||
//
|
||||
// Created by my on 2019/11/11.
|
||||
//
|
||||
|
||||
#include "DritteFont.h"
|
||||
|
||||
DritteFont::DritteFont(){
|
||||
readFont();
|
||||
}
|
||||
|
||||
std::vector<char> DritteFont::test() {
|
||||
return loadBitmap();
|
||||
}
|
||||
|
||||
std::vector<std::vector<bool>> DritteFont::getCharacter(unsigned char character) {
|
||||
return characters[character - FIRST_CHARACTER_INDEX];
|
||||
}
|
||||
|
||||
void DritteFont::readFont() {
|
||||
std::vector<char> 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<char> DritteFont::loadBitmap() {
|
||||
std::ifstream ifstream;
|
||||
ifstream.open(PATH_OF_FONT_BITMAP);
|
||||
if(ifstream.is_open()) {
|
||||
std::string str((std::istreambuf_iterator<char>(ifstream)), std::istreambuf_iterator<char>());
|
||||
std::vector<char> 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<char>();
|
||||
}
|
||||
|
||||
int DritteFont::getBitmapSize(std::vector<char> 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<char> 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<char> 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;
|
||||
}
|
Loading…
Reference in New Issue