plugin-api.h 6.18 KB
Newer Older
1 2 3 4 5 6 7
/* See LICENSE file for license and copyright information */

#ifndef PLUGIN_API_H
#define PLUGIN_API_H

#include "page.h"
#include "document.h"
Moritz Lipp's avatar
Moritz Lipp committed
8
#include "links.h"
9
#include "zathura-version.h"
10

11
typedef struct zathura_plugin_functions_s zathura_plugin_functions_t;
12

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
/**
 * Opens a document
 */
typedef zathura_error_t (*zathura_plugin_document_open_t)(zathura_document_t* document);

/**
 * Frees the document
 */
typedef zathura_error_t (*zathura_plugin_document_free_t)(zathura_document_t* document, void* data);

/**
 * Generates the document index
 */
typedef girara_tree_node_t* (*zathura_plugin_document_index_generate_t)(zathura_document_t* document, void* data, zathura_error_t* error);

/**
 * Save the document
 */
typedef zathura_error_t (*zathura_plugin_document_save_as_t)(zathura_document_t* document, void* data, const char* path);

/**
 * Get list of attachments
 */
typedef girara_list_t* (*zathura_plugin_document_attachments_get_t)(zathura_document_t* document, void* data, zathura_error_t* error);

/**
 * Save attachment to a file
 */
typedef zathura_error_t (*zathura_plugin_document_attachment_save_t)(zathura_document_t* document, void* data, const char* attachment, const char* file);

/**
 * Get document information
 */
typedef girara_list_t* (*zathura_plugin_document_get_information_t)(zathura_document_t* document, void* data, zathura_error_t* error);

/**
 * Gets the page object
 */
typedef zathura_error_t (*zathura_plugin_page_init_t)(zathura_page_t* page);

/**
 * Free page
 */
typedef zathura_error_t (*zathura_plugin_page_clear_t)(zathura_page_t* page, void* data);

/**
 * Search text
 */
typedef girara_list_t* (*zathura_plugin_page_search_text_t)(zathura_page_t* page, void* data, const char* text, zathura_error_t* error);

/**
 * Get links on a page
 */
typedef girara_list_t* (*zathura_plugin_page_links_get_t)(zathura_page_t* page, void* data, zathura_error_t* error);

/**
 * Get form fields
 */
typedef girara_list_t* (*zathura_plugin_page_form_fields_get_t)(zathura_page_t* page, void* data, zathura_error_t* error);

/**
 * Get list of images
 */
typedef girara_list_t* (*zathura_plugin_page_images_get_t)(zathura_page_t* page, void* data, zathura_error_t* error);

/**
 * Get the image
 */
typedef cairo_surface_t* (*zathura_plugin_page_image_get_cairo_t)(zathura_page_t* page, void* data, zathura_image_t* image, zathura_error_t* error);

/**
 * Get text for selection
 */
typedef char* (*zathura_plugin_page_get_text_t)(zathura_page_t* page, void* data, zathura_rectangle_t rectangle, zathura_error_t* error);

/**
 * Renders the page
 */
typedef zathura_image_buffer_t* (*zathura_plugin_page_render_t)(zathura_page_t* page, void* data, zathura_error_t* error);

/**
94
 * Renders the page to a cairo surface.
95 96 97
 */
typedef zathura_error_t (*zathura_plugin_page_render_cairo_t)(zathura_page_t* page, void* data, cairo_t* cairo, bool printing);

98 99 100 101 102
/**
 * Get page label.
 */
typedef zathura_error_t (*zathura_plugin_page_get_label_t)(zathura_page_t* page, void* data, char** label);

103

