sylware / charfbuzz (public) (License: LGPLv3) (since 2019-09-09) (hash sha1)
partial C implementation of harfbuzz C API for roman scripts

/hb-font.c (80df40b5a885a7e2ae668ef1fc01020247a4e155) (24805 bytes) (mode 100644) (type blob)

/*
Port from c++ is protected by a GNU Lesser GPLv3
Copyright © 2013 Sylvain BERTRAND <sylvain.bertrand@gmail.com>
                                  <sylware@legeek.net>       
*/
#include <stdlib.h>
#include <string.h>

#include <ft2build.h>
#include FT_FREETYPE_H

#include "hb.h"
#include "hb-private.h"
#include "hb-atomic-private.h"
#include "hb-shaper-private.h"
#include "hb-face-private.h"
#include "hb-font-private.h"

void hb_font_destroy(hb_font_t * font)
{
	if (!font)
		return;
	if (hb_atomic_int32_get(&font->ref_cnt) == REF_CNT_INVALID_VAL)
		return;
	hb_atomic_int32_add(&font->ref_cnt, -1);
	if (hb_atomic_int32_get(&font->ref_cnt) > 0)
		return;
	hb_atomic_int32_set(&font->ref_cnt, REF_CNT_INVALID_VAL);

#ifdef HAVE_GRAPHITE2
	if (font->shaper_data.graphite2
	    && font->shaper_data.graphite2 != HB_SHAPER_DATA_INVALID
	    && font->shaper_data.graphite2 != HB_SHAPER_DATA_SUCCEEDED)
		hb_graphite2_shaper_font_data_destroy(font->shaper_data.
						      graphite2);
#endif
#ifdef HAVE_OT
	if (font->shaper_data.ot
	    && font->shaper_data.ot != HB_SHAPER_DATA_INVALID
	    && font->shaper_data.ot != HB_SHAPER_DATA_SUCCEEDED)
		hb_ot_shaper_font_data_destroy(font->shaper_data.ot);
#endif
	if (font->shaper_data.fallback
	    && font->shaper_data.fallback != HB_SHAPER_DATA_INVALID
	    && font->shaper_data.fallback != HB_SHAPER_DATA_SUCCEEDED)
		hb_fallback_shaper_font_data_destroy(font->shaper_data.
						     fallback);

	if (font->destroy)
		font->destroy(font->user_data);

	hb_font_destroy(font->parent);
	hb_face_destroy(font->face);
	hb_font_funcs_destroy(font->klass);
	free(font);
}

hb_bool_t hb_font_get_glyph(hb_font_t * font, hb_codepoint_t unicode,
			    hb_codepoint_t variation_selector,
			    hb_codepoint_t * glyph)
{
	*glyph = 0;
	return font->klass->get.glyph(font, font->user_data, unicode,
				      variation_selector, glyph,
				      font->klass->user_data.glyph);
}

/*Convert from parent-font user-space to our user-space*/
hb_position_t hb_font_parent_scale_x_distance(hb_font_t * font, hb_position_t v)
{
	if (font->parent && font->parent->x_scale != font->x_scale)
		return v * (int64_t) font->x_scale / font->parent->x_scale;
	return v;
}

hb_position_t hb_font_parent_scale_y_distance(hb_font_t * font, hb_position_t v)
{
	if (font->parent && font->parent->y_scale != font->y_scale)
		return v * (int64_t) font->y_scale / font->parent->y_scale;
	return v;
}

hb_position_t hb_font_parent_scale_x_position(hb_font_t * font, hb_position_t v)
{
	return hb_font_parent_scale_x_distance(font, v);
}

hb_position_t hb_font_parent_scale_y_position(hb_font_t * font, hb_position_t v)
{
	return hb_font_parent_scale_y_distance(font, v);
}

void hb_font_parent_scale_position(hb_font_t * font, hb_position_t * x,
				   hb_position_t * y)
{
	*x = hb_font_parent_scale_x_position(font, *x);
	*y = hb_font_parent_scale_y_position(font, *y);
}

void hb_font_parent_scale_distance(hb_font_t * font, hb_position_t * x,
				   hb_position_t * y)
{
	*x = hb_font_parent_scale_x_distance(font, *x);
	*y = hb_font_parent_scale_y_distance(font, *y);
}

hb_position_t hb_font_get_glyph_h_advance(hb_font_t * font,
					  hb_codepoint_t glyph)
{
	return font->klass->get.glyph_h_advance(font, font->user_data, glyph,
						font->klass->user_data.
						glyph_h_advance);
}

hb_position_t hb_font_get_glyph_v_advance(hb_font_t * font,
					  hb_codepoint_t glyph)
{
	return font->klass->get.glyph_v_advance(font, font->user_data, glyph,
						font->klass->user_data.
						glyph_v_advance);
}

