Compare commits
29 Commits
label-buil
...
5f673b7d57
| Author | SHA1 | Date | |
|---|---|---|---|
|
5f673b7d57
|
|||
|
58287202d8
|
|||
|
ae22feed4f
|
|||
|
652e687fb0
|
|||
|
bf7ff27b8d
|
|||
|
8658e5c9fd
|
|||
|
99b355b033
|
|||
|
6a593f2a40
|
|||
|
59b3b34edc
|
|||
|
6e3a5bd12f
|
|||
|
0b8ff28a60
|
|||
|
3dc5da6fc8
|
|||
|
5132eab6fa
|
|||
|
77c6b7bc7b
|
|||
|
f702ec5473
|
|||
|
59ef4189c4
|
|||
|
bb7ab6239d
|
|||
|
37ee7c10f1
|
|||
|
d98399949c
|
|||
|
a47a3189d3
|
|||
|
6857de7b1f
|
|||
|
5a38600e2a
|
|||
|
1163ae5745
|
|||
|
09a2e621d6
|
|||
|
28308dccad
|
|||
|
5f5c0f0f97
|
|||
|
4a59b50839
|
|||
|
79477baecd
|
|||
|
cf8492a714
|
@@ -1,22 +1,3 @@
|
|||||||
/*
|
|
||||||
ptrnt - print labels on linux
|
|
||||||
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
|
|
||||||
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 "PrinterDriverFactory.hpp"
|
#include "PrinterDriverFactory.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|||||||
@@ -1,26 +1,6 @@
|
|||||||
/*
|
|
||||||
ptrnt - print labels on linux
|
|
||||||
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
|
|
||||||
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 <memory>
|
#include <memory>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
#include "interface/IPrinterDriver.hpp"
|
#include "interface/IPrinterDriver.hpp"
|
||||||
#include "libusbwrap/LibUsbTypes.hpp"
|
#include "libusbwrap/LibUsbTypes.hpp"
|
||||||
|
|
||||||
@@ -65,4 +45,4 @@ class PrinterDriverFactory {
|
|||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ptprnt
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2024-2025 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2023-2024 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2023-2024 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2023-2024 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2023-2024 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,22 +1,3 @@
|
|||||||
/*
|
|
||||||
ptrnt - print labels on linux
|
|
||||||
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
|
|
||||||
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
|
#pragma once
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|||||||
@@ -1,22 +1,3 @@
|
|||||||
/*
|
|
||||||
ptrnt - print labels on linux
|
|
||||||
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
|
|
||||||
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
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -28,8 +9,8 @@
|
|||||||
namespace libusbwrap {
|
namespace libusbwrap {
|
||||||
class IUsbDeviceFactory {
|
class IUsbDeviceFactory {
|
||||||
public:
|
public:
|
||||||
virtual ~IUsbDeviceFactory() = default;
|
virtual ~IUsbDeviceFactory() = default;
|
||||||
virtual std::vector<std::unique_ptr<IUsbDevice>> findAllDevices() = 0;
|
virtual std::vector<std::unique_ptr<IUsbDevice>> findAllDevices() = 0;
|
||||||
virtual std::vector<std::unique_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
virtual std::vector<std::unique_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) = 0;
|
||||||
};
|
};
|
||||||
} // namespace libusbwrap
|
} // namespace libusbwrap
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2022-2023 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2025 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2025 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2025 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
ptrnt - print labels on linux
|
ptrnt - print labels on linux
|
||||||
Copyright (C) 2025 Moritz Martinius
|
Copyright (C) 2023 Moritz Martinius
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@@ -1,115 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# update_copyright.sh
|
|
||||||
# Updates copyright year ranges in a source file based on git history
|
|
||||||
#
|
|
||||||
# Usage: ./update_copyright.sh [--dry-run] <file>
|
|
||||||
#
|
|
||||||
# Examples:
|
|
||||||
# # Update a single file
|
|
||||||
# ./update_copyright.sh src/main.cpp
|
|
||||||
#
|
|
||||||
# # Dry-run on a single file
|
|
||||||
# ./update_copyright.sh --dry-run src/main.cpp
|
|
||||||
#
|
|
||||||
# # Update all C++ files using find -exec
|
|
||||||
# find src \( -name "*.cpp" -o -name "*.hpp" \) -exec ./update_copyright.sh {} \;
|
|
||||||
#
|
|
||||||
# # Dry-run on all C++ files
|
|
||||||
# find src \( -name "*.cpp" -o -name "*.hpp" \) -exec ./update_copyright.sh --dry-run {} \;
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Check for dry-run flag
|
|
||||||
DRY_RUN=false
|
|
||||||
FILE=""
|
|
||||||
|
|
||||||
if [ "$1" = "--dry-run" ]; then
|
|
||||||
DRY_RUN=true
|
|
||||||
FILE="$2"
|
|
||||||
elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
|
|
||||||
grep "^#" "$0" | sed 's/^# \?//'
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
FILE="$1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if file argument provided
|
|
||||||
if [ -z "$FILE" ]; then
|
|
||||||
echo "Error: No file specified"
|
|
||||||
echo "Usage: $0 [--dry-run] <file>"
|
|
||||||
echo "Run '$0 --help' for more information"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if file exists
|
|
||||||
if [ ! -f "$FILE" ]; then
|
|
||||||
echo "Error: File not found: $FILE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get the repository root
|
|
||||||
REPO_ROOT=$(git rev-parse --show-toplevel)
|
|
||||||
cd "$REPO_ROOT"
|
|
||||||
|
|
||||||
# Copyright holder name
|
|
||||||
COPYRIGHT_HOLDER="Moritz Martinius"
|
|
||||||
|
|
||||||
# Function to get first and last commit years for a file
|
|
||||||
get_years_for_file() {
|
|
||||||
local file="$1"
|
|
||||||
|
|
||||||
# Get the year of the first commit that touched this file
|
|
||||||
first_year=$(git log --follow --format=%ad --date=format:%Y --reverse "$file" 2>/dev/null | head -1)
|
|
||||||
|
|
||||||
# Get the year of the last commit that touched this file
|
|
||||||
last_year=$(git log --follow --format=%ad --date=format:%Y -1 "$file" 2>/dev/null)
|
|
||||||
|
|
||||||
# If file is not in git, use current year
|
|
||||||
if [ -z "$first_year" ]; then
|
|
||||||
first_year=$(date +%Y)
|
|
||||||
last_year=$(date +%Y)
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$first_year $last_year"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get years from git history
|
|
||||||
read -r first_year last_year <<< "$(get_years_for_file "$FILE")"
|
|
||||||
|
|
||||||
# Determine the copyright year string
|
|
||||||
if [ "$first_year" = "$last_year" ]; then
|
|
||||||
year_string="$first_year"
|
|
||||||
else
|
|
||||||
year_string="$first_year-$last_year"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if file has a copyright notice
|
|
||||||
if ! grep -q "Copyright (C)" "$FILE"; then
|
|
||||||
echo "No copyright notice found in $FILE, skipping"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$DRY_RUN" = true ]; then
|
|
||||||
# Just show what would be changed
|
|
||||||
current_year=$(grep "Copyright (C)" "$FILE" | sed -n 's/.*Copyright (C) \([0-9]\{4\}\(-[0-9]\{4\}\)\?\).*/\1/p' | head -1)
|
|
||||||
if [ "$current_year" != "$year_string" ]; then
|
|
||||||
echo "Would update $FILE: $current_year → $year_string"
|
|
||||||
else
|
|
||||||
echo "No change needed for $FILE (already $year_string)"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Update the copyright line
|
|
||||||
# Matches patterns like "Copyright (C) 2023 Moritz Martinius" or "Copyright (C) 2023-2024 Moritz Martinius"
|
|
||||||
# Handle variable whitespace between year and name
|
|
||||||
|
|
||||||
# Get current year from file for comparison
|
|
||||||
current_year=$(grep "Copyright (C)" "$FILE" | sed -n 's/.*Copyright (C) \([0-9]\{4\}\(-[0-9]\{4\}\)\?\).*/\1/p' | head -1)
|
|
||||||
|
|
||||||
if [ "$current_year" = "$year_string" ]; then
|
|
||||||
echo "No changes needed for $FILE (already $year_string)"
|
|
||||||
else
|
|
||||||
sed -i "s/Copyright (C) [0-9]\{4\}\(-[0-9]\{4\}\)\? \+$COPYRIGHT_HOLDER/Copyright (C) $year_string $COPYRIGHT_HOLDER/" "$FILE"
|
|
||||||
echo "✓ Updated $FILE: $current_year → $year_string"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user