1 2 3 4 5 6 7 8 9 10 11 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/* See LICENSE file for license and copyright information */
#include "plugin.h"
#include "utils.h"
static void pdf_zathura_image_free(void* image);
girara_list_t*
pdf_page_images_get(zathura_page_t* page, void* data, zathura_error_t* error)
{
if (page == NULL || data == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
goto error_ret;
}
girara_list_t* list = NULL;
GList* image_mapping = NULL;
PopplerPage* poppler_page = data;
image_mapping = poppler_page_get_image_mapping(poppler_page);
if (image_mapping == NULL || g_list_length(image_mapping) == 0) {
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
goto error_free;
}
list = girara_list_new();
if (list == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_OUT_OF_MEMORY;
}
goto error_free;
}
girara_list_set_free_function(list, pdf_zathura_image_free);
for (GList* image = image_mapping; image != NULL; image = g_list_next(image)) {
zathura_image_t* zathura_image = g_malloc0(sizeof(zathura_image_t));
PopplerImageMapping* poppler_image = (PopplerImageMapping*) image->data;
/* extract id */
zathura_image->data = g_malloc(sizeof(gint));
gint* image_id = zathura_image->data;
*image_id = poppler_image->image_id;
/* extract position */
zathura_image->position.x1 = poppler_image->area.x1;
zathura_image->position.x2 = poppler_image->area.x2;
zathura_image->position.y1 = poppler_image->area.y1;
zathura_image->position.y2 = poppler_image->area.y2;
girara_list_append(list, zathura_image);
}
poppler_page_free_image_mapping(image_mapping);
return list;
error_free:
if (list != NULL) {
girara_list_free(list);
}
if (image_mapping != NULL) {
poppler_page_free_image_mapping(image_mapping);
}
error_ret:
return NULL;
}
cairo_surface_t*
pdf_page_image_get_cairo(zathura_page_t* page, void* data,
zathura_image_t* image, zathura_error_t* error)
{
if (page == NULL || data == NULL || image == NULL || image->data == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
goto error_ret;
}
gint* image_id = (gint*) image->data;
PopplerPage* poppler_page = data;
cairo_surface_t* surface = poppler_page_get_image(poppler_page, *image_id);
if (surface == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
goto error_ret;
}
return surface;
error_ret:
return NULL;
}
static void
pdf_zathura_image_free(void* data)
{
if (data == NULL) {
return;
}
zathura_image_t* image = data;
if (image->data != NULL) {
g_free(image->data);
}
g_free(image);
}
|