src/java.desktop/share/native/libfontmanager/harfbuzz/hb-ot-cff2-table.cc
author prr
Fri, 01 Mar 2019 16:59:19 -0800
changeset 54232 7c11a7cc7c1d
permissions -rw-r--r--
8210782: Upgrade HarfBuzz to the latest 2.3.1 Reviewed-by: serb, ihse, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54232
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     1
/*
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     2
 * Copyright © 2018 Adobe Inc.
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     3
 *
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     4
 *  This is part of HarfBuzz, a text shaping library.
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     5
 *
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     6
 * Permission is hereby granted, without written agreement and without
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     7
 * license or royalty fees, to use, copy, modify, and distribute this
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     8
 * software and its documentation for any purpose, provided that the
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
     9
 * above copyright notice and the following two paragraphs appear in
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    10
 * all copies of this software.
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    11
 *
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    12
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    13
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    14
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    15
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    16
 * DAMAGE.
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    17
 *
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    18
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    19
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    20
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    21
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    22
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    23
 *
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    24
 * Adobe Author(s): Michiharu Ariza
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    25
 */
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    26
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    27
#include "hb-ot-cff2-table.hh"
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    28
#include "hb-cff2-interp-cs.hh"
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    29
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    30
using namespace CFF;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    31
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    32
struct extents_param_t
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    33
{
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    34
  void init ()
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    35
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    36
    path_open = false;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    37
    min_x.set_int (0x7FFFFFFF);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    38
    min_y.set_int (0x7FFFFFFF);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    39
    max_x.set_int (-0x80000000);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    40
    max_y.set_int (-0x80000000);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    41
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    42
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    43
  void start_path ()         { path_open = true; }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    44
  void end_path ()           { path_open = false; }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    45
  bool is_path_open () const { return path_open; }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    46
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    47
  void update_bounds (const point_t &pt)
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    48
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    49
    if (pt.x < min_x) min_x = pt.x;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    50
    if (pt.x > max_x) max_x = pt.x;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    51
    if (pt.y < min_y) min_y = pt.y;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    52
    if (pt.y > max_y) max_y = pt.y;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    53
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    54
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    55
  bool  path_open;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    56
  number_t min_x;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    57
  number_t min_y;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    58
  number_t max_x;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    59
  number_t max_y;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    60
};
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    61
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    62
struct cff2_path_procs_extents_t : path_procs_t<cff2_path_procs_extents_t, cff2_cs_interp_env_t, extents_param_t>
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    63
{
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    64
  static void moveto (cff2_cs_interp_env_t &env, extents_param_t& param, const point_t &pt)
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    65
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    66
    param.end_path ();
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    67
    env.moveto (pt);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    68
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    69
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    70
  static void line (cff2_cs_interp_env_t &env, extents_param_t& param, const point_t &pt1)
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    71
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    72
    if (!param.is_path_open ())
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    73
    {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    74
      param.start_path ();
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    75
      param.update_bounds (env.get_pt ());
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    76
    }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    77
    env.moveto (pt1);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    78
    param.update_bounds (env.get_pt ());
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    79
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    80
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    81
  static void curve (cff2_cs_interp_env_t &env, extents_param_t& param, const point_t &pt1, const point_t &pt2, const point_t &pt3)
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    82
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    83
    if (!param.is_path_open ())
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    84
    {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    85
      param.start_path ();
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    86
      param.update_bounds (env.get_pt ());
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    87
    }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    88
    /* include control points */
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    89
    param.update_bounds (pt1);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    90
    param.update_bounds (pt2);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    91
    env.moveto (pt3);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    92
    param.update_bounds (env.get_pt ());
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    93
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    94
};
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    95
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    96
struct cff2_cs_opset_extents_t : cff2_cs_opset_t<cff2_cs_opset_extents_t, extents_param_t, cff2_path_procs_extents_t> {};
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    97
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    98
bool OT::cff2::accelerator_t::get_extents (hb_font_t *font,
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
    99
                                           hb_codepoint_t glyph,
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   100
                                           hb_glyph_extents_t *extents) const
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   101
{
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   102
  if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   103
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   104
  unsigned int num_coords;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   105
  const int *coords = hb_font_get_var_coords_normalized (font, &num_coords);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   106
  unsigned int fd = fdSelect->get_fd (glyph);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   107
  cff2_cs_interpreter_t<cff2_cs_opset_extents_t, extents_param_t> interp;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   108
  const byte_str_t str = (*charStrings)[glyph];
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   109
  interp.env.init (str, *this, fd, coords, num_coords);
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   110
  extents_param_t  param;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   111
  param.init ();
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   112
  if (unlikely (!interp.interpret (param))) return false;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   113
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   114
  if (param.min_x >= param.max_x)
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   115
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   116
    extents->width = 0;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   117
    extents->x_bearing = 0;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   118
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   119
  else
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   120
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   121
    extents->x_bearing = (int32_t)param.min_x.floor ();
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   122
    extents->width = (int32_t)param.max_x.ceil () - extents->x_bearing;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   123
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   124
  if (param.min_y >= param.max_y)
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   125
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   126
    extents->height = 0;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   127
    extents->y_bearing = 0;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   128
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   129
  else
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   130
  {
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   131
    extents->y_bearing = (int32_t)param.max_y.ceil ();
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   132
    extents->height = (int32_t)param.min_y.floor () - extents->y_bearing;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   133
  }
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   134
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   135
  return true;
7c11a7cc7c1d 8210782: Upgrade HarfBuzz to the latest 2.3.1
prr
parents:
diff changeset
   136
}