OLD | NEW |
(Empty) | |
| 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 /* ^--- Add new callbacks here */ |
| 54 |
| 55 struct _hb_font_funcs_t { |
| 56 hb_object_header_t header; |
| 57 |
| 58 hb_bool_t immutable; |
| 59 |
| 60 /* Don't access these directly. Call hb_font_get_*() instead. */ |
| 61 |
| 62 struct { |
| 63 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name; |
| 64 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 65 #undef HB_FONT_FUNC_IMPLEMENT |
| 66 } get; |
| 67 |
| 68 struct { |
| 69 #define HB_FONT_FUNC_IMPLEMENT(name) void *name; |
| 70 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 71 #undef HB_FONT_FUNC_IMPLEMENT |
| 72 } user_data; |
| 73 |
| 74 struct { |
| 75 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name; |
| 76 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
| 77 #undef HB_FONT_FUNC_IMPLEMENT |
| 78 } destroy; |
| 79 }; |
| 80 |
| 81 |
| 82 /* |
| 83 * hb_face_t |
| 84 */ |
| 85 |
| 86 struct _hb_face_t { |
| 87 hb_object_header_t header; |
| 88 |
| 89 hb_bool_t immutable; |
| 90 |
| 91 hb_reference_table_func_t reference_table; |
| 92 void *user_data; |
| 93 hb_destroy_func_t destroy; |
| 94 |
| 95 struct hb_ot_layout_t *ot_layout; |
| 96 |
| 97 unsigned int index; |
| 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_scal
e); } |
| 127 inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scal
e); } |
| 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) sc
ale / hb_face_get_upem (this->face); } |
| 159 }; |
| 160 |
| 161 |
| 162 |
| 163 #endif /* HB_FONT_PRIVATE_HH */ |
OLD | NEW |