From 1ecd8d69c6f5593876947bc86541a9d0d2e41f5b Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 26 Oct 2023 21:46:51 +0200 Subject: [PATCH] Add new function to get signatures from pages --- zathura/page.c | 38 ++++++++++++++++++++++++++++++++++++++ zathura/page.h | 12 +++++++++++- zathura/plugin-api.h | 9 +++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/zathura/page.c b/zathura/page.c index 8c7be99..f228e69 100644 --- a/zathura/page.c +++ b/zathura/page.c @@ -412,3 +412,41 @@ zathura_page_get_label(zathura_page_t* page, zathura_error_t* error) return ret; } + +static void +sig_free(void* sig) +{ + zathura_signature_info_free(sig); +} + +girara_list_t* +zathura_page_get_signatures(zathura_page_t* page, zathura_error_t* error) +{ + if (page == NULL || page->document == NULL) { + if (error) { + *error = ZATHURA_ERROR_INVALID_ARGUMENTS; + } + return NULL; + } + + zathura_plugin_t* plugin = zathura_document_get_plugin(page->document); + const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(plugin); + if (functions->page_get_signatures == NULL) { + if (error) { + *error = ZATHURA_ERROR_NOT_IMPLEMENTED; + } + return NULL; + } + + girara_list_t* ret = girara_list_new2(sig_free); + zathura_error_t e = functions->page_get_signatures(page, page->data, ret); + if (e != ZATHURA_ERROR_OK) { + if (error) { + *error = e; + } + girara_list_free(ret); + return NULL; + } + + return ret; +} diff --git a/zathura/page.h b/zathura/page.h index da14278..9324ca5 100644 --- a/zathura/page.h +++ b/zathura/page.h @@ -218,10 +218,20 @@ ZATHURA_PLUGIN_API zathura_error_t zathura_page_render(zathura_page_t* page, cai * is returned. * * @param page Page - * @param error Set to an error value (see \ref zathura_Error_t) if an error + * @param error Set to an error value (see \ref zathura_error_t) if an error * occurred. * @return Page label */ ZATHURA_PLUGIN_API char* zathura_page_get_label(zathura_page_t* page, zathura_error_t* error); +/** + * Get signatures of a page + * + * @param page Page + * @param error Set to an error value (see \ref zathura_error_t) if an error + * occurred. + * @return List of signatures + */ +ZATHURA_PLUGIN_API girara_list_t* zathura_page_get_signatures(zathura_page_t* page, zathura_error_t* error); + #endif // PAGE_H diff --git a/zathura/plugin-api.h b/zathura/plugin-api.h index c090918..da3901f 100644 --- a/zathura/plugin-api.h +++ b/zathura/plugin-api.h @@ -108,6 +108,10 @@ typedef zathura_error_t (*zathura_plugin_page_render_cairo_t)(zathura_page_t* pa */ typedef zathura_error_t (*zathura_plugin_page_get_label_t)(zathura_page_t* page, void* data, char** label); +/** + * Get signatures + */ +typedef zathura_error_t (*zathura_plugin_page_get_signatures)(zathura_page_t* page, void* data, girara_list_t*); struct zathura_plugin_functions_s { @@ -205,6 +209,11 @@ struct zathura_plugin_functions_s * Get page label. */ zathura_plugin_page_get_label_t page_get_label; + + /** + * Get signatures. + */ + zathura_plugin_page_get_signatures page_get_signatures; }; typedef struct zathura_plugin_version_s {