Files
med-notes/.pnpm-store/v10/files/8d/5d859cfd192a435724eafe294a284bef3af43066c05e002736180a57581d867164d797849d517eb2f78ef0c8445123185d5868658e8c77dc2bdc3ba1d448c7
2025-05-09 05:30:08 +02:00

68 lines
1.4 KiB
Plaintext

#pragma once
#include <cairo.h>
#include "../dll_visibility.h"
#include <exception>
#include <napi.h>
#include <string>
class Canvas;
class Backend
{
private:
const std::string name;
const char* error = NULL;
protected:
int width;
int height;
cairo_surface_t* surface = nullptr;
Canvas* canvas = nullptr;
Backend(std::string name, Napi::CallbackInfo& info);
public:
Napi::Env env;
virtual ~Backend();
void setCanvas(Canvas* canvas);
virtual cairo_surface_t* createSurface() = 0;
virtual cairo_surface_t* recreateSurface();
DLL_PUBLIC cairo_surface_t* getSurface();
virtual void destroySurface();
DLL_PUBLIC std::string getName();
DLL_PUBLIC int getWidth();
virtual void setWidth(int width);
DLL_PUBLIC int getHeight();
virtual void setHeight(int height);
// Overridden by ImageBackend. SVG and PDF thus always return INVALID.
virtual cairo_format_t getFormat() {
return CAIRO_FORMAT_INVALID;
}
bool isSurfaceValid();
inline const char* getError(){ return error; }
};
class BackendOperationNotAvailable: public std::exception
{
private:
std::string operation_name;
std::string msg;
public:
BackendOperationNotAvailable(Backend* backend, std::string operation_name);
~BackendOperationNotAvailable() throw();
const char* what() const throw();
};