hb_bool_t hb_font_get_glyph_h_origin(hb_font_t * font, hb_codepoint_t glyph,
				     hb_position_t * x, hb_position_t * y)
{
	*x = *y = 0;
	return font->klass->get.glyph_h_origin(font, font->user_data, glyph, x,
					       y,
					       font->klass->user_data.
					       glyph_h_origin);
}

hb_bool_t hb_font_get_glyph_v_origin(hb_font_t * font, hb_codepoint_t glyph,
				     hb_position_t * x, hb_position_t * y)
{
	*x = *y = 0;
	return font->klass->get.glyph_v_origin(font, font->user_data, glyph, x,
					       y,
					       font->klass->user_data.
					       glyph_v_origin);
}

hb_position_t hb_font_get_glyph_h_kerning(hb_font_t * font,
					  hb_codepoint_t left_glyph,
					  hb_codepoint_t right_glyph)
{
	return font->klass->get.glyph_h_kerning(font, font->user_data,
						left_glyph, right_glyph,
						font->klass->user_data.
						glyph_h_kerning);
}

hb_position_t hb_font_get_glyph_v_kerning(hb_font_t * font,
					  hb_codepoint_t top_glyph,
					  hb_codepoint_t bottom_glyph)
{
	return font->klass->get.glyph_v_kerning(font, font->user_data,
						top_glyph, bottom_glyph,
						font->klass->user_data.
						glyph_v_kerning);
}

hb_bool_t hb_font_get_glyph_extents(hb_font_t * font, hb_codepoint_t glyph,
				    hb_glyph_extents_t * extents)
{
	memset(extents, 0, sizeof(*extents));
	return font->klass->get.glyph_extents(font, font->user_data, glyph,
					      extents,
					      font->klass->user_data.
					      glyph_extents);
}

hb_bool_t hb_font_get_glyph_contour_point(hb_font_t * font,
					  hb_codepoint_t glyph,
					  unsigned int point_index,
					  hb_position_t * x, hb_position_t * y)
{
	*x = *y = 0;
	return font->klass->get.glyph_contour_point(font, font->user_data,
						    glyph, point_index, x, y,
						    font->klass->user_data.
						    glyph_contour_point);
}

hb_bool_t hb_font_get_glyph_name(hb_font_t * font, hb_codepoint_t glyph,
				 char *name, unsigned int size)
{
	if (size)
		*name = '\0';
	return font->klass->get.glyph_name(font, font->user_data, glyph, name,
					   size,
					   font->klass->user_data.glyph_name);
}

hb_bool_t hb_font_get_glyph_from_name(hb_font_t * font, const char *name,
				      int len /*-1 means nul-terminated*/ ,
				      hb_codepoint_t * glyph)
{
	*glyph = 0;
	if (len == -1)
		len = strlen(name);
	return font->klass->get.glyph_from_name(font, font->user_data, name,
						len, glyph,
						font->klass->user_data.
						glyph_from_name);
}

static hb_bool_t hb_font_get_glyph_nil(hb_font_t * font,
				       void *font_data HB_UNUSED,
				       hb_codepoint_t unicode,
				       hb_codepoint_t variation_selector,
				       hb_codepoint_t * glyph,
				       void *user_data HB_UNUSED)
{
	if (font->parent)
		return hb_font_get_glyph(font->parent, unicode,
					 variation_selector, glyph);

	*glyph = 0;
	return FALSE;
}

static hb_position_t hb_font_get_glyph_h_advance_nil(hb_font_t * font,
						     void *font_data HB_UNUSED,
						     hb_codepoint_t glyph,
						     void *user_data HB_UNUSED)
{
	if (font->parent)
		return hb_font_parent_scale_x_distance(font,
						       hb_font_get_glyph_h_advance
						       (font->parent, glyph));
	return font->x_scale;
}

static hb_position_t hb_font_get_glyph_v_advance_nil(hb_font_t * font,
						     void *font_data HB_UNUSED,
						     hb_codepoint_t glyph,
						     void *user_data HB_UNUSED)
{
	if (font->parent)
		return hb_font_parent_scale_y_distance(font,
						       hb_font_get_glyph_v_advance
						       (font->parent, glyph));
	return font->y_scale;
}

static hb_bool_t hb_font_get_glyph_h_origin_nil(hb_font_t * font,
						void *font_data HB_UNUSED,
						hb_codepoint_t glyph,
						hb_position_t * x,
						hb_position_t * y,
						void *user_data HB_UNUSED)
{
	if (font->parent) {
		hb_bool_t ret;

		ret = hb_font_get_glyph_h_origin(font->parent, glyph, x, y);
		if (ret)
			hb_font_parent_scale_position(font, x, y);
		return ret;
	}

	*x = *y = 0;
	return FALSE;
}

