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 #include "hb-private.hh" 30 31 #include "hb-ot-layout-private.hh" 32 33 #include "hb-font-private.hh" 34 #include "hb-open-file-private.hh" 35 #include "hb-ot-head-table.hh" 36 #include "hb-ot-maxp-table.hh" 37 38 #include "hb-cache-private.hh" 39 40 #include <string.h> 41 42 43 /* 44 * hb_font_funcs_t 45 */ 46 47 static hb_bool_t 48 hb_font_get_font_h_extents_nil (hb_font_t *font, 49 void *font_data HB_UNUSED, 50 hb_font_extents_t *metrics, 51 void *user_data HB_UNUSED) 52 { 53 memset (metrics, 0, sizeof (*metrics)); 54 return false; 55 } 56 static hb_bool_t 57 hb_font_get_font_h_extents_parent (hb_font_t *font, 58 void *font_data HB_UNUSED, 59 hb_font_extents_t *metrics, 1150 * Since: 0.9.2 1151 **/ 1152 hb_font_t * 1153 hb_font_create_sub_font (hb_font_t *parent) 1154 { 1155 if (unlikely (!parent)) 1156 parent = hb_font_get_empty (); 1157 1158 hb_font_t *font = hb_font_create (parent->face); 1159 1160 if (unlikely (hb_object_is_inert (font))) 1161 return font; 1162 1163 font->parent = hb_font_reference (parent); 1164 1165 font->x_scale = parent->x_scale; 1166 font->y_scale = parent->y_scale; 1167 font->x_ppem = parent->x_ppem; 1168 font->y_ppem = parent->y_ppem; 1169 1170 return font; 1171 } 1172 1173 /** 1174 * hb_font_get_empty: 1175 * 1176 * 1177 * 1178 * Return value: (transfer full) 1179 * 1180 * Since: 0.9.2 1181 **/ 1182 hb_font_t * 1183 hb_font_get_empty (void) 1184 { 1185 static const hb_font_t _hb_font_nil = { 1186 HB_OBJECT_HEADER_STATIC, 1187 1188 true, /* immutable */ 1189 1190 NULL, /* parent */ 1191 const_cast<hb_face_t *> (&_hb_face_nil), 1192 1193 1000, /* x_scale */ 1194 1000, /* y_scale */ 1195 1196 0, /* x_ppem */ 1197 0, /* y_ppem */ 1198 1199 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */ 1200 NULL, /* user_data */ 1201 NULL, /* destroy */ 1202 1203 { 1204 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, 1205 #include "hb-shaper-list.hh" 1206 #undef HB_SHAPER_IMPLEMENT 1207 } 1208 }; 1209 1210 return const_cast<hb_font_t *> (&_hb_font_nil); 1211 } 1212 1213 /** 1214 * hb_font_reference: (skip) 1215 * @font: a font. 1216 * 1217 * 1218 * 1233 * 1234 * 1235 * Since: 0.9.2 1236 **/ 1237 void 1238 hb_font_destroy (hb_font_t *font) 1239 { 1240 if (!hb_object_destroy (font)) return; 1241 1242 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font); 1243 #include "hb-shaper-list.hh" 1244 #undef HB_SHAPER_IMPLEMENT 1245 1246 if (font->destroy) 1247 font->destroy (font->user_data); 1248 1249 hb_font_destroy (font->parent); 1250 hb_face_destroy (font->face); 1251 hb_font_funcs_destroy (font->klass); 1252 1253 free (font); 1254 } 1255 1256 /** 1257 * hb_font_set_user_data: (skip) 1258 * @font: a font. 1259 * @key: 1260 * @data: 1261 * @destroy: 1262 * @replace: 1263 * 1264 * 1265 * 1266 * Return value: 1267 * 1268 * Since: 0.9.2 1269 **/ 1270 hb_bool_t 1271 hb_font_set_user_data (hb_font_t *font, 1272 hb_user_data_key_t *key, 1519 font->y_ppem = y_ppem; 1520 } 1521 1522 /** 1523 * hb_font_get_ppem: 1524 * @font: a font. 1525 * @x_ppem: (out): 1526 * @y_ppem: (out): 1527 * 1528 * 1529 * 1530 * Since: 0.9.2 1531 **/ 1532 void 1533 hb_font_get_ppem (hb_font_t *font, 1534 unsigned int *x_ppem, 1535 unsigned int *y_ppem) 1536 { 1537 if (x_ppem) *x_ppem = font->x_ppem; 1538 if (y_ppem) *y_ppem = font->y_ppem; 1539 } 1540 1541 1542 #ifndef HB_DISABLE_DEPRECATED 1543 1544 /* 1545 * Deprecated get_glyph_func(): 1546 */ 1547 1548 struct hb_trampoline_closure_t 1549 { 1550 void *user_data; 1551 hb_destroy_func_t destroy; 1552 unsigned int ref_count; 1553 }; 1554 1555 template <typename FuncType> 1556 struct hb_trampoline_t 1557 { 1558 hb_trampoline_closure_t closure; /* Must be first. */ | 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 #include "hb-private.hh" 30 31 #include "hb-ot-layout-private.hh" 32 33 #include "hb-font-private.hh" 34 #include "hb-open-file-private.hh" 35 #include "hb-ot-head-table.hh" 36 #include "hb-ot-maxp-table.hh" 37 38 #include <string.h> 39 40 41 /* 42 * hb_font_funcs_t 43 */ 44 45 static hb_bool_t 46 hb_font_get_font_h_extents_nil (hb_font_t *font, 47 void *font_data HB_UNUSED, 48 hb_font_extents_t *metrics, 49 void *user_data HB_UNUSED) 50 { 51 memset (metrics, 0, sizeof (*metrics)); 52 return false; 53 } 54 static hb_bool_t 55 hb_font_get_font_h_extents_parent (hb_font_t *font, 56 void *font_data HB_UNUSED, 57 hb_font_extents_t *metrics, 1148 * Since: 0.9.2 1149 **/ 1150 hb_font_t * 1151 hb_font_create_sub_font (hb_font_t *parent) 1152 { 1153 if (unlikely (!parent)) 1154 parent = hb_font_get_empty (); 1155 1156 hb_font_t *font = hb_font_create (parent->face); 1157 1158 if (unlikely (hb_object_is_inert (font))) 1159 return font; 1160 1161 font->parent = hb_font_reference (parent); 1162 1163 font->x_scale = parent->x_scale; 1164 font->y_scale = parent->y_scale; 1165 font->x_ppem = parent->x_ppem; 1166 font->y_ppem = parent->y_ppem; 1167 1168 /* TODO: copy variation coordinates. */ 1169 1170 return font; 1171 } 1172 1173 /** 1174 * hb_font_get_empty: 1175 * 1176 * 1177 * 1178 * Return value: (transfer full) 1179 * 1180 * Since: 0.9.2 1181 **/ 1182 hb_font_t * 1183 hb_font_get_empty (void) 1184 { 1185 static const hb_font_t _hb_font_nil = { 1186 HB_OBJECT_HEADER_STATIC, 1187 1188 true, /* immutable */ 1189 1190 NULL, /* parent */ 1191 const_cast<hb_face_t *> (&_hb_face_nil), 1192 1193 1000, /* x_scale */ 1194 1000, /* y_scale */ 1195 1196 0, /* x_ppem */ 1197 0, /* y_ppem */ 1198 1199 0, /* num_coords */ 1200 NULL, /* coords */ 1201 1202 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */ 1203 NULL, /* user_data */ 1204 NULL, /* destroy */ 1205 1206 { 1207 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, 1208 #include "hb-shaper-list.hh" 1209 #undef HB_SHAPER_IMPLEMENT 1210 } 1211 }; 1212 1213 return const_cast<hb_font_t *> (&_hb_font_nil); 1214 } 1215 1216 /** 1217 * hb_font_reference: (skip) 1218 * @font: a font. 1219 * 1220 * 1221 * 1236 * 1237 * 1238 * Since: 0.9.2 1239 **/ 1240 void 1241 hb_font_destroy (hb_font_t *font) 1242 { 1243 if (!hb_object_destroy (font)) return; 1244 1245 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font); 1246 #include "hb-shaper-list.hh" 1247 #undef HB_SHAPER_IMPLEMENT 1248 1249 if (font->destroy) 1250 font->destroy (font->user_data); 1251 1252 hb_font_destroy (font->parent); 1253 hb_face_destroy (font->face); 1254 hb_font_funcs_destroy (font->klass); 1255 1256 free (font->coords); 1257 1258 free (font); 1259 } 1260 1261 /** 1262 * hb_font_set_user_data: (skip) 1263 * @font: a font. 1264 * @key: 1265 * @data: 1266 * @destroy: 1267 * @replace: 1268 * 1269 * 1270 * 1271 * Return value: 1272 * 1273 * Since: 0.9.2 1274 **/ 1275 hb_bool_t 1276 hb_font_set_user_data (hb_font_t *font, 1277 hb_user_data_key_t *key, 1524 font->y_ppem = y_ppem; 1525 } 1526 1527 /** 1528 * hb_font_get_ppem: 1529 * @font: a font. 1530 * @x_ppem: (out): 1531 * @y_ppem: (out): 1532 * 1533 * 1534 * 1535 * Since: 0.9.2 1536 **/ 1537 void 1538 hb_font_get_ppem (hb_font_t *font, 1539 unsigned int *x_ppem, 1540 unsigned int *y_ppem) 1541 { 1542 if (x_ppem) *x_ppem = font->x_ppem; 1543 if (y_ppem) *y_ppem = font->y_ppem; 1544 } 1545 1546 1547 void 1548 hb_font_set_var_coords_normalized (hb_font_t *font, 1549 int *coords, /* XXX 2.14 normalized */ 1550 unsigned int coords_length) 1551 { 1552 if (font->immutable) 1553 return; 1554 1555 /* Skip tail zero entries. */ 1556 while (coords_length && !coords[coords_length - 1]) 1557 coords_length--; 1558 1559 int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : NULL; 1560 if (unlikely (coords_length && !copy)) 1561 return; 1562 1563 free (font->coords); 1564 1565 if (coords_length) 1566 memcpy (copy, coords, coords_length * sizeof (coords[0])); 1567 1568 font->coords = copy; 1569 font->num_coords = coords_length; 1570 } 1571 1572 1573 #ifndef HB_DISABLE_DEPRECATED 1574 1575 /* 1576 * Deprecated get_glyph_func(): 1577 */ 1578 1579 struct hb_trampoline_closure_t 1580 { 1581 void *user_data; 1582 hb_destroy_func_t destroy; 1583 unsigned int ref_count; 1584 }; 1585 1586 template <typename FuncType> 1587 struct hb_trampoline_t 1588 { 1589 hb_trampoline_closure_t closure; /* Must be first. */ |