hb-font-private.hh revision 3897335c7620c37e9a0224b0c42ade0dfdce4053
1c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod/*
22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2009  Red Hat, Inc.
32409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2011  Google, Inc.
4c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod *
5c755cb3e3ac55156d0d2ec05adea7a650b97cc41Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
6c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod *
7c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * Permission is hereby granted, without written agreement and without
8c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
9c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * software and its documentation for any purpose, provided that the
10c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * above copyright notice and the following two paragraphs appear in
11c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * all copies of this software.
12c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod *
13c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * DAMAGE.
18c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod *
19c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod *
25c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
262409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Google Author(s): Behdad Esfahbod
27c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod */
28c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
29c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#ifndef HB_FONT_PRIVATE_HH
30c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#define HB_FONT_PRIVATE_HH
31c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
32c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#include "hb-private.hh"
33c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
34c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod#include "hb-font.h"
35fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod#include "hb-object-private.hh"
36c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
37c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
38acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
39c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod/*
405c44188455ca1b696aa24b20c3a83877dfae2fb2Behdad Esfahbod * hb_font_funcs_t
41c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod */
42c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
43744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod#define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \
44744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph) \
45744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \
46744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \
477e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \
48744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \
497e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \
507e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning) \
51744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_extents) \
524b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbod  HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
534b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbod  /* ^--- Add new callbacks here */
54744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod
554b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbodstruct _hb_font_funcs_t {
564b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbod  hb_object_header_t header;
574b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbod
584b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbod  hb_bool_t immutable;
594b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbod
604b6317c4f426cfaf21e509dbf6ee6d4e0422cdacBehdad Esfahbod  /* Don't access these directly.  Call hb_font_get_*() instead. */
61744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod
62b9d975b931d6310f25fab5ac280f523cdc27bf94Behdad Esfahbod  struct {
63744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name;
64744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
65744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod#undef HB_FONT_FUNC_IMPLEMENT
66b9d975b931d6310f25fab5ac280f523cdc27bf94Behdad Esfahbod  } get;
67b9d975b931d6310f25fab5ac280f523cdc27bf94Behdad Esfahbod
68b9d975b931d6310f25fab5ac280f523cdc27bf94Behdad Esfahbod  struct {
69744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod#define HB_FONT_FUNC_IMPLEMENT(name) void *name;
70744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
71744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod#undef HB_FONT_FUNC_IMPLEMENT
72b9d975b931d6310f25fab5ac280f523cdc27bf94Behdad Esfahbod  } user_data;
73b9d975b931d6310f25fab5ac280f523cdc27bf94Behdad Esfahbod
74bf36a1074ab23abeab0a7a6c47db26770dc1ab0aBehdad Esfahbod  struct {
75744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod#define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
76744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod    HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
77744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod#undef HB_FONT_FUNC_IMPLEMENT
78b9d975b931d6310f25fab5ac280f523cdc27bf94Behdad Esfahbod  } destroy;
79c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod};
80c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
81c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
82c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod/*
83c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * hb_face_t
84c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod */
85c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
86c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbodstruct _hb_face_t {
87fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  hb_object_header_t header;
88c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
897fc5a30cb4fbe9a4633ab842b0a8cbbcc6f6bd1bBehdad Esfahbod  hb_bool_t immutable;
907fc5a30cb4fbe9a4633ab842b0a8cbbcc6f6bd1bBehdad Esfahbod
91e715784be35f0846c0e084b7c53c7556ce933a45Behdad Esfahbod  hb_reference_table_func_t  reference_table;
92e715784be35f0846c0e084b7c53c7556ce933a45Behdad Esfahbod  void                      *user_data;
93e715784be35f0846c0e084b7c53c7556ce933a45Behdad Esfahbod  hb_destroy_func_t          destroy;
94c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
950a4399ca228d244e646abdb3487da0f13b228889Behdad Esfahbod  struct hb_ot_layout_t *ot_layout;
96abcfe9b59b4475eb02dd679aac4bc59616713b28Behdad Esfahbod
973897335c7620c37e9a0224b0c42ade0dfdce4053Behdad Esfahbod  unsigned int index;
98abcfe9b59b4475eb02dd679aac4bc59616713b28Behdad Esfahbod  unsigned int upem;
99c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod};
100c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
101c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
102c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod/*
103c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod * hb_font_t
104c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod */
105c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
106c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbodstruct _hb_font_t {
107fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  hb_object_header_t header;
108c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
10974f1d896f2479500d65649cf3ec86dd201f0663aBehdad Esfahbod  hb_bool_t immutable;
11074f1d896f2479500d65649cf3ec86dd201f0663aBehdad Esfahbod
111defc45be6d75aba4a67fa7814b91b73bad953fe6Behdad Esfahbod  hb_font_t *parent;
11272657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_face_t *face;
11372657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod
11411bb8fe7b3925bc9b019ad0c0218a231e581f152Behdad Esfahbod  int x_scale;
11511bb8fe7b3925bc9b019ad0c0218a231e581f152Behdad Esfahbod  int y_scale;
116c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
117c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod  unsigned int x_ppem;
118c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod  unsigned int y_ppem;
1195c44188455ca1b696aa24b20c3a83877dfae2fb2Behdad Esfahbod
1208fb3d1aa4e613cdf965a83bd650c668884c58ad8Behdad Esfahbod  hb_font_funcs_t   *klass;
1218fb3d1aa4e613cdf965a83bd650c668884c58ad8Behdad Esfahbod  void              *user_data;
1225668189c12c264e8d2caf0d12dac918363ef6f80Behdad Esfahbod  hb_destroy_func_t  destroy;
123abcfe9b59b4475eb02dd679aac4bc59616713b28Behdad Esfahbod
124abcfe9b59b4475eb02dd679aac4bc59616713b28Behdad Esfahbod
125abcfe9b59b4475eb02dd679aac4bc59616713b28Behdad Esfahbod  /* Convert from font-space to user-space */
126b6f902a1a9c8b72b5d6a241a14a7bacfaea3a56aBehdad Esfahbod  inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); }
127b6f902a1a9c8b72b5d6a241a14a7bacfaea3a56aBehdad Esfahbod  inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scale); }
128abcfe9b59b4475eb02dd679aac4bc59616713b28Behdad Esfahbod
12963d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  /* Convert from parent-font user-space to our user-space */
13063d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  inline hb_position_t parent_scale_x_distance (hb_position_t v) {
13163d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    if (unlikely (parent && parent->x_scale != x_scale))
13263d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod      return v * (int64_t) this->x_scale / this->parent->x_scale;
13363d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    return v;
13463d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  }
13563d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  inline hb_position_t parent_scale_y_distance (hb_position_t v) {
13663d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    if (unlikely (parent && parent->y_scale != y_scale))
13763d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod      return v * (int64_t) this->y_scale / this->parent->y_scale;
13863d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    return v;
13963d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  }
14063d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  inline hb_position_t parent_scale_x_position (hb_position_t v) {
14160fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod    return parent_scale_x_distance (v);
14263d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  }
14363d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  inline hb_position_t parent_scale_y_position (hb_position_t v) {
14460fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod    return parent_scale_y_distance (v);
14563d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  }
14663d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod
14763d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) {
14863d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    *x = parent_scale_x_distance (*x);
14963d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    *y = parent_scale_y_distance (*y);
15063d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  }
15163d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  inline void parent_scale_position (hb_position_t *x, hb_position_t *y) {
15263d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    *x = parent_scale_x_position (*x);
15363d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod    *y = parent_scale_y_position (*y);
15463d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod  }
15563d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod
15663d646fb2933c2765ce526d321a498d0f7fae2f5Behdad Esfahbod
157abcfe9b59b4475eb02dd679aac4bc59616713b28Behdad Esfahbod  private:
1583897335c7620c37e9a0224b0c42ade0dfdce4053Behdad Esfahbod  inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / hb_face_get_upem (this->face); }
159c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod};
160c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
161c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
162c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
163c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#endif /* HB_FONT_PRIVATE_HH */
164