3 Commits

Author SHA1 Message Date
f8a008a105 Reorganize folders, interface for both cli parser and core module
Some checks failed
Build ptprnt / build (push) Failing after 41s
2025-10-13 21:00:16 +02:00
81b0f25f32 Fix multiple lines and printer selection 2025-10-13 20:35:58 +02:00
69810e1c5c Refactor cli setup and printer selection logic into separate classes
All checks were successful
Build ptprnt / build (push) Successful in 3m49s
2025-10-13 20:29:14 +02:00
28 changed files with 119 additions and 110 deletions

View File

@@ -88,7 +88,6 @@
},
"clangd.onConfigChanged": "restart",
"cSpell.words": [
"fakelabel",
"fontsize",
"halign",
"libusb",

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
Copyright (C) 2024-2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
Copyright (C) 2024-2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -23,10 +23,10 @@
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include "PrinterDriverFactory.hpp"
#include "cli/CliParser.hpp"
#include "cli/interface/ICliParser.hpp"
#include "constants.hpp"
#include "core/PrinterDriverFactory.hpp"
#include "core/PrinterService.hpp"
#include "core/interface/IPrinterService.hpp"
#include "graphics/LabelBuilder.hpp"

View File

@@ -21,7 +21,7 @@
#include <spdlog/spdlog.h>
#include "core/PrinterDriverFactory.hpp"
#include "PrinterDriverFactory.hpp"
namespace ptprnt::core {
@@ -38,7 +38,7 @@ bool PrinterService::initialize() {
std::vector<std::shared_ptr<IPrinterDriver>> PrinterService::detectPrinters() {
spdlog::debug("Detecting printers...");
auto usbDevs = mUsbDeviceFactory.findAllDevices();
auto usbDevs = mUsbDeviceFactory.findAllDevices();
auto driverFactory = std::make_unique<PrinterDriverFactory>();
mDetectedPrinters.clear();
@@ -57,7 +57,7 @@ std::shared_ptr<IPrinterDriver> PrinterService::selectPrinter(const std::string&
// If a specific printer is requested by name (not "auto"), try to create it directly
if (printerName != "auto") {
auto driverFactory = std::make_unique<PrinterDriverFactory>();
auto printer = driverFactory->createByName(printerName);
auto printer = driverFactory->createByName(printerName);
if (printer) {
mCurrentPrinter = printer;
spdlog::info("Using explicitly selected printer: {}", printerName);

View File

@@ -23,9 +23,9 @@
#include <string>
#include <vector>
#include "../printers/interface/IPrinterDriver.hpp"
#include "interface/IPrinterService.hpp"
#include "libusbwrap/UsbDeviceFactory.hpp"
#include "printers/interface/IPrinterDriver.hpp"
#include "../libusbwrap/UsbDeviceFactory.hpp"
namespace ptprnt::core {

View File

@@ -23,8 +23,8 @@
#include <string>
#include <vector>
#include "graphics/interface/ILabel.hpp"
#include "printers/interface/IPrinterDriver.hpp"
#include "../../printers/interface/IPrinterDriver.hpp"
#include "../../graphics/interface/ILabel.hpp"
namespace ptprnt::core {

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
Copyright (C) 2023-2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
Copyright (C) 2023-2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
Copyright (C) 2024-2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2023-2025 Moritz Martinius
Copyright (C) 2023-2024 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2023-2025 Moritz Martinius
Copyright (C) 2023-2024 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2023-2025 Moritz Martinius
Copyright (C) 2023-2024 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2023-2025 Moritz Martinius
Copyright (C) 2023 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2023-2025 Moritz Martinius
Copyright (C) 2023-2024 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2023-2025 Moritz Martinius
Copyright (C) 2023 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2022-2025 Moritz Martinius
Copyright (C) 2022-2023 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,34 +1,34 @@
ptprnt_hpps = files(
'cli/CliParser.hpp',
'core/PrinterDriverFactory.hpp',
'core/PrinterService.hpp',
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',
'printers/P700Printer.hpp',
'printers/FakePrinter.hpp',
'PtouchPrint.hpp',
'PrinterDriverFactory.hpp',
'graphics/Bitmap.hpp',
'graphics/Label.hpp',
'graphics/LabelBuilder.hpp',
'graphics/Monochrome.hpp',
'libusbwrap/LibUsbTypes.hpp',
'libusbwrap/UsbDevice.hpp',
'libusbwrap/UsbDeviceFactory.hpp',
'libusbwrap/interface/IUsbDevice.hpp',
'libusbwrap/interface/IUsbDeviceFactory.hpp',
'printers/FakePrinter.hpp',
'printers/P700Printer.hpp',
'printers/interface/IPrinterDriver.hpp',
'printers/interface/IPrinterTypes.hpp',
'PtouchPrint.hpp',
'cli/CliParser.hpp',
'core/PrinterService.hpp'
)
ptprnt_srcs = files(
'cli/CliParser.cpp',
'core/PrinterDriverFactory.cpp',
'core/PrinterService.cpp',
'graphics/Bitmap.cpp',
ptprnt_srcs = files (
'PtouchPrint.cpp',
'PrinterDriverFactory.cpp',
'printers/P700Printer.cpp',
'printers/FakePrinter.cpp',
'graphics/Label.cpp',
'graphics/LabelBuilder.cpp',
'graphics/Bitmap.cpp',
'graphics/Monochrome.cpp',
'libusbwrap/UsbDevice.cpp',
'libusbwrap/UsbDeviceFactory.cpp',
'printers/FakePrinter.cpp',
'printers/P700Printer.cpp',
'PtouchPrint.cpp',
'libusbwrap/UsbDevice.cpp',
'cli/CliParser.cpp',
'core/PrinterService.cpp'
)

View File

@@ -19,25 +19,27 @@
#include "FakePrinter.hpp"
#include <cairo.h>
#include <spdlog/spdlog.h>
#include <cairo.h>
#include <chrono>
#include <cstdint>
#include <iomanip>
#include <sstream>
#include <stdexcept>
#include <vector>
#include <chrono>
#include <iomanip>
#include <sstream>
#include "graphics/Monochrome.hpp"
#include "../graphics/Monochrome.hpp"
namespace ptprnt::printer {
const PrinterInfo FakePrinter::mInfo = {.driverName = "FakePrinter",
.name = "Virtual Test Printer",
.version = "v1.0",
.usbId{0x0000, 0x0000}, // No USB ID - virtual printer created explicitly
.pixelLines = 128};
const PrinterInfo FakePrinter::mInfo = {
.driverName = "FakePrinter",
.name = "Virtual Test Printer",
.version = "v1.0",
.usbId{0x0000, 0x0000}, // No USB ID - virtual printer created explicitly
.pixelLines = 128
};
const std::string_view FakePrinter::getDriverName() {
return mInfo.driverName;
@@ -78,8 +80,8 @@ bool FakePrinter::detachUsbDevice() {
bool FakePrinter::printBitmap(const graphics::Bitmap<graphics::ALPHA8>& bitmap) {
// Convert bitmap to MonochromeData and delegate
auto pixels = bitmap.getPixelsCpy();
auto mono = graphics::Monochrome(pixels, bitmap.getWidth(), bitmap.getHeight());
auto pixels = bitmap.getPixelsCpy();
auto mono = graphics::Monochrome(pixels, bitmap.getWidth(), bitmap.getHeight());
auto monoData = mono.get();
return printMonochromeData(monoData);
@@ -90,10 +92,10 @@ bool FakePrinter::printMonochromeData(const graphics::MonochromeData& data) {
// Simulate the printing process by reconstructing the bitmap
auto printed = simulatePrinting(data);
mLastPrint = std::make_unique<graphics::Bitmap<graphics::ALPHA8>>(std::move(printed));
mLastPrint = std::make_unique<graphics::Bitmap<graphics::ALPHA8>>(std::move(printed));
spdlog::info("FakePrinter: Successfully 'printed' label ({}x{} pixels)", mLastPrint->getWidth(),
mLastPrint->getHeight());
spdlog::info("FakePrinter: Successfully 'printed' label ({}x{} pixels)",
mLastPrint->getWidth(), mLastPrint->getHeight());
// Save to timestamped PNG file
std::string filename = generateTimestampedFilename();
@@ -118,8 +120,7 @@ bool FakePrinter::printLabel(const std::unique_ptr<graphics::ILabel> label) {
// Transform to portrait orientation for printing
monoData.transformTo(graphics::Orientation::PORTRAIT);
spdlog::debug("FakePrinter: Label surface is {}x{}, transformed to portrait", label->getWidth(),
label->getHeight());
spdlog::debug("FakePrinter: Label surface is {}x{}, transformed to portrait", label->getWidth(), label->getHeight());
return printMonochromeData(monoData);
}
@@ -159,7 +160,7 @@ graphics::Bitmap<graphics::ALPHA8> FakePrinter::simulatePrinting(const graphics:
// Now "print" this column by unpacking the bytes back to pixels
for (size_t byteIdx = 0; byteIdx < columnBytes.size(); byteIdx++) {
uint8_t byte = columnBytes[byteIdx];
uint8_t byte = columnBytes[byteIdx];
uint32_t baseRow = byteIdx * 8;
for (int bit = 0; bit < 8 && (baseRow + bit) < data.height; bit++) {
@@ -167,7 +168,7 @@ graphics::Bitmap<graphics::ALPHA8> FakePrinter::simulatePrinting(const graphics:
uint32_t row = baseRow + bit;
// Write to output bitmap
size_t pixelIdx = row * data.width + col;
size_t pixelIdx = row * data.width + col;
pixels[pixelIdx] = pixelOn ? 255 : 0; // 255 = black, 0 = white
}
}
@@ -176,8 +177,8 @@ graphics::Bitmap<graphics::ALPHA8> FakePrinter::simulatePrinting(const graphics:
// Set the pixels in the result bitmap
result.setPixels(pixels);
spdlog::debug("FakePrinter: Simulation complete, reconstructed {}x{} bitmap", result.getWidth(),
result.getHeight());
spdlog::debug("FakePrinter: Simulation complete, reconstructed {}x{} bitmap",
result.getWidth(), result.getHeight());
return result;
}
@@ -200,8 +201,8 @@ bool FakePrinter::saveLastPrintToPng(const std::string& filename) const {
bool FakePrinter::saveBitmapToPng(const graphics::Bitmap<graphics::ALPHA8>& bitmap, const std::string& filename) const {
// Create Cairo surface from bitmap data
auto pixels = bitmap.getPixelsCpy();
uint16_t width = bitmap.getWidth();
auto pixels = bitmap.getPixelsCpy();
uint16_t width = bitmap.getWidth();
uint16_t height = bitmap.getHeight();
// Cairo expects ARGB32 format, but we have ALPHA8
@@ -216,9 +217,14 @@ bool FakePrinter::saveBitmapToPng(const graphics::Bitmap<graphics::ALPHA8>& bitm
}
// Create Cairo surface
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
cairo_surface_t* surface = cairo_image_surface_create_for_data(reinterpret_cast<unsigned char*>(argbPixels.data()),
CAIRO_FORMAT_ARGB32, width, height, stride);
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
cairo_surface_t* surface = cairo_image_surface_create_for_data(
reinterpret_cast<unsigned char*>(argbPixels.data()),
CAIRO_FORMAT_ARGB32,
width,
height,
stride
);
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
spdlog::error("FakePrinter: Failed to create Cairo surface: {}",
@@ -242,12 +248,14 @@ bool FakePrinter::saveBitmapToPng(const graphics::Bitmap<graphics::ALPHA8>& bitm
std::string FakePrinter::generateTimestampedFilename() const {
// Get current time
auto now = std::chrono::system_clock::now();
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
// Format: fakelabel_YYYYMMDD_HHMMSS.png
std::stringstream ss;
ss << "fakelabel_" << std::put_time(std::localtime(&time), "%Y%m%d_%H%M%S") << ".png";
ss << "fakelabel_"
<< std::put_time(std::localtime(&time), "%Y%m%d_%H%M%S")
<< ".png";
return ss.str();
}

View File

@@ -19,15 +19,15 @@
#pragma once
#include <cstdint>
#include <memory>
#include <vector>
#include <cstdint>
#include "graphics/Bitmap.hpp"
#include "interface/IPrinterDriver.hpp"
#include "interface/IPrinterTypes.hpp"
#include "libusbwrap/LibUsbTypes.hpp"
#include "libusbwrap/interface/IUsbDevice.hpp"
#include "../libusbwrap/LibUsbTypes.hpp"
#include "../libusbwrap/interface/IUsbDevice.hpp"
#include "../graphics/Bitmap.hpp"
namespace ptprnt::printer {
@@ -40,7 +40,7 @@ namespace ptprnt::printer {
*/
class FakePrinter : public ::ptprnt::IPrinterDriver {
public:
FakePrinter() = default;
FakePrinter() = default;
~FakePrinter() override = default;
FakePrinter(const FakePrinter&) = delete;

View File

@@ -28,9 +28,9 @@
#include <thread>
#include <vector>
#include "graphics/Bitmap.hpp"
#include "graphics/Monochrome.hpp"
#include "libusbwrap/LibUsbTypes.hpp"
#include "../graphics/Bitmap.hpp"
#include "../graphics/Monochrome.hpp"
#include "../libusbwrap/LibUsbTypes.hpp"
#include "spdlog/fmt/bin_to_hex.h"
namespace ptprnt::printer {

View File

@@ -27,16 +27,16 @@
#include "interface/IPrinterDriver.hpp"
#include "interface/IPrinterTypes.hpp"
#include "libusbwrap/LibUsbTypes.hpp"
#include "libusbwrap/interface/IUsbDevice.hpp"
#include "../libusbwrap/LibUsbTypes.hpp"
#include "../libusbwrap/interface/IUsbDevice.hpp"
namespace ptprnt::printer {
namespace p700::commands {
const cmd_T INITIALIZE{0x1b, 0x40}; // ESC @ - Initialize
const cmd_T GET_STATUS{0x1b, 0x69, 0x53}; // ESC i S - Status query
const cmd_T PRINT_MODE{0x4d, 0x02}; // M 0x02 - Print mode
const cmd_T AUTO_STATUS{0x1b, 0x69, 0x61, 0x01}; // ESC i a - Auto status
const cmd_T MODE_SETTING{0x1b, 0x69, 0x4d, 0x40}; // ESC i M @ - Advanced mode
const cmd_T INITIALIZE{0x1b, 0x40}; // ESC @ - Initialize
const cmd_T GET_STATUS{0x1b, 0x69, 0x53}; // ESC i S - Status query
const cmd_T PRINT_MODE{0x4d, 0x02}; // M 0x02 - Print mode
const cmd_T AUTO_STATUS{0x1b, 0x69, 0x61, 0x01}; // ESC i a - Auto status
const cmd_T MODE_SETTING{0x1b, 0x69, 0x4d, 0x40}; // ESC i M @ - Advanced mode
const cmd_T RASTER_START{0x1b, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const cmd_T INFO{0x1b, 0x69, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const cmd_T PACKBITSON{0x02};

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
Copyright (C) 2023-2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,11 +22,11 @@
#include <memory>
#include <string_view>
#include "../../graphics/Bitmap.hpp"
#include "../../graphics/Monochrome.hpp"
#include "../../graphics/interface/ILabel.hpp"
#include "../../libusbwrap/interface/IUsbDevice.hpp"
#include "IPrinterTypes.hpp"
#include "graphics/Bitmap.hpp"
#include "graphics/Monochrome.hpp"
#include "graphics/interface/ILabel.hpp"
#include "libusbwrap/interface/IUsbDevice.hpp"
namespace ptprnt {
class IPrinterDriver {

View File

@@ -1,6 +1,6 @@
/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
Copyright (C) 2023-2024 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
#pragma once
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>

0
src/ptprnt.log Normal file
View File

View File

@@ -1,10 +1,9 @@
[wrap-file]
directory = CLI11-2.5.0
source_url = https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.5.0.tar.gz
source_filename = CLI11-2.5.0.tar.gz
source_hash = 17e02b4cddc2fa348e5dbdbb582c59a3486fa2b2433e70a0c3bacb871334fd55
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/cli11_2.5.0-2/CLI11-2.5.0.tar.gz
wrapdb_version = 2.5.0-2
directory = CLI11-2.3.2
source_url = https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.3.2.tar.gz
source_filename = CLI11-2.3.2.tar.gz
source_hash = aac0ab42108131ac5d3344a9db0fdf25c4db652296641955720a4fbe52334e22
wrapdb_version = 2.3.2-1
[provide]
dependency_names = CLI11
cli11 = CLI11_dep

View File

@@ -1,13 +1,13 @@
[wrap-file]
directory = googletest-1.17.0
source_url = https://github.com/google/googletest/archive/refs/tags/v1.17.0.tar.gz
source_filename = googletest-1.17.0.tar.gz
source_hash = 65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c
patch_filename = gtest_1.17.0-4_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.17.0-4/get_patch
patch_hash = 3abf7662d09db706453a5b064a1e914678c74b9d9b0b19382747ca561d0d8750
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.17.0-4/googletest-1.17.0.tar.gz
wrapdb_version = 1.17.0-4
directory = googletest-1.14.0
source_url = https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
source_filename = gtest-1.14.0.tar.gz
source_hash = 8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7
patch_filename = gtest_1.14.0-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.14.0-1/get_patch
patch_hash = 2e693c7d3f9370a7aa6dac802bada0874d3198ad4cfdf75647b818f691182b50
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.14.0-1/gtest-1.14.0.tar.gz
wrapdb_version = 1.14.0-1
[provide]
gtest = gtest_dep

View File

@@ -35,4 +35,6 @@ foreach test : tests
],
),
)
endforeach
endforeach