document.h 8.32 KB
Newer Older
Moritz Lipp's avatar
Moritz Lipp committed
1
2
3
4
5
/* See LICENSE file for license and copyright information */

#ifndef DOCUMENT_H
#define DOCUMENT_H

6
#include <gtk/gtk.h>
Moritz Lipp's avatar
Moritz Lipp committed
7
8
#include <stdbool.h>

9
10
#include <girara-datastructures.h>

Moritz Lipp's avatar
Moritz Lipp committed
11
12
13
#define PLUGIN_DIR "/usr/lib/zathura"
#define PLUGIN_REGISTER_FUNCTION "plugin_register"

Moritz Lipp's avatar
Moritz Lipp committed
14
15
16
typedef struct zathura_list_s zathura_list_t;
typedef struct zathura_document_s zathura_document_t;

Moritz Lipp's avatar
Moritz Lipp committed
17
18
typedef bool (*zathura_document_open_t)(zathura_document_t* document);

Moritz Lipp's avatar
Moritz Lipp committed
19
20
21
/**
 * Document plugin structure
 */
Moritz Lipp's avatar
Moritz Lipp committed
22
23
typedef struct zathura_document_plugin_s
{
Moritz Lipp's avatar
Moritz Lipp committed
24
25
26
27
  char* file_extension; /**> File extension */
  zathura_document_open_t open_function; /**> Document open function */
  void* handle; /**> DLL handle */
  struct zathura_document_plugin_s *next; /**> Next plugin */ // TODO: Use list_t
Moritz Lipp's avatar
Moritz Lipp committed
28
29
} zathura_document_plugin_t;

Moritz Lipp's avatar
Moritz Lipp committed
30
31
32
33
34
/**
 * Function prototype that is called to register a document plugin
 *
 * @param The document plugin
 */
35
typedef void (*zathura_plugin_register_service_t)(zathura_document_plugin_t*);
Moritz Lipp's avatar
Moritz Lipp committed
36

Moritz Lipp's avatar
Moritz Lipp committed
37
38
39
/**
 * Structure for a list
 */
Moritz Lipp's avatar
Moritz Lipp committed
40
41
struct zathura_list_s
{
Moritz Lipp's avatar
Moritz Lipp committed
42
43
  void* data; /**> Data value */
  struct zathura_list_s* next; /**> Next element in the list */
Moritz Lipp's avatar
Moritz Lipp committed
44
45
};

46
47
48
49
50
51
52
53
/**
 * Image buffer
 */
typedef struct zathura_image_buffer_s
{
  unsigned char* data; /**> Image buffer data */
  unsigned int height; /**> Height of the image */
  unsigned int width; /**> Width of the image */
Moritz Lipp's avatar
Moritz Lipp committed
54
  unsigned int rowstride; /**> Rowstride of the image */
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
} zathura_image_buffer_t;

/**
 * Creates an image buffer
 *
 * @param width Width of the image stored in the buffer
 * @param height Height of the image stored in the buffer
 * @return Image buffer or NULL if an error occured
 */
zathura_image_buffer_t* zathura_image_buffer_create(unsigned int width, unsigned int height);

/**
 * Frees the image buffer
 *
 * @param zathura_image_buffer_t
 */
void zathura_image_buffer_free(zathura_image_buffer_t*);

Moritz Lipp's avatar
Moritz Lipp committed
73
74
75
/**
 * Rectangle structure
 */
Moritz Lipp's avatar
Moritz Lipp committed
76
77
typedef struct zathura_rectangle_s
{
Moritz Lipp's avatar
Moritz Lipp committed
78
79
80
81
  double x1; /**> X coordinate of point 1 */
  double y1; /**> Y coordinate of point 1 */
  double x2; /**> X coordinate of point 2 */
  double y2; /**> Y coordinate of point 2 */
Moritz Lipp's avatar
Moritz Lipp committed
82
83
} zathura_rectangle_t;

Moritz Lipp's avatar
Moritz Lipp committed
84
85
86
/**
 * Possible link types
 */
