91a43047daeacc972eea51d899f8aaa530f06304
[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
38
39 /*
40  * hb_font_funcs_t
41  */
42
43 #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \
44   HB_FONT_FUNC_IMPLEMENT (glyph) \
45   HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \
46   HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \
47   HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \
48   HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \
49   HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \
50   HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning) \
51   HB_FONT_FUNC_IMPLEMENT (glyph_extents) \
52   HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
53   HB_FONT_FUNC_IMPLEMENT (glyph_name) \
54   HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \
55   /* ^--- Add new callbacks here */
56
57 struct _hb_font_funcs_t {
58   hb_object_header_t header;
59   ASSERT_POD ();
60
61   hb_bool_t immutable;
62
63   /* Don't access these directly.  Call hb_font_get_*() instead. */
64
65   struct {
66 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name;
67     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
68 #undef HB_FONT_FUNC_IMPLEMENT
69   } get;
70
71   struct {
72 #define HB_FONT_FUNC_IMPLEMENT(name) void *name;
73     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
74 #undef HB_FONT_FUNC_IMPLEMENT
75   } user_data;
76
77   struct {
78 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
79     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
80 #undef HB_FONT_FUNC_IMPLEMENT
81   } destroy;
82 };
83
84
85 /*
86  * hb_face_t
87  */
88
89 struct _hb_face_t {
90   hb_object_header_t header;
91   ASSERT_POD ();
92
93   hb_bool_t immutable;
94
95   hb_reference_table_func_t  reference_table;
96   void                      *user_data;
97   hb_destroy_func_t          destroy;
98
99   struct hb_ot_layout_t *ot_layout;
100
101   unsigned int index;
102   unsigned int upem;
103 };
104
105
106 /*
107  * hb_font_t
108  */
109
110 struct _hb_font_t {
111   hb_object_header_t header;
112   ASSERT_POD ();
113
114   hb_bool_t immutable;
115
116   hb_font_t *parent;
117   hb_face_t *face;
118
119   int x_scale;
120   int y_scale;
121
122   unsigned int x_ppem;
123   unsigned int y_ppem;
124
125   hb_font_funcs_t   *klass;
126   void              *user_data;
127   hb_destroy_func_t  destroy;
128
129
130   /* Convert from font-space to user-space */
131   inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); }
132   inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scale); }
133
134   /* Convert from parent-font user-space to our user-space */
135   inline hb_position_t parent_scale_x_distance (hb_position_t v) {
136     if (unlikely (parent && parent->x_scale != x_scale))
137       return v * (int64_t) this->x_scale / this->parent->x_scale;
138     return v;
139   }
140   inline hb_position_t parent_scale_y_distance (hb_position_t v) {
141     if (unlikely (parent && parent->y_scale != y_scale))
142       return v * (int64_t) this->y_scale / this->parent->y_scale;
143     return v;
144   }
145   inline hb_position_t parent_scale_x_position (hb_position_t v) {
146     return parent_scale_x_distance (v);
147   }
148   inline hb_position_t parent_scale_y_position (hb_position_t v) {
149     return parent_scale_y_distance (v);
150   }
151
152   inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) {
153     *x = parent_scale_x_distance (*x);
154     *y = parent_scale_y_distance (*y);
155   }
156   inline void parent_scale_position (hb_position_t *x, hb_position_t *y) {
157     *x = parent_scale_x_position (*x);
158     *y = parent_scale_y_position (*y);
159   }
160
161
162   private:
163   inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / hb_face_get_upem (this->face); }
164 };
165
166
167
168 #endif /* HB_FONT_PRIVATE_HH */