1 Commits

Author SHA1 Message Date
bb7ab6239d Implement basic layouting
Some checks failed
Build ptprnt / build (push) Failing after 37s
2024-04-28 17:38:56 +02:00

View File

@@ -0,0 +1,78 @@
/*
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
#include <cstdint>
#include <map>
#include <string>
#include <vector>
constexpr const char* DEFAULT_FONT_FAMILY = "sans";
constexpr const double DEFAULT_FONT_SIZE = 32.0;
enum class HAlignPosition {
UNKNOWN = 0,
LEFT = 1,
CENTER = 2,
RIGHT = 3,
JUSTIFY = 4,
};
const std::map<std::string, HAlignPosition> HALignPositionMap{{"", HAlignPosition::UNKNOWN},
{"left", HAlignPosition::LEFT},
{"center", HAlignPosition::CENTER},
{"right", HAlignPosition::RIGHT},
{"justify", HAlignPosition::JUSTIFY}};
enum class VAlignPosition {
UNKNOWN = 0,
TOP = 1,
MIDDLE = 2,
BOTTOM = 3,
};
const std::map<std::string, VAlignPosition> VALignPositionMap{{"", VAlignPosition::UNKNOWN},
{"top", VAlignPosition::TOP},
{"middle", VAlignPosition::MIDDLE},
{"bottom", VAlignPosition::BOTTOM}};
struct PrintableText {
std::string text{""};
std::string fontFamily{DEFAULT_FONT_FAMILY};
double fontSize{DEFAULT_FONT_SIZE};
HAlignPosition hAlign{HAlignPosition::LEFT};
VAlignPosition vAlign{VAlignPosition::MIDDLE};
};
class ILabel {
public:
virtual ~ILabel() = default;
virtual bool create(PrintableText printableText, const uint16_t heightPixel) = 0;
virtual bool create(const std::string& labelText, const uint16_t heightPixel) = 0;
virtual std::vector<uint8_t> getRaw() = 0;
virtual int getLayoutWidth() = 0;
virtual int getLayoutHeight() = 0;
virtual void setText(const std::string& text) = 0;
virtual void setFontSize(const double fontSize) = 0;
virtual void setFontFamily(const std::string& fontFamily) = 0;
virtual void setHAlign(HAlignPosition hpos) = 0;
virtual void setVAlign(VAlignPosition vpos) = 0;
};