Moritz Lipp's avatar
Moritz Lipp committed
87
88
typedef enum zathura_link_type_e
{
Moritz Lipp's avatar
Moritz Lipp committed
89
90
  ZATHURA_LINK_TO_PAGE, /**> Links to a page */
  ZATHURA_LINK_EXTERNAL, /**> Links to an external source */
Moritz Lipp's avatar
Moritz Lipp committed
91
92
} zathura_link_type_t;

Moritz Lipp's avatar
Moritz Lipp committed
93
94
95
/**
 * Link
 */
Moritz Lipp's avatar
Moritz Lipp committed
96
97
typedef struct zathura_link_s
{
Moritz Lipp's avatar
Moritz Lipp committed
98
99
  zathura_rectangle_t position; /**> Position of the link */
  zathura_link_type_t type; /**> Link type */
Moritz Lipp's avatar
Moritz Lipp committed
100
101
  union
  {
Moritz Lipp's avatar
Moritz Lipp committed
102
103
    unsigned int page_number; /**> Page number */
    char* value; /**> Value */
Moritz Lipp's avatar
Moritz Lipp committed
104
105
106
  } target;
} zathura_link_t;

Moritz Lipp's avatar
Moritz Lipp committed
107
108
109
/**
 * Index element
 */
110
111
typedef struct zathura_index_element_s
{
Moritz Lipp's avatar
Moritz Lipp committed
112
113
  char* title; /**> Title of the element */
  zathura_link_type_t type; /**> Type */
114
115
  union
  {
Moritz Lipp's avatar
Moritz Lipp committed
116
117
    unsigned int page_number; /**> Page number */
    char* uri; /**> Uri */
118
119
120
  } target;
} zathura_index_element_t;

Moritz Lipp's avatar
Moritz Lipp committed
121
122
123
/**
 * Form type
 */
Moritz Lipp's avatar
Moritz Lipp committed
124
125
typedef enum zathura_form_type_e
{
Moritz Lipp's avatar
Moritz Lipp committed
126
127
  ZATHURA_FORM_CHECKBOX, /**> Checkbox */
  ZATHURA_FORM_TEXTFIELD /**> Textfield */
Moritz Lipp's avatar
Moritz Lipp committed
128
129
} zathura_form_type_t;

Moritz Lipp's avatar
Moritz Lipp committed
130
131
132
/**
 * Form element
 */
Moritz Lipp's avatar
Moritz Lipp committed
133
134
typedef struct zathura_form_s
{
Moritz Lipp's avatar
Moritz Lipp committed
135
136
  zathura_rectangle_t position; /**> Position */
  zathura_form_type_t type; /**> Type */
Moritz Lipp's avatar
Moritz Lipp committed
137
138
} zathura_form_t;

Moritz Lipp's avatar
Moritz Lipp committed
139
140
141
/**
 * Page
 */
Moritz Lipp's avatar
Moritz Lipp committed
142
143
typedef struct zathura_page_s
{
Moritz Lipp's avatar
Moritz Lipp committed
144
145
146
147
148
149
  double height; /**> Page height */
  double width; /**> Page width */
  unsigned int number; /**> Page number */
  zathura_document_t* document; /**> Document */
  void* data; /**> Custom data */
  bool rendered; /**> Page has been rendered */
Moritz Lipp's avatar
Moritz Lipp committed
150
151
  GtkWidget* event_box; /**> Widget wrapper for mouse events */
  GtkWidget* drawing_area; /**> Drawing area */
Moritz Lipp's avatar
Moritz Lipp committed
152
  GStaticMutex lock; /**> Lock */
Moritz Lipp's avatar
Moritz Lipp committed
153
154
} zathura_page_t;

Moritz Lipp's avatar
Moritz Lipp committed
155
156
157
/**
 * Document
 */
