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

/*
Copyright (C) 2014 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.h>
#include <glib-object.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_CMAP_SUBTABLE_FORMAT0_0_PROPERTY,
	BIRD_FONT_CMAP_SUBTABLE_FORMAT0_NUM_PROPERTIES
};
static GParamSpec* bird_font_cmap_subtable_format0_properties[BIRD_FONT_CMAP_SUBTABLE_FORMAT0_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BirdFontCmapSubtableFormat0Private {
	BirdFontFontData* cmap_data;
};

static gint BirdFontCmapSubtableFormat0_private_offset;
static gpointer bird_font_cmap_subtable_format0_parent_class = NULL;

static gushort bird_font_cmap_subtable_format0_real_get_platform (BirdFontCmapSubtable* base);
static gushort bird_font_cmap_subtable_format0_real_get_encoding (BirdFontCmapSubtable* base);
static BirdFontFontData* bird_font_cmap_subtable_format0_real_get_cmap_data (BirdFontCmapSubtable* base);
static void bird_font_cmap_subtable_format0_real_generate_cmap_data (BirdFontCmapSubtable* base,
                                                              BirdFontGlyfTable* glyf_table,
                                                              GError** error);
static guint8 bird_font_cmap_subtable_format0_get_gid_for_unichar (BirdFontCmapSubtableFormat0* self,
                                                            gunichar c,
                                                            BirdFontGlyfTable* glyf_table);
static void bird_font_cmap_subtable_format0_finalize (GObject * obj);
static GType bird_font_cmap_subtable_format0_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_cmap_subtable_format0_get_instance_private (BirdFontCmapSubtableFormat0* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontCmapSubtableFormat0_private_offset);
}

BirdFontCmapSubtableFormat0*
bird_font_cmap_subtable_format0_construct (GType object_type)
{
	BirdFontCmapSubtableFormat0 * self = NULL;
	self = (BirdFontCmapSubtableFormat0*) bird_font_cmap_subtable_construct (object_type);
	return self;
}

BirdFontCmapSubtableFormat0*
bird_font_cmap_subtable_format0_new (void)
{
	return bird_font_cmap_subtable_format0_construct (BIRD_FONT_TYPE_CMAP_SUBTABLE_FORMAT0);
}

static gushort
bird_font_cmap_subtable_format0_real_get_platform (BirdFontCmapSubtable* base)
{
	BirdFontCmapSubtableFormat0 * self;
	gushort result;
	self = (BirdFontCmapSubtableFormat0*) base;
	result = (gushort) 1;
	return result;
}

static gushort
bird_font_cmap_subtable_format0_real_get_encoding (BirdFontCmapSubtable* base)
{
	BirdFontCmapSubtableFormat0 * self;
	gushort result;
	self = (BirdFontCmapSubtableFormat0*) base;
	result = (gushort) 0;
	return result;
}

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

static BirdFontFontData*
bird_font_cmap_subtable_format0_real_get_cmap_data (BirdFontCmapSubtable* base)
{
	BirdFontCmapSubtableFormat0 * self;
	BirdFontFontData* _tmp0_;
	BirdFontFontData* _tmp1_;
	BirdFontFontData* result;
	self = (BirdFontCmapSubtableFormat0*) base;
	_tmp0_ = self->priv->cmap_data;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
bird_font_cmap_subtable_format0_real_generate_cmap_data (BirdFontCmapSubtable* base,
                                                         BirdFontGlyfTable* glyf_table,
                                                         GError** error)
{
	BirdFontCmapSubtableFormat0 * self;
	BirdFontFontData* fd = NULL;
	BirdFontFontData* _tmp0_;
	BirdFontFontData* _tmp1_;
	BirdFontFontData* _tmp2_;
	BirdFontFontData* _tmp3_;
	BirdFontFontData* _tmp7_;
	BirdFontFontData* _tmp8_;
	self = (BirdFontCmapSubtableFormat0*) base;
	g_return_if_fail (glyf_table != NULL);
	_tmp0_ = bird_font_font_data_new ((guint32) 1024);
	fd = _tmp0_;
	_tmp1_ = fd;
	bird_font_font_data_add_u16 (_tmp1_, (guint16) 0);
	_tmp2_ = fd;
	bird_font_font_data_add_u16 (_tmp2_, (guint16) 262);
	_tmp3_ = fd;
	bird_font_font_data_add_u16 (_tmp3_, (guint16) 0);
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				BirdFontFontData* _tmp6_;
				if (!_tmp4_) {
					guint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (!(i < ((guint) 256))) {
					break;
				}
				_tmp6_ = fd;
				bird_font_font_data_add (_tmp6_, bird_font_cmap_subtable_format0_get_gid_for_unichar (self, (gunichar) i, glyf_table));
			}
		}
	}
	_tmp7_ = fd;
	_tmp8_ = _g_object_ref0 (_tmp7_);
	_g_object_unref0 (self->priv->cmap_data);
	self->priv->cmap_data = _tmp8_;
	_g_object_unref0 (fd);
}

static guint8
bird_font_cmap_subtable_format0_get_gid_for_unichar (BirdFontCmapSubtableFormat0* self,
                                                     gunichar c,
                                                     BirdFontGlyfTable* glyf_table)
{
	guint32 index = 0U;
	guint8 result;
	g_return_val_if_fail (self != NULL, 0U);
	g_return_val_if_fail (glyf_table != NULL, 0U);
	index = (guint32) 0;
	{
		GeeArrayList* _g_list = NULL;
		GeeArrayList* _tmp0_;
		gint _g_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _g_index = 0;
		_tmp0_ = glyf_table->glyphs;
		_g_list = _tmp0_;
		_tmp1_ = _g_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_g_size = _tmp3_;
		_g_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontGlyphCollection* g = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			BirdFontGlyphCollection* _tmp9_;
			guint32 _tmp12_;
			_g_index = _g_index + 1;
			_tmp4_ = _g_index;
			_tmp5_ = _g_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _g_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _g_index);
			g = (BirdFontGlyphCollection*) _tmp7_;
			_tmp9_ = g;
			if (bird_font_glyph_collection_get_unicode_character (_tmp9_) == c) {
				BirdFontGlyphCollection* _tmp10_;
				_tmp10_ = g;
				_tmp8_ = !bird_font_glyph_collection_is_unassigned (_tmp10_);
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				guint8 _tmp11_ = 0U;
				if (index <= ((guint32) G_MAXUINT8)) {
					_tmp11_ = (guint8) index;
				} else {
					_tmp11_ = (guint8) 0;
				}
				result = _tmp11_;
				_g_object_unref0 (g);
				return result;
			}
			_tmp12_ = index;
			index = _tmp12_ + 1;
			_g_object_unref0 (g);
		}
	}
	result = (guint8) 0;
	return result;
}

static void
bird_font_cmap_subtable_format0_class_init (BirdFontCmapSubtableFormat0Class * klass,
                                            gpointer klass_data)
{
	bird_font_cmap_subtable_format0_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontCmapSubtableFormat0_private_offset);
	((BirdFontCmapSubtableClass *) klass)->get_platform = (gushort (*) (BirdFontCmapSubtable*)) bird_font_cmap_subtable_format0_real_get_platform;
	((BirdFontCmapSubtableClass *) klass)->get_encoding = (gushort (*) (BirdFontCmapSubtable*)) bird_font_cmap_subtable_format0_real_get_encoding;
	((BirdFontCmapSubtableClass *) klass)->get_cmap_data = (BirdFontFontData* (*) (BirdFontCmapSubtable*)) bird_font_cmap_subtable_format0_real_get_cmap_data;
	((BirdFontCmapSubtableClass *) klass)->generate_cmap_data = (void (*) (BirdFontCmapSubtable*, BirdFontGlyfTable*, GError**)) bird_font_cmap_subtable_format0_real_generate_cmap_data;
	G_OBJECT_CLASS (klass)->finalize = bird_font_cmap_subtable_format0_finalize;
}

static void
bird_font_cmap_subtable_format0_instance_init (BirdFontCmapSubtableFormat0 * self,
                                               gpointer klass)
{
	BirdFontFontData* _tmp0_;
	self->priv = bird_font_cmap_subtable_format0_get_instance_private (self);
	_tmp0_ = bird_font_font_data_new ((guint32) 1024);
	self->priv->cmap_data = _tmp0_;
}

static void
bird_font_cmap_subtable_format0_finalize (GObject * obj)
{
	BirdFontCmapSubtableFormat0 * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_CMAP_SUBTABLE_FORMAT0, BirdFontCmapSubtableFormat0);
	_g_object_unref0 (self->priv->cmap_data);
	G_OBJECT_CLASS (bird_font_cmap_subtable_format0_parent_class)->finalize (obj);
}

/** Format 0 cmap subtable */
static GType
bird_font_cmap_subtable_format0_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontCmapSubtableFormat0Class), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_cmap_subtable_format0_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontCmapSubtableFormat0), 0, (GInstanceInitFunc) bird_font_cmap_subtable_format0_instance_init, NULL };
	GType bird_font_cmap_subtable_format0_type_id;
	bird_font_cmap_subtable_format0_type_id = g_type_register_static (BIRD_FONT_TYPE_CMAP_SUBTABLE, "BirdFontCmapSubtableFormat0", &g_define_type_info, 0);
	BirdFontCmapSubtableFormat0_private_offset = g_type_add_instance_private (bird_font_cmap_subtable_format0_type_id, sizeof (BirdFontCmapSubtableFormat0Private));
	return bird_font_cmap_subtable_format0_type_id;
}

GType
bird_font_cmap_subtable_format0_get_type (void)
{
	static volatile gsize bird_font_cmap_subtable_format0_type_id__once = 0;
	if (g_once_init_enter (&bird_font_cmap_subtable_format0_type_id__once)) {
		GType bird_font_cmap_subtable_format0_type_id;
		bird_font_cmap_subtable_format0_type_id = bird_font_cmap_subtable_format0_get_type_once ();
		g_once_init_leave (&bird_font_cmap_subtable_format0_type_id__once, bird_font_cmap_subtable_format0_type_id);
	}
	return bird_font_cmap_subtable_format0_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;
}

