Commit d4646148 authored by Moritz Lipp's avatar Moritz Lipp

Store annotation opacity and blend mode

parent 85d87006
Pipeline #142 passed with stage
in 10 minutes and 6 seconds
......@@ -34,6 +34,8 @@ zathura_annotation_new(zathura_page_t* page, zathura_annotation_t** annotation,
/* Initialize defaults */
(*annotation)->has_appearance_stream = false;
(*annotation)->blend_mode = ZATHURA_BLEND_MODE_NORMAL;
(*annotation)->opacity = 1.0;
/* Set type */
switch (type) {
......@@ -440,6 +442,58 @@ zathura_annotation_get_color(zathura_annotation_t* annotation,
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_annotation_set_blend_mode(zathura_annotation_t* annotation,
zathura_blend_mode_t blend_mode)
{
if (annotation == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
annotation->blend_mode = blend_mode;
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_annotation_get_blend_mode(zathura_annotation_t* annotation,
zathura_blend_mode_t* blend_mode)
{
if (annotation == NULL || blend_mode == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
*blend_mode = annotation->blend_mode;
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_annotation_set_opacity(zathura_annotation_t* annotation,
float opacity)
{
if (annotation == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
annotation->opacity = opacity;
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_annotation_get_opacity(zathura_annotation_t* annotation,
float* opacity)
{
if (annotation == NULL || opacity == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
*opacity = annotation->opacity;
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_annotation_get_page(zathura_annotation_t* annotation,
zathura_page_t** page)
......
......@@ -395,6 +395,58 @@ zathura_error_t zathura_annotation_set_color(zathura_annotation_t* annotation,
zathura_error_t zathura_annotation_get_color(zathura_annotation_t* annotation,
zathura_annotation_color_t* color);
/**
* Sets the blend mode of the annotation
*
* @param[in] annotation The annotation
* @param[in] blend_mode The blend mode
*
* @return ZATHURA_ERROR_OK No error occurred
* @return ZATHURA_ERROR_INVALID_ARGUMENTS Invalid arguments have been passed
* @return ZATHURA_ERROR_UNKNOWN An unspecified error occurred
*/
zathura_error_t zathura_annotation_set_blend_mode(zathura_annotation_t* annotation,
zathura_blend_mode_t blend_mode);
/**
* Returns the blend mode of the annotation
*
* @param[in] annotation The annotation
* @param[out] blend_mode The blend mode
*
* @return ZATHURA_ERROR_OK No error occurred
* @return ZATHURA_ERROR_INVALID_ARGUMENTS Invalid arguments have been passed
* @return ZATHURA_ERROR_UNKNOWN An unspecified error occurred
*/
zathura_error_t zathura_annotation_get_blend_mode(zathura_annotation_t* annotation,
zathura_blend_mode_t* blend_mode);
/**
* Sets the opacity of the annotation
*
* @param[in] annotation The annotation
* @param[in] opacity The opacity
*
* @return ZATHURA_ERROR_OK No error occurred
* @return ZATHURA_ERROR_INVALID_ARGUMENTS Invalid arguments have been passed
* @return ZATHURA_ERROR_UNKNOWN An unspecified error occurred
*/
zathura_error_t zathura_annotation_set_opacity(zathura_annotation_t* annotation,
float opacity);
/**
* Returns the opacity of the annotation
*
* @param[in] annotation The annotation
* @param[out] opacity The opacity
*
* @return ZATHURA_ERROR_OK No error occurred
* @return ZATHURA_ERROR_INVALID_ARGUMENTS Invalid arguments have been passed
* @return ZATHURA_ERROR_UNKNOWN An unspecified error occurred
*/
zathura_error_t zathura_annotation_get_opacity(zathura_annotation_t* annotation,
float* opacity);
/**
* Returns the page associated with this annotation
*
......
......@@ -73,6 +73,16 @@ struct zathura_annotation_s {
*/
bool is_markup;
/**
* Blend mode of the annotation
*/
zathura_blend_mode_t blend_mode;
/**
* Opacity of the annotation
*/
float opacity;
/**
* A markup annotation
*/
......
......@@ -43,6 +43,10 @@ zathura_annotation_text_markup_init(zathura_annotation_t* annotation)
return ZATHURA_ERROR_OUT_OF_MEMORY;
}
if (annotation->type == ZATHURA_ANNOTATION_HIGHLIGHT) {
annotation->blend_mode = ZATHURA_BLEND_MODE_MULTIPLY;
}
return ZATHURA_ERROR_OK;
}
......
......@@ -53,6 +53,21 @@ typedef struct zathura_form_field_mapping_s {
typedef void (*zathura_free_function_t)(void* data);
typedef enum zathura_blend_mode_e {
ZATHURA_BLEND_MODE_NORMAL,
ZATHURA_BLEND_MODE_MULTIPLY,
ZATHURA_BLEND_MODE_SCREEN,
ZATHURA_BLEND_MODE_OVERLAY,
ZATHURA_BLEND_MODE_DARKEN,
ZATHURA_BLEND_MODE_LIGHTEN,
ZATHURA_BLEND_MODE_COLOR_DODGE,
ZATHURA_BLEND_MODE_COLOR_BURN,
ZATHURA_BLEND_MODE_HARD_LIGHT,
ZATHURA_BLEND_MODE_SOFT_LIGHT,
ZATHURA_BLEND_MODE_DIFFERENCE,
ZATHURA_BLEND_MODE_EXCLUSION
} zathura_blend_mode_t;
#ifdef __cplusplus
}
#endif
......
......@@ -241,6 +241,58 @@ START_TEST(test_annotation_get_color) {
fail_unless(zathura_annotation_get_color(annotation, &color) == ZATHURA_ERROR_OK);
} END_TEST
START_TEST(test_annotation_set_blend_mode) {
zathura_blend_mode_t blend_mode = ZATHURA_BLEND_MODE_NORMAL;
/* invalid arguments */
fail_unless(zathura_annotation_set_blend_mode(NULL, blend_mode) == ZATHURA_ERROR_INVALID_ARGUMENTS);
/* valid arguments */
fail_unless(zathura_annotation_set_blend_mode(annotation, blend_mode) == ZATHURA_ERROR_OK);
} END_TEST
START_TEST(test_annotation_get_blend_mode) {
zathura_blend_mode_t blend_mode = ZATHURA_BLEND_MODE_NORMAL;
zathura_blend_mode_t blend_mode_input = ZATHURA_BLEND_MODE_DARKEN;
/* invalid arguments */
fail_unless(zathura_annotation_get_blend_mode(NULL, NULL) == ZATHURA_ERROR_INVALID_ARGUMENTS);
fail_unless(zathura_annotation_get_blend_mode(annotation, NULL) == ZATHURA_ERROR_INVALID_ARGUMENTS);
fail_unless(zathura_annotation_get_blend_mode(NULL, &blend_mode) == ZATHURA_ERROR_INVALID_ARGUMENTS);
/* valid arguments */
fail_unless(zathura_annotation_get_blend_mode(annotation, &blend_mode) == ZATHURA_ERROR_OK);
fail_unless(zathura_annotation_set_blend_mode(annotation, blend_mode_input) == ZATHURA_ERROR_OK);
fail_unless(zathura_annotation_get_blend_mode(annotation, &blend_mode) == ZATHURA_ERROR_OK);
} END_TEST
START_TEST(test_annotation_set_opacity) {
float opacity = 1.0;
/* invalid arguments */
fail_unless(zathura_annotation_set_opacity(NULL, opacity) == ZATHURA_ERROR_INVALID_ARGUMENTS);
/* valid arguments */
fail_unless(zathura_annotation_set_opacity(annotation, opacity) == ZATHURA_ERROR_OK);
} END_TEST
START_TEST(test_annotation_get_opacity) {
float opacity = 1.0;
float opacity_input = 2.0;
/* invalid arguments */
fail_unless(zathura_annotation_get_opacity(NULL, NULL) == ZATHURA_ERROR_INVALID_ARGUMENTS);
fail_unless(zathura_annotation_get_opacity(annotation, NULL) == ZATHURA_ERROR_INVALID_ARGUMENTS);
fail_unless(zathura_annotation_get_opacity(NULL, &opacity) == ZATHURA_ERROR_INVALID_ARGUMENTS);
/* valid arguments */
fail_unless(zathura_annotation_get_opacity(annotation, &opacity) == ZATHURA_ERROR_OK);
fail_unless(zathura_annotation_set_opacity(annotation, opacity_input) == ZATHURA_ERROR_OK);
fail_unless(zathura_annotation_get_opacity(annotation, &opacity) == ZATHURA_ERROR_OK);
fail_unless(opacity == opacity_input);
} END_TEST
START_TEST(test_annotation_get_page) {
zathura_page_t* ppage;
......@@ -376,6 +428,10 @@ suite_annotations(void)
tcase_add_test(tcase, test_annotation_get_flags);
tcase_add_test(tcase, test_annotation_set_color);
tcase_add_test(tcase, test_annotation_get_color);
tcase_add_test(tcase, test_annotation_set_blend_mode);
tcase_add_test(tcase, test_annotation_get_blend_mode);
tcase_add_test(tcase, test_annotation_set_opacity);
tcase_add_test(tcase, test_annotation_get_opacity);
tcase_add_test(tcase, test_annotation_get_page);
tcase_add_test(tcase, test_annotation_render);
tcase_add_test(tcase, test_annotation_render_cairo);
......
......@@ -21,6 +21,10 @@ START_TEST(test_annotation_highlight_get_type) {
zathura_annotation_type_t type;
fail_unless(zathura_annotation_get_type(annotation, &type) == ZATHURA_ERROR_OK);
fail_unless(type == ZATHURA_ANNOTATION_HIGHLIGHT);
zathura_blend_mode_t blend_mode;
fail_unless(zathura_annotation_get_blend_mode(annotation, &blend_mode) == ZATHURA_ERROR_OK);
fail_unless(blend_mode == ZATHURA_BLEND_MODE_MULTIPLY);
} END_TEST
START_TEST(test_annotation_highlight_set_quad_points) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment