/* KerningPair.c generated by valac 0.56.17, the Vala compiler
 * generated from KerningPair.vala, do not modify */

/*
Copyright (C) 2014 Johan Mattsson

This library is free software; you can redistribute it and/or modify 
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation; either version 3 of the 
License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
Lesser General Public License for more details.
*/

#include "birdfont.h"
#include <glib-object.h>
#include <glib.h>
#include <gee.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	BIRD_FONT_KERNING_PAIR_0_PROPERTY,
	BIRD_FONT_KERNING_PAIR_NUM_PROPERTIES
};
static GParamSpec* bird_font_kerning_pair_properties[BIRD_FONT_KERNING_PAIR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer bird_font_kerning_pair_parent_class = NULL;

static gint __lambda52_ (BirdFontKerningPair* self,
                  BirdFontKerning* a,
                  BirdFontKerning* b);
static gint ___lambda52__gcompare_data_func (gconstpointer a,
                                      gconstpointer b,
                                      gpointer self);
static void bird_font_kerning_pair_finalize (GObject * obj);
static GType bird_font_kerning_pair_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

BirdFontKerningPair*
bird_font_kerning_pair_construct (GType object_type,
                                  BirdFontGlyph* left)
{
	BirdFontKerningPair * self = NULL;
	BirdFontGlyph* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	g_return_val_if_fail (left != NULL, NULL);
	self = (BirdFontKerningPair*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (left);
	_g_object_unref0 (self->character);
	self->character = _tmp0_;
	_tmp1_ = gee_array_list_new (BIRD_FONT_TYPE_GLYPH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->right);
	self->right = _tmp1_;
	_tmp2_ = gee_array_list_new (BIRD_FONT_TYPE_KERNING, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->kerning);
	self->kerning = _tmp2_;
	return self;
}

BirdFontKerningPair*
bird_font_kerning_pair_new (BirdFontGlyph* left)
{
	return bird_font_kerning_pair_construct (BIRD_FONT_TYPE_KERNING_PAIR, left);
}

void
bird_font_kerning_pair_add_unique (BirdFontKerningPair* self,
                                   BirdFontGlyph* g,
                                   gdouble k)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (g != NULL);
	_tmp0_ = self->right;
	if (!gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp0_, G_TYPE_CHECK_INSTANCE_CAST (g, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph))) {
		GeeArrayList* _tmp1_;
		GeeArrayList* _tmp2_;
		BirdFontKerning* _tmp3_;
		BirdFontKerning* _tmp4_;
		_tmp1_ = self->right;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp1_, G_TYPE_CHECK_INSTANCE_CAST (g, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
		_tmp2_ = self->kerning;
		_tmp3_ = bird_font_kerning_new_for_glyph (g, k);
		_tmp4_ = _tmp3_;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp2_, _tmp4_);
		_g_object_unref0 (_tmp4_);
	}
}

static gint
__lambda52_ (BirdFontKerningPair* self,
             BirdFontKerning* a,
             BirdFontKerning* b)
{
	BirdFontKerning* first = NULL;
	BirdFontKerning* next = NULL;
	BirdFontKerning* _tmp0_;
	BirdFontKerning* _tmp1_;
	GCompareFunc _tmp2_;
	BirdFontGlyph* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	BirdFontGlyph* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gint _tmp9_;
	gint result;
	g_return_val_if_fail (a != NULL, 0);
	g_return_val_if_fail (b != NULL, 0);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (a, BIRD_FONT_TYPE_KERNING, BirdFontKerning));
	_g_object_unref0 (first);
	first = _tmp0_;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (b, BIRD_FONT_TYPE_KERNING, BirdFontKerning));
	_g_object_unref0 (next);
	next = _tmp1_;
	_tmp2_ = ((GCompareFunc) g_strcmp0);
	_tmp3_ = first->glyph;
	_tmp4_ = bird_font_glyph_get_unichar_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
	_tmp5_ = _tmp4_;
	_tmp6_ = next->glyph;
	_tmp7_ = bird_font_glyph_get_unichar_string (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
	_tmp8_ = _tmp7_;
	_tmp9_ = _tmp2_ (_tmp5_, _tmp8_);
	_g_free0 (_tmp8_);
	_g_free0 (_tmp5_);
	result = _tmp9_;
	_g_object_unref0 (next);
	_g_object_unref0 (first);
	return result;
}

static gint
___lambda52__gcompare_data_func (gconstpointer a,
                                 gconstpointer b,
                                 gpointer self)
{
	gint result;
	result = __lambda52_ ((BirdFontKerningPair*) self, (BirdFontKerning*) a, (BirdFontKerning*) b);
	return result;
}

