/* FontName.c generated by valac 0.56.17, the Vala compiler
 * generated from FontName.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 <cairo-gobject.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_FONT_NAME_0_PROPERTY,
	BIRD_FONT_FONT_NAME_NUM_PROPERTIES
};
static GParamSpec* bird_font_font_name_properties[BIRD_FONT_FONT_NAME_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer bird_font_font_name_parent_class = NULL;

static void __lambda90_ (BirdFontFontName* self,
                  BirdFontTool* tool);
static void ___lambda90__bird_font_tool_select_action (BirdFontTool* _sender,
                                                BirdFontTool* selected,
                                                gpointer self);
static void bird_font_font_name_real_draw_tool (BirdFontTool* base,
                                         cairo_t* cr,
                                         gdouble px,
                                         gdouble py);
static GType bird_font_font_name_get_type_once (void);

static void
__lambda90_ (BirdFontFontName* self,
             BirdFontTool* tool)
{
	g_return_if_fail (tool != NULL);
	bird_font_menu_tab_select_overview ();
}

static void
___lambda90__bird_font_tool_select_action (BirdFontTool* _sender,
                                           BirdFontTool* selected,
                                           gpointer self)
{
	__lambda90_ ((BirdFontFontName*) self, selected);
}

BirdFontFontName*
bird_font_font_name_construct (GType object_type,
                               const gchar* name,
                               const gchar* tip)
{
	BirdFontFontName * self = NULL;
	g_return_val_if_fail (tip != NULL, NULL);
	self = (BirdFontFontName*) bird_font_tool_construct (object_type, NULL, tip);
	if (name != NULL) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ((const gchar*) name);
		_g_free0 (G_TYPE_CHECK_INSTANCE_CAST (self, BIRD_FONT_TYPE_TOOL, BirdFontTool)->name);
		G_TYPE_CHECK_INSTANCE_CAST (self, BIRD_FONT_TYPE_TOOL, BirdFontTool)->name = _tmp0_;
	}
	g_signal_connect_object ((BirdFontTool*) self, "select-action", (GCallback) ___lambda90__bird_font_tool_select_action, self, 0);
	return self;
}

BirdFontFontName*
bird_font_font_name_new (const gchar* name,
                         const gchar* tip)
{
	return bird_font_font_name_construct (BIRD_FONT_TYPE_FONT_NAME, name, tip);
}

static void
bird_font_font_name_real_draw_tool (BirdFontTool* base,
                                    cairo_t* cr,
                                    gdouble px,
                                    gdouble py)
{
	BirdFontFontName * self;
	BirdFontText* font_name = NULL;
	gdouble text_height = 0.0;
	gdouble extent = 0.0;
	gdouble width = 0.0;
	gdouble max_width = 0.0;
	gdouble x = 0.0;
	gdouble y = 0.0;
	BirdFontText* _tmp0_;
	BirdFontText* _tmp1_;
	BirdFontFont* _tmp2_;
	BirdFontFont* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	BirdFontText* _tmp6_;
	BirdFontText* _tmp7_;
	BirdFontText* _tmp8_;
	BirdFontText* _tmp9_;
	BirdFontText* _tmp10_;
	self = (BirdFontFontName*) base;
	g_return_if_fail (cr != NULL);
	width = bird_font_toolbox_allocation_width * bird_font_toolbox_get_scale ();
	x = ((BirdFontTool*) self)->x - px;
	y = ((BirdFontTool*) self)->y - py;
	cairo_save (cr);
	_tmp0_ = bird_font_text_new ("", (gdouble) 17, (gdouble) 0);
	_g_object_unref0 (font_name);
	font_name = _tmp0_;
	_tmp1_ = font_name;
	_tmp2_ = bird_font_bird_font_get_current_font ();
	_tmp3_ = _tmp2_;
	_tmp4_ = bird_font_font_get_full_name (_tmp3_);
	_tmp5_ = _tmp4_;
	bird_font_text_set_text (_tmp1_, _tmp5_);
	_g_free0 (_tmp5_);
	_g_object_unref0 (_tmp3_);
	text_height = 22 * bird_font_toolbox_get_scale ();
	max_width = width - ((2 * x) * bird_font_toolbox_get_scale ());
	_tmp6_ = font_name;
	bird_font_text_set_font_size (_tmp6_, text_height);
	_tmp7_ = font_name;
	extent = bird_font_text_get_extent (_tmp7_) * bird_font_toolbox_get_scale ();
	if (extent > max_width) {
		text_height *= max_width / extent;
	}
	_tmp8_ = font_name;
	bird_font_theme_text_color (_tmp8_, "Font Name");
	_tmp9_ = font_name;
	bird_font_text_set_font_size (_tmp9_, text_height);
	_tmp10_ = font_name;
	bird_font_text_draw_at_top (_tmp10_, cr, x, y, "");
	cairo_restore (cr);
	_g_object_unref0 (font_name);
}

static void
bird_font_font_name_class_init (BirdFontFontNameClass * klass,
                                gpointer klass_data)
{
	bird_font_font_name_parent_class = g_type_class_peek_parent (klass);
	((BirdFontToolClass *) klass)->draw_tool = (void (*) (BirdFontTool*, cairo_t*, gdouble, gdouble)) bird_font_font_name_real_draw_tool;
}

static void
bird_font_font_name_instance_init (BirdFontFontName * self,
                                   gpointer klass)
{
}

static GType
bird_font_font_name_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontFontNameClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_font_name_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontFontName), 0, (GInstanceInitFunc) bird_font_font_name_instance_init, NULL };
	GType bird_font_font_name_type_id;
	bird_font_font_name_type_id = g_type_register_static (BIRD_FONT_TYPE_TOOL, "BirdFontFontName", &g_define_type_info, 0);
	return bird_font_font_name_type_id;
}

GType
bird_font_font_name_get_type (void)
{
	static volatile gsize bird_font_font_name_type_id__once = 0;
	if (g_once_init_enter (&bird_font_font_name_type_id__once)) {
		GType bird_font_font_name_type_id;
		bird_font_font_name_type_id = bird_font_font_name_get_type_once ();
		g_once_init_leave (&bird_font_font_name_type_id__once, bird_font_font_name_type_id);
	}
	return bird_font_font_name_type_id__once;
}

