This commit is contained in:
2020-06-11 11:25:19 +02:00
parent 5cb02880b3
commit 5177cd5cbd
15 changed files with 1090 additions and 411 deletions

View File

@@ -41,7 +41,8 @@ public:
/** get the pixel-width of the given char */
uint8_t getCharWidht(char c) const {
if (c == 32) {return 3;} // whitespace
return offsets[c-off+1] - offsets[c-off];
const int i = c-off;
return offsets[i+1] - offsets[i];
}
uint8_t getHeight() const {
@@ -57,8 +58,8 @@ public:
return sum;
}
/** draw the given char at the given position */
template <typename Scalar, typename Destination> void draw(const char* c, Scalar dx, Scalar dy, Destination& dst) {
/** draw the given string at the given position */
template <typename Scalar, typename Destination> void draw(const char* c, Scalar dx, Scalar dy, Destination& dst) const {
while(*c) {
draw(*c, dx, dy, dst);
dx += getCharWidht(*c);// + 1;
@@ -67,11 +68,10 @@ public:
}
/** draw the given char at the given position */
template <typename Scalar, typename Destination> void draw(unsigned char c, Scalar dx, Scalar dy, Destination& dst) {
template <typename Scalar, typename Destination> void draw(unsigned char c, Scalar dx, Scalar dy, Destination& dst) const {
if (c == 32) {return;} // skip whitespace
const uint16_t x1 = offsets[c-off];
const uint16_t x2 = offsets[c-off+1];
const uint16_t y1 = 0;
@@ -80,8 +80,8 @@ public:
for (uint16_t y = y1; y < y2; ++y) {
for (uint16_t x = x1; x < x2; ++x) {
const uint16_t idx = (x/8) + (y*this->w/8);
const uint8_t pixel = data[idx] & (1<<(x&7));
if (pixel) {
const uint8_t pxInFont = data[idx] & (1<<(x&7)); // pixel from font glyph
if (pxInFont) {
dst.setPixel(dx+x-x1, dy+y);
}
}