Add function to get page labels

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2018-02-03 13:26:39 +01:00
parent c4ef771c51
commit bba265ccfe
3 changed files with 54 additions and 2 deletions

View file

@ -359,3 +359,34 @@ zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing)
return functions->page_render_cairo(page, page->data, cairo, printing);
}
char*
zathura_page_get_label(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);
zathura_plugin_functions_t* functions = zathura_plugin_get_functions(plugin);
if (functions->page_get_label == NULL) {
if (error) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
char* ret = NULL;
zathura_error_t e = functions->page_get_label(page, page->data, &ret);
if (e != ZATHURA_ERROR_OK) {
if (error) {
*error = e;
}
return NULL;
}
return ret;
}

View file

@ -203,4 +203,15 @@ char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle,
*/
zathura_error_t zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing);
/**
* Get page label. Note that the page label might not exist, in this case NULL
* is returned.
*
* @param page Page
* @param error Set to an error value (see \ref zathura_Error_t) if an error
* occurred.
* @return Page label
*/
char* zathura_page_get_label(zathura_page_t* page, zathura_error_t* error);
#endif // PAGE_H

View file

@ -91,10 +91,15 @@ typedef char* (*zathura_plugin_page_get_text_t)(zathura_page_t* page, void* data
typedef zathura_image_buffer_t* (*zathura_plugin_page_render_t)(zathura_page_t* page, void* data, zathura_error_t* error);
/**
* Renders the page
* Renders the page to a cairo surface.
*/
typedef zathura_error_t (*zathura_plugin_page_render_cairo_t)(zathura_page_t* page, void* data, cairo_t* cairo, bool printing);
/**
* Get page label.
*/
typedef zathura_error_t (*zathura_plugin_page_get_label_t)(zathura_page_t* page, void* data, char** label);
struct zathura_plugin_functions_s
{
@ -179,9 +184,14 @@ struct zathura_plugin_functions_s
zathura_plugin_page_render_t page_render;
/**
* Renders the page
* Renders the page to a cairo surface.
*/
zathura_plugin_page_render_cairo_t page_render_cairo;
/**
* Get page label.
*/
zathura_plugin_page_get_label_t page_get_label;
};
/**