Introduce zathura_annotation_t

This commit is contained in:
Moritz Lipp 2012-05-02 01:13:55 +02:00
parent 800d039293
commit e70a07e0cd
4 changed files with 375 additions and 1 deletions

View File

@ -6,7 +6,7 @@ include common.mk
PROJECT = zathura
OSOURCE = $(wildcard *.c)
HEADER = $(wildcard *.h)
HEADERINST = version.h document.h macros.h page.h types.h plugin-api.h
HEADERINST = version.h document.h macros.h page.h types.h plugin-api.h annotations.h
ifneq (${WITH_SQLITE},0)
INCS += $(SQLITE_INC)

201
annotations.c Normal file
View File

@ -0,0 +1,201 @@
/* See LICENSE file for license and copyright information */
#include "annotations.h"
#include <stdlib.h>
#include <string.h>
struct zathura_annotation_s {
zathura_annotation_type_t type; /**< Type of the annotation */
zathura_annotation_flag_t flags; /**< Flags of the annotation */
char* name; /**< Name of the annotation */
char* content; /**< Content of the annotation */
time_t modification_date; /**< Modification date */
unsigned int page_index; /**< Page index */
void* data; /**< Custom data */
};
static char* __strdup(const char* string);
zathura_annotation_t*
zathura_annotation_new(zathura_annotation_type_t type)
{
zathura_annotation_t* annotation = calloc(1, sizeof(zathura_annotation_t));
annotation->type = type;
return annotation;
}
void
zathura_annotation_free(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return;
}
if (annotation->name) {
free(annotation->name);
}
if (annotation->content) {
free(annotation->content);
}
free(annotation);
}
void*
zathura_annotation_get_data(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return NULL;
}
return annotation->data;
}
void
zathura_annotation_set_data(zathura_annotation_t* annotation, void* data)
{
if (annotation == NULL) {
return;
}
annotation->data = data;
}
zathura_annotation_type_t
zathura_annotation_get_type(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return ZATHURA_ANNOTATION_UNKNOWN;
}
return annotation->type;
}
zathura_annotation_flag_t
zathura_annotation_get_flags(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return ZATHURA_ANNOTATION_FLAG_UNKNOWN;
}
return annotation->flags;
}
void
zathura_annotation_set_flags(zathura_annotation_t* annotation, zathura_annotation_flag_t flags)
{
if (annotation == NULL) {
return;
}
annotation->flags = flags;
}
char*
zathura_annotation_get_content(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return NULL;
}
return annotation->content;
}
void
zathura_annotation_set_content(zathura_annotation_t* annotation, char* content)
{
if (annotation == NULL) {
return;
}
if (content != NULL) {
annotation->content = __strdup(content);
} else {
annotation->content = NULL;
}
}
char*
zathura_annotation_get_name(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return NULL;
}
return annotation->name;
}
void
zathura_annotation_set_name(zathura_annotation_t* annotation, const char* name)
{
if (annotation == NULL) {
return;
}
if (name != NULL) {
annotation->name = __strdup(name);
} else {
annotation->name = NULL;
}
}
time_t
zathura_annotation_get_modified(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return (time_t) -1;
}
return annotation->modification_date;
}
void
zathura_annotation_set_modified(zathura_annotation_t* annotation, time_t modification_date)
{
if (annotation == NULL) {
return;
}
annotation->modification_date = modification_date;
}
unsigned int
zathura_annotation_get_page_index(zathura_annotation_t* annotation)
{
if (annotation == NULL) {
return 0;
}
return annotation->page_index;
}
void
zathura_annotation_set_page_index(zathura_annotation_t* annotation, unsigned int page_index)
{
if (annotation == NULL) {
return;
}
annotation->page_index = page_index;
}
static char*
__strdup(const char* string)
{
if (string == NULL) {
return NULL;
}
size_t length = strlen(string) + 1;
char* new_string = malloc(sizeof(char) * length);
if (new_string == NULL) {
return NULL;
}
return (char*) memcpy(new_string, string, length);
}

172
annotations.h Normal file
View File

