adjustment.h 3.49 KB
Newer Older
1 2 3 4 5 6
/* See LICENSE file for license and copyright information */

#ifndef ZATHURA_ADJUSTMENT_H
#define ZATHURA_ADJUSTMENT_H

#include <gtk/gtk.h>
7 8
#include <stdbool.h>
#include "document.h"
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/**
 * Calculate the page size according to the corrent scaling and rotation if
 * desired.
 *
 * @param document the document
 * @param height width the original height and width
 * @return page_height page_width the scaled and rotated height and width
 * @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);

/**
 * Calculate a page relative position after a rotation. The positions x y are
 * relative to a page, i.e. 0=top of page, 1=bottom of page. They are NOT
 * relative to the entire document.
 *
 * @param document the document
 * @param x y the x y coordinates on the unrotated page
 * @param xn yn the x y coordinates after rotation
 */
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.
 *
 * @param document The document
 * @param pos_x pos_y the 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);

/**
 * Converts a page number to a position in units relative to the document
 *
 * We can specify where to aliwn the viewport and the page. For instance, xalign
 * = 0 means align them on the left margin, xalign = 0.5 means centered, and
 * xalign = 1.0 align them on the right margin.
 *
 * The return value is the position in in units relative to the document (0=top
 * 1=bottom) of the point thet will lie at the center of the viewport.
 *
 * @param document The document
 * @param page_number the given page number
 * @param xalign yalign where to align the viewport and the page
 * @return pos_x 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);

/**
 * Checks whether a given page falls within the viewport
 *
 * @param document The document
 * @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);

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/**
 * Set the adjustment value while enforcing its limits
 *
 * @param adjustment Adjustment instance
 * @param value Adjustment value
 */
void zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value);

/**
 * Compute the adjustment ratio
 *
 * That is, the ratio between the length from the lower bound to the middle of
 * the slider, and the total length of the scrollbar.
 *
 * @param adjustment Scrollbar adjustment
 * @return Adjustment ratio
 */
gdouble zathura_adjustment_get_ratio(GtkAdjustment* adjustment);

/**
 * Set the adjustment value from ratio
 *
 * The ratio is usually obtained from a previous call to
 * zathura_adjustment_get_ratio().
 *
 * @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);

#endif /* ZATHURA_ADJUSTMENT_H */