zathura/document.h

379 lines
8.3 KiB
C
Raw Normal View History

2010-11-17 22:51:15 +01:00
/* See LICENSE file for license and copyright information */
#ifndef DOCUMENT_H
#define DOCUMENT_H
#include <gtk/gtk.h>
2010-11-17 22:51:15 +01:00
#include <stdbool.h>
#include <girara-datastructures.h>
2011-03-05 21:00:41 +01:00
#define PLUGIN_DIR "/usr/lib/zathura"
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
2010-11-17 22:51:15 +01:00
typedef struct zathura_list_s zathura_list_t;
typedef struct zathura_document_s zathura_document_t;
2010-11-18 02:35:33 +01:00
typedef bool (*zathura_document_open_t)(zathura_document_t* document);
2011-03-12 11:32:24 +01:00
/**
* Document plugin structure
*/
2010-11-18 02:35:33 +01:00
typedef struct zathura_document_plugin_s
{
2011-03-12 11:32:24 +01:00
char* file_extension; /**> File extension */
zathura_document_open_t open_function; /**> Document open function */
void* handle; /**> DLL handle */
struct zathura_document_plugin_s *next; /**> Next plugin */ // TODO: Use list_t
2010-11-18 02:35:33 +01:00
} zathura_document_plugin_t;
2011-03-12 11:32:24 +01:00
/**
* Function prototype that is called to register a document plugin
*
* @param The document plugin
*/
typedef void (*zathura_plugin_register_service_t)(zathura_document_plugin_t*);
2011-03-05 21:00:41 +01:00
2011-03-12 11:32:24 +01:00
/**
* Structure for a list
*/
2010-11-17 22:51:15 +01:00
struct zathura_list_s
{
2011-03-12 11:32:24 +01:00
void* data; /**> Data value */
struct zathura_list_s* next; /**> Next element in the list */
2010-11-17 22:51:15 +01:00
};
2011-03-12 11:32:24 +01:00
/**
* Rectangle structure
*/
2010-11-17 22:51:15 +01:00
typedef struct zathura_rectangle_s
{
2011-03-12 11:32:24 +01:00
double x1; /**> X coordinate of point 1 */
double y1; /**> Y coordinate of point 1 */
double x2; /**> X coordinate of point 2 */
double y2; /**> Y coordinate of point 2 */
2010-11-17 22:51:15 +01:00
} zathura_rectangle_t;
2011-03-12 11:32:24 +01:00
/**
* Possible link types
*/
2010-11-17 22:51:15 +01:00
typedef enum zathura_link_type_e
{
2011-03-12 11:32:24 +01:00
ZATHURA_LINK_TO_PAGE, /**> Links to a page */
ZATHURA_LINK_EXTERNAL, /**> Links to an external source */
2010-11-17 22:51:15 +01:00
} zathura_link_type_t;
2011-03-12 11:32:24 +01:00
/**
* Link
*/
2010-11-17 22:51:15 +01:00
typedef struct zathura_link_s
{
2011-03-12 11:32:24 +01:00
zathura_rectangle_t position; /**> Position of the link */
zathura_link_type_t type; /**> Link type */
2010-11-17 22:51:15 +01:00
union
{
2011-03-12 11:32:24 +01:00
unsigned int page_number; /**> Page number */
char* value; /**> Value */
2010-11-17 22:51:15 +01:00
} target;
} zathura_link_t;
2011-03-12 11:32:24 +01:00
/**
* Index element
*/
2010-12-25 00:47:52 +01:00
typedef struct zathura_index_element_s
{
2011-03-12 11:32:24 +01:00
char* title; /**> Title of the element */
zathura_link_type_t type; /**> Type */
2010-12-25 00:47:52 +01:00
union
{
2011-03-12 11:32:24 +01:00
unsigned int page_number; /**> Page number */
char* uri; /**> Uri */
2010-12-25 00:47:52 +01:00
} target;
} zathura_index_element_t;
2011-03-12 11:32:24 +01:00
/**
* Form type
*/
2010-11-17 22:51:15 +01:00
typedef enum zathura_form_type_e
{
2011-03-12 11:32:24 +01:00
ZATHURA_FORM_CHECKBOX, /**> Checkbox */
ZATHURA_FORM_TEXTFIELD /**> Textfield */
2010-11-17 22:51:15 +01:00
} zathura_form_type_t;
2011-03-12 11:32:24 +01:00
/**
* Form element
*/
2010-11-17 22:51:15 +01:00
typedef struct zathura_form_s
{
2011-03-12 11:32:24 +01:00
zathura_rectangle_t position; /**> Position */
zathura_form_type_t type; /**> Type */
2010-11-17 22:51:15 +01:00
} zathura_form_t;
2011-03-12 11:32:24 +01:00
/**
* Page
*/
2010-11-17 22:51:15 +01:00
typedef struct zathura_page_s
{
2011-03-12 11:32:24 +01:00
double height; /**> Page height */
double width; /**> Page width */
double offset; /**> Page offset */
unsigned int number; /**> Page number */
zathura_document_t* document; /**> Document */
void* data; /**> Custom data */
bool rendered; /**> Page has been rendered */
GStaticMutex lock; /**> Lock */
2010-11-17 22:51:15 +01:00
} zathura_page_t;
2011-03-12 11:32:24 +01:00
/**
* Document
*/
2010-11-17 22:51:15 +01:00
struct zathura_document_s
{
2011-03-12 11:32:24 +01:00
char* file_path; /**> File path 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 scale; /**> Scale value */
int rotate; /**> Rotation */
void* data; /**> Custom data */
2010-11-17 22:51:15 +01:00
struct
{
2011-03-12 11:32:24 +01:00
/**
* Frees the document
*
* @param document The document
*/
2010-11-18 02:35:33 +01:00
bool (*document_free)(zathura_document_t* document);
2011-03-12 11:32:24 +01:00
/**
* Generates the document index
*
* @param document The document
* @return NULL if an error occured or no index exists
*/
girara_tree_node_t* (*document_index_generate)(zathura_document_t* document);
2011-03-12 11:32:24 +01:00
/**
* Save the document
*
* @param document The document
* @param path The new path
* @return true if no error occured
*/
2010-11-18 02:35:33 +01:00
bool (*document_save_as)(zathura_document_t* document, const char* path);
2011-03-12 11:32:24 +01:00
/**
* Get list of attachments
*
* @param document The document
* @return NULL if an error occured, otherwise the attachment list
*/
2010-11-18 02:35:33 +01:00
zathura_list_t* (*document_attachments_get)(zathura_document_t* document);
2011-03-12 11:32:24 +01:00
/**
* Gets the page object
*
* @param document The document
* @param page_id Number of the page
* @return The page object or NULL, if an error occured
*/
zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id);
2011-03-12 11:32:24 +01:00
/**
* Search text
*
* @param page The page
* @param text Search item
* @return List of results
*/
2010-11-17 22:51:15 +01:00
zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text);
2011-03-12 11:32:24 +01:00
/**
* Get links on a page
*
* @param page
* @return List of links
*/
2010-11-17 22:51:15 +01:00
zathura_list_t* (*page_links_get)(zathura_page_t* page);
2011-03-12 11:32:24 +01:00
/**
* Get form fields
*
* @param page
* @return List of form fields
*/
2010-11-17 22:51:15 +01:00
zathura_list_t* (*page_form_fields_get)(zathura_page_t* page);
2011-03-12 11:32:24 +01:00
/**
* Renders the page
*
* @param page
* @return Rendered page
*/
GtkWidget* (*page_render)(zathura_page_t* page);
2011-03-12 11:32:24 +01:00
/**
* Free page
*
* @param page
* @return true if no error occured, otherwise false
*/
2010-11-18 02:35:33 +01:00
bool (*page_free)(zathura_page_t* page);
2010-11-17 22:51:15 +01:00
} functions;
2010-12-28 00:47:41 +01:00
2011-03-12 11:32:24 +01:00
/**
* Document pages
*/
2010-12-28 00:47:41 +01:00
zathura_page_t** pages;
2010-11-17 22:51:15 +01:00
};
2011-03-12 11:32:24 +01:00
/**
* Load all document plugins
*/
2011-03-05 21:00:41 +01:00
void zathura_document_plugins_load(void);
2011-03-12 11:32:24 +01:00
/**
* Free all document plugins
*/
2011-03-05 21:00:41 +01:00
void zathura_document_plugins_free(void);
2011-03-12 11:32:24 +01:00
/**
* Register document plugin
*/
bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle);
2011-03-12 11:32:24 +01:00
/**
* Open the document
*
* @param path Path to the document
* @param password Password of the document or NULL
* @return The document object
*/
2010-11-18 02:35:33 +01:00
zathura_document_t* zathura_document_open(const char* path, const char* password);
2011-03-12 11:32:24 +01:00
/**
* Free the document
*
* @param document
* @return true if no error occured, otherwise false
*/
2010-11-17 23:15:08 +01:00
bool zathura_document_free(zathura_document_t* document);
2011-03-12 11:32:24 +01:00
/**
* Save the document
*
* @param document The document object
* @param path Path for the saved file
* @return true if no error occured, otherwise false
*/
2010-11-17 23:15:08 +01:00
bool zathura_document_save_as(zathura_document_t* document, const char* path);
2011-03-12 11:32:24 +01:00
/**
* Generate the document index
*
* @param document The document object
* @return Generated index
*/
girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document);
2011-03-12 11:32:24 +01:00
/**
* Get list of attachments
*
* @param document The document object
* @return List of attachments
*/
2010-11-17 23:15:08 +01:00
zathura_list_t* zathura_document_attachments_get(zathura_document_t* document);
2011-03-12 11:32:24 +01:00
/**
* Free document attachments
*
* @param list list of document attachments
* @return
*/
2010-11-17 23:15:08 +01:00
bool zathura_document_attachments_free(zathura_list_t* list);
2011-03-12 11:32:24 +01:00
/**
* Get the page object
*
* @param document The document
* @param page_id Page number
* @return Page object or NULL if an error occured
*/
zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id);
2011-03-12 11:32:24 +01:00
/**
* Frees the page object
*
* @param page The page object
* @return true if no error occured, otherwise false
*/
2010-11-18 02:35:33 +01:00
bool zathura_page_free(zathura_page_t* page);
2011-03-12 11:32:24 +01:00
/**
* Search page
*
* @param page The page object
* @param text Search item
* @return List of results
*/
2010-11-17 22:51:15 +01:00
zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text);
2011-03-12 11:32:24 +01:00
/**
* Get page links
*
* @param page The page object
* @return List of links
*/
2010-11-17 22:51:15 +01:00
zathura_list_t* zathura_page_links_get(zathura_page_t* page);
2011-03-12 11:32:24 +01:00
/**
* Free page links
*
* @param list List of links
* @return true if no error occured, otherwise false
*/
2010-11-17 22:51:15 +01:00
bool zathura_page_links_free(zathura_list_t* list);
2011-03-12 11:32:24 +01:00
/**
* Get list of form fields
*
* @param page The page object
* @return List of form fields
*/
2010-11-17 22:51:15 +01:00
zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page);
2011-03-12 11:32:24 +01:00
/**
* Free list of form fields
*
* @param list List of form fields
* @return true if no error occured, otherwise false
*/
2010-11-17 22:51:15 +01:00
bool zathura_page_form_fields_free(zathura_list_t* list);
2011-03-12 11:32:24 +01:00
/**
* Render page
*
* @param page The page object
* @return Rendered page
*/
GtkWidget* zathura_page_render(zathura_page_t* page);
2010-11-17 22:51:15 +01:00
2011-03-12 11:32:24 +01:00
/**
* Create new index element
*
* @param title Title of the index element
* @return Index element
*/
2010-12-25 00:47:52 +01:00
zathura_index_element_t* zathura_index_element_new(const char* title);
2011-03-12 11:32:24 +01:00
/**
* Free index element
*
* @param index The index element
*/
2010-12-25 00:47:52 +01:00
void zathura_index_element_free(zathura_index_element_t* index);
2010-11-17 22:51:15 +01:00
#endif // DOCUMENT_H