diff --git a/src/P700Printer.cpp b/src/P700Printer.cpp index 98ed2ed..67ecdbd 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" @@ -124,7 +124,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)); } @@ -182,7 +182,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 e9375c3..f81e6c8 100644 --- a/src/PtouchPrint.cpp +++ b/src/PtouchPrint.cpp @@ -39,7 +39,7 @@ #include "CLI/Option.hpp" #include "P700Printer.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()) { @@ -71,7 +71,7 @@ int PtouchPrint::init(int argc, char** argv) { } int PtouchPrint::run() { - spdlog::debug("ptprnt version {}", mVersionString); + SPDLOG_DEBUG("ptprnt version {}", mVersionString); SPDLOG_TRACE("testing trace"); auto numFoundPrinters = getCompatiblePrinters(); if (numFoundPrinters == 0) { @@ -97,10 +97,15 @@ 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) { - spdlog::debug("Command: {}", cmd.second); + SPDLOG_DEBUG("Command: {}", cmd.second); if (cmd.first == CliCmdType::Text) { - auto label{graphics::Image()}; + auto label{graphics::Label()}; label.createLabel(cmd.second); } } @@ -133,7 +138,12 @@ unsigned int 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 a5fb667..15a4ced 100644 --- a/src/meson.build +++ b/src/meson.build @@ -9,14 +9,14 @@ ptprnt_hpps = files ( 'P700Printer.hpp', 'PtouchPrint.hpp', 'graphics/Bitmap.hpp', - 'graphics/Image.hpp', + 'graphics/Label.hpp', 'graphics/Monochrome.hpp' ) ptprnt_srcs = files ( 'PtouchPrint.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 87% rename from tests/image_test/image_test.cpp rename to tests/label_test/label_test.cpp index efa7cda..4ead793 100644 --- a/tests/image_test/image_test.cpp +++ b/tests/label_test/label_test.cpp @@ -17,12 +17,12 @@ */ -#include "graphics/Image.hpp" +#include "graphics/Label.hpp" #include #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 493afcc..23e5d13 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,5 +1,5 @@ tests = [['bitmap_test', 'bitmap_test_exe', ptprnt_srcs + ['bitmap_test/bitmap_test.cpp']], - ['image_test', 'image_test_exe', ptprnt_srcs +['image_test/image_test.cpp']], + ['label_test', 'label_test_exe', ptprnt_srcs +['label_test/label_test.cpp']], ['monochrome_test', 'monochrome_test_exe', ptprnt_srcs +['monochrome_test/monochrome_test.cpp']] ]