Skip to content

Commit

Permalink
Apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinas committed Jun 16, 2024
1 parent 67e9729 commit 3a722a8
Show file tree
Hide file tree
Showing 34 changed files with 1,109 additions and 1,653 deletions.
70 changes: 23 additions & 47 deletions zathura/adjustment.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

#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)
{
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);
Expand All @@ -18,21 +15,18 @@ page_calc_height_width(zathura_document_t* document, double height,
// 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);
scale = MAX(*page_width / height, *page_height / width);
*page_height = round(width * scale);
scale = MAX(*page_width / height, *page_height / width);
} else {
*page_width = round(width * scale);
*page_width = round(width * scale);
*page_height = round(height * scale);
scale = MAX(*page_width / width, *page_height / height);
scale = MAX(*page_width / width, *page_height / 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);
Expand All @@ -51,10 +45,7 @@ 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;
Expand All @@ -77,7 +68,7 @@ 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 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);
Expand All @@ -88,22 +79,18 @@ 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);
unsigned int npag = zathura_document_get_number_of_pages(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 */
unsigned int row = (page_number + c0 - 1) / ncol;
unsigned int col = (page_number + c0 - 1) % ncol;
unsigned int row = (page_number + c0 - 1) / ncol;
unsigned int col = (page_number + c0 - 1) % ncol;

/* sizes of page cell, viewport and document */
unsigned int cell_height = 0, cell_width = 0;
Expand All @@ -130,10 +117,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 */
Expand All @@ -153,23 +137,18 @@ 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);
const gdouble upper_m_size = gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment);

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);
Expand All @@ -178,16 +157,13 @@ 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;
}

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 value = (upper - lower) * ratio + lower - page_size / 2.0;
Expand Down
19 changes: 8 additions & 11 deletions zathura/adjustment.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* @param rotate honor page's rotation
* @return real scale after rounding
*/
double page_calc_height_width(zathura_document_t* document, double height, 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,
unsigned int* page_width, bool rotate);

/**
* Calculate a page relative position after a rotation. The positions x y are
Expand All @@ -33,8 +33,7 @@ double page_calc_height_width(zathura_document_t* document, double height, doubl
* @param xn the x coordinates after rotation
* @param yn the y coordinates after rotation
*/
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);

/**
* Converts a relative position within the document to a page number.
Expand All @@ -44,8 +43,7 @@ void page_calc_position(zathura_document_t* document, double x, double y,
* @param pos_y the y position relative to the document
* @return page sitting in that position
*/
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);

/**
* Converts a page number to a position in units relative to the document
Expand All @@ -64,8 +62,8 @@ unsigned int position_to_page_number(zathura_document_t* document,
* @param pos_x position that will lie at the center of the viewport.
* @param pos_y position that will lie at the center of the viewport.
*/
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);

/**
* Checks whether a given page falls within the viewport
Expand All @@ -74,7 +72,7 @@ void page_number_to_position(zathura_document_t* document, unsigned int page_num
* @param page_number the page number
* @return true if the page intersects the viewport
*/
bool page_is_visible(zathura_document_t *document, unsigned int page_number);
bool page_is_visible(zathura_document_t* document, unsigned int page_number);

/**
* Set the adjustment value while enforcing its limits
Expand Down Expand Up @@ -104,7 +102,6 @@ gdouble zathura_adjustment_get_ratio(GtkAdjustment* adjustment);
* @param adjustment Adjustment instance
* @param ratio Ratio from which the adjustment value will be set
*/
void zathura_adjustment_set_value_from_ratio(GtkAdjustment* adjustment,
gdouble ratio);
void zathura_adjustment_set_value_from_ratio(GtkAdjustment* adjustment, gdouble ratio);

#endif /* ZATHURA_ADJUSTMENT_H */
3 changes: 1 addition & 2 deletions zathura/bookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <stdbool.h>
#include "zathura.h"

struct zathura_bookmark_s
{
struct zathura_bookmark_s {
gchar* id;
unsigned int page;
double x;
Expand Down
Loading

0 comments on commit 3a722a8

Please sign in to comment.