mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 10:06:01 +01:00
Update zathura_page plugin functions
This commit is contained in:
parent
efc108fbe2
commit
1133207a48
5 changed files with 51 additions and 36 deletions
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ include common.mk
|
||||||
PROJECT = zathura
|
PROJECT = zathura
|
||||||
OSOURCE = $(wildcard *.c)
|
OSOURCE = $(wildcard *.c)
|
||||||
HEADER = $(wildcard *.h)
|
HEADER = $(wildcard *.h)
|
||||||
HEADERINST = version.h zathura.h document.h macros.h
|
HEADERINST = version.h zathura.h document.h macros.h page.h
|
||||||
|
|
||||||
ifneq (${WITH_SQLITE},0)
|
ifneq (${WITH_SQLITE},0)
|
||||||
INCS += $(SQLITE_INC)
|
INCS += $(SQLITE_INC)
|
||||||
|
|
|
@ -372,7 +372,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
|
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
|
||||||
zathura_page_t* page = zathura_page_get(document, page_id, NULL);
|
zathura_page_t* page = zathura_page_new(document, page_id, NULL);
|
||||||
if (page == NULL) {
|
if (page == NULL) {
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
12
document.h
12
document.h
|
@ -284,7 +284,12 @@ struct zathura_document_s
|
||||||
/**
|
/**
|
||||||
* Gets the page object
|
* Gets the page object
|
||||||
*/
|
*/
|
||||||
zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id, zathura_plugin_error_t* error);
|
zathura_plugin_error_t (*page_init)(zathura_page_t* page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free page
|
||||||
|
*/
|
||||||
|
zathura_plugin_error_t (*page_clear)(zathura_page_t* page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search text
|
* Search text
|
||||||
|
@ -325,11 +330,6 @@ struct zathura_document_s
|
||||||
* Renders the page
|
* Renders the page
|
||||||
*/
|
*/
|
||||||
zathura_plugin_error_t (*page_render_cairo)(zathura_page_t* page, cairo_t* cairo, bool printing);
|
zathura_plugin_error_t (*page_render_cairo)(zathura_page_t* page, cairo_t* cairo, bool printing);
|
||||||
|
|
||||||
/**
|
|
||||||
* Free page
|
|
||||||
*/
|
|
||||||
zathura_plugin_error_t (*page_free)(zathura_page_t* page);
|
|
||||||
} functions;
|
} functions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
50
page.c
50
page.c
|
@ -20,7 +20,7 @@ struct zathura_page_s {
|
||||||
};
|
};
|
||||||
|
|
||||||
zathura_page_t*
|
zathura_page_t*
|
||||||
zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plugin_error_t* error)
|
zathura_page_new(zathura_document_t* document, unsigned int id, zathura_plugin_error_t* error)
|
||||||
{
|
{
|
||||||
if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) {
|
if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) {
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
|
@ -29,9 +29,23 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plu
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_page_t* page = NULL;
|
/* init page */
|
||||||
|
zathura_page_t* page = g_malloc0(sizeof(zathura_page_t));
|
||||||
|
|
||||||
if (document->functions.page_get == NULL) {
|
page->id = id;
|
||||||
|
page->visible = false;
|
||||||
|
page->document = document;
|
||||||
|
page->widget = zathura_page_widget_new(page);
|
||||||
|
|
||||||
|
if (page->widget == NULL) {
|
||||||
|
if (error != NULL) {
|
||||||
|
*error = ZATHURA_PLUGIN_ERROR_UNKNOWN;
|
||||||
|
}
|
||||||
|
goto error_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* init plugin */
|
||||||
|
if (document->functions.page_init == NULL) {
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
|
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
|
||||||
girara_error("%s not implemented", __FUNCTION__);
|
girara_error("%s not implemented", __FUNCTION__);
|
||||||
|
@ -40,27 +54,20 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plu
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
page = document->functions.page_get(document, page_id, error);
|
zathura_plugin_error_t ret = document->functions.page_init(page);
|
||||||
|
if (ret != ZATHURA_PLUGIN_ERROR_OK) {
|
||||||
if (page != NULL) {
|
|
||||||
page->id = page_id;
|
|
||||||
page->visible = false;
|
|
||||||
page->document = document;
|
|
||||||
|
|
||||||
page->widget = zathura_page_widget_new(page);
|
|
||||||
if (page->widget == NULL) {
|
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
*error = ZATHURA_PLUGIN_ERROR_UNKNOWN;
|
*error = ret;
|
||||||
}
|
}
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set widget size */
|
||||||
unsigned int page_height = 0;
|
unsigned int page_height = 0;
|
||||||
unsigned int page_width = 0;
|
unsigned int page_width = 0;
|
||||||
page_calc_height_width(page, &page_height, &page_width, true);
|
page_calc_height_width(page, &page_height, &page_width, true);
|
||||||
|
|
||||||
gtk_widget_set_size_request(page->widget, page_width, page_height);
|
gtk_widget_set_size_request(page->widget, page_width, page_height);
|
||||||
}
|
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
|
|
||||||
|
@ -78,17 +85,26 @@ error_ret:
|
||||||
zathura_plugin_error_t
|
zathura_plugin_error_t
|
||||||
zathura_page_free(zathura_page_t* page)
|
zathura_page_free(zathura_page_t* page)
|
||||||
{
|
{
|
||||||
if (page == NULL || page->document == NULL || page->document->zathura == NULL || page->document->zathura->ui.session == NULL) {
|
if (page == NULL) {
|
||||||
return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS;
|
return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page->document->functions.page_free == NULL) {
|
if (page->document == NULL || page->document->zathura == NULL || page->document->zathura->ui.session == NULL) {
|
||||||
|
g_free(page);
|
||||||
|
return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page->document->functions.page_clear == NULL) {
|
||||||
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
|
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
|
||||||
girara_error("%s not implemented", __FUNCTION__);
|
girara_error("%s not implemented", __FUNCTION__);
|
||||||
return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED;
|
return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return page->document->functions.page_free(page);
|
zathura_plugin_error_t error = page->document->functions.page_clear(page);
|
||||||
|
|
||||||
|
g_free(page);
|
||||||
|
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_document_t*
|
zathura_document_t*
|
||||||
|
|
5
page.h
5
page.h
|
@ -12,11 +12,10 @@
|
||||||
*
|
*
|
||||||
* @param document The document
|
* @param document The document
|
||||||
* @param id Page number
|
* @param id Page number
|
||||||
* @param error Set to an error value (see \ref zathura_plugin_error_t) if an
|
* @param error Optional error
|
||||||
* error occured
|
|
||||||
* @return Page object or NULL if an error occured
|
* @return Page object or NULL if an error occured
|
||||||
*/
|
*/
|
||||||
zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plugin_error_t* error);
|
zathura_page_t* zathura_page_new(zathura_document_t* document, unsigned int id, zathura_plugin_error_t* error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees the page object
|
* Frees the page object
|
||||||
|
|
Loading…
Reference in a new issue