1 /* SPDX-License-Identifier: Zlib */
2 
3 #ifndef PLUGIN_API_H
4 #define PLUGIN_API_H
5 
6 #include <cairo.h>
7 
8 #include "types.h"
9 #include "page.h"
10 #include "document.h"
11 #include "links.h"
12 #include "zathura-version.h"
13 
14 typedef struct zathura_plugin_functions_s zathura_plugin_functions_t;
15 
16 /**
17  * Opens a document
18  */
19 typedef zathura_error_t (*zathura_plugin_document_open_t)(zathura_document_t* document);
20 
21 /**
22  * Frees the document
23  */
24 typedef zathura_error_t (*zathura_plugin_document_free_t)(zathura_document_t* document, void* data);
25 
26 /**
27  * Generates the document index
28  */
29 typedef girara_tree_node_t* (*zathura_plugin_document_index_generate_t)(zathura_document_t* document, void* data, zathura_error_t* error);
30 
31 /**
32  * Save the document
33  */
34 typedef zathura_error_t (*zathura_plugin_document_save_as_t)(zathura_document_t* document, void* data, const char* path);
35 
36 /**
37  * Get list of attachments
38  */
39 typedef girara_list_t* (*zathura_plugin_document_attachments_get_t)(zathura_document_t* document, void* data, zathura_error_t* error);
40 
41 /**
42  * Save attachment to a file
43  */
44 typedef zathura_error_t (*zathura_plugin_document_attachment_save_t)(zathura_document_t* document, void* data, const char* attachment, const char* file);
45 
46 /**
47  * Get document information
48  */
49 typedef girara_list_t* (*zathura_plugin_document_get_information_t)(zathura_document_t* document, void* data, zathura_error_t* error);
50 
51 /**
52  * Gets the page object
53  */
54 typedef zathura_error_t (*zathura_plugin_page_init_t)(zathura_page_t* page);
55 
56 /**
57  * Free page
58  */
59 typedef zathura_error_t (*zathura_plugin_page_clear_t)(zathura_page_t* page, void* data);
60 
61 /**
62  * Search text
63  */
64 typedef girara_list_t* (*zathura_plugin_page_search_text_t)(zathura_page_t* page, void* data, const char* text, zathura_error_t* error);
65 
66 /**
67  * Get links on a page
68  */
69 typedef girara_list_t* (*zathura_plugin_page_links_get_t)(zathura_page_t* page, void* data, zathura_error_t* error);
70 
71 /**
72  * Get form fields
73  */
74 typedef girara_list_t* (*zathura_plugin_page_form_fields_get_t)(zathura_page_t* page, void* data, zathura_error_t* error);
75 
76 /**
77  * Get list of images
78  */
79 typedef girara_list_t* (*zathura_plugin_page_images_get_t)(zathura_page_t* page, void* data, zathura_error_t* error);
80 
81 /**
82  * Get the image
83  */
84 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);
85 
86 /**
87  * Get text for selection
88  */
89 typedef char* (*zathura_plugin_page_get_text_t)(zathura_page_t* page, void* data, zathura_rectangle_t rectangle, zathura_error_t* error);
90 
91 /**
92  * Renders the page
93  */
94 typedef zathura_image_buffer_t* (*zathura_plugin_page_render_t)(zathura_page_t* page, void* data, zathura_error_t* error);
95 
96 /**
97  * Renders the page to a cairo surface.
98  */
99 typedef zathura_error_t (*zathura_plugin_page_render_cairo_t)(zathura_page_t* page, void* data, cairo_t* cairo, bool printing);
100 
101 /**
102  * Get page label.
103  */
104 typedef zathura_error_t (*zathura_plugin_page_get_label_t)(zathura_page_t* page, void* data, char** label);
105 
106 
107 struct zathura_plugin_functions_s
108 {
109   /**
110    * Opens a document
111    */
112   zathura_plugin_document_open_t document_open;
113 
114   /**
115    * Frees the document
116    */
117   zathura_plugin_document_free_t document_free;
118 
119   /**
120    * Generates the document index
121    */
122   zathura_plugin_document_index_generate_t document_index_generate;
123 
124   /**
125    * Save the document
126    */
127   zathura_plugin_document_save_as_t document_save_as;
128 
129   /**
130    * Get list of attachments
131    */
132   zathura_plugin_document_attachments_get_t document_attachments_get;
133 
134   /**
135    * Save attachment to a file
136    */
137   zathura_plugin_document_attachment_save_t document_attachment_save;
138 
139   /**
140    * Get document information
141    */
142   zathura_plugin_document_get_information_t document_get_information;
143 
144   /**
145    * Gets the page object
146    */
147   zathura_plugin_page_init_t page_init;
148 
149   /**
150    * Free page
151    */
152   zathura_plugin_page_clear_t page_clear;
153 
154   /**
155    * Search text
156    */
157   zathura_plugin_page_search_text_t page_search_text;
158 
159   /**
160    * Get links on a page
161    */
162   zathura_plugin_page_links_get_t page_links_get;
163 
164   /**
165    * Get form fields
166    */
167   zathura_plugin_page_form_fields_get_t page_form_fields_get;
168 
169   /**
170    * Get list of images
171    */
172   zathura_plugin_page_images_get_t page_images_get;
173 
174   /**
175    * Get the image
176    */
177   zathura_plugin_page_image_get_cairo_t page_image_get_cairo;
178 
179   /**
180    * Get text for selection
181    */
182   zathura_plugin_page_get_text_t page_get_text;
183 
184   /**
185    * Renders the page
186    */
187   zathura_plugin_page_render_t page_render;
188 
189   /**
190    * Renders the page to a cairo surface.
191    */
192   zathura_plugin_page_render_cairo_t page_render_cairo;
193 
194   /**
195    * Get page label.
196    */
197   zathura_plugin_page_get_label_t page_get_label;
198 };
199 
200 typedef struct zathura_plugin_version_s {
201   unsigned int major; /**< Major */
202   unsigned int minor; /**< Minor */
203   unsigned int rev; /**< Revision */
204 } zathura_plugin_version_t;
205 
206 typedef struct zathura_plugin_definition_s {
207   const char* name;
208   const zathura_plugin_version_t version;
209   zathura_plugin_functions_t functions;
210   const size_t mime_types_size;
211   const char** mime_types;
212 } zathura_plugin_definition_t;
213 
214 #define JOIN(x, y) JOIN2(x, y)
215 #define JOIN2(x, y) x ## _ ## y
216 
217 #define ZATHURA_PLUGIN_DEFINITION_SYMBOL \
218   JOIN(zathura_plugin, JOIN(ZATHURA_API_VERSION, ZATHURA_ABI_VERSION))
219 
220 /**
221  * Register a plugin.
222  *
223  * @param plugin_name the name of the plugin
224  * @param major the plugin's major version
225  * @param minor the plugin's minor version
226  * @param rev the plugin's revision
227  * @param plugin_functions function to register the plugin's document functions
228  * @param mimetypes a char array of mime types supported by the plugin
229  */
230 #define ZATHURA_PLUGIN_REGISTER_WITH_FUNCTIONS(plugin_name, major, minor, rev, plugin_functions, mimetypes) \
231   static const char* zathura_plugin_mime_types[] = mimetypes; \
232   \
233   ZATHURA_PLUGIN_API const zathura_plugin_definition_t ZATHURA_PLUGIN_DEFINITION_SYMBOL = { \
234     .name = plugin_name, \
235     .version = { major, minor, rev }, \
236     .functions = plugin_functions, \
237     .mime_types_size = sizeof(zathura_plugin_mime_types) / sizeof(zathura_plugin_mime_types[0]), \
238     .mime_types = zathura_plugin_mime_types \
239   }; \
240 
241 
242 #define ZATHURA_PLUGIN_MIMETYPES(...) __VA_ARGS__
243 #define ZATHURA_PLUGIN_FUNCTIONS(...) __VA_ARGS__
244 
245 #endif // PLUGIN_API_H
246