This commit is contained in:
Jimmy 2021-02-04 16:16:02 -08:00
parent 12c8cd9110
commit 46dfa2be22
8 changed files with 1003 additions and 1064 deletions

1
.gitignore vendored
View file

@ -36,3 +36,4 @@ compile_commands.json
*.log
.ycm_extra_conf.py
_*/
.ccls-cache/

View file

@ -5,15 +5,19 @@
#include <math.h>
double
page_calc_height_width(zathura_document_t* document, double height,
double width, unsigned int* page_height,
unsigned int* page_width, bool rotate)
{
g_return_val_if_fail(document != NULL && page_height != NULL && page_width != NULL, 0.0);
// @debug
#include <stdio.h>
double page_calc_height_width(zathura_document_t *document, double height,
double width, unsigned int *page_height,
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);
// 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) {
*page_width = round(height * scale);
*page_height = round(width * scale);
@ -27,10 +31,8 @@ page_calc_height_width(zathura_document_t* document, double height,
return scale;
}
void
page_calc_position(zathura_document_t* document, double x, double y, double* xn,
double* yn)
{
void page_calc_position(zathura_document_t *document, double x, double y,
double *xn, double *yn) {
g_return_if_fail(document != NULL && xn != NULL && yn != NULL);
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
position_to_page_number(zathura_document_t* document, double pos_x,
double pos_y)
{
unsigned int position_to_page_number(zathura_document_t *document, double pos_x,
double pos_y) {
g_return_val_if_fail(document != NULL, 0);
unsigned int doc_width, doc_height;
@ -75,8 +75,10 @@ position_to_page_number(zathura_document_t* document, double pos_x,
nrow = 1 + (npag - (ncol - c0 - 1) + (ncol - 1)) / ncol;
}
unsigned int col = 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 col =
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);
if (page < c0 - 1) {
@ -86,12 +88,9 @@ position_to_page_number(zathura_document_t* document, double pos_x,
}
}
void
page_number_to_position(zathura_document_t* document, unsigned int page_number,
double xalign, double yalign, double* pos_x,
double* pos_y)
{
void page_number_to_position(zathura_document_t *document,
unsigned int page_number, double xalign,
double yalign, double *pos_x, double *pos_y) {
g_return_if_fail(document != NULL);
unsigned int c0 = zathura_document_get_first_page_column(document);
@ -113,14 +112,18 @@ page_number_to_position(zathura_document_t* document, unsigned int page_number,
unsigned int doc_height = 0, doc_width = 0;
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;
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) {
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 */
@ -128,10 +131,7 @@ page_number_to_position(zathura_document_t* document, unsigned int page_number,
*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);
/* position at the center of the viewport */
@ -151,13 +151,13 @@ page_is_visible(zathura_document_t *document, unsigned int page_number)
unsigned int view_width, view_height;
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 &&
fabs(pos_y - page_y) < 0.5 * (double)(view_height + cell_height) / (double)doc_height);
return (fabs(pos_x - page_x) <
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
zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value)
{
void zathura_adjustment_set_value(GtkAdjustment *adjustment, gdouble value) {
const gdouble lower = gtk_adjustment_get_lower(adjustment);
const gdouble upper_m_size = gtk_adjustment_get_upper(adjustment) -
gtk_adjustment_get_page_size(adjustment);
@ -165,9 +165,7 @@ zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value)
gtk_adjustment_set_value(adjustment, MAX(lower, MIN(upper_m_size, value)));
}
gdouble
zathura_adjustment_get_ratio(GtkAdjustment* adjustment)
{
gdouble zathura_adjustment_get_ratio(GtkAdjustment *adjustment) {
gdouble lower = gtk_adjustment_get_lower(adjustment);
gdouble upper = gtk_adjustment_get_upper(adjustment);
gdouble page_size = gtk_adjustment_get_page_size(adjustment);
@ -176,10 +174,8 @@ zathura_adjustment_get_ratio(GtkAdjustment* adjustment)
return (value - lower + page_size / 2.0) / (upper - lower);
}
void
zathura_adjustment_set_value_from_ratio(GtkAdjustment* adjustment,
gdouble ratio)
{
void zathura_adjustment_set_value_from_ratio(GtkAdjustment *adjustment,
gdouble ratio) {
if (ratio == 0.0) {
return;
}

View file

@ -1,45 +1,50 @@
/* SPDX-License-Identifier: Zlib */
#include <gio/gio.h>
#include <glib.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <glib.h>
#include <gio/gio.h>
#include <math.h>
#include <girara/datastructures.h>
#include <girara/utils.h>
#include "adjustment.h"
#include "content-type.h"
#include "document.h"
#include "utils.h"
#include "zathura.h"
#include "page.h"
#include "plugin.h"
#include "content-type.h"
#include "utils.h"
#include "zathura.h"
// @debug
#include <stdio.h>
/**
* Document
*/
struct zathura_document_s {
char* file_path; /**< File path of the document */
char* uri; /**< URI of the document */
char* basename; /**< Basename of the document */
char *file_path; /**< File path of the document */
char *uri; /**< URI of the document */
char *basename; /**< Basename 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 number_of_pages; /**< Number of pages */
double zoom; /**< Zoom value */
unsigned int rotate; /**< Rotation */
void* data; /**< Custom data */
void *data; /**< Custom data */
zathura_adjust_mode_t adjust_mode; /**< Adjust mode (best-fit, width) */
int page_offset; /**< Page offset */
double cell_width; /**< width of a page cell in the document (not transformed by scale and rotation) */
double cell_height; /**< height 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
by scale and rotation) */
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 */
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
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 page_padding; /**< padding between pages */
@ -49,30 +54,27 @@ struct zathura_document_s {
/**
* Document pages
*/
zathura_page_t** pages;
zathura_page_t **pages;
/**
* Used plugin
*/
zathura_plugin_t* plugin;
zathura_plugin_t *plugin;
};
static void
check_set_error(zathura_error_t* error, zathura_error_t code) {
static void check_set_error(zathura_error_t *error, zathura_error_t code) {
if (error != NULL) {
*error = code;
}
}
static bool
hash_file_sha256(uint8_t* dst, const char* path)
{
FILE* f = fopen(path, "rb");
static bool hash_file_sha256(uint8_t *dst, const char *path) {
FILE *f = fopen(path, "rb");
if (f == NULL) {
return false;
}
GChecksum* checksum = g_checksum_new(G_CHECKSUM_SHA256);
GChecksum *checksum = g_checksum_new(G_CHECKSUM_SHA256);
if (checksum == NULL) {
fclose(f);
return false;
@ -97,19 +99,18 @@ hash_file_sha256(uint8_t* dst, const char* path)
return true;
}
zathura_document_t*
zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
const char* password, zathura_error_t* error)
{
zathura_document_t *zathura_document_open(zathura_t *zathura, const char *path,
const char *uri, const char *password,
zathura_error_t *error) {
if (zathura == NULL || path == NULL) {
return NULL;
}
GFile* file = g_file_new_for_path(path);
char* real_path = NULL;
char* content_type = NULL;
zathura_plugin_t* plugin = NULL;
zathura_document_t* document = NULL;
GFile *file = g_file_new_for_path(path);
char *real_path = NULL;
char *content_type = NULL;
zathura_plugin_t *plugin = NULL;
zathura_document_t *document = NULL;
if (file == NULL) {
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;
}
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) {
girara_error("Could not determine file type.");
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
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) {
girara_error("Unknown file type: '%s'", content_type);
check_set_error(error, ZATHURA_ERROR_UNKNOWN);
g_free((void*)content_type);
g_free((void *)content_type);
content_type = NULL;
goto error_free;
@ -156,7 +160,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
if (document->uri == NULL) {
document->basename = g_file_get_basename(file);
} 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);
g_object_unref(gf);
}
@ -180,7 +184,8 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
file = NULL;
/* 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) {
girara_error("plugin has no open function\n");
goto error_free;
@ -194,14 +199,15 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
}
/* 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) {
check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY);
goto error_free;
}
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
zathura_page_t* page = zathura_page_new(document, page_id, NULL);
for (unsigned int page_id = 0; page_id < document->number_of_pages;
page_id++) {
zathura_page_t *page = zathura_page_new(document, page_id, NULL);
if (page == NULL) {
check_set_error(error, ZATHURA_ERROR_OUT_OF_MEMORY);
goto error_free;
@ -209,7 +215,8 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
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);
if (document->cell_width < width)
document->cell_width = width;
@ -239,16 +246,15 @@ error_free:
return NULL;
}
zathura_error_t
zathura_document_free(zathura_document_t* document)
{
zathura_error_t zathura_document_free(zathura_document_t *document) {
if (document == NULL || document->plugin == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
if (document->pages != NULL) {
/* 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]);
document->pages[page_id] = NULL;
}
@ -257,7 +263,8 @@ zathura_document_free(zathura_document_t* document)
/* free document */
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) {
error = ZATHURA_ERROR_NOT_IMPLEMENTED;
} else {
@ -273,9 +280,7 @@ zathura_document_free(zathura_document_t* document)
return error;
}
const char*
zathura_document_get_path(zathura_document_t* document)
{
const char *zathura_document_get_path(zathura_document_t *document) {
if (document == NULL) {
return NULL;
}
@ -283,9 +288,7 @@ zathura_document_get_path(zathura_document_t* document)
return document->file_path;
}
const uint8_t*
zathura_document_get_hash(zathura_document_t* document)
{
const uint8_t *zathura_document_get_hash(zathura_document_t *document) {
if (document == NULL) {
return NULL;
}
@ -293,9 +296,7 @@ zathura_document_get_hash(zathura_document_t* document)
return document->hash_sha256;
}
const char*
zathura_document_get_uri(zathura_document_t* document)
{
const char *zathura_document_get_uri(zathura_document_t *document) {
if (document == NULL) {
return NULL;
}
@ -303,9 +304,7 @@ zathura_document_get_uri(zathura_document_t* document)
return document->uri;
}
const char*
zathura_document_get_basename(zathura_document_t* document)
{
const char *zathura_document_get_basename(zathura_document_t *document) {
if (document == NULL) {
return NULL;
}
@ -313,9 +312,7 @@ zathura_document_get_basename(zathura_document_t* document)
return document->basename;
}
const char*
zathura_document_get_password(zathura_document_t* document)
{
const char *zathura_document_get_password(zathura_document_t *document) {
if (document == NULL) {
return NULL;
}
@ -323,19 +320,17 @@ zathura_document_get_password(zathura_document_t* document)
return document->password;
}
zathura_page_t*
zathura_document_get_page(zathura_document_t* document, unsigned int index)
{
if (document == NULL || document->pages == NULL || (document->number_of_pages <= index)) {
zathura_page_t *zathura_document_get_page(zathura_document_t *document,
unsigned int index) {
if (document == NULL || document->pages == NULL ||
(document->number_of_pages <= index)) {
return NULL;
}
return document->pages[index];
}
void*
zathura_document_get_data(zathura_document_t* document)
{
void *zathura_document_get_data(zathura_document_t *document) {
if (document == NULL) {
return NULL;
}
@ -343,9 +338,7 @@ zathura_document_get_data(zathura_document_t* document)
return document->data;
}
void
zathura_document_set_data(zathura_document_t* document, void* data)
{
void zathura_document_set_data(zathura_document_t *document, void *data) {
if (document == NULL) {
return;
}
@ -354,8 +347,7 @@ zathura_document_set_data(zathura_document_t* document, void* data)
}
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) {
return 0;
}
@ -363,9 +355,8 @@ zathura_document_get_number_of_pages(zathura_document_t* document)
return document->number_of_pages;
}
void
zathura_document_set_number_of_pages(zathura_document_t* document, unsigned int number_of_pages)
{
void zathura_document_set_number_of_pages(zathura_document_t *document,
unsigned int number_of_pages) {
if (document == NULL) {
return;
}
@ -374,8 +365,7 @@ zathura_document_set_number_of_pages(zathura_document_t* document, 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) {
return 0;
}
@ -383,10 +373,8 @@ zathura_document_get_current_page_number(zathura_document_t* document)
return document->current_page_number;
}
void
zathura_document_set_current_page_number(zathura_document_t* document, unsigned int
current_page)
{
void zathura_document_set_current_page_number(zathura_document_t *document,
unsigned int current_page) {
if (document == NULL) {
return;
}
@ -394,9 +382,7 @@ zathura_document_set_current_page_number(zathura_document_t* document, unsigned
document->current_page_number = current_page;
}
double
zathura_document_get_position_x(zathura_document_t* document)
{
double zathura_document_get_position_x(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
@ -404,9 +390,7 @@ zathura_document_get_position_x(zathura_document_t* document)
return document->position_x;
}
double
zathura_document_get_position_y(zathura_document_t* document)
{
double zathura_document_get_position_y(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
@ -414,9 +398,8 @@ zathura_document_get_position_y(zathura_document_t* document)
return document->position_y;
}
void
zathura_document_set_position_x(zathura_document_t* document, double position_x)
{
void zathura_document_set_position_x(zathura_document_t *document,
double position_x) {
if (document == NULL) {
return;
}
@ -424,9 +407,8 @@ zathura_document_set_position_x(zathura_document_t* document, double position_x)
document->position_x = position_x;
}
void
zathura_document_set_position_y(zathura_document_t* document, double position_y)
{
void zathura_document_set_position_y(zathura_document_t *document,
double position_y) {
if (document == NULL) {
return;
}
@ -434,9 +416,7 @@ zathura_document_set_position_y(zathura_document_t* document, double position_y)
document->position_y = position_y;
}
double
zathura_document_get_zoom(zathura_document_t* document)
{
double zathura_document_get_zoom(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
@ -444,9 +424,7 @@ zathura_document_get_zoom(zathura_document_t* document)
return document->zoom;
}
void
zathura_document_set_zoom(zathura_document_t* document, double zoom)
{
void zathura_document_set_zoom(zathura_document_t *document, double zoom) {
if (document == NULL) {
return;
}
@ -454,9 +432,7 @@ zathura_document_set_zoom(zathura_document_t* document, double zoom)
document->zoom = zoom;
}
double
zathura_document_get_scale(zathura_document_t* document)
{
double zathura_document_get_scale(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
@ -471,9 +447,7 @@ zathura_document_get_scale(zathura_document_t* document)
return document->zoom * ppi / 72.0;
}
unsigned int
zathura_document_get_rotation(zathura_document_t* document)
{
unsigned int zathura_document_get_rotation(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
@ -481,9 +455,8 @@ zathura_document_get_rotation(zathura_document_t* document)
return document->rotate;
}
void
zathura_document_set_rotation(zathura_document_t* document, unsigned int rotation)
{
void zathura_document_set_rotation(zathura_document_t *document,
unsigned int rotation) {
if (document == NULL) {
return;
}
@ -501,8 +474,7 @@ zathura_document_set_rotation(zathura_document_t* document, unsigned int rotatio
}
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) {
return ZATHURA_ADJUST_NONE;
}
@ -510,9 +482,8 @@ zathura_document_get_adjust_mode(zathura_document_t* document)
return document->adjust_mode;
}
void
zathura_document_set_adjust_mode(zathura_document_t* document, zathura_adjust_mode_t mode)
{
void zathura_document_set_adjust_mode(zathura_document_t *document,
zathura_adjust_mode_t mode) {
if (document == NULL) {
return;
}
@ -520,9 +491,7 @@ zathura_document_set_adjust_mode(zathura_document_t* document, zathura_adjust_mo
document->adjust_mode = mode;
}
int
zathura_document_get_page_offset(zathura_document_t* document)
{
int zathura_document_get_page_offset(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
@ -530,9 +499,8 @@ zathura_document_get_page_offset(zathura_document_t* document)
return document->page_offset;
}
void
zathura_document_set_page_offset(zathura_document_t* document, unsigned int page_offset)
{
void zathura_document_set_page_offset(zathura_document_t *document,
unsigned int page_offset) {
if (document == NULL) {
return;
}
@ -540,55 +508,47 @@ zathura_document_set_page_offset(zathura_document_t* document, unsigned int page
document->page_offset = page_offset;
}
void
zathura_document_set_viewport_width(zathura_document_t* document, unsigned int width)
{
void zathura_document_set_viewport_width(zathura_document_t *document,
unsigned int width) {
if (document == NULL) {
return;
}
document->view_width = width;
}
void
zathura_document_set_viewport_height(zathura_document_t* document, unsigned int height)
{
void zathura_document_set_viewport_height(zathura_document_t *document,
unsigned int height) {
if (document == NULL) {
return;
}
document->view_height = height;
}
void
zathura_document_set_viewport_ppi(zathura_document_t* document, double ppi)
{
void zathura_document_set_viewport_ppi(zathura_document_t *document,
double ppi) {
if (document == NULL) {
return;
}
document->view_ppi = ppi;
}
void
zathura_document_get_viewport_size(zathura_document_t* document,
unsigned int *height, unsigned int* width)
{
void zathura_document_get_viewport_size(zathura_document_t *document,
unsigned int *height,
unsigned int *width) {
g_return_if_fail(document != NULL && height != NULL && width != NULL);
*height = document->view_height;
*width = document->view_width;
}
double
zathura_document_get_viewport_ppi(zathura_document_t* document)
{
double zathura_document_get_viewport_ppi(zathura_document_t *document) {
if (document == NULL) {
return 0.0;
}
return document->view_ppi;
}
void
zathura_document_set_device_factors(zathura_document_t* document,
double x_factor, double y_factor)
{
void zathura_document_set_device_factors(zathura_document_t *document,
double x_factor, double y_factor) {
if (document == NULL) {
return;
}
@ -603,8 +563,7 @@ zathura_document_set_device_factors(zathura_document_t* document,
}
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) {
/* The function is guaranteed to not return zero values */
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;
}
void
zathura_document_get_cell_size(zathura_document_t* document,
unsigned int* height, unsigned int* width)
{
void zathura_document_get_cell_size(zathura_document_t *document,
unsigned int *height, unsigned int *width) {
g_return_if_fail(document != NULL && height != NULL && width != NULL);
page_calc_height_width(document, document->cell_height, document->cell_width,
height, width, true);
}
void
zathura_document_get_document_size(zathura_document_t* document,
unsigned int* height, unsigned int* width)
{
void zathura_document_get_document_size(zathura_document_t *document,
unsigned int *height,
unsigned int *width) {
g_return_if_fail(document != NULL && height != NULL && width != NULL);
const unsigned int npag = zathura_document_get_number_of_pages(document);
@ -637,7 +593,8 @@ zathura_document_get_document_size(zathura_document_t* 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 =
(npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
const unsigned int pad = zathura_document_get_page_padding(document);
unsigned int cell_height = 0;
@ -648,10 +605,10 @@ zathura_document_get_document_size(zathura_document_t* document,
*height = nrow * cell_height + (nrow - 1) * pad;
}
void
zathura_document_set_page_layout(zathura_document_t* document, unsigned int page_padding,
unsigned int pages_per_row, unsigned int first_page_column)
{
void zathura_document_set_page_layout(zathura_document_t *document,
unsigned int page_padding,
unsigned int pages_per_row,
unsigned int first_page_column) {
g_return_if_fail(document != NULL);
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;
}
unsigned int
zathura_document_get_page_padding(zathura_document_t* document)
{
unsigned int zathura_document_get_page_padding(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
return document->page_padding;
}
unsigned int
zathura_document_get_pages_per_row(zathura_document_t* document)
{
unsigned int zathura_document_get_pages_per_row(zathura_document_t *document) {
if (document == NULL) {
return 0;
}
@ -685,22 +638,21 @@ zathura_document_get_pages_per_row(zathura_document_t* document)
}
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) {
return 0;
}
return document->first_page_column;
}
zathura_error_t
zathura_document_save_as(zathura_document_t* document, const char* path)
{
zathura_error_t zathura_document_save_as(zathura_document_t *document,
const char *path) {
if (document == NULL || document->plugin == NULL || path == NULL) {
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) {
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);
}
girara_tree_node_t*
zathura_document_index_generate(zathura_document_t* document, zathura_error_t* error)
{
girara_tree_node_t *
zathura_document_index_generate(zathura_document_t *document,
zathura_error_t *error) {
if (document == NULL || document->plugin == NULL) {
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
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) {
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
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);
}
girara_list_t*
zathura_document_attachments_get(zathura_document_t* document, zathura_error_t* error)
{
girara_list_t *zathura_document_attachments_get(zathura_document_t *document,
zathura_error_t *error) {
if (document == NULL || document->plugin == NULL) {
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
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) {
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
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);
}
zathura_error_t
zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file)
{
zathura_error_t zathura_document_attachment_save(zathura_document_t *document,
const char *attachment,
const char *file) {
if (document == NULL || document->plugin == NULL) {
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) {
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*
zathura_document_get_information(zathura_document_t* document, zathura_error_t* error)
{
girara_list_t *zathura_document_get_information(zathura_document_t *document,
zathura_error_t *error) {
if (document == NULL || document->plugin == NULL) {
check_set_error(error, ZATHURA_ERROR_INVALID_ARGUMENTS);
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) {
check_set_error(error, ZATHURA_ERROR_NOT_IMPLEMENTED);
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) {
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;
}
zathura_plugin_t*
zathura_document_get_plugin(zathura_document_t* document)
{
zathura_plugin_t *zathura_document_get_plugin(zathura_document_t *document) {
if (document == NULL) {
return NULL;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff