LCOV - code coverage report
Current view: top level - gfx/harfbuzz/src - hb-font.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 47 370 12.7 %
Date: 2017-07-14 16:53:18 Functions: 18 106 17.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright © 2009  Red Hat, Inc.
       3             :  * Copyright © 2012  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             : #include "hb-private.hh"
      30             : 
      31             : #include "hb-font-private.hh"
      32             : 
      33             : 
      34             : /*
      35             :  * hb_font_funcs_t
      36             :  */
      37             : 
      38             : static hb_bool_t
      39           0 : hb_font_get_font_h_extents_nil (hb_font_t *font,
      40             :                                 void *font_data HB_UNUSED,
      41             :                                 hb_font_extents_t *metrics,
      42             :                                 void *user_data HB_UNUSED)
      43             : {
      44           0 :   memset (metrics, 0, sizeof (*metrics));
      45           0 :   return false;
      46             : }
      47             : static hb_bool_t
      48           0 : hb_font_get_font_h_extents_parent (hb_font_t *font,
      49             :                                    void *font_data HB_UNUSED,
      50             :                                    hb_font_extents_t *metrics,
      51             :                                    void *user_data HB_UNUSED)
      52             : {
      53           0 :   hb_bool_t ret = font->parent->get_font_h_extents (metrics);
      54           0 :   if (ret) {
      55           0 :     metrics->ascender = font->parent_scale_y_distance (metrics->ascender);
      56           0 :     metrics->descender = font->parent_scale_y_distance (metrics->descender);
      57           0 :     metrics->line_gap = font->parent_scale_y_distance (metrics->line_gap);
      58             :   }
      59           0 :   return ret;
      60             : }
      61             : 
      62             : static hb_bool_t
      63           0 : hb_font_get_font_v_extents_nil (hb_font_t *font,
      64             :                                 void *font_data HB_UNUSED,
      65             :                                 hb_font_extents_t *metrics,
      66             :                                 void *user_data HB_UNUSED)
      67             : {
      68           0 :   memset (metrics, 0, sizeof (*metrics));
      69           0 :   return false;
      70             : }
      71             : static hb_bool_t
      72           0 : hb_font_get_font_v_extents_parent (hb_font_t *font,
      73             :                                    void *font_data HB_UNUSED,
      74             :                                    hb_font_extents_t *metrics,
      75             :                                    void *user_data HB_UNUSED)
      76             : {
      77           0 :   hb_bool_t ret = font->parent->get_font_v_extents (metrics);
      78           0 :   if (ret) {
      79           0 :     metrics->ascender = font->parent_scale_x_distance (metrics->ascender);
      80           0 :     metrics->descender = font->parent_scale_x_distance (metrics->descender);
      81           0 :     metrics->line_gap = font->parent_scale_x_distance (metrics->line_gap);
      82             :   }
      83           0 :   return ret;
      84             : }
      85             : 
      86             : static hb_bool_t
      87           0 : hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
      88             :                                void *font_data HB_UNUSED,
      89             :                                hb_codepoint_t unicode,
      90             :                                hb_codepoint_t *glyph,
      91             :                                void *user_data HB_UNUSED)
      92             : {
      93           0 :   *glyph = 0;
      94           0 :   return false;
      95             : }
      96             : static hb_bool_t
      97           0 : hb_font_get_nominal_glyph_parent (hb_font_t *font,
      98             :                                   void *font_data HB_UNUSED,
      99             :                                   hb_codepoint_t unicode,
     100             :                                   hb_codepoint_t *glyph,
     101             :                                   void *user_data HB_UNUSED)
     102             : {
     103           0 :   return font->parent->get_nominal_glyph (unicode, glyph);
     104             : }
     105             : 
     106             : static hb_bool_t
     107           0 : hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
     108             :                                  void *font_data HB_UNUSED,
     109             :                                  hb_codepoint_t unicode,
     110             :                                  hb_codepoint_t variation_selector,
     111             :                                  hb_codepoint_t *glyph,
     112             :                                  void *user_data HB_UNUSED)
     113             : {
     114           0 :   *glyph = 0;
     115           0 :   return false;
     116             : }
     117             : static hb_bool_t
     118           0 : hb_font_get_variation_glyph_parent (hb_font_t *font,
     119             :                                     void *font_data HB_UNUSED,
     120             :                                     hb_codepoint_t unicode,
     121             :                                     hb_codepoint_t variation_selector,
     122             :                                     hb_codepoint_t *glyph,
     123             :                                     void *user_data HB_UNUSED)
     124             : {
     125           0 :   return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
     126             : }
     127             : 
     128             : 
     129             : static hb_position_t
     130           0 : hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
     131             :                                  void *font_data HB_UNUSED,
     132             :                                  hb_codepoint_t glyph,
     133             :                                  void *user_data HB_UNUSED)
     134             : {
     135           0 :   return font->x_scale;
     136             : }
     137             : static hb_position_t
     138           0 : hb_font_get_glyph_h_advance_parent (hb_font_t *font,
     139             :                                     void *font_data HB_UNUSED,
     140             :                                     hb_codepoint_t glyph,
     141             :                                     void *user_data HB_UNUSED)
     142             : {
     143           0 :   return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
     144             : }
     145             : 
     146             : static hb_position_t
     147           0 : hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
     148             :                                  void *font_data HB_UNUSED,
     149             :                                  hb_codepoint_t glyph,
     150             :                                  void *user_data HB_UNUSED)
     151             : {
     152             :   /* TODO use font_extents.ascender+descender */
     153           0 :   return font->y_scale;
     154             : }
     155             : static hb_position_t
     156           0 : hb_font_get_glyph_v_advance_parent (hb_font_t *font,
     157             :                                     void *font_data HB_UNUSED,
     158             :                                     hb_codepoint_t glyph,
     159             :                                     void *user_data HB_UNUSED)
     160             : {
     161           0 :   return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
     162             : }
     163             : 
     164             : static hb_bool_t
     165           0 : hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
     166             :                                 void *font_data HB_UNUSED,
     167             :                                 hb_codepoint_t glyph,
     168             :                                 hb_position_t *x,
     169             :                                 hb_position_t *y,
     170             :                                 void *user_data HB_UNUSED)
     171             : {
     172           0 :   *x = *y = 0;
     173           0 :   return true;
     174             : }
     175             : static hb_bool_t
     176           0 : hb_font_get_glyph_h_origin_parent (hb_font_t *font,
     177             :                                    void *font_data HB_UNUSED,
     178             :                                    hb_codepoint_t glyph,
     179             :                                    hb_position_t *x,
     180             :                                    hb_position_t *y,
     181             :                                    void *user_data HB_UNUSED)
     182             : {
     183           0 :   hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
     184           0 :   if (ret)
     185           0 :     font->parent_scale_position (x, y);
     186           0 :   return ret;
     187             : }
     188             : 
     189             : static hb_bool_t
     190           0 : hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
     191             :                                 void *font_data HB_UNUSED,
     192             :                                 hb_codepoint_t glyph,
     193             :                                 hb_position_t *x,
     194             :                                 hb_position_t *y,
     195             :                                 void *user_data HB_UNUSED)
     196             : {
     197           0 :   *x = *y = 0;
     198           0 :   return false;
     199             : }
     200             : static hb_bool_t
     201           0 : hb_font_get_glyph_v_origin_parent (hb_font_t *font,
     202             :                                    void *font_data HB_UNUSED,
     203             :                                    hb_codepoint_t glyph,
     204             :                                    hb_position_t *x,
     205             :                                    hb_position_t *y,
     206             :                                    void *user_data HB_UNUSED)
     207             : {
     208           0 :   hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
     209           0 :   if (ret)
     210           0 :     font->parent_scale_position (x, y);
     211           0 :   return ret;
     212             : }
     213             : 
     214             : static hb_position_t
     215           0 : hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
     216             :                                  void *font_data HB_UNUSED,
     217             :                                  hb_codepoint_t left_glyph,
     218             :                                  hb_codepoint_t right_glyph,
     219             :                                  void *user_data HB_UNUSED)
     220             : {
     221           0 :   return 0;
     222             : }
     223             : static hb_position_t
     224           0 : hb_font_get_glyph_h_kerning_parent (hb_font_t *font,
     225             :                                     void *font_data HB_UNUSED,
     226             :                                     hb_codepoint_t left_glyph,
     227             :                                     hb_codepoint_t right_glyph,
     228             :                                     void *user_data HB_UNUSED)
     229             : {
     230           0 :   return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
     231             : }
     232             : 
     233             : static hb_position_t
     234           0 : hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
     235             :                                  void *font_data HB_UNUSED,
     236             :                                  hb_codepoint_t top_glyph,
     237             :                                  hb_codepoint_t bottom_glyph,
     238             :                                  void *user_data HB_UNUSED)
     239             : {
     240           0 :   return 0;
     241             : }
     242             : static hb_position_t
     243           0 : hb_font_get_glyph_v_kerning_parent (hb_font_t *font,
     244             :                                     void *font_data HB_UNUSED,
     245             :                                     hb_codepoint_t top_glyph,
     246             :                                     hb_codepoint_t bottom_glyph,
     247             :                                     void *user_data HB_UNUSED)
     248             : {
     249           0 :   return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
     250             : }
     251             : 
     252             : static hb_bool_t
     253           0 : hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
     254             :                                void *font_data HB_UNUSED,
     255             :                                hb_codepoint_t glyph,
     256             :                                hb_glyph_extents_t *extents,
     257             :                                void *user_data HB_UNUSED)
     258             : {
     259           0 :   memset (extents, 0, sizeof (*extents));
     260           0 :   return false;
     261             : }
     262             : static hb_bool_t
     263           0 : hb_font_get_glyph_extents_parent (hb_font_t *font,
     264             :                                   void *font_data HB_UNUSED,
     265             :                                   hb_codepoint_t glyph,
     266             :                                   hb_glyph_extents_t *extents,
     267             :                                   void *user_data HB_UNUSED)
     268             : {
     269           0 :   hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
     270           0 :   if (ret) {
     271           0 :     font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
     272           0 :     font->parent_scale_distance (&extents->width, &extents->height);
     273             :   }
     274           0 :   return ret;
     275             : }
     276             : 
     277             : static hb_bool_t
     278           0 : hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
     279             :                                      void *font_data HB_UNUSED,
     280             :                                      hb_codepoint_t glyph,
     281             :                                      unsigned int point_index,
     282             :                                      hb_position_t *x,
     283             :                                      hb_position_t *y,
     284             :                                      void *user_data HB_UNUSED)
     285             : {
     286           0 :   *x = *y = 0;
     287           0 :   return false;
     288             : }
     289             : static hb_bool_t
     290           0 : hb_font_get_glyph_contour_point_parent (hb_font_t *font,
     291             :                                         void *font_data HB_UNUSED,
     292             :                                         hb_codepoint_t glyph,
     293             :                                         unsigned int point_index,
     294             :                                         hb_position_t *x,
     295             :                                         hb_position_t *y,
     296             :                                         void *user_data HB_UNUSED)
     297             : {
     298           0 :   hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
     299           0 :   if (ret)
     300           0 :     font->parent_scale_position (x, y);
     301           0 :   return ret;
     302             : }
     303             : 
     304             : static hb_bool_t
     305           0 : hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
     306             :                             void *font_data HB_UNUSED,
     307             :                             hb_codepoint_t glyph,
     308             :                             char *name, unsigned int size,
     309             :                             void *user_data HB_UNUSED)
     310             : {
     311           0 :   if (size) *name = '\0';
     312           0 :   return false;
     313             : }
     314             : static hb_bool_t
     315           0 : hb_font_get_glyph_name_parent (hb_font_t *font,
     316             :                                void *font_data HB_UNUSED,
     317             :                                hb_codepoint_t glyph,
     318             :                                char *name, unsigned int size,
     319             :                                void *user_data HB_UNUSED)
     320             : {
     321           0 :   return font->parent->get_glyph_name (glyph, name, size);
     322             : }
     323             : 
     324             : static hb_bool_t
     325           0 : hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
     326             :                                  void *font_data HB_UNUSED,
     327             :                                  const char *name, int len, /* -1 means nul-terminated */
     328             :                                  hb_codepoint_t *glyph,
     329             :                                  void *user_data HB_UNUSED)
     330             : {
     331           0 :   *glyph = 0;
     332           0 :   return false;
     333             : }
     334             : static hb_bool_t
     335           0 : hb_font_get_glyph_from_name_parent (hb_font_t *font,
     336             :                                     void *font_data HB_UNUSED,
     337             :                                     const char *name, int len, /* -1 means nul-terminated */
     338             :                                     hb_codepoint_t *glyph,
     339             :                                     void *user_data HB_UNUSED)
     340             : {
     341           0 :   return font->parent->get_glyph_from_name (name, len, glyph);
     342             : }
     343             : 
     344             : static const hb_font_funcs_t _hb_font_funcs_nil = {
     345             :   HB_OBJECT_HEADER_STATIC,
     346             : 
     347             :   true, /* immutable */
     348             : 
     349             :   {
     350             : #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
     351             :     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     352             : #undef HB_FONT_FUNC_IMPLEMENT
     353             :   },
     354             :   {
     355             : #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
     356             :     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     357             : #undef HB_FONT_FUNC_IMPLEMENT
     358             :   },
     359             :   {
     360             :     {
     361             : #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
     362             :       HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     363             : #undef HB_FONT_FUNC_IMPLEMENT
     364             :     }
     365             :   }
     366             : };
     367             : static const hb_font_funcs_t _hb_font_funcs_parent = {
     368             :   HB_OBJECT_HEADER_STATIC,
     369             : 
     370             :   true, /* immutable */
     371             : 
     372             :   {
     373             : #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
     374             :     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     375             : #undef HB_FONT_FUNC_IMPLEMENT
     376             :   },
     377             :   {
     378             : #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
     379             :     HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     380             : #undef HB_FONT_FUNC_IMPLEMENT
     381             :   },
     382             :   {
     383             :     {
     384             : #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
     385             :       HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     386             : #undef HB_FONT_FUNC_IMPLEMENT
     387             :     }
     388             :   }
     389             : };
     390             : 
     391             : 
     392             : /**
     393             :  * hb_font_funcs_create: (Xconstructor)
     394             :  *
     395             :  * 
     396             :  *
     397             :  * Return value: (transfer full): 
     398             :  *
     399             :  * Since: 0.9.2
     400             :  **/
     401             : hb_font_funcs_t *
     402           2 : hb_font_funcs_create (void)
     403             : {
     404             :   hb_font_funcs_t *ffuncs;
     405             : 
     406           2 :   if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
     407           0 :     return hb_font_funcs_get_empty ();
     408             : 
     409           2 :   ffuncs->get = _hb_font_funcs_parent.get;
     410             : 
     411           2 :   return ffuncs;
     412             : }
     413             : 
     414             : /**
     415             :  * hb_font_funcs_get_empty:
     416             :  *
     417             :  * 
     418             :  *
     419             :  * Return value: (transfer full): 
     420             :  *
     421             :  * Since: 0.9.2
     422             :  **/
     423             : hb_font_funcs_t *
     424           2 : hb_font_funcs_get_empty (void)
     425             : {
     426           2 :   return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
     427             : }
     428             : 
     429             : /**
     430             :  * hb_font_funcs_reference: (skip)
     431             :  * @ffuncs: font functions.
     432             :  *
     433             :  * 
     434             :  *
     435             :  * Return value: 
     436             :  *
     437             :  * Since: 0.9.2
     438             :  **/
     439             : hb_font_funcs_t *
     440           2 : hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
     441             : {
     442           2 :   return hb_object_reference (ffuncs);
     443             : }
     444             : 
     445             : /**
     446             :  * hb_font_funcs_destroy: (skip)
     447             :  * @ffuncs: font functions.
     448             :  *
     449             :  * 
     450             :  *
     451             :  * Since: 0.9.2
     452             :  **/
     453             : void
     454           2 : hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
     455             : {
     456           2 :   if (!hb_object_destroy (ffuncs)) return;
     457             : 
     458             : #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
     459             :   ffuncs->destroy.name (ffuncs->user_data.name);
     460           0 :   HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     461             : #undef HB_FONT_FUNC_IMPLEMENT
     462             : 
     463           0 :   free (ffuncs);
     464             : }
     465             : 
     466             : /**
     467             :  * hb_font_funcs_set_user_data: (skip)
     468             :  * @ffuncs: font functions.
     469             :  * @key: 
     470             :  * @data: 
     471             :  * @destroy: 
     472             :  * @replace: 
     473             :  *
     474             :  * 
     475             :  *
     476             :  * Return value: 
     477             :  *
     478             :  * Since: 0.9.2
     479             :  **/
     480             : hb_bool_t
     481           0 : hb_font_funcs_set_user_data (hb_font_funcs_t    *ffuncs,
     482             :                              hb_user_data_key_t *key,
     483             :                              void *              data,
     484             :                              hb_destroy_func_t   destroy,
     485             :                              hb_bool_t           replace)
     486             : {
     487           0 :   return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
     488             : }
     489             : 
     490             : /**
     491             :  * hb_font_funcs_get_user_data: (skip)
     492             :  * @ffuncs: font functions.
     493             :  * @key: 
     494             :  *
     495             :  * 
     496             :  *
     497             :  * Return value: (transfer none): 
     498             :  *
     499             :  * Since: 0.9.2
     500             :  **/
     501             : void *
     502           0 : hb_font_funcs_get_user_data (hb_font_funcs_t    *ffuncs,
     503             :                              hb_user_data_key_t *key)
     504             : {
     505           0 :   return hb_object_get_user_data (ffuncs, key);
     506             : }
     507             : 
     508             : 
     509             : /**
     510             :  * hb_font_funcs_make_immutable:
     511             :  * @ffuncs: font functions.
     512             :  *
     513             :  * 
     514             :  *
     515             :  * Since: 0.9.2
     516             :  **/
     517             : void
     518           0 : hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
     519             : {
     520           0 :   if (unlikely (hb_object_is_inert (ffuncs)))
     521           0 :     return;
     522             : 
     523           0 :   ffuncs->immutable = true;
     524             : }
     525             : 
     526             : /**
     527             :  * hb_font_funcs_is_immutable:
     528             :  * @ffuncs: font functions.
     529             :  *
     530             :  * 
     531             :  *
     532             :  * Return value: 
     533             :  *
     534             :  * Since: 0.9.2
     535             :  **/
     536             : hb_bool_t
     537           0 : hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
     538             : {
     539           0 :   return ffuncs->immutable;
     540             : }
     541             : 
     542             : 
     543             : #define HB_FONT_FUNC_IMPLEMENT(name) \
     544             :                                                                          \
     545             : void                                                                     \
     546             : hb_font_funcs_set_##name##_func (hb_font_funcs_t             *ffuncs,    \
     547             :                                  hb_font_get_##name##_func_t  func,      \
     548             :                                  void                        *user_data, \
     549             :                                  hb_destroy_func_t            destroy)   \
     550             : {                                                                        \
     551             :   if (ffuncs->immutable) {                                               \
     552             :     if (destroy)                                                         \
     553             :       destroy (user_data);                                               \
     554             :     return;                                                              \
     555             :   }                                                                      \
     556             :                                                                          \
     557             :   if (ffuncs->destroy.name)                                              \
     558             :     ffuncs->destroy.name (ffuncs->user_data.name);                       \
     559             :                                                                          \
     560             :   if (func) {                                                            \
     561             :     ffuncs->get.f.name = func;                                           \
     562             :     ffuncs->user_data.name = user_data;                                  \
     563             :     ffuncs->destroy.name = destroy;                                      \
     564             :   } else {                                                               \
     565             :     ffuncs->get.f.name = hb_font_get_##name##_parent;                    \
     566             :     ffuncs->user_data.name = NULL;                                       \
     567             :     ffuncs->destroy.name = NULL;                                         \
     568             :   }                                                                      \
     569             : }
     570             : 
     571          16 : HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
     572             : #undef HB_FONT_FUNC_IMPLEMENT
     573             : 
     574             : bool
     575         102 : hb_font_t::has_func (unsigned int i)
     576             : {
     577         102 :   if (parent && parent != hb_font_get_empty () && parent->has_func (i))
     578           0 :     return true;
     579         102 :   return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
     580             : }
     581             : 
     582             : /* Public getters */
     583             : 
     584             : /**
     585             :  * hb_font_get_h_extents:
     586             :  * @font: a font.
     587             :  * @extents: (out):
     588             :  *
     589             :  *
     590             :  *
     591             :  * Return value:
     592             :  *
     593             :  * Since: 1.1.3
     594             :  **/
     595             : hb_bool_t
     596           0 : hb_font_get_h_extents (hb_font_t *font,
     597             :                        hb_font_extents_t *extents)
     598             : {
     599           0 :   return font->get_font_h_extents (extents);
     600             : }
     601             : 
     602             : /**
     603             :  * hb_font_get_v_extents:
     604             :  * @font: a font.
     605             :  * @extents: (out):
     606             :  *
     607             :  *
     608             :  *
     609             :  * Return value:
     610             :  *
     611             :  * Since: 1.1.3
     612             :  **/
     613             : hb_bool_t
     614           0 : hb_font_get_v_extents (hb_font_t *font,
     615             :                        hb_font_extents_t *extents)
     616             : {
     617           0 :   return font->get_font_v_extents (extents);
     618             : }
     619             : 
     620             : /**
     621             :  * hb_font_get_glyph:
     622             :  * @font: a font.
     623             :  * @unicode: 
     624             :  * @variation_selector: 
     625             :  * @glyph: (out): 
     626             :  *
     627             :  * 
     628             :  *
     629             :  * Return value: 
     630             :  *
     631             :  * Since: 0.9.2
     632             :  **/
     633             : hb_bool_t
     634           0 : hb_font_get_glyph (hb_font_t *font,
     635             :                    hb_codepoint_t unicode, hb_codepoint_t variation_selector,
     636             :                    hb_codepoint_t *glyph)
     637             : {
     638           0 :   if (unlikely (variation_selector))
     639           0 :     return font->get_variation_glyph (unicode, variation_selector, glyph);
     640           0 :   return font->get_nominal_glyph (unicode, glyph);
     641             : }
     642             : 
     643             : /**
     644             :  * hb_font_get_nominal_glyph:
     645             :  * @font: a font.
     646             :  * @unicode: 
     647             :  * @glyph: (out): 
     648             :  *
     649             :  * 
     650             :  *
     651             :  * Return value: 
     652             :  *
     653             :  * Since: 1.2.3
     654             :  **/
     655             : hb_bool_t
     656           0 : hb_font_get_nominal_glyph (hb_font_t *font,
     657             :                            hb_codepoint_t unicode,
     658             :                            hb_codepoint_t *glyph)
     659             : {
     660           0 :   return font->get_nominal_glyph (unicode, glyph);
     661             : }
     662             : 
     663             : /**
     664             :  * hb_font_get_variation_glyph:
     665             :  * @font: a font.
     666             :  * @unicode: 
     667             :  * @variation_selector: 
     668             :  * @glyph: (out): 
     669             :  *
     670             :  * 
     671             :  *
     672             :  * Return value: 
     673             :  *
     674             :  * Since: 1.2.3
     675             :  **/
     676             : hb_bool_t
     677           0 : hb_font_get_variation_glyph (hb_font_t *font,
     678             :                              hb_codepoint_t unicode, hb_codepoint_t variation_selector,
     679             :                              hb_codepoint_t *glyph)
     680             : {
     681           0 :   return font->get_variation_glyph (unicode, variation_selector, glyph);
     682             : }
     683             : 
     684             : /**
     685             :  * hb_font_get_glyph_h_advance:
     686             :  * @font: a font.
     687             :  * @glyph: 
     688             :  *
     689             :  * 
     690             :  *
     691             :  * Return value: 
     692             :  *
     693             :  * Since: 0.9.2
     694             :  **/
     695             : hb_position_t
     696           0 : hb_font_get_glyph_h_advance (hb_font_t *font,
     697             :                              hb_codepoint_t glyph)
     698             : {
     699           0 :   return font->get_glyph_h_advance (glyph);
     700             : }
     701             : 
     702             : /**
     703             :  * hb_font_get_glyph_v_advance:
     704             :  * @font: a font.
     705             :  * @glyph: 
     706             :  *
     707             :  * 
     708             :  *
     709             :  * Return value: 
     710             :  *
     711             :  * Since: 0.9.2
     712             :  **/
     713             : hb_position_t
     714           0 : hb_font_get_glyph_v_advance (hb_font_t *font,
     715             :                              hb_codepoint_t glyph)
     716             : {
     717           0 :   return font->get_glyph_v_advance (glyph);
     718             : }
     719             : 
     720             : /**
     721             :  * hb_font_get_glyph_h_origin:
     722             :  * @font: a font.
     723             :  * @glyph: 
     724             :  * @x: (out): 
     725             :  * @y: (out): 
     726             :  *
     727             :  * 
     728             :  *
     729             :  * Return value: 
     730             :  *
     731             :  * Since: 0.9.2
     732             :  **/
     733             : hb_bool_t
     734           0 : hb_font_get_glyph_h_origin (hb_font_t *font,
     735             :                             hb_codepoint_t glyph,
     736             :                             hb_position_t *x, hb_position_t *y)
     737             : {
     738           0 :   return font->get_glyph_h_origin (glyph, x, y);
     739             : }
     740             : 
     741             : /**
     742             :  * hb_font_get_glyph_v_origin:
     743             :  * @font: a font.
     744             :  * @glyph: 
     745             :  * @x: (out): 
     746             :  * @y: (out): 
     747             :  *
     748             :  * 
     749             :  *
     750             :  * Return value: 
     751             :  *
     752             :  * Since: 0.9.2
     753             :  **/
     754             : hb_bool_t
     755           0 : hb_font_get_glyph_v_origin (hb_font_t *font,
     756             :                             hb_codepoint_t glyph,
     757             :                             hb_position_t *x, hb_position_t *y)
     758             : {
     759           0 :   return font->get_glyph_v_origin (glyph, x, y);
     760             : }
     761             : 
     762             : /**
     763             :  * hb_font_get_glyph_h_kerning:
     764             :  * @font: a font.
     765             :  * @left_glyph: 
     766             :  * @right_glyph: 
     767             :  *
     768             :  * 
     769             :  *
     770             :  * Return value: 
     771             :  *
     772             :  * Since: 0.9.2
     773             :  **/
     774             : hb_position_t
     775           0 : hb_font_get_glyph_h_kerning (hb_font_t *font,
     776             :                              hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
     777             : {
     778           0 :   return font->get_glyph_h_kerning (left_glyph, right_glyph);
     779             : }
     780             : 
     781             : /**
     782             :  * hb_font_get_glyph_v_kerning:
     783             :  * @font: a font.
     784             :  * @top_glyph: 
     785             :  * @bottom_glyph: 
     786             :  *
     787             :  * 
     788             :  *
     789             :  * Return value: 
     790             :  *
     791             :  * Since: 0.9.2
     792             :  **/
     793             : hb_position_t
     794           0 : hb_font_get_glyph_v_kerning (hb_font_t *font,
     795             :                              hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
     796             : {
     797           0 :   return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
     798             : }
     799             : 
     800             : /**
     801             :  * hb_font_get_glyph_extents:
     802             :  * @font: a font.
     803             :  * @glyph: 
     804             :  * @extents: (out): 
     805             :  *
     806             :  * 
     807             :  *
     808             :  * Return value: 
     809             :  *
     810             :  * Since: 0.9.2
     811             :  **/
     812             : hb_bool_t
     813           0 : hb_font_get_glyph_extents (hb_font_t *font,
     814             :                            hb_codepoint_t glyph,
     815             :                            hb_glyph_extents_t *extents)
     816             : {
     817           0 :   return font->get_glyph_extents (glyph, extents);
     818             : }
     819             : 
     820             : /**
     821             :  * hb_font_get_glyph_contour_point:
     822             :  * @font: a font.
     823             :  * @glyph: 
     824             :  * @point_index: 
     825             :  * @x: (out): 
     826             :  * @y: (out): 
     827             :  *
     828             :  * 
     829             :  *
     830             :  * Return value: 
     831             :  *
     832             :  * Since: 0.9.2
     833             :  **/
     834             : hb_bool_t
     835           0 : hb_font_get_glyph_contour_point (hb_font_t *font,
     836             :                                  hb_codepoint_t glyph, unsigned int point_index,
     837             :                                  hb_position_t *x, hb_position_t *y)
     838             : {
     839           0 :   return font->get_glyph_contour_point (glyph, point_index, x, y);
     840             : }
     841             : 
     842             : /**
     843             :  * hb_font_get_glyph_name:
     844             :  * @font: a font.
     845             :  * @glyph: 
     846             :  * @name: (array length=size): 
     847             :  * @size: 
     848             :  *
     849             :  * 
     850             :  *
     851             :  * Return value: 
     852             :  *
     853             :  * Since: 0.9.2
     854             :  **/
     855             : hb_bool_t
     856           0 : hb_font_get_glyph_name (hb_font_t *font,
     857             :                         hb_codepoint_t glyph,
     858             :                         char *name, unsigned int size)
     859             : {
     860           0 :   return font->get_glyph_name (glyph, name, size);
     861             : }
     862             : 
     863             : /**
     864             :  * hb_font_get_glyph_from_name:
     865             :  * @font: a font.
     866             :  * @name: (array length=len): 
     867             :  * @len: 
     868             :  * @glyph: (out): 
     869             :  *
     870             :  * 
     871             :  *
     872             :  * Return value: 
     873             :  *
     874             :  * Since: 0.9.2
     875             :  **/
     876             : hb_bool_t
     877           0 : hb_font_get_glyph_from_name (hb_font_t *font,
     878             :                              const char *name, int len, /* -1 means nul-terminated */
     879             :                              hb_codepoint_t *glyph)
     880             : {
     881           0 :   return font->get_glyph_from_name (name, len, glyph);
     882             : }
     883             : 
     884             : 
     885             : /* A bit higher-level, and with fallback */
     886             : 
     887             : /**
     888             :  * hb_font_get_extents_for_direction:
     889             :  * @font: a font.
     890             :  * @direction:
     891             :  * @extents:
     892             :  *
     893             :  *
     894             :  *
     895             :  * Since: 1.1.3
     896             :  **/
     897             : void
     898           0 : hb_font_get_extents_for_direction (hb_font_t *font,
     899             :                                    hb_direction_t direction,
     900             :                                    hb_font_extents_t *extents)
     901             : {
     902           0 :   return font->get_extents_for_direction (direction, extents);
     903             : }
     904             : /**
     905             :  * hb_font_get_glyph_advance_for_direction:
     906             :  * @font: a font.
     907             :  * @glyph: 
     908             :  * @direction: 
     909             :  * @x: (out): 
     910             :  * @y: (out): 
     911             :  *
     912             :  * 
     913             :  *
     914             :  * Since: 0.9.2
     915             :  **/
     916             : void
     917           0 : hb_font_get_glyph_advance_for_direction (hb_font_t *font,
     918             :                                          hb_codepoint_t glyph,
     919             :                                          hb_direction_t direction,
     920             :                                          hb_position_t *x, hb_position_t *y)
     921             : {
     922           0 :   return font->get_glyph_advance_for_direction (glyph, direction, x, y);
     923             : }
     924             : 
     925             : /**
     926             :  * hb_font_get_glyph_origin_for_direction:
     927             :  * @font: a font.
     928             :  * @glyph: 
     929             :  * @direction: 
     930             :  * @x: (out): 
     931             :  * @y: (out): 
     932             :  *
     933             :  * 
     934             :  *
     935             :  * Since: 0.9.2
     936             :  **/
     937             : void
     938           0 : hb_font_get_glyph_origin_for_direction (hb_font_t *font,
     939             :                                         hb_codepoint_t glyph,
     940             :                                         hb_direction_t direction,
     941             :                                         hb_position_t *x, hb_position_t *y)
     942             : {
     943           0 :   return font->get_glyph_origin_for_direction (glyph, direction, x, y);
     944             : }
     945             : 
     946             : /**
     947             :  * hb_font_add_glyph_origin_for_direction:
     948             :  * @font: a font.
     949             :  * @glyph: 
     950             :  * @direction: 
     951             :  * @x: (out): 
     952             :  * @y: (out): 
     953             :  *
     954             :  * 
     955             :  *
     956             :  * Since: 0.9.2
     957             :  **/
     958             : void
     959           0 : hb_font_add_glyph_origin_for_direction (hb_font_t *font,
     960             :                                         hb_codepoint_t glyph,
     961             :                                         hb_direction_t direction,
     962             :                                         hb_position_t *x, hb_position_t *y)
     963             : {
     964           0 :   return font->add_glyph_origin_for_direction (glyph, direction, x, y);
     965             : }
     966             : 
     967             : /**
     968             :  * hb_font_subtract_glyph_origin_for_direction:
     969             :  * @font: a font.
     970             :  * @glyph: 
     971             :  * @direction: 
     972             :  * @x: (out): 
     973             :  * @y: (out): 
     974             :  *
     975             :  * 
     976             :  *
     977             :  * Since: 0.9.2
     978             :  **/
     979             : void
     980           0 : hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
     981             :                                              hb_codepoint_t glyph,
     982             :                                              hb_direction_t direction,
     983             :                                              hb_position_t *x, hb_position_t *y)
     984             : {
     985           0 :   return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
     986             : }
     987             : 
     988             : /**
     989             :  * hb_font_get_glyph_kerning_for_direction:
     990             :  * @font: a font.
     991             :  * @first_glyph: 
     992             :  * @second_glyph: 
     993             :  * @direction: 
     994             :  * @x: (out): 
     995             :  * @y: (out): 
     996             :  *
     997             :  * 
     998             :  *
     999             :  * Since: 0.9.2
    1000             :  **/
    1001             : void
    1002           0 : hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
    1003             :                                          hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
    1004             :                                          hb_direction_t direction,
    1005             :                                          hb_position_t *x, hb_position_t *y)
    1006             : {
    1007           0 :   return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
    1008             : }
    1009             : 
    1010             : /**
    1011             :  * hb_font_get_glyph_extents_for_origin:
    1012             :  * @font: a font.
    1013             :  * @glyph: 
    1014             :  * @direction: 
    1015             :  * @extents: (out): 
    1016             :  *
    1017             :  * 
    1018             :  *
    1019             :  * Return value: 
    1020             :  *
    1021             :  * Since: 0.9.2
    1022             :  **/
    1023             : hb_bool_t
    1024           0 : hb_font_get_glyph_extents_for_origin (hb_font_t *font,
    1025             :                                       hb_codepoint_t glyph,
    1026             :                                       hb_direction_t direction,
    1027             :                                       hb_glyph_extents_t *extents)
    1028             : {
    1029           0 :   return font->get_glyph_extents_for_origin (glyph, direction, extents);
    1030             : }
    1031             : 
    1032             : /**
    1033             :  * hb_font_get_glyph_contour_point_for_origin:
    1034             :  * @font: a font.
    1035             :  * @glyph: 
    1036             :  * @point_index: 
    1037             :  * @direction: 
    1038             :  * @x: (out): 
    1039             :  * @y: (out): 
    1040             :  *
    1041             :  * 
    1042             :  *
    1043             :  * Return value: 
    1044             :  *
    1045             :  * Since: 0.9.2
    1046             :  **/
    1047             : hb_bool_t
    1048           0 : hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
    1049             :                                             hb_codepoint_t glyph, unsigned int point_index,
    1050             :                                             hb_direction_t direction,
    1051             :                                             hb_position_t *x, hb_position_t *y)
    1052             : {
    1053           0 :   return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
    1054             : }
    1055             : 
    1056             : /* Generates gidDDD if glyph has no name. */
    1057             : /**
    1058             :  * hb_font_glyph_to_string:
    1059             :  * @font: a font.
    1060             :  * @glyph: 
    1061             :  * @s: (array length=size): 
    1062             :  * @size: 
    1063             :  *
    1064             :  * 
    1065             :  *
    1066             :  * Since: 0.9.2
    1067             :  **/
    1068             : void
    1069           0 : hb_font_glyph_to_string (hb_font_t *font,
    1070             :                          hb_codepoint_t glyph,
    1071             :                          char *s, unsigned int size)
    1072             : {
    1073           0 :   font->glyph_to_string (glyph, s, size);
    1074           0 : }
    1075             : 
    1076             : /* Parses gidDDD and uniUUUU strings automatically. */
    1077             : /**
    1078             :  * hb_font_glyph_from_string:
    1079             :  * @font: a font.
    1080             :  * @s: (array length=len) (element-type uint8_t): 
    1081             :  * @len: 
    1082             :  * @glyph: (out): 
    1083             :  *
    1084             :  * 
    1085             :  *
    1086             :  * Return value: 
    1087             :  *
    1088             :  * Since: 0.9.2
    1089             :  **/
    1090             : hb_bool_t
    1091           0 : hb_font_glyph_from_string (hb_font_t *font,
    1092             :                            const char *s, int len, /* -1 means nul-terminated */
    1093             :                            hb_codepoint_t *glyph)
    1094             : {
    1095           0 :   return font->glyph_from_string (s, len, glyph);
    1096             : }
    1097             : 
    1098             : 
    1099             : /*
    1100             :  * hb_font_t
    1101             :  */
    1102             : 
    1103             : /**
    1104             :  * hb_font_create: (Xconstructor)
    1105             :  * @face: a face.
    1106             :  *
    1107             :  * 
    1108             :  *
    1109             :  * Return value: (transfer full): 
    1110             :  *
    1111             :  * Since: 0.9.2
    1112             :  **/
    1113             : hb_font_t *
    1114           2 : hb_font_create (hb_face_t *face)
    1115             : {
    1116             :   hb_font_t *font;
    1117             : 
    1118           2 :   if (unlikely (!face))
    1119           0 :     face = hb_face_get_empty ();
    1120           2 :   if (!(font = hb_object_create<hb_font_t> ()))
    1121           0 :     return hb_font_get_empty ();
    1122             : 
    1123           2 :   hb_face_make_immutable (face);
    1124           2 :   font->parent = hb_font_get_empty ();
    1125           2 :   font->face = hb_face_reference (face);
    1126           2 :   font->klass = hb_font_funcs_get_empty ();
    1127             : 
    1128           2 :   font->x_scale = font->y_scale = hb_face_get_upem (face);
    1129             : 
    1130           2 :   return font;
    1131             : }
    1132             : 
    1133             : /**
    1134             :  * hb_font_create_sub_font:
    1135             :  * @parent: parent font.
    1136             :  *
    1137             :  * 
    1138             :  *
    1139             :  * Return value: (transfer full): 
    1140             :  *
    1141             :  * Since: 0.9.2
    1142             :  **/
    1143             : hb_font_t *
    1144           0 : hb_font_create_sub_font (hb_font_t *parent)
    1145             : {
    1146           0 :   if (unlikely (!parent))
    1147           0 :     parent = hb_font_get_empty ();
    1148             : 
    1149           0 :   hb_font_t *font = hb_font_create (parent->face);
    1150             : 
    1151           0 :   if (unlikely (hb_object_is_inert (font)))
    1152           0 :     return font;
    1153             : 
    1154           0 :   font->parent = hb_font_reference (parent);
    1155             : 
    1156           0 :   font->x_scale = parent->x_scale;
    1157           0 :   font->y_scale = parent->y_scale;
    1158           0 :   font->x_ppem = parent->x_ppem;
    1159           0 :   font->y_ppem = parent->y_ppem;
    1160             : 
    1161             :   /* TODO: copy variation coordinates. */
    1162             : 
    1163           0 :   return font;
    1164             : }
    1165             : 
    1166             : /**
    1167             :  * hb_font_get_empty:
    1168             :  *
    1169             :  * 
    1170             :  *
    1171             :  * Return value: (transfer full)
    1172             :  *
    1173             :  * Since: 0.9.2
    1174             :  **/
    1175             : hb_font_t *
    1176         104 : hb_font_get_empty (void)
    1177             : {
    1178             :   static const hb_font_t _hb_font_nil = {
    1179             :     HB_OBJECT_HEADER_STATIC,
    1180             : 
    1181             :     true, /* immutable */
    1182             : 
    1183             :     NULL, /* parent */
    1184             :     const_cast<hb_face_t *> (&_hb_face_nil),
    1185             : 
    1186             :     1000, /* x_scale */
    1187             :     1000, /* y_scale */
    1188             : 
    1189             :     0, /* x_ppem */
    1190             :     0, /* y_ppem */
    1191             : 
    1192             :     0, /* num_coords */
    1193             :     NULL, /* coords */
    1194             : 
    1195             :     const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
    1196             :     NULL, /* user_data */
    1197             :     NULL, /* destroy */
    1198             : 
    1199             :     hb_font_t::NOTHING, /* dirty */
    1200             : 
    1201             :     {
    1202             : #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
    1203             : #include "hb-shaper-list.hh"
    1204             : #undef HB_SHAPER_IMPLEMENT
    1205             :     }
    1206             :   };
    1207             : 
    1208         104 :   return const_cast<hb_font_t *> (&_hb_font_nil);
    1209             : }
    1210             : 
    1211             : /**
    1212             :  * hb_font_reference: (skip)
    1213             :  * @font: a font.
    1214             :  *
    1215             :  * 
    1216             :  *
    1217             :  * Return value: (transfer full): 
    1218             :  *
    1219             :  * Since: 0.9.2
    1220             :  **/
    1221             : hb_font_t *
    1222           0 : hb_font_reference (hb_font_t *font)
    1223             : {
    1224           0 :   return hb_object_reference (font);
    1225             : }
    1226             : 
    1227             : /**
    1228             :  * hb_font_destroy: (skip)
    1229             :  * @font: a font.
    1230             :  *
    1231             :  * 
    1232             :  *
    1233             :  * Since: 0.9.2
    1234             :  **/
    1235             : void
    1236           0 : hb_font_destroy (hb_font_t *font)
    1237             : {
    1238           0 :   if (!hb_object_destroy (font)) return;
    1239             : 
    1240             : #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
    1241             : #include "hb-shaper-list.hh"
    1242             : #undef HB_SHAPER_IMPLEMENT
    1243             : 
    1244           0 :   if (font->destroy)
    1245           0 :     font->destroy (font->user_data);
    1246             : 
    1247           0 :   hb_font_destroy (font->parent);
    1248           0 :   hb_face_destroy (font->face);
    1249           0 :   hb_font_funcs_destroy (font->klass);
    1250             : 
    1251           0 :   free (font->coords);
    1252             : 
    1253           0 :   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           0 : hb_font_set_user_data (hb_font_t          *font,
    1272             :                        hb_user_data_key_t *key,
    1273             :                        void *              data,
    1274             :                        hb_destroy_func_t   destroy,
    1275             :                        hb_bool_t           replace)
    1276             : {
    1277           0 :   return hb_object_set_user_data (font, key, data, destroy, replace);
    1278             : }
    1279             : 
    1280             : /**
    1281             :  * hb_font_get_user_data: (skip)
    1282             :  * @font: a font.
    1283             :  * @key: 
    1284             :  *
    1285             :  * 
    1286             :  *
    1287             :  * Return value: (transfer none): 
    1288             :  *
    1289             :  * Since: 0.9.2
    1290             :  **/
    1291             : void *
    1292           0 : hb_font_get_user_data (hb_font_t          *font,
    1293             :                        hb_user_data_key_t *key)
    1294             : {
    1295           0 :   return hb_object_get_user_data (font, key);
    1296             : }
    1297             : 
    1298             : /**
    1299             :  * hb_font_make_immutable:
    1300             :  * @font: a font.
    1301             :  *
    1302             :  * 
    1303             :  *
    1304             :  * Since: 0.9.2
    1305             :  **/
    1306             : void
    1307           0 : hb_font_make_immutable (hb_font_t *font)
    1308             : {
    1309           0 :   if (unlikely (hb_object_is_inert (font)))
    1310           0 :     return;
    1311             : 
    1312           0 :   if (font->parent)
    1313           0 :     hb_font_make_immutable (font->parent);
    1314             : 
    1315           0 :   font->immutable = true;
    1316             : }
    1317             : 
    1318             : /**
    1319             :  * hb_font_is_immutable:
    1320             :  * @font: a font.
    1321             :  *
    1322             :  * 
    1323             :  *
    1324             :  * Return value: 
    1325             :  *
    1326             :  * Since: 0.9.2
    1327             :  **/
    1328             : hb_bool_t
    1329           0 : hb_font_is_immutable (hb_font_t *font)
    1330             : {
    1331           0 :   return font->immutable;
    1332             : }
    1333             : 
    1334             : /**
    1335             :  * hb_font_set_parent:
    1336             :  * @font: a font.
    1337             :  * @parent: new parent.
    1338             :  *
    1339             :  * Sets parent font of @font.
    1340             :  *
    1341             :  * Since: 1.0.5
    1342             :  **/
    1343             : void
    1344           0 : hb_font_set_parent (hb_font_t *font,
    1345             :                     hb_font_t *parent)
    1346             : {
    1347           0 :   if (font->immutable)
    1348           0 :     return;
    1349             : 
    1350           0 :   if (!parent)
    1351           0 :     parent = hb_font_get_empty ();
    1352             : 
    1353           0 :   if (parent == font->parent)
    1354           0 :     return;
    1355             : 
    1356           0 :   font->dirty |= font->PARENT;
    1357             : 
    1358           0 :   hb_font_t *old = font->parent;
    1359             : 
    1360           0 :   font->parent = hb_font_reference (parent);
    1361             : 
    1362           0 :   hb_font_destroy (old);
    1363             : }
    1364             : 
    1365             : /**
    1366             :  * hb_font_get_parent:
    1367             :  * @font: a font.
    1368             :  *
    1369             :  * 
    1370             :  *
    1371             :  * Return value: (transfer none): 
    1372             :  *
    1373             :  * Since: 0.9.2
    1374             :  **/
    1375             : hb_font_t *
    1376           0 : hb_font_get_parent (hb_font_t *font)
    1377             : {
    1378           0 :   return font->parent;
    1379             : }
    1380             : 
    1381             : /**
    1382             :  * hb_font_set_face:
    1383             :  * @font: a font.
    1384             :  * @face: new face.
    1385             :  *
    1386             :  * Sets font-face of @font.
    1387             :  *
    1388             :  * Since: 1.4.3
    1389             :  **/
    1390             : void
    1391           0 : hb_font_set_face (hb_font_t *font,
    1392             :                   hb_face_t *face)
    1393             : {
    1394           0 :   if (font->immutable)
    1395           0 :     return;
    1396             : 
    1397           0 :   if (unlikely (!face))
    1398           0 :     face = hb_face_get_empty ();
    1399             : 
    1400           0 :   if (font->face == face)
    1401           0 :     return;
    1402             : 
    1403           0 :   font->dirty |= font->FACE;
    1404             : 
    1405           0 :   hb_face_t *old = font->face;
    1406             : 
    1407           0 :   font->face = hb_face_reference (face);
    1408             : 
    1409           0 :   hb_face_destroy (old);
    1410             : }
    1411             : 
    1412             : /**
    1413             :  * hb_font_get_face:
    1414             :  * @font: a font.
    1415             :  *
    1416             :  * 
    1417             :  *
    1418             :  * Return value: (transfer none): 
    1419             :  *
    1420             :  * Since: 0.9.2
    1421             :  **/
    1422             : hb_face_t *
    1423           0 : hb_font_get_face (hb_font_t *font)
    1424             : {
    1425           0 :   return font->face;
    1426             : }
    1427             : 
    1428             : 
    1429             : /**
    1430             :  * hb_font_set_funcs:
    1431             :  * @font: a font.
    1432             :  * @klass: (closure font_data) (destroy destroy) (scope notified):
    1433             :  * @font_data: 
    1434             :  * @destroy: 
    1435             :  *
    1436             :  * 
    1437             :  *
    1438             :  * Since: 0.9.2
    1439             :  **/
    1440             : void
    1441           2 : hb_font_set_funcs (hb_font_t         *font,
    1442             :                    hb_font_funcs_t   *klass,
    1443             :                    void              *font_data,
    1444             :                    hb_destroy_func_t  destroy)
    1445             : {
    1446           2 :   if (font->immutable) {
    1447           0 :     if (destroy)
    1448           0 :       destroy (font_data);
    1449           0 :     return;
    1450             :   }
    1451             : 
    1452           2 :   if (font->destroy)
    1453           0 :     font->destroy (font->user_data);
    1454             : 
    1455           2 :   if (!klass)
    1456           0 :     klass = hb_font_funcs_get_empty ();
    1457             : 
    1458           2 :   font->dirty |= font->FUNCS;
    1459             : 
    1460           2 :   hb_font_funcs_reference (klass);
    1461           2 :   hb_font_funcs_destroy (font->klass);
    1462           2 :   font->klass = klass;
    1463           2 :   font->user_data = font_data;
    1464           2 :   font->destroy = destroy;
    1465             : }
    1466             : 
    1467             : /**
    1468             :  * hb_font_set_funcs_data:
    1469             :  * @font: a font.
    1470             :  * @font_data: (destroy destroy) (scope notified):
    1471             :  * @destroy: 
    1472             :  *
    1473             :  * 
    1474             :  *
    1475             :  * Since: 0.9.2
    1476             :  **/
    1477             : void
    1478           0 : hb_font_set_funcs_data (hb_font_t         *font,
    1479             :                         void              *font_data,
    1480             :                         hb_destroy_func_t  destroy)
    1481             : {
    1482             :   /* Destroy user_data? */
    1483           0 :   if (font->immutable) {
    1484           0 :     if (destroy)
    1485           0 :       destroy (font_data);
    1486           0 :     return;
    1487             :   }
    1488             : 
    1489           0 :   if (font->destroy)
    1490           0 :     font->destroy (font->user_data);
    1491             : 
    1492           0 :   font->user_data = font_data;
    1493           0 :   font->destroy = destroy;
    1494             : }
    1495             : 
    1496             : 
    1497             : /**
    1498             :  * hb_font_set_scale:
    1499             :  * @font: a font.
    1500             :  * @x_scale: 
    1501             :  * @y_scale: 
    1502             :  *
    1503             :  * 
    1504             :  *
    1505             :  * Since: 0.9.2
    1506             :  **/
    1507             : void
    1508           2 : hb_font_set_scale (hb_font_t *font,
    1509             :                    int x_scale,
    1510             :                    int y_scale)
    1511             : {
    1512           2 :   if (font->immutable)
    1513           0 :     return;
    1514             : 
    1515           2 :   if (font->x_scale == x_scale && font->y_scale == y_scale)
    1516           0 :     return;
    1517             : 
    1518           2 :   font->dirty |= font->SCALE;
    1519             : 
    1520           2 :   font->x_scale = x_scale;
    1521           2 :   font->y_scale = y_scale;
    1522             : }
    1523             : 
    1524             : /**
    1525             :  * hb_font_get_scale:
    1526             :  * @font: a font.
    1527             :  * @x_scale: (out): 
    1528             :  * @y_scale: (out): 
    1529             :  *
    1530             :  * 
    1531             :  *
    1532             :  * Since: 0.9.2
    1533             :  **/
    1534             : void
    1535           0 : hb_font_get_scale (hb_font_t *font,
    1536             :                    int *x_scale,
    1537             :                    int *y_scale)
    1538             : {
    1539           0 :   if (x_scale) *x_scale = font->x_scale;
    1540           0 :   if (y_scale) *y_scale = font->y_scale;
    1541           0 : }
    1542             : 
    1543             : /**
    1544             :  * hb_font_set_ppem:
    1545             :  * @font: a font.
    1546             :  * @x_ppem: 
    1547             :  * @y_ppem: 
    1548             :  *
    1549             :  * 
    1550             :  *
    1551             :  * Since: 0.9.2
    1552             :  **/
    1553             : void
    1554           2 : hb_font_set_ppem (hb_font_t *font,
    1555             :                   unsigned int x_ppem,
    1556             :                   unsigned int y_ppem)
    1557             : {
    1558           2 :   if (font->immutable)
    1559           0 :     return;
    1560             : 
    1561           2 :   if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
    1562           0 :     return;
    1563             : 
    1564           2 :   font->dirty |= font->PPEM;
    1565             : 
    1566           2 :   font->x_ppem = x_ppem;
    1567           2 :   font->y_ppem = y_ppem;
    1568             : }
    1569             : 
    1570             : /**
    1571             :  * hb_font_get_ppem:
    1572             :  * @font: a font.
    1573             :  * @x_ppem: (out): 
    1574             :  * @y_ppem: (out): 
    1575             :  *
    1576             :  * 
    1577             :  *
    1578             :  * Since: 0.9.2
    1579             :  **/
    1580             : void
    1581           0 : hb_font_get_ppem (hb_font_t *font,
    1582             :                   unsigned int *x_ppem,
    1583             :                   unsigned int *y_ppem)
    1584             : {
    1585           0 :   if (x_ppem) *x_ppem = font->x_ppem;
    1586           0 :   if (y_ppem) *y_ppem = font->y_ppem;
    1587           0 : }
    1588             : 
    1589             : /*
    1590             :  * Variations
    1591             :  */
    1592             : 
    1593             : static void
    1594           0 : _hb_font_adopt_var_coords_normalized (hb_font_t *font,
    1595             :                                       int *coords, /* 2.14 normalized */
    1596             :                                       unsigned int coords_length)
    1597             : {
    1598           0 :   if (font->num_coords == coords_length &&
    1599           0 :       (coords_length == 0 ||
    1600           0 :        0 == memcmp (font->coords, coords, coords_length * sizeof (coords[0]))))
    1601             :   {
    1602           0 :     free (coords);
    1603           0 :     return;
    1604             :   }
    1605             : 
    1606           0 :   font->dirty |= font->VARIATIONS;
    1607             : 
    1608           0 :   free (font->coords);
    1609             : 
    1610           0 :   font->coords = coords;
    1611           0 :   font->num_coords = coords_length;
    1612             : }
    1613             : 
    1614             : /**
    1615             :  * hb_font_set_variations:
    1616             :  *
    1617             :  * Since: 1.4.2
    1618             :  */
    1619             : void
    1620           0 : hb_font_set_variations (hb_font_t *font,
    1621             :                         const hb_variation_t *variations,
    1622             :                         unsigned int variations_length)
    1623             : {
    1624           0 :   if (font->immutable)
    1625           0 :     return;
    1626             : 
    1627           0 :   if (!variations_length)
    1628             :   {
    1629           0 :     hb_font_set_var_coords_normalized (font, NULL, 0);
    1630           0 :     return;
    1631             :   }
    1632             : 
    1633           0 :   unsigned int coords_length = hb_ot_var_get_axis_count (font->face);
    1634             : 
    1635           0 :   int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
    1636           0 :   if (unlikely (coords_length && !normalized))
    1637           0 :     return;
    1638             : 
    1639           0 :   hb_ot_var_normalize_variations (font->face,
    1640             :                                   variations, variations_length,
    1641           0 :                                   normalized, coords_length);
    1642           0 :   _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
    1643             : }
    1644             : 
    1645             : /**
    1646             :  * hb_font_set_var_coords_design:
    1647             :  *
    1648             :  * Since: 1.4.2
    1649             :  */
    1650             : void
    1651           0 : hb_font_set_var_coords_design (hb_font_t *font,
    1652             :                                const float *coords,
    1653             :                                unsigned int coords_length)
    1654             : {
    1655           0 :   if (font->immutable)
    1656           0 :     return;
    1657             : 
    1658           0 :   int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
    1659           0 :   if (unlikely (coords_length && !normalized))
    1660           0 :     return;
    1661             : 
    1662           0 :   hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
    1663           0 :   _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
    1664             : }
    1665             : 
    1666             : /**
    1667             :  * hb_font_set_var_coords_normalized:
    1668             :  *
    1669             :  * Since: 1.4.2
    1670             :  */
    1671             : void
    1672           0 : hb_font_set_var_coords_normalized (hb_font_t *font,
    1673             :                                    const int *coords, /* 2.14 normalized */
    1674             :                                    unsigned int coords_length)
    1675             : {
    1676           0 :   if (font->immutable)
    1677           0 :     return;
    1678             : 
    1679           0 :   int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : NULL;
    1680           0 :   if (unlikely (coords_length && !copy))
    1681           0 :     return;
    1682             : 
    1683           0 :   if (coords_length)
    1684           0 :     memcpy (copy, coords, coords_length * sizeof (coords[0]));
    1685             : 
    1686           0 :   _hb_font_adopt_var_coords_normalized (font, copy, coords_length);
    1687             : }
    1688             : 
    1689             : /**
    1690             :  * hb_font_get_var_coords_normalized:
    1691             :  *
    1692             :  * Return value is valid as long as variation coordinates of the font
    1693             :  * are not modified.
    1694             :  *
    1695             :  * Since: 1.4.2
    1696             :  */
    1697             : const int *
    1698           0 : hb_font_get_var_coords_normalized (hb_font_t *font,
    1699             :                                    unsigned int *length)
    1700             : {
    1701           0 :   if (length)
    1702           0 :     *length = font->num_coords;
    1703             : 
    1704           0 :   return font->coords;
    1705             : }
    1706             : 
    1707             : 
    1708             : #ifndef HB_DISABLE_DEPRECATED
    1709             : 
    1710             : /*
    1711             :  * Deprecated get_glyph_func():
    1712             :  */
    1713             : 
    1714             : struct hb_trampoline_closure_t
    1715             : {
    1716             :   void *user_data;
    1717             :   hb_destroy_func_t destroy;
    1718             :   unsigned int ref_count;
    1719             : };
    1720             : 
    1721             : template <typename FuncType>
    1722             : struct hb_trampoline_t
    1723             : {
    1724             :   hb_trampoline_closure_t closure; /* Must be first. */
    1725             :   FuncType func;
    1726             : };
    1727             : 
    1728             : template <typename FuncType>
    1729             : static hb_trampoline_t<FuncType> *
    1730           0 : trampoline_create (FuncType           func,
    1731             :                    void              *user_data,
    1732             :                    hb_destroy_func_t  destroy)
    1733             : {
    1734             :   typedef hb_trampoline_t<FuncType> trampoline_t;
    1735             : 
    1736           0 :   trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
    1737             : 
    1738           0 :   if (unlikely (!trampoline))
    1739           0 :     return NULL;
    1740             : 
    1741           0 :   trampoline->closure.user_data = user_data;
    1742           0 :   trampoline->closure.destroy = destroy;
    1743           0 :   trampoline->closure.ref_count = 1;
    1744           0 :   trampoline->func = func;
    1745             : 
    1746           0 :   return trampoline;
    1747             : }
    1748             : 
    1749             : static void
    1750           0 : trampoline_reference (hb_trampoline_closure_t *closure)
    1751             : {
    1752           0 :   closure->ref_count++;
    1753           0 : }
    1754             : 
    1755             : static void
    1756           0 : trampoline_destroy (void *user_data)
    1757             : {
    1758           0 :   hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
    1759             : 
    1760           0 :   if (--closure->ref_count)
    1761           0 :     return;
    1762             : 
    1763           0 :   if (closure->destroy)
    1764           0 :     closure->destroy (closure->user_data);
    1765           0 :   free (closure);
    1766             : }
    1767             : 
    1768             : typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
    1769             : 
    1770             : static hb_bool_t
    1771           0 : hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
    1772             :                                       void *font_data,
    1773             :                                       hb_codepoint_t unicode,
    1774             :                                       hb_codepoint_t *glyph,
    1775             :                                       void *user_data)
    1776             : {
    1777           0 :   hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
    1778           0 :   return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
    1779             : }
    1780             : 
    1781             : static hb_bool_t
    1782           0 : hb_font_get_variation_glyph_trampoline (hb_font_t *font,
    1783             :                                         void *font_data,
    1784             :                                         hb_codepoint_t unicode,
    1785             :                                         hb_codepoint_t variation_selector,
    1786             :                                         hb_codepoint_t *glyph,
    1787             :                                         void *user_data)
    1788             : {
    1789           0 :   hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
    1790           0 :   return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
    1791             : }
    1792             : 
    1793             : /**
    1794             :  * hb_font_funcs_set_glyph_func:
    1795             :  * @ffuncs: font functions.
    1796             :  * @func: (closure user_data) (destroy destroy) (scope notified):
    1797             :  * @user_data:
    1798             :  * @destroy:
    1799             :  *
    1800             :  * Deprecated.  Use hb_font_funcs_set_nominal_glyph_func() and
    1801             :  * hb_font_funcs_set_variation_glyph_func() instead.
    1802             :  *
    1803             :  * Since: 0.9.2
    1804             :  * Deprecated: 1.2.3
    1805             :  **/
    1806             : void
    1807           0 : hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
    1808             :                               hb_font_get_glyph_func_t func,
    1809             :                               void *user_data, hb_destroy_func_t destroy)
    1810             : {
    1811             :   hb_font_get_glyph_trampoline_t *trampoline;
    1812             : 
    1813           0 :   trampoline = trampoline_create (func, user_data, destroy);
    1814           0 :   if (unlikely (!trampoline))
    1815             :   {
    1816           0 :     if (destroy)
    1817           0 :       destroy (user_data);
    1818           0 :     return;
    1819             :   }
    1820             : 
    1821             :   hb_font_funcs_set_nominal_glyph_func (ffuncs,
    1822             :                                         hb_font_get_nominal_glyph_trampoline,
    1823             :                                         trampoline,
    1824           0 :                                         trampoline_destroy);
    1825             : 
    1826           0 :   trampoline_reference (&trampoline->closure);
    1827             :   hb_font_funcs_set_variation_glyph_func (ffuncs,
    1828             :                                           hb_font_get_variation_glyph_trampoline,
    1829             :                                           trampoline,
    1830           0 :                                           trampoline_destroy);
    1831             : }
    1832             : 
    1833             : #endif /* HB_DISABLE_DEPRECATED */

Generated by: LCOV version 1.13