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

#ifndef PDF_H
#define PDF_H

#include <stdbool.h>
7
#include <zathura/plugin-api.h>
8
#include <mupdf/fitz.h>
Moritz Lipp's avatar
Moritz Lipp committed
9

10 11 12 13
#if HAVE_CAIRO
#include <cairo.h>
#endif

14
typedef struct mupdf_document_s
Moritz Lipp's avatar
Moritz Lipp committed
15
{
16
  fz_context* ctx; /**< Context */
Moritz Lipp's avatar
Moritz Lipp committed
17
  fz_document* document; /**< mupdf document */
18
} mupdf_document_t;
Moritz Lipp's avatar
Moritz Lipp committed
19 20 21

typedef struct mupdf_page_s
{
Moritz Lipp's avatar
Moritz Lipp committed
22
  fz_page* page; /**< Reference to the mupdf page */
23
  fz_context* ctx; /**< Context */
Christian Hesse's avatar
Christian Hesse committed
24 25
  fz_stext_sheet* sheet; /**< Text sheet */
  fz_stext_page* text; /**< Page text */
Moritz Lipp's avatar
Moritz Lipp committed
26
  fz_rect bbox; /**< Bbox */
Moritz Lipp's avatar
Moritz Lipp committed
27
  bool extracted_text; /**< If text has already been extracted */
Moritz Lipp's avatar
Moritz Lipp committed
28 29
} mupdf_page_t;

Moritz Lipp's avatar
Moritz Lipp committed
30 31 32 33
/**
 * Open a pdf document
 *
 * @param document Zathura document
34
 * @return true if no error occurred, otherwise false
Moritz Lipp's avatar
Moritz Lipp committed
35
 */
36
zathura_error_t pdf_document_open(zathura_document_t* document);
Moritz Lipp's avatar
Moritz Lipp committed
37 38 39 40 41

/**
 * Closes and frees the internal document structure
 *
 * @param document Zathura document
42
 * @return true if no error occurred, otherwise false
Moritz Lipp's avatar
Moritz Lipp committed
43
 */
44
zathura_error_t pdf_document_free(zathura_document_t* document, mupdf_document_t* mupdf_document);
Moritz Lipp's avatar
Moritz Lipp committed
45

46 47 48 49 50
/**
 * Saves the document to the given path
 *
 * @param document Zathura document
 * @param path File path
51
 * @return ZATHURA_ERROR_OK when no error occurred, otherwise see
52 53 54 55 56
 *    zathura_error_t
 */
zathura_error_t pdf_document_save_as(zathura_document_t* document,
    mupdf_document_t* mupdf_document, const char* path);

Moritz Lipp's avatar
Moritz Lipp committed
57 58 59 60 61
/**
 * Generates the index of the document
 *
 * @param document Zathura document
 * @param error Set to an error value (see zathura_error_t) if an
62
 *   error occurred
Moritz Lipp's avatar
Moritz Lipp committed
63 64 65 66 67 68
 * @return Tree node object or NULL if an error occurred (e.g.: the document has
 *   no index)
 */
girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document,
    mupdf_document_t* mupdf_document, zathura_error_t* error);

Moritz Lipp's avatar
Moritz Lipp committed
69 70 71
/**
 * Returns a reference to a page
 *
Moritz Lipp's avatar
Moritz Lipp committed
72
 * @param page Page object
73
 * @return A page object or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
74
 */
75
zathura_error_t pdf_page_init(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
76 77 78 79 80

/**
 * Frees a pdf page
 *
 * @param page Page
81
 * @return true if no error occurred, otherwise false
Moritz Lipp's avatar
Moritz Lipp committed
82
 */
83
zathura_error_t pdf_page_clear(zathura_page_t* page, mupdf_page_t* mupdf_page);
Moritz Lipp's avatar
Moritz Lipp committed
84 85 86 87 88 89

/**
 * Searches for a specific text on a page and returns a list of results
 *
 * @param page Page
 * @param text Search item
90
 * @param error Set to an error value (see zathura_error_t) if an
91 92
 *   error occurred
 * @return List of search results or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
93
 */
94
girara_list_t* pdf_page_search_text(zathura_page_t* page, mupdf_page_t* mupdf_page, const char* text, zathura_error_t* error);
Moritz Lipp's avatar
Moritz Lipp committed
95 96 97 98 99

/**
 * Returns a list of internal/external links that are shown on the given page
 *
 * @param page Page
100
 * @param error Set to an error value (see zathura_error_t) if an
101 102
 *   error occurred
 * @return List of links or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
103
 */
104
girara_list_t* pdf_page_links_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t* error);
Moritz Lipp's avatar
Moritz Lipp committed
105

106 107 108 109
/**
 * Returns a list of images included on the zathura page
 *
 * @param page The page
110
 * @param error Set to an error value (see zathura_error_t) if an
111
 *   error occurred
112 113
 * @return List of images
 */
114
girara_list_t* pdf_page_images_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t* error);
115

116 117 118 119 120 121 122
#if HAVE_CAIRO
/**
 * Gets the content of the image in a cairo surface
 *
 * @param page Page
 * @param image Image identifier
 * @param error Set to an error value (see \ref zathura_error_t) if an
123 124
 *   error occurred
 * @return The cairo image surface or NULL if an error occurred
125 126 127 128 129
 */
cairo_surface_t* pdf_page_image_get_cairo(zathura_page_t* page, mupdf_page_t*
    mupdf_page, zathura_image_t* image, zathura_error_t* error);
#endif

Moritz Lipp's avatar
Moritz Lipp committed
130 131 132 133
/**
 * Get text for selection
 * @param page Page
 * @param rectangle Selection
134
 * @error Set to an error value (see \ref zathura_error_t) if an error
135
 * occurred
Moritz Lipp's avatar
Moritz Lipp committed
136 137
 * @return The selected text (needs to be deallocated with g_free)
 */
138
char* pdf_page_get_text(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_rectangle_t rectangle, zathura_error_t* error);
Moritz Lipp's avatar
Moritz Lipp committed
139

140
/**
141
 * Returns a list of document information entries of the document
142 143
 *
 * @param document Zathura document
144
 * @param error Set to an error value (see zathura_error_t) if an
145
 *   error occurred
146
 * @return List of information entries or NULL if an error occurred
147
 */
148 149
girara_list_t* pdf_document_get_information(zathura_document_t* document,
    mupdf_document_t* mupdf_document, zathura_error_t* error);
150

Moritz Lipp's avatar
Moritz Lipp committed
151 152 153 154 155
/**
 * Renders a page and returns a allocated image buffer which has to be freed
 * with zathura_image_buffer_free
 *
 * @param page Page
156
 * @param error Set to an error value (see zathura_error_t) if an
157 158
 *   error occurred
 * @return Image buffer or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
159
 */
160
zathura_image_buffer_t* pdf_page_render(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t* error);
Moritz Lipp's avatar
Moritz Lipp committed
161

162
#if HAVE_CAIRO
Moritz Lipp's avatar
Moritz Lipp committed
163 164 165 166 167
/**
 * Renders a page onto a cairo object
 *
 * @param page Page
 * @param cairo Cairo object
168
 * @return  true if no error occurred, otherwise false
Moritz Lipp's avatar
Moritz Lipp committed
169
 */
170
zathura_error_t pdf_page_render_cairo(zathura_page_t* page, mupdf_page_t* mupdf_page, cairo_t* cairo, bool printing);
171
#endif
Moritz Lipp's avatar
Moritz Lipp committed
172 173

#endif // PDF_H