Implement integer text scaling

This commit is contained in:
BlackMark 2022-06-04 19:44:25 +02:00
parent d23814fefc
commit 827decfcbd

View File

@ -211,7 +211,8 @@ class Eink {
} }
static void drawText(const std::pair<std::uint8_t, std::uint8_t> &pos, const char *text, static void drawText(const std::pair<std::uint8_t, std::uint8_t> &pos, const char *text,
const Color textColor = Color::BLACK, const Color backgroundColor = Color::WHITE) const Color textColor = Color::BLACK, const Color backgroundColor = Color::WHITE,
const std::uint8_t scaling = 1)
{ {
const auto textLength = std::strlen(text); const auto textLength = std::strlen(text);
@ -260,9 +261,9 @@ class Eink {
const auto sendChannel = [&](const auto command) { const auto sendChannel = [&](const auto command) {
for (auto i = std::size_t{0}; i < textLength; ++i) { for (auto i = std::size_t{0}; i < textLength; ++i) {
const auto posX = pos.first + i * 8; const auto posX = pos.first + i * 8 * scaling;
const auto screenPosX = getXScreenCoordinates(posX); const auto screenPosX = getXScreenCoordinates(posX);
setRamRange({screenPosX, screenPosX}, {pos.second, pos.second + 7}); setRamRange({screenPosX, screenPosX - (scaling - 1)}, {pos.second, pos.second + 8 * scaling - 1});
setRamXPos(screenPosX); setRamXPos(screenPosX);
setRamYPos(pos.second); setRamYPos(pos.second);
@ -271,7 +272,22 @@ class Eink {
const auto fontByte = flash::loadLike<decltype(FONT_8X8)>(FONT_8X8.value[text[i]][j]); const auto fontByte = flash::loadLike<decltype(FONT_8X8)>(FONT_8X8.value[text[i]][j]);
static_assert(std::is_same_v<std::remove_cvref_t<decltype(fontByte)>, std::uint8_t>); static_assert(std::is_same_v<std::remove_cvref_t<decltype(fontByte)>, std::uint8_t>);
const auto dataByte = adjustColor(flipEndianness(fontByte), command); const auto dataByte = adjustColor(flipEndianness(fontByte), command);
sendData(dataByte);
auto scaledByte = std::uint8_t{0};
auto bitCounter = 0;
for (auto sy = std::uint8_t{0}; sy < scaling; ++sy) {
for (auto b = std::uint8_t{0}; b < 8; ++b) {
const auto currentBit = dataByte >> (8 - b - 1) & 1;
for (auto sx = std::uint8_t{0}; sx < scaling; ++sx) {
scaledByte |= currentBit << (8 - bitCounter - 1);
if (++bitCounter == 8) {
sendData(scaledByte);
scaledByte = 0;
bitCounter = 0;
}
}
}
}
} }
} }
}; };