From 28308dccad288950a81b4bbc93755433eaa34e54 Mon Sep 17 00:00:00 2001 From: Moritz Martinius Date: Sun, 3 Dec 2023 11:13:15 +0100 Subject: [PATCH] Rename Image class to Label --- src/P700Printer.cpp | 6 +++--- src/PtouchPrint.cpp | 16 +++++++++++++--- src/graphics/{Image.cpp => Label.cpp} | 16 ++++++++-------- src/graphics/{Image.hpp => Label.hpp} | 14 +++++++------- src/graphics/hello.png | 6 ++++++ src/graphics/hello.txt | 7 +++++++ src/graphics/ptprnt.log | 0 src/hello.txt | 7 +++++++ src/meson.build | 4 ++-- src/ptprnt.log | 0 .../image_test.cpp => label_test/label_test.cpp} | 6 +++--- tests/meson.build | 8 +++++--- 12 files changed, 61 insertions(+), 29 deletions(-) rename src/graphics/{Image.cpp => Label.cpp} (90%) rename src/graphics/{Image.hpp => Label.hpp} (85%) create mode 100644 src/graphics/hello.png create mode 100644 src/graphics/hello.txt create mode 100644 src/graphics/ptprnt.log create mode 100644 src/hello.txt create mode 100644 src/ptprnt.log rename tests/{image_test/image_test.cpp => label_test/label_test.cpp} (86%) diff --git a/src/P700Printer.cpp b/src/P700Printer.cpp index d022084..2b25419 100644 --- a/src/P700Printer.cpp +++ b/src/P700Printer.cpp @@ -30,7 +30,7 @@ #include #include "graphics/Bitmap.hpp" -#include "graphics/Image.hpp" +#include "graphics/Label.hpp" #include "graphics/Monochrome.hpp" #include "libusb.h" #include "libusbwrap/LibUsbTypes.hpp" @@ -125,7 +125,7 @@ bool P700Printer::detachUsbDevice() { bool P700Printer::printBitmap(const graphics::Bitmap& bitmap) { auto bm = graphics::Bitmap(512, 128); { - auto img = graphics::Image(); + auto img = graphics::Label(); bm.setPixels(std::vector(img.getRaw(), img.getRaw() + 512 * 128)); } @@ -203,7 +203,7 @@ bool P700Printer::send(std::vector& data) { } #else tx = data.size(); - spdlog::debug("USB raw data(len {}): {}", data.size(), spdlog::to_hex(data)); + SPDLOG_DEBUG("USB raw data(len {}): {}", data.size(), spdlog::to_hex(data)); #endif if (tx != static_cast(data.size())) { diff --git a/src/PtouchPrint.cpp b/src/PtouchPrint.cpp index e933166..92ddb9f 100644 --- a/src/PtouchPrint.cpp +++ b/src/PtouchPrint.cpp @@ -39,7 +39,7 @@ #include "PrinterDriverFactory.hpp" #include "PtouchPrint.hpp" #include "graphics/Bitmap.hpp" -#include "graphics/Image.hpp" +#include "graphics/Label.hpp" #include "libusbwrap/UsbDeviceFactory.hpp" namespace ptprnt { @@ -59,7 +59,7 @@ int PtouchPrint::init(int argc, char** argv) { if (mVerboseFlag) { setupLogger(spdlog::level::debug); } else { - setupLogger(spdlog::level::err); + setupLogger(spdlog::level::warn); } if (!mUsbDeviceFactory.init()) { @@ -98,6 +98,11 @@ int PtouchPrint::run() { //printer->printBitmap(bm); //printer->printText("wurst", 1); + if (0 == mCommands.size()) { + spdlog::warn("No command specified, nothing to do..."); + return 0; + } + for (auto& cmd : mCommands) { switch (cmd.first) { case CliCmdType::Text: @@ -152,7 +157,12 @@ std::vector> PtouchPrint::getCompatiblePrinters( void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) { auto consoleSink = std::make_shared(); consoleSink->set_level(lvl); - consoleSink->set_pattern("%^%L:%$ %v"); + 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:%#)"); + } else { + consoleSink->set_pattern("%^%L:%$ %v"); + } auto fileSink = std::make_shared("ptprnt.log", true); fileSink->set_level(spdlog::level::trace); diff --git a/src/graphics/Image.cpp b/src/graphics/Label.cpp similarity index 90% rename from src/graphics/Image.cpp rename to src/graphics/Label.cpp index f9f1425..8409755 100644 --- a/src/graphics/Image.cpp +++ b/src/graphics/Label.cpp @@ -17,7 +17,7 @@ */ -#include "Image.hpp" +#include "graphics/Label.hpp" #include #include @@ -35,7 +35,7 @@ #include "pango/pangocairo.h" namespace ptprnt::graphics { -Image::Image() { +Label::Label() { /*mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128); cairo_t* cr = cairo_create(mSurface); mFontDescription = pango_font_description_new(); @@ -56,16 +56,16 @@ Image::Image() { cairo_surface_write_to_png(mSurface, "hello.png");*/ } -uint8_t* Image::getRaw() { +uint8_t* Label::getRaw() { cairo_surface_flush(mSurface); return cairo_image_surface_get_data(mSurface); } -uint8_t Image::getNumLines(std::string_view strv) { +uint8_t Label::getNumLines(std::string_view strv) { return std::count(strv.begin(), strv.end(), '\n'); } -void Image::createLabel(const std::string& str) { +void Label::createLabel(const std::string& str) { // create Pango layout first, to get the render dimensions auto pangoCtx{pango_font_map_create_context(pango_cairo_font_map_get_default())}; @@ -83,7 +83,7 @@ void Image::createLabel(const std::string& str) { pango_layout_get_size(pangoLyt, &width, &height); - spdlog::debug("Layout width: {}, height: {}", width / PANGO_SCALE, height / PANGO_SCALE); + SPDLOG_DEBUG("Layout width: {}, height: {}", width / PANGO_SCALE, height / PANGO_SCALE); auto surf = cairo_image_surface_create(CAIRO_FORMAT_A8, width / PANGO_SCALE, 128); cairo_t* cr = cairo_create(surf); @@ -95,7 +95,7 @@ void Image::createLabel(const std::string& str) { cairo_surface_write_to_png(surf, "hellow.png"); } -Image::~Image() { - spdlog::info("Image dtor..."); +Label::~Label() { + SPDLOG_DEBUG("Image dtor..."); } } // namespace ptprnt::graphics \ No newline at end of file diff --git a/src/graphics/Image.hpp b/src/graphics/Label.hpp similarity index 85% rename from src/graphics/Image.hpp rename to src/graphics/Label.hpp index 86f2ca5..db880de 100644 --- a/src/graphics/Image.hpp +++ b/src/graphics/Label.hpp @@ -29,15 +29,15 @@ namespace ptprnt::graphics { constexpr const char* DEFAULT_FONT_FAMILY = "sans"; constexpr const uint8_t DEFAULT_FONT_SIZE = 32; -class Image { +class Label { public: - Image(); - ~Image(); + Label(); + ~Label(); - Image(const Image&) = delete; - Image& operator=(const Image&) = delete; - Image(Image&&) = delete; - Image& operator=(Image&&) = delete; + Label(const Label&) = delete; + Label& operator=(const Label&) = delete; + Label(Label&&) = delete; + Label& operator=(Label&&) = delete; uint8_t* getRaw(); void createLabel(const std::string& labelText); diff --git a/src/graphics/hello.png b/src/graphics/hello.png new file mode 100644 index 0000000..8aed0fc --- /dev/null +++ b/src/graphics/hello.png @@ -0,0 +1,6 @@ +{ + "text" : "Hello, world :)!", + "font" : "Liberation Sans", + "single-paragraph" : true, + "height" : 0 +} diff --git a/src/graphics/hello.txt b/src/graphics/hello.txt new file mode 100644 index 0000000..a5916b9 --- /dev/null +++ b/src/graphics/hello.txt @@ -0,0 +1,7 @@ +{ + "text" : " Hello", + "font" : "FreeSans 32", + "single-paragraph" : true, + "alignment" : "center", + "height" : 0 +} diff --git a/src/graphics/ptprnt.log b/src/graphics/ptprnt.log new file mode 100644 index 0000000..e69de29 diff --git a/src/hello.txt b/src/hello.txt new file mode 100644 index 0000000..a5916b9 --- /dev/null +++ b/src/hello.txt @@ -0,0 +1,7 @@ +{ + "text" : " Hello", + "font" : "FreeSans 32", + "single-paragraph" : true, + "alignment" : "center", + "height" : 0 +} diff --git a/src/meson.build b/src/meson.build index 9061231..ee66606 100644 --- a/src/meson.build +++ b/src/meson.build @@ -10,7 +10,7 @@ ptprnt_hpps = files ( 'PtouchPrint.hpp', 'PrinterDriverFactory.hpp', 'graphics/Bitmap.hpp', - 'graphics/Image.hpp', + 'graphics/Label.hpp', 'graphics/Monochrome.hpp' ) @@ -18,7 +18,7 @@ ptprnt_srcs = files ( 'PtouchPrint.cpp', 'PrinterDriverFactory.cpp', 'P700Printer.cpp', - 'graphics/Image.cpp', + 'graphics/Label.cpp', 'graphics/Bitmap.cpp', 'graphics/Monochrome.cpp', 'libusbwrap/UsbDeviceFactory.cpp', diff --git a/src/ptprnt.log b/src/ptprnt.log new file mode 100644 index 0000000..e69de29 diff --git a/tests/image_test/image_test.cpp b/tests/label_test/label_test.cpp similarity index 86% rename from tests/image_test/image_test.cpp rename to tests/label_test/label_test.cpp index 46d0f08..a4f1dfd 100644 --- a/tests/image_test/image_test.cpp +++ b/tests/label_test/label_test.cpp @@ -17,10 +17,10 @@ */ -#include "graphics/Image.hpp" +#include "graphics/Label.hpp" #include -TEST(basic_test, Image_smokeTest_succeeds) { - auto im = ptprnt::graphics::Image(); +TEST(basic_test, Label_smokeTest_succeeds) { + auto im = ptprnt::graphics::Label(); } diff --git a/tests/meson.build b/tests/meson.build index 1d45232..4d59e27 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -5,9 +5,9 @@ tests = [ ['../src/graphics/Bitmap.cpp', 'bitmap_test/bitmap_test.cpp'], ], [ - 'image_test', - 'image_test_exe', - ['../src/graphics/Image.cpp', 'image_test/image_test.cpp'], + 'label_test', + 'label_test_exe', + ['../src/graphics/Label.cpp', 'label_test/label_test.cpp'], ], [ 'monochrome_test', @@ -36,3 +36,5 @@ foreach test : tests ), ) endforeach + +