static hb_bool_t hb_font_get_glyph_v_origin_nil(hb_font_t * font,
						void *font_data HB_UNUSED,
						hb_codepoint_t glyph,
						hb_position_t * x,
						hb_position_t * y,
						void *user_data HB_UNUSED)
{
	if (font->parent) {
		hb_bool_t ret;

		ret = hb_font_get_glyph_v_origin(font->parent, glyph, x, y);
		if (ret)
			hb_font_parent_scale_position(font, x, y);
		return ret;
	}

	*x = *y = 0;
	return FALSE;
}

static hb_position_t hb_font_get_glyph_h_kerning_nil(hb_font_t * font,
						     void *font_data HB_UNUSED,
						     hb_codepoint_t left_glyph,
						     hb_codepoint_t right_glyph,
						     void *user_data HB_UNUSED)
{
	if (font->parent)
		return hb_font_parent_scale_x_distance(font,
						       hb_font_get_glyph_h_kerning
						       (font->parent,
							left_glyph,
							right_glyph));
	return 0;
}

static hb_position_t hb_font_get_glyph_v_kerning_nil(hb_font_t * font,
						     void *font_data HB_UNUSED,
						     hb_codepoint_t top_glyph,
						     hb_codepoint_t
						     bottom_glyph,
						     void *user_data HB_UNUSED)
{
	if (font->parent)
		return hb_font_parent_scale_y_distance(font,
						       hb_font_get_glyph_v_kerning
						       (font->parent, top_glyph,
							bottom_glyph));
	return 0;
}

static hb_bool_t hb_font_get_glyph_extents_nil(hb_font_t * font,
					       void *font_data HB_UNUSED,
					       hb_codepoint_t glyph,
					       hb_glyph_extents_t * extents,
					       void *user_data HB_UNUSED)
{
	if (font->parent) {
		hb_bool_t ret;

		ret = hb_font_get_glyph_extents(font->parent, glyph, extents);
		if (ret) {
			hb_font_parent_scale_position(font, &extents->x_bearing,
						      &extents->y_bearing);
			hb_font_parent_scale_distance(font, &extents->width,
						      &extents->height);
		}
		return ret;
	}

	memset(extents, 0, sizeof(*extents));
	return FALSE;
}

static hb_bool_t hb_font_get_glyph_contour_point_nil(hb_font_t * font,
						     void *font_data HB_UNUSED,
						     hb_codepoint_t glyph,
						     unsigned int point_index,
						     hb_position_t * x,
						     hb_position_t * y,
						     void *user_data HB_UNUSED)
{
	if (font->parent) {
		hb_bool_t ret;

		ret =
		    hb_font_get_glyph_contour_point(font->parent, glyph,
						    point_index, x, y);
		if (ret)
			hb_font_parent_scale_position(font, x, y);
		return ret;
	}

	*x = *y = 0;
	return FALSE;
}

static hb_bool_t hb_font_get_glyph_name_nil(hb_font_t * font,
					    void *font_data HB_UNUSED,
					    hb_codepoint_t glyph, char *name,
					    unsigned int size,
					    void *user_data HB_UNUSED)
{
	if (font->parent)
		return hb_font_get_glyph_name(font->parent, glyph, name, size);

	if (size)
		*name = '\0';
	return FALSE;
}

static hb_bool_t hb_font_get_glyph_from_name_nil(hb_font_t * font,
						 void *font_data HB_UNUSED,
						 const char *name,
						 int len
						 /*-1 means nul-terminated*/ ,
						 hb_codepoint_t * glyph,
						 void *user_data HB_UNUSED)
{
	if (font->parent)
		return hb_font_get_glyph_from_name(font->parent, name, len,
						   glyph);

	*glyph = 0;
	return FALSE;
}

/*A bit higher-level, and with fallback*/

void hb_font_get_glyph_advance_for_direction(hb_font_t * font,
					     hb_codepoint_t glyph,
					     hb_direction_t direction,
					     hb_position_t * x,
					     hb_position_t * y)
{
	if (HB_DIRECTION_IS_HORIZONTAL(direction)) {
		*x = hb_font_get_glyph_h_advance(font, glyph);
		*y = 0;
	} else {
		*x = 0;
		*y = hb_font_get_glyph_v_advance(font, glyph);
	}
}

/*Internal only*/
static void
hb_font_guess_v_origin_minus_h_origin(hb_font_t * font, hb_codepoint_t glyph,
				      hb_position_t * x, hb_position_t * y)
{
	*x = hb_font_get_glyph_h_advance(font, glyph) / 2;

	/*TODO:use font_metics.ascent */
	*y = font->y_scale;
}

