Rename Image class to Label
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
#include <vector>
|
||||
|
||||
#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<graphics::ALPHA8>& bitmap) {
|
||||
auto bm = graphics::Bitmap<graphics::ALPHA8>(512, 128);
|
||||
{
|
||||
auto img = graphics::Image();
|
||||
auto img = graphics::Label();
|
||||
bm.setPixels(std::vector<uint8_t>(img.getRaw(), img.getRaw() + 512 * 128));
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ bool P700Printer::send(std::vector<uint8_t>& 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<int>(data.size())) {
|
||||
|
@@ -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<spdlog::sinks::stdout_color_sink_mt>();
|
||||
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<spdlog::sinks::basic_file_sink_mt>("ptprnt.log", true);
|
||||
fileSink->set_level(spdlog::level::trace);
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "Image.hpp"
|
||||
#include "graphics/Label.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <spdlog/spdlog.h>
|
||||
@@ -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
|
@@ -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);
|
6
src/graphics/hello.png
Normal file
6
src/graphics/hello.png
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"text" : "Hello, world :)!",
|
||||
"font" : "Liberation Sans",
|
||||
"single-paragraph" : true,
|
||||
"height" : 0
|
||||
}
|
7
src/graphics/hello.txt
Normal file
7
src/graphics/hello.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"text" : " Hello",
|
||||
"font" : "FreeSans 32",
|
||||
"single-paragraph" : true,
|
||||
"alignment" : "center",
|
||||
"height" : 0
|
||||
}
|
0
src/graphics/ptprnt.log
Normal file
0
src/graphics/ptprnt.log
Normal file
7
src/hello.txt
Normal file
7
src/hello.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"text" : " Hello",
|
||||
"font" : "FreeSans 32",
|
||||
"single-paragraph" : true,
|
||||
"alignment" : "center",
|
||||
"height" : 0
|
||||
}
|
@@ -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',
|
||||
|
0
src/ptprnt.log
Normal file
0
src/ptprnt.log
Normal file
@@ -17,12 +17,12 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "graphics/Image.hpp"
|
||||
#include "graphics/Label.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
TEST(basic_test, Image_smokeTest_succeeds) {
|
||||
auto im = ptprnt::graphics::Image();
|
||||
TEST(basic_test, Label_smokeTest_succeeds) {
|
||||
auto im = ptprnt::graphics::Label();
|
||||
}
|
@@ -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']]
|
||||
]
|
||||
|
||||
|
Reference in New Issue
Block a user