Backend.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <cairo.h>
  3. #include "../dll_visibility.h"
  4. #include <exception>
  5. #include <nan.h>
  6. #include <string>
  7. #include <v8.h>
  8. class Canvas;
  9. class Backend : public Nan::ObjectWrap
  10. {
  11. private:
  12. const std::string name;
  13. const char* error = NULL;
  14. protected:
  15. int width;
  16. int height;
  17. cairo_surface_t* surface = nullptr;
  18. Canvas* canvas = nullptr;
  19. Backend(std::string name, int width, int height);
  20. static void init(const Nan::FunctionCallbackInfo<v8::Value> &info);
  21. static Backend *construct(int width, int height){ return nullptr; }
  22. public:
  23. virtual ~Backend();
  24. void setCanvas(Canvas* canvas);
  25. virtual cairo_surface_t* createSurface() = 0;
  26. virtual cairo_surface_t* recreateSurface();
  27. DLL_PUBLIC cairo_surface_t* getSurface();
  28. virtual void destroySurface();
  29. DLL_PUBLIC std::string getName();
  30. DLL_PUBLIC int getWidth();
  31. virtual void setWidth(int width);
  32. DLL_PUBLIC int getHeight();
  33. virtual void setHeight(int height);
  34. // Overridden by ImageBackend. SVG and PDF thus always return INVALID.
  35. virtual cairo_format_t getFormat() {
  36. return CAIRO_FORMAT_INVALID;
  37. }
  38. bool isSurfaceValid();
  39. inline const char* getError(){ return error; }
  40. };
  41. class BackendOperationNotAvailable: public std::exception
  42. {
  43. private:
  44. Backend* backend;
  45. std::string operation_name;
  46. std::string msg;
  47. public:
  48. BackendOperationNotAvailable(Backend* backend, std::string operation_name);
  49. ~BackendOperationNotAvailable() throw();
  50. const char* what() const throw();
  51. };