void hb_font_get_glyph_origin_for_direction(hb_font_t * font,
					    hb_codepoint_t glyph,
					    hb_direction_t direction,
					    hb_position_t * x,
					    hb_position_t * y)
{
	if (HB_DIRECTION_IS_HORIZONTAL(direction)) {
		if (!hb_font_get_glyph_h_origin(font, glyph, x, y)
		    && hb_font_get_glyph_v_origin(font, glyph, x, y)) {
			hb_position_t dx, dy;
			hb_font_guess_v_origin_minus_h_origin(font, glyph, &dx,
							      &dy);
			*x -= dx;
			*y -= dy;
		}
	} else {
		if (!hb_font_get_glyph_v_origin(font, glyph, x, y)
		    && hb_font_get_glyph_h_origin(font, glyph, x, y)) {
			hb_position_t dx, dy;
			hb_font_guess_v_origin_minus_h_origin(font, glyph, &dx,
							      &dy);
			*x += dx;
			*y += dy;
		}
	}
}

void hb_font_subtract_glyph_origin_for_direction(hb_font_t * font,
						 hb_codepoint_t glyph,
						 hb_direction_t direction,
						 hb_position_t * x,
						 hb_position_t * y)
{
	hb_position_t origin_x, origin_y;

	hb_font_get_glyph_origin_for_direction(font, glyph, direction,
					       &origin_x, &origin_y);

	*x -= origin_x;
	*y -= origin_y;
}

/*XXX:should go in lib "global init"*/
static hb_font_funcs_t hb_font_funcs_nil = {
	REF_CNT_INVALID_VAL,	/*ref_cnt */
	TRUE,			/*immutable */
	{			/*get */
	 hb_font_get_glyph_nil,
	 hb_font_get_glyph_h_advance_nil,
	 hb_font_get_glyph_v_advance_nil,
	 hb_font_get_glyph_h_origin_nil,
	 hb_font_get_glyph_v_origin_nil,
	 hb_font_get_glyph_h_kerning_nil,
	 hb_font_get_glyph_v_kerning_nil,
	 hb_font_get_glyph_extents_nil,
	 hb_font_get_glyph_contour_point_nil,
	 hb_font_get_glyph_name_nil,
	 hb_font_get_glyph_from_name_nil,
	 },
	{			/*user_data */
	 NULL,			/*glyph */
	 NULL,			/*glyph_h_advance */
	 NULL,			/*glyph_v_advance */
	 NULL,			/*glyph_h_origin */
	 NULL,			/*glyph_v_origin */
	 NULL,			/*glyph_h_kerning */
	 NULL,			/*glyph_v_kerning */
	 NULL,			/*glyph_extents */
	 NULL,			/*glyph_contour_po */
	 NULL,			/*glyph_name */
	 NULL,			/*glyph_from_name */
	 },
	{			/*destroy */
	 NULL,			/*glyph */
	 NULL,			/*glyph_h_advance */
	 NULL,			/*glyph_v_advance */
	 NULL,			/*glyph_h_origin */
	 NULL,			/*glyph_v_origin */
	 NULL,			/*glyph_h_kerning */
	 NULL,			/*glyph_v_kerning */
	 NULL,			/*glyph_extents */
	 NULL,			/*glyph_contour_po */
	 NULL,			/*glyph_name */
	 NULL,			/*glyph_from_name */
	 }
};

/*XXX:should go in lib "global init"*/
static hb_font_t hb_font_nil = {
	REF_CNT_INVALID_VAL,	/*ref_cnt */
	TRUE,			/*immutable */
	NULL,			/*parent */
	NULL,			/*face */
	0,			/*x_scale */
	0,			/*y_scale */
	0,			/*x_ppem */
	0,			/*y_ppem */
	NULL,			/*klass */
	NULL,			/*user_data */
	NULL,			/*destroy */
	{
#ifdef HAVE_GRAPHITE2
	 HB_SHAPER_DATA_INVALID,
#endif
#ifdef HAVE_OT
	 HB_SHAPER_DATA_INVALID,
#endif
	 HB_SHAPER_DATA_INVALID	/*fallback */
	 },
};

hb_font_funcs_t *hb_font_funcs_get_empty(void)
{
	return &hb_font_funcs_nil;
}

hb_font_t *hb_font_get_empty(void)
{
	return &hb_font_nil;
}

