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

/*
Copyright (C) 2012, 2013 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 <stdlib.h>
#include <string.h>
#include <gee.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_MAXP_TABLE_0_PROPERTY,
	BIRD_FONT_MAXP_TABLE_NUM_PROPERTIES
};
static GParamSpec* bird_font_maxp_table_properties[BIRD_FONT_MAXP_TABLE_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))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _BirdFontMaxpTablePrivate {
	BirdFontGlyfTable* glyf_table;
};

static gint BirdFontMaxpTable_private_offset;
static gpointer bird_font_maxp_table_parent_class = NULL;

static void bird_font_maxp_table_real_parse (BirdFontOtfTable* base,
                                      BirdFontFontData* dis,
                                      GError** error);
static void bird_font_maxp_table_finalize (GObject * obj);
static GType bird_font_maxp_table_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_maxp_table_get_instance_private (BirdFontMaxpTable* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontMaxpTable_private_offset);
}

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

BirdFontMaxpTable*
bird_font_maxp_table_construct (GType object_type,
                                BirdFontGlyfTable* g)
{
	BirdFontMaxpTable * self = NULL;
	BirdFontGlyfTable* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (g != NULL, NULL);
	self = (BirdFontMaxpTable*) bird_font_otf_table_construct (object_type);
	_tmp0_ = _g_object_ref0 (g);
	_g_object_unref0 (self->priv->glyf_table);
	self->priv->glyf_table = _tmp0_;
	_tmp1_ = g_strdup ("maxp");
	_g_free0 (((BirdFontOtfTable*) self)->id);
	((BirdFontOtfTable*) self)->id = _tmp1_;
	return self;
}

BirdFontMaxpTable*
bird_font_maxp_table_new (BirdFontGlyfTable* g)
{
	return bird_font_maxp_table_construct (BIRD_FONT_TYPE_MAXP_TABLE, g);
}

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 void
bird_font_maxp_table_real_parse (BirdFontOtfTable* base,
                                 BirdFontFontData* dis,
                                 GError** error)
{
	BirdFontMaxpTable * self;
	BirdFontFixed format = 0U;
	gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	self = (BirdFontMaxpTable*) base;
	g_return_if_fail (dis != NULL);
	_vala_return_if_fail ((((BirdFontOtfTable*) self)->offset > ((guint32) 0)) && (((BirdFontOtfTable*) self)->length > ((guint32) 0)), "offset > 0 && length > 0");
	bird_font_font_data_seek (dis, (guint) ((BirdFontOtfTable*) self)->offset);
	format = bird_font_font_data_read_fixed (dis);
	_tmp0_ = bird_font_fixed_get_string (format);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_to_string (_tmp1_);
	_tmp3_ = g_strconcat ("Maxp version: ", _tmp2_, "\n", NULL);
	_tmp4_ = _tmp3_;
	bird_font_printd (_tmp4_);
	_g_free0 (_tmp4_);
	_g_free0 (_tmp1_);
	self->num_glyphs = bird_font_font_data_read_ushort (dis);
	if (format == ((BirdFontFixed) 0x00005000)) {
		return;
	}
}

void
bird_font_maxp_table_process (BirdFontMaxpTable* self)
{
	BirdFontFontData* fd = NULL;
	BirdFontFontData* _tmp0_;
	BirdFontFontData* _tmp1_;
	BirdFontGlyfTable* _tmp2_;
	GeeArrayList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	BirdFontFontData* _tmp6_;
	BirdFontGlyfTable* _tmp7_;
	GeeArrayList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	BirdFontFontData* _tmp11_;
	BirdFontGlyfTable* _tmp12_;
	BirdFontFontData* _tmp13_;
	BirdFontGlyfTable* _tmp14_;
	BirdFontFontData* _tmp15_;
	BirdFontFontData* _tmp16_;
	BirdFontFontData* _tmp17_;
	BirdFontFontData* _tmp18_;
	BirdFontFontData* _tmp19_;
	BirdFontFontData* _tmp20_;
	BirdFontFontData* _tmp21_;
	BirdFontFontData* _tmp22_;
	BirdFontFontData* _tmp23_;
	BirdFontFontData* _tmp24_;
	BirdFontFontData* _tmp25_;
	BirdFontFontData* _tmp26_;
	BirdFontFontData* _tmp27_;
	BirdFontFontData* _tmp28_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_font_data_new ((guint32) 1024);
	fd = _tmp0_;
	_tmp1_ = fd;
	bird_font_font_data_add_u32 (_tmp1_, (guint32) 0x00010000);
	_tmp2_ = self->priv->glyf_table;
	_tmp3_ = _tmp2_->glyphs;
	_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == 0) {
		g_warning ("MaxpTable.vala:53: Zero glyphs in maxp table.");
	}
	_tmp6_ = fd;
	_tmp7_ = self->priv->glyf_table;
	_tmp8_ = _tmp7_->glyphs;
	_tmp9_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp8_);
	_tmp10_ = _tmp9_;
	bird_font_font_data_add_u16 (_tmp6_, (guint16) _tmp10_);
	_tmp11_ = fd;
	_tmp12_ = self->priv->glyf_table;
	bird_font_font_data_add_u16 (_tmp11_, bird_font_glyf_table_get_max_points (_tmp12_));
	_tmp13_ = fd;
	_tmp14_ = self->priv->glyf_table;
	bird_font_font_data_add_u16 (_tmp13_, bird_font_glyf_table_get_max_contours (_tmp14_));
	_tmp15_ = fd;
	bird_font_font_data_add_u16 (_tmp15_, (guint16) 0);
	_tmp16_ = fd;
	bird_font_font_data_add_u16 (_tmp16_, (guint16) 0);
	_tmp17_ = fd;
	bird_font_font_data_add_u16 (_tmp17_, (guint16) 1);
	_tmp18_ = fd;
	bird_font_font_data_add_u16 (_tmp18_, (guint16) 0);
	_tmp19_ = fd;
	bird_font_font_data_add_u16 (_tmp19_, (guint16) 0);
	_tmp20_ = fd;
	bird_font_font_data_add_u16 (_tmp20_, (guint16) 0);
	_tmp21_ = fd;
	bird_font_font_data_add_u16 (_tmp21_, (guint16) 0);
	_tmp22_ = fd;
	bird_font_font_data_add_u16 (_tmp22_, (guint16) 0);
	_tmp23_ = fd;
	bird_font_font_data_add_u16 (_tmp23_, (guint16) 0);
	_tmp24_ = fd;
	bird_font_font_data_add_u16 (_tmp24_, (guint16) 0);
	_tmp25_ = fd;
	bird_font_font_data_add_u16 (_tmp25_, (guint16) 0);
	_tmp26_ = fd;
	bird_font_font_data_pad (_tmp26_);
	_tmp27_ = fd;
	_tmp28_ = _g_object_ref0 (_tmp27_);
	_g_object_unref0 (((BirdFontOtfTable*) self)->font_data);
	((BirdFontOtfTable*) self)->font_data = _tmp28_;
	_g_object_unref0 (fd);
}

static void
bird_font_maxp_table_class_init (BirdFontMaxpTableClass * klass,
                                 gpointer klass_data)
{
	bird_font_maxp_table_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontMaxpTable_private_offset);
	((BirdFontOtfTableClass *) klass)->parse = (void (*) (BirdFontOtfTable*, BirdFontFontData*, GError**)) bird_font_maxp_table_real_parse;
	G_OBJECT_CLASS (klass)->finalize = bird_font_maxp_table_finalize;
}

static void
bird_font_maxp_table_instance_init (BirdFontMaxpTable * self,
                                    gpointer klass)
{
	self->priv = bird_font_maxp_table_get_instance_private (self);
	self->num_glyphs = (guint16) 0;
}

static void
bird_font_maxp_table_finalize (GObject * obj)
{
	BirdFontMaxpTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_MAXP_TABLE, BirdFontMaxpTable);
	_g_object_unref0 (self->priv->glyf_table);
	G_OBJECT_CLASS (bird_font_maxp_table_parent_class)->finalize (obj);
}

static GType
bird_font_maxp_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontMaxpTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_maxp_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontMaxpTable), 0, (GInstanceInitFunc) bird_font_maxp_table_instance_init, NULL };
	GType bird_font_maxp_table_type_id;
	bird_font_maxp_table_type_id = g_type_register_static (BIRD_FONT_TYPE_OTF_TABLE, "BirdFontMaxpTable", &g_define_type_info, 0);
	BirdFontMaxpTable_private_offset = g_type_add_instance_private (bird_font_maxp_table_type_id, sizeof (BirdFontMaxpTablePrivate));
	return bird_font_maxp_table_type_id;
}

GType
bird_font_maxp_table_get_type (void)
{
	static volatile gsize bird_font_maxp_table_type_id__once = 0;
	if (g_once_init_enter (&bird_font_maxp_table_type_id__once)) {
		GType bird_font_maxp_table_type_id;
		bird_font_maxp_table_type_id = bird_font_maxp_table_get_type_once ();
		g_once_init_leave (&bird_font_maxp_table_type_id__once, bird_font_maxp_table_type_id);
	}
	return bird_font_maxp_table_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;
}

