From 4a08c433ad835b00c6eab4a303cd2b2560ff54ba Mon Sep 17 00:00:00 2001 From: my Date: Thu, 14 Nov 2019 13:12:48 +0100 Subject: [PATCH] defination of Font and Block interface. --- CMakeLists.txt | 5 +- main/main.cpp | 12 +-- res/{font.bmp => font1.bmp} | Bin res/font1.toml | 11 +++ res/font2.bmp | Bin 0 -> 393354 bytes res/font2.toml | 13 +++ res/font3.ppm | 22 +++++ res/font3.toml | 7 ++ src/Bitmap.cpp | 5 +- src/Bitmap.h | 2 +- src/Block.cpp | 65 +++++++++++++++ src/Block.h | 35 ++++++++ src/Config.cpp | 66 +++++++++++++++ src/Config.h | 42 ++++++++++ src/DritteFont.cpp | 162 ++++++++++++++++++++++++++++++++++++ src/DritteFont.h | 42 ++++++++++ src/Font.cpp | 44 +--------- src/Font.h | 34 +------- src/MainFont.cpp | 91 ++++++++++++++++++++ src/MainFont.h | 53 ++++++++++++ 20 files changed, 631 insertions(+), 80 deletions(-) rename res/{font.bmp => font1.bmp} (100%) create mode 100644 res/font1.toml create mode 100644 res/font2.bmp create mode 100644 res/font2.toml create mode 100644 res/font3.ppm create mode 100644 res/font3.toml create mode 100644 src/Block.cpp create mode 100644 src/Block.h create mode 100644 src/Config.cpp create mode 100644 src/Config.h create mode 100644 src/DritteFont.cpp create mode 100644 src/DritteFont.h create mode 100644 src/MainFont.cpp create mode 100644 src/MainFont.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b41e461..60d47c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,10 +21,13 @@ file(GLOB_RECURSE TESTS test/*.cpp) include_directories(src) include_directories(test) +#toml +include_directories(lib/toml) + set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") include_directories(${LIB_PATH}/include) -add_executable(TextRenderer ${SOURCES} ${HEADERS} main/main.cpp) +add_executable(TextRenderer ${SOURCES} ${HEADERS} main/main.cpp src/Font.cpp src/Font.h src/DritteFont.cpp src/DritteFont.h src/Config.cpp src/Config.h src/Block.cpp src/Block.h) target_link_libraries(TextRenderer ${LIB_PATH}/lib/liblibrary.a) diff --git a/main/main.cpp b/main/main.cpp index a5541a8..033a82a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,8 +1,8 @@ -#include - -#include "add.h" +//#include "add.h" #include "Bitmap.h" -#include "Font.h" +#include "MainFont.h" + +#include /** * @author: Julian Hinxlage @@ -12,7 +12,7 @@ * Currently only to test. */ int main() { - Font font("../res/font.bmp"); + MainFont font("../res/font2.bmp", "../res/font2.toml"); std::string str; std::cout << "string to draw: "; @@ -33,4 +33,4 @@ int main() { } return 0; -} \ No newline at end of file +} diff --git a/res/font.bmp b/res/font1.bmp similarity index 100% rename from res/font.bmp rename to res/font1.bmp diff --git a/res/font1.toml b/res/font1.toml new file mode 100644 index 0000000..fb5c1e4 --- /dev/null +++ b/res/font1.toml @@ -0,0 +1,11 @@ +xOffset = 2 +yOffset = 2 +xSize = 5 +ySize = 7 +xCount = 18 +yCount = 4 +xStart = 1 +yStart = 1 +fillValue = 0xffffff +firstChar = 32 +pixelSize = 1 \ No newline at end of file diff --git a/res/font2.bmp b/res/font2.bmp new file mode 100644 index 0000000000000000000000000000000000000000..1962db214e9d27bdf82af87095deea4186877bb4 GIT binary patch literal 393354 zcmeI3v94_EQG|~HT?qmbghb>JIp)SBPKXE~CcZB~N=o9y@qH7=@DMx%F|j$vTZm8o zRa@1kyVtClDGQ@=-RiIVuQlEY;@AK9n=e0n`S!2heEs*oeG`B3_20kv_CJ5~?LU3} z*AHL*^Dn>r;ol$s`P={g{r~;XAO6Fy|KXqi^|$}=Kfn5?-~IBhfBEnK{fi%e{PC}T z`st^?{rc}8e*XFAKmYr`_^&_x)xZ4q@BV-O%a=dnfA}N)d;IH<{?Wt#BToBTLjIKo zp05G^hN++LCAs(&8@Tgt^3J!t;%^~uns0!=Ve0u!A*O+P19$#S-ubqA)0ue32KXDM ze#b8I=KD2p=ilU=Z@b@@%td!>fWKktJKma`-mif>|0eHz+xz`e^5V$`^4s>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OjZ>$evlBY$hi#lX{hXc9Nk44k)amE!giiWl8>db`XD4*h58F6(`Z+tH zlYZF7sngHd37z!AHcp*>&Q9p0AGUGo^mBGXC;hOEQ>UM^6FTXKZJav&oSo1~KWyXF z>F4Z(PWoXRr%pd-Cv?&e+c>4$BcI{loT&`CdRATKW8U&(hu7>b^19wp_6{t#;McK*$JKW!!}Nxe$Gzlq#w3%>hyDVLMQ#OjZ>$e zvlBY$hi#lX{hXc9Nk44k)amE!giiWl8>db`XD4*h58F6(`Z+tHlYZF7sngHd37z!A zHcp*>&Q9p0AGUGo^mBGXC;hOEQ>UM^6FTXKZJav&oSo1~KWyXF>F4Z(PWoXRr%pd- zCv?&e+c>>===VVV++++++444<<<vvv111111111"""++++++444000DDDJJJSSSmmm111!!!111111XXXXXX !!!VVV===hhh+++^^^...444///IIIDDD 111+++...^^^===mmm111111111111mmm======mmmXXX+++...vvvOOOrrr111+++......BBB111111===XXX===XXX111111BBBBBBVVV000...iiiuuu 111+++//////BBB111111BBBBBB===XXX+++kkk^^^......///111JJJwww111+++//////===mmm111111mmm======mmm++++++###///000111000 +++///000!!! !!!++++++000...mmmmmmmmmyyyEEE|||+++000000VVV======VVVAAAAAAVVV===000...111111111111 ---VVVBBB===VVV000111VVV======VVVVVV======VVVVVV======VVVVVV===>>>VVVJJJJJJ000111000111111111111mmmmmmyyy@@@111JJJJJJVVVVVV VVV^^^111FFF111111111111VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV111111111111<<<111111111111999dddaaaVVVWWW000111000VVVWWWVVVWWW}}}VVVVVVWWWWWWVVVWWW 111VVVWWWVVVVVVWWWVVVVVVWWW///000000/// 111VVV======WWW...//////...VVV======WWWVVV======WWW??????~~~===VVVVVV======WWW===WWWVVV======WWW 111VVV======WWW===VVVVVV======WWW===VVVVVV======WWW............ 111111111111111111mmmmmmmmmmmm------------555??????~~~!!!111111!!!??????111111111111,,,,,,,,,,,,...^^^555===mmm111111===WWW===mmmVVV===111111111111mmmmmmmmmmmm++++++++++++///...??????BBB111111BBBXXX??????111111VVV===++++++++++++000///BBB111WWWBBBVVV111111,,,,,,,,,,,,111000666555===mmm111===mmm===XXX??????111111111111VVV------------111777444!!!!!!111111111111mmmmmmmmmmmm............+++??????111111111111===VVV .../////////VVV======VVVVVV======VVV===VVVVVV======VVVVVV======VVVVVV======VVVVVV???,,,+++GGGWWWVVV======VVVVVV======VVV mmmmmmmmm///000000///JJJJJJ?????? VVV000111000JJJJJJVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV(((VVVVVVVVVVVV ---)))+++}}}ddd|||NNN+++++++++@@@lll++++++WWWJJJJJJJJJJJJlll++++++JJJJJJJJJJJJ???lllNNN++++++WWW===IIIllllll+++III>>>ooolllVVVXXXXXXXXXVVVVVVXXXVVVXXX111111XXX$$$VVVVVVXXXXXXVVV$$$VVVuuu((( 111111111111III + + +lll111111RRRRRR111111111111111111111111III===VVV======XXXXXX======XXXVVV===VVV======XXXVVV======XXX111111===XXXGGG___===VVVVVV======XXX===XXXVVV===GGG___===VVVfffDDD??????111111111111111111111111III111111fffDDD111111111111111111III<<<111111(((ttt??????111111III!!!111111111uuu((( 111111III:::111111111GGGbbb?????? 111111111111%%%VVV===___HHH===VVVXXX===VVV===VVV===VVV===111111VVV======VVV===VVVVVV===GGGbbbVVV===VVV===___HHHZZZwwwwwwttttttZZZ111111111111999OOO111111OOO??????iiiiii111111111111)))VVV$$$VVVXXXVVVVVVVVV111VVVVVVVVVVVV (((tttVVVVVV$$$$$$@@@???$$$888...<<<WWW<<<WWW888kkkWWWWWWLLLLLLVVVVVVbbb999======999VVVXXX===VVVVVV===VVVXXXIIIJJJJJJVVV======XXX......JJJJJJJJJJJJWWWIIIWWWIIIVVV======XXX111111qqqJJJJJJ......JJJJJJJJJJJJVVV===111111IIIzzz//////CCC綶>>>CCC綶>>>111222[[[//////{{{VVV{{{VVV======WWW```333vvv///XXXXXXBBBBBBaaa///000vvv???vvv???EEE{{{111===??????===vvv222еBBB,,,,,,BBBaaa111000000000vvvIII栠栠vvvIIIVVVWWWqqq111111iiiiii555vvvXXX======XXX,,,,,,aaa111000000111}}}bbb}}}bbbmmmmmm111111iiiiii000vvvaaa111000JJJ111111===??????===aaa111///vvvIII888888zzzmmmmmm111111aaa111///vvv@@@666666 㯯)))111111111aaa111...}}}666666000VVV===111111XXX===000```,,,,,,aaa111...DDD綶@@@888888...111======111BBB,,,,,,BBBaaaVVVXXX```BBBBBBaaaVVV===WWWIII}}}bbb}}}bbbVVVWWWbbb桡桡<<<WWW999===<<<999VVVccccccWWWLLLLLLdddVVVXXXvvv///JJJJJJJJJJJJvvvvvvJJJJJJJJJJJJJJJJJJJJJJJJCCC + + +ZZZvvv///JJJJJJJJJJJJ}}}}}}vvv222еJJJJJJJJJJJJvvvvvv}}}JJJJJJJJJJJJ}}}JJJJJJJJJJJJZZZ """}}}vvv222еJJJJJJJJJJJJVVV======XXX||||||555vvv||||||```|||555vvv 000vvv   (((cccKKK  000vvv JJJJJJ}}}}}}???;;;}}}}}}wwwwwwVVVVVVWWW!!!VVVVVVVVVVVVPPPSSSVVVWWWVVVWWWVVVWWWVVV======VVVJJJJJJ ***(((??????~~~??????~~~??????~~~??????~~~??????~~~??????VVV===VVV======WWWVVV======VVVVVV======VVV}}}======|||VVV======WWWVVV======WWWVVV===IIIWWWVVVVVVVVV))))))111000??????~~~??????~~~??????~~~??????~~~??????~~~??????VVV111000111VVV111+++bbb}}}bbb}}}///000????????????????????????????????????VVV111+++...///VVV111+++888888^^^...VVV111+++666666+++666666+++888888VVV======VVVVVV======VVVVVV======VVVVVV======VVVVVV======VVVVVV======VVVVVV======VVVVVVBBB===VVVVVV======VVVbbb}}}bbb}}}VVVVVVVVVVVV333333333333VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVccccccdddJJJJJJJJJJJJJJJJJJJJJJJJ111XXX111111111111111111vvv///vvvvvv111111111111111111111111111111111111vvv///111111111111111111vvv///111111 111111222111111111222vvv222еvvvvvv111222111111111222111222111111111222vvv222е111222111111111222vvv222е111222߽߼111111===XXX222333111222111111111333555vvvJJJJJJJJJJJJ222333111222111111111333JJJJJJJJJJJJ222333111222111111111333JJJJJJJJJJJJ555vvv222333111222111111111333555vvvJJJJJJJJJJJJ222333111333333ccc```333```333333ccc000vvvJJJJJJJJJJJJ333ccc```333```333333cccJJJJJJJJJJJJ333ccc```333```333333cccJJJJJJJJJJJJ000vvv333ccc```333```333333ccc000vvvJJJJJJJJJJJJ333ccc___111vvvvvvJJJJJJFFFXXXvvvvvvJJJJJJeeeVVVVVVVVVVVVVVVVVVVVVXXXXXXXXXVVVXXXVVVXXXVVVXXXVVVXXX$$$VVVVVVXXXVVVXXXVVVXXXVVVXXXVVVXXXVVVXXX RRRVVV===VVV===VVV===VVV===VVV===VVV===VVV======XXXXXX======XXXVVV======XXXVVV======XXXVVV======XXXVVV======XXXGGG___===VVVVVV======XXXVVV======XXXVVV======XXXVVV======XXXVVV======XXXVVV==='''XXXXXX---&&&MMM[[[,,,+++++++++JJJJJJ###+++VVV======VVVVVV======VVVVVV======VVV===VVVVVV===___HHHVVV===___HHHVVV===___HHHVVV===___HHHVVV===___HHHVVV===___HHHVVV===WWW===VVV===VVV===VVV===VVV===VVV======VVVVVV======VVVVVV======VVVVVV======VVVVVV======VVVJJJJJJVVV%%%===VVVVVV===___HHHOOOOOOOOOOOOOOOOOOOOOVVVVVVVVVVVVVVVVVVVVVVVV$$$VVV$$$VVV$$$VVV$$$VVV$$$VVV$$$VVVWWWVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV$$$ccccccdddJJJJJJJJJJJJWWWJJJJJJJJJJJJ111111FFFFFFWWW===111111<<<$$$MMM111gggvvv///www + + +BBB"""111111FFFHHH111222BBB"""UUUppp...LLL>>>]]]vvv222еxxx + + +BBB###111222FFFIIIJJJJJJJJJJJJJJJJJJJJJJJJVVV111111111333BBBTTT @@@,,,222555vvv~~~ + + +BBB$$$VVVWWW```333FFFHHHJJJJJJJJJJJJJJJJJJJJJJJJ```333333cccBBBRRRaaaNNNOOO222000vvvxxx$$$VVV===OOO]]]VVV======WWW@@@,,,ggg??????vvvvvvvvvvvvvvv111111111111??????111111111111??????111111111111??????111111??????ZZZOOOUUU\\\??????ttt??????%%%VVV===___HHHVVV===___HHHVVV===___HHHVVV===VVV===??????======OOOOOOOOOvvvvvvvvvVVV$$$VVV$$$VVV$$$VVVVVVvvvtttvvvvvvVVVWWW<<<WWW<<<WWWccccccWWWWWWeeeWWW'''WWW===KKK~~~KKK~~~KKK~~~ZZZlll333;;;ggg@@@VVVWWW111111---uuuuuu---ӌ+++;;;&&&@@@@@@111111ccc---......---*********IIIIII>>>...~~~&&&```zzzVVV======WWW111111ccc--- ,,,......,,,;;;*********lllAAA??????111111??????ccc333 ,,,...---,,,;;;JJJ333+++333333333333ttt111cccvvvvvvvvvvvvvvv+++...---+++vvvvvv;;;~~~KKK~~~KKK~~~KKKIIIIII###栠===***QQQ222%%%??????ccc000lllvvvvvvvvvvvvHHHHHHvvvvvv;;;;;;$$$}}}bbbbbb}}}===333??????cccmmmmmm $$$IIIIII;;;;;;<<<333??????cccUUU,,,qqq$$$IIIIII;;;IIIIIIDDDllllll'''888888<<<LLLZZZOOOUUU\\\??????cccmmmmmm::: vvvvvvvvvvvvIIIIIIvvvvvv;;;666666;;;333+++333333333333pppttt'''??????ccc---)))wwwvvvvvvvvvvvvvvvXXXXXXvvvvvv;;;777+++666666[[[AAA%%%??????ccc&&& ;;;IIIIIIZZZllllll'''888888@@@~~~&&&ZZZ###bbb:::===VVV??????ccc||| +++;;;JJJJJJJJJJJJJJJJJJ&&&vvvvvvccc*********JJJJJJJJJJJJJJJJJJ'''%%%}}}bbbbbb}}}gggGGGvvvvvv\\\VVV桡~~~KKK~~~KKK~~~KKK<<<WWWWWWpppFFF mmm___aaaaaa<<<888sssUUU + + +ddd555ppp...ppp...111111eeekkkPPPjjjiii000ZZZuuu888'''vvveee$$$ \ No newline at end of file diff --git a/res/font3.toml b/res/font3.toml new file mode 100644 index 0000000..0132316 --- /dev/null +++ b/res/font3.toml @@ -0,0 +1,7 @@ +border_color=192 192 192 +backgroud_color=255 255 255 +font_color=0 0 0 +border_width=2 +row=8 +column=32 +columnOfFinalRow=6 \ No newline at end of file diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp index a7fc8e8..a264e50 100644 --- a/src/Bitmap.cpp +++ b/src/Bitmap.cpp @@ -52,9 +52,12 @@ int Bitmap::getBitsPerPixel() { unsigned int Bitmap::getPixel(int x, int y) { 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++){ *((char*)&pixel+i) = ptr[i]; } + if(pixel != 0){ + return pixel; + } return pixel; } diff --git a/src/Bitmap.h b/src/Bitmap.h index 7c82032..fd73947 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -19,7 +19,7 @@ public: * @since: v0.0.0 * @brief: Used to load a Bitmap from a file. */ - void load(const std::string &file); + void load(const std::string &file); /** * @author: Julian Hinxlage diff --git a/src/Block.cpp b/src/Block.cpp new file mode 100644 index 0000000..ee07787 --- /dev/null +++ b/src/Block.cpp @@ -0,0 +1,65 @@ +// +// 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 new file mode 100644 index 0000000..c0c9fc3 --- /dev/null +++ b/src/Block.h @@ -0,0 +1,35 @@ +// +// 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 new file mode 100644 index 0000000..adfbc26 --- /dev/null +++ b/src/Config.cpp @@ -0,0 +1,66 @@ +// +// 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 new file mode 100644 index 0000000..a890ae4 --- /dev/null +++ b/src/Config.h @@ -0,0 +1,42 @@ +// +// 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 new file mode 100644 index 0000000..5b2466b --- /dev/null +++ b/src/DritteFont.cpp @@ -0,0 +1,162 @@ +// +// 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 diff --git a/src/DritteFont.h b/src/DritteFont.h new file mode 100644 index 0000000..4d61b66 --- /dev/null +++ b/src/DritteFont.h @@ -0,0 +1,42 @@ +// +// Created by my on 2019/11/13. +// + +#ifndef TRE_DRITTEFONT_H +#define TRE_DRITTEFONT_H + + +#include +#include +#include +#include "Config.h" +#include "Font.h" + +#define FIRST_CHARACTER_INDEX 25 +#define NUMBER_OF_CHARACTERS 262 +#define DATA_OFFSET 0xf; +#define WIDTH_OFFSET 3; +#define WIDTH_END_SIGNAL 0x20 +#define HEIGHT_END_SIGNAL 0x0A +#define PATH_OF_FONT_BITMAP "../res/font4.ppm" +#define DEVIATION_NUMBER 10 +#define PIXEL_SIZE 3 + +class DritteFont : public Font{ +public: + DritteFont(); + + std::vector test(); + std::vector> getCharacter(unsigned char character) override; + std::vector> characters[NUMBER_OF_CHARACTERS]; + +private: + void readFont(); + + std::vector loadBitmap(); + int getBitmapSize(std::vector data); + int getCharacterSize(std::vector data, Config config, int width); + int findNextStartOffset(std::vector data, int offset, Config config); +}; + +#endif //TRE_DRITTEFONT_H diff --git a/src/Font.cpp b/src/Font.cpp index f29fdf0..f5b302c 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -1,47 +1,9 @@ // -// Copyright (c) 2019 Julian Hinxlage. All rights reserved. +// Created by my on 2019/11/14. // #include "Font.h" -Font::Font() { - xOffset = 2; - yOffset = 2; - xSize = 5; - ySize = 7; - xCount = 18; - yCount = 4; - xStart = 1; - yStart = 2; - fillValue = 0xffffff; +std::vector> Font::getCharacter(unsigned char character) { + return std::vector>(); } - -Font::Font(const std::string &file) : Font() { - bitmap.load(file); -} - -void Font::load(const std::string &file) { - bitmap.load(file); -} - -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; -} - diff --git a/src/Font.h b/src/Font.h index 41459dd..9f00af6 100644 --- a/src/Font.h +++ b/src/Font.h @@ -1,42 +1,16 @@ // -// Copyright (c) 2019 Julian Hinxlage. All rights reserved. +// Created by my on 2019/11/14. // #ifndef TEXTRENDERER_FONT_H #define TEXTRENDERER_FONT_H -#include "Bitmap.h" + +#include class Font { public: - Bitmap bitmap; - - //space between characters - int xOffset; - int yOffset; - - //size of a character - int xSize; - int ySize; - - //count of characters per row - int xCount; - //count of rows - int yCount; - - //pixel offset of first character - int xStart; - int yStart; - - unsigned int fillValue; - - Font(); - explicit Font(const std::string &file); - void load(const std::string &file); - - int width(); - int height(); - bool getPixel(char character, int x, int y); + virtual std::vector> getCharacter(unsigned char character); }; diff --git a/src/MainFont.cpp b/src/MainFont.cpp new file mode 100644 index 0000000..a10ef3b --- /dev/null +++ b/src/MainFont.cpp @@ -0,0 +1,91 @@ +// +// Copyright (c) 2019 Julian Hinxlage. All rights reserved. +// + +#include "MainFont.h" +#include + +MainFont::MainFont() { + xOffset = 0; + yOffset = 0; + xSize = 0; + ySize = 0; + xCount = 0; + yCount = 0; + xStart = 0; + yStart = 0; + fillValue = 0; + firstChar = ' '; +} + +MainFont::MainFont(const std::string &file, const std::string &configFile) : MainFont() { + load(file, configFile); +} + +void MainFont::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); + firstChar = (char)config->get_as("firstChar").value_or(0); + pixelSize = config->get_as("pixelSize").value_or(0); + gap = config->get_as("gap").value_or(-1); +} + +int MainFont::width() { + return xSize; +} + +int MainFont::height() { + return ySize; +} + +bool MainFont::getPixel(char character, int x, int y) { + //index of character(x and y) + int index = (character - firstChar); + + if(gap != -1){ + if (index >= gap){ + index++; + } + } + + int xIndex = index % xCount; + int yIndex = index / xCount; + + if(index < 0){ + yIndex--; + xIndex += xCount; + } + + //character index to pixel index conversion + int xPos = xIndex * (xSize + xOffset) + xStart; + int yPos = yIndex * (ySize + yOffset) + yStart; + + return bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue; +} + +std::vector> MainFont::getCharacter(unsigned char character) { + + std::vector> bitmap_character; + int fontHeight = height(); + int fontWidth = width(); + + bitmap_character.resize(fontHeight); + for (int i = 0; i < fontHeight; i++) { + bitmap_character.resize(fontWidth); + for (int j = 0; j < fontWidth; j++) { + bitmap_character[i][j] = getPixel(character, j, i); + } + } + + return bitmap_character; +} + diff --git a/src/MainFont.h b/src/MainFont.h new file mode 100644 index 0000000..b30ad94 --- /dev/null +++ b/src/MainFont.h @@ -0,0 +1,53 @@ +// +// Copyright (c) 2019 Julian Hinxlage. All rights reserved. +// + +#ifndef TEXTRENDERER_MAINFONT_H +#define TEXTRENDERER_MAINFONT_H + +#include "Bitmap.h" +#include "Font.h" + +/** + * @author: Julian Hinxlage + * @since: v0.0.0 + * @brief: this class provides pixel access based on characters + */ +class MainFont : public Font{ +public: + Bitmap bitmap; + + //space between characters + int xOffset; + int yOffset; + + //size of a character + int xSize; + int ySize; + + //count of characters per row + int xCount; + //count of rows + int yCount; + + //pixel offset of first character + int xStart; + int yStart; + + unsigned int fillValue; + char firstChar; + int pixelSize; + int gap; + + MainFont(); + explicit MainFont(const std::string &file, const std::string &configFile); + void load(const std::string &file, const std::string &configFile); + std::vector> getCharacter(unsigned char character) override; + + int width(); + int height(); + bool getPixel(char character, int x, int y); +}; + + +#endif //TEXTRENDERER_MAINFONT_H