void hb_font_funcs_destroy(hb_font_funcs_t * ffuncs)
{
	if (!ffuncs)
		return;
	if (hb_atomic_int32_get(&ffuncs->ref_cnt) == REF_CNT_INVALID_VAL)
		return;
	hb_atomic_int32_add(&ffuncs->ref_cnt, -1);
	if (hb_atomic_int32_get(&ffuncs->ref_cnt) > 0)
		return;
	hb_atomic_int32_set(&ffuncs->ref_cnt, REF_CNT_INVALID_VAL);

	if (ffuncs->destroy.glyph)
		ffuncs->destroy.glyph(ffuncs->user_data.glyph);
	if (ffuncs->destroy.glyph_h_advance)
		ffuncs->destroy.glyph_h_advance(ffuncs->user_data.
						glyph_h_advance);
	if (ffuncs->destroy.glyph_v_advance)
		ffuncs->destroy.glyph_v_advance(ffuncs->user_data.
						glyph_v_advance);
	if (ffuncs->destroy.glyph_h_origin)
		ffuncs->destroy.glyph_h_origin(ffuncs->user_data.
					       glyph_h_origin);
	if (ffuncs->destroy.glyph_v_origin)
		ffuncs->destroy.glyph_v_origin(ffuncs->user_data.
					       glyph_v_origin);
	if (ffuncs->destroy.glyph_h_kerning)
		ffuncs->destroy.glyph_h_kerning(ffuncs->user_data.
						glyph_h_kerning);
	if (ffuncs->destroy.glyph_v_kerning)
		ffuncs->destroy.glyph_v_kerning(ffuncs->user_data.
						glyph_v_kerning);
	if (ffuncs->destroy.glyph_extents)
		ffuncs->destroy.glyph_extents(ffuncs->user_data.glyph_extents);
	if (ffuncs->destroy.glyph_contour_point)
		ffuncs->destroy.glyph_contour_point(ffuncs->user_data.
						    glyph_contour_point);
	if (ffuncs->destroy.glyph_name)
		ffuncs->destroy.glyph_name(ffuncs->user_data.glyph_name);
	if (ffuncs->destroy.glyph_from_name)
		ffuncs->destroy.glyph_from_name(ffuncs->user_data.
						glyph_from_name);

	free(ffuncs);
}

hb_font_t *hb_font_create(hb_face_t * face)
{
	hb_font_t *font;

	if (!face)
		face = hb_face_get_empty();

	if (face->ref_cnt == REF_CNT_INVALID_VAL)
		return hb_font_get_empty();

	font = calloc(1, sizeof(*font));
	if (!font)
		return hb_font_get_empty();

	hb_atomic_int32_set(&font->ref_cnt, 1);
	hb_face_make_immutable(face);
	font->face = hb_face_reference(face);
	font->klass = hb_font_funcs_get_empty();
	return font;
}

void hb_font_funcs_set_glyph_func(hb_font_funcs_t * ffuncs,
				  hb_font_get_glyph_func_t func,
				  void *user_data, hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph)
		ffuncs->destroy.glyph(ffuncs->user_data.glyph);

	if (func) {
		ffuncs->get.glyph = func;
		ffuncs->user_data.glyph = user_data;
		ffuncs->destroy.glyph = destroy;
	} else {
		ffuncs->get.glyph = hb_font_get_glyph_nil;
		ffuncs->user_data.glyph = NULL;
		ffuncs->destroy.glyph = NULL;
	}
}

void hb_font_funcs_set_glyph_h_advance_func(hb_font_funcs_t * ffuncs,
					    hb_font_get_glyph_h_advance_func_t
					    func, void *user_data,
					    hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_h_advance)
		ffuncs->destroy.glyph_h_advance(ffuncs->user_data.
						glyph_h_advance);

	if (func) {
		ffuncs->get.glyph_h_advance = func;
		ffuncs->user_data.glyph_h_advance = user_data;
		ffuncs->destroy.glyph_h_advance = destroy;
	} else {
		ffuncs->get.glyph_h_advance = hb_font_get_glyph_h_advance_nil;
		ffuncs->user_data.glyph_h_advance = NULL;
		ffuncs->destroy.glyph_h_advance = NULL;
	}
}

void hb_font_funcs_set_glyph_v_advance_func(hb_font_funcs_t * ffuncs,
					    hb_font_get_glyph_v_advance_func_t
					    func, void *user_data,
					    hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_v_advance)
		ffuncs->destroy.glyph_v_advance(ffuncs->user_data.
						glyph_v_advance);

	if (func) {
		ffuncs->get.glyph_v_advance = func;
		ffuncs->user_data.glyph_v_advance = user_data;
		ffuncs->destroy.glyph_v_advance = destroy;
	} else {
		ffuncs->get.glyph_v_advance = hb_font_get_glyph_v_advance_nil;
		ffuncs->user_data.glyph_v_advance = NULL;
		ffuncs->destroy.glyph_v_advance = NULL;
	}
}

