Add a label builder (#14)
All checks were successful
Build ptprnt / build (push) Successful in 3m22s
All checks were successful
Build ptprnt / build (push) Successful in 3m22s
Reviewed-on: moritz/ptouch-prnt#14
This commit was merged in pull request #14.
This commit is contained in:
64
src/graphics/LabelBuilder.hpp
Normal file
64
src/graphics/LabelBuilder.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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
|
||||
Reference in New Issue
Block a user