Code documentation
[aaf.git] / aaf.h
1 #ifndef __AAF_H
2 #define __AAF_H
3
4 #include <stdio.h>
5 #include <stdint.h>
6
7 /**
8  * @file
9  */
10
11 /** Maximum allowed number of glyphs in AAF file */
12 #define AAF_GLYPH_MAX 256
13
14 /**
15  * Structure containing information about given glyph
16  */
17 struct aaf_glyph {
18         /**
19          * Width of glyph.
20          * The width (in pixels) of the glyph corresponding to its ascii
21          */
22         uint16_t w;
23
24         /**
25          * Height of glyph.
26          * The height (in pixels) of the glyph corresponding to its ascii
27          */
28         uint16_t h;
29         
30         /**
31          * Offset of glyph.
32          * The width (in pixels) of the glyph corresponding to its ascii
33          */
34         uint32_t off;
35 };
36
37 /**
38  * Structure containing informations about AAF file
39  */
40 struct aaf {
41         /**
42          * Signature used to identify file type.
43          * Should be equal to: "AAFF"
44          */
45         char signature[4];
46         
47         /**
48          * Maximum glyph Height.
49          * This is the maximum height of the glyph, including ascenders and
50          * descenders.
51          */
52         uint16_t max_h;
53         
54         /**
55          * Horizontal gap.
56          * Gap size (in pixels) between adjacent glyphs.
57          */
58         uint16_t gap_h;
59         
60         /**
61          * Width of space.
62          * The width of the space character.
63          */
64         uint16_t space_width;
65         
66         /**
67          * Vertical gap.
68          * The number of pixels between two lines of glyphs.
69          */
70         uint16_t gap_v;
71         
72         struct aaf_glyph glyphs[AAF_GLYPH_MAX];
73 };
74
75 /**
76  * Structure containing informations about glyph display
77  */
78 struct aaf_glyph_data {
79         /**
80          * Variable size array containing values 0-9
81          *
82          * Array size can be calculated using: aaf_glyph::w * aaf_glyph::h
83          *
84          * 0 means that the pixel is transparent.
85          *
86          * The values 1 to 9 represent the relative brightness of that pixel,
87          * with 9 being the brightest. There does not appear to be a linear
88          * increase in brightness from values 1 to 9.
89          */
90         uint8_t * pixels;
91 };
92
93 /**
94  * Reads AAF informations about font
95  *
96  * @param in opened stream for reading
97  * @param _aaf reference to structure where read informations will be stored
98  *
99  * @return when succesful function returns 0, otherwise non-zero value
100  */
101 int aaf_read(FILE * in, struct aaf * _aaf);
102
103 /**
104  * Reads AAF glyph data from input stream
105  * Returned structure is an array with number of elements equal to AAF_GLYPH_MAX.
106  * Every X element of array relates to _aaf->glyphs[X].
107  * Structure should be freed using aaf_free_glyph_data function.
108  *
109  * @param in opened input stream
110  * @param _aaf pointer to AAF header information
111  *
112  * @return when succesful returns pointer to newly allocated array of struct
113  * aaf_glyph_data. On error NULL is returned.
114  */
115 struct aaf_glyph_data ** aaf_read_glyph_data(FILE * in, struct aaf * _aaf);
116
117 /**
118  * Function used to free memory allocated using aaf_read_glyph_data.
119  *
120  * @param data pointer to array of glyph data
121  */
122 void aaf_free_glyph_data(struct aaf_glyph_data ** data);
123
124 /**
125  * Writes AAF glyph as PGM image
126  *
127  * @param out opened output stream for writting
128  * @param glyph glyph description
129  * @param data glyph data
130  * @return 0 if data was written succesfully, non-zero value when error occured
131  */
132 int aaf_write_glyph_as_pgm(FILE * out, const struct aaf_glyph * glyph, const struct aaf_glyph_data * data);
133
134 #endif /* __AAF_H */