Start refactoring printers into own directory
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -31,6 +32,28 @@
|
||||
|
||||
namespace ptprnt::graphics {
|
||||
|
||||
// Custom deleters for Cairo/Pango resources
|
||||
struct CairoSurfaceDeleter {
|
||||
void operator()(cairo_surface_t* surface) const {
|
||||
if (surface)
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
};
|
||||
|
||||
struct CairoDeleter {
|
||||
void operator()(cairo_t* cr) const {
|
||||
if (cr)
|
||||
cairo_destroy(cr);
|
||||
}
|
||||
};
|
||||
|
||||
struct GObjectDeleter {
|
||||
void operator()(gpointer obj) const {
|
||||
if (obj)
|
||||
g_object_unref(obj);
|
||||
}
|
||||
};
|
||||
|
||||
class Label : public ILabel {
|
||||
public:
|
||||
Label(const uint16_t heightPixel);
|
||||
@@ -60,13 +83,14 @@ class Label : public ILabel {
|
||||
// methods
|
||||
[[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};
|
||||
PangoFontMap* mFontMap{nullptr};
|
||||
void configureLayout(PangoLayout* layout, const std::string& text, PangoFontDescription* fontDesc);
|
||||
void applyHorizontalAlignment(PangoLayout* layout);
|
||||
|
||||
std::unique_ptr<cairo_surface_t, CairoSurfaceDeleter> mSurface{nullptr};
|
||||
std::unique_ptr<cairo_t, CairoDeleter> mCairoCtx{nullptr};
|
||||
std::unique_ptr<PangoContext, GObjectDeleter> mPangoCtx{nullptr};
|
||||
std::unique_ptr<PangoLayout, GObjectDeleter> mPangoLyt{nullptr};
|
||||
std::unique_ptr<PangoFontMap, GObjectDeleter> mFontMap{nullptr};
|
||||
double mFontSize{DEFAULT_FONT_SIZE};
|
||||
std::string mFontFamily{DEFAULT_FONT_FAMILY};
|
||||
HAlignPosition mHAlign = HAlignPosition::LEFT;
|
||||
|
||||
Reference in New Issue
Block a user