104
struct zathura_plugin_functions_s
105 106 107 108
{
  /**
   * Opens a document
   */
109
  zathura_plugin_document_open_t document_open;
110 111 112 113

  /**
   * Frees the document
   */
114
  zathura_plugin_document_free_t document_free;
115 116 117 118

  /**
   * Generates the document index
   */
119
  zathura_plugin_document_index_generate_t document_index_generate;
120 121 122 123

  /**
   * Save the document
   */
124
  zathura_plugin_document_save_as_t document_save_as;
125 126 127 128

  /**
   * Get list of attachments
   */
129
  zathura_plugin_document_attachments_get_t document_attachments_get;
130 131 132 133

  /**
   * Save attachment to a file
   */
134
  zathura_plugin_document_attachment_save_t document_attachment_save;
135 136 137 138

  /**
   * Get document information
   */
139
  zathura_plugin_document_get_information_t document_get_information;
140 141 142 143

  /**
   * Gets the page object
   */
144
  zathura_plugin_page_init_t page_init;
145 146 147 148

  /**
   * Free page
   */
149
  zathura_plugin_page_clear_t page_clear;
150 151 152 153

  /**
   * Search text
   */
154
  zathura_plugin_page_search_text_t page_search_text;
155 156 157 158

  /**
   * Get links on a page
   */
159
  zathura_plugin_page_links_get_t page_links_get;
160 161 162 163

  /**
   * Get form fields
   */
164
  zathura_plugin_page_form_fields_get_t page_form_fields_get;
165 166 167 168

  /**
   * Get list of images
   */
169
  zathura_plugin_page_images_get_t page_images_get;
170 171 172 173

  /**
   * Get the image
   */
174
  zathura_plugin_page_image_get_cairo_t page_image_get_cairo;
175 176 177 178

  /**
   * Get text for selection
   */
179
  zathura_plugin_page_get_text_t page_get_text;
180 181 182 183

  /**
   * Renders the page
   */
184
  zathura_plugin_page_render_t page_render;
185 186

  /**
187
   * Renders the page to a cairo surface.
188
   */
189
  zathura_plugin_page_render_cairo_t page_render_cairo;
190 191 192 193 194

  /**
   * Get page label.
   */
  zathura_plugin_page_get_label_t page_get_label;
195 196
};

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
typedef struct zathura_plugin_version_s {
  unsigned int major; /**< Major */
  unsigned int minor; /**< Minor */
  unsigned int rev; /**< Revision */
} zathura_plugin_version_t;

typedef struct zathura_plugin_definition_s {
  const char* name;
  const zathura_plugin_version_t version;
  zathura_plugin_functions_t functions;
  const size_t mime_types_size;
  const char** mime_types;
} zathura_plugin_definition_t;

#define JOIN(x, y) JOIN2(x, y)
#define JOIN2(x, y) x ## _ ## y

#define ZATHURA_PLUGIN_DEFINITION_SYMBOL \
  JOIN(zathura_plugin, JOIN(ZATHURA_API_VERSION, ZATHURA_ABI_VERSION))

/**
 * Register a plugin.
 *
 * @param plugin_name the name of the plugin
 * @param major the plugin's major version
 * @param minor the plugin's minor version
 * @param rev the plugin's revision
 * @param plugin_functions function to register the plugin's document functions
 * @param mimetypes a char array of mime types supported by the plugin
 */
#define ZATHURA_PLUGIN_REGISTER_WITH_FUNCTIONS(plugin_name, major, minor, rev, plugin_functions, mimetypes) \
  static const char* zathura_plugin_mime_types[] = mimetypes; \
  \
  const zathura_plugin_definition_t ZATHURA_PLUGIN_DEFINITION_SYMBOL = { \
    .name = plugin_name, \
    .version = { major, minor, rev }, \
    .functions = plugin_functions, \
    .mime_types_size = sizeof(zathura_plugin_mime_types) / sizeof(zathura_plugin_mime_types[0]), \
    .mime_types = zathura_plugin_mime_types \
  }; \


#define ZATHURA_PLUGIN_MIMETYPES(...) __VA_ARGS__
#define ZATHURA_PLUGIN_FUNCTIONS(...) __VA_ARGS__
241 242

#endif // PLUGIN_API_H