From c34e6931ebb2f7856abb495fb9a13bff4c22aeff Mon Sep 17 00:00:00 2001 From: Emanuele Trabattoni Date: Sun, 15 Aug 2021 18:54:16 +0200 Subject: [PATCH] chardacters render --- libs/epaper/Fonts/font12.c | 2 +- libs/epaper/Fonts/font16.c | 2 +- libs/epaper/Fonts/font20.c | 2 +- libs/epaper/Fonts/font24.c | 2 +- libs/epaper/Fonts/font8.c | 2 +- libs/epaper/Fonts/fonts.h | 31 ++---------------- libs/mare/mare.h | 10 +++--- libs/mare/mare_drawables.cpp | 62 +++++++++++++++++++++++++++++------- 8 files changed, 63 insertions(+), 50 deletions(-) diff --git a/libs/epaper/Fonts/font12.c b/libs/epaper/Fonts/font12.c index 485c3f0..d689a74 100644 --- a/libs/epaper/Fonts/font12.c +++ b/libs/epaper/Fonts/font12.c @@ -1375,7 +1375,7 @@ const uint8_t Font12_Table[] = 0x00, // }; -sFONT Font12 = { +sFONT Font12_t = { Font12_Table, 7, /* Width */ 12, /* Height */ diff --git a/libs/epaper/Fonts/font16.c b/libs/epaper/Fonts/font16.c index 58ce59b..466676a 100644 --- a/libs/epaper/Fonts/font16.c +++ b/libs/epaper/Fonts/font16.c @@ -1755,7 +1755,7 @@ const uint8_t Font16_Table[] = 0x00, 0x00, // }; -sFONT Font16 = { +sFONT Font16_t = { Font16_Table, 11, /* Width */ 16, /* Height */ diff --git a/libs/epaper/Fonts/font20.c b/libs/epaper/Fonts/font20.c index 697e3ed..7e206c4 100644 --- a/libs/epaper/Fonts/font20.c +++ b/libs/epaper/Fonts/font20.c @@ -2133,7 +2133,7 @@ const uint8_t Font20_Table[] = }; -sFONT Font20 = { +sFONT Font20_t = { Font20_Table, 14, /* Width */ 20, /* Height */ diff --git a/libs/epaper/Fonts/font24.c b/libs/epaper/Fonts/font24.c index fea3321..6f09ef7 100644 --- a/libs/epaper/Fonts/font24.c +++ b/libs/epaper/Fonts/font24.c @@ -2511,7 +2511,7 @@ const uint8_t Font24_Table [] = 0x00, 0x00, 0x00, // }; -sFONT Font24 = { +sFONT Font24_t = { Font24_Table, 17, /* Width */ 24, /* Height */ diff --git a/libs/epaper/Fonts/font8.c b/libs/epaper/Fonts/font8.c index 88450d9..d7996d0 100644 --- a/libs/epaper/Fonts/font8.c +++ b/libs/epaper/Fonts/font8.c @@ -995,7 +995,7 @@ const uint8_t Font8_Table[] = 0x00, // }; -sFONT Font8 = { +const sFONT Font8_t = { Font8_Table, 5, /* Width */ 8, /* Height */ diff --git a/libs/epaper/Fonts/fonts.h b/libs/epaper/Fonts/fonts.h index 214ceb9..928da81 100644 --- a/libs/epaper/Fonts/fonts.h +++ b/libs/epaper/Fonts/fonts.h @@ -55,38 +55,11 @@ typedef struct _tFont { const uint8_t *table; - uint16_t Width; - uint16_t Height; + const uint16_t Width; + const uint16_t Height; } sFONT; - -//GB2312 -// typedef struct // ������ģ���ݽṹ -// { -// const char index[2]; // ������������ -// const char matrix[MAX_HEIGHT_FONT*MAX_WIDTH_FONT/8+2]; // ���������� -// }CH_CN; - - -// typedef struct -// { -// const CH_CN *table; -// uint16_t size; -// uint16_t ASCII_Width; -// uint16_t Width; -// uint16_t Height; - -// }cFONT; - -// extern sFONT Font24; -// extern sFONT Font20; -// extern sFONT Font16; -// extern sFONT Font12; -// extern sFONT Font8; - -// extern cFONT Font12CN; -// extern cFONT Font24CN; #ifdef __cplusplus } #endif diff --git a/libs/mare/mare.h b/libs/mare/mare.h index 7aa08b2..a278957 100644 --- a/libs/mare/mare.h +++ b/libs/mare/mare.h @@ -270,7 +270,7 @@ namespace Render{ void setRadius(uint16_t radius) { _radius = radius; }; const uint16_t getRadius() { return _radius; }; void setOutline(bool outline) { _outline = outline; }; - const getOutline() { return _outline; }; + const bool getOutline() { return _outline; }; private: void render(); @@ -296,7 +296,7 @@ namespace Render{ // members private: Font _fontEnum; - _tFont _font; + const _tFont* _font; char _char; }; @@ -307,12 +307,13 @@ namespace Render{ public: void setString(std::string& s) { _s = s; }; - const std::string& getString() { return &s; }; + const std::string& getString() { return _s; }; void setFont(Font f) { _fontEnum = f; }; const Font getFont() { return _fontEnum; }; void setRotation(TextRotation rotation) { _rotation = rotation; }; const TextRotation getRotation() { return _rotation; }; - + void setSpacing(uint8_t hSpace, uint8_t vSpace) {_vSpace= vSpace; _hSpace=hSpace;} + const pos_t getSpacing() { return {_hSpace,_vSpace}; }; private: void render(); @@ -322,6 +323,7 @@ namespace Render{ TextRotation _rotation; std::string _s; std::vector _chars; + uint8_t _hSpace=2, _vSpace=2; }; class DrawableCustom: public Drawable { diff --git a/libs/mare/mare_drawables.cpp b/libs/mare/mare_drawables.cpp index a756597..68238a1 100644 --- a/libs/mare/mare_drawables.cpp +++ b/libs/mare/mare_drawables.cpp @@ -231,11 +231,11 @@ namespace Render { //--------+--------+--------+--------+--------+--------+--------+--------+--------+--------// //Character - extern const _tFont* Font8; - extern const _tFont* Font12; - extern const _tFont* Font16; - extern const _tFont* Font20; - extern const _tFont* Font24; + extern const _tFont* Font8_t; + extern const _tFont* Font12_t; + extern const _tFont* Font16_t; + extern const _tFont* Font20_t; + extern const _tFont* Font24_t; DrawableChar::DrawableChar(const size_t id, Drawable* parent, Mare* engine, char c, Font f) : @@ -246,23 +246,23 @@ namespace Render { switch (_fontEnum) { case Font::Font8: - _font = *Font8; + _font = Font8_t; break; case Font::Font12: - _font = *Font12; + _font = Font12_t; break; case Font::Font16: - _font = *Font16; + _font = Font16_t; break; case Font::Font20: - _font = *Font20; + _font = Font20_t; break; case Font::Font24: - _font = *Font24; + _font = Font24_t; break; default: @@ -275,7 +275,22 @@ namespace Render { } void DrawableChar::render() { - + uint8_t* buf = getBuffer(); + const pos_t o = getOrigin(); + const BlendMode bm = getBlendMode(); + const uint8_t w = _font->Width; + const uint8_t h = _font->Height; + const uint16_t w_ch = w%7 ? (w/7)+1 : w/7; + const uint8_t* ch = _font->table + (_char - ' ') * w_ch * h; + for(uint8_t y(0); y < h; y++) { + for(uint8_t x(0); x < w; x++) { + const uint8_t* ch_v = ch + x / 7 + y * w_ch; + if (ch_v == 0) continue; + if ((*ch_v >> x) & 0x01){ + engine()->setPixel(buf,o.x+x, o.y+y, bm); + } + } + } } //--------+--------+--------+--------+--------+--------+--------+--------+--------+--------// @@ -289,7 +304,7 @@ namespace Render { _chars.reserve(s.size()); uint16_t idx(0); for(auto c : _s){ - _chars.push_back(engine->addDrawable(c.c_str(),_fontEnum)); + _chars.push_back(engine->addDrawable(reinterpret_cast(c),_fontEnum)); } } @@ -304,9 +319,32 @@ namespace Render { } void DrawableString::render() { + pos_t ofs; + int32_t ofsX=0, ofsY=0; + switch(_rotation) { + case TextRotation::Rot0: { + ofsX = _chars.front()->_font->Width + _hSpace; + break; + } + case TextRotation::Rot180:{ + ofsY = -_chars.front()->_font->Width - _hSpace; + break; + } + case TextRotation::Rot90: { + ofsY = _chars.front()->_font->Height + _vSpace; + break; + } + case TextRotation::Rot270: { + ofsY = _chars.front()->_font->Height + _vSpace; + break; + } + } for (auto c : _chars){ if (c != nullptr){ + c->setOrigin(ofs); c->render(); + ofs.x += ofsX; + ofs.y += ofsY; } } }