void
bird_font_kerning_pair_sort (BirdFontKerningPair* self)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->kerning;
	gee_list_sort ((GeeList*) _tmp0_, ___lambda52__gcompare_data_func, g_object_ref (self), g_object_unref);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static gchar*
double_to_string (gdouble self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp1__length1;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = G_ASCII_DTOSTR_BUF_SIZE;
	_tmp2_ = g_ascii_dtostr (_tmp1_, (gint) G_ASCII_DTOSTR_BUF_SIZE, self);
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	result = _tmp4_;
	return result;
}

void
bird_font_kerning_pair_print (BirdFontKerningPair* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->kerning;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		g_warning ("KerningPair.vala:50: No pairs.");
	}
	{
		GeeArrayList* _k_list = NULL;
		GeeArrayList* _tmp3_;
		gint _k_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _k_index = 0;
		_tmp3_ = self->kerning;
		_k_list = _tmp3_;
		_tmp4_ = _k_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_k_size = _tmp6_;
		_k_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			BirdFontKerning* k = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			BirdFontKerning* _tmp11_;
			BirdFontGlyph* _tmp12_;
			_k_index = _k_index + 1;
			_tmp7_ = _k_index;
			_tmp8_ = _k_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _k_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _k_index);
			k = (BirdFontKerning*) _tmp10_;
			_tmp11_ = k;
			_tmp12_ = _tmp11_->glyph;
			if (_tmp12_ != NULL) {
				FILE* _tmp13_;
				BirdFontGlyph* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				const gchar* _tmp17_;
				BirdFontKerning* _tmp18_;
				BirdFontGlyph* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				const gchar* _tmp22_;
				BirdFontKerning* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				gchar* _tmp26_;
				gchar* _tmp27_;
				_tmp13_ = stdout;
				_tmp14_ = self->character;
				_tmp15_ = bird_font_font_display_get_name ((BirdFontFontDisplay*) _tmp14_);
				_tmp16_ = _tmp15_;
				_tmp17_ = string_to_string (_tmp16_);
				_tmp18_ = k;
				_tmp19_ = _tmp18_->glyph;
				_tmp20_ = bird_font_font_display_get_name ((BirdFontFontDisplay*) G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
				_tmp21_ = _tmp20_;
				_tmp22_ = string_to_string (_tmp21_);
				_tmp23_ = k;
				_tmp24_ = double_to_string (_tmp23_->val);
				_tmp25_ = _tmp24_;
				_tmp26_ = g_strconcat (_tmp17_, " <-> ", _tmp22_, ": ", _tmp25_, "\n", NULL);
				_tmp27_ = _tmp26_;
				fprintf (_tmp13_, "%s", _tmp27_);
				_g_free0 (_tmp27_);
				_g_free0 (_tmp25_);
				_g_free0 (_tmp21_);
				_g_free0 (_tmp16_);
			}
			_g_object_unref0 (k);
		}
	}
}

static void
bird_font_kerning_pair_class_init (BirdFontKerningPairClass * klass,
                                   gpointer klass_data)
{
	bird_font_kerning_pair_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_kerning_pair_finalize;
}

static void
bird_font_kerning_pair_instance_init (BirdFontKerningPair * self,
                                      gpointer klass)
{
}

static void
bird_font_kerning_pair_finalize (GObject * obj)
{
	BirdFontKerningPair * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_KERNING_PAIR, BirdFontKerningPair);
	_g_object_unref0 (self->character);
	_g_object_unref0 (self->kerning);
	_g_object_unref0 (self->right);
	G_OBJECT_CLASS (bird_font_kerning_pair_parent_class)->finalize (obj);
}

/** A list of all kerning pairs for one glyph. */
static GType
bird_font_kerning_pair_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontKerningPairClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_kerning_pair_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontKerningPair), 0, (GInstanceInitFunc) bird_font_kerning_pair_instance_init, NULL };
	GType bird_font_kerning_pair_type_id;
	bird_font_kerning_pair_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontKerningPair", &g_define_type_info, 0);
	return bird_font_kerning_pair_type_id;
}

GType
bird_font_kerning_pair_get_type (void)
{
	static volatile gsize bird_font_kerning_pair_type_id__once = 0;
	if (g_once_init_enter (&bird_font_kerning_pair_type_id__once)) {
		GType bird_font_kerning_pair_type_id;
		bird_font_kerning_pair_type_id = bird_font_kerning_pair_get_type_once ();
		g_once_init_leave (&bird_font_kerning_pair_type_id__once, bird_font_kerning_pair_type_id);
	}
	return bird_font_kerning_pair_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

