30 Commits

Author SHA1 Message Date
7437d79393 Update copyright
All checks were successful
Build ptprnt / build (push) Successful in 3m41s
2025-10-12 22:04:29 +02:00
5f673b7d57 Printing not flipped
All checks were successful
Build ptprnt / build (push) Successful in 3m37s
2025-10-12 21:46:24 +02:00
58287202d8 printing but flipped 2025-10-12 21:20:17 +02:00
ae22feed4f Add meson options 2025-10-12 12:56:29 +02:00
652e687fb0 Add a trace mode for usb tracing 2025-10-12 12:56:09 +02:00
bf7ff27b8d cleanup
All checks were successful
Build ptprnt / build (push) Successful in 3m25s
2025-10-11 18:37:27 +02:00
8658e5c9fd Fix merge
All checks were successful
Build ptprnt / build (push) Successful in 3m48s
2025-10-11 17:38:47 +02:00
99b355b033 Merge branch 'master' into generate-text-part-one 2025-10-11 17:34:31 +02:00
6a593f2a40 Remove unused interface methods
All checks were successful
Build ptprnt / build (push) Successful in 3m44s
2025-10-11 17:30:50 +02:00
59b3b34edc Fix the label corruption issue
All checks were successful
Build ptprnt / build (push) Successful in 4m43s
2025-10-11 17:04:55 +02:00
6e3a5bd12f Add fake printer for testing 2025-10-11 13:00:26 +02:00
0b8ff28a60 Start refactoring printers into own directory 2025-10-11 12:29:43 +02:00
3dc5da6fc8 Fix Monochrome class with new data structure, unit tests. There is work to be done still
All checks were successful
Build ptprnt / build (push) Successful in 3m51s
2025-09-11 10:02:43 +02:00
5132eab6fa Merge branch 'master' into generate-text-part-one
All checks were successful
Build ptprnt / build (push) Successful in 2m34s
2024-05-01 11:27:54 +02:00
77c6b7bc7b Fix for the old dependency code in the CI
All checks were successful
Build ptprnt / build (push) Successful in 2m31s
2024-04-28 20:49:10 +02:00
f702ec5473 Small Todos for the next session, some clean up
Some checks failed
Build ptprnt / build (push) Failing after 32s
2024-04-28 20:44:13 +02:00
59ef4189c4 Implement Label printing interface for PrinterDriver
Some checks failed
Build ptprnt / build (push) Failing after 32s
2024-04-28 20:02:07 +02:00
bb7ab6239d Implement basic layouting
Some checks failed
Build ptprnt / build (push) Failing after 37s
2024-04-28 17:38:56 +02:00
37ee7c10f1 c++ standard needs to be c++2a as c++20 is not possible with CI
All checks were successful
Build ptprnt / build (push) Successful in 1m23s
2024-04-20 14:03:51 +02:00
d98399949c Fix printer info issue
Some checks failed
Build ptprnt / build (push) Failing after 18s
2024-04-20 14:01:52 +02:00
a47a3189d3 Fix issues after rebase 2024-04-20 13:53:12 +02:00
6857de7b1f commands restructured to be const vectors 2024-04-20 13:39:28 +02:00
5a38600e2a Got it almost working... 2024-04-20 13:36:32 +02:00
1163ae5745 Removing files that shouldn't have been staged 2024-04-20 13:34:41 +02:00
09a2e621d6 Some side tracking fixing undefined behaviour and memory vulnurabilities 2024-04-20 13:34:11 +02:00
28308dccad Rename Image class to Label 2024-04-20 13:33:45 +02:00
5f5c0f0f97 Remove debug output as build pipeline does not have pango >=v1.5.0 2024-04-20 13:28:00 +02:00
4a59b50839 Fix typo 2024-04-20 13:28:00 +02:00
79477baecd Width is no automatically chosen based on image width 2024-04-20 13:28:00 +02:00
cf8492a714 A somewhat working state, but still struggeling with pangocairo 2024-04-20 13:28:00 +02:00
5 changed files with 18 additions and 263 deletions

View File

