1 /*
2  * Copyright © 2015 Information Technology Authority (ITA) <foss@ita.gov.om>
3  * Copyright © 2016 Khaled Hosny <khaledhosny@eglug.org>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef _RAQM_H_
26 #define _RAQM_H_
27 #define _RAQM_H_IN_
28 
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include <ft2build.h>
36 #include FT_FREETYPE_H
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include "raqm-version.h"
43 
44 /**
45  * raqm_t:
46  *
47  * This is the main object holding all state of the currently processed text as
48  * well as its output.
49  *
50  * Since: 0.1
51  */
52 typedef struct _raqm raqm_t;
53 
54 /**
55  * raqm_direction_t:
56  * @RAQM_DIRECTION_DEFAULT: Detect paragraph direction automatically.
57  * @RAQM_DIRECTION_RTL: Paragraph is mainly right-to-left text.
58  * @RAQM_DIRECTION_LTR: Paragraph is mainly left-to-right text.
59  * @RAQM_DIRECTION_TTB: Paragraph is mainly vertical top-to-bottom text.
60  *
61  * Base paragraph direction, see raqm_set_par_direction().
62  *
63  * Since: 0.1
64  */
65 typedef enum
66 {
67     RAQM_DIRECTION_DEFAULT,
68     RAQM_DIRECTION_RTL,
69     RAQM_DIRECTION_LTR,
70     RAQM_DIRECTION_TTB
71 } raqm_direction_t;
72 
73 /**
74  * raqm_glyph_t:
75  * @index: the index of the glyph in the font file.
76  * @x_advance: the glyph advance width in horizontal text.
77  * @y_advance: the glyph advance width in vertical text.
78  * @x_offset: the horizontal movement of the glyph from the current point.
79  * @y_offset: the vertical movement of the glyph from the current point.
80  * @cluster: the index of original character in input text.
81  * @ftface: the @FT_Face of the glyph.
82  *
83  * The structure that holds information about output glyphs, returned from
84  * raqm_get_glyphs().
85  */
86 typedef struct raqm_glyph_t {
87     unsigned int index;
88     int x_advance;
89     int y_advance;
90     int x_offset;
91     int y_offset;
92     uint32_t cluster;
93     FT_Face ftface;
94 } raqm_glyph_t;
95 
96 raqm_t *
97 raqm_create (void);
98 
99 raqm_t *
100 raqm_reference (raqm_t *rq);
101 
102 void
103 raqm_destroy (raqm_t *rq);
104 
105 bool
106 raqm_set_text (raqm_t         *rq,
107                const uint32_t *text,
108                size_t          len);
109 
110 bool
111 raqm_set_text_utf8 (raqm_t     *rq,
112                     const char *text,
113                     size_t      len);
114 
115 bool
116 raqm_set_par_direction (raqm_t          *rq,
117                         raqm_direction_t dir);
118 
119 bool
120 raqm_set_language (raqm_t       *rq,
121                    const char   *lang,
122                    size_t        start,
123                    size_t        len);
124 
125 bool
126 raqm_add_font_feature  (raqm_t     *rq,
127                         const char *feature,
128                         int         len);
129 
130 bool
131 raqm_set_freetype_face (raqm_t *rq,
132                         FT_Face face);
133 
134 bool
135 raqm_set_freetype_face_range (raqm_t *rq,
136                               FT_Face face,
137                               size_t  start,
138                               size_t  len);
139 
140 bool
141 raqm_set_freetype_load_flags (raqm_t *rq,
142                               int flags);
143 
144 bool
145 raqm_set_invisible_glyph (raqm_t *rq,
146                           int gid);
147 
148 bool
149 raqm_layout (raqm_t *rq);
150 
151 raqm_glyph_t *
152 raqm_get_glyphs (raqm_t *rq,
153                  size_t *length);
154 
155 bool
156 raqm_index_to_position (raqm_t *rq,
157                         size_t *index,
158                         int *x,
159                         int *y);
160 
161 bool
162 raqm_position_to_index (raqm_t *rq,
163                         int x,
164                         int y,
165                         size_t *index);
166 
167 void
168 raqm_version (unsigned int *major,
169               unsigned int *minor,
170               unsigned int *micro);
171 
172 const char *
173 raqm_version_string (void);
174 
175 bool
176 raqm_version_atleast (unsigned int major,
177                       unsigned int minor,
178                       unsigned int micro);
179 
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 #undef _RAQM_H_IN_
185 #endif /* _RAQM_H_ */
186