Implement basic layouting
Some checks failed
Build ptprnt / build (push) Failing after 37s

This commit is contained in:
2024-04-28 17:37:09 +02:00
parent 37ee7c10f1
commit bb7ab6239d
8 changed files with 261 additions and 110 deletions

View File

@@ -26,15 +26,12 @@
#include <vector>
#include "cairo.h"
#include "pango/pango-font.h"
#include "graphics/interface/ILabel.hpp"
#include "pango/pango-types.h"
namespace ptprnt::graphics {
constexpr const char* DEFAULT_FONT_FAMILY = "sans";
constexpr const uint8_t DEFAULT_FONT_SIZE = 32;
class Label {
class Label : public ILabel {
public:
Label();
~Label();
@@ -44,20 +41,35 @@ class Label {
Label(Label&&) = delete;
Label& operator=(Label&&) = delete;
std::vector<uint8_t> getRaw();
void create(const std::string& labelText, const uint16_t heightPixel);
bool create(PrintableText printableText, const uint16_t heightPixel) override;
bool create(const std::string& labelText, const uint16_t heightPixel) override;
void writeToPng(const std::string& file);
int getLayoutWidth();
int getLayoutHeight();
[[nodiscard]] int getLayoutWidth() override;
[[nodiscard]] int getLayoutHeight() override;
[[nodiscard]] std::vector<uint8_t> getRaw() override;
void setFontSize(const double fontSize) override;
void setFontFamily(const std::string& fontFamily) override;
void setText(const std::string& text) override;
void setHAlign(HAlignPosition hpos) override;
void setVAlign(VAlignPosition vpos) override;
private:
// methods
uint8_t getNumLines(std::string_view str);
[[nodiscard]] uint8_t getNumLines(std::string_view str);
[[nodiscard]] PangoFontMap* createCustomFontMap();
// members
// TODO: convert raw pointers here into std::unique_ptr with custom deleters, calling g_object_unref()
cairo_surface_t* mSurface{nullptr};
cairo_t* mCairoCtx{nullptr};
PangoContext* mPangoCtx{nullptr};
PangoLayout* mPangoLyt{nullptr};
PangoFontDescription* mPangoFontDesc{nullptr};
cairo_surface_t* mSurface{nullptr};
PangoFontMap* mFontMap{nullptr};
double mFontSize{DEFAULT_FONT_SIZE};
std::string mFontFamily{DEFAULT_FONT_FAMILY};
HAlignPosition mHAlign = HAlignPosition::LEFT;
VAlignPosition mVAlign = VAlignPosition::MIDDLE;
std::string mText{""};
int mLayoutWidth = 0, mLayoutHeight = 0;
int mPrinterHeight = 0;
};