Merge "Make GlyphBufferData as another class" into devel/master
[platform/core/uifw/dali-adaptor.git] / third-party / glyphy / glyphy.h
1 /*
2  * Copyright 2012 Google, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * Google Author(s): Behdad Esfahbod, Maysum Panju
17  */
18
19 #ifndef GLYPHY_H
20 #define GLYPHY_H
21
22 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 typedef int glyphy_bool_t;
29
30 typedef struct {
31   double x;
32   double y;
33 } glyphy_point_t;
34
35 /*
36  * Geometry extents
37  */
38
39 typedef struct {
40   double min_x;
41   double min_y;
42   double max_x;
43   double max_y;
44 } glyphy_extents_t;
45
46 void
47 glyphy_extents_clear (glyphy_extents_t *extents);
48
49 glyphy_bool_t
50 glyphy_extents_is_empty (const glyphy_extents_t *extents);
51
52 void
53 glyphy_extents_add (glyphy_extents_t     *extents,
54                     const glyphy_point_t *p);
55
56 void
57 glyphy_extents_extend (glyphy_extents_t       *extents,
58                        const glyphy_extents_t *other);
59
60 glyphy_bool_t
61 glyphy_extents_includes (const glyphy_extents_t *extents,
62                          const glyphy_point_t   *p);
63
64 void
65 glyphy_extents_scale (glyphy_extents_t *extents,
66                       double            x_scale,
67                       double            y_scale);
68
69 /*
70  * Circular arcs
71  */
72
73 typedef struct {
74   glyphy_point_t p0;
75   glyphy_point_t p1;
76   double d;
77 } glyphy_arc_t;
78
79 /*
80  * Approximate outlines with multiple arcs
81  */
82
83 typedef struct {
84   glyphy_point_t p;
85   double d;
86 } glyphy_arc_endpoint_t;
87
88 typedef glyphy_bool_t (*glyphy_arc_endpoint_accumulator_callback_t) (glyphy_arc_endpoint_t *endpoint,
89                                                                      void                  *user_data);
90
91 typedef struct glyphy_arc_accumulator_t glyphy_arc_accumulator_t;
92
93 glyphy_arc_accumulator_t *
94 glyphy_arc_accumulator_create (void);
95
96 void
97 glyphy_arc_accumulator_destroy (glyphy_arc_accumulator_t *acc);
98
99 void
100 glyphy_arc_accumulator_reset (glyphy_arc_accumulator_t *acc);
101
102 /* Configure accumulator */
103
104 void
105 glyphy_arc_accumulator_set_tolerance (glyphy_arc_accumulator_t *acc,
106                                       double                    tolerance);
107
108 double
109 glyphy_arc_accumulator_get_tolerance (glyphy_arc_accumulator_t *acc);
110
111 void
112 glyphy_arc_accumulator_set_callback (glyphy_arc_accumulator_t *acc,
113                                      glyphy_arc_endpoint_accumulator_callback_t callback,
114                                      void                     *user_data);
115
116 void
117 glyphy_arc_accumulator_get_callback (glyphy_arc_accumulator_t  *acc,
118                                      glyphy_arc_endpoint_accumulator_callback_t *callback,
119                                      void                     **user_data);
120
121 /* Accumulation results */
122
123 double
124 glyphy_arc_accumulator_get_error (glyphy_arc_accumulator_t *acc);
125
126 glyphy_bool_t
127 glyphy_arc_accumulator_successful (glyphy_arc_accumulator_t *acc);
128
129
130 /* Accumulate */
131
132 void
133 glyphy_arc_accumulator_move_to (glyphy_arc_accumulator_t *acc,
134                                 const glyphy_point_t *p0);
135
136 void
137 glyphy_arc_accumulator_line_to (glyphy_arc_accumulator_t *acc,
138                                 const glyphy_point_t *p1);
139
140 void
141 glyphy_arc_accumulator_conic_to (glyphy_arc_accumulator_t *acc,
142                                  const glyphy_point_t *p1,
143                                  const glyphy_point_t *p2);
144
145 void
146 glyphy_arc_accumulator_cubic_to (glyphy_arc_accumulator_t *acc,
147                                  const glyphy_point_t *p1,
148                                  const glyphy_point_t *p2,
149                                  const glyphy_point_t *p3);
150
151 void
152 glyphy_arc_accumulator_arc_to (glyphy_arc_accumulator_t *acc,
153                                const glyphy_point_t *p1,
154                                double                d);
155
156 void
157 glyphy_arc_accumulator_close_path (glyphy_arc_accumulator_t *acc);
158
159 void
160 glyphy_arc_list_extents (const glyphy_arc_endpoint_t *endpoints,
161                          unsigned int                 num_endpoints,
162                          glyphy_extents_t            *extents);
163
164 /*
165  * Modify outlines for proper consumption
166  */
167
168 void
169 glyphy_outline_reverse (glyphy_arc_endpoint_t *endpoints,
170                         unsigned int           num_endpoints);
171
172 /* Returns true if outline was modified */
173 glyphy_bool_t
174 glyphy_outline_winding_from_even_odd (glyphy_arc_endpoint_t *endpoints,
175                                       unsigned int           num_endpoints,
176                                       glyphy_bool_t          inverse);
177
178 /*
179  * Encode an arc outline into binary blob for fast SDF calculation
180  */
181
182 typedef Dali::TextAbstraction::VectorBlob glyphy_rgba_t;
183
184 glyphy_bool_t
185 glyphy_arc_list_encode_blob (const glyphy_arc_endpoint_t *endpoints,
186                              unsigned int                 num_endpoints,
187                              glyphy_rgba_t               *blob,
188                              unsigned int                 blob_size,
189                              double                       faraway,
190                              double                       avg_fetch_desired,
191                              double                      *avg_fetch_achieved,
192                              unsigned int                *output_len,
193                              unsigned int                *nominal_width,  /* 6bit */
194                              unsigned int                *nominal_height, /* 6bit */
195                              glyphy_extents_t            *extents);
196
197 /*
198  * Calculate signed-distance-field from (encoded) arc list
199  */
200
201 double
202 glyphy_sdf_from_arc_list (const glyphy_arc_endpoint_t *endpoints,
203                           unsigned int                 num_endpoints,
204                           const glyphy_point_t        *p,
205                           glyphy_point_t              *closest_p /* may be NULL; TBD not implemented yet */);
206
207 double
208 glyphy_sdf_from_blob (const glyphy_rgba_t  *blob,
209                       unsigned int          nominal_width,
210                       unsigned int          nominal_height,
211                       const glyphy_point_t *p,
212                       glyphy_point_t       *closest_p /* may be NULL; TBD not implemented yet */);
213
214 #ifdef __cplusplus
215 }
216 #endif
217
218 #endif /* GLYPHY_H */