Adaptor refactor
[platform/core/uifw/dali-adaptor.git] / third-party / glyphy / glyphy-freetype.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 /* Intentionally doesn't have include guards */
20
21 #include "glyphy.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27
28 #include <ft2build.h>
29 #include FT_FREETYPE_H
30 #include FT_OUTLINE_H
31
32 static int
33 glyphy_freetype_move_to(FT_Vector *to,
34                         glyphy_arc_accumulator_t *acc)
35 {
36   glyphy_point_t p1 = {static_cast<double>(to->x), static_cast<double>(to->y)};
37   glyphy_arc_accumulator_close_path (acc);
38   glyphy_arc_accumulator_move_to (acc, &p1);
39   return glyphy_arc_accumulator_successful (acc) ? FT_Err_Ok : FT_Err_Out_Of_Memory;
40 }
41
42 static int
43 glyphy_freetype_line_to(FT_Vector *to,
44                         glyphy_arc_accumulator_t *acc)
45 {
46   glyphy_point_t p1 = {static_cast<double>(to->x), static_cast<double>(to->y)};
47   glyphy_arc_accumulator_line_to (acc, &p1);
48   return glyphy_arc_accumulator_successful (acc) ? FT_Err_Ok : FT_Err_Out_Of_Memory;
49 }
50
51 static int
52 glyphy_freetype_conic_to(FT_Vector *control, FT_Vector *to,
53                          glyphy_arc_accumulator_t *acc)
54 {
55   glyphy_point_t p1 = {static_cast<double>(control->x), static_cast<double>(control->y)};
56   glyphy_point_t p2 = {static_cast<double>(to->x), static_cast<double>(to->y)};
57   glyphy_arc_accumulator_conic_to (acc, &p1, &p2);
58   return glyphy_arc_accumulator_successful (acc) ? FT_Err_Ok : FT_Err_Out_Of_Memory;
59 }
60
61 static int
62 glyphy_freetype_cubic_to(FT_Vector *control1, FT_Vector *control2, FT_Vector *to,
63                          glyphy_arc_accumulator_t *acc)
64 {
65   glyphy_point_t p1 = {static_cast<double>(control1->x), static_cast<double>(control1->y)};
66   glyphy_point_t p2 = {static_cast<double>(control2->x), static_cast<double>(control2->y)};
67   glyphy_point_t p3 = {static_cast<double>(to->x), static_cast<double>(to->y)};
68   glyphy_arc_accumulator_cubic_to (acc, &p1, &p2, &p3);
69   return glyphy_arc_accumulator_successful (acc) ? FT_Err_Ok : FT_Err_Out_Of_Memory;
70 }
71
72 static FT_Error
73 glyphy_freetype_outline_decompose(const FT_Outline         *outline,
74                                   glyphy_arc_accumulator_t *acc)
75 {
76   const FT_Outline_Funcs outline_funcs = {
77     (FT_Outline_MoveToFunc) glyphy_freetype_move_to,
78     (FT_Outline_LineToFunc) glyphy_freetype_line_to,
79     (FT_Outline_ConicToFunc) glyphy_freetype_conic_to,
80     (FT_Outline_CubicToFunc) glyphy_freetype_cubic_to,
81     0, /* shift */
82     0, /* delta */
83   };
84
85   return FT_Outline_Decompose ((FT_Outline *) outline, &outline_funcs, acc);
86 }
87
88 #ifdef __cplusplus
89 }
90 #endif