This commit is contained in:
@@ -16,12 +16,10 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
#include <cstdint>
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||
#define SPDLOG_DEBUG_ON
|
||||
#define SPDLOG_TRACE_ON
|
||||
#include "PtouchPrint.hpp"
|
||||
|
||||
#include <CLI/App.hpp>
|
||||
#include <algorithm>
|
||||
#include <fmt/core.h>
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/details/synchronous_factory.h>
|
||||
@@ -31,15 +29,16 @@
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "CLI/Option.hpp"
|
||||
#include "PrinterDriverFactory.hpp"
|
||||
#include "PtouchPrint.hpp"
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "graphics/Label.hpp"
|
||||
#include "graphics/interface/ILabel.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
|
||||
namespace ptprnt {
|
||||
@@ -98,37 +97,64 @@ int PtouchPrint::run() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (auto& cmd : mCommands) {
|
||||
switch (cmd.first) {
|
||||
auto label = graphics::Label();
|
||||
std::string labelText{};
|
||||
|
||||
for (const auto& [cmd, value] : mCommands) {
|
||||
switch (cmd) {
|
||||
case CliCmdType::Text:
|
||||
spdlog::debug("Setting text to {}", cmd.second);
|
||||
printer->setText(cmd.second);
|
||||
if (labelText.empty()) {
|
||||
labelText = value;
|
||||
} else {
|
||||
labelText = labelText + '\n' + value;
|
||||
}
|
||||
break;
|
||||
case CliCmdType::Font:;
|
||||
spdlog::debug("Setting font to {}", cmd.second);
|
||||
printer->setFont(cmd.second);
|
||||
case CliCmdType::Font:
|
||||
spdlog::debug("Setting font to {}", value);
|
||||
label.setFontFamily(value);
|
||||
break;
|
||||
case CliCmdType::FontSize:;
|
||||
spdlog::debug("Setting font size to {}", cmd.second);
|
||||
printer->setFontSize(static_cast<uint8_t>(std::atoi(cmd.second.c_str())));
|
||||
case CliCmdType::FontSize:
|
||||
spdlog::debug("Setting font size to {}", std::stod(value));
|
||||
label.setFontSize(std::stod(value));
|
||||
break;
|
||||
case CliCmdType::HAlign:;
|
||||
spdlog::debug("[Not implemented] Setting text horizontal alignment to {}", cmd.second);
|
||||
case CliCmdType::HAlign:
|
||||
spdlog::debug("Setting text horizontal alignment to {}", value);
|
||||
{
|
||||
auto hPos = HALignPositionMap.find(value);
|
||||
if (hPos == HALignPositionMap.end()) {
|
||||
spdlog::warn("Invalid horizontal alignment specified!");
|
||||
label.setHAlign(HAlignPosition::UNKNOWN);
|
||||
} else {
|
||||
label.setHAlign(hPos->second);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CliCmdType::VAlign:;
|
||||
spdlog::debug("[Not implemented] Setting text vertical alignment to {}", cmd.second);
|
||||
case CliCmdType::VAlign:
|
||||
spdlog::debug("Setting text vertical alignment to {}", value);
|
||||
{
|
||||
auto vPos = VALignPositionMap.find(value);
|
||||
if (vPos == VALignPositionMap.end()) {
|
||||
spdlog::warn("Invalid verical alignment specified!");
|
||||
label.setVAlign(VAlignPosition::UNKNOWN);
|
||||
} else {
|
||||
label.setVAlign(vPos->second);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CliCmdType::None:;
|
||||
case CliCmdType::None:
|
||||
[[fallthrough]];
|
||||
default:
|
||||
spdlog::warn("This command is currently not supported.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*if (!printer->print()) {
|
||||
if (!printer->print()) {
|
||||
spdlog::error("An error occured while printing");
|
||||
return -1;
|
||||
}*/
|
||||
}
|
||||
|
||||
label.create(labelText, 128);
|
||||
label.writeToPng("./testlabel.png");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -185,23 +211,39 @@ void PtouchPrint::setupCliParser() {
|
||||
->each([this](std::string text) { mCommands.emplace_back(CliCmdType::Text, text); });
|
||||
mApp.add_option("-f,--font", "Font used for the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeFirst)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string font) { mCommands.emplace_back(CliCmdType::Font, font); });
|
||||
mApp.add_option("-s,--fontsize", "Font size of the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeFirst)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string size) { mCommands.emplace_back(CliCmdType::FontSize, size); });
|
||||
mApp.add_option("--valign", "Vertical alignment of the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeFirst)
|
||||
->trigger_on_parse()
|
||||
->transform([](std::string in) -> std::string {
|
||||
std::unordered_set<std::string> validValignOptions{"top", "middle", "bottom"};
|
||||
std::transform(in.begin(), in.end(), in.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
if (validValignOptions.find(in) == validValignOptions.end()) {
|
||||
return {""};
|
||||
}
|
||||
return in;
|
||||
})
|
||||
->each([this](std::string valign) { mCommands.emplace_back(CliCmdType::VAlign, valign); });
|
||||
mApp.add_option("--halign", "Vertical alignment of the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeFirst)
|
||||
->trigger_on_parse()
|
||||
->transform([](std::string in) -> std::string {
|
||||
std::unordered_set<std::string> validValignOptions{"left", "center", "right", "justify"};
|
||||
std::transform(in.begin(), in.end(), in.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
if (validValignOptions.find(in) == validValignOptions.end()) {
|
||||
return {""};
|
||||
}
|
||||
return in;
|
||||
})
|
||||
->each([this](std::string halign) { mCommands.emplace_back(CliCmdType::HAlign, halign); });
|
||||
|
||||
// Image options
|
||||
|
Reference in New Issue
Block a user