Moritz Lipp's avatar
Moritz Lipp committed
158
159
struct zathura_document_s
{
Moritz Lipp's avatar
Moritz Lipp committed
160
161
162
163
164
165
166
  char* file_path; /**> File path of the document */
  const char* password; /**> Password of the document */
  unsigned int current_page_number; /**> Current page number */
  unsigned int number_of_pages; /**> Number of pages */
  double scale; /**> Scale value */
  int rotate; /**> Rotation */
  void* data; /**> Custom data */
Moritz Lipp's avatar
Moritz Lipp committed
167
168
169

  struct
  {
Moritz Lipp's avatar
Moritz Lipp committed
170
171
172
    /**
     * Frees the document
     */
Moritz Lipp's avatar
Moritz Lipp committed
173
    bool (*document_free)(zathura_document_t* document);
Moritz Lipp's avatar
Moritz Lipp committed
174
175
176
177

    /**
     * Generates the document index
     */
178
    girara_tree_node_t* (*document_index_generate)(zathura_document_t* document);
Moritz Lipp's avatar
Moritz Lipp committed
179
180
181
182

    /**
     * Save the document
     */
Moritz Lipp's avatar
Moritz Lipp committed
183
    bool (*document_save_as)(zathura_document_t* document, const char* path);
Moritz Lipp's avatar
Moritz Lipp committed
184
185
186
187

    /**
     * Get list of attachments
     */
Moritz Lipp's avatar
Moritz Lipp committed
188
189
    zathura_list_t* (*document_attachments_get)(zathura_document_t* document);

Moritz Lipp's avatar
Moritz Lipp committed
190
191
192
    /**
     * Gets the page object
     */
193
    zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id);
Moritz Lipp's avatar
Moritz Lipp committed
194
195
196
197

    /**
     * Search text
     */
Moritz Lipp's avatar
Moritz Lipp committed
198
    zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text);
Moritz Lipp's avatar
Moritz Lipp committed
199
200
201
202

    /**
     * Get links on a page
     */
Moritz Lipp's avatar
Moritz Lipp committed
203
    zathura_list_t* (*page_links_get)(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
204
205
206
207

    /**
     * Get form fields
     */
Moritz Lipp's avatar
Moritz Lipp committed
208
    zathura_list_t* (*page_form_fields_get)(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
209
210
211
212

    /**
     * Renders the page
     */
213
    zathura_image_buffer_t* (*page_render)(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
214
215
216
217

    /**
     * Free page
     */
Moritz Lipp's avatar
Moritz Lipp committed
218
    bool (*page_free)(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
219
  } functions;
Moritz Lipp's avatar
Moritz Lipp committed
220

Moritz Lipp's avatar
Moritz Lipp committed
221
222
223
  /**
   * Document pages
   */
Moritz Lipp's avatar
Moritz Lipp committed
224
  zathura_page_t** pages;
Moritz Lipp's avatar
Moritz Lipp committed
225
226
};

Moritz Lipp's avatar
Moritz Lipp committed
227
228
229
/**
 * Load all document plugins
 */
Moritz Lipp's avatar
Moritz Lipp committed
230
void zathura_document_plugins_load(void);
Moritz Lipp's avatar
Moritz Lipp committed
231
232
233
234

/**
 * Free all document plugins
 */
Moritz Lipp's avatar
Moritz Lipp committed
235
void zathura_document_plugins_free(void);
Moritz Lipp's avatar
Moritz Lipp committed
236
237
238
239

/**
 * Register document plugin
 */
240
bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle);
241

Moritz Lipp's avatar
Moritz Lipp committed
242
243
244
245
246
247
248
/**
 * Open the document
 *
 * @param path Path to the document
 * @param password Password of the document or NULL
 * @return The document object
 */
Moritz Lipp's avatar
Moritz Lipp committed
249
zathura_document_t* zathura_document_open(const char* path, const char* password);
Moritz Lipp's avatar
Moritz Lipp committed
250
251
252
253
254
255
256

/**
 * Free the document
 *
 * @param document
 * @return true if no error occured, otherwise false
 */
Moritz Lipp's avatar
Moritz Lipp committed
257
bool zathura_document_free(zathura_document_t* document);
Moritz Lipp's avatar
Moritz Lipp committed
258
259
260
261
262
263
264
265

/**
 * Save the document
 *
 * @param document The document object
 * @param path Path for the saved file
 * @return true if no error occured, otherwise false
 */
Moritz Lipp's avatar
Moritz Lipp committed
266
bool zathura_document_save_as(zathura_document_t* document, const char* path);
Moritz Lipp's avatar
Moritz Lipp committed
267
268
269
270
271
272
273
274

/**
 * Generate the document index
 *
 * @param document The document object
 * @return Generated index
 */

275
girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document);
Moritz Lipp's avatar
Moritz Lipp committed
276
277
278
279
280
281
282

