mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-02-27 14:44:39 +01:00
pinned
This commit is contained in:
parent
12c8cd9110
commit
46dfa2be22
8 changed files with 1003 additions and 1064 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -36,3 +36,4 @@ compile_commands.json
|
||||||
*.log
|
*.log
|
||||||
.ycm_extra_conf.py
|
.ycm_extra_conf.py
|
||||||
_*/
|
_*/
|
||||||
|
.ccls-cache/
|
||||||
|
|
|
@ -5,21 +5,25 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
double
|
// @debug
|
||||||
page_calc_height_width(zathura_document_t* document, double height,
|
#include <stdio.h>
|
||||||
double width, unsigned int* page_height,
|
|
||||||
unsigned int* page_width, bool rotate)
|
double page_calc_height_width(zathura_document_t *document, double height,
|
||||||
{
|
double width, unsigned int *page_height,
|
||||||
g_return_val_if_fail(document != NULL && page_height != NULL && page_width != NULL, 0.0);
|
unsigned int *page_width, bool rotate) {
|
||||||
|
g_return_val_if_fail(
|
||||||
|
document != NULL && page_height != NULL && page_width != NULL, 0.0);
|
||||||
|
|
||||||
double scale = zathura_document_get_scale(document);
|
double scale = zathura_document_get_scale(document);
|
||||||
|
|
||||||
|
// TODO this just set all pages to the maximum.
|
||||||
|
// needs to adjust cell size based on the page size itself.
|
||||||
if (rotate == true && zathura_document_get_rotation(document) % 180 != 0) {
|
if (rotate == true && zathura_document_get_rotation(document) % 180 != 0) {
|
||||||
*page_width = round(height * scale);
|
*page_width = round(height * scale);
|
||||||
*page_height = round(width * scale);
|
*page_height = round(width * scale);
|
||||||
scale = MAX(*page_width / height, *page_height / width);
|
scale = MAX(*page_width / height, *page_height / width);
|
||||||
} else {
|
} else {
|
||||||
*page_width = round(width * scale);
|
*page_width = round(width * scale);
|
||||||
*page_height = round(height * scale);
|
*page_height = round(height * scale);
|
||||||
scale = MAX(*page_width / width, *page_height / height);
|
scale = MAX(*page_width / width, *page_height / height);
|
||||||
}
|
}
|
||||||
|
@ -27,10 +31,8 @@ page_calc_height_width(zathura_document_t* document, double height,
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void page_calc_position(zathura_document_t *document, double x, double y,
|
||||||
page_calc_position(zathura_document_t* document, double x, double y, double* xn,
|
double *xn, double *yn) {
|
||||||
double* yn)
|
|
||||||
{
|
|
||||||
g_return_if_fail(document != NULL && xn != NULL && yn != NULL);
|
g_return_if_fail(document != NULL && xn != NULL && yn != NULL);
|
||||||
|
|
||||||
const unsigned int rot = zathura_document_get_rotation(document);
|
const unsigned int rot = zathura_document_get_rotation(document);
|
||||||
|
@ -49,10 +51,8 @@ page_calc_position(zathura_document_t* document, double x, double y, double* xn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int position_to_page_number(zathura_document_t *document, double pos_x,
|
||||||
position_to_page_number(zathura_document_t* document, double pos_x,
|
double pos_y) {
|
||||||
double pos_y)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail(document != NULL, 0);
|
g_return_val_if_fail(document != NULL, 0);
|
||||||
|
|
||||||
unsigned int doc_width, doc_height;
|
unsigned int doc_width, doc_height;
|
||||||
|
@ -61,11 +61,11 @@ position_to_page_number(zathura_document_t* document, double pos_x,
|
||||||
unsigned int cell_width, cell_height;
|
unsigned int cell_width, cell_height;
|
||||||
zathura_document_get_cell_size(document, &cell_height, &cell_width);
|
zathura_document_get_cell_size(document, &cell_height, &cell_width);
|
||||||
|
|
||||||
unsigned int c0 = zathura_document_get_first_page_column(document);
|
unsigned int c0 = zathura_document_get_first_page_column(document);
|
||||||
unsigned int npag = zathura_document_get_number_of_pages(document);
|
unsigned int npag = zathura_document_get_number_of_pages(document);
|
||||||
unsigned int ncol = zathura_document_get_pages_per_row(document);
|
unsigned int ncol = zathura_document_get_pages_per_row(document);
|
||||||
unsigned int nrow = 0;
|
unsigned int nrow = 0;
|
||||||
unsigned int pad = zathura_document_get_page_padding(document);
|
unsigned int pad = zathura_document_get_page_padding(document);
|
||||||
|
|
||||||
if (c0 == 1) {
|
if (c0 == 1) {
|
||||||
/* There is no offset, so this is easy. */
|
/* There is no offset, so this is easy. */
|
||||||
|
@ -75,8 +75,10 @@ position_to_page_number(zathura_document_t* document, double pos_x,
|
||||||
nrow = 1 + (npag - (ncol - c0 - 1) + (ncol - 1)) / ncol;
|
nrow = 1 + (npag - (ncol - c0 - 1) + (ncol - 1)) / ncol;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int col = floor(pos_x * (double)doc_width / (double)(cell_width + pad));
|
unsigned int col =
|
||||||
unsigned int row = floor(pos_y * (double)doc_height / (double)(cell_height + pad));
|
floor(pos_x * (double)doc_width / (double)(cell_width + pad));
|
||||||
|
unsigned int row =
|
||||||
|
floor(pos_y * (double)doc_height / (double)(cell_height + pad));
|
||||||
|
|
||||||
unsigned int page = ncol * (row % nrow) + (col % ncol);
|
unsigned int page = ncol * (row % nrow) + (col % ncol);
|
||||||
if (page < c0 - 1) {
|
if (page < c0 - 1) {
|
||||||
|
@ -86,22 +88,19 @@ position_to_page_number(zathura_document_t* document, double pos_x,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void page_number_to_position(zathura_document_t *document,
|
||||||
void
|
unsigned int page_number, double xalign,
|
||||||
page_number_to_position(zathura_document_t* document, unsigned int page_number,
|
double yalign, double *pos_x, double *pos_y) {
|
||||||
double xalign, double yalign, double* pos_x,
|
|
||||||
double* pos_y)
|
|
||||||
{
|
|
||||||
g_return_if_fail(document != NULL);
|
g_return_if_fail(document != NULL);
|
||||||
|
|
||||||
unsigned int c0 = zathura_document_get_first_page_column(document);
|
unsigned int c0 = zathura_document_get_first_page_column(document);
|
||||||
unsigned int npag = zathura_document_get_number_of_pages(document);
|
unsigned int npag = zathura_document_get_number_of_pages(document);
|
||||||
unsigned int ncol = zathura_document_get_pages_per_row(document);
|
unsigned int ncol = zathura_document_get_pages_per_row(document);
|
||||||
unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
|
unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
|
||||||
|
|
||||||
/* row and column for page_number indexed from 0 */
|
/* row and column for page_number indexed from 0 */
|
||||||
unsigned int row = (page_number + c0 - 1) / ncol;
|
unsigned int row = (page_number + c0 - 1) / ncol;
|
||||||
unsigned int col = (page_number + c0 - 1) % ncol;
|
unsigned int col = (page_number + c0 - 1) % ncol;
|
||||||
|
|
||||||
/* sizes of page cell, viewport and document */
|
/* sizes of page cell, viewport and document */
|
||||||
unsigned int cell_height = 0, cell_width = 0;
|
unsigned int cell_height = 0, cell_width = 0;
|
||||||
|
@ -113,14 +112,18 @@ page_number_to_position(zathura_document_t* document, unsigned int page_number,
|
||||||
unsigned int doc_height = 0, doc_width = 0;
|
unsigned int doc_height = 0, doc_width = 0;
|
||||||
zathura_document_get_document_size(document, &doc_height, &doc_width);
|
zathura_document_get_document_size(document, &doc_height, &doc_width);
|
||||||
|
|
||||||
/* compute the shift to align to the viewport. If the page fits to viewport, just center it. */
|
/* compute the shift to align to the viewport. If the page fits to viewport,
|
||||||
|
* just center it. */
|
||||||
double shift_x = 0.5, shift_y = 0.5;
|
double shift_x = 0.5, shift_y = 0.5;
|
||||||
if (cell_width > view_width) {
|
if (cell_width > view_width) {
|
||||||
shift_x = 0.5 + (xalign - 0.5) * ((double)cell_width - (double)view_width) / (double)cell_width;
|
shift_x = 0.5 + (xalign - 0.5) * ((double)cell_width - (double)view_width) /
|
||||||
|
(double)cell_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell_height > view_height) {
|
if (cell_height > view_height) {
|
||||||
shift_y = 0.5 + (yalign - 0.5) * ((double)cell_height - (double)view_height) / (double)cell_height;
|
shift_y = 0.5 + (yalign - 0.5) *
|
||||||
|
((double)cell_height - (double)view_height) /
|
||||||
|
(double)cell_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute the position */
|
/* compute the position */
|
||||||
|
@ -128,10 +131,7 @@ page_number_to_position(zathura_document_t* document, unsigned int page_number,
|
||||||
*pos_y = ((double)row + shift_y) / (double)nrow;
|
*pos_y = ((double)row + shift_y) / (double)nrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool page_is_visible(zathura_document_t *document, unsigned int page_number) {
|
||||||
bool
|
|
||||||
page_is_visible(zathura_document_t *document, unsigned int page_number)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail(document != NULL, false);
|
g_return_val_if_fail(document != NULL, false);
|
||||||
|
|
||||||
/* position at the center of the viewport */
|
/* position at the center of the viewport */
|
||||||
|
@ -151,35 +151,31 @@ page_is_visible(zathura_document_t *document, unsigned int page_number)
|
||||||
unsigned int view_width, view_height;
|
unsigned int view_width, view_height;
|
||||||
zathura_document_get_viewport_size(document, &view_height, &view_width);
|
zathura_document_get_viewport_size(document, &view_height, &view_width);
|
||||||
|
|
||||||
return ( fabs(pos_x - page_x) < 0.5 * (double)(view_width + cell_width) / (double)doc_width &&
|
return (fabs(pos_x - page_x) <
|
||||||
fabs(pos_y - page_y) < 0.5 * (double)(view_height + cell_height) / (double)doc_height);
|
0.5 * (double)(view_width + cell_width) / (double)doc_width &&
|
||||||
|
fabs(pos_y - page_y) <
|
||||||
|
0.5 * (double)(view_height + cell_height) / (double)doc_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_adjustment_set_value(GtkAdjustment *adjustment, gdouble value) {
|
||||||
zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value)
|
const gdouble lower = gtk_adjustment_get_lower(adjustment);
|
||||||
{
|
|
||||||
const gdouble lower = gtk_adjustment_get_lower(adjustment);
|
|
||||||
const gdouble upper_m_size = gtk_adjustment_get_upper(adjustment) -
|
const gdouble upper_m_size = gtk_adjustment_get_upper(adjustment) -
|
||||||
gtk_adjustment_get_page_size(adjustment);
|
gtk_adjustment_get_page_size(adjustment);
|
||||||
|
|
||||||
gtk_adjustment_set_value(adjustment, MAX(lower, MIN(upper_m_size, value)));
|
gtk_adjustment_set_value(adjustment, MAX(lower, MIN(upper_m_size, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
gdouble
|
gdouble zathura_adjustment_get_ratio(GtkAdjustment *adjustment) {
|
||||||
zathura_adjustment_get_ratio(GtkAdjustment* adjustment)
|
gdouble lower = gtk_adjustment_get_lower(adjustment);
|
||||||
{
|
gdouble upper = gtk_adjustment_get_upper(adjustment);
|
||||||
gdouble lower = gtk_adjustment_get_lower(adjustment);
|
|
||||||
gdouble upper = gtk_adjustment_get_upper(adjustment);
|
|
||||||
gdouble page_size = gtk_adjustment_get_page_size(adjustment);
|
gdouble page_size = gtk_adjustment_get_page_size(adjustment);
|
||||||
gdouble value = gtk_adjustment_get_value(adjustment);
|
gdouble value = gtk_adjustment_get_value(adjustment);
|
||||||
|
|
||||||
return (value - lower + page_size / 2.0) / (upper - lower);
|
return (value - lower + page_size / 2.0) / (upper - lower);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_adjustment_set_value_from_ratio(GtkAdjustment *adjustment,
|
||||||
zathura_adjustment_set_value_from_ratio(GtkAdjustment* adjustment,
|
gdouble ratio) {
|
||||||
gdouble ratio)
|
|
||||||
{
|
|
||||||
if (ratio == 0.0) {
|
if (ratio == 0.0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
* desired.
|
* desired.
|
||||||
*
|
*
|
||||||
* @param document the document
|
* @param document the document
|
||||||
* @param height the original height
|
* @param height the original height
|
||||||
* @param width the original width
|
* @param width the original width
|
||||||
* @param page_height the scaled and rotated height
|
* @param page_height the scaled and rotated height
|
||||||
* @param page_width the scaled and rotated width
|
* @param page_width the scaled and rotated width
|
||||||
* @param rotate honor page's rotation
|
* @param rotate honor page's rotation
|
||||||
* @return real scale after rounding
|
* @return real scale after rounding
|
||||||
|
|
|
@ -1,78 +1,80 @@
|
||||||
/* SPDX-License-Identifier: Zlib */
|
/* SPDX-License-Identifier: Zlib */
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#include <glib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <gio/gio.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include <girara/datastructures.h>
|
#include <girara/datastructures.h>
|
||||||
#include <girara/utils.h>
|
#include <girara/utils.h>
|
||||||
|
|
||||||
#include "adjustment.h"
|
#include "adjustment.h"
|
||||||
|
#include "content-type.h"
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "zathura.h"
|
|
||||||
#include "page.h"
|
#include "page.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "content-type.h"
|
#include "utils.h"
|
||||||
|
#include "zathura.h"
|
||||||
|
// @debug
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document
|
* Document
|
||||||
*/
|
*/
|
||||||
struct zathura_document_s {
|
struct zathura_document_s {
|
||||||
char* file_path; /**< File path of the document */
|
char *file_path; /**< File path of the document */
|
||||||
char* uri; /**< URI of the document */
|
char *uri; /**< URI of the document */
|
||||||
char* basename; /**< Basename of the document */
|
char *basename; /**< Basename of the document */
|
||||||
uint8_t hash_sha256[32]; /**< SHA256 hash of the document */
|
uint8_t hash_sha256[32]; /**< SHA256 hash of the document */
|
||||||
const char* password; /**< Password of the document */
|
const char *password; /**< Password of the document */
|
||||||
unsigned int current_page_number; /**< Current page number */
|
unsigned int current_page_number; /**< Current page number */
|
||||||
unsigned int number_of_pages; /**< Number of pages */
|
unsigned int number_of_pages; /**< Number of pages */
|
||||||
double zoom; /**< Zoom value */
|
double zoom; /**< Zoom value */
|
||||||
unsigned int rotate; /**< Rotation */
|
unsigned int rotate; /**< Rotation */
|
||||||
void* data; /**< Custom data */
|
void *data; /**< Custom data */
|
||||||
zathura_adjust_mode_t adjust_mode; /**< Adjust mode (best-fit, width) */
|
zathura_adjust_mode_t adjust_mode; /**< Adjust mode (best-fit, width) */
|
||||||
int page_offset; /**< Page offset */
|
int page_offset; /**< Page offset */
|
||||||
double cell_width; /**< width of a page cell in the document (not transformed by scale and rotation) */
|
double cell_width; /**< width of a page cell in the document (not transformed
|
||||||
double cell_height; /**< height of a page cell in the document (not transformed by scale and rotation) */
|
by scale and rotation) */
|
||||||
unsigned int view_width; /**< width of current viewport */
|
double cell_height; /**< height of a page cell in the document (not
|
||||||
|
transformed by scale and rotation) */
|
||||||
|
unsigned int view_width; /**< width of current viewport */
|
||||||
unsigned int view_height; /**< height of current viewport */
|
unsigned int view_height; /**< height of current viewport */
|
||||||
double view_ppi; /**< PPI of the current viewport */
|
double view_ppi; /**< PPI of the current viewport */
|
||||||
zathura_device_factors_t device_factors; /**< x and y device scale factors (for e.g. HiDPI) */
|
zathura_device_factors_t
|
||||||
unsigned int pages_per_row; /**< number of pages in a row */
|
device_factors; /**< x and y device scale factors (for e.g. HiDPI) */
|
||||||
|
unsigned int pages_per_row; /**< number of pages in a row */
|
||||||
unsigned int first_page_column; /**< column of the first page */
|
unsigned int first_page_column; /**< column of the first page */
|
||||||
unsigned int page_padding; /**< padding between pages */
|
unsigned int page_padding; /**< padding between pages */
|
||||||
double position_x; /**< X adjustment */
|
double position_x; /**< X adjustment */
|
||||||
double position_y; /**< Y adjustment */
|
double position_y; /**< Y adjustment */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document pages
|
* Document pages
|
||||||
*/
|
*/
|
||||||
zathura_page_t** pages;
|
zathura_page_t **pages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used plugin
|
* Used plugin
|
||||||
*/
|
*/
|
||||||
zathura_plugin_t* plugin;
|
zathura_plugin_t *plugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void check_set_error(zathura_error_t *error, zathura_error_t code) {
|
||||||
check_set_error(zathura_error_t* error, zathura_error_t code) {
|
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
*error = code;
|
*error = code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool hash_file_sha256(uint8_t *dst, const char *path) {
|
||||||
hash_file_sha256(uint8_t* dst, const char* path)
|
FILE *f = fopen(path, "rb");
|
||||||
{
|
|
||||||
FILE* f = fopen(path, "rb");
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GChecksum* checksum = g_checksum_new(G_CHECKSUM_SHA256);
|
GChecksum *checksum = g_checksum_new(G_CHECKSUM_SHA256);
|
||||||
if (checksum == NULL) {
|
if (checksum == NULL) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return false;
|
return false;
|
||||||
|
@ -97,19 +99,18 @@ hash_file_sha256(uint8_t* dst, const char* path)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_document_t*
|
zathura_document_t *zathura_document_open(zathura_t *zathura, const char *path,
|
||||||
zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
|
const char *uri, const char *password,
|
||||||
const char* password, zathura_error_t* error)
|
zathura_error_t *error) {
|
||||||
{
|
|
||||||
if (zathura == NULL || path == NULL) {
|
if (zathura == NULL || path == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GFile* file = g_file_new_for_path(path);
|
GFile *file = g_file_new_for_path(path);
|
||||||
char* real_path = NULL;
|
char *real_path = NULL;
|
||||||
char* content_type = NULL;
|
char *content_type = NULL;
|
||||||
zathura_plugin_t* plugin = NULL;
|
zathura_plugin_t *plugin = NULL;
|
||||||
zathura_document_t* document = NULL;
|
zathura_document_t *document = NULL;
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
girara_error("Error while handling path '%s'.", path);
|
girara_error("Error while handling path '%s'.", path);
|
||||||
|
@ -124,19 +125,22 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
content_type = zathura_content_type_guess(zathura->content_type_context, real_path, zathura_plugin_manager_get_content_types(zathura->plugins.manager));
|
content_type = zathura_content_type_guess(
|
||||||
|
zathura->content_type_context, real_path,
|
||||||
|
zathura_plugin_manager_get_content_types(zathura->plugins.manager));
|
||||||
if (content_type == NULL) {
|
if (content_type == NULL) {
|
||||||
girara_error("Could not determine file type.");
|
girara_error("Could not determine file type.");
|
||||||
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
|
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin = zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type);
|
plugin =
|
||||||
|
zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type);
|
||||||
if (plugin == NULL) {
|
if (plugin == NULL) {
|
||||||
girara_error("Unknown file type: '%s'", content_type);
|
girara_error("Unknown file type: '%s'", content_type);
|
||||||
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
|
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
|
||||||
|
|
||||||
g_free((void*)content_type);
|
g_free((void *)content_type);
|
||||||
content_type = NULL;
|
content_type = NULL;
|
||||||
|
|
||||||
goto error_free;
|
goto error_free;
|
||||||
|
@ -151,36 +155,37 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
document->file_path = real_path;
|
document->file_path = real_path;
|
||||||
document->uri = g_strdup(uri);
|
document->uri = g_strdup(uri);
|
||||||
if (document->uri == NULL) {
|
if (document->uri == NULL) {
|
||||||
document->basename = g_file_get_basename(file);
|
document->basename = g_file_get_basename(file);
|
||||||
} else {
|
} else {
|
||||||
GFile*gf = g_file_new_for_uri(document->uri);
|
GFile *gf = g_file_new_for_uri(document->uri);
|
||||||
document->basename = g_file_get_basename(gf);
|
document->basename = g_file_get_basename(gf);
|
||||||
g_object_unref(gf);
|
g_object_unref(gf);
|
||||||
}
|
}
|
||||||
hash_file_sha256(document->hash_sha256, document->file_path);
|
hash_file_sha256(document->hash_sha256, document->file_path);
|
||||||
document->password = password;
|
document->password = password;
|
||||||
document->zoom = 1.0;
|
document->zoom = 1.0;
|
||||||
document->plugin = plugin;
|
document->plugin = plugin;
|
||||||
document->adjust_mode = ZATHURA_ADJUST_NONE;
|
document->adjust_mode = ZATHURA_ADJUST_NONE;
|
||||||
document->cell_width = 0.0;
|
document->cell_width = 0.0;
|
||||||
document->cell_height = 0.0;
|
document->cell_height = 0.0;
|
||||||
document->view_height = 0;
|
document->view_height = 0;
|
||||||
document->view_width = 0;
|
document->view_width = 0;
|
||||||
document->view_ppi = 0.0;
|
document->view_ppi = 0.0;
|
||||||
document->device_factors.x = 1.0;
|
document->device_factors.x = 1.0;
|
||||||
document->device_factors.y = 1.0;
|
document->device_factors.y = 1.0;
|
||||||
document->position_x = 0.0;
|
document->position_x = 0.0;
|
||||||
document->position_y = 0.0;
|
document->position_y = 0.0;
|
||||||
|
|
||||||
real_path = NULL;
|
real_path = NULL;
|
||||||
g_object_unref(file);
|
g_object_unref(file);
|
||||||
file = NULL;
|
file = NULL;
|
||||||
|
|
||||||
/* open document */
|
/* open document */
|
||||||
const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(plugin);
|
const zathura_plugin_functions_t *functions =
|
||||||
|
zathura_plugin_get_functions(plugin);
|
||||||
if (functions->document_open == NULL) {
|
if (functions->document_open == NULL) {
|
||||||
girara_error("plugin has no open function\n");
|
girara_error("plugin has no open function\n");
|
||||||
goto error_free;
|
goto error_free;
|
||||||
|
@ -194,14 +199,15 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read all pages */
|
/* read all pages */
|
||||||
document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*));
|
document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t *));
|
||||||
if (document->pages == NULL) {
|
if (document->pages == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY);
|
check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY);
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
zathura_page_t* page = zathura_page_new(document, page_id, NULL);
|
page_id++) {
|
||||||
|
zathura_page_t *page = zathura_page_new(document, page_id, NULL);
|
||||||
if (page == NULL) {
|
if (page == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY);
|
check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY);
|
||||||
goto error_free;
|
goto error_free;
|
||||||
|
@ -209,7 +215,8 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
|
||||||
|
|
||||||
document->pages[page_id] = page;
|
document->pages[page_id] = page;
|
||||||
|
|
||||||
/* cell_width and cell_height is the maximum of all the pages width and height */
|
/* cell_width and cell_height is the maximum of all the pages width and
|
||||||
|
* height */
|
||||||
const double width = zathura_page_get_width(page);
|
const double width = zathura_page_get_width(page);
|
||||||
if (document->cell_width < width)
|
if (document->cell_width < width)
|
||||||
document->cell_width = width;
|
document->cell_width = width;
|
||||||
|
@ -239,16 +246,15 @@ error_free:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_error_t
|
zathura_error_t zathura_document_free(zathura_document_t *document) {
|
||||||
zathura_document_free(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL || document->plugin == NULL) {
|
if (document == NULL || document->plugin == NULL) {
|
||||||
return ZATHURA_ERROR_INVALID_ARGUMENTS;
|
return ZATHURA_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document->pages != NULL) {
|
if (document->pages != NULL) {
|
||||||
/* free pages */
|
/* free pages */
|
||||||
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_free(document->pages[page_id]);
|
zathura_page_free(document->pages[page_id]);
|
||||||
document->pages[page_id] = NULL;
|
document->pages[page_id] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +263,8 @@ zathura_document_free(zathura_document_t* document)
|
||||||
|
|
||||||
/* free document */
|
/* free document */
|
||||||
zathura_error_t error = ZATHURA_ERROR_OK;
|
zathura_error_t error = ZATHURA_ERROR_OK;
|
||||||
const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin);
|
const zathura_plugin_functions_t *functions =
|
||||||
|
zathura_plugin_get_functions(document->plugin);
|
||||||
if (functions->document_free == NULL) {
|
if (functions->document_free == NULL) {
|
||||||
error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -273,9 +280,7 @@ zathura_document_free(zathura_document_t* document)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char *zathura_document_get_path(zathura_document_t *document) {
|
||||||
zathura_document_get_path(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -283,9 +288,7 @@ zathura_document_get_path(zathura_document_t* document)
|
||||||
return document->file_path;
|
return document->file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t*
|
const uint8_t *zathura_document_get_hash(zathura_document_t *document) {
|
||||||
zathura_document_get_hash(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -293,9 +296,7 @@ zathura_document_get_hash(zathura_document_t* document)
|
||||||
return document->hash_sha256;
|
return document->hash_sha256;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char *zathura_document_get_uri(zathura_document_t *document) {
|
||||||
zathura_document_get_uri(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -303,9 +304,7 @@ zathura_document_get_uri(zathura_document_t* document)
|
||||||
return document->uri;
|
return document->uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char *zathura_document_get_basename(zathura_document_t *document) {
|
||||||
zathura_document_get_basename(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -313,9 +312,7 @@ zathura_document_get_basename(zathura_document_t* document)
|
||||||
return document->basename;
|
return document->basename;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char *zathura_document_get_password(zathura_document_t *document) {
|
||||||
zathura_document_get_password(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -323,19 +320,17 @@ zathura_document_get_password(zathura_document_t* document)
|
||||||
return document->password;
|
return document->password;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_page_t*
|
zathura_page_t *zathura_document_get_page(zathura_document_t *document,
|
||||||
zathura_document_get_page(zathura_document_t* document, unsigned int index)
|
unsigned int index) {
|
||||||
{
|
if (document == NULL || document->pages == NULL ||
|
||||||
if (document == NULL || document->pages == NULL || (document->number_of_pages <= index)) {
|
(document->number_of_pages <= index)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return document->pages[index];
|
return document->pages[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void *zathura_document_get_data(zathura_document_t *document) {
|
||||||
zathura_document_get_data(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -343,9 +338,7 @@ zathura_document_get_data(zathura_document_t* document)
|
||||||
return document->data;
|
return document->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_data(zathura_document_t *document, void *data) {
|
||||||
zathura_document_set_data(zathura_document_t* document, void* data)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -354,8 +347,7 @@ zathura_document_set_data(zathura_document_t* document, void* data)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
zathura_document_get_number_of_pages(zathura_document_t* document)
|
zathura_document_get_number_of_pages(zathura_document_t *document) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -363,9 +355,8 @@ zathura_document_get_number_of_pages(zathura_document_t* document)
|
||||||
return document->number_of_pages;
|
return document->number_of_pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_number_of_pages(zathura_document_t *document,
|
||||||
zathura_document_set_number_of_pages(zathura_document_t* document, unsigned int number_of_pages)
|
unsigned int number_of_pages) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -374,8 +365,7 @@ zathura_document_set_number_of_pages(zathura_document_t* document, unsigned int
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
zathura_document_get_current_page_number(zathura_document_t* document)
|
zathura_document_get_current_page_number(zathura_document_t *document) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -383,10 +373,8 @@ zathura_document_get_current_page_number(zathura_document_t* document)
|
||||||
return document->current_page_number;
|
return document->current_page_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_current_page_number(zathura_document_t *document,
|
||||||
zathura_document_set_current_page_number(zathura_document_t* document, unsigned int
|
unsigned int current_page) {
|
||||||
current_page)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -394,9 +382,7 @@ zathura_document_set_current_page_number(zathura_document_t* document, unsigned
|
||||||
document->current_page_number = current_page;
|
document->current_page_number = current_page;
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double zathura_document_get_position_x(zathura_document_t *document) {
|
||||||
zathura_document_get_position_x(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -404,9 +390,7 @@ zathura_document_get_position_x(zathura_document_t* document)
|
||||||
return document->position_x;
|
return document->position_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double zathura_document_get_position_y(zathura_document_t *document) {
|
||||||
zathura_document_get_position_y(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -414,9 +398,8 @@ zathura_document_get_position_y(zathura_document_t* document)
|
||||||
return document->position_y;
|
return document->position_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_position_x(zathura_document_t *document,
|
||||||
zathura_document_set_position_x(zathura_document_t* document, double position_x)
|
double position_x) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -424,9 +407,8 @@ zathura_document_set_position_x(zathura_document_t* document, double position_x)
|
||||||
document->position_x = position_x;
|
document->position_x = position_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_position_y(zathura_document_t *document,
|
||||||
zathura_document_set_position_y(zathura_document_t* document, double position_y)
|
double position_y) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -434,9 +416,7 @@ zathura_document_set_position_y(zathura_document_t* document, double position_y)
|
||||||
document->position_y = position_y;
|
document->position_y = position_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double zathura_document_get_zoom(zathura_document_t *document) {
|
||||||
zathura_document_get_zoom(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -444,9 +424,7 @@ zathura_document_get_zoom(zathura_document_t* document)
|
||||||
return document->zoom;
|
return document->zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_zoom(zathura_document_t *document, double zoom) {
|
||||||
zathura_document_set_zoom(zathura_document_t* document, double zoom)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -454,9 +432,7 @@ zathura_document_set_zoom(zathura_document_t* document, double zoom)
|
||||||
document->zoom = zoom;
|
document->zoom = zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double zathura_document_get_scale(zathura_document_t *document) {
|
||||||
zathura_document_get_scale(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -471,9 +447,7 @@ zathura_document_get_scale(zathura_document_t* document)
|
||||||
return document->zoom * ppi / 72.0;
|
return document->zoom * ppi / 72.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int zathura_document_get_rotation(zathura_document_t *document) {
|
||||||
zathura_document_get_rotation(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -481,9 +455,8 @@ zathura_document_get_rotation(zathura_document_t* document)
|
||||||
return document->rotate;
|
return document->rotate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_rotation(zathura_document_t *document,
|
||||||
zathura_document_set_rotation(zathura_document_t* document, unsigned int rotation)
|
unsigned int rotation) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -501,8 +474,7 @@ zathura_document_set_rotation(zathura_document_t* document, unsigned int rotatio
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_adjust_mode_t
|
zathura_adjust_mode_t
|
||||||
zathura_document_get_adjust_mode(zathura_document_t* document)
|
zathura_document_get_adjust_mode(zathura_document_t *document) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return ZATHURA_ADJUST_NONE;
|
return ZATHURA_ADJUST_NONE;
|
||||||
}
|
}
|
||||||
|
@ -510,9 +482,8 @@ zathura_document_get_adjust_mode(zathura_document_t* document)
|
||||||
return document->adjust_mode;
|
return document->adjust_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_adjust_mode(zathura_document_t *document,
|
||||||
zathura_document_set_adjust_mode(zathura_document_t* document, zathura_adjust_mode_t mode)
|
zathura_adjust_mode_t mode) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -520,9 +491,7 @@ zathura_document_set_adjust_mode(zathura_document_t* document, zathura_adjust_mo
|
||||||
document->adjust_mode = mode;
|
document->adjust_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int zathura_document_get_page_offset(zathura_document_t *document) {
|
||||||
zathura_document_get_page_offset(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -530,9 +499,8 @@ zathura_document_get_page_offset(zathura_document_t* document)
|
||||||
return document->page_offset;
|
return document->page_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_page_offset(zathura_document_t *document,
|
||||||
zathura_document_set_page_offset(zathura_document_t* document, unsigned int page_offset)
|
unsigned int page_offset) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -540,61 +508,53 @@ zathura_document_set_page_offset(zathura_document_t* document, unsigned int page
|
||||||
document->page_offset = page_offset;
|
document->page_offset = page_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_viewport_width(zathura_document_t *document,
|
||||||
zathura_document_set_viewport_width(zathura_document_t* document, unsigned int width)
|
unsigned int width) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document->view_width = width;
|
document->view_width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_viewport_height(zathura_document_t *document,
|
||||||
zathura_document_set_viewport_height(zathura_document_t* document, unsigned int height)
|
unsigned int height) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document->view_height = height;
|
document->view_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_viewport_ppi(zathura_document_t *document,
|
||||||
zathura_document_set_viewport_ppi(zathura_document_t* document, double ppi)
|
double ppi) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document->view_ppi = ppi;
|
document->view_ppi = ppi;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_get_viewport_size(zathura_document_t *document,
|
||||||
zathura_document_get_viewport_size(zathura_document_t* document,
|
unsigned int *height,
|
||||||
unsigned int *height, unsigned int* width)
|
unsigned int *width) {
|
||||||
{
|
|
||||||
g_return_if_fail(document != NULL && height != NULL && width != NULL);
|
g_return_if_fail(document != NULL && height != NULL && width != NULL);
|
||||||
*height = document->view_height;
|
*height = document->view_height;
|
||||||
*width = document->view_width;
|
*width = document->view_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double zathura_document_get_viewport_ppi(zathura_document_t *document) {
|
||||||
zathura_document_get_viewport_ppi(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return document->view_ppi;
|
return document->view_ppi;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_device_factors(zathura_document_t *document,
|
||||||
zathura_document_set_device_factors(zathura_document_t* document,
|
double x_factor, double y_factor) {
|
||||||
double x_factor, double y_factor)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fabs(x_factor) < DBL_EPSILON || fabs(y_factor) < DBL_EPSILON) {
|
if (fabs(x_factor) < DBL_EPSILON || fabs(y_factor) < DBL_EPSILON) {
|
||||||
girara_debug("Ignoring new device factors %0.2f and %0.2f: too small",
|
girara_debug("Ignoring new device factors %0.2f and %0.2f: too small",
|
||||||
x_factor, y_factor);
|
x_factor, y_factor);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,8 +563,7 @@ zathura_document_set_device_factors(zathura_document_t* document,
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_device_factors_t
|
zathura_device_factors_t
|
||||||
zathura_document_get_device_factors(zathura_document_t* document)
|
zathura_document_get_device_factors(zathura_document_t *document) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
/* The function is guaranteed to not return zero values */
|
/* The function is guaranteed to not return zero values */
|
||||||
return (zathura_device_factors_t){1.0, 1.0};
|
return (zathura_device_factors_t){1.0, 1.0};
|
||||||
|
@ -613,20 +572,17 @@ zathura_document_get_device_factors(zathura_document_t* document)
|
||||||
return document->device_factors;
|
return document->device_factors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_get_cell_size(zathura_document_t *document,
|
||||||
zathura_document_get_cell_size(zathura_document_t* document,
|
unsigned int *height, unsigned int *width) {
|
||||||
unsigned int* height, unsigned int* width)
|
|
||||||
{
|
|
||||||
g_return_if_fail(document != NULL && height != NULL && width != NULL);
|
g_return_if_fail(document != NULL && height != NULL && width != NULL);
|
||||||
|
|
||||||
page_calc_height_width(document, document->cell_height, document->cell_width,
|
page_calc_height_width(document, document->cell_height, document->cell_width,
|
||||||
height, width, true);
|
height, width, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_get_document_size(zathura_document_t *document,
|
||||||
zathura_document_get_document_size(zathura_document_t* document,
|
unsigned int *height,
|
||||||
unsigned int* height, unsigned int* width)
|
unsigned int *width) {
|
||||||
{
|
|
||||||
g_return_if_fail(document != NULL && height != NULL && width != NULL);
|
g_return_if_fail(document != NULL && height != NULL && width != NULL);
|
||||||
|
|
||||||
const unsigned int npag = zathura_document_get_number_of_pages(document);
|
const unsigned int npag = zathura_document_get_number_of_pages(document);
|
||||||
|
@ -636,22 +592,23 @@ zathura_document_get_document_size(zathura_document_t* document,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned int c0 = zathura_document_get_first_page_column(document);
|
const unsigned int c0 = zathura_document_get_first_page_column(document);
|
||||||
const unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
|
const unsigned int nrow =
|
||||||
const unsigned int pad = zathura_document_get_page_padding(document);
|
(npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
|
||||||
|
const unsigned int pad = zathura_document_get_page_padding(document);
|
||||||
|
|
||||||
unsigned int cell_height = 0;
|
unsigned int cell_height = 0;
|
||||||
unsigned int cell_width = 0;
|
unsigned int cell_width = 0;
|
||||||
zathura_document_get_cell_size(document, &cell_height, &cell_width);
|
zathura_document_get_cell_size(document, &cell_height, &cell_width);
|
||||||
|
|
||||||
*width = ncol * cell_width + (ncol - 1) * pad;
|
*width = ncol * cell_width + (ncol - 1) * pad;
|
||||||
*height = nrow * cell_height + (nrow - 1) * pad;
|
*height = nrow * cell_height + (nrow - 1) * pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void zathura_document_set_page_layout(zathura_document_t *document,
|
||||||
zathura_document_set_page_layout(zathura_document_t* document, unsigned int page_padding,
|
unsigned int page_padding,
|
||||||
unsigned int pages_per_row, unsigned int first_page_column)
|
unsigned int pages_per_row,
|
||||||
{
|
unsigned int first_page_column) {
|
||||||
g_return_if_fail(document != NULL);
|
g_return_if_fail(document != NULL);
|
||||||
|
|
||||||
document->page_padding = page_padding;
|
document->page_padding = page_padding;
|
||||||
|
@ -666,18 +623,14 @@ zathura_document_set_page_layout(zathura_document_t* document, unsigned int page
|
||||||
document->first_page_column = first_page_column;
|
document->first_page_column = first_page_column;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int zathura_document_get_page_padding(zathura_document_t *document) {
|
||||||
zathura_document_get_page_padding(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return document->page_padding;
|
return document->page_padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int zathura_document_get_pages_per_row(zathura_document_t *document) {
|
||||||
zathura_document_get_pages_per_row(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -685,22 +638,21 @@ zathura_document_get_pages_per_row(zathura_document_t* document)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
zathura_document_get_first_page_column(zathura_document_t* document)
|
zathura_document_get_first_page_column(zathura_document_t *document) {
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return document->first_page_column;
|
return document->first_page_column;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_error_t
|
zathura_error_t zathura_document_save_as(zathura_document_t *document,
|
||||||
zathura_document_save_as(zathura_document_t* document, const char* path)
|
const char *path) {
|
||||||
{
|
|
||||||
if (document == NULL || document->plugin == NULL || path == NULL) {
|
if (document == NULL || document->plugin == NULL || path == NULL) {
|
||||||
return ZATHURA_ERROR_UNKNOWN;
|
return ZATHURA_ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin);
|
const zathura_plugin_functions_t *functions =
|
||||||
|
zathura_plugin_get_functions(document->plugin);
|
||||||
if (functions->document_save_as == NULL) {
|
if (functions->document_save_as == NULL) {
|
||||||
return ZATHURA_ERROR_NOT_IMPLEMENTED;
|
return ZATHURA_ERROR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
@ -708,15 +660,16 @@ zathura_document_save_as(zathura_document_t* document, const char* path)
|
||||||
return functions->document_save_as(document, document->data, path);
|
return functions->document_save_as(document, document->data, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_tree_node_t*
|
girara_tree_node_t *
|
||||||
zathura_document_index_generate(zathura_document_t* document, zathura_error_t* error)
|
zathura_document_index_generate(zathura_document_t *document,
|
||||||
{
|
zathura_error_t *error) {
|
||||||
if (document == NULL || document->plugin == NULL) {
|
if (document == NULL || document->plugin == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
|
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin);
|
const zathura_plugin_functions_t *functions =
|
||||||
|
zathura_plugin_get_functions(document->plugin);
|
||||||
if (functions->document_index_generate == NULL) {
|
if (functions->document_index_generate == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
|
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -725,15 +678,15 @@ zathura_document_index_generate(zathura_document_t* document, zathura_error_t* e
|
||||||
return functions->document_index_generate(document, document->data, error);
|
return functions->document_index_generate(document, document->data, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_list_t*
|
girara_list_t *zathura_document_attachments_get(zathura_document_t *document,
|
||||||
zathura_document_attachments_get(zathura_document_t* document, zathura_error_t* error)
|
zathura_error_t *error) {
|
||||||
{
|
|
||||||
if (document == NULL || document->plugin == NULL) {
|
if (document == NULL || document->plugin == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
|
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin);
|
const zathura_plugin_functions_t *functions =
|
||||||
|
zathura_plugin_get_functions(document->plugin);
|
||||||
if (functions->document_attachments_get == NULL) {
|
if (functions->document_attachments_get == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
|
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -742,46 +695,49 @@ zathura_document_attachments_get(zathura_document_t* document, zathura_error_t*
|
||||||
return functions->document_attachments_get(document, document->data, error);
|
return functions->document_attachments_get(document, document->data, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_error_t
|
zathura_error_t zathura_document_attachment_save(zathura_document_t *document,
|
||||||
zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file)
|
const char *attachment,
|
||||||
{
|
const char *file) {
|
||||||
if (document == NULL || document->plugin == NULL) {
|
if (document == NULL || document->plugin == NULL) {
|
||||||
return ZATHURA_ERROR_INVALID_ARGUMENTS;
|
return ZATHURA_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin);
|
const zathura_plugin_functions_t *functions =
|
||||||
|
zathura_plugin_get_functions(document->plugin);
|
||||||
if (functions->document_attachment_save == NULL) {
|
if (functions->document_attachment_save == NULL) {
|
||||||
return ZATHURA_ERROR_NOT_IMPLEMENTED;
|
return ZATHURA_ERROR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return functions->document_attachment_save(document, document->data, attachment, file);
|
return functions->document_attachment_save(document, document->data,
|
||||||
|
attachment, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_list_t*
|
girara_list_t *zathura_document_get_information(zathura_document_t *document,
|
||||||
zathura_document_get_information(zathura_document_t* document, zathura_error_t* error)
|
zathura_error_t *error) {
|
||||||
{
|
|
||||||
if (document == NULL || document->plugin == NULL) {
|
if (document == NULL || document->plugin == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
|
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const zathura_plugin_functions_t* functions = zathura_plugin_get_functions(document->plugin);
|
const zathura_plugin_functions_t *functions =
|
||||||
|
zathura_plugin_get_functions(document->plugin);
|
||||||
if (functions->document_get_information == NULL) {
|
if (functions->document_get_information == NULL) {
|
||||||
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
|
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_list_t* result = functions->document_get_information(document, document->data, error);
|
girara_list_t *result =
|
||||||
|
functions->document_get_information(document, document->data, error);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
girara_list_set_free_function(result, (girara_free_function_t) zathura_document_information_entry_free);
|
girara_list_set_free_function(
|
||||||
|
result,
|
||||||
|
(girara_free_function_t)zathura_document_information_entry_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_plugin_t*
|
zathura_plugin_t *zathura_document_get_plugin(zathura_document_t *document) {
|
||||||
zathura_document_get_plugin(zathura_document_t* document)
|
|
||||||
{
|
|
||||||
if (document == NULL) {
|
if (document == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,7 +336,7 @@ zathura_plugin_free(zathura_plugin_t* plugin)
|
||||||
if (plugin == NULL) {
|
if (plugin == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin->path != NULL) {
|
if (plugin->path != NULL) {
|
||||||
g_free(plugin->path);
|
g_free(plugin->path);
|
||||||
}
|
}
|
||||||
|
|
722
zathura/render.c
722
zathura/render.c
File diff suppressed because it is too large
Load diff
|
@ -204,7 +204,7 @@ synctex_rectangles_from_position(const char* filename, const char* input_file,
|
||||||
|
|
||||||
girara_list_t* hitlist_flat = flatten_rectangles(hitlist);
|
girara_list_t* hitlist_flat = flatten_rectangles(hitlist);
|
||||||
girara_list_free(hitlist);
|
girara_list_free(hitlist);
|
||||||
|
|
||||||
return hitlist_flat;
|
return hitlist_flat;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue