Rename Image class to Label
This commit is contained in:
@@ -30,7 +30,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "graphics/Bitmap.hpp"
|
#include "graphics/Bitmap.hpp"
|
||||||
#include "graphics/Image.hpp"
|
#include "graphics/Label.hpp"
|
||||||
#include "graphics/Monochrome.hpp"
|
#include "graphics/Monochrome.hpp"
|
||||||
#include "libusb.h"
|
#include "libusb.h"
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
#include "libusbwrap/LibUsbTypes.hpp"
|
||||||
@@ -125,7 +125,7 @@ bool P700Printer::detachUsbDevice() {
|
|||||||
bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) {
|
bool P700Printer::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) {
|
||||||
auto bm = graphics::Bitmap<graphics::ALPHA8>(512, 128);
|
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));
|
bm.setPixels(std::vector<uint8_t>(img.getRaw(), img.getRaw() + 512 * 128));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ bool P700Printer::send(std::vector<uint8_t>& data) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
tx = data.size();
|
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
|
#endif
|
||||||
|
|
||||||
if (tx != static_cast<int>(data.size())) {
|
if (tx != static_cast<int>(data.size())) {
|
||||||
|
@@ -39,7 +39,7 @@
|
|||||||
#include "PrinterDriverFactory.hpp"
|
#include "PrinterDriverFactory.hpp"
|
||||||
#include "PtouchPrint.hpp"
|
#include "PtouchPrint.hpp"
|
||||||
#include "graphics/Bitmap.hpp"
|
#include "graphics/Bitmap.hpp"
|
||||||
#include "graphics/Image.hpp"
|
#include "graphics/Label.hpp"
|
||||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||||
|
|
||||||
namespace ptprnt {
|
namespace ptprnt {
|
||||||
@@ -59,7 +59,7 @@ int PtouchPrint::init(int argc, char** argv) {
|
|||||||
if (mVerboseFlag) {
|
if (mVerboseFlag) {
|
||||||
setupLogger(spdlog::level::debug);
|
setupLogger(spdlog::level::debug);
|
||||||
} else {
|
} else {
|
||||||
setupLogger(spdlog::level::err);
|
setupLogger(spdlog::level::warn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mUsbDeviceFactory.init()) {
|
if (!mUsbDeviceFactory.init()) {
|
||||||
@@ -98,6 +98,11 @@ int PtouchPrint::run() {
|
|||||||
//printer->printBitmap(bm);
|
//printer->printBitmap(bm);
|
||||||
//printer->printText("wurst", 1);
|
//printer->printText("wurst", 1);
|
||||||
|
|
||||||
|
if (0 == mCommands.size()) {
|
||||||
|
spdlog::warn("No command specified, nothing to do...");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& cmd : mCommands) {
|
for (auto& cmd : mCommands) {
|
||||||
switch (cmd.first) {
|
switch (cmd.first) {
|
||||||
case CliCmdType::Text:
|
case CliCmdType::Text:
|
||||||
@@ -152,7 +157,12 @@ std::vector<std::shared_ptr<IPrinterDriver>> PtouchPrint::getCompatiblePrinters(
|
|||||||
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
||||||
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||||
consoleSink->set_level(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:%#)");
|
||||||
|
} else {
|
||||||
consoleSink->set_pattern("%^%L:%$ %v");
|
consoleSink->set_pattern("%^%L:%$ %v");
|
||||||
|
}
|
||||||
|
|
||||||
auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("ptprnt.log", true);
|
auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("ptprnt.log", true);
|
||||||
fileSink->set_level(spdlog::level::trace);
|
fileSink->set_level(spdlog::level::trace);
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Image.hpp"
|
#include "graphics/Label.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
#include "pango/pangocairo.h"
|
#include "pango/pangocairo.h"
|
||||||
|
|
||||||
namespace ptprnt::graphics {
|
namespace ptprnt::graphics {
|
||||||
Image::Image() {
|
Label::Label() {
|
||||||
/*mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128);
|
/*mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128);
|
||||||
cairo_t* cr = cairo_create(mSurface);
|
cairo_t* cr = cairo_create(mSurface);
|
||||||
mFontDescription = pango_font_description_new();
|
mFontDescription = pango_font_description_new();
|
||||||
@@ -56,16 +56,16 @@ Image::Image() {
|
|||||||
cairo_surface_write_to_png(mSurface, "hello.png");*/
|
cairo_surface_write_to_png(mSurface, "hello.png");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* Image::getRaw() {
|
uint8_t* Label::getRaw() {
|
||||||
cairo_surface_flush(mSurface);
|
cairo_surface_flush(mSurface);
|
||||||
return cairo_image_surface_get_data(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');
|
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
|
// create Pango layout first, to get the render dimensions
|
||||||
auto pangoCtx{pango_font_map_create_context(pango_cairo_font_map_get_default())};
|
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);
|
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);
|
auto surf = cairo_image_surface_create(CAIRO_FORMAT_A8, width / PANGO_SCALE, 128);
|
||||||
cairo_t* cr = cairo_create(surf);
|
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");
|
cairo_surface_write_to_png(surf, "hellow.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::~Image() {
|
Label::~Label() {
|
||||||
spdlog::info("Image dtor...");
|
SPDLOG_DEBUG("Image dtor...");
|
||||||
}
|
}
|
||||||
} // namespace ptprnt::graphics
|
} // namespace ptprnt::graphics
|
@@ -29,15 +29,15 @@ namespace ptprnt::graphics {
|
|||||||
constexpr const char* DEFAULT_FONT_FAMILY = "sans";
|
constexpr const char* DEFAULT_FONT_FAMILY = "sans";
|
||||||
constexpr const uint8_t DEFAULT_FONT_SIZE = 32;
|
constexpr const uint8_t DEFAULT_FONT_SIZE = 32;
|
||||||
|
|
||||||
class Image {
|
class Label {
|
||||||
public:
|
public:
|
||||||
Image();
|
Label();
|
||||||
~Image();
|
~Label();
|
||||||
|
|
||||||
Image(const Image&) = delete;
|
Label(const Label&) = delete;
|
||||||
Image& operator=(const Image&) = delete;
|
Label& operator=(const Label&) = delete;
|
||||||
Image(Image&&) = delete;
|
Label(Label&&) = delete;
|
||||||
Image& operator=(Image&&) = delete;
|
Label& operator=(Label&&) = delete;
|
||||||
|
|
||||||
uint8_t* getRaw();
|
uint8_t* getRaw();
|
||||||
void createLabel(const std::string& labelText);
|
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
|
||||||
|
}
|
@@ -10,7 +10,7 @@ ptprnt_hpps = files (
|
|||||||
'PtouchPrint.hpp',
|
'PtouchPrint.hpp',
|
||||||
'PrinterDriverFactory.hpp',
|
'PrinterDriverFactory.hpp',
|
||||||
'graphics/Bitmap.hpp',
|
'graphics/Bitmap.hpp',
|
||||||
'graphics/Image.hpp',
|
'graphics/Label.hpp',
|
||||||
'graphics/Monochrome.hpp'
|
'graphics/Monochrome.hpp'
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ ptprnt_srcs = files (
|
|||||||
'PtouchPrint.cpp',
|
'PtouchPrint.cpp',
|
||||||
'PrinterDriverFactory.cpp',
|
'PrinterDriverFactory.cpp',
|
||||||
'P700Printer.cpp',
|
'P700Printer.cpp',
|
||||||
'graphics/Image.cpp',
|
'graphics/Label.cpp',
|
||||||
'graphics/Bitmap.cpp',
|
'graphics/Bitmap.cpp',
|
||||||
'graphics/Monochrome.cpp',
|
'graphics/Monochrome.cpp',
|
||||||
'libusbwrap/UsbDeviceFactory.cpp',
|
'libusbwrap/UsbDeviceFactory.cpp',
|
||||||
|
0
src/ptprnt.log
Normal file
0
src/ptprnt.log
Normal file
@@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "graphics/Image.hpp"
|
#include "graphics/Label.hpp"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(basic_test, Image_smokeTest_succeeds) {
|
TEST(basic_test, Label_smokeTest_succeeds) {
|
||||||
auto im = ptprnt::graphics::Image();
|
auto im = ptprnt::graphics::Label();
|
||||||
}
|
}
|
@@ -5,9 +5,9 @@ tests = [
|
|||||||
['../src/graphics/Bitmap.cpp', 'bitmap_test/bitmap_test.cpp'],
|
['../src/graphics/Bitmap.cpp', 'bitmap_test/bitmap_test.cpp'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'image_test',
|
'label_test',
|
||||||
'image_test_exe',
|
'label_test_exe',
|
||||||
['../src/graphics/Image.cpp', 'image_test/image_test.cpp'],
|
['../src/graphics/Label.cpp', 'label_test/label_test.cpp'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'monochrome_test',
|
'monochrome_test',
|
||||||
@@ -36,3 +36,5 @@ foreach test : tests
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user