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

/*
Copyright (C) 2016 2019 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 <cairo-gobject.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.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_SVG_TRANSFORM_0_PROPERTY,
	BIRD_FONT_SVG_TRANSFORM_NUM_PROPERTIES
};
static GParamSpec* bird_font_svg_transform_properties[BIRD_FONT_SVG_TRANSFORM_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 _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

static gpointer bird_font_svg_transform_parent_class = NULL;

static void bird_font_svg_transform_finalize (GObject * obj);
static GType bird_font_svg_transform_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GType
bird_font_transform_type_get_type_once (void)
{
	static const GEnumValue values[] = {{BIRD_FONT_TRANSFORM_TYPE_NONE, "BIRD_FONT_TRANSFORM_TYPE_NONE", "none"}, {BIRD_FONT_TRANSFORM_TYPE_TRANSLATE, "BIRD_FONT_TRANSFORM_TYPE_TRANSLATE", "translate"}, {BIRD_FONT_TRANSFORM_TYPE_MATRIX, "BIRD_FONT_TRANSFORM_TYPE_MATRIX", "matrix"}, {BIRD_FONT_TRANSFORM_TYPE_SCALE, "BIRD_FONT_TRANSFORM_TYPE_SCALE", "scale"}, {BIRD_FONT_TRANSFORM_TYPE_ROTATE, "BIRD_FONT_TRANSFORM_TYPE_ROTATE", "rotate"}, {0, NULL, NULL}};
	GType bird_font_transform_type_type_id;
	bird_font_transform_type_type_id = g_enum_register_static ("BirdFontTransformType", values);
	return bird_font_transform_type_type_id;
}

GType
bird_font_transform_type_get_type (void)
{
	static volatile gsize bird_font_transform_type_type_id__once = 0;
	if (g_once_init_enter (&bird_font_transform_type_type_id__once)) {
		GType bird_font_transform_type_type_id;
		bird_font_transform_type_type_id = bird_font_transform_type_get_type_once ();
		g_once_init_leave (&bird_font_transform_type_type_id__once, bird_font_transform_type_type_id);
	}
	return bird_font_transform_type_type_id__once;
}

BirdFontSvgTransform*
bird_font_svg_transform_construct (GType object_type)
{
	BirdFontSvgTransform * self = NULL;
	self = (BirdFontSvgTransform*) g_object_new (object_type, NULL);
	return self;
}

BirdFontSvgTransform*
bird_font_svg_transform_new (void)
{
	return bird_font_svg_transform_construct (BIRD_FONT_TYPE_SVG_TRANSFORM);
}

BirdFontSvgTransform*
bird_font_svg_transform_construct_for_matrix (GType object_type,
                                              cairo_matrix_t* matrix)
{
	BirdFontSvgTransform * self = NULL;
	BirdFontDoubles* _tmp0_;
	cairo_matrix_t _tmp1_;
	BirdFontDoubles* _tmp2_;
	cairo_matrix_t _tmp3_;
	BirdFontDoubles* _tmp4_;
	cairo_matrix_t _tmp5_;
	BirdFontDoubles* _tmp6_;
	cairo_matrix_t _tmp7_;
	BirdFontDoubles* _tmp8_;
	cairo_matrix_t _tmp9_;
	BirdFontDoubles* _tmp10_;
	cairo_matrix_t _tmp11_;
	g_return_val_if_fail (matrix != NULL, NULL);
	self = (BirdFontSvgTransform*) g_object_new (object_type, NULL);
	self->type = BIRD_FONT_TRANSFORM_TYPE_MATRIX;
	_tmp0_ = self->arguments;
	_tmp1_ = *matrix;
	bird_font_doubles_add (_tmp0_, _tmp1_.xx);
	_tmp2_ = self->arguments;
	_tmp3_ = *matrix;
	bird_font_doubles_add (_tmp2_, _tmp3_.yx);
	_tmp4_ = self->arguments;
	_tmp5_ = *matrix;
	bird_font_doubles_add (_tmp4_, _tmp5_.xy);
	_tmp6_ = self->arguments;
	_tmp7_ = *matrix;
	bird_font_doubles_add (_tmp6_, _tmp7_.yy);
	_tmp8_ = self->arguments;
	_tmp9_ = *matrix;
	bird_font_doubles_add (_tmp8_, _tmp9_.x0);
	_tmp10_ = self->arguments;
	_tmp11_ = *matrix;
	bird_font_doubles_add (_tmp10_, _tmp11_.y0);
	return self;
}

BirdFontSvgTransform*
bird_font_svg_transform_new_for_matrix (cairo_matrix_t* matrix)
{
	return bird_font_svg_transform_construct_for_matrix (BIRD_FONT_TYPE_SVG_TRANSFORM, matrix);
}

BirdFontSvgTransform*
bird_font_svg_transform_copy (BirdFontSvgTransform* self)
{
	BirdFontSvgTransform* transform = NULL;
	BirdFontSvgTransform* _tmp0_;
	BirdFontDoubles* _tmp1_;
	BirdFontDoubles* _tmp2_;
	BirdFontSvgTransform* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = bird_font_svg_transform_new ();
	transform = _tmp0_;
	transform->type = self->type;
	_tmp1_ = self->arguments;
	_tmp2_ = bird_font_doubles_copy (_tmp1_);
	_g_object_unref0 (transform->arguments);
	transform->arguments = _tmp2_;
	result = transform;
	return result;
}

static gchar*
double_to_string (gdouble self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp1__length1;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = G_ASCII_DTOSTR_BUF_SIZE;
	_tmp2_ = g_ascii_dtostr (_tmp1_, (gint) G_ASCII_DTOSTR_BUF_SIZE, self);
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	result = _tmp4_;
	return result;
}

gchar*
bird_font_svg_transform_to_string (BirdFontSvgTransform* self)
{
	GString* sb = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	GEnumValue* _tmp2_;
	GString* _tmp3_;
	GString* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_string_new ("");
	sb = _tmp0_;
	_tmp1_ = sb;
	_tmp2_ = g_enum_get_value (g_type_class_ref (BIRD_FONT_TYPE_TRANSFORM_TYPE), self->type);
	g_string_append (_tmp1_, (_tmp2_ != NULL) ? _tmp2_->value_name : NULL);
	_tmp3_ = sb;
	g_string_append (_tmp3_, " ");
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				BirdFontDoubles* _tmp6_;
				GString* _tmp7_;
				BirdFontDoubles* _tmp8_;
				gchar* _tmp9_;
				gchar* _tmp10_;
				gchar* _tmp11_;
				gchar* _tmp12_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				_tmp6_ = self->arguments;
				if (!(i < _tmp6_->size)) {
					break;
				}
				_tmp7_ = sb;
				_tmp8_ = self->arguments;
				_tmp9_ = double_to_string (bird_font_doubles_get_double (_tmp8_, i));
				_tmp10_ = _tmp9_;
				_tmp11_ = g_strconcat (_tmp10_, " ", NULL);
				_tmp12_ = _tmp11_;
				g_string_append (_tmp7_, _tmp12_);
				_g_free0 (_tmp12_);
				_g_free0 (_tmp10_);
			}
		}
	}
	_tmp13_ = sb;
	_tmp14_ = _tmp13_->str;
	_tmp15_ = g_strdup (_tmp14_);
	result = _tmp15_;
	_g_string_free0 (sb);
	return result;
}

void
bird_font_svg_transform_get_matrix (BirdFontSvgTransform* self,
                                    cairo_matrix_t* result)
{
	cairo_matrix_t matrix = {0};
	g_return_if_fail (self != NULL);
	cairo_matrix_init_identity (&matrix);
	if (self->type == BIRD_FONT_TRANSFORM_TYPE_ROTATE) {
		BirdFontDoubles* _tmp0_;
		_tmp0_ = self->arguments;
		if (_tmp0_->size == 1) {
			gdouble r = 0.0;
			BirdFontDoubles* _tmp1_;
			_tmp1_ = self->arguments;
			r = bird_font_doubles_get_double (_tmp1_, 0);
			r *= G_PI / 180;
			cairo_matrix_rotate (&matrix, r);
		}
	} else {
		if (self->type == BIRD_FONT_TRANSFORM_TYPE_SCALE) {
			BirdFontDoubles* _tmp2_;
			_tmp2_ = self->arguments;
			if (_tmp2_->size == 1) {
				gdouble s = 0.0;
				BirdFontDoubles* _tmp3_;
				_tmp3_ = self->arguments;
				s = bird_font_doubles_get_double (_tmp3_, 0);
				cairo_matrix_scale (&matrix, s, s);
			} else {
				BirdFontDoubles* _tmp4_;
				_tmp4_ = self->arguments;
				if (_tmp4_->size == 2) {
					gdouble s0 = 0.0;
					BirdFontDoubles* _tmp5_;
					gdouble s1 = 0.0;
					BirdFontDoubles* _tmp6_;
					_tmp5_ = self->arguments;
					s0 = bird_font_doubles_get_double (_tmp5_, 0);
					_tmp6_ = self->arguments;
					s1 = bird_font_doubles_get_double (_tmp6_, 1);
					cairo_matrix_scale (&matrix, s0, s1);
				}
			}
		} else {
			if (self->type == BIRD_FONT_TRANSFORM_TYPE_TRANSLATE) {
				BirdFontDoubles* _tmp7_;
				_tmp7_ = self->arguments;
				if (_tmp7_->size == 1) {
					gdouble s = 0.0;
					BirdFontDoubles* _tmp8_;
					_tmp8_ = self->arguments;
					s = bird_font_doubles_get_double (_tmp8_, 0);
					cairo_matrix_translate (&matrix, s, (gdouble) 0);
				} else {
					BirdFontDoubles* _tmp9_;
					_tmp9_ = self->arguments;
					if (_tmp9_->size == 2) {
						gdouble s0 = 0.0;
						BirdFontDoubles* _tmp10_;
						gdouble s1 = 0.0;
						BirdFontDoubles* _tmp11_;
						_tmp10_ = self->arguments;
						s0 = bird_font_doubles_get_double (_tmp10_, 0);
						_tmp11_ = self->arguments;
						s1 = bird_font_doubles_get_double (_tmp11_, 1);
						cairo_matrix_translate (&matrix, s0, s1);
					}
				}
			} else {
				if (self->type == BIRD_FONT_TRANSFORM_TYPE_MATRIX) {
					BirdFontDoubles* _tmp12_;
					_tmp12_ = self->arguments;
					if (_tmp12_->size == 6) {
						gdouble s0 = 0.0;
						BirdFontDoubles* _tmp13_;
						gdouble s1 = 0.0;
						BirdFontDoubles* _tmp14_;
						gdouble s2 = 0.0;
						BirdFontDoubles* _tmp15_;
						gdouble s3 = 0.0;
						BirdFontDoubles* _tmp16_;
						gdouble s4 = 0.0;
						BirdFontDoubles* _tmp17_;
						gdouble s5 = 0.0;
						BirdFontDoubles* _tmp18_;
						_tmp13_ = self->arguments;
						s0 = bird_font_doubles_get_double (_tmp13_, 0);
						_tmp14_ = self->arguments;
						s1 = bird_font_doubles_get_double (_tmp14_, 1);
						_tmp15_ = self->arguments;
						s2 = bird_font_doubles_get_double (_tmp15_, 2);
						_tmp16_ = self->arguments;
						s3 = bird_font_doubles_get_double (_tmp16_, 3);
						_tmp17_ = self->arguments;
						s4 = bird_font_doubles_get_double (_tmp17_, 4);
						_tmp18_ = self->arguments;
						s5 = bird_font_doubles_get_double (_tmp18_, 5);
						cairo_matrix_init (&matrix, s0, s1, s2, s3, s4, s5);
					}
				}
			}
		}
	}
	*result = matrix;
	return;
}

static void
bird_font_svg_transform_class_init (BirdFontSvgTransformClass * klass,
                                    gpointer klass_data)
{
	bird_font_svg_transform_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_svg_transform_finalize;
}

static void
bird_font_svg_transform_instance_init (BirdFontSvgTransform * self,
                                       gpointer klass)
{
	BirdFontDoubles* _tmp0_;
	self->type = BIRD_FONT_TRANSFORM_TYPE_NONE;
	_tmp0_ = bird_font_doubles_new_for_capacity (10);
	self->arguments = _tmp0_;
}

static void
bird_font_svg_transform_finalize (GObject * obj)
{
	BirdFontSvgTransform * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_SVG_TRANSFORM, BirdFontSvgTransform);
	_g_object_unref0 (self->arguments);
	G_OBJECT_CLASS (bird_font_svg_transform_parent_class)->finalize (obj);
}

static GType
bird_font_svg_transform_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontSvgTransformClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_svg_transform_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontSvgTransform), 0, (GInstanceInitFunc) bird_font_svg_transform_instance_init, NULL };
	GType bird_font_svg_transform_type_id;
	bird_font_svg_transform_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontSvgTransform", &g_define_type_info, 0);
	return bird_font_svg_transform_type_id;
}

GType
bird_font_svg_transform_get_type (void)
{
	static volatile gsize bird_font_svg_transform_type_id__once = 0;
	if (g_once_init_enter (&bird_font_svg_transform_type_id__once)) {
		GType bird_font_svg_transform_type_id;
		bird_font_svg_transform_type_id = bird_font_svg_transform_get_type_once ();
		g_once_init_leave (&bird_font_svg_transform_type_id__once, bird_font_svg_transform_type_id);
	}
	return bird_font_svg_transform_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;
}

