utils.h 3.6 KB
Newer Older
1
/* SPDX-License-Identifier: Zlib */
2 3 4 5

#ifndef UTILS_H
#define UTILS_H

6
#include <stdbool.h>
Moritz Lipp's avatar
Moritz Lipp committed
7
#include <gtk/gtk.h>
8
#include <girara/types.h>
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
 * Generates the document index based upon the list retrieved from the document
32 33 34
 * 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);

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
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);
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
/**
 * Returns the page widget of the page
 *
 * @param zathura The zathura instance
 * @param page The page object
 * @return The page widget of the page
67
 * @return NULL if an error occurred
68 69
 */
GtkWidget* zathura_page_get_widget(zathura_t* zathura, zathura_page_t* page);
70

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);

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

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 124 125 126 127 128 129 130 131 132
/**
 * Parse color string and print warning if color cannot be parsed.
 *
 * @param[out] color The color
 * @param[in] str Color string
 *
 * @return True if color string can be parsed, false otherwise.
 */
bool parse_color(GdkRGBA* color, const char* str);

133
#endif // UTILS_H