@ -0,0 +1,172 @@
/* See LICENSE file for license and copyright information */
#ifndef ANNOTATION_H
#define ANNOTATION_H
#include <time.h>
typedef struct zathura_annotation_s zathura_annotation_t;
typedef enum zathura_annotation_type_s {
ZATHURA_ANNOTATION_UNKNOWN,
ZATHURA_ANNOTATION_TEXT,
ZATHURA_ANNOTATION_LINK,
ZATHURA_ANNOTATION_FREE_TEXT,
ZATHURA_ANNOTATION_LINE,
ZATHURA_ANNOTATION_SQUARE,
ZATHURA_ANNOTATION_CIRCLE,
ZATHURA_ANNOTATION_POLYGON,
ZATHURA_ANNOTATION_POLY_LINE,
ZATHURA_ANNOTATION_HIGHLIGHT,
ZATHURA_ANNOTATION_UNDERLINE,
ZATHURA_ANNOTATION_SQUIGGLY,
ZATHURA_ANNOTATION_STRIKE_OUT,
ZATHURA_ANNOTATION_STAMP,
ZATHURA_ANNOTATION_CARET,
ZATHURA_ANNOTATION_INK,
ZATHURA_ANNOTATION_POPUP,
ZATHURA_ANNOTATION_FILE_ATTACHMENT,
ZATHURA_ANNOTATION_SOUND,
ZATHURA_ANNOTATION_MOVIE,
ZATHURA_ANNOTATION_WIDGET,
ZATHURA_ANNOTATION_SCREEN,
ZATHURA_ANNOTATION_PRINTER_MARK,
ZATHURA_ANNOTATION_TRAP_NET,
ZATHURA_ANNOTATION_WATERMARK,
ZATHURA_ANNOTATION_3D
} zathura_annotation_type_t;
typedef enum zathura_annotation_flag_s {
ZATHURA_ANNOTATION_FLAG_UNKNOWN = 0,
ZATHURA_ANNOTATION_FLAG_INVISIBLE = 1 << 0,
ZATHURA_ANNOTATION_FLAG_HIDDEN = 1 << 1,
ZATHURA_ANNOTATION_FLAG_PRINT = 1 << 2,
ZATHURA_ANNOTATION_FLAG_NO_ZOOM = 1 << 3,
ZATHURA_ANNOTATION_FLAG_NO_ROTATE = 1 << 4,
ZATHURA_ANNOTATION_FLAG_NO_VIEW = 1 << 5,
ZATHURA_ANNOTATION_FLAG_READ_ONLY = 1 << 6,
ZATHURA_ANNOTATION_FLAG_LOCKED = 1 << 7,
ZATHURA_ANNOTATION_FLAG_TOGGLE_NO_VIEW = 1 << 8,
ZATHURA_ANNOTATION_FLAG_LOCKED_CONTENTS = 1 << 9,
} zathura_annotation_flag_t;
/**
* Creates a new annotation
*
* @param type The type of the annotation
* @return Pointer to the created annotation object or NULL if an error occured
*/
zathura_annotation_t* zathura_annotation_new(zathura_annotation_type_t type);
/**
* Frees the given annotation
*
* @param annotation The annotation
*/
void zathura_annotation_free(zathura_annotation_t* annotation);
/**
* Returns the pointer to the custom data for the given annotation
*
* @param annotation The annotation
* @return Pointer to the custom data or NULL
*/
void* zathura_annotation_get_data(zathura_annotation_t* annotation);
/**
* Sets the custom data for the given annotation
*
* @param annotation The annotation
* @param data Custom data
*/
void zathura_annotation_set_data(zathura_annotation_t* annotation, void* data);
/**
* Returns the type of the annotation
*
* @param annotation The annotation
* @return The type of the annotation (\ref zathura_annotation_type_t)
*/
zathura_annotation_type_t zathura_annotation_get_type(zathura_annotation_t* annotation);
/**
* Returns the flags of the annotation
*
* @param annotation The annotation
* @return The set flags of the annotation (\ref zathura_annotation_flag_t)
*/
zathura_annotation_flag_t zathura_annotation_get_flags(zathura_annotation_t* annotation);
/**
* Sets the flags of the annotation
*
* @param annotation The annotation
* @param flags The flags that should be set to the annotation
*/
void zathura_annotation_set_flags(zathura_annotation_t* annotation, zathura_annotation_flag_t flags);
/**
* Returns the content of the annotation
*
* @param annotation The annotation
* @return The content of the annotation or NULL
*/
char* zathura_annotation_get_content(zathura_annotation_t* annotation);
/**
* Sets the content of the annotation
*
* @param annotation The annotation
* @param content The new content of the annotation
*/
void zathura_annotation_set_content(zathura_annotation_t* annotation, char* content);
/**
* Returns the name of the annotation
*
* @param annotation The annotation
* @return The name of the annotation or NULL
*/
char* zathura_annotation_get_name(zathura_annotation_t* annotation);
/**
* Sets the name of the annotation
*
* @param annotation The annotation
* @param name The new name of the annotation
*/
void zathura_annotation_set_name(zathura_annotation_t* annotation, const char* name);
/**
* Returns the modification date of the annotation
*
* @param annotation The annotation
* @return The date on which the annotation has been modified the last time
*/
time_t zathura_annotation_get_modified(zathura_annotation_t* annotation);
/**
* Sets the date on which the annotation has been modified the last time
*
* @param annotation The annotation
* @param modification_date The modification date
*/
void zathura_annotation_set_modified(zathura_annotation_t* annotation, time_t modification_date);
/**
* Returns the page index of the annotation
*
* @param annotation The annotation
* @return The page index of the annotation
*/
unsigned int zathura_annotation_get_page_index(zathura_annotation_t* annotation);
/**
* Sets the page index of the annotation
*
* @param annotation The annotation
* @param page_index The page index of the annotation
*/
void zathura_annotation_set_page_index(zathura_annotation_t* annotation, unsigned int page_index);
#endif // ANNOTATION_H

View File

@ -4,6 +4,7 @@
#define PLUGIN_API_H
#include "page.h"
#include "annotations.h"
#include "document.h"
#include "version.h"