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

#ifndef PDF_H
#define PDF_H

6 7
#include <stdlib.h>
#include <string.h>
8
#include <stdbool.h>
9
#include <zathura/plugin-api.h>
10
#include <mupdf/fitz.h>
11 12
#include <cairo.h>

13
typedef struct mupdf_document_s
14
{
15
  fz_context* ctx; /**< Context */
16
  fz_document* document; /**< mupdf document */
17
} mupdf_document_t;
18 19 20

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

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

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

44 45 46 47 48
/**
 * Saves the document to the given path
 *
 * @param document Zathura document
 * @param path File path
49
 * @return ZATHURA_ERROR_OK when no error occurred, otherwise see
50 51 52 53 54
 *    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
55 56 57 58 59
/**
 * Generates the index of the document
 *
 * @param document Zathura document
 * @param error Set to an error value (see zathura_error_t) if an
60
 *   error occurred
Moritz Lipp's avatar
Moritz Lipp committed
61 62 63 64 65 66
 * @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
67 68 69
/**
 * Returns a reference to a page
 *
70
 * @param page Page object
71
 * @return A page object or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
72
 */
73
zathura_error_t pdf_page_init(zathura_page_t* page);
Moritz Lipp's avatar
Moritz Lipp committed
74 75 76 77 78

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

/**
 * Searches for a specific text on a page and returns a list of results
 *
 * @param page Page
 * @param text Search item
88
 * @param error Set to an error value (see zathura_error_t) if an
89 90
 *   error occurred
 * @return List of search results or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
91
 */
92
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
93 94 95 96 97

/**
 * Returns a list of internal/external links that are shown on the given page
 *
 * @param page Page
98
 * @param error Set to an error value (see zathura_error_t) if an
99 100
 *   error occurred
 * @return List of links or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
101
 */
102
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
103

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

114 115 116 117 118 119
/**
 * 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
120 121
 *   error occurred
 * @return The cairo image surface or NULL if an error occurred
122 123 124 125
 */
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);

126 127 128 129
/**
 * Get text for selection
 * @param page Page
 * @param rectangle Selection
130
 * @error Set to an error value (see \ref zathura_error_t) if an error
131
 * occurred
132 133
 * @return The selected text (needs to be deallocated with g_free)
 */
134
char* pdf_page_get_text(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_rectangle_t rectangle, zathura_error_t* error);
135

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

Moritz Lipp's avatar
Moritz Lipp committed
147 148 149 150 151
/**
 * Renders a page and returns a allocated image buffer which has to be freed
 * with zathura_image_buffer_free
 *
 * @param page Page
152
 * @param error Set to an error value (see zathura_error_t) if an
153 154
 *   error occurred
 * @return Image buffer or NULL if an error occurred
Moritz Lipp's avatar
Moritz Lipp committed
155
 */
156
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
157 158 159 160 161 162

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

#endif // PDF_H