[ot-glyph] Support CFF1's seac

This commit is contained in:
Ebrahim Byagowi 2019-10-21 13:28:05 +03:30
parent 04ac7fb1c9
commit af08f388ab
1 changed files with 20 additions and 23 deletions

View File

@ -344,13 +344,14 @@ bool OT::cff1::accelerator_t::get_extents (hb_font_t *font, hb_codepoint_t glyph
struct cff1_path_param_t
{
void init (const OT::cff1::accelerator_t *cff_, hb_font_t *font_, hb_vector_t<hb_position_t> *points_, hb_vector_t<uint8_t> *commands_)
void init (const OT::cff1::accelerator_t *cff_, hb_font_t *font_, hb_vector_t<hb_position_t> *points_, hb_vector_t<uint8_t> *commands_, point_t *delta_)
{
path_open = false;
cff = cff_;
font = font_;
points = points_;
commands = commands_;
delta = delta_;
}
void start_path () { path_open = true; }
@ -359,8 +360,10 @@ struct cff1_path_param_t
void push_point (const point_t &p)
{
points->push (font->em_scalef_x (p.x.to_real ()));
points->push (font->em_scalef_y (p.y.to_real ()));
point_t point = p;
if (delta) point.move (*delta);
points->push (font->em_scalef_x (point.x.to_real ()));
points->push (font->em_scalef_y (point.y.to_real ()));
}
void push_command (uint8_t c) { commands->push (c); }
@ -368,6 +371,7 @@ struct cff1_path_param_t
hb_font_t *font;
hb_vector_t<hb_position_t> *points;
hb_vector_t<uint8_t> *commands;
point_t *delta;
const OT::cff1::accelerator_t *cff;
};
@ -409,34 +413,27 @@ struct cff1_path_procs_path_t : path_procs_t<cff1_path_procs_path_t, cff1_cs_int
}
};
static bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoint_t glyph, hb_vector_t<hb_position_t> *points, hb_vector_t<uint8_t> *commands, bool in_seac=false);
static bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoint_t glyph, hb_vector_t<hb_position_t> *points, hb_vector_t<uint8_t> *commands, bool in_seac=false, point_t *delta = nullptr);
struct cff1_cs_opset_path_t : cff1_cs_opset_t<cff1_cs_opset_path_t, cff1_path_param_t, cff1_path_procs_path_t>
{
static void process_seac (cff1_cs_interp_env_t &env, cff1_path_param_t& param)
{
// unsigned int n = env.argStack.get_count ();
// point_t delta;
// delta.x = env.argStack[n-4];
// delta.y = env.argStack[n-3];
// hb_codepoint_t base = param.cff->std_code_to_glyph (env.argStack[n-2].to_int ());
// hb_codepoint_t accent = param.cff->std_code_to_glyph (env.argStack[n-1].to_int ());
unsigned int n = env.argStack.get_count ();
point_t delta;
delta.x = env.argStack[n-4];
delta.y = env.argStack[n-3];
hb_codepoint_t base = param.cff->std_code_to_glyph (env.argStack[n-2].to_int ());
hb_codepoint_t accent = param.cff->std_code_to_glyph (env.argStack[n-1].to_int ());
// bounds_t base_bounds, accent_bounds;
// if (likely (!env.in_seac && base && accent
// && _get_path (param.cff, base, base_bounds, true)
// && _get_path (param.cff, accent, accent_bounds, true)))
// {
// param.bounds.merge (base_bounds);
// accent_bounds.offset (delta);
// param.bounds.merge (accent_bounds);
// }
// else
// env.set_error ();
if (unlikely (!(!env.in_seac && base && accent
&& _get_path (param.cff, param.font, base, param.points, param.commands, true)
&& _get_path (param.cff, param.font, accent, param.points, param.commands, true, &delta))))
env.set_error ();
}
};
bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoint_t glyph, hb_vector_t<hb_position_t> *points, hb_vector_t<uint8_t> *commands, bool in_seac)
bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoint_t glyph, hb_vector_t<hb_position_t> *points, hb_vector_t<uint8_t> *commands, bool in_seac, point_t *delta)
{
if (unlikely (!cff->is_valid () || (glyph >= cff->num_glyphs))) return false;
@ -446,7 +443,7 @@ bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoin
interp.env.init (str, *cff, fd);
interp.env.set_in_seac (in_seac);
cff1_path_param_t param;
param.init (cff, font, points, commands);
param.init (cff, font, points, commands, delta);
if (unlikely (!interp.interpret (param))) return false;
return true;
}