mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-14 07:13:46 +01:00
Update annotation functions
This commit is contained in:
parent
5e42c18fc6
commit
d02d49c79b
203
annotations.c
203
annotations.c
@ -11,9 +11,11 @@ struct zathura_annotation_s {
|
||||
char* name; /**< Name of the annotation */
|
||||
char* content; /**< Content of the annotation */
|
||||
time_t modification_date; /**< Modification date */
|
||||
time_t creation_date; /**< Creation date */
|
||||
zathura_page_t* page; /**< Zathura page */
|
||||
zathura_rectangle_t position; /**< Position of the annotation */
|
||||
void* user_data; /**< Custom data */
|
||||
zathura_annotation_popup_t* popup; /**< Optional popup */
|
||||
|
||||
union {
|
||||
struct {
|
||||
@ -22,19 +24,11 @@ struct zathura_annotation_s {
|
||||
bool opened; /**< Open status of the text annotation */
|
||||
} text;
|
||||
} data;
|
||||
|
||||
struct {
|
||||
char* label; /**< Label */
|
||||
char* subject; /**< Subject of the annotation */
|
||||
zathura_annotation_popup_t* popup; /**< Optional popup */
|
||||
time_t creation_date; /**< Creation date */
|
||||
} markup;
|
||||
};
|
||||
|
||||
struct zathura_annotation_popup_s {
|
||||
double opacity; /**< The opacity of the popup */
|
||||
char* label; /**< Label */
|
||||
zathura_rectangle_t position; /**< Position of the annotation */
|
||||
bool opened; /**< true if popup is opened */
|
||||
};
|
||||
|
||||
static char* __strdup(const char* string);
|
||||
@ -55,11 +49,11 @@ zathura_annotation_new(zathura_annotation_type_t type)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
annotation->type = type;
|
||||
annotation->modification_date = (time_t) -1;
|
||||
annotation->markup.creation_date = (time_t) -1;
|
||||
annotation->data.text.icon = ZATHURA_ANNOTATION_TEXT_ICON_UNKNOWN;
|
||||
annotation->data.text.state = ZATHURA_ANNOTATION_TEXT_STATE_UNKNOWN;
|
||||
annotation->type = type;
|
||||
annotation->modification_date = (time_t) -1;
|
||||
annotation->creation_date = (time_t) -1;
|
||||
annotation->data.text.icon = ZATHURA_ANNOTATION_TEXT_ICON_UNKNOWN;
|
||||
annotation->data.text.state = ZATHURA_ANNOTATION_TEXT_STATE_UNKNOWN;
|
||||
|
||||
return annotation;
|
||||
}
|
||||
@ -79,16 +73,8 @@ zathura_annotation_free(zathura_annotation_t* annotation)
|
||||
free(annotation->content);
|
||||
}
|
||||
|
||||
if (annotation->markup.label != NULL) {
|
||||
free(annotation->markup.label);
|
||||
}
|
||||
|
||||
if (annotation->markup.subject != NULL) {
|
||||
free(annotation->markup.subject);
|
||||
}
|
||||
|
||||
if (annotation->markup.popup != NULL) {
|
||||
zathura_annotation_popup_free(annotation->markup.popup);
|
||||
if (annotation->popup != NULL) {
|
||||
zathura_annotation_popup_free(annotation->popup);
|
||||
}
|
||||
|
||||
free(annotation);
|
||||
@ -124,29 +110,6 @@ zathura_annotation_get_type(zathura_annotation_t* annotation)
|
||||
return annotation->type;
|
||||
}
|
||||
|
||||
bool
|
||||
zathura_annotation_is_markup_annotation(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (annotation->type) {
|
||||
case ZATHURA_ANNOTATION_TEXT:
|
||||
case ZATHURA_ANNOTATION_FREE_TEXT:
|
||||
case ZATHURA_ANNOTATION_LINE:
|
||||
case ZATHURA_ANNOTATION_STAMP:
|
||||
case ZATHURA_ANNOTATION_POLYGON:
|
||||
case ZATHURA_ANNOTATION_CARET:
|
||||
case ZATHURA_ANNOTATION_INK:
|
||||
case ZATHURA_ANNOTATION_FILE_ATTACHMENT:
|
||||
case ZATHURA_ANNOTATION_SOUND:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
zathura_annotation_flag_t
|
||||
zathura_annotation_get_flags(zathura_annotation_t* annotation)
|
||||
{
|
||||
@ -235,6 +198,27 @@ zathura_annotation_set_modification_date(zathura_annotation_t* annotation, time_
|
||||
annotation->modification_date = modification_date;
|
||||
}
|
||||
|
||||
time_t
|
||||
zathura_annotation_get_creation_date(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL) {
|
||||
return (time_t) -1;
|
||||
}
|
||||
|
||||
return annotation->creation_date;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_set_creation_date(zathura_annotation_t* annotation, time_t creation_date)
|
||||
{
|
||||
if (annotation == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
annotation->creation_date = creation_date;
|
||||
}
|
||||
|
||||
|
||||
zathura_page_t*
|
||||
zathura_annotation_get_page(zathura_annotation_t* annotation)
|
||||
{
|
||||
@ -285,98 +269,55 @@ zathura_annotation_set_position(zathura_annotation_t* annotation,
|
||||
}
|
||||
|
||||
char*
|
||||
zathura_annotation_markup_get_label(zathura_annotation_t* annotation)
|
||||
zathura_annotation_popup_get_label(zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
|
||||
if (popup == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return annotation->markup.label;
|
||||
return popup->label;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_markup_set_label(zathura_annotation_t* annotation, const char* label)
|
||||
zathura_annotation_popup_set_label(zathura_annotation_popup_t* popup, const char* label)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (annotation->markup.label != NULL) {
|
||||
free(annotation->markup.label);
|
||||
if (popup->label != NULL) {
|
||||
free(popup->label);
|
||||
}
|
||||
|
||||
if (label != NULL) {
|
||||
annotation->markup.label = __strdup(label);
|
||||
popup->label = __strdup(label);
|
||||
} else {
|
||||
annotation->markup.label = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
zathura_annotation_markup_get_subject(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return annotation->markup.subject;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_markup_set_subject(zathura_annotation_t* annotation, const char* subject)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
|
||||
return;
|
||||
}
|
||||
if (annotation->markup.subject != NULL) {
|
||||
free(annotation->markup.subject);
|
||||
}
|
||||
|
||||
if (subject != NULL) {
|
||||
annotation->markup.subject = __strdup(subject);
|
||||
} else {
|
||||
annotation->markup.subject = NULL;
|
||||
popup->label = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
zathura_annotation_popup_t*
|
||||
zathura_annotation_markup_get_popup(zathura_annotation_t* annotation)
|
||||
zathura_annotation_get_popup(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
|
||||
if (annotation == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return annotation->markup.popup;
|
||||
return annotation->popup;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_markup_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup)
|
||||
zathura_annotation_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false || popup == NULL) {
|
||||
if (annotation == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
annotation->markup.popup = popup;
|
||||
}
|
||||
|
||||
time_t
|
||||
zathura_annotation_markup_get_creation_date(zathura_annotation_t* annotation)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
|
||||
return (time_t) -1;
|
||||
if (annotation->popup != NULL) {
|
||||
zathura_annotation_popup_free(annotation->popup);
|
||||
}
|
||||
|
||||
return annotation->markup.creation_date;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_markup_set_creation_date(zathura_annotation_t* annotation, time_t creation_date)
|
||||
{
|
||||
if (annotation == NULL || zathura_annotation_is_markup_annotation(annotation) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
annotation->markup.creation_date = creation_date;
|
||||
annotation->popup = popup;
|
||||
}
|
||||
|
||||
zathura_annotation_text_icon_t
|
||||
@ -447,8 +388,6 @@ zathura_annotation_popup_new()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
popup->opacity = 1.0;
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
@ -490,52 +429,6 @@ zathura_annotation_popup_set_position(zathura_annotation_popup_t* popup, zathura
|
||||
popup->position.y2 = position.y2;
|
||||
}
|
||||
|
||||
double
|
||||
zathura_annotation_popup_get_opacity(zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return popup->opacity;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_popup_set_opacity(zathura_annotation_popup_t* popup, double opacity)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (opacity < 0) {
|
||||
popup->opacity = 0;
|
||||
} else if (opacity > 1) {
|
||||
popup->opacity = 1;
|
||||
} else {
|
||||
popup->opacity = opacity;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
zathura_annotation_popup_get_open_status(zathura_annotation_popup_t* popup)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return popup->opened;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_annotation_popup_set_open_status(zathura_annotation_popup_t* popup, bool opened)
|
||||
{
|
||||
if (popup == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
popup->opened = opened;
|
||||
}
|
||||
|
||||
static char*
|
||||
__strdup(const char* string)
|
||||
{
|
||||
|
172
annotations.h
172
annotations.h
@ -118,14 +118,6 @@ void zathura_annotation_set_data(zathura_annotation_t* annotation, void* data);
|
||||
*/
|
||||
zathura_annotation_type_t zathura_annotation_get_type(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* True if the given annotation is a markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return true whether the annotation is a markup annotation otherwise false
|
||||
*/
|
||||
bool zathura_annotation_is_markup_annotation(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Returns the flags of the annotation
|
||||
*
|
||||
@ -190,6 +182,22 @@ time_t zathura_annotation_get_modification_date(zathura_annotation_t* annotation
|
||||
*/
|
||||
void zathura_annotation_set_modification_date(zathura_annotation_t* annotation, time_t modification_date);
|
||||
|
||||
/**
|
||||
* Returns the creation date of the annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @retun The creation date
|
||||
*/
|
||||
time_t zathura_annotation_get_creation_date(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the creation date of the annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param creation_date The creation date
|
||||
*/
|
||||
void zathura_annotation_set_creation_date(zathura_annotation_t* annotation, time_t creation_date);
|
||||
|
||||
/**
|
||||
* Returns the page of the annotation
|
||||
*
|
||||
@ -223,13 +231,43 @@ zathura_rectangle_t zathura_annotation_get_position(zathura_annotation_t* annota
|
||||
*/
|
||||
void zathura_annotation_set_position(zathura_annotation_t* annotation, zathura_rectangle_t position);
|
||||
|
||||
/**
|
||||
* Returns the popup of the annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return The popup or NULL if an error occured or no popup exists
|
||||
*/
|
||||
zathura_annotation_popup_t* zathura_annotation_get_popup(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the annotation popup
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param popup The new popup
|
||||
*/
|
||||
void zathura_annotation_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Creates a new annotation popup
|
||||
*
|
||||
* @return The popup or NULL if an error occured
|
||||
*/
|
||||
zathura_annotation_popup_t* zathura_annotation_popup_new();
|
||||
|
||||
/**
|
||||
* Frees the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
*/
|
||||
void zathura_annotation_popup_free(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Gets the current label of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return The label or NULL
|
||||
*/
|
||||
char* zathura_annotation_markup_get_label(zathura_annotation_t* annotation);
|
||||
char* zathura_annotation_popup_get_label(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Sets the label of the markup annotation
|
||||
@ -237,55 +275,7 @@ char* zathura_annotation_markup_get_label(zathura_annotation_t* annotation);
|
||||
* @param annotation The annotation
|
||||
* @param label The new label of the markup annotation
|
||||
*/
|
||||
void zathura_annotation_markup_set_label(zathura_annotation_t* annotation, const char* label);
|
||||
|
||||
/**
|
||||
* Returns the subject of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return The subject or NULL
|
||||
*/
|
||||
char* zathura_annotation_markup_get_subject(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the new subject of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param subject The new subject of the markup annotation
|
||||
*/
|
||||
void zathura_annotation_markup_set_subject(zathura_annotation_t* annotation, const char* subject);
|
||||
|
||||
/**
|
||||
* Sets the annotation popup of the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return The popup (if available) from the markup annotation
|
||||
*/
|
||||
zathura_annotation_popup_t* zathura_annotation_markup_get_popup(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the new popup for the markup annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param popup The new popup for the markup annotation
|
||||
*/
|
||||
void zathura_annotation_markup_set_popup(zathura_annotation_t* annotation, zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Returns the creation date of the annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @retun The creation date
|
||||
*/
|
||||
time_t zathura_annotation_markup_get_creation_date(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the creation date of the annotation
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param creation_date The creation date
|
||||
*/
|
||||
void zathura_annotation_markup_set_creation_date(zathura_annotation_t* annotation, time_t creation_date);
|
||||
void zathura_annotation_popup_set_label(zathura_annotation_popup_t* popup, const char* label);
|
||||
|
||||
/**
|
||||
* Returns the defined icon of the text annotation
|
||||
@ -309,7 +299,7 @@ void zathura_annotation_text_set_icon(zathura_annotation_t* annotation, zathura_
|
||||
* @param annotation The annotation
|
||||
* @return The state of the text annotation
|
||||
*/
|
||||
zathura_annotation_text_state_t zathura_annotation_text_get_state(zathura_annotation_t* annotation);
|
||||
int zathura_annotation_text_get_flags(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the state of the text annotation
|
||||
@ -317,37 +307,7 @@ zathura_annotation_text_state_t zathura_annotation_text_get_state(zathura_annota
|
||||
* @param annotation The annotation
|
||||
* @param state The new state of the text annotation
|
||||
*/
|
||||
void zathura_annotation_text_set_state(zathura_annotation_t* annotation, zathura_annotation_text_state_t state);
|
||||
|
||||
/**
|
||||
* Returns whether the text annotation is open or not
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @return true if the annotation is open otherwise false
|
||||
*/
|
||||
bool zathura_annotation_text_get_open_status(zathura_annotation_t* annotation);
|
||||
|
||||
/**
|
||||
* Sets the text annotation open status
|
||||
*
|
||||
* @param annotation The annotation
|
||||
* @param opened The new open status
|
||||
*/
|
||||
void zathura_annotation_text_set_open_status(zathura_annotation_t* annotation, bool opened);
|
||||
|
||||
/**
|
||||
* Creates a new annotation popup
|
||||
*
|
||||
* @return The popup or NULL if an error occured
|
||||
*/
|
||||
zathura_annotation_popup_t* zathura_annotation_popup_new();
|
||||
|
||||
/**
|
||||
* Frees the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
*/
|
||||
void zathura_annotation_popup_free(zathura_annotation_popup_t* popup);
|
||||
void zathura_annotation_text_set_flags(zathura_annotation_t* annotation, int flags);
|
||||
|
||||
/**
|
||||
* Returns the position of the annotation popup
|
||||
@ -365,36 +325,4 @@ zathura_rectangle_t zathura_annotation_popup_get_position(zathura_annotation_pop
|
||||
*/
|
||||
void zathura_annotation_popup_set_position(zathura_annotation_popup_t* popup, zathura_rectangle_t position);
|
||||
|
||||
/**
|
||||
* Returns the opacity of the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @return The opacity of the annotation popup
|
||||
*/
|
||||
double zathura_annotation_popup_get_opacity(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Sets the opacity of the annotation popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @param opacity The new value for the opacity
|
||||
*/
|
||||
void zathura_annotation_popup_set_opacity(zathura_annotation_popup_t* popup, double opacity);
|
||||
|
||||
/**
|
||||
* Returns whether the popup is opened or not
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @return true if the popup is opened otherwise false
|
||||
*/
|
||||
bool zathura_annotation_popup_get_open_status(zathura_annotation_popup_t* popup);
|
||||
|
||||
/**
|
||||
* Sets the open status of the popup
|
||||
*
|
||||
* @param popup The annotation popup
|
||||
* @param opened The new status
|
||||
*/
|
||||
void zathura_annotation_popup_set_open_status(zathura_annotation_popup_t* popup, bool opened);
|
||||
|
||||
#endif // ANNOTATION_H
|
||||
|
Loading…
Reference in New Issue
Block a user