Commit 25ef21ef authored by Moritz Lipp's avatar Moritz Lipp

Update form fields

parent 8135a4e5
Pipeline #340 failed with stages
in 2 minutes and 12 seconds
......@@ -132,6 +132,45 @@ zathura_form_field_get_type(zathura_form_field_t* form_field,
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_form_field_set_position(zathura_form_field_t* form_field,
zathura_rectangle_t position)
{
if (form_field == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
form_field->position = position;
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_form_field_get_position(zathura_form_field_t* form_field,
zathura_rectangle_t* position)
{
if (form_field == NULL || position == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
*position = form_field->position;
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_form_field_get_page(zathura_form_field_t* form_field,
zathura_page_t** page)
{
if (form_field == NULL || page == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
*page = form_field->page;
return ZATHURA_ERROR_OK;
}
zathura_error_t
zathura_form_field_set_name(zathura_form_field_t* form_field, const char* name)
{
......@@ -291,3 +330,31 @@ zathura_form_field_save(zathura_form_field_t* form_field)
return form_field->page->document->plugin->functions.form_field_save(form_field);
}
zathura_error_t
zathura_form_field_render(zathura_form_field_t* form_field,
zathura_image_buffer_t** buffer, double scale)
{
if (form_field == NULL || buffer == NULL || scale <= 0.0) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
CHECK_IF_IMPLEMENTED(form_field->page, form_field_render)
return form_field->page->document->plugin->functions.form_field_render(form_field, buffer, scale);
}
#ifdef HAVE_CAIRO
zathura_error_t
zathura_form_field_render_cairo(zathura_form_field_t*
form_field, cairo_t* cairo, double scale)
{
if (form_field == NULL || cairo == NULL || scale <= 0.0) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}
CHECK_IF_IMPLEMENTED(form_field->page, form_field_render_cairo)
return form_field->page->document->plugin->functions.form_field_render_cairo(form_field, cairo, scale);
}
#endif
......@@ -9,8 +9,17 @@ extern "C" {
#include <stdbool.h>
#ifdef HAVE_CAIRO
#include <cairo.h>
#endif
#include "image-buffer.h"
#include "page.h"
#include "error.h"
/* Forward declaration */
typedef struct zathura_rectangle_s zathura_rectangle_t;
/**
* An interactive form is a collection of fields for gathering information
* interactively from the user. A document may contain any number of fields
......@@ -72,6 +81,49 @@ typedef enum zathura_form_field_flag_s {
zathura_error_t zathura_form_field_get_type(zathura_form_field_t* form_field,
zathura_form_field_type_t* type);
/**
* Sets the position of the form field defining the location of the form field
* on the page in default user space units.
*
* @param[in] annotation The annotation
* @param[in] position The position defining the location of the form field on
* the page in default user space units
*
* @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_form_field_set_position(zathura_form_field_t* form_field,
zathura_rectangle_t position);
/**
* Returns the position of the form field defining the location of the form field
* on the page in default user space units.
*
* @param[in] form_field The form field
* @param[out] position The position defining the location of the form field on
* the page in default user space units
*
* @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_form_field_get_position(zathura_form_field_t* form_field,
zathura_rectangle_t* position);
/**
* Returns the page associated with this form field
*
* @param[in] annotation The form field
* @param[out] page The associated page
*
* @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_form_field_get_page(zathura_form_field_t* form_field,
zathura_page_t** page);
/**
* Returns the name of the form field
*
......@@ -131,6 +183,36 @@ zathura_error_t zathura_form_field_get_flags(zathura_form_field_t* form_field, z
*/
zathura_error_t zathura_form_field_save(zathura_form_field_t* form_field);
/**
* Renders the form field to a @a ::zathura_image_buffer_t image buffer
*
* @param[in] annotation The form field
* @param[out] buffer The image buffer
* @param[in] scale Scale level
*
* @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_form_field_render(zathura_form_field_t* form_field,
zathura_image_buffer_t** buffer, double scale);
#ifdef HAVE_CAIRO
/**
* Renders the form field to a cairo object
*
* @param[in] annotation The used form field object
* @param[out] cairo The cairo object
* @param[in] scale Scale level
*
* @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_form_field_render_cairo(zathura_form_field_t*
form_field, cairo_t* cairo, double scale);
#endif
#include "form-fields/form-field-button.h"
#include "form-fields/form-field-text.h"
#include "form-fields/form-field-choice.h"
......
......@@ -33,6 +33,12 @@ struct zathura_form_field_s {
*/
zathura_form_field_type_t type;
/**
* The form field rectangle, defining the location of the form field on
* the page in default user space units.
*/
zathura_rectangle_t position;
/**
* An alternate field name to be used in place of the actual field name
* wherever the field must be identified in the user interface (such as in
......
/* See LICENSE file for license and copyright information */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "page.h"
......
......@@ -95,6 +95,10 @@ typedef zathura_error_t (*zathura_plugin_page_render_t)(zathura_page_t* page, za
typedef zathura_error_t (*zathura_plugin_page_render_cairo_t)(zathura_page_t* page, cairo_t* cairo, double scale, int rotation, int flags);
#endif
typedef zathura_error_t (*zathura_plugin_form_field_render_t)(zathura_form_field_t* form_field, zathura_image_buffer_t** buffer, double scale);
#ifdef HAVE_CAIRO
typedef zathura_error_t (*zathura_plugin_form_field_render_cairo_t)(zathura_form_field_t* form_field, cairo_t* cairo, double scale);
#endif
typedef zathura_error_t (*zathura_plugin_form_field_save_t)(zathura_form_field_t* form_field);
typedef zathura_error_t (*zathura_plugin_annotation_render_t)(zathura_annotation_t* annotation, zathura_image_buffer_t** buffer, double scale);
......@@ -162,6 +166,14 @@ struct zathura_plugin_functions_s {
/** Function to save a form field */
zathura_plugin_form_field_save_t form_field_save;
/** Function to render a form field */
zathura_plugin_form_field_render_t form_field_render;
#ifdef HAVE_CAIRO
/** Function to render a form field to a cairo surface */
zathura_plugin_form_field_render_cairo_t form_field_render_cairo;
#endif
/** Function to render an annotation */
zathura_plugin_annotation_render_t annotation_render;
......
......@@ -46,6 +46,8 @@ typedef struct zathura_link_mapping_s {
#include "form-fields.h"
typedef struct zathura_form_field_s zathura_form_field_t;
typedef struct zathura_form_field_mapping_s {
zathura_rectangle_t position;
zathura_form_field_t* form_field;
......
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