@@ -37,7 +37,7 @@
#include "CLI/Option.hpp" #include "CLI/Option.hpp"
#include "PrinterDriverFactory.hpp" #include "PrinterDriverFactory.hpp"
#include "graphics/LabelBuilder.hpp" #include "graphics/Label.hpp"
#include "graphics/interface/ILabel.hpp" #include "graphics/interface/ILabel.hpp"
#include "libusbwrap/UsbDeviceFactory.hpp" #include "libusbwrap/UsbDeviceFactory.hpp"
@@ -162,21 +162,25 @@ int PtouchPrint::run() {
return 0; return 0;
} }
// Use LabelBuilder to construct the label auto label = std::make_unique<graphics::Label>(printer->getPrinterInfo().pixelLines);
graphics::LabelBuilder labelBuilder(printer->getPrinterInfo().pixelLines); std::string labelText{};
// TODO: refactor
for (const auto& [cmd, value] : mCommands) { for (const auto& [cmd, value] : mCommands) {
switch (cmd) { switch (cmd) {
case CliCmdType::Text: case CliCmdType::Text:
labelBuilder.addText(value); if (labelText.empty()) {
labelText = value;
} else {
labelText = labelText + '\n' + value;
}
break; break;
case CliCmdType::Font: case CliCmdType::Font:
spdlog::debug("Setting font to {}", value); spdlog::debug("Setting font to {}", value);
labelBuilder.setFontFamily(value); label->setFontFamily(value);
break; break;
case CliCmdType::FontSize: case CliCmdType::FontSize:
spdlog::debug("Setting font size to {}", std::stod(value)); spdlog::debug("Setting font size to {}", std::stod(value));
labelBuilder.setFontSize(std::stod(value)); label->setFontSize(std::stod(value));
break; break;
case CliCmdType::HAlign: case CliCmdType::HAlign:
spdlog::debug("Setting text horizontal alignment to {}", value); spdlog::debug("Setting text horizontal alignment to {}", value);
@@ -184,9 +188,9 @@ int PtouchPrint::run() {
auto hPos = HALignPositionMap.find(value); auto hPos = HALignPositionMap.find(value);
if (hPos == HALignPositionMap.end()) { if (hPos == HALignPositionMap.end()) {
spdlog::warn("Invalid horizontal alignment specified!"); spdlog::warn("Invalid horizontal alignment specified!");
labelBuilder.setHAlign(HAlignPosition::UNKNOWN); label->setHAlign(HAlignPosition::UNKNOWN);
} else { } else {
labelBuilder.setHAlign(hPos->second); label->setHAlign(hPos->second);
} }
} }
break; break;
@@ -195,10 +199,10 @@ int PtouchPrint::run() {
{ {
auto vPos = VALignPositionMap.find(value); auto vPos = VALignPositionMap.find(value);
if (vPos == VALignPositionMap.end()) { if (vPos == VALignPositionMap.end()) {
spdlog::warn("Invalid vertical alignment specified!"); spdlog::warn("Invalid verical alignment specified!");
labelBuilder.setVAlign(VAlignPosition::UNKNOWN); label->setVAlign(VAlignPosition::UNKNOWN);
} else { } else {
labelBuilder.setVAlign(vPos->second); label->setVAlign(vPos->second);
} }
} }
break; break;
@@ -209,8 +213,8 @@ int PtouchPrint::run() {
break; break;
} }
} }
label->create(labelText);
auto label = labelBuilder.build(); label->writeToPng("./testlabel.png");
if (!printer->printLabel(std::move(label))) { if (!printer->printLabel(std::move(label))) {
spdlog::error("An error occured while printing"); spdlog::error("An error occured while printing");
return -1; return -1;

View File

@@ -1,95 +0,0 @@
/*
ptrnt - print labels on linux
Copyright (C) 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "LabelBuilder.hpp"
#include <spdlog/spdlog.h>
#include "Label.hpp"
namespace ptprnt::graphics {
LabelBuilder::LabelBuilder(int printerHeight) : mPrinterHeight(printerHeight) {
reset();
}
ILabelBuilder& LabelBuilder::addText(const std::string& text) {
if (!text.empty()) {
if (!mAccumulatedText.empty()) {
// Add a newline if the label already has some text accumulated
mAccumulatedText += '\n';
}
mAccumulatedText += text;
spdlog::debug("LabelBuilder: Added text '{}', total length: {}", text, mAccumulatedText.length());
}
return *this;
}
ILabelBuilder& LabelBuilder::setFontFamily(const std::string& fontFamily) {
mCurrentFontFamily = fontFamily;
spdlog::debug("LabelBuilder: Set font family to '{}'", fontFamily);
return *this;
}
ILabelBuilder& LabelBuilder::setFontSize(double fontSize) {
mCurrentFontSize = fontSize;
spdlog::debug("LabelBuilder: Set font size to {}", fontSize);
return *this;
}
ILabelBuilder& LabelBuilder::setHAlign(HAlignPosition hAlign) {
mCurrentHAlign = hAlign;
spdlog::debug("LabelBuilder: Set horizontal alignment to {}", static_cast<int>(hAlign));
return *this;
}
ILabelBuilder& LabelBuilder::setVAlign(VAlignPosition vAlign) {
mCurrentVAlign = vAlign;
spdlog::debug("LabelBuilder: Set vertical alignment to {}", static_cast<int>(vAlign));
return *this;
}
std::unique_ptr<ILabel> LabelBuilder::build() {
spdlog::debug("LabelBuilder: Building label with text: '{}'", mAccumulatedText);
auto label = std::make_unique<Label>(mPrinterHeight);
// Apply current formatting settings
label->setFontFamily(mCurrentFontFamily);
label->setFontSize(mCurrentFontSize);
label->setHAlign(mCurrentHAlign);
label->setVAlign(mCurrentVAlign);
// Create the label with accumulated text
label->create(mAccumulatedText);
return label;
}
ILabelBuilder& LabelBuilder::reset() {
mAccumulatedText.clear();
mCurrentFontFamily = DEFAULT_FONT_FAMILY;
mCurrentFontSize = DEFAULT_FONT_SIZE;
mCurrentHAlign = HAlignPosition::LEFT;
mCurrentVAlign = VAlignPosition::MIDDLE;
spdlog::debug("LabelBuilder: Reset to default state");
return *this;
}
} // namespace ptprnt::graphics

View File

@@ -1,64 +0,0 @@
/*
ptrnt - print labels on linux
Copyright (C) 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "interface/ILabel.hpp"
#include "interface/ILabelBuilder.hpp"
namespace ptprnt::graphics {
/**
* @brief Concrete implementation of ILabelBuilder
*
* Builds labels by accumulating text segments with formatting options,
* then creates a Label instance with all the collected content.
*/
class LabelBuilder : public ILabelBuilder {
public:
/**
* @brief Construct a LabelBuilder for a specific printer height
* @param printerHeight Height of the printer in pixels (tape width)
*/
explicit LabelBuilder(int printerHeight);
~LabelBuilder() override = default;
ILabelBuilder& addText(const std::string& text) override;
ILabelBuilder& setFontFamily(const std::string& fontFamily) override;
ILabelBuilder& setFontSize(double fontSize) override;
ILabelBuilder& setHAlign(HAlignPosition hAlign) override;
ILabelBuilder& setVAlign(VAlignPosition vAlign) override;
std::unique_ptr<ILabel> build() override;
ILabelBuilder& reset() override;
private:
int mPrinterHeight;
std::string mAccumulatedText;
std::string mCurrentFontFamily{DEFAULT_FONT_FAMILY};
double mCurrentFontSize{DEFAULT_FONT_SIZE};
HAlignPosition mCurrentHAlign{HAlignPosition::LEFT};
VAlignPosition mCurrentVAlign{VAlignPosition::MIDDLE};
};
} // namespace ptprnt::graphics

View File

@@ -1,88 +0,0 @@
/*
ptrnt - print labels on linux
Copyright (C) 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <string>
#include "ILabel.hpp"
namespace ptprnt::graphics {
/**
* @brief Builder interface for creating labels with text and formatting options
*
* The LabelBuilder provides a fluent API for constructing labels with various
* text elements, fonts, sizes, and alignment options. It separates the construction
* logic from the label rendering logic, making it easier to test and maintain.
*/
class ILabelBuilder {
public:
virtual ~ILabelBuilder() = default;
/**
* @brief Add text to the label with current formatting settings
* @param text The text to add
* @return Reference to this builder for method chaining
*/
virtual ILabelBuilder& addText(const std::string& text) = 0;
/**
* @brief Set the font family for subsequent text additions
* @param fontFamily Font family name (e.g., "sans", "serif", "monospace")
* @return Reference to this builder for method chaining
*/
virtual ILabelBuilder& setFontFamily(const std::string& fontFamily) = 0;
/**
* @brief Set the font size for subsequent text additions
* @param fontSize Font size in points
* @return Reference to this builder for method chaining
*/
virtual ILabelBuilder& setFontSize(double fontSize) = 0;
/**
* @brief Set horizontal alignment for subsequent text additions
* @param hAlign Horizontal alignment position
* @return Reference to this builder for method chaining
*/
virtual ILabelBuilder& setHAlign(HAlignPosition hAlign) = 0;
/**
* @brief Set vertical alignment for subsequent text additions
* @param vAlign Vertical alignment position
* @return Reference to this builder for method chaining
*/
virtual ILabelBuilder& setVAlign(VAlignPosition vAlign) = 0;
/**
* @brief Build and return the label with all added content
* @return Unique pointer to the constructed label
*/
virtual std::unique_ptr<ILabel> build() = 0;
/**
* @brief Reset the builder to initial state
* @return Reference to this builder for method chaining
*/
virtual ILabelBuilder& reset() = 0;
};
} // namespace ptprnt::graphics

View File

@@ -12,7 +12,6 @@ ptprnt_hpps = files (
'PrinterDriverFactory.hpp', 'PrinterDriverFactory.hpp',
'graphics/Bitmap.hpp', 'graphics/Bitmap.hpp',
'graphics/Label.hpp', 'graphics/Label.hpp',
'graphics/LabelBuilder.hpp',
'graphics/Monochrome.hpp' 'graphics/Monochrome.hpp'
) )
@@ -22,7 +21,6 @@ ptprnt_srcs = files (
'printers/P700Printer.cpp', 'printers/P700Printer.cpp',
'printers/FakePrinter.cpp', 'printers/FakePrinter.cpp',
'graphics/Label.cpp', 'graphics/Label.cpp',
'graphics/LabelBuilder.cpp',
'graphics/Bitmap.cpp', 'graphics/Bitmap.cpp',
'graphics/Monochrome.cpp', 'graphics/Monochrome.cpp',
'libusbwrap/UsbDeviceFactory.cpp', 'libusbwrap/UsbDeviceFactory.cpp',