diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 834ef9165..95a054082 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -523,11 +523,18 @@ hb_ot_font_set_funcs
hb-ot-glyph hb_ot_glyph_decompose_funcs_t -hb_ot_glyph_decompose_move_to_func_t -hb_ot_glyph_decompose_line_to_func_t hb_ot_glyph_decompose_conic_to_func_t hb_ot_glyph_decompose_cubic_to_func_t +hb_ot_glyph_decompose_line_to_func_t +hb_ot_glyph_decompose_move_to_func_t hb_ot_glyph_decompose +hb_ot_glyph_decompose_funcs_create +hb_ot_glyph_decompose_funcs_destroy +hb_ot_glyph_decompose_funcs_reference +hb_ot_glyph_decompose_funcs_set_conic_to_func +hb_ot_glyph_decompose_funcs_set_cubic_to_func +hb_ot_glyph_decompose_funcs_set_line_to_func +hb_ot_glyph_decompose_funcs_set_move_to_func
diff --git a/src/Makefile.sources b/src/Makefile.sources index 061b3b8a8..58c9fda3b 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -74,6 +74,7 @@ HB_BASE_sources = \ hb-ot-gasp-table.hh \ hb-ot-glyf-table.hh \ hb-ot-glyph.cc \ + hb-ot-glyph.hh \ hb-ot-hdmx-table.hh \ hb-ot-head-table.hh \ hb-ot-hhea-table.hh \ diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index 2c9323276..040e583ce 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -30,6 +30,7 @@ #include "hb-ot-cff1-table.hh" #include "hb-cff1-interp-cs.hh" +#include "hb-ot-glyph.hh" using namespace CFF; @@ -345,7 +346,7 @@ 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_ot_glyph_decompose_funcs_t *funcs_, void *user_data_, + const hb_ot_glyph_decompose_funcs_t *funcs_, void *user_data_, point_t *delta_) { path_open = false; @@ -393,7 +394,7 @@ struct cff1_path_param_t bool path_open; hb_font_t *font; - hb_ot_glyph_decompose_funcs_t *funcs; + const hb_ot_glyph_decompose_funcs_t *funcs; void *user_data; point_t *delta; @@ -425,7 +426,7 @@ struct cff1_path_procs_path_t : path_procs_t @@ -447,7 +448,7 @@ struct cff1_cs_opset_path_t : cff1_cs_opset_tis_valid () || (glyph >= cff->num_glyphs))) return false; @@ -463,7 +464,7 @@ bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoin } bool OT::cff1::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, - hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const + const hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const { #ifdef HB_NO_OT_FONT_CFF /* XXX Remove check when this code moves to .hh file. */ diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index ae5519499..da3210303 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -1348,7 +1348,7 @@ struct cff1 HB_INTERNAL bool get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const; HB_INTERNAL bool get_seac_components (hb_codepoint_t glyph, hb_codepoint_t *base, hb_codepoint_t *accent) const; HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, - hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const; + const hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const; private: struct gname_t diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index b51ea51a6..c2b0d1778 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -30,6 +30,7 @@ #include "hb-ot-cff2-table.hh" #include "hb-cff2-interp-cs.hh" +#include "hb-ot-glyph.hh" using namespace CFF; @@ -144,7 +145,7 @@ bool OT::cff2::accelerator_t::get_extents (hb_font_t *font, struct cff2_path_param_t { - void init (hb_font_t *font_, hb_ot_glyph_decompose_funcs_t *funcs_, void *user_data_) + void init (hb_font_t *font_, const hb_ot_glyph_decompose_funcs_t *funcs_, void *user_data_) { path_open = false; font = font_; @@ -178,7 +179,7 @@ struct cff2_path_param_t bool path_open; hb_font_t *font; - hb_ot_glyph_decompose_funcs_t *funcs; + const hb_ot_glyph_decompose_funcs_t *funcs; void *user_data; }; @@ -209,7 +210,7 @@ struct cff2_path_procs_path_t : path_procs_t {}; bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, - hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const + const hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const { #ifdef HB_NO_OT_FONT_CFF /* XXX Remove check when this code moves to .hh file. */ diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index 50620ecfc..55312287f 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -534,7 +534,7 @@ struct cff2 hb_codepoint_t glyph, hb_glyph_extents_t *extents) const; HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, - hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const; + const hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const; }; typedef accelerator_templ_t accelerator_subset_t; diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index b0ccbe177..774eb94c4 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -34,6 +34,7 @@ #include "hb-ot-head-table.hh" #include "hb-ot-hmtx-table.hh" #include "hb-ot-var-gvar-table.hh" +#include "hb-ot-glyph.hh" #include @@ -1044,7 +1045,7 @@ struct glyf bool get_path (hb_font_t *font, hb_codepoint_t gid, - hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const + const hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) const { /* TODO: Make it alloc free and work without all_points vector */ contour_point_vector_t all_points; diff --git a/src/hb-ot-glyph.cc b/src/hb-ot-glyph.cc index 065a2c4ca..6315c97ba 100644 --- a/src/hb-ot-glyph.cc +++ b/src/hb-ot-glyph.cc @@ -30,13 +30,165 @@ #include "hb-ot-glyf-table.hh" #include "hb-ot-cff1-table.hh" #include "hb-ot-cff2-table.hh" +#include "hb-ot-glyph.hh" +/** + * hb_ot_glyph_decompose_funcs_set_move_to_func: + * @funcs: decompose functions object + * @move_to: move-to callback + * + * Sets move-to callback to the decompose functions object. + * + * Since: REPLACEME + **/ +void +hb_ot_glyph_decompose_funcs_set_move_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_move_to_func_t move_to) +{ + if (unlikely (funcs == &Null (hb_ot_glyph_decompose_funcs_t))) return; + funcs->move_to = move_to; +} + +/** + * hb_ot_glyph_decompose_funcs_set_line_to_func: + * @funcs: decompose functions object + * @line_to: line-to callback + * + * Sets line-to callback to the decompose functions object. + * + * Since: REPLACEME + **/ +void +hb_ot_glyph_decompose_funcs_set_line_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_line_to_func_t line_to) +{ + if (unlikely (funcs == &Null (hb_ot_glyph_decompose_funcs_t))) return; + funcs->line_to = line_to; +} + +/** + * hb_ot_glyph_decompose_funcs_set_conic_to_func: + * @funcs: decompose functions object + * @move_to: conic-to callback + * + * Sets conic-to callback to the decompose functions object. + * + * Since: REPLACEME + **/ +void +hb_ot_glyph_decompose_funcs_set_conic_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_conic_to_func_t conic_to) +{ + if (unlikely (funcs == &Null (hb_ot_glyph_decompose_funcs_t))) return; + funcs->conic_to = conic_to; +} + +/** + * hb_ot_glyph_decompose_funcs_set_cubic_to_func: + * @funcs: decompose functions + * @cubic_to: cubic-to callback + * + * Sets cubic-to callback to the decompose functions object. + * + * Since: REPLACEME + **/ +void +hb_ot_glyph_decompose_funcs_set_cubic_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_cubic_to_func_t cubic_to) +{ + if (unlikely (funcs == &Null (hb_ot_glyph_decompose_funcs_t))) return; + funcs->cubic_to = cubic_to; +} + +static void +_move_to_noop (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {} + +static void +_line_to_noop (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {} + +static void +_conic_to_noop (hb_position_t control_x HB_UNUSED, hb_position_t control_y HB_UNUSED, + hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, + void *user_data HB_UNUSED) {} +static void +_cubic_to_noop (hb_position_t control1_x HB_UNUSED, hb_position_t control1_y HB_UNUSED, + hb_position_t control2_x HB_UNUSED, hb_position_t control2_y HB_UNUSED, + hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, + void *user_data HB_UNUSED) {} + +/** + * hb_ot_glyph_decompose_funcs_create: + * + * Creates a new decompose callbacks object. + * + * Since: REPLACEME + **/ +hb_ot_glyph_decompose_funcs_t * +hb_ot_glyph_decompose_funcs_create () +{ + hb_ot_glyph_decompose_funcs_t *funcs; + if (unlikely (!(funcs = hb_object_create ()))) + return const_cast (&Null (hb_ot_glyph_decompose_funcs_t)); + + funcs->move_to = (hb_ot_glyph_decompose_move_to_func_t) _move_to_noop; + funcs->line_to = (hb_ot_glyph_decompose_line_to_func_t) _line_to_noop; + funcs->conic_to = (hb_ot_glyph_decompose_conic_to_func_t) _conic_to_noop; + funcs->cubic_to = (hb_ot_glyph_decompose_cubic_to_func_t) _cubic_to_noop; + return funcs; +} + +/** + * hb_ot_glyph_decompose_funcs_reference: + * @funcs: decompose functions + * + * Add to callbacks object refcount. + * + * Returns: The same object. + * Since: REPLACEME + **/ +hb_ot_glyph_decompose_funcs_t * +hb_ot_glyph_decompose_funcs_reference (hb_ot_glyph_decompose_funcs_t *funcs) +{ + return hb_object_reference (funcs); +} + +/** + * hb_ot_glyph_decompose_funcs_destroy: + * @funcs: decompose functions + * + * Decreases refcount of callbacks object and deletes the object if it reaches + * to zero. + * + * Since: REPLACEME + **/ +void +hb_ot_glyph_decompose_funcs_destroy (hb_ot_glyph_decompose_funcs_t *funcs) +{ + if (!hb_object_destroy (funcs)) return; + + free (funcs); +} + +/** + * hb_ot_glyph_decompose: + * @font: a font object + * @glyph: a glyph id + * @funcs: decompose callbacks object + * @user_data: parameter you like be passed to the callbacks when are called + * + * Decomposes a glyph. + * + * Returns: Whether the font had the glyph and the operation completed successfully. + * Since: REPLACEME + **/ hb_bool_t hb_ot_glyph_decompose (hb_font_t *font, hb_codepoint_t glyph, - hb_ot_glyph_decompose_funcs_t *funcs, + const hb_ot_glyph_decompose_funcs_t *funcs, void *user_data) { - if (unlikely (!funcs || glyph >= font->face->get_num_glyphs ())) return false; + if (unlikely (!funcs || funcs == &Null (hb_ot_glyph_decompose_funcs_t) || + glyph >= font->face->get_num_glyphs ())) + return false; if (font->face->table.glyf->get_path (font, glyph, funcs, user_data)) return true; #ifndef HB_NO_CFF diff --git a/src/hb-ot-glyph.h b/src/hb-ot-glyph.h index ee72c9e80..015589f52 100644 --- a/src/hb-ot-glyph.h +++ b/src/hb-ot-glyph.h @@ -50,22 +50,37 @@ typedef void (*hb_ot_glyph_decompose_cubic_to_func_t) (hb_position_t control1_x, * * Since: REPLACEME **/ -typedef struct hb_ot_glyph_decompose_funcs_t -{ - hb_ot_glyph_decompose_move_to_func_t move_to; - hb_ot_glyph_decompose_line_to_func_t line_to; - hb_ot_glyph_decompose_conic_to_func_t conic_to; - hb_ot_glyph_decompose_cubic_to_func_t cubic_to; - /*< private >*/ - void *reserved4; - void *reserved3; - void *reserved2; - void *reserved1; -} hb_ot_glyph_decompose_funcs_t; +typedef struct hb_ot_glyph_decompose_funcs_t hb_ot_glyph_decompose_funcs_t; + +HB_EXTERN void +hb_ot_glyph_decompose_funcs_set_move_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_move_to_func_t move_to); + +HB_EXTERN void +hb_ot_glyph_decompose_funcs_set_line_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_move_to_func_t line_to); + +HB_EXTERN void +hb_ot_glyph_decompose_funcs_set_conic_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_conic_to_func_t conic_to); + +HB_EXTERN void +hb_ot_glyph_decompose_funcs_set_cubic_to_func (hb_ot_glyph_decompose_funcs_t *funcs, + hb_ot_glyph_decompose_cubic_to_func_t cubic_to); + +HB_EXTERN hb_ot_glyph_decompose_funcs_t * +hb_ot_glyph_decompose_funcs_create (void); + +HB_EXTERN hb_ot_glyph_decompose_funcs_t * +hb_ot_glyph_decompose_funcs_reference (hb_ot_glyph_decompose_funcs_t *funcs); + +HB_EXTERN void +hb_ot_glyph_decompose_funcs_destroy (hb_ot_glyph_decompose_funcs_t *funcs); HB_EXTERN hb_bool_t hb_ot_glyph_decompose (hb_font_t *font, hb_codepoint_t glyph, - hb_ot_glyph_decompose_funcs_t *funcs, void *user_data); + const hb_ot_glyph_decompose_funcs_t *funcs, + void *user_data); HB_END_DECLS diff --git a/src/hb-ot-glyph.hh b/src/hb-ot-glyph.hh new file mode 100644 index 000000000..b78a9650f --- /dev/null +++ b/src/hb-ot-glyph.hh @@ -0,0 +1,44 @@ +/* + * Copyright © 2020 Ebrahim Byagowi + * + * 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. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_GLYPH_HH +#define HB_OT_GLYPH_HH + +#include "hb.hh" + +struct hb_ot_glyph_decompose_funcs_t +{ + hb_object_header_t header; + + hb_ot_glyph_decompose_move_to_func_t move_to; + hb_ot_glyph_decompose_line_to_func_t line_to; + hb_ot_glyph_decompose_conic_to_func_t conic_to; + hb_ot_glyph_decompose_cubic_to_func_t cubic_to; +}; + + +#endif /* HB_OT_GLYPH_HH */ diff --git a/src/test-ot-glyph.cc b/src/test-ot-glyph.cc index 3f9d326b2..1e38fc0da 100644 --- a/src/test-ot-glyph.cc +++ b/src/test-ot-glyph.cc @@ -87,11 +87,11 @@ main (int argc, char **argv) exit (1); } - hb_ot_glyph_decompose_funcs_t funcs; - funcs.move_to = (hb_ot_glyph_decompose_move_to_func_t) move_to; - funcs.line_to = (hb_ot_glyph_decompose_line_to_func_t) line_to; - funcs.conic_to = (hb_ot_glyph_decompose_conic_to_func_t) conic_to; - funcs.cubic_to = (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to; + hb_ot_glyph_decompose_funcs_t *funcs = hb_ot_glyph_decompose_funcs_create (); + hb_ot_glyph_decompose_funcs_set_move_to_func (funcs, (hb_ot_glyph_decompose_move_to_func_t) move_to); + hb_ot_glyph_decompose_funcs_set_line_to_func (funcs, (hb_ot_glyph_decompose_line_to_func_t) line_to); + hb_ot_glyph_decompose_funcs_set_conic_to_func (funcs, (hb_ot_glyph_decompose_conic_to_func_t) conic_to); + hb_ot_glyph_decompose_funcs_set_cubic_to_func (funcs, (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to); for (unsigned int face_index = 0; face_index < hb_face_count (blob); face_index++) { @@ -119,7 +119,7 @@ main (int argc, char **argv) user_data_t user_data; user_data.ascender = font_extents.ascender; user_data.f = f; - if (!hb_ot_glyph_decompose (font, gid, &funcs, &user_data)) + if (!hb_ot_glyph_decompose (font, gid, funcs, &user_data)) printf ("Failed to decompose gid: %d\n", gid); fprintf (f, "\"/>"); fclose (f); @@ -128,6 +128,8 @@ main (int argc, char **argv) hb_face_destroy (face); } + hb_ot_glyph_decompose_funcs_destroy (funcs); + hb_blob_destroy (blob); return 0; diff --git a/test/api/test-ot-face.c b/test/api/test-ot-face.c index ffb11e213..5df4eb19f 100644 --- a/test/api/test-ot-face.c +++ b/test/api/test-ot-face.c @@ -25,36 +25,13 @@ */ #ifndef TEST_OT_FACE_NO_MAIN -# include "hb-test.h" -#else -# if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__) -# define HB_UNUSED __attribute__((unused)) -# else -# define HB_UNUSED -# endif +#include "hb-test.h" #endif #include /* Unit tests for hb-ot-*.h */ -static void -move_to (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {} - -static void -line_to (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {} - -static void -conic_to (hb_position_t control_x HB_UNUSED, hb_position_t control_y HB_UNUSED, - hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, - void *user_data HB_UNUSED) {} - -static void -cubic_to (hb_position_t control1_x HB_UNUSED, hb_position_t control1_y HB_UNUSED, - hb_position_t control2_x HB_UNUSED, hb_position_t control2_y HB_UNUSED, - hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, - void *user_data HB_UNUSED) {} - static void test_face (hb_face_t *face, hb_codepoint_t cp) @@ -132,13 +109,10 @@ test_face (hb_face_t *face, hb_ot_var_normalize_variations (face, NULL, 0, NULL, 0); hb_ot_var_normalize_coords (face, 0, NULL, NULL); - hb_ot_glyph_decompose_funcs_t funcs; - funcs.move_to = (hb_ot_glyph_decompose_move_to_func_t) move_to; - funcs.line_to = (hb_ot_glyph_decompose_line_to_func_t) line_to; - funcs.conic_to = (hb_ot_glyph_decompose_conic_to_func_t) conic_to; - funcs.cubic_to = (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to; + hb_ot_glyph_decompose_funcs_t *funcs = hb_ot_glyph_decompose_funcs_create (); for (unsigned gid = 0; gid < 10; ++gid) - hb_ot_glyph_decompose (font, gid, &funcs, NULL); + hb_ot_glyph_decompose (font, gid, funcs, NULL); + hb_ot_glyph_decompose_funcs_destroy (funcs); hb_set_destroy (set); hb_font_destroy (font); diff --git a/test/api/test-ot-glyph.c b/test/api/test-ot-glyph.c index 69820cbf2..41adba09d 100644 --- a/test/api/test-ot-glyph.c +++ b/test/api/test-ot-glyph.c @@ -74,27 +74,17 @@ cubic_to (hb_position_t control1_x, hb_position_t control1_y, to_x, to_y); } +static hb_ot_glyph_decompose_funcs_t *funcs; + static void test_hb_ot_glyph_empty (void) { - hb_ot_glyph_decompose_funcs_t funcs; - funcs.move_to = (hb_ot_glyph_decompose_move_to_func_t) move_to; - funcs.line_to = (hb_ot_glyph_decompose_line_to_func_t) line_to; - funcs.conic_to = (hb_ot_glyph_decompose_conic_to_func_t) conic_to; - funcs.cubic_to = (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to; - - g_assert (!hb_ot_glyph_decompose (hb_font_get_empty (), 3, &funcs, NULL)); + g_assert (!hb_ot_glyph_decompose (hb_font_get_empty (), 3, funcs, NULL)); } static void test_hb_ot_glyph_glyf (void) { - hb_ot_glyph_decompose_funcs_t funcs; - funcs.move_to = (hb_ot_glyph_decompose_move_to_func_t) move_to; - funcs.line_to = (hb_ot_glyph_decompose_line_to_func_t) line_to; - funcs.conic_to = (hb_ot_glyph_decompose_conic_to_func_t) conic_to; - funcs.cubic_to = (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to; - hb_face_t *face = hb_test_open_font_file ("fonts/SourceSerifVariable-Roman-VVAR.abc.ttf"); hb_font_t *font = hb_font_create (face); hb_face_destroy (face); @@ -105,8 +95,8 @@ test_hb_ot_glyph_glyf (void) .size = sizeof (str), .consumed = 0 }; - g_assert (!hb_ot_glyph_decompose (font, 4, &funcs, &user_data)); - g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data)); + g_assert (!hb_ot_glyph_decompose (font, 4, funcs, &user_data)); + g_assert (hb_ot_glyph_decompose (font, 3, funcs, &user_data)); char expected[] = "M275,442L275,442Q232,442 198,420Q164,397 145,353Q126,309 126,245L126,245" "Q126,182 147,139Q167,95 204,73Q240,50 287,50L287,50Q330,50 367,70Q404,90 427,128L427,128L451,116" "Q431,54 384,21Q336,-13 266,-13L266,-13Q198,-13 148,18Q97,48 70,104Q43,160 43,236L43,236Q43,314 76,371" @@ -126,7 +116,7 @@ test_hb_ot_glyph_glyf (void) .size = sizeof (str2), .consumed = 0 }; - g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data2)); + g_assert (hb_ot_glyph_decompose (font, 3, funcs, &user_data2)); char expected2[] = "M323,448L323,448Q297,448 271,430Q244,412 227,371Q209,330 209,261L209,261Q209,204 226,166" "Q242,127 273,107Q303,86 344,86L344,86Q378,86 404,101Q430,115 451,137L451,137L488,103" "Q458,42 404,13Q350,-16 279,-16L279,-16Q211,-16 153,13Q95,41 60,99Q25,156 25,241L25,241" @@ -141,12 +131,6 @@ test_hb_ot_glyph_glyf (void) static void test_hb_ot_glyph_cff1 (void) { - hb_ot_glyph_decompose_funcs_t funcs; - funcs.move_to = (hb_ot_glyph_decompose_move_to_func_t) move_to; - funcs.line_to = (hb_ot_glyph_decompose_line_to_func_t) line_to; - funcs.conic_to = (hb_ot_glyph_decompose_conic_to_func_t) conic_to; - funcs.cubic_to = (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to; - hb_face_t *face = hb_test_open_font_file ("fonts/cff1_seac.otf"); hb_font_t *font = hb_font_create (face); hb_face_destroy (face); @@ -157,7 +141,7 @@ test_hb_ot_glyph_cff1 (void) .size = sizeof (str), .consumed = 0 }; - g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data)); + g_assert (hb_ot_glyph_decompose (font, 3, funcs, &user_data)); char expected[] = "M203,367C227,440 248,512 268,588L272,588C293,512 314,440 338,367" "L369,267L172,267M3,0L88,0L151,200L390,200L452,0L541,0L319,656L225,656" "M300,653L342,694L201,861L143,806"; @@ -169,12 +153,6 @@ test_hb_ot_glyph_cff1 (void) static void test_hb_ot_glyph_cff2 (void) { - hb_ot_glyph_decompose_funcs_t funcs; - funcs.move_to = (hb_ot_glyph_decompose_move_to_func_t) move_to; - funcs.line_to = (hb_ot_glyph_decompose_line_to_func_t) line_to; - funcs.conic_to = (hb_ot_glyph_decompose_conic_to_func_t) conic_to; - funcs.cubic_to = (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to; - hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype.abc.otf"); hb_font_t *font = hb_font_create (face); hb_face_destroy (face); @@ -185,7 +163,7 @@ test_hb_ot_glyph_cff2 (void) .size = sizeof (str), .consumed = 0 }; - g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data)); + g_assert (hb_ot_glyph_decompose (font, 3, funcs, &user_data)); char expected[] = "M275,442C303,442 337,435 371,417L325,454L350,366C357,341 370,321 403,321" "C428,321 443,333 448,358C435,432 361,487 272,487C153,487 43,393 43,236" "C43,83 129,-13 266,-13C360,-13 424,33 451,116L427,128C396,78 345,50 287,50" @@ -203,7 +181,7 @@ test_hb_ot_glyph_cff2 (void) .size = sizeof (str2), .consumed = 0 }; - g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data2)); + g_assert (hb_ot_glyph_decompose (font, 3, funcs, &user_data2)); char expected2[] = "M323,448C356,448 380,441 411,427L333,469L339,401C343,322 379,297 420,297" "C458,297 480,314 492,352C486,433 412,501 303,501C148,501 25,406 25,241" "C25,70 143,-16 279,-16C374,-16 447,22 488,103L451,137C423,107 390,86 344,86" @@ -216,10 +194,19 @@ test_hb_ot_glyph_cff2 (void) int main (int argc, char **argv) { + funcs = hb_ot_glyph_decompose_funcs_create (); + hb_ot_glyph_decompose_funcs_set_move_to_func (funcs, (hb_ot_glyph_decompose_move_to_func_t) move_to); + hb_ot_glyph_decompose_funcs_set_line_to_func (funcs, (hb_ot_glyph_decompose_line_to_func_t) line_to); + hb_ot_glyph_decompose_funcs_set_conic_to_func (funcs, (hb_ot_glyph_decompose_conic_to_func_t) conic_to); + hb_ot_glyph_decompose_funcs_set_cubic_to_func (funcs, (hb_ot_glyph_decompose_cubic_to_func_t) cubic_to); + hb_test_init (&argc, &argv); hb_test_add (test_hb_ot_glyph_empty); hb_test_add (test_hb_ot_glyph_glyf); hb_test_add (test_hb_ot_glyph_cff1); hb_test_add (test_hb_ot_glyph_cff2); - return hb_test_run (); + unsigned result = hb_test_run (); + + hb_ot_glyph_decompose_funcs_destroy (funcs); + return result; }