From f702ec5473862ecf05eba02fd8cd6ba48585c704 Mon Sep 17 00:00:00 2001 From: Moritz Martinius Date: Sun, 28 Apr 2024 20:44:13 +0200 Subject: [PATCH] Small Todos for the next session, some clean up --- src/P700Printer.cpp | 2 +- src/PtouchPrint.cpp | 3 ++- src/graphics/Bitmap.cpp | 9 +++------ src/graphics/Label.cpp | 4 +++- src/graphics/Monochrome.cpp | 3 --- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/P700Printer.cpp b/src/P700Printer.cpp index fa43a2b..fec1b7a 100644 --- a/src/P700Printer.cpp +++ b/src/P700Printer.cpp @@ -33,7 +33,7 @@ #include "spdlog/fmt/bin_to_hex.h" // as long as DRYRUN is defined, no data is actually send to the printer, we need to save some tape ;) -//#define DRYRUN +#define DRYRUN namespace ptprnt::printer { diff --git a/src/PtouchPrint.cpp b/src/PtouchPrint.cpp index 9a5e0d4..5ac960e 100644 --- a/src/PtouchPrint.cpp +++ b/src/PtouchPrint.cpp @@ -178,7 +178,8 @@ void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) { consoleSink->set_level(lvl); if (spdlog::level::level_enum::debug == lvl || spdlog::level::level_enum::trace == lvl) { // This will enable file and line number for debug and trace macros - consoleSink->set_pattern("%^%L:%$ %v (%s:%#)"); + // TODO: line number and functions only work with macros + consoleSink->set_pattern("%^%L:%$ %v"); } else { consoleSink->set_pattern("%^%L:%$ %v"); } diff --git a/src/graphics/Bitmap.cpp b/src/graphics/Bitmap.cpp index b31f045..9254d8d 100644 --- a/src/graphics/Bitmap.cpp +++ b/src/graphics/Bitmap.cpp @@ -19,18 +19,15 @@ #include "Bitmap.hpp" -#include #include -#include #include #include #include namespace ptprnt::graphics { template -Bitmap::Bitmap(uint16_t width, uint16_t height) - : mWidth{width}, mHeight{height}, mPixels(width * height) {} +Bitmap::Bitmap(uint16_t width, uint16_t height) : mWidth{width}, mHeight{height}, mPixels(width * height) {} template [[nodiscard]] uint16_t Bitmap::getWidth() const { @@ -45,8 +42,7 @@ template template bool Bitmap::setPixels(const std::vector& pixels) { if (pixels.size() != mPixels.size()) { - spdlog::error("Invalid pixel buffer size (got {} vs. {} bitmap size).", pixels.size(), - mPixels.size()); + spdlog::error("Invalid pixel buffer size (got {} vs. {} bitmap size).", pixels.size(), mPixels.size()); return false; } @@ -71,6 +67,7 @@ template return std::vector(lineStart, lineEnd); } +// TODO: I guess this is borked template [[nodiscard]] std::optional> Bitmap::getCol(uint16_t col) const { if (col >= mWidth) { diff --git a/src/graphics/Label.cpp b/src/graphics/Label.cpp index fefedbb..070c895 100644 --- a/src/graphics/Label.cpp +++ b/src/graphics/Label.cpp @@ -118,7 +118,9 @@ bool Label::create(const std::string& labelText) { mLayoutHeight /= PANGO_SCALE; spdlog::debug("Layout width: {}, height: {}", mLayoutWidth, mLayoutHeight); - mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, mLayoutWidth, mPrinterHeight); + auto alignedWidth = mLayoutWidth + (8 - (mLayoutWidth % 8)); + + mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, alignedWidth, mPrinterHeight); cairo_t* cr = cairo_create(mSurface); // Adjust Cairo cursor position to respect the vertical alignment diff --git a/src/graphics/Monochrome.cpp b/src/graphics/Monochrome.cpp index 2c1a892..496d549 100644 --- a/src/graphics/Monochrome.cpp +++ b/src/graphics/Monochrome.cpp @@ -21,8 +21,6 @@ #include -#include -#include #include #include @@ -40,7 +38,6 @@ void Monochrome::invert(bool shouldInvert) { std::vector Monochrome::get() { std::vector outPixels( (static_cast((mPixels.size() / 8)) + (std::floor(mPixels.size() % 8 + 0.9)))); - unsigned int outIndex = 0; for (unsigned int byteNo = 0; byteNo < mPixels.size(); byteNo += 8) {