void hb_font_funcs_set_glyph_h_origin_func(hb_font_funcs_t * ffuncs,
					   hb_font_get_glyph_h_origin_func_t
					   func, void *user_data,
					   hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_h_origin)
		ffuncs->destroy.glyph_h_origin(ffuncs->user_data.
					       glyph_h_origin);

	if (func) {
		ffuncs->get.glyph_h_origin = func;
		ffuncs->user_data.glyph_h_origin = user_data;
		ffuncs->destroy.glyph_h_origin = destroy;
	} else {
		ffuncs->get.glyph_h_origin = hb_font_get_glyph_h_origin_nil;
		ffuncs->user_data.glyph_h_origin = NULL;
		ffuncs->destroy.glyph_h_origin = NULL;
	}
}

void hb_font_funcs_set_glyph_v_origin_func(hb_font_funcs_t * ffuncs,
					   hb_font_get_glyph_v_origin_func_t
					   func, void *user_data,
					   hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_v_origin)
		ffuncs->destroy.glyph_v_origin(ffuncs->user_data.
					       glyph_v_origin);

	if (func) {
		ffuncs->get.glyph_v_origin = func;
		ffuncs->user_data.glyph_v_origin = user_data;
		ffuncs->destroy.glyph_v_origin = destroy;
	} else {
		ffuncs->get.glyph_v_origin = hb_font_get_glyph_v_origin_nil;
		ffuncs->user_data.glyph_v_origin = NULL;
		ffuncs->destroy.glyph_v_origin = NULL;
	}
}

void hb_font_funcs_set_glyph_h_kerning_func(hb_font_funcs_t * ffuncs,
					    hb_font_get_glyph_h_kerning_func_t
					    func, void *user_data,
					    hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_h_kerning)
		ffuncs->destroy.glyph_h_kerning(ffuncs->user_data.
						glyph_h_kerning);

	if (func) {
		ffuncs->get.glyph_h_kerning = func;
		ffuncs->user_data.glyph_h_kerning = user_data;
		ffuncs->destroy.glyph_h_kerning = destroy;
	} else {
		ffuncs->get.glyph_h_kerning = hb_font_get_glyph_h_kerning_nil;
		ffuncs->user_data.glyph_h_kerning = NULL;
		ffuncs->destroy.glyph_h_kerning = NULL;
	}
}

void hb_font_funcs_set_glyph_v_kerning_func(hb_font_funcs_t * ffuncs,
					    hb_font_get_glyph_v_kerning_func_t
					    func, void *user_data,
					    hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_v_kerning)
		ffuncs->destroy.glyph_v_kerning(ffuncs->user_data.
						glyph_v_kerning);

	if (func) {
		ffuncs->get.glyph_v_kerning = func;
		ffuncs->user_data.glyph_v_kerning = user_data;
		ffuncs->destroy.glyph_v_kerning = destroy;
	} else {
		ffuncs->get.glyph_v_kerning = hb_font_get_glyph_v_kerning_nil;
		ffuncs->user_data.glyph_v_kerning = NULL;
		ffuncs->destroy.glyph_v_kerning = NULL;
	}
}

void hb_font_funcs_set_glyph_extents_func(hb_font_funcs_t * ffuncs,
					  hb_font_get_glyph_extents_func_t func,
					  void *user_data,
					  hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_extents)
		ffuncs->destroy.glyph_extents(ffuncs->user_data.glyph_extents);

	if (func) {
		ffuncs->get.glyph_extents = func;
		ffuncs->user_data.glyph_extents = user_data;
		ffuncs->destroy.glyph_extents = destroy;
	} else {
		ffuncs->get.glyph_extents = hb_font_get_glyph_extents_nil;
		ffuncs->user_data.glyph_extents = NULL;
		ffuncs->destroy.glyph_extents = NULL;
	}
}

void hb_font_funcs_set_glyph_contour_point_func(hb_font_funcs_t * ffuncs,
						hb_font_get_glyph_contour_point_func_t
						func, void *user_data,
						hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_contour_point)
		ffuncs->destroy.glyph_contour_point(ffuncs->user_data.
						    glyph_contour_point);

	if (func) {
		ffuncs->get.glyph_contour_point = func;
		ffuncs->user_data.glyph_contour_point = user_data;
		ffuncs->destroy.glyph_contour_point = destroy;
	} else {
		ffuncs->get.glyph_contour_point =
		    hb_font_get_glyph_contour_point_nil;
		ffuncs->user_data.glyph_contour_point = NULL;
		ffuncs->destroy.glyph_contour_point = NULL;
	}
}

void hb_font_funcs_set_glyph_name_func(hb_font_funcs_t * ffuncs,
				       hb_font_get_glyph_name_func_t func,
				       void *user_data,
				       hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_name)
		ffuncs->destroy.glyph_name(ffuncs->user_data.glyph_name);

	if (func) {
		ffuncs->get.glyph_name = func;
		ffuncs->user_data.glyph_name = user_data;
		ffuncs->destroy.glyph_name = destroy;
	} else {
		ffuncs->get.glyph_name = hb_font_get_glyph_name_nil;
		ffuncs->user_data.glyph_name = NULL;
		ffuncs->destroy.glyph_name = NULL;
	}
}

