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

/*
Copyright (C) 2015 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 <string.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_CONTEXTUAL_LIGATURE_COLLECTION_0_PROPERTY,
	BIRD_FONT_CONTEXTUAL_LIGATURE_COLLECTION_NUM_PROPERTIES
};
static GParamSpec* bird_font_contextual_ligature_collection_properties[BIRD_FONT_CONTEXTUAL_LIGATURE_COLLECTION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer bird_font_contextual_ligature_collection_parent_class = NULL;

static void bird_font_contextual_ligature_collection_add_contextual_ligatures (BirdFontContextualLigatureCollection* self,
                                                                        BirdFontGlyfTable* glyf_table);
static void bird_font_contextual_ligature_collection_finalize (GObject * obj);
static GType bird_font_contextual_ligature_collection_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

BirdFontContextualLigatureCollection*
bird_font_contextual_ligature_collection_construct (GType object_type,
                                                    BirdFontGlyfTable* glyf_table)
{
	BirdFontContextualLigatureCollection * self = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	g_return_val_if_fail (glyf_table != NULL, NULL);
	self = (BirdFontContextualLigatureCollection*) g_object_new (object_type, NULL);
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_CONTEXTUAL_LIGATURE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->ligature_context);
	self->ligature_context = _tmp0_;
	_tmp1_ = gee_array_list_new (BIRD_FONT_TYPE_LIGATURE_COLLECTION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->ligatures);
	self->ligatures = _tmp1_;
	bird_font_contextual_ligature_collection_add_contextual_ligatures (self, glyf_table);
	return self;
}

BirdFontContextualLigatureCollection*
bird_font_contextual_ligature_collection_new (BirdFontGlyfTable* glyf_table)
{
	return bird_font_contextual_ligature_collection_construct (BIRD_FONT_TYPE_CONTEXTUAL_LIGATURE_COLLECTION, glyf_table);
}

gint16
bird_font_contextual_ligature_collection_get_size (BirdFontContextualLigatureCollection* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeArrayList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	GeeArrayList* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gint16 result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->ligatures;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->ligature_context;
	_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp2_ != _tmp5_) {
		g_warning ("ContextualLigatureCollection.vala:31: Expecting one substitution table" \
" per contextual ligature");
	}
	_tmp6_ = self->ligature_context;
	_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
	_tmp8_ = _tmp7_;
	result = (gint16) _tmp8_;
	return result;
}

gboolean
bird_font_contextual_ligature_collection_has_ligatures (BirdFontContextualLigatureCollection* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->ligature_context;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_ > 0;
	return result;
}

static void
bird_font_contextual_ligature_collection_add_contextual_ligatures (BirdFontContextualLigatureCollection* self,
                                                                   BirdFontGlyfTable* glyf_table)
{
	BirdFontFont* font = NULL;
	BirdFontFont* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (glyf_table != NULL);
	_tmp0_ = bird_font_bird_font_get_current_font ();
	font = _tmp0_;
	{
		GeeArrayList* _c_list = NULL;
		BirdFontFont* _tmp1_;
		BirdFontLigatures* _tmp2_;
		GeeArrayList* _tmp3_;
		gint _c_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _c_index = 0;
		_tmp1_ = font;
		_tmp2_ = _tmp1_->ligature_substitution;
		_tmp3_ = _tmp2_->contextual_ligatures;
		_c_list = _tmp3_;
		_tmp4_ = _c_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_c_size = _tmp6_;
		_c_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			BirdFontContextualLigature* c = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			GeeArrayList* _tmp11_;
			BirdFontContextualLigature* _tmp12_;
			GeeArrayList* _tmp13_;
			BirdFontContextualLigature* _tmp14_;
			BirdFontLigatureCollection* _tmp15_;
			BirdFontLigatureCollection* _tmp16_;
			_c_index = _c_index + 1;
			_tmp7_ = _c_index;
			_tmp8_ = _c_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _c_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _c_index);
			c = (BirdFontContextualLigature*) _tmp10_;
			_tmp11_ = self->ligature_context;
			_tmp12_ = c;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp11_, _tmp12_);
			_tmp13_ = self->ligatures;
			_tmp14_ = c;
			_tmp15_ = bird_font_ligature_collection_new_contextual (glyf_table, _tmp14_);
			_tmp16_ = _tmp15_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp13_, _tmp16_);
			_g_object_unref0 (_tmp16_);
			_g_object_unref0 (c);
		}
	}
	_g_object_unref0 (font);
}

static void
bird_font_contextual_ligature_collection_class_init (BirdFontContextualLigatureCollectionClass * klass,
                                                     gpointer klass_data)
{
	bird_font_contextual_ligature_collection_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_contextual_ligature_collection_finalize;
}

static void
bird_font_contextual_ligature_collection_instance_init (BirdFontContextualLigatureCollection * self,
                                                        gpointer klass)
{
}

static void
bird_font_contextual_ligature_collection_finalize (GObject * obj)
{
	BirdFontContextualLigatureCollection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_CONTEXTUAL_LIGATURE_COLLECTION, BirdFontContextualLigatureCollection);
	_g_object_unref0 (self->ligature_context);
	_g_object_unref0 (self->ligatures);
	G_OBJECT_CLASS (bird_font_contextual_ligature_collection_parent_class)->finalize (obj);
}

static GType
bird_font_contextual_ligature_collection_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontContextualLigatureCollectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_contextual_ligature_collection_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontContextualLigatureCollection), 0, (GInstanceInitFunc) bird_font_contextual_ligature_collection_instance_init, NULL };
	GType bird_font_contextual_ligature_collection_type_id;
	bird_font_contextual_ligature_collection_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontContextualLigatureCollection", &g_define_type_info, 0);
	return bird_font_contextual_ligature_collection_type_id;
}

GType
bird_font_contextual_ligature_collection_get_type (void)
{
	static volatile gsize bird_font_contextual_ligature_collection_type_id__once = 0;
	if (g_once_init_enter (&bird_font_contextual_ligature_collection_type_id__once)) {
		GType bird_font_contextual_ligature_collection_type_id;
		bird_font_contextual_ligature_collection_type_id = bird_font_contextual_ligature_collection_get_type_once ();
		g_once_init_leave (&bird_font_contextual_ligature_collection_type_id__once, bird_font_contextual_ligature_collection_type_id);
	}
	return bird_font_contextual_ligature_collection_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;
}

