Commit 334b4fbb authored by Moritz Lipp's avatar Moritz Lipp

Introduce and use zathura_document wrapper functions

parent c82c2aaf
......@@ -34,7 +34,8 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
girara_list_append(zathura->bookmarks.bookmarks, bookmark);
if (zathura->database != NULL) {
if (zathura_db_add_bookmark(zathura->database, zathura->document->file_path, bookmark) == false) {
const char* path = zathura_document_get_path(zathura->document);
if (zathura_db_add_bookmark(zathura->database, path, bookmark) == false) {
girara_warning("Failed to add bookmark to database.");
}
}
......@@ -54,7 +55,8 @@ zathura_bookmark_remove(zathura_t* zathura, const gchar* id)
}
if (zathura->database != NULL) {
if (zathura_db_remove_bookmark(zathura->database, zathura->document->file_path, bookmark->id) == false) {
const char* path = zathura_document_get_path(zathura->document);
if (zathura_db_remove_bookmark(zathura->database, path, bookmark->id) == false) {
girara_warning("Failed to remove bookmark from database.");
}
}
......
......@@ -51,8 +51,7 @@ void
cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpointer data)
{
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL || zathura->document->pages == NULL
|| zathura->ui.page_widget == NULL) {
if (zathura == NULL || zathura->document == NULL || zathura->ui.page_widget == NULL) {
return;
}
......@@ -74,23 +73,26 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
center.y = (view_rect.height + 1) / 2;
center.height = center.width = (2 * page_padding) + 1;
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
double scale = zathura_document_get_scale(zathura->document);
bool updated = false;
/* find page that fits */
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
zathura_page_t* page = zathura->document->pages[page_id];
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
GdkRectangle page_rect;
GtkWidget* page_widget = zathura_page_get_widget(page);
gtk_widget_translate_coordinates(page_widget,
zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y);
page_rect.width = zathura_page_get_width(page) * zathura->document->scale;
page_rect.height = zathura_page_get_height(page) * zathura->document->scale;
page_rect.width = zathura_page_get_width(page) * scale;
page_rect.height = zathura_page_get_height(page) * scale;
if (gdk_rectangle_intersect(&view_rect, &page_rect, NULL) == TRUE) {
zathura_page_set_visibility(page, true);
if (zathura->global.update_page_number == true && updated == false
&& gdk_rectangle_intersect(&center, &page_rect, NULL) == TRUE) {
zathura->document->current_page_number = page_id;
zathura_document_set_current_page_number(zathura->document, page_id);
updated = true;
}
} else {
......@@ -119,7 +121,7 @@ cb_pages_per_row_value_changed(girara_session_t* session, const char* UNUSED(nam
page_widget_set_mode(zathura, pages_per_row);
if (zathura->document != NULL) {
unsigned int current_page = zathura->document->current_page_number;
unsigned int current_page = zathura_document_get_current_page_number(zathura->document);
page_set_delayed(zathura, current_page);
}
}
......@@ -185,8 +187,9 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session)
/* set pages to draw links */
bool invalid_index = true;
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
zathura_page_t* page = zathura->document->pages[page_id];
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL || zathura_page_get_visibility(page) == false) {
continue;
}
......@@ -322,7 +325,7 @@ cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* allocation, zathura_t*
/* adjust only if the allocation changed */
if (width != allocation->width || height != allocation->height) {
girara_argument_t argument = { zathura->document->adjust_mode, NULL };
girara_argument_t argument = { zathura_document_get_adjust_mode(zathura->document), NULL };
sc_adjust_window(zathura->ui.session, &argument, NULL, 0);
width = allocation->width;
......
......@@ -40,12 +40,12 @@ cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list)
const char* bookmark_name = girara_list_nth(argument_list, 0);
zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, bookmark_name);
if (bookmark != NULL) {
bookmark->page = zathura->document->current_page_number + 1;
bookmark->page = zathura_document_get_current_page_number(zathura->document) + 1;
girara_notify(session, GIRARA_INFO, _("Bookmark successfuly updated: %s"), bookmark_name);
return true;
}
bookmark = zathura_bookmark_add(zathura, bookmark_name, zathura->document->current_page_number + 1);
bookmark = zathura_bookmark_add(zathura, bookmark_name, zathura_document_get_current_page_number(zathura->document) + 1);
if (bookmark == NULL) {
girara_notify(session, GIRARA_ERROR, _("Could not create bookmark: %s"), bookmark_name);
return false;
......@@ -304,8 +304,13 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu
bool firsthit = true;
zathura_error_t error = ZATHURA_ERROR_OK;
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; ++page_id) {
zathura_page_t* page = zathura->document->pages[(page_id + zathura->document->current_page_number) % zathura->document->number_of_pages];
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document);
for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) {
unsigned int index = (page_id + current_page_number) % number_of_pages;
zathura_page_t* page = zathura_document_get_page(zathura->document, index);
if (page == NULL) {
continue;
}
......@@ -385,7 +390,7 @@ cmd_offset(girara_session_t* session, girara_list_t* argument_list)
}
/* no argument: take current page as offset */
unsigned int page_offset = zathura->document->current_page_number;
unsigned int page_offset = zathura_document_get_current_page_number(zathura->document);
/* retrieve offset from argument */
if (girara_list_size(argument_list) == 1) {
......@@ -399,8 +404,8 @@ cmd_offset(girara_session_t* session, girara_list_t* argument_list)
}
}
if (page_offset < zathura->document->number_of_pages) {
zathura->document->page_offset = page_offset;
if (page_offset < zathura_document_get_number_of_pages(zathura->document)) {
zathura_document_set_page_offset(zathura->document, page_offset);
}
return true;
......
......@@ -126,8 +126,8 @@ config_load_default(zathura_t* zathura)
girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c, NULL, sc_abort, 0, 0, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_Escape, NULL, sc_abort, 0, 0, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, NORMAL, ZATHURA_ADJUST_BESTFIT, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_s, NULL, sc_adjust_window, NORMAL, ZATHURA_ADJUST_WIDTH, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL);
girara_shortcut_add(gsession, 0, GDK_KEY_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL);
......@@ -302,8 +302,8 @@ config_load_default(zathura_t* zathura)
girara_argument_mapping_add(gsession, "specific", ZOOM_SPECIFIC);
girara_argument_mapping_add(gsession, "top", TOP);
girara_argument_mapping_add(gsession, "up", UP);
girara_argument_mapping_add(gsession, "best-fit", ADJUST_BESTFIT);
girara_argument_mapping_add(gsession, "width", ADJUST_WIDTH);
girara_argument_mapping_add(gsession, "best-fit", ZATHURA_ADJUST_BESTFIT);
girara_argument_mapping_add(gsession, "width", ZATHURA_ADJUST_WIDTH);
girara_argument_mapping_add(gsession, "rotate-cw", ROTATE_CW);
girara_argument_mapping_add(gsession, "rotate-ccw", ROTATE_CCW);
}
......
This diff is collapsed.
......@@ -26,33 +26,6 @@ typedef enum zathura_document_meta_e
ZATHURA_DOCUMENT_MODIFICATION_DATE /**< Modification data */
} zathura_document_meta_t;
/**
* Document
*/
struct zathura_document_s
{
char* file_path; /**< File path of the document */
const char* password; /**< Password of the document */
unsigned int current_page_number; /**< Current page number */
unsigned int number_of_pages; /**< Number of pages */
double scale; /**< Scale value */
unsigned int rotate; /**< Rotation */
void* data; /**< Custom data */
zathura_t* zathura; /** Zathura object */
int adjust_mode; /**< Adjust mode (best-fit, width) */
unsigned int page_offset; /**< Page offset */
/**
* Document pages
*/
zathura_page_t** pages;
/**
* Used plugin
*/
zathura_plugin_t* plugin;
};
/**
* Open the document
*
......@@ -64,6 +37,15 @@ struct zathura_document_s
zathura_document_t* zathura_document_open(zathura_t* zathura, const char* path,
const char* password);
/**
* Free the document
*
* @param document
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* zathura_error_t
*/
zathura_error_t zathura_document_free(zathura_document_t* document);
/**
* Returns the path of the document
*
......@@ -81,21 +63,13 @@ const char* zathura_document_get_path(zathura_document_t* document);
const char* zathura_document_get_password(zathura_document_t* document);
/**
* Free the document
*
* @param document
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* zathura_error_t
*/
zathura_error_t zathura_document_free(zathura_document_t* document);
/**
* Returns the private data of the document
* Returns the page at the given index
*
* @param document The document
* @return The private data or NULL
* @param index The index of the page
* @return The page or NULL if an error occured
*/
void* zathura_document_get_data(zathura_document_t* document);
zathura_page_t* zathura_document_get_page(zathura_document_t* document, unsigned int index);
/**
* Returns the number of pages
......@@ -120,7 +94,7 @@ void zathura_document_set_number_of_pages(zathura_document_t* document, unsigned
* @param document The document
* @return Current page
*/
unsigned int zathura_document_get_current_page(zathura_document_t* document);
unsigned int zathura_document_get_current_page_number(zathura_document_t* document);
/**
* Sets the number of pages
......@@ -128,9 +102,81 @@ unsigned int zathura_document_get_current_page(zathura_document_t* document);
* @param document The document
* @param current_page The current page number
*/
void zathura_document_set_current_page(zathura_document_t* document, unsigned
void zathura_document_set_current_page_number(zathura_document_t* document, unsigned
int current_page);
/**
* Returns the current scale value of the document
*
* @param document The document
* @return The current scale value
*/
double zathura_document_get_scale(zathura_document_t* document);
/**
* Sets the new scale value of the document
*
* @param document The document
* @param scale The new scale value
*/
void zathura_document_set_scale(zathura_document_t* document, double scale);
/**
* Returns the rotation value of zathura (0..360)
*
* @param document The document
* @return The current rotation value
*/
unsigned int zathura_document_get_rotation(zathura_document_t* document);
/**
* Sets the new rotation value
*
* @param document The document
* @param rotation The new rotation value
*/
void zathura_document_set_rotation(zathura_document_t* document, unsigned int rotation);
/**
* Returns the adjust mode of the document
*
* @param document The document
* @return The adjust mode
*/
zathura_adjust_mode_t zathura_document_get_adjust_mode(zathura_document_t* document);
/**
* Sets the new adjust mode of the document
*
* @param document The document
* @param mode The new adjust mode
*/
void zathura_document_set_adjust_mode(zathura_document_t* document, zathura_adjust_mode_t mode);
/**
* Returns the page offset of the document
*
* @param document The document
* @return The page offset
*/
unsigned int zathura_document_get_page_offset(zathura_document_t* document);
/**
* Sets the new page offset of the document
*
* @param document The document
* @param page_offset The new page offset
*/
void zathura_document_set_page_offset(zathura_document_t* document, unsigned int page_offset);
/**
* Returns the private data of the document
*
* @param document The document
* @return The private data or NULL
*/
void* zathura_document_get_data(zathura_document_t* document);
/**
* Sets the private data of the document
*
......
......@@ -4,6 +4,7 @@
#define INTERNAL_H
#include "zathura.h"
#include "plugin.h"
/**
* Zathura password dialog
......@@ -14,4 +15,21 @@ typedef struct zathura_password_dialog_info_s
zathura_t* zathura; /**< Zathura session */
} zathura_password_dialog_info_t;
/**
* Returns the associated zathura instance
* TODO: Separate zathura_t completely from the document
*
* @param document The docment
* @return The associated zathura instance
*/
zathura_t* zathura_document_get_zathura(zathura_document_t* document);
/**
* Returns the associated plugin
*
* @param document The document
* @return The plugin or NULL
*/
zathura_plugin_t* zathura_document_get_plugin(zathura_document_t* document);
#endif // INTERNAL_H
......@@ -179,7 +179,7 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v
case PROP_PAGE:
priv->page = g_value_get_pointer(value);
document = zathura_page_get_document(priv->page);
priv->zathura = document->zathura;
priv->zathura = zathura_document_get_zathura(document);
break;
case PROP_DRAW_LINKS:
priv->draw_links = g_value_get_boolean(value);
......@@ -300,7 +300,8 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
if (priv->surface != NULL) {
cairo_save(cairo);
switch (document->rotate) {
unsigned int rotation = zathura_document_get_rotation(document);
switch (rotation) {
case 90:
cairo_translate(cairo, page_width, 0);
break;
......@@ -312,8 +313,8 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
break;
}
if (document->rotate != 0) {
cairo_rotate(cairo, document->rotate * G_PI / 180.0);
if (rotation != 0) {
cairo_rotate(cairo, rotation * G_PI / 180.0);
}
cairo_set_source_surface(cairo, priv->surface, 0, 0);
......@@ -547,7 +548,7 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
&& rect.y1 <= button->y && rect.y2 >= button->y) {
switch (link->type) {
case ZATHURA_LINK_TO_PAGE:
page_set_delayed(document->zathura, link->target.page_number);
page_set_delayed(priv->zathura, link->target.page_number);
return false;
case ZATHURA_LINK_EXTERNAL:
girara_xdg_open(link->target.uri);
......@@ -562,10 +563,11 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
redraw_rect(ZATHURA_PAGE(widget), &priv->selection);
zathura_rectangle_t tmp = priv->selection;
tmp.x1 /= document->scale;
tmp.x2 /= document->scale;
tmp.y1 /= document->scale;
tmp.y2 /= document->scale;
double scale = zathura_document_get_scale(document);
tmp.x1 /= scale;
tmp.x2 /= scale;
tmp.y1 /= scale;
tmp.y2 /= scale;
char* text = zathura_page_get_text(priv->page, tmp, NULL);
if (text != NULL) {
......@@ -574,10 +576,9 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), text, -1);
if (priv->page != NULL && document != NULL && document->zathura != NULL) {
zathura_t* zathura = document->zathura;
if (priv->page != NULL && document != NULL && priv->zathura != NULL) {
char* stripped_text = g_strdelimit(g_strdup(text), "\n\t\r\n", ' ');
girara_notify(zathura->ui.session, GIRARA_INFO, _("Copied selected text to clipbard: %s"), stripped_text);
girara_notify(priv->zathura->ui.session, GIRARA_INFO, _("Copied selected text to clipbard: %s"), stripped_text);
g_free(stripped_text);
}
}
......
......@@ -9,6 +9,7 @@
#include "page-widget.h"
#include "plugin.h"
#include "utils.h"
#include "internal.h"
struct zathura_page_s {
double height; /**< Page height */
......@@ -23,8 +24,7 @@ struct zathura_page_s {
zathura_page_t*
zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error_t* error)
{
if (document == NULL || document->plugin == NULL || document->zathura == NULL
|| document->zathura->ui.session == NULL) {
if (document == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
......@@ -47,16 +47,15 @@ zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error
}
/* init plugin */
if (document->plugin->functions.page_init == NULL) {
zathura_plugin_t* plugin = zathura_document_get_plugin(document);
if (plugin->functions.page_init == NULL) {
if (error != NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
goto error_ret;
}
zathura_error_t ret = document->plugin->functions.page_init(page);
zathura_error_t ret = plugin->functions.page_init(page);
if (ret != ZATHURA_ERROR_OK) {
if (error != NULL) {
*error = ret;
......@@ -91,19 +90,17 @@ zathura_page_free(zathura_page_t* page)
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
if (page->document == NULL || page->document->plugin == NULL ||
page->document->zathura == NULL || page->document->zathura->ui.session == NULL) {
if (page->document == NULL) {
g_free(page);
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
if (page->document->plugin->functions.page_clear == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_clear == NULL) {
return ZATHURA_ERROR_NOT_IMPLEMENTED;
}
zathura_error_t error = page->document->plugin->functions.page_clear(page, page->data);
zathura_error_t error = plugin->functions.page_clear(page, page->data);
g_free(page);
......@@ -223,47 +220,43 @@ zathura_page_set_data(zathura_page_t* page, void* data)
girara_list_t*
zathura_page_search_text(zathura_page_t* page, const char* text, zathura_error_t* error)
{
if (page == NULL || page->document == NULL || page->document->plugin == NULL || text == NULL ||
page->document->zathura == NULL || page->document->zathura->ui.session == NULL) {
if (page == NULL || page->document == NULL || text == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}
if (page->document->plugin->functions.page_search_text == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_search_text == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
return page->document->plugin->functions.page_search_text(page, page->data, text, error);
return plugin->functions.page_search_text(page, page->data, text, error);
}
girara_list_t*
zathura_page_links_get(zathura_page_t* page, zathura_error_t* error)
{
if (page == NULL || page->document == NULL || page->document->plugin == NULL || page->document->zathura == NULL
|| page->document->zathura->ui.session == NULL) {
if (page == NULL || page->document == NULL ) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}
if (page->document->plugin->functions.page_links_get == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_links_get == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
return page->document->plugin->functions.page_links_get(page, page->data, error);
return plugin->functions.page_links_get(page, page->data, error);
}
zathura_error_t
......@@ -275,24 +268,22 @@ zathura_page_links_free(girara_list_t* UNUSED(list))
girara_list_t*
zathura_page_form_fields_get(zathura_page_t* page, zathura_error_t* error)
{
if (page == NULL || page->document == NULL || page->document->plugin == NULL || page->document->zathura == NULL
|| page->document->zathura->ui.session == NULL) {
if (page == NULL || page->document == NULL ) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}
if (page->document->plugin->functions.page_form_fields_get == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_form_fields_get == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
return page->document->plugin->functions.page_form_fields_get(page, page->data, error);
return plugin->functions.page_form_fields_get(page, page->data, error);
}
zathura_error_t
......@@ -304,87 +295,76 @@ zathura_page_form_fields_free(girara_list_t* UNUSED(list))
girara_list_t*
zathura_page_images_get(zathura_page_t* page, zathura_error_t* error)
{
if (page == NULL || page->document == NULL || page->document->plugin == NULL || page->document->zathura == NULL
|| page->document->zathura->ui.session == NULL) {
if (page == NULL || page->document == NULL ) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}
if (page->document->plugin->functions.page_images_get == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_images_get == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
return page->document->plugin->functions.page_images_get(page, page->data, error);
return plugin->functions.page_images_get(page, page->data, error);
}
cairo_surface_t*
zathura_page_image_get_cairo(zathura_page_t* page, zathura_image_t* image, zathura_error_t* error)
{
if (page == NULL || page->document == NULL || page->document->plugin == NULL || image == NULL ||
page->document->zathura == NULL || page->document->zathura->ui.session ==
NULL) {
if (page == NULL || page->document == NULL || image == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}
if (page->document->plugin->functions.page_image_get_cairo == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_image_get_cairo == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
return page->document->plugin->functions.page_image_get_cairo(page, page->data, image, error);
return plugin->functions.page_image_get_cairo(page, page->data, image, error);
}
char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, zathura_error_t* error)
{
if (page == NULL || page->document == NULL || page->document->plugin == NULL
|| page->document->zathura == NULL || page->document->zathura->ui.session
== NULL) {
if (page == NULL || page->document == NULL ) {
if (error) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}
if (page->document->plugin->functions.page_get_text == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_get_text == NULL) {
if (error) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
return page->document->plugin->functions.page_get_text(page, page->data, rectangle, error);
return plugin->functions.page_get_text(page, page->data, rectangle, error);
}
zathura_error_t
zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing)
{
if (page == NULL || page->document->plugin == NULL || page->document == NULL || cairo == NULL ||
page->document->zathura == NULL || page->document->zathura->ui.session ==
NULL) {
if (page == NULL || page->document == NULL || cairo == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
if (page->document->plugin->functions.page_render_cairo == NULL) {
girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, _("%s not implemented"), __FUNCTION__);
girara_error("%s not implemented", __FUNCTION__);
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
if (plugin->functions.page_render_cairo == NULL) {
return ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return page->document->plugin->functions.page_render_cairo(page, page->data, cairo, printing);
return plugin->functions.page_render_cairo(page, page->data, cairo, printing);
}
......@@ -41,11 +41,11 @@ void zathura_plugin_add_mimetype(zathura_plugin_t* plugin, const char* mime_type
* @param mimetypes a char array of mime types supported by the plugin
*/
#define ZATHURA_PLUGIN_REGISTER(plugin_name, major, minor, rev, register_functions, mimetypes) \
unsigned int plugin_version_major() { return major; } \
unsigned int plugin_version_minor() { return minor; } \
unsigned int plugin_version_revision() { return rev; } \
unsigned int plugin_api_version() { return ZATHURA_API_VERSION; } \
unsigned int plugin_abi_version() { return ZATHURA_ABI_VERSION; } \
unsigned int zathura_plugin_version_major() { return major; } \
unsigned int zathura_plugin_version_minor() { return minor; } \
unsigned int zathura_plugin_version_revision() { return rev; } \
unsigned int zathura_plugin_api_version() { return ZATHURA_API_VERSION; } \
unsigned int zathura_plugin_abi_version() { return ZATHURA_ABI_VERSION; } \
\
void zathura_plugin_register(zathura_plugin_t* plugin) \
{ \
......
......@@ -10,9 +10,9 @@
#include "version.h"
#include "zathura.h"
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
#define PLUGIN_API_VERSION_FUNCTION "plugin_api_version"
#define PLUGIN_ABI_VERSION_FUNCTION "plugin_abi_version"
#define PLUGIN_REGISTER_FUNCTION "zathura_plugin_register"
#define PLUGIN_API_VERSION_FUNCTION "zathura_plugin_api_version"
#define PLUGIN_ABI_VERSION_FUNCTION "zathura_plugin_abi_version"
/**
* Plugin mapping
......
......@@ -26,8 +26,8 @@ print(zathura_t* zathura)
}
gtk_print_operation_set_allow_async(print_operation, TRUE);
gtk_print_operation_set_n_pages(print_operation, zathura->document->number_of_pages);
gtk_print_operation_set_current_page(print_operation, zathura->document->current_page_number);
gtk_print_operation_set_n_pages(print_operation, zathura_document_get_number_of_pages(zathura->document));
gtk_print_operation_set_current_page(print_operation, zathura_document_get_current_page_number(zathura->document));
/* print operation signals */
g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura);
......@@ -59,20 +59,23 @@ void
cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
UNUSED(context), zathura_t* zathura)
{
if (zathura == NULL || zathura->ui.session == NULL || zathura->document == NULL
|| zathura->document->file_path == NULL) {
if (zathura == NULL || zathura->ui.session == NULL || zathura->document == NULL) {
return;
}
girara_statusbar_item_set_text(zathura->ui.session,
zathura->ui.statusbar.file, zathura->document->file_path);
const char* file_path = zathura_document_get_path(zathura->document);