dd71b6780f72dc7bbf8a9785353ea7b8c60f1212
[framework/uifw/harfbuzz.git] / src / hb-font-private.hh
1 /*
2  * Copyright © 2009  Red Hat, Inc.
3  * Copyright © 2011  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Red Hat Author(s): Behdad Esfahbod
26  * Google Author(s): Behdad Esfahbod
27  */
28
29 #ifndef HB_FONT_PRIVATE_HH
30 #define HB_FONT_PRIVATE_HH
31
32 #include "hb-private.hh"
33
34 #include "hb-font.h"
35 #include "hb-object-private.hh"
36
37 HB_BEGIN_DECLS
38
39
40 /*
41  * hb_font_funcs_t
42  */
43
44 #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \
45   HB_FONT_FUNC_IMPLEMENT (glyph) \
46   HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \
47   HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \
48   HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \
49   HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \
50   HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \
51   HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning) \
52   HB_FONT_FUNC_IMPLEMENT (glyph_extents) \
53   HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
54   /* ^--- Add new callbacks here */
55
56 struct _hb_font_funcs_t {
57   hb_object_header_t header;
58
59   hb_bool_t immutable;
60
61   /* Don't access these directly.  Call hb_font_get_*() instead. */
62
63   struct {
64 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name;
65     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
66 #undef HB_FONT_FUNC_IMPLEMENT
67   } get;
68
69   struct {
70 #define HB_FONT_FUNC_IMPLEMENT(name) void *name;
71     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
72 #undef HB_FONT_FUNC_IMPLEMENT
73   } user_data;
74
75   struct {
76 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
77     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
78 #undef HB_FONT_FUNC_IMPLEMENT
79   } destroy;
80 };
81
82
83 /*
84  * hb_face_t
85  */
86
87 struct _hb_face_t {
88   hb_object_header_t header;
89
90   hb_bool_t immutable;
91
92   hb_get_table_func_t  get_table;
93   void                *user_data;
94   hb_destroy_func_t    destroy;
95
96   struct hb_ot_layout_t *ot_layout;
97
98   unsigned int upem;
99 };
100
101
102 /*
103  * hb_font_t
104  */
105
106 struct _hb_font_t {
107   hb_object_header_t header;
108
109   hb_bool_t immutable;
110
111   hb_font_t *parent;
112   hb_face_t *face;
113
114   int x_scale;
115   int y_scale;
116
117   unsigned int x_ppem;
118   unsigned int y_ppem;
119
120   hb_font_funcs_t   *klass;
121   void              *user_data;
122   hb_destroy_func_t  destroy;
123
124
125   /* Convert from font-space to user-space */
126   inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); }
127   inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scale); }
128
129   /* Convert from parent-font user-space to our user-space */
130   inline hb_position_t parent_scale_x_distance (hb_position_t v) {
131     if (unlikely (parent && parent->x_scale != x_scale))
132       return v * (int64_t) this->x_scale / this->parent->x_scale;
133     return v;
134   }
135   inline hb_position_t parent_scale_y_distance (hb_position_t v) {
136     if (unlikely (parent && parent->y_scale != y_scale))
137       return v * (int64_t) this->y_scale / this->parent->y_scale;
138     return v;
139   }
140   inline hb_position_t parent_scale_x_position (hb_position_t v) {
141     return parent_scale_x_distance (v);
142   }
143   inline hb_position_t parent_scale_y_position (hb_position_t v) {
144     return parent_scale_y_distance (v);
145   }
146
147   inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) {
148     *x = parent_scale_x_distance (*x);
149     *y = parent_scale_y_distance (*y);
150   }
151   inline void parent_scale_position (hb_position_t *x, hb_position_t *y) {
152     *x = parent_scale_x_position (*x);
153     *y = parent_scale_y_position (*y);
154   }
155
156
157   private:
158   inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / this->face->upem; }
159 };
160
161
162 HB_END_DECLS
163
164 #endif /* HB_FONT_PRIVATE_HH */