aboutsummaryrefslogtreecommitdiffstats
path: root/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h
blob: 87bdd709f2f55370e9947a52b8df3a3296a1b24e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* See LICENSE file for copyright and license details. */
#ifndef LIBRIFUNKTIONSTECKENSNITTSGLYFRASTERISERINGSPROGRAMBIBLIOTEKET_H
#define LIBRIFUNKTIONSTECKENSNITTSGLYFRASTERISERINGSPROGRAMBIBLIOTEKET_H
/*         ^ <        ^     <     ^   ^             >      ^          */
/*         r          t           g   r             p      b      lib */

#include <stddef.h>


#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdocumentation"
#endif


/**
 * Object that the library draws on, is converted to
 * an ink-level image using the `rtgrpblib_fill_shapes`
 * function. This object also contain drawing
 * configurations.
 */
typedef struct rtgrpblib_raster RTGRPBLIB_RASTER;


/**
 * Create a buffer that the library can use for drawing
 *
 * @param   width   The width of the buffer
 * @param   height  The height of the buffer
 * @return          Drawing buffer, which can be deallocated with (3),
 *                  or `NULL` on failure
 * 
 * @throws  EINVAL  `width` or `height` is zero
 * @throws  ENOMEM  Cannot allocate enough memory
 * 
 * @seealso  rtgrpblib_reset_raster
 */
RTGRPBLIB_RASTER *rtgrpblib_create_raster(size_t width, size_t height);

/**
 * Reshape and clear a drawing buffer
 * 
 * @param   raster  The buffer to reshape and clear
 * @param   width   The new width of the buffer
 * @param   height  The new height of the buffer
 * @return          0 on success, -1 on failure
 * 
 * @throws  EINVAL  `width` or `height` is zero
 * @throws  EINVAL  The buffers new area size exceeds its original area size
 */
int rtgrpblib_reset_raster(RTGRPBLIB_RASTER *raster, size_t width, size_t height);


/**
 * Reconfigure a drawing buffer with a new draftness value
 * 
 * When drawing a curve, the size of each step the library
 * takes will be proportional to the draftness value, but
 * will also depend on other factors. Doubling the draftness
 * value with halve (disregarind overheads) the time it takes
 * to draw any given curve.
 * 
 * @param  raster     The drawing buffer to reconfigure
 * @param  draftness  The new draftness value, must be positive
 */
void rtgrpblib_set_draftness(RTGRPBLIB_RASTER *raster, double draftness);


/**
 * Create an image of the drawings applied to a drawing buffer
 * 
 * All drawn shapes must be closed
 * 
 * Shapes that are drawn in the same angular direction add to
 * each other, shapes that are drawn in opposite angular
 * directions subtract from each other
 * 
 * @param  image    Output buffer, need not be initialised, but
 *                  shall have an allocation size of `rowsize`
 *                  multiplied by the height of `raster` and
 *                  by `sizeof(double)`
 * @param  rowsize  The number of elements in `image` per row,
 *                  must be at least the width of `raster`
 * @param  raster   The drawing buffer
 * 
 * @seealso  rtgrpblib_reset_raster
 */
void rtgrpblib_fill_shapes(double *restrict image, size_t rowsize, const RTGRPBLIB_RASTER *raster);


/**
 * Draw a line between two points
 * 
 * @param  raster  The drawing buffer
 * @param  x1, y1  The starting point
 * @param  x2, y2  The end point
 */
void rtgrpblib_draw_linear_bezier(RTGRPBLIB_RASTER *restrict raster,
                                  double x1, double y1,
                                  double x2, double y2);

/**
 * Draw a quadratic bézier curve
 * 
 * @param  raster  The drawing buffer
 * @param  x1, y1  The starting point
 * @param  x2, y2  The control point
 * @param  x3, y3  The end point
 */
void rtgrpblib_draw_quadratic_bezier(RTGRPBLIB_RASTER *restrict raster,
                                     double x1, double y1,
                                     double x2, double y2,
                                     double x3, double y3);

/**
 * Draw a cubic bézier curve
 * 
 * @param  raster  The drawing buffer
 * @param  x1, y1  The starting point
 * @param  x2, y2  The first control point
 * @param  x3, y3  The second control point
 * @param  x4, y4  The end point
 */
void rtgrpblib_draw_cubic_bezier(RTGRPBLIB_RASTER *restrict raster, /* needed for OpenType */
                                 double x1, double y1,
                                 double x2, double y2,
                                 double x3, double y3,
                                 double x4, double y4);

/**
 * Draw a cricular arc
 * 
 * @param  raster      The drawing buffer
 * @param  x0, y0      The midpoint of the ellipse
 * @param  semiwidth   Half the width of the ellipse
 * @param  semiheight  Half the height of the ellipse
 * @param  start       The angular starting point of the arc, in radians
 * @param  end         The angular end point of the arc, in radians
 */
void rtgrpblib_draw_circular_arc(RTGRPBLIB_RASTER *restrict raster, /* needed for outline stoking */
                                 double x0, double y0,
                                 double semiwidth, double semiheight,
                                 double start, double end);


#if defined(__clang__)
# pragma clang diagnostic pop
#endif

#endif