2012-03-27 11:19:39 +02:00
|
|
|
/* See LICENSE file for license and copyright information */
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
#include <stdlib.h>
|
2012-03-30 18:24:00 +02:00
|
|
|
#include <girara/datastructures.h>
|
2012-04-03 18:39:00 +02:00
|
|
|
#include <glib.h>
|
2012-03-27 13:30:04 +02:00
|
|
|
|
2012-03-27 11:19:39 +02:00
|
|
|
#include "types.h"
|
2012-04-06 13:54:17 +02:00
|
|
|
#include "internal.h"
|
2012-03-27 11:19:39 +02:00
|
|
|
|
|
|
|
zathura_link_t*
|
|
|
|
zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position,
|
|
|
|
zathura_link_target_t target)
|
|
|
|
{
|
|
|
|
zathura_link_t* link = g_malloc0(sizeof(zathura_link_t));
|
|
|
|
|
|
|
|
link->type = type;
|
|
|
|
link->position = position;
|
|
|
|
|
|
|
|
switch (type) {
|
2012-04-22 10:04:46 +02:00
|
|
|
case ZATHURA_LINK_GOTO_DEST:
|
2012-03-27 11:19:39 +02:00
|
|
|
link->target.page_number = target.page_number;
|
|
|
|
break;
|
2012-04-22 11:11:36 +02:00
|
|
|
case ZATHURA_LINK_GOTO_REMOTE:
|
2012-04-22 10:04:46 +02:00
|
|
|
case ZATHURA_LINK_URI:
|
|
|
|
if (target.value == NULL) {
|
2012-03-27 11:19:39 +02:00
|
|
|
g_free(link);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-22 10:04:46 +02:00
|
|
|
link->target.value = g_strdup(target.value);
|
2012-03-27 11:19:39 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_free(link);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_link_free(zathura_link_t* link)
|
|
|
|
{
|
|
|
|
if (link == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-22 10:04:46 +02:00
|
|
|
if (link->type == ZATHURA_LINK_URI) {
|
|
|
|
if (link->target.value != NULL) {
|
|
|
|
g_free(link->target.value);
|
2012-03-27 11:19:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(link);
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_link_type_t
|
|
|
|
zathura_link_get_type(zathura_link_t* link)
|
|
|
|
{
|
|
|
|
if (link == NULL) {
|
|
|
|
return ZATHURA_LINK_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return link->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_rectangle_t
|
|
|
|
zathura_link_get_position(zathura_link_t* link)
|
|
|
|
{
|
|
|
|
if (link == NULL) {
|
|
|
|
zathura_rectangle_t position = { 0, 0, 0, 0 };
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
return link->position;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_link_target_t
|
|
|
|
zathura_link_get_target(zathura_link_t* link)
|
|
|
|
{
|
|
|
|
if (link == NULL) {
|
|
|
|
zathura_link_target_t target = { 0 };
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
return link->target;
|
|
|
|
}
|
2012-03-27 13:30:04 +02:00
|
|
|
|
|
|
|
zathura_index_element_t*
|
|
|
|
zathura_index_element_new(const char* title)
|
|
|
|
{
|
|
|
|
if (title == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t));
|
|
|
|
|
|
|
|
res->title = g_strdup(title);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_index_element_free(zathura_index_element_t* index)
|
|
|
|
{
|
|
|
|
if (index == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(index->title);
|
2012-04-22 10:04:46 +02:00
|
|
|
zathura_link_free(index->link);
|
2012-03-27 13:30:04 +02:00
|
|
|
g_free(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_image_buffer_t*
|
|
|
|
zathura_image_buffer_create(unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
zathura_image_buffer_t* image_buffer = malloc(sizeof(zathura_image_buffer_t));
|
|
|
|
|
|
|
|
if (image_buffer == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_buffer->data = calloc(width * height * 3, sizeof(unsigned char));
|
|
|
|
|
|
|
|
if (image_buffer->data == NULL) {
|
|
|
|
free(image_buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_buffer->width = width;
|
|
|
|
image_buffer->height = height;
|
|
|
|
image_buffer->rowstride = width * 3;
|
|
|
|
|
|
|
|
return image_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_image_buffer_free(zathura_image_buffer_t* image_buffer)
|
|
|
|
{
|
|
|
|
if (image_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(image_buffer->data);
|
|
|
|
free(image_buffer);
|
|
|
|
}
|
|
|
|
|
2012-03-30 18:24:00 +02:00
|
|
|
girara_list_t*
|
|
|
|
zathura_document_information_entry_list_new()
|
|
|
|
{
|
|
|
|
girara_list_t* list = girara_list_new2((girara_free_function_t)
|
|
|
|
zathura_document_information_entry_free);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_document_information_entry_t*
|
|
|
|
zathura_document_information_entry_new(zathura_document_information_type_t type,
|
|
|
|
const char* value)
|
|
|
|
{
|
|
|
|
if (value == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_document_information_entry_t* entry =
|
|
|
|
g_malloc0(sizeof(zathura_document_information_entry_t));
|
|
|
|
|
|
|
|
entry->type = type;
|
|
|
|
entry->value = g_strdup(value);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_document_information_entry_free(zathura_document_information_entry_t* entry)
|
|
|
|
{
|
|
|
|
if (entry == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry->value != NULL) {
|
|
|
|
g_free(entry->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(entry);
|
|
|
|
}
|