Compare commits
3 Commits
fix-logger
...
778a01429c
Author | SHA1 | Date | |
---|---|---|---|
778a01429c | |||
d8b70e5d56 | |||
cd15930e1d |
@@ -14,7 +14,7 @@ jobs:
|
|||||||
- name: install meson
|
- name: install meson
|
||||||
run: apt-get -yq install meson
|
run: apt-get -yq install meson
|
||||||
- name: Install build dependencies
|
- name: Install build dependencies
|
||||||
run: apt-get -yq install libusb-1.0-0-dev libspdlog-dev libpango1.0-dev libcairo2-dev gcovr
|
run: apt-get -yq install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev gcovr
|
||||||
- name: setup builddir
|
- name: setup builddir
|
||||||
run: meson setup builddir -Db_coverage=true
|
run: meson setup builddir -Db_coverage=true
|
||||||
- name: build all targets
|
- name: build all targets
|
||||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,9 +1,13 @@
|
|||||||
|
# Folder
|
||||||
builddir/
|
builddir/
|
||||||
|
ptouch-print/
|
||||||
subprojects/*
|
subprojects/*
|
||||||
!subprojects/*.wrap
|
|
||||||
.cache/
|
.cache/
|
||||||
|
coverageReport/
|
||||||
|
|
||||||
|
# Files
|
||||||
|
!subprojects/*.wrap
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/c_cpp_properties.json
|
!.vscode/c_cpp_properties.json
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
ptouch-print/
|
|
@@ -19,7 +19,7 @@ pacman -S libusb spdlog pango cairo meson gcovr
|
|||||||
|
|
||||||
Install dependencies on Debian/Ubuntu
|
Install dependencies on Debian/Ubuntu
|
||||||
``` bash
|
``` bash
|
||||||
apt-get install libusb-1.0-0-dev libspdlog-dev libpango1.0-dev libcairo2-dev meson gcovr
|
apt-get install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev meson gcovr
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
21
generate_coverage.sh
Executable file
21
generate_coverage.sh
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
HTML_COV_PATH="coverageReport/html"
|
||||||
|
HTML_START_FILE="index.html"
|
||||||
|
|
||||||
|
echo "Generating Coverage report for ptouch-prnt"
|
||||||
|
|
||||||
|
ninja -C builddir
|
||||||
|
ninja -C builddir test
|
||||||
|
|
||||||
|
mkdir -p ${HTML_COV_PATH}
|
||||||
|
gcovr --html --html-details --html-syntax-highlighting --filter src --output ${HTML_COV_PATH}/${HTML_START_FILE}
|
||||||
|
|
||||||
|
if [ $? ]
|
||||||
|
then
|
||||||
|
echo "Coverage report successful generated!"
|
||||||
|
echo "Open: file://${SCRIPT_PATH}/${HTML_COV_PATH}/${HTML_START_FILE}"
|
||||||
|
else
|
||||||
|
echo "Error generating coverage report!"
|
||||||
|
fi
|
39
meson.build
39
meson.build
@@ -6,6 +6,7 @@ project('ptprnt', 'cpp',
|
|||||||
|
|
||||||
usb_dep = dependency('libusb-1.0')
|
usb_dep = dependency('libusb-1.0')
|
||||||
log_dep = dependency('spdlog')
|
log_dep = dependency('spdlog')
|
||||||
|
fmt_dep = dependency('fmt')
|
||||||
pangocairo_dep = dependency('pangocairo')
|
pangocairo_dep = dependency('pangocairo')
|
||||||
|
|
||||||
# CLI11
|
# CLI11
|
||||||
@@ -17,45 +18,15 @@ endif
|
|||||||
|
|
||||||
incdir = include_directories('src')
|
incdir = include_directories('src')
|
||||||
|
|
||||||
ptprnt_hpps = [
|
subdir('src')
|
||||||
'src/libusbwrap/interface/IUsbDeviceFactory.hpp',
|
|
||||||
'src/libusbwrap/interface/IUsbDevice.hpp',
|
|
||||||
'src/libusbwrap/UsbDeviceFactory.hpp',
|
|
||||||
'src/libusbwrap/LibUsbTypes.hpp',
|
|
||||||
'src/libusbwrap/UsbDevice.hpp',
|
|
||||||
'src/interface/IPrinterDriver.hpp',
|
|
||||||
'src/interface/IPrinterTypes.hpp',
|
|
||||||
'src/P700Printer.hpp',
|
|
||||||
'src/PtouchPrint.hpp',
|
|
||||||
'src/graphics/Bitmap.hpp',
|
|
||||||
'src/graphics/Image.hpp',
|
|
||||||
'src/graphics/Monochrome.hpp'
|
|
||||||
]
|
|
||||||
|
|
||||||
ptprnt_srcs = [
|
|
||||||
'src/PtouchPrint.cpp',
|
|
||||||
'src/P700Printer.cpp',
|
|
||||||
'src/graphics/Image.cpp',
|
|
||||||
'src/graphics/Bitmap.cpp',
|
|
||||||
'src/graphics/Monochrome.cpp',
|
|
||||||
'src/libusbwrap/UsbDeviceFactory.cpp',
|
|
||||||
'src/libusbwrap/UsbDevice.cpp',
|
|
||||||
]
|
|
||||||
|
|
||||||
ptprnt_lib = library('ptprnt',
|
|
||||||
include_directories: incdir,
|
|
||||||
install: true,
|
|
||||||
dependencies: [usb_dep, log_dep, pangocairo_dep, cli11_dep],
|
|
||||||
sources: [ptprnt_hpps, ptprnt_srcs])
|
|
||||||
|
|
||||||
ptprnt_dep = declare_dependency(include_directories: incdir,
|
|
||||||
link_with: ptprnt_lib)
|
|
||||||
|
|
||||||
ptprnt_exe = executable(
|
ptprnt_exe = executable(
|
||||||
'ptprnt',
|
'ptprnt',
|
||||||
'src/main.cpp',
|
'src/main.cpp',
|
||||||
install: true,
|
install: true,
|
||||||
dependencies : [usb_dep, log_dep, cli11_dep, ptprnt_dep],
|
dependencies : [usb_dep, log_dep, fmt_dep, pangocairo_dep, cli11_dep],
|
||||||
|
include_directories: incdir,
|
||||||
|
sources: [ptprnt_srcs],
|
||||||
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"'],
|
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -16,18 +16,30 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||||
|
#define SPDLOG_DEBUG_ON
|
||||||
|
#define SPDLOG_TRACE_ON
|
||||||
|
|
||||||
#include "PtouchPrint.hpp"
|
#include "PtouchPrint.hpp"
|
||||||
|
|
||||||
#include <CLI/App.hpp>
|
#include <CLI/App.hpp>
|
||||||
|
#include <fmt/core.h>
|
||||||
#include <spdlog/common.h>
|
#include <spdlog/common.h>
|
||||||
|
#include <spdlog/details/synchronous_factory.h>
|
||||||
|
#include <spdlog/logger.h>
|
||||||
|
#include <spdlog/sinks/base_sink.h>
|
||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "CLI/Option.hpp"
|
#include "CLI/Option.hpp"
|
||||||
#include "P700Printer.hpp"
|
#include "P700Printer.hpp"
|
||||||
#include "graphics/Bitmap.hpp"
|
#include "graphics/Bitmap.hpp"
|
||||||
|
#include "graphics/Image.hpp"
|
||||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||||
|
|
||||||
namespace ptprnt {
|
namespace ptprnt {
|
||||||
@@ -45,9 +57,9 @@ int PtouchPrint::init(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mVerboseFlag) {
|
if (mVerboseFlag) {
|
||||||
setupLogger(spdlog::level::trace);
|
setupLogger(spdlog::level::debug);
|
||||||
} else {
|
} else {
|
||||||
setupLogger(spdlog::level::critical);
|
setupLogger(spdlog::level::err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mUsbDeviceFactory.init()) {
|
if (!mUsbDeviceFactory.init()) {
|
||||||
@@ -59,10 +71,12 @@ int PtouchPrint::init(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PtouchPrint::run() {
|
int PtouchPrint::run() {
|
||||||
|
spdlog::debug("ptprnt version {}", mVersionString);
|
||||||
|
SPDLOG_TRACE("testing trace");
|
||||||
auto numFoundPrinters = getCompatiblePrinters();
|
auto numFoundPrinters = getCompatiblePrinters();
|
||||||
if (numFoundPrinters == 0) {
|
if (numFoundPrinters == 0) {
|
||||||
spdlog::error(
|
spdlog::error(
|
||||||
"No compatible printers found, please make sure if they are turned on and connected");
|
"No compatible printers found, please make sure that they are turned on and connected");
|
||||||
return -1;
|
return -1;
|
||||||
} else if (numFoundPrinters > 1) {
|
} else if (numFoundPrinters > 1) {
|
||||||
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
||||||
@@ -84,7 +98,11 @@ int PtouchPrint::run() {
|
|||||||
//printer->printText("wurst", 1);
|
//printer->printText("wurst", 1);
|
||||||
|
|
||||||
for (auto& cmd : mCommands) {
|
for (auto& cmd : mCommands) {
|
||||||
std::cout << cmd.second << std::endl;
|
spdlog::debug("Command: {}", cmd.second);
|
||||||
|
if (cmd.first == CliCmdType::Text) {
|
||||||
|
auto label{graphics::Image()};
|
||||||
|
label.createLabel(cmd.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -113,13 +131,22 @@ unsigned int PtouchPrint::getCompatiblePrinters() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
||||||
spdlog::set_level(lvl);
|
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||||
spdlog::debug("Starting ptprnt {}", mVersionString);
|
consoleSink->set_level(lvl);
|
||||||
|
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);
|
||||||
|
fileSink->set_pattern("%Y-%m-%d %H:%m:%S:%e [pid:%P tid:%t] [%^%l%$] %v (%@)");
|
||||||
|
std::vector<spdlog::sink_ptr> sinks{consoleSink, fileSink};
|
||||||
|
auto logger = std::make_shared<spdlog::logger>("default_logger", sinks.begin(), sinks.end());
|
||||||
|
logger->set_level(spdlog::level::trace);
|
||||||
|
spdlog::set_default_logger(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PtouchPrint::setupCliParser() {
|
void PtouchPrint::setupCliParser() {
|
||||||
auto printVersion = [this](std::size_t) {
|
auto printVersion = [this](std::size_t) {
|
||||||
std::cout << "ptprnt version: " << mVersionString << std::endl;
|
fmt::print("ptprnt version: {}\n", mVersionString);
|
||||||
};
|
};
|
||||||
|
|
||||||
// General options
|
// General options
|
||||||
|
@@ -52,6 +52,11 @@ bool Bitmap<T>::setPixels(const std::vector<T>& pixels) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
std::vector<T> Bitmap<T>::getPixelsCpy() {
|
||||||
|
return mPixels;
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::optional<std::vector<T>> Bitmap<T>::getLine(uint16_t line) {
|
std::optional<std::vector<T>> Bitmap<T>::getLine(uint16_t line) {
|
||||||
if (line >= mHeight) {
|
if (line >= mHeight) {
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ class Bitmap {
|
|||||||
uint16_t getWidth();
|
uint16_t getWidth();
|
||||||
uint16_t getHeight();
|
uint16_t getHeight();
|
||||||
bool setPixels(const std::vector<T>& pixels);
|
bool setPixels(const std::vector<T>& pixels);
|
||||||
|
std::vector<T> getPixelsCpy();
|
||||||
std::optional<std::vector<T>> getLine(uint16_t line);
|
std::optional<std::vector<T>> getLine(uint16_t line);
|
||||||
std::optional<std::vector<T>> getCol(uint16_t col);
|
std::optional<std::vector<T>> getCol(uint16_t col);
|
||||||
|
|
||||||
|
@@ -19,13 +19,23 @@
|
|||||||
|
|
||||||
#include "Image.hpp"
|
#include "Image.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <iostream> // remove me
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "cairo.h"
|
||||||
|
#include "pango/pango-context.h"
|
||||||
#include "pango/pango-font.h"
|
#include "pango/pango-font.h"
|
||||||
|
#include "pango/pango-layout.h"
|
||||||
|
#include "pango/pango-types.h"
|
||||||
|
#include "pango/pangocairo.h"
|
||||||
|
|
||||||
namespace ptprnt::graphics {
|
namespace ptprnt::graphics {
|
||||||
Image::Image() {
|
Image::Image() {
|
||||||
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();
|
||||||
pango_font_description_set_family(mFontDescription, "sans");
|
pango_font_description_set_family(mFontDescription, "sans");
|
||||||
@@ -42,7 +52,7 @@ Image::Image() {
|
|||||||
cairo_move_to(cr, 0.0, 94.0);
|
cairo_move_to(cr, 0.0, 94.0);
|
||||||
pango_cairo_show_layout_line(cr, pango_layout_get_line(mLayout, 0));
|
pango_cairo_show_layout_line(cr, pango_layout_get_line(mLayout, 0));
|
||||||
|
|
||||||
cairo_surface_write_to_png(mSurface, "hello.png");
|
cairo_surface_write_to_png(mSurface, "hello.png");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* Image::getRaw() {
|
uint8_t* Image::getRaw() {
|
||||||
@@ -50,8 +60,46 @@ uint8_t* Image::getRaw() {
|
|||||||
return cairo_image_surface_get_data(mSurface);
|
return cairo_image_surface_get_data(mSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t Image::getNumLines(std::string_view strv) {
|
||||||
|
return std::count(strv.begin(), strv.end(), '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
void Image::createLabel(const std::string& str) {
|
||||||
|
// create Pango layout first, to get the render dimensions
|
||||||
|
mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128);
|
||||||
|
cairo_t* cr = cairo_create(mSurface);
|
||||||
|
//auto pangoCtx{pango_context_new()};
|
||||||
|
auto pangoLyt{pango_cairo_create_layout(cr)};
|
||||||
|
auto pangoFontDesc{pango_font_description_from_string("FreeSans 32")};
|
||||||
|
|
||||||
|
pango_layout_set_single_paragraph_mode(pangoLyt, true);
|
||||||
|
pango_layout_set_height(pangoLyt, getNumLines(str) * -1);
|
||||||
|
pango_layout_set_alignment(pangoLyt, PANGO_ALIGN_CENTER);
|
||||||
|
pango_layout_set_font_description(pangoLyt, pangoFontDesc);
|
||||||
|
pango_layout_set_text(pangoLyt, str.c_str(), static_cast<int>(str.length()));
|
||||||
|
|
||||||
|
// Debug only
|
||||||
|
GError* gerr{nullptr};
|
||||||
|
pango_layout_write_to_file(pangoLyt, PANGO_LAYOUT_SERIALIZE_DEFAULT, "hello.txt", &gerr);
|
||||||
|
|
||||||
|
// create Cairo surface from p ango layout
|
||||||
|
int* width{};
|
||||||
|
int* height{}; // TODO: change me, fixed for current printer (128px)
|
||||||
|
PangoRectangle* rect{};
|
||||||
|
|
||||||
|
pango_cairo_show_layout(cr, pangoLyt);
|
||||||
|
pango_layout_get_extents(pangoLyt, rect, rect);
|
||||||
|
std::cerr << "Width is: " << rect->width << " height is:" << rect->height << std::endl;
|
||||||
|
|
||||||
|
//auto cairoSfc{cairo_image_surface_create(CAIRO_FORMAT_A8, *width, *height)};
|
||||||
|
|
||||||
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
// Debug only
|
||||||
|
cairo_surface_write_to_png(mSurface, "hellow.png");
|
||||||
|
}
|
||||||
|
|
||||||
Image::~Image() {
|
Image::~Image() {
|
||||||
g_object_unref(mLayout);
|
spdlog::info("Image dtor...");
|
||||||
pango_font_description_free(mFontDescription);
|
|
||||||
}
|
}
|
||||||
} // namespace ptprnt::graphics
|
} // namespace ptprnt::graphics
|
@@ -22,15 +22,30 @@
|
|||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace ptprnt::graphics {
|
namespace ptprnt::graphics {
|
||||||
|
|
||||||
|
constexpr const char* DEFAULT_FONT_FAMILY = "sans";
|
||||||
|
constexpr const uint8_t DEFAULT_FONT_SIZE = 32;
|
||||||
|
|
||||||
class Image {
|
class Image {
|
||||||
public:
|
public:
|
||||||
Image();
|
Image();
|
||||||
~Image();
|
~Image();
|
||||||
|
|
||||||
|
Image(const Image&) = delete;
|
||||||
|
Image& operator=(const Image&) = delete;
|
||||||
|
Image(Image&&) = delete;
|
||||||
|
Image& operator=(Image&&) = delete;
|
||||||
|
|
||||||
uint8_t* getRaw();
|
uint8_t* getRaw();
|
||||||
|
void createLabel(const std::string& labelText);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// methods
|
||||||
|
uint8_t getNumLines(std::string_view str);
|
||||||
|
// members
|
||||||
PangoLayout* mLayout;
|
PangoLayout* mLayout;
|
||||||
PangoFontDescription* mFontDescription;
|
PangoFontDescription* mFontDescription;
|
||||||
cairo_surface_t* mSurface;
|
cairo_surface_t* mSurface;
|
||||||
|
@@ -30,6 +30,7 @@ namespace ptprnt {
|
|||||||
|
|
||||||
class IPrinterDriver {
|
class IPrinterDriver {
|
||||||
public:
|
public:
|
||||||
|
virtual ~IPrinterDriver() = default;
|
||||||
virtual const std::string_view getDriverName() = 0;
|
virtual const std::string_view getDriverName() = 0;
|
||||||
virtual const std::string_view getName() = 0;
|
virtual const std::string_view getName() = 0;
|
||||||
virtual const std::string_view getVersion() = 0;
|
virtual const std::string_view getVersion() = 0;
|
||||||
|
@@ -29,8 +29,8 @@
|
|||||||
namespace libusbwrap {
|
namespace libusbwrap {
|
||||||
class UsbDevice : public IUsbDevice {
|
class UsbDevice : public IUsbDevice {
|
||||||
public:
|
public:
|
||||||
UsbDevice(libusb_context* ctx, libusb_device* dev);
|
explicit UsbDevice(libusb_context* ctx, libusb_device* dev);
|
||||||
~UsbDevice();
|
~UsbDevice() override;
|
||||||
|
|
||||||
// delete copy ctor and assignment
|
// delete copy ctor and assignment
|
||||||
UsbDevice(const UsbDevice&) = delete;
|
UsbDevice(const UsbDevice&) = delete;
|
||||||
|
@@ -24,6 +24,7 @@ enum class Speed {
|
|||||||
|
|
||||||
class IUsbDevice {
|
class IUsbDevice {
|
||||||
public:
|
public:
|
||||||
|
virtual ~IUsbDevice() = default;
|
||||||
virtual bool open() = 0;
|
virtual bool open() = 0;
|
||||||
virtual void close() = 0;
|
virtual void close() = 0;
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
namespace libusbwrap {
|
namespace libusbwrap {
|
||||||
class IUsbDeviceFactory {
|
class IUsbDeviceFactory {
|
||||||
public:
|
public:
|
||||||
|
virtual ~IUsbDeviceFactory() = default;
|
||||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() = 0;
|
virtual std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() = 0;
|
||||||
virtual std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
virtual std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
||||||
};
|
};
|
||||||
|
@@ -16,10 +16,6 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <spdlog/common.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
|
|
||||||
#include "PtouchPrint.hpp"
|
#include "PtouchPrint.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
24
src/meson.build
Normal file
24
src/meson.build
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
ptprnt_hpps = files (
|
||||||
|
'libusbwrap/interface/IUsbDeviceFactory.hpp',
|
||||||
|
'libusbwrap/interface/IUsbDevice.hpp',
|
||||||
|
'libusbwrap/UsbDeviceFactory.hpp',
|
||||||
|
'libusbwrap/LibUsbTypes.hpp',
|
||||||
|
'libusbwrap/UsbDevice.hpp',
|
||||||
|
'interface/IPrinterDriver.hpp',
|
||||||
|
'interface/IPrinterTypes.hpp',
|
||||||
|
'P700Printer.hpp',
|
||||||
|
'PtouchPrint.hpp',
|
||||||
|
'graphics/Bitmap.hpp',
|
||||||
|
'graphics/Image.hpp',
|
||||||
|
'graphics/Monochrome.hpp'
|
||||||
|
)
|
||||||
|
|
||||||
|
ptprnt_srcs = files (
|
||||||
|
'PtouchPrint.cpp',
|
||||||
|
'P700Printer.cpp',
|
||||||
|
'graphics/Image.cpp',
|
||||||
|
'graphics/Bitmap.cpp',
|
||||||
|
'graphics/Monochrome.cpp',
|
||||||
|
'libusbwrap/UsbDeviceFactory.cpp',
|
||||||
|
'libusbwrap/UsbDevice.cpp',
|
||||||
|
)
|
@@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
TEST(basic_test, Bitmap_createBitmapWithCertainSize_yieldsSpecifiedSize) {
|
TEST(basic_test, Bitmap_createBitmapWithCertainSize_yieldsSpecifiedSize) {
|
||||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||||
@@ -64,3 +66,36 @@ TEST(basic_test, Bitmap_getBitmapColInsideOfImage_yieldsValidColSize) {
|
|||||||
auto colSize = col->size();
|
auto colSize = col->size();
|
||||||
ASSERT_EQ(8, colSize);
|
ASSERT_EQ(8, colSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(basic_test, Bitmap_setPixels_setsGivenPixels) {
|
||||||
|
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||||
|
std::vector<uint8_t> pix(16 * 8);
|
||||||
|
|
||||||
|
bm.setPixels(pix);
|
||||||
|
auto pixCpy = bm.getPixelsCpy();
|
||||||
|
|
||||||
|
ASSERT_EQ(pix, pixCpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(basic_test, Bitmap_setPixels_isSuccessfulWithValidPixels) {
|
||||||
|
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||||
|
std::vector<uint8_t> pix(16 * 8);
|
||||||
|
|
||||||
|
ASSERT_TRUE(bm.setPixels(pix));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(basic_test, Bitmap_setPixels_yieldsSamePixelsBack) {
|
||||||
|
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||||
|
std::vector<uint8_t> pix(16 * 8);
|
||||||
|
|
||||||
|
bm.setPixels(pix);
|
||||||
|
auto pixCpy = bm.getPixelsCpy();
|
||||||
|
ASSERT_EQ(pix, pixCpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(basic_test, Bitmap_setPixelsWithWrongSize_isFailing) {
|
||||||
|
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(5, 8);
|
||||||
|
std::vector<uint8_t> pix(16 * 8);
|
||||||
|
|
||||||
|
ASSERT_FALSE(bm.setPixels(pix));
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
tests = [['bitmap_test', 'bitmap_test_exe', ['bitmap_test/bitmap_test.cpp']],
|
tests = [['bitmap_test', 'bitmap_test_exe', ptprnt_srcs + ['bitmap_test/bitmap_test.cpp']],
|
||||||
['image_test', 'image_test_exe', ['image_test/image_test.cpp']],
|
['image_test', 'image_test_exe', ptprnt_srcs +['image_test/image_test.cpp']],
|
||||||
['monochrome_test', 'monochrome_test_exe', ['monochrome_test/monochrome_test.cpp']]
|
['monochrome_test', 'monochrome_test_exe', ptprnt_srcs +['monochrome_test/monochrome_test.cpp']]
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach test : tests
|
foreach test : tests
|
||||||
@@ -8,8 +8,7 @@ foreach test : tests
|
|||||||
executable(test.get(1),
|
executable(test.get(1),
|
||||||
sources: test.get(2),
|
sources: test.get(2),
|
||||||
include_directories: incdir,
|
include_directories: incdir,
|
||||||
link_with:[ptprnt_lib],
|
dependencies: [gtest_dep, usb_dep, log_dep, pangocairo_dep, cli11_dep]
|
||||||
dependencies: [gtest_dep, pangocairo_dep]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
endforeach
|
endforeach
|
Reference in New Issue
Block a user