/**
 * Get list of attachments
 *
 * @param document The document object
 * @return List of attachments
 */
Moritz Lipp's avatar
Moritz Lipp committed
283
zathura_list_t* zathura_document_attachments_get(zathura_document_t* document);
Moritz Lipp's avatar
Moritz Lipp committed
284
285
286
287
288
289
290

/**
 * Free document attachments
 *
 * @param list list of document attachments
 * @return
 */
Moritz Lipp's avatar
Moritz Lipp committed
291
292
bool zathura_document_attachments_free(zathura_list_t* list);

Moritz Lipp's avatar
Moritz Lipp committed
293
294
295
296
297
298
299
/**
 * Get the page object
 *
 * @param document The document
 * @param page_id Page number
 * @return Page object or NULL if an error occured
 */
300
zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id);
Moritz Lipp's avatar
Moritz Lipp committed
301
302
303
304
305
306
307

/**
 * Frees the page object
 *
 * @param page The page object
 * @return true if no error occured, otherwise false
 */
Moritz Lipp's avatar
Moritz Lipp committed
308
bool zathura_page_free(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
309
310
311
312
313
314
315
316

/**
 * Search page
 *
 * @param page The page object
 * @param text Search item
 * @return List of results
 */
Moritz Lipp's avatar
Moritz Lipp committed
317
zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text);
Moritz Lipp's avatar
Moritz Lipp committed
318
319
320
321
322
323
324

/**
 * Get page links
 *
 * @param page The page object
 * @return List of links
 */
Moritz Lipp's avatar
Moritz Lipp committed
325
zathura_list_t* zathura_page_links_get(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
326
327
328
329
330
331
332

/**
 * Free page links
 *
 * @param list List of links
 * @return true if no error occured, otherwise false
 */
Moritz Lipp's avatar
Moritz Lipp committed
333
bool zathura_page_links_free(zathura_list_t* list);
Moritz Lipp's avatar
Moritz Lipp committed
334
335
336
337
338
339
340

/**
 * Get list of form fields
 *
 * @param page The page object
 * @return List of form fields
 */
Moritz Lipp's avatar
Moritz Lipp committed
341
zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
342
343
344
345
346
347
348

/**
 * Free list of form fields
 *
 * @param list List of form fields
 * @return true if no error occured, otherwise false
 */
Moritz Lipp's avatar
Moritz Lipp committed
349
bool zathura_page_form_fields_free(zathura_list_t* list);
Moritz Lipp's avatar
Moritz Lipp committed
350
351
352
353
354

/**
 * Render page
 *
 * @param page The page object
355
 * @return Image buffer or NULL if an error occured
Moritz Lipp's avatar
Moritz Lipp committed
356
 */
357
zathura_image_buffer_t* zathura_page_render(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
358

Moritz Lipp's avatar
Moritz Lipp committed
359
360
361
362
363
364
/**
 * Create new index element
 *
 * @param title Title of the index element
 * @return Index element
 */
365
zathura_index_element_t* zathura_index_element_new(const char* title);
Moritz Lipp's avatar
Moritz Lipp committed
366
367
368
369
370
371

/**
 * Free index element
 *
 * @param index The index element
 */
372
373
void zathura_index_element_free(zathura_index_element_t* index);

Moritz Lipp's avatar
Moritz Lipp committed
374
#endif // DOCUMENT_H