/* CachedFont.c generated by valac 0.56.17, the Vala compiler
 * generated from CachedFont.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.h>
#include <float.h>
#include <math.h>
#include <glib-object.h>
#include <stdlib.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_CACHED_FONT_0_PROPERTY,
	BIRD_FONT_CACHED_FONT_TOP_LIMIT_PROPERTY,
	BIRD_FONT_CACHED_FONT_BOTTOM_LIMIT_PROPERTY,
	BIRD_FONT_CACHED_FONT_NUM_PROPERTIES
};
static GParamSpec* bird_font_cached_font_properties[BIRD_FONT_CACHED_FONT_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BirdFontCachedFontPrivate {
	gdouble _top_limit;
	gdouble _bottom_limit;
};

static gint BirdFontCachedFont_private_offset;
static gpointer bird_font_cached_font_parent_class = NULL;
static BirdFontFallbackFont* bird_font_cached_font__fallback_font;
static BirdFontFallbackFont* bird_font_cached_font__fallback_font = NULL;

static BirdFontFallbackFont* bird_font_cached_font_get_fallback_font (void);
static void bird_font_cached_font_finalize (GObject * obj);
static GType bird_font_cached_font_get_type_once (void);
static void _vala_bird_font_cached_font_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_bird_font_cached_font_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_cached_font_get_instance_private (BirdFontCachedFont* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontCachedFont_private_offset);
}

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

BirdFontCachedFont*
bird_font_cached_font_construct (GType object_type,
                                 BirdFontFont* font)
{
	BirdFontCachedFont * self = NULL;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* glyph = NULL;
	BirdFontFont* _tmp0_;
	BirdFontGlyph* _tmp1_;
	BirdFontGlyph* _tmp2_;
	self = (BirdFontCachedFont*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (font);
	_g_object_unref0 (self->font);
	self->font = _tmp0_;
	_tmp1_ = bird_font_cached_font_get_glyph_by_name (self, "a");
	_g_object_unref0 (g);
	g = _tmp1_;
	_tmp2_ = g;
	if (_tmp2_ != NULL) {
		BirdFontGlyph* _tmp3_;
		BirdFontGlyph* _tmp4_;
		BirdFontGlyph* _tmp5_;
		BirdFontGlyph* _tmp6_;
		BirdFontGlyph* _tmp7_;
		_tmp3_ = g;
		_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
		_g_object_unref0 (glyph);
		glyph = _tmp4_;
		_tmp5_ = glyph;
		self->base_line = _tmp5_->baseline;
		_tmp6_ = glyph;
		bird_font_cached_font_set_top_limit (self, _tmp6_->top_limit);
		_tmp7_ = glyph;
		bird_font_cached_font_set_bottom_limit (self, _tmp7_->bottom_limit);
	} else {
		g_warning ("CachedFont.vala:60: No default chararacter found in font.");
	}
	_g_object_unref0 (glyph);
	_g_object_unref0 (g);
	return self;
}

BirdFontCachedFont*
bird_font_cached_font_new (BirdFontFont* font)
{
	return bird_font_cached_font_construct (BIRD_FONT_TYPE_CACHED_FONT, font);
}

static gunichar
string_get_char (const gchar* self,
                 glong index)
{
	gunichar result;
	g_return_val_if_fail (self != NULL, 0U);
	result = g_utf8_get_char (((gchar*) self) + index);
	return result;
}

BirdFontGlyph*
bird_font_cached_font_get_glyph_by_name (BirdFontCachedFont* self,
                                         const gchar* name)
{
	BirdFontGlyph* g = NULL;
	BirdFontFont* f = NULL;
	BirdFontGlyph* glyph = NULL;
	BirdFontFont* _tmp0_;
	gboolean _tmp14_ = FALSE;
	BirdFontGlyph* _tmp15_;
	BirdFontGlyph* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g = NULL;
	_tmp0_ = self->font;
	if (_tmp0_ != NULL) {
		BirdFontFont* _tmp1_;
		BirdFontFont* _tmp2_;
		BirdFontFont* _tmp3_;
		BirdFontGlyph* _tmp4_;
		BirdFontGlyph* _tmp5_;
		_tmp1_ = self->font;
		_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, BIRD_FONT_TYPE_FONT, BirdFontFont));
		_g_object_unref0 (f);
		f = _tmp2_;
		_tmp3_ = f;
		_tmp4_ = bird_font_font_get_glyph_by_name (_tmp3_, name);
		_g_object_unref0 (g);
		g = _tmp4_;
		_tmp5_ = g;
		if (_tmp5_ != NULL) {
			BirdFontGlyph* _tmp6_;
			BirdFontGlyph* _tmp7_;
			BirdFontGlyph* _tmp8_;
			BirdFontFont* _tmp9_;
			BirdFontGlyph* _tmp10_;
			BirdFontFont* _tmp11_;
			BirdFontGlyph* _tmp12_;
			BirdFontFont* _tmp13_;
			_tmp6_ = g;
			_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
			_g_object_unref0 (glyph);
			glyph = _tmp7_;
			_tmp8_ = glyph;
			_tmp9_ = f;
			_tmp8_->top_limit = _tmp9_->top_limit;
			_tmp10_ = glyph;
			_tmp11_ = f;
			_tmp10_->baseline = _tmp11_->base_line;
			_tmp12_ = glyph;
			_tmp13_ = f;
			_tmp12_->bottom_limit = _tmp13_->bottom_limit;
		}
	}
	_tmp15_ = g;
	if (_tmp15_ == NULL) {
		_tmp14_ = g_utf8_strlen (name, (gssize) -1) == 1;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		BirdFontFallbackFont* _tmp16_;
		BirdFontFallbackFont* _tmp17_;
		BirdFontFont* _tmp18_;
		BirdFontFont* _tmp19_;
		BirdFontGlyph* _tmp20_;
		BirdFontGlyph* _tmp21_;
		BirdFontGlyph* _tmp22_;
		BirdFontGlyph* _tmp23_;
		BirdFontGlyph* _tmp24_;
		BirdFontFont* _tmp25_;
		BirdFontGlyph* _tmp26_;
		BirdFontFont* _tmp27_;
		BirdFontGlyph* _tmp28_;
		BirdFontFont* _tmp29_;
		_tmp16_ = bird_font_cached_font_get_fallback_font ();
		_tmp17_ = _tmp16_;
		_tmp18_ = bird_font_fallback_font_get_single_glyph_font (_tmp17_, string_get_char (name, (glong) 0));
		_g_object_unref0 (f);
		f = _tmp18_;
		_tmp19_ = f;
		_tmp20_ = bird_font_font_get_glyph_by_name (_tmp19_, name);
		_g_object_unref0 (g);
		g = _tmp20_;
		_tmp21_ = g;
		if (_tmp21_ == NULL) {
			result = NULL;
			_g_object_unref0 (glyph);
			_g_object_unref0 (f);
			_g_object_unref0 (g);
			return result;
		}
		_tmp22_ = g;
		_tmp23_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp22_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
		_g_object_unref0 (glyph);
		glyph = _tmp23_;
		_tmp24_ = glyph;
		_tmp25_ = f;
		_tmp24_->top_limit = _tmp25_->top_limit;
		_tmp26_ = glyph;
		_tmp27_ = f;
		_tmp26_->baseline = _tmp27_->base_line;
		_tmp28_ = glyph;
		_tmp29_ = f;
		_tmp28_->bottom_limit = _tmp29_->bottom_limit;
	}
	result = g;
	_g_object_unref0 (glyph);
	_g_object_unref0 (f);
	return result;
}

gdouble
bird_font_cached_font_get_top_limit (BirdFontCachedFont* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, 0.0);
	result = self->priv->_top_limit;
	return result;
}

void
bird_font_cached_font_set_top_limit (BirdFontCachedFont* self,
                                     gdouble value)
{
	g_return_if_fail (self != NULL);
	self->priv->_top_limit = value;
	g_object_notify_by_pspec ((GObject *) self, bird_font_cached_font_properties[BIRD_FONT_CACHED_FONT_TOP_LIMIT_PROPERTY]);
}

gdouble
bird_font_cached_font_get_bottom_limit (BirdFontCachedFont* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, 0.0);
	result = self->priv->_bottom_limit;
	return result;
}

void
bird_font_cached_font_set_bottom_limit (BirdFontCachedFont* self,
                                        gdouble value)
{
	g_return_if_fail (self != NULL);
	self->priv->_bottom_limit = value;
	g_object_notify_by_pspec ((GObject *) self, bird_font_cached_font_properties[BIRD_FONT_CACHED_FONT_BOTTOM_LIMIT_PROPERTY]);
}

static BirdFontFallbackFont*
bird_font_cached_font_get_fallback_font (void)
{
	BirdFontFallbackFont* result;
	BirdFontFallbackFont* _tmp0_;
	BirdFontFallbackFont* _tmp2_;
	_tmp0_ = bird_font_cached_font__fallback_font;
	if (_tmp0_ == NULL) {
		BirdFontFallbackFont* _tmp1_;
		_tmp1_ = bird_font_fallback_font_new ();
		_g_object_unref0 (bird_font_cached_font__fallback_font);
		bird_font_cached_font__fallback_font = _tmp1_;
	}
	_tmp2_ = bird_font_cached_font__fallback_font;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, BIRD_FONT_TYPE_FALLBACK_FONT, BirdFontFallbackFont);
	return result;
}

static void
bird_font_cached_font_class_init (BirdFontCachedFontClass * klass,
                                  gpointer klass_data)
{
	bird_font_cached_font_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontCachedFont_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_bird_font_cached_font_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_bird_font_cached_font_set_property;
	G_OBJECT_CLASS (klass)->finalize = bird_font_cached_font_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BIRD_FONT_CACHED_FONT_TOP_LIMIT_PROPERTY, bird_font_cached_font_properties[BIRD_FONT_CACHED_FONT_TOP_LIMIT_PROPERTY] = g_param_spec_double ("top-limit", "top-limit", "top-limit", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BIRD_FONT_CACHED_FONT_BOTTOM_LIMIT_PROPERTY, bird_font_cached_font_properties[BIRD_FONT_CACHED_FONT_BOTTOM_LIMIT_PROPERTY] = g_param_spec_double ("bottom-limit", "bottom-limit", "bottom-limit", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
bird_font_cached_font_instance_init (BirdFontCachedFont * self,
                                     gpointer klass)
{
	self->priv = bird_font_cached_font_get_instance_private (self);
	self->base_line = (gdouble) 0;
	self->priv->_top_limit = 92.77;
	self->priv->_bottom_limit = -24.4;
}

static void
bird_font_cached_font_finalize (GObject * obj)
{
	BirdFontCachedFont * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_CACHED_FONT, BirdFontCachedFont);
	_g_object_unref0 (self->font);
	G_OBJECT_CLASS (bird_font_cached_font_parent_class)->finalize (obj);
}

static GType
bird_font_cached_font_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontCachedFontClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_cached_font_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontCachedFont), 0, (GInstanceInitFunc) bird_font_cached_font_instance_init, NULL };
	GType bird_font_cached_font_type_id;
	bird_font_cached_font_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontCachedFont", &g_define_type_info, 0);
	BirdFontCachedFont_private_offset = g_type_add_instance_private (bird_font_cached_font_type_id, sizeof (BirdFontCachedFontPrivate));
	return bird_font_cached_font_type_id;
}

GType
bird_font_cached_font_get_type (void)
{
	static volatile gsize bird_font_cached_font_type_id__once = 0;
	if (g_once_init_enter (&bird_font_cached_font_type_id__once)) {
		GType bird_font_cached_font_type_id;
		bird_font_cached_font_type_id = bird_font_cached_font_get_type_once ();
		g_once_init_leave (&bird_font_cached_font_type_id__once, bird_font_cached_font_type_id);
	}
	return bird_font_cached_font_type_id__once;
}

static void
_vala_bird_font_cached_font_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	BirdFontCachedFont * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BIRD_FONT_TYPE_CACHED_FONT, BirdFontCachedFont);
	switch (property_id) {
		case BIRD_FONT_CACHED_FONT_TOP_LIMIT_PROPERTY:
		g_value_set_double (value, bird_font_cached_font_get_top_limit (self));
		break;
		case BIRD_FONT_CACHED_FONT_BOTTOM_LIMIT_PROPERTY:
		g_value_set_double (value, bird_font_cached_font_get_bottom_limit (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_bird_font_cached_font_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	BirdFontCachedFont * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BIRD_FONT_TYPE_CACHED_FONT, BirdFontCachedFont);
	switch (property_id) {
		case BIRD_FONT_CACHED_FONT_TOP_LIMIT_PROPERTY:
		bird_font_cached_font_set_top_limit (self, g_value_get_double (value));
		break;
		case BIRD_FONT_CACHED_FONT_BOTTOM_LIMIT_PROPERTY:
		bird_font_cached_font_set_bottom_limit (self, g_value_get_double (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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;
}

