84 lines
4.4 KiB
C++
84 lines
4.4 KiB
C++
/*
|
|
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 <cairo.h>
|
|
#include <pango/pango.h>
|
|
#include <pango/pangocairo.h>
|
|
|
|
namespace ptprnt::graphics {
|
|
|
|
/**
|
|
* @brief Interface wrapper for Cairo and Pango C API functions
|
|
*
|
|
* This interface allows for dependency injection and mocking of Cairo/Pango
|
|
* functionality in unit tests, making the Label class fully testable.
|
|
*/
|
|
class ICairoWrapper {
|
|
public:
|
|
virtual ~ICairoWrapper() = default;
|
|
|
|
// Cairo image surface functions
|
|
virtual cairo_surface_t* cairo_image_surface_create(cairo_format_t format, int width, int height) = 0;
|
|
virtual void cairo_surface_destroy(cairo_surface_t* surface) = 0;
|
|
virtual void cairo_surface_flush(cairo_surface_t* surface) = 0;
|
|
virtual void cairo_surface_mark_dirty(cairo_surface_t* surface) = 0;
|
|
virtual cairo_status_t cairo_surface_status(cairo_surface_t* surface) = 0;
|
|
virtual cairo_format_t cairo_image_surface_get_format(cairo_surface_t* surface) = 0;
|
|
virtual int cairo_image_surface_get_width(cairo_surface_t* surface) = 0;
|
|
virtual int cairo_image_surface_get_height(cairo_surface_t* surface) = 0;
|
|
virtual int cairo_image_surface_get_stride(cairo_surface_t* surface) = 0;
|
|
virtual unsigned char* cairo_image_surface_get_data(cairo_surface_t* surface) = 0;
|
|
virtual cairo_status_t cairo_surface_write_to_png(cairo_surface_t* surface, const char* filename) = 0;
|
|
|
|
// Cairo context functions
|
|
virtual cairo_t* cairo_create(cairo_surface_t* surface) = 0;
|
|
virtual void cairo_destroy(cairo_t* cr) = 0;
|
|
virtual void cairo_move_to(cairo_t* cr, double x, double y) = 0;
|
|
virtual void cairo_set_source_rgb(cairo_t* cr, double red, double green, double blue) = 0;
|
|
|
|
// Pango-Cairo functions
|
|
virtual PangoFontMap* pango_cairo_font_map_new() = 0;
|
|
virtual PangoContext* pango_cairo_create_context(cairo_t* cr) = 0;
|
|
virtual void pango_cairo_show_layout(cairo_t* cr, PangoLayout* layout) = 0;
|
|
|
|
// Pango layout functions
|
|
virtual PangoLayout* pango_layout_new(PangoContext* context) = 0;
|
|
virtual void pango_layout_set_font_description(PangoLayout* layout, const PangoFontDescription* desc) = 0;
|
|
virtual void pango_layout_set_text(PangoLayout* layout, const char* text, int length) = 0;
|
|
virtual void pango_layout_set_height(PangoLayout* layout, int height) = 0;
|
|
virtual void pango_layout_set_alignment(PangoLayout* layout, PangoAlignment alignment) = 0;
|
|
virtual void pango_layout_set_justify(PangoLayout* layout, gboolean justify) = 0;
|
|
#if PANGO_VERSION_MAJOR >= 1 && PANGO_VERSION_MINOR >= 50
|
|
virtual void pango_layout_set_justify_last_line(PangoLayout* layout, gboolean justify) = 0;
|
|
#endif
|
|
virtual void pango_layout_get_size(PangoLayout* layout, int* width, int* height) = 0;
|
|
|
|
// Pango font description functions
|
|
virtual PangoFontDescription* pango_font_description_new() = 0;
|
|
virtual void pango_font_description_set_size(PangoFontDescription* desc, gint size) = 0;
|
|
virtual void pango_font_description_set_family(PangoFontDescription* desc, const char* family) = 0;
|
|
|
|
// GObject reference counting
|
|
virtual void g_object_unref(gpointer object) = 0;
|
|
};
|
|
|
|
} // namespace ptprnt::graphics
|