utils.h 3.38 KB
Newer Older
Moritz Lipp's avatar
Moritz Lipp committed
1
/* See LICENSE file for license and copyright information */
2
3
4
5

#ifndef UTILS_H
#define UTILS_H

Moritz Lipp's avatar
Moritz Lipp committed
6
#include <stdbool.h>
Moritz Lipp's avatar
Moritz Lipp committed
7
#include <gtk/gtk.h>
8
#include <girara/types.h>
Moritz Lipp's avatar
Moritz Lipp committed
9

Moritz Lipp's avatar
Moritz Lipp committed
10
11
#include "document.h"

Moritz Lipp's avatar
Moritz Lipp committed
12
13
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))

Moritz Lipp's avatar
Moritz Lipp committed
14
15
16
17
18
19
typedef struct page_offset_s
{
  int x;
  int y;
} page_offset_t;

20
21
22
23
24
25
26
27
28
29
/**
 * This function checks if the file has a valid extension. A extension is
 * evaluated as valid if it matches a supported filetype.
 *
 * @param zathura Zathura object
 * @param path The path to the file
 * @return true if the extension is valid, otherwise false
 */
bool file_valid_extension(zathura_t* zathura, const char* path);

30
31
32
33
34
/**
 * Generates the document index based upon the list retreived from the document
 * object.
 *
 * @param model The tree model
Moritz Lipp's avatar
Moritz Lipp committed
35
36
 * @param parent The tree iterator parent
 * @param tree The Tree iterator
37
38
39
 */
void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree);

Sebastian Ramacher's avatar
Sebastian Ramacher committed
40
41
/**
 * Rotate a rectangle by 0, 90, 180 or 270 degree
Moritz Lipp's avatar
Moritz Lipp committed
42
43
 *
 * @param rectangle the rectangle to rotate
Sebastian Ramacher's avatar
Sebastian Ramacher committed
44
45
46
47
48
 * @param degree rotation degree
 * @param height the height of the enclosing rectangle
 * @param width the width of the enclosing rectangle
 * @return the rotated rectangle
 */
49
zathura_rectangle_t rotate_rectangle(zathura_rectangle_t rectangle, unsigned int degree, double height, double width);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
50

Moritz Lipp's avatar
Moritz Lipp committed
51
52
53
54
55
56
57
58
59
60
/**
 * Calculates the new coordinates based on the rotation and scale level of the
 * document for the given rectangle
 *
 * @param page Page where the rectangle should be
 * @param rectangle The rectangle
 * @return New rectangle
 */
zathura_rectangle_t recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle);

61
62
63
64
65
66
67
68
69
/**
 * Returns the page widget of the page
 *
 * @param zathura The zathura instance
 * @param page The page object
 * @return The page widget of the page
 * @return NULL if an error occured
 */
GtkWidget* zathura_page_get_widget(zathura_t* zathura, zathura_page_t* page);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
70

Moritz Lipp's avatar
Moritz Lipp committed
71
72
73
74
75
76
77
78
/**
 * Set if the search results should be drawn or not
 *
 * @param zathura Zathura instance
 * @param value true if they should be drawn, otherwise false
 */
void document_draw_search_results(zathura_t* zathura, bool value);

79
80
81
82
83
/**
 * Create zathura version string
 *
 * @param zathura The zathura instance
 * @param markup Enable markup
84
 * @return Version string
85
86
87
 */
char* zathura_get_version_string(zathura_t* zathura, bool markup);

88
89
90
91
92
93
94
95
96
97
/**
 * Get a pointer to the GdkAtom of the current clipboard.
 *
 * @param zathura The zathura instance
 *
 * @return A pointer to a GdkAtom object correspoinding to the current
 * clipboard, or NULL.
 */
GdkAtom* get_selection(zathura_t* zathura);

Moritz Lipp's avatar
Moritz Lipp committed
98
99
100
101
102
103
104
105
106
107
108
109
/**
 * Returns the valid scale value which needs to lie in the interval of zoom_min
 * and zoom_max specified in the girara session
 *
 * @param[in] session The session
 * @param[in] scale The proposed scale value
 *
 * @return The corrected scale value
 */
double zathura_correct_scale_value(girara_session_t* session, const double
    scale);

110
111
112
113
114
115
116
117
118
119
120
121
122

/**
 * Extracts the column the first page should be rendered in from the specified
 * list of settings corresponding to the specified pages per row
 *
 * @param[in] first_page_column_list The settings list
 * @param[in] pages_per_row The current pages per row
 *
 * @return The column the first page should be rendered in
 */
unsigned int find_first_page_column(const char* first_page_column_list,
                                    const unsigned int pages_per_row);

123
#endif // UTILS_H