void hb_font_funcs_set_glyph_from_name_func(hb_font_funcs_t * ffuncs,
					    hb_font_get_glyph_from_name_func_t
					    func, void *user_data,
					    hb_destroy_func_t destroy)
{
	if (ffuncs->immutable) {
		if (destroy)
			destroy(user_data);
		return;
	}

	if (ffuncs->destroy.glyph_from_name)
		ffuncs->destroy.glyph_from_name(ffuncs->user_data.
						glyph_from_name);

	if (func) {
		ffuncs->get.glyph_from_name = func;
		ffuncs->user_data.glyph_from_name = user_data;
		ffuncs->destroy.glyph_from_name = destroy;
	} else {
		ffuncs->get.glyph_from_name = hb_font_get_glyph_from_name_nil;
		ffuncs->user_data.glyph_from_name = NULL;
		ffuncs->destroy.glyph_from_name = NULL;
	}
}

hb_font_funcs_t *hb_font_funcs_create(void)
{
	hb_font_funcs_t *ffuncs;

	ffuncs = calloc(1, sizeof(*ffuncs));
	if (!ffuncs)
		return hb_font_funcs_get_empty();
	hb_atomic_int32_set(&ffuncs->ref_cnt, 1);

	ffuncs->get = hb_font_funcs_nil.get;
	return ffuncs;
}

void hb_font_set_funcs(hb_font_t * font, hb_font_funcs_t * klass,
		       void *font_data, hb_destroy_func_t destroy)
{
	if (font->immutable) {
		if (destroy)
			destroy(font_data);
		return;
	}

	if (font->destroy)
		font->destroy(font->user_data);

	if (!klass)
		klass = hb_font_funcs_get_empty();

	hb_font_funcs_reference(klass);
	hb_font_funcs_destroy(font->klass);
	font->klass = klass;
	font->user_data = font_data;
	font->destroy = destroy;
}

hb_font_funcs_t *hb_font_funcs_reference(hb_font_funcs_t * ffuncs)
{
	if (hb_atomic_int32_get(&ffuncs->ref_cnt) != REF_CNT_INVALID_VAL)
		hb_atomic_int32_add(&ffuncs->ref_cnt, 1);
	return ffuncs;
}

void hb_font_set_scale(hb_font_t * font, int x_scale, int y_scale)
{
	if (font->immutable)
		return;

	font->x_scale = x_scale;
	font->y_scale = y_scale;
}

void hb_font_set_ppem(hb_font_t * font, unsigned int x_ppem,
		      unsigned int y_ppem)
{
	if (font->immutable)
		return;

	font->x_ppem = x_ppem;
	font->y_ppem = y_ppem;
}


