2018-10-09 00:05:36 +02:00
|
|
|
/*
|
2018-11-12 17:47:07 +01:00
|
|
|
* Copyright © 2018 Adobe Inc.
|
2018-10-09 00:05:36 +02:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Adobe Author(s): Michiharu Ariza
|
|
|
|
*/
|
|
|
|
|
2019-06-18 22:07:44 +02:00
|
|
|
#include "hb.hh"
|
2018-10-09 00:05:36 +02:00
|
|
|
|
2019-05-12 19:29:47 +02:00
|
|
|
#ifndef HB_NO_OT_FONT_CFF
|
|
|
|
|
2019-06-18 22:07:44 +02:00
|
|
|
#include "hb-ot-cff2-table.hh"
|
|
|
|
#include "hb-cff2-interp-cs.hh"
|
2020-01-13 17:01:18 +01:00
|
|
|
#include "hb-ot-glyph.hh"
|
2019-06-18 22:07:44 +02:00
|
|
|
|
2018-10-09 00:05:36 +02:00
|
|
|
using namespace CFF;
|
|
|
|
|
2019-07-03 01:00:58 +02:00
|
|
|
struct cff2_extents_param_t
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
void init ()
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
|
|
|
path_open = false;
|
2019-04-18 22:54:58 +02:00
|
|
|
min_x.set_int (INT_MAX);
|
|
|
|
min_y.set_int (INT_MAX);
|
|
|
|
max_x.set_int (INT_MIN);
|
|
|
|
max_y.set_int (INT_MIN);
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
|
2019-10-01 12:19:55 +02:00
|
|
|
void start_path () { path_open = true; }
|
|
|
|
void end_path () { path_open = false; }
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_path_open () const { return path_open; }
|
2018-10-09 00:05:36 +02:00
|
|
|
|
2018-12-22 16:47:04 +01:00
|
|
|
void update_bounds (const point_t &pt)
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
|
|
|
if (pt.x < min_x) min_x = pt.x;
|
|
|
|
if (pt.x > max_x) max_x = pt.x;
|
|
|
|
if (pt.y < min_y) min_y = pt.y;
|
|
|
|
if (pt.y > max_y) max_y = pt.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool path_open;
|
2018-12-22 16:47:04 +01:00
|
|
|
number_t min_x;
|
|
|
|
number_t min_y;
|
|
|
|
number_t max_x;
|
|
|
|
number_t max_y;
|
2018-10-09 00:05:36 +02:00
|
|
|
};
|
|
|
|
|
2019-07-03 01:00:58 +02:00
|
|
|
struct cff2_path_procs_extents_t : path_procs_t<cff2_path_procs_extents_t, cff2_cs_interp_env_t, cff2_extents_param_t>
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2019-07-03 01:00:58 +02:00
|
|
|
static void moveto (cff2_cs_interp_env_t &env, cff2_extents_param_t& param, const point_t &pt)
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
|
|
|
param.end_path ();
|
|
|
|
env.moveto (pt);
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:00:58 +02:00
|
|
|
static void line (cff2_cs_interp_env_t &env, cff2_extents_param_t& param, const point_t &pt1)
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
|
|
|
if (!param.is_path_open ())
|
|
|
|
{
|
|
|
|
param.start_path ();
|
|
|
|
param.update_bounds (env.get_pt ());
|
|
|
|
}
|
|
|
|
env.moveto (pt1);
|
|
|
|
param.update_bounds (env.get_pt ());
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:00:58 +02:00
|
|
|
static void curve (cff2_cs_interp_env_t &env, cff2_extents_param_t& param, const point_t &pt1, const point_t &pt2, const point_t &pt3)
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
|
|
|
if (!param.is_path_open ())
|
|
|
|
{
|
|
|
|
param.start_path ();
|
|
|
|
param.update_bounds (env.get_pt ());
|
|
|
|
}
|
|
|
|
/* include control points */
|
|
|
|
param.update_bounds (pt1);
|
|
|
|
param.update_bounds (pt2);
|
|
|
|
env.moveto (pt3);
|
|
|
|
param.update_bounds (env.get_pt ());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-03 01:00:58 +02:00
|
|
|
struct cff2_cs_opset_extents_t : cff2_cs_opset_t<cff2_cs_opset_extents_t, cff2_extents_param_t, cff2_path_procs_extents_t> {};
|
2018-10-09 00:05:36 +02:00
|
|
|
|
2018-11-02 00:18:13 +01:00
|
|
|
bool OT::cff2::accelerator_t::get_extents (hb_font_t *font,
|
2018-12-01 05:04:59 +01:00
|
|
|
hb_codepoint_t glyph,
|
|
|
|
hb_glyph_extents_t *extents) const
|
2018-10-09 00:05:36 +02:00
|
|
|
{
|
2019-05-11 08:39:53 +02:00
|
|
|
#ifdef HB_NO_OT_FONT_CFF
|
|
|
|
/* XXX Remove check when this code moves to .hh file. */
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2018-10-09 00:05:36 +02:00
|
|
|
if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false;
|
|
|
|
|
|
|
|
unsigned int fd = fdSelect->get_fd (glyph);
|
2019-07-03 01:00:58 +02:00
|
|
|
cff2_cs_interpreter_t<cff2_cs_opset_extents_t, cff2_extents_param_t> interp;
|
2018-12-22 16:47:04 +01:00
|
|
|
const byte_str_t str = (*charStrings)[glyph];
|
2019-08-14 16:40:02 +02:00
|
|
|
interp.env.init (str, *this, fd, font->coords, font->num_coords);
|
2019-07-03 01:00:58 +02:00
|
|
|
cff2_extents_param_t param;
|
2018-10-09 00:05:36 +02:00
|
|
|
param.init ();
|
|
|
|
if (unlikely (!interp.interpret (param))) return false;
|
|
|
|
|
|
|
|
if (param.min_x >= param.max_x)
|
|
|
|
{
|
|
|
|
extents->width = 0;
|
|
|
|
extents->x_bearing = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-06 16:39:14 +02:00
|
|
|
extents->x_bearing = font->em_scalef_x (param.min_x.to_real ());
|
2019-10-08 21:57:37 +02:00
|
|
|
extents->width = font->em_scalef_x (param.max_x.to_real () - param.min_x.to_real ());
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
if (param.min_y >= param.max_y)
|
|
|
|
{
|
|
|
|
extents->height = 0;
|
|
|
|
extents->y_bearing = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-06 16:39:14 +02:00
|
|
|
extents->y_bearing = font->em_scalef_y (param.max_y.to_real ());
|
2019-10-08 21:57:37 +02:00
|
|
|
extents->height = font->em_scalef_y (param.min_y.to_real () - param.max_y.to_real ());
|
2018-10-09 00:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-12 19:29:47 +02:00
|
|
|
|
2019-10-21 11:36:12 +02:00
|
|
|
struct cff2_path_param_t
|
|
|
|
{
|
2020-01-23 12:18:59 +01:00
|
|
|
cff2_path_param_t (hb_font_t *font_, const hb_ot_glyph_decompose_funcs_t *funcs_, void *user_data_)
|
2019-10-21 11:36:12 +02:00
|
|
|
{
|
|
|
|
path_open = false;
|
|
|
|
font = font_;
|
2020-01-10 19:44:46 +01:00
|
|
|
funcs = funcs_;
|
|
|
|
user_data = user_data_;
|
2019-10-21 11:36:12 +02:00
|
|
|
}
|
2020-01-23 12:18:59 +01:00
|
|
|
~cff2_path_param_t () { end_path (); }
|
2019-10-21 11:36:12 +02:00
|
|
|
|
2020-01-14 14:53:30 +01:00
|
|
|
void start_path () { funcs->open_path (user_data); path_open = true; }
|
|
|
|
void end_path () { if (path_open) funcs->close_path (user_data); path_open = false; }
|
2019-10-21 11:36:12 +02:00
|
|
|
bool is_path_open () const { return path_open; }
|
|
|
|
|
2020-01-10 19:44:46 +01:00
|
|
|
void move_to (const point_t &p)
|
2019-10-21 11:36:12 +02:00
|
|
|
{
|
2020-01-10 19:44:46 +01:00
|
|
|
funcs->move_to (font->em_scalef_x (p.x.to_real ()), font->em_scalef_y (p.y.to_real ()),
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void line_to (const point_t &p)
|
|
|
|
{
|
|
|
|
funcs->line_to (font->em_scalef_x (p.x.to_real ()), font->em_scalef_y (p.y.to_real ()),
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cubic_to (const point_t &p1, const point_t &p2, const point_t &p3)
|
|
|
|
{
|
|
|
|
funcs->cubic_to (font->em_scalef_x (p1.x.to_real ()), font->em_scalef_y (p1.y.to_real ()),
|
|
|
|
font->em_scalef_x (p2.x.to_real ()), font->em_scalef_y (p2.y.to_real ()),
|
|
|
|
font->em_scalef_x (p3.x.to_real ()), font->em_scalef_y (p3.y.to_real ()),
|
|
|
|
user_data);
|
2019-10-21 11:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool path_open;
|
|
|
|
hb_font_t *font;
|
2020-01-13 17:01:18 +01:00
|
|
|
const hb_ot_glyph_decompose_funcs_t *funcs;
|
2020-01-10 19:44:46 +01:00
|
|
|
void *user_data;
|
2019-10-21 11:36:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cff2_path_procs_path_t : path_procs_t<cff2_path_procs_path_t, cff2_cs_interp_env_t, cff2_path_param_t>
|
|
|
|
{
|
|
|
|
static void moveto (cff2_cs_interp_env_t &env, cff2_path_param_t& param, const point_t &pt)
|
|
|
|
{
|
|
|
|
param.end_path ();
|
2020-01-10 19:44:46 +01:00
|
|
|
param.move_to (pt);
|
2019-10-21 11:36:12 +02:00
|
|
|
env.moveto (pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void line (cff2_cs_interp_env_t &env, cff2_path_param_t& param, const point_t &pt1)
|
|
|
|
{
|
2020-01-10 19:44:46 +01:00
|
|
|
if (!param.is_path_open ()) param.start_path ();
|
|
|
|
param.line_to (pt1);
|
2019-10-21 11:36:12 +02:00
|
|
|
env.moveto (pt1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void curve (cff2_cs_interp_env_t &env, cff2_path_param_t& param, const point_t &pt1, const point_t &pt2, const point_t &pt3)
|
|
|
|
{
|
2020-01-10 19:44:46 +01:00
|
|
|
if (!param.is_path_open ()) param.start_path ();
|
|
|
|
param.cubic_to (pt1, pt2, pt3);
|
2019-10-21 11:36:12 +02:00
|
|
|
env.moveto (pt3);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cff2_cs_opset_path_t : cff2_cs_opset_t<cff2_cs_opset_path_t, cff2_path_param_t, cff2_path_procs_path_t> {};
|
|
|
|
|
2020-01-10 19:44:46 +01:00
|
|
|
bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph,
|
2020-01-13 17:01:18 +01:00
|
|
|
const hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const
|
2019-10-21 11:36:12 +02:00
|
|
|
{
|
|
|
|
#ifdef HB_NO_OT_FONT_CFF
|
|
|
|
/* XXX Remove check when this code moves to .hh file. */
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false;
|
|
|
|
|
|
|
|
unsigned int fd = fdSelect->get_fd (glyph);
|
|
|
|
cff2_cs_interpreter_t<cff2_cs_opset_path_t, cff2_path_param_t> interp;
|
|
|
|
const byte_str_t str = (*charStrings)[glyph];
|
|
|
|
interp.env.init (str, *this, fd, font->coords, font->num_coords);
|
2020-01-23 12:18:59 +01:00
|
|
|
cff2_path_param_t param (font, funcs, user_data);
|
2019-10-21 11:36:12 +02:00
|
|
|
if (unlikely (!interp.interpret (param))) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-18 22:07:44 +02:00
|
|
|
|
2019-05-12 19:29:47 +02:00
|
|
|
#endif
|