2012-03-26 14:44:56 +02:00
|
|
|
/* See LICENSE file for license and copyright information */
|
|
|
|
|
|
|
|
#include <girara/session.h>
|
|
|
|
#include <girara/utils.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
#include "document.h"
|
|
|
|
#include "page.h"
|
|
|
|
#include "page-widget.h"
|
2012-03-27 13:30:04 +02:00
|
|
|
#include "plugin.h"
|
2012-03-26 14:44:56 +02:00
|
|
|
#include "utils.h"
|
2012-03-27 21:59:35 +02:00
|
|
|
#include "internal.h"
|
2012-03-26 14:44:56 +02:00
|
|
|
|
|
|
|
struct zathura_page_s {
|
|
|
|
double height; /**< Page height */
|
|
|
|
double width; /**< Page width */
|
2012-03-26 15:30:58 +02:00
|
|
|
unsigned int index; /**< Page number */
|
2012-03-26 14:44:56 +02:00
|
|
|
void* data; /**< Custom data */
|
|
|
|
bool visible; /**< Page is visible */
|
|
|
|
GtkWidget* widget; /**< Drawing area */
|
|
|
|
zathura_document_t* document; /**< Document */
|
|
|
|
};
|
|
|
|
|
|
|
|
zathura_page_t*
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error_t* error)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (document == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
2012-03-26 15:17:01 +02:00
|
|
|
/* init page */
|
|
|
|
zathura_page_t* page = g_malloc0(sizeof(zathura_page_t));
|
2012-03-26 14:44:56 +02:00
|
|
|
|
2012-03-26 15:30:58 +02:00
|
|
|
page->index = index;
|
2012-03-26 15:17:01 +02:00
|
|
|
page->visible = false;
|
|
|
|
page->document = document;
|
|
|
|
page->widget = zathura_page_widget_new(page);
|
|
|
|
|
|
|
|
if (page->widget == NULL) {
|
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_UNKNOWN;
|
2012-03-26 15:17:01 +02:00
|
|
|
}
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init plugin */
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(document);
|
|
|
|
if (plugin->functions.page_init == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_error_t ret = plugin->functions.page_init(page);
|
2012-03-27 13:30:04 +02:00
|
|
|
if (ret != ZATHURA_ERROR_OK) {
|
2012-03-26 15:17:01 +02:00
|
|
|
if (error != NULL) {
|
|
|
|
*error = ret;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
2012-03-26 15:17:01 +02:00
|
|
|
goto error_free;
|
|
|
|
}
|
2012-03-26 14:44:56 +02:00
|
|
|
|
2012-03-26 15:17:01 +02:00
|
|
|
/* set widget size */
|
|
|
|
unsigned int page_height = 0;
|
|
|
|
unsigned int page_width = 0;
|
|
|
|
page_calc_height_width(page, &page_height, &page_width, true);
|
2012-03-26 14:44:56 +02:00
|
|
|
|
2012-03-26 15:17:01 +02:00
|
|
|
gtk_widget_set_size_request(page->widget, page_width, page_height);
|
2012-03-26 14:44:56 +02:00
|
|
|
|
|
|
|
return page;
|
|
|
|
|
|
|
|
error_free:
|
|
|
|
|
|
|
|
if (page != NULL) {
|
|
|
|
zathura_page_free(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_ret:
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_error_t
|
2012-03-26 14:44:56 +02:00
|
|
|
zathura_page_free(zathura_page_t* page)
|
|
|
|
{
|
2012-03-26 15:17:01 +02:00
|
|
|
if (page == NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
return ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 15:17:01 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page->document == NULL) {
|
2012-03-26 15:17:01 +02:00
|
|
|
g_free(page);
|
2012-03-27 13:30:04 +02:00
|
|
|
return ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_clear == NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
return ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_error_t error = plugin->functions.page_clear(page, page->data);
|
2012-03-26 15:17:01 +02:00
|
|
|
|
|
|
|
g_free(page);
|
|
|
|
|
|
|
|
return error;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zathura_document_t*
|
|
|
|
zathura_page_get_document(zathura_page_t* page)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page->document;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2012-03-26 15:30:58 +02:00
|
|
|
zathura_page_get_index(zathura_page_t* page)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-26 15:30:58 +02:00
|
|
|
return page->index;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
zathura_page_get_widget(zathura_page_t* page)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page->widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
zathura_page_get_width(zathura_page_t* page)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_page_set_width(zathura_page_t* page, double width)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
page->width = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
zathura_page_get_height(zathura_page_t* page)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_page_set_height(zathura_page_t* page, double height)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
page->height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
zathura_page_get_visibility(zathura_page_t* page)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page->visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_page_set_visibility(zathura_page_t* page, bool visibility)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
page->visible = visibility;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
zathura_page_get_data(zathura_page_t* page)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_page_set_data(zathura_page_t* page, void* data)
|
|
|
|
{
|
|
|
|
if (page == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
page->data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
girara_list_t*
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_page_search_text(zathura_page_t* page, const char* text, zathura_error_t* error)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page == NULL || page->document == NULL || text == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_search_text == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
return plugin->functions.page_search_text(page, page->data, text, error);
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
girara_list_t*
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_page_links_get(zathura_page_t* page, zathura_error_t* error)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page == NULL || page->document == NULL ) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_links_get == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
return plugin->functions.page_links_get(page, page->data, error);
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_error_t
|
2012-03-26 14:44:56 +02:00
|
|
|
zathura_page_links_free(girara_list_t* UNUSED(list))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
girara_list_t*
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_page_form_fields_get(zathura_page_t* page, zathura_error_t* error)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page == NULL || page->document == NULL ) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_form_fields_get == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
return plugin->functions.page_form_fields_get(page, page->data, error);
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_error_t
|
2012-03-26 14:44:56 +02:00
|
|
|
zathura_page_form_fields_free(girara_list_t* UNUSED(list))
|
|
|
|
{
|
2012-03-27 13:30:04 +02:00
|
|
|
return ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
girara_list_t*
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_page_images_get(zathura_page_t* page, zathura_error_t* error)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page == NULL || page->document == NULL ) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_images_get == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
return plugin->functions.page_images_get(page, page->data, error);
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_t*
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_page_image_get_cairo(zathura_page_t* page, zathura_image_t* image, zathura_error_t* error)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page == NULL || page->document == NULL || image == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_image_get_cairo == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error != NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
return plugin->functions.page_image_get_cairo(page, page->data, image, error);
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, zathura_error_t* error)
|
2012-03-26 14:44:56 +02:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page == NULL || page->document == NULL ) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_get_text == NULL) {
|
2012-03-26 14:44:56 +02:00
|
|
|
if (error) {
|
2012-03-27 13:30:04 +02:00
|
|
|
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
return plugin->functions.page_get_text(page, page->data, rectangle, error);
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_error_t
|
2012-03-26 14:44:56 +02:00
|
|
|
zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing)
|
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (page == NULL || page->document == NULL || cairo == NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
return ZATHURA_ERROR_INVALID_ARGUMENTS;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_plugin_t* plugin = zathura_document_get_plugin(page->document);
|
|
|
|
if (plugin->functions.page_render_cairo == NULL) {
|
2012-03-27 13:30:04 +02:00
|
|
|
return ZATHURA_ERROR_NOT_IMPLEMENTED;
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
return plugin->functions.page_render_cairo(page, page->data, cairo, printing);
|
2012-03-26 14:44:56 +02:00
|
|
|
}
|