Mode Type Size Ref File
100644 blob 215 9381999f3aeff23f92475e7aef7a141e7b31c938 ABBREVIATIONS
100644 blob 120 b5b8344f6c0ab2a879570909dfc67753d036ea10 FIXME
100644 blob 241 9c28271a27b1d0acd9a2a8f412a4f107767e4df2 README
100644 blob 240 18919b3e2f18beb79b9077d0fde23d77d8e115b0 harfbuzz.pc.in
100644 blob 1192 833e0c5e348c3c7663711b84cd05baf7f2ec4b6b hb-atomic-private.h
100644 blob 119 154fbbb0957b9a8247993436984ab9cda943720c hb-blob-private.h
100644 blob 4603 6cc79394dfa9884d604a6e958268d841c370f3f1 hb-blob.c
100644 blob 3534 ef3fc98c05de6d2fa43f6303d6419f6620d474bf hb-blob.h
100644 blob 1326 3b93b65480793ced5bdd1c6e2587d3c2a66f3a53 hb-buffer-private.h
100644 blob 11355 24118c098a5412ec39226fe2a18b7e192dd902b2 hb-buffer.c
100644 blob 10513 d3a2512d800fde857f72764b150aaa392fd8b15d hb-buffer.h
100644 blob 3302 92b54dbaf82493e6f281bb20231df3e1ecb9d63c hb-common.c
100644 blob 13612 af17d780c27fc757441d5ce0fce1db120bd87c9b hb-common.h
100644 blob 1746 82066e4e0dc0b2770a8800f9a9fb417e14d9d7d0 hb-coretext.h
100644 blob 1584 30ae4b1caf76dd03cc682eda7458728b5380ad6c hb-deprecated.h
100644 blob 1175 5e43e30983efc3b0936efbdaf3921eecbfc1635a hb-face-private.h
100644 blob 5222 770d81b8c6b9bafd4c9eb018f1420e369ba09647 hb-face.c
100644 blob 2985 91237b70850bc9750516c73aca7051228e5c22c1 hb-face.h
100644 blob 3268 cdc0ae9a6a50a1b444db3a148db08f01bececa7c hb-fallback-shape.c
100644 blob 2875 dce2474d44b59f5349528718422dd9af7975cf52 hb-font-private.h
100644 blob 24805 80df40b5a885a7e2ae668ef1fc01020247a4e155 hb-font.c
100644 blob 13844 c3165e1d74c123fc1aa289ce503e38f870b43611 hb-font.h
100644 blob 2502 551d6e47f67a13ce27d21f4bfadc86a8091507ce hb-ft.c
100644 blob 3790 dc8ef8558484cb4faaa3cbe6906a84d8005a3a10 hb-ft.h
100644 blob 3637 1468f247a5f2d3c48a0de2a9a9156e17fe4521dc hb-glib.c
100644 blob 1627 a6b6ff82026f3a0016eab1f5201e13afbde93feb hb-glib.h
100644 blob 3140 0ea3b12cf1676dc6a2da8e546d9d6b7cbc60ed41 hb-gobject-structs.h
100644 blob 1334 ea1bd25df82d46a222436a1ad078d0fc95d5c303 hb-gobject.h
100644 blob 1461 122c3e476366b341bc74ced282f424d863255ca7 hb-graphite2.h
100644 blob 1525 2db6a7b6797bddc46688f7b583de991a956a2e2a hb-icu.h
100644 blob 2133 3e4514517efb14434d2ac3a08b82a06eedf8ffaa hb-open-file-private.h
100644 blob 2674 18b89705a885521c6d8d08448eac1f65395a3a0d hb-open-file.c
100644 blob 65 642c3d3d45fdc42619d000cc9f7b3c890bdc0190 hb-ot-face-private.h
100644 blob 1365 80eaa54b1add7333d975fbee27c00bc777f3e046 hb-ot-font.h
100644 blob 2784 91122b51fbb221aeb52634439405e47e700a1e80 hb-ot-layout.c
100644 blob 9658 eb23d45b68aabd24538b46bb482ac187c5f61d73 hb-ot-layout.h
100644 blob 1712 7b1bcc0637808bbbceda020409b61d947237d925 hb-ot-shape.h
100644 blob 730 bfa3d45093e12bf9aa7a0a8920d6a573145e1f99 hb-ot-tag.c
100644 blob 1728 54fb747f582301c6d46bbe33ede8a2ef127dc999 hb-ot-tag.h
100644 blob 1348 47c92a58e4b7ddc3225e7cb65ce20aafceb3b81a hb-ot.h
100644 blob 2541 827e6c9b4e8f90ba02b24a259ddd10fa8b7f34cb hb-private.h
100644 blob 3828 2164c1a6549afc39d9f3c6e82bb6ca8f0b8f732d hb-set.h
100644 blob 1417 62ff962974ac05946c099ea7d4fb3473bd95f6ba hb-shape-plan-private.h
100644 blob 14266 11f405cdb548fd9ac6aaebda60059202512d5831 hb-shape-plan.c
100644 blob 2837 aa5e0c7d6f519b841c4519811f18845cdf92ee77 hb-shape-plan.h
100644 blob 5057 00628cd3079786a1cf9c2534458ceeac98bcc9b6 hb-shape.c
100644 blob 2170 53bb845bf48f40758c69ae31a399054b43690413 hb-shape.h
100644 blob 1015 ee80e4526b63481a48b348fe279c15e757363776 hb-shaper-private.h
100644 blob 2250 8073a7cc168f5624424250b6a81f0440243fc015 hb-shaper.c
100644 blob 1210 276c97e391a35215a71ad538b77696c69dd16eb1 hb-unicode-private.h
100644 blob 7644 53862e6db7e90afb058efbc0f0bad27cd25b28c1 hb-unicode.c
100644 blob 14695 33b68aa0d85b666090c2820e46c7a5242992b228 hb-unicode.h
100644 blob 1391 4e4ef9986a62e3df91d1d4ea048ec89d3526498d hb-uniscribe.h
100644 blob 4990 319e112fe2de8d3ccb9249fec39a96971d13f1fc hb-utf-private.c
100644 blob 1246 dca4a18b95114b239706d6917a6c74eac87b3279 hb-utf-private.h
100644 blob 1887 0ffd889b278962a33f2b8882e1dba4b41af6b672 hb-version.h.in
100644 blob 1521 7402034f4379372b3a7d0529142e4c87e4b4599d hb.h
100644 blob 7651 65c5ca88a67c30becee01c5a8816d964b03862f9 license.md
100755 blob 5867 d786a7162742b83e67d6039f51d97c6e34d39768 make
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/charfbuzz

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/charfbuzz

Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/charfbuzz

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main