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

/*
Copyright (C) 2012 2013 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 <stdlib.h>
#include <string.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_OS2_TABLE_0_PROPERTY,
	BIRD_FONT_OS2_TABLE_NUM_PROPERTIES
};
static GParamSpec* bird_font_os2_table_properties[BIRD_FONT_OS2_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))

struct _BirdFontOs2TablePrivate {
	BirdFontGlyfTable* glyf_table;
	BirdFontHmtxTable* hmtx_table;
	BirdFontHheaTable* hhea_table;
};

static gint BirdFontOs2Table_private_offset;
static gpointer bird_font_os2_table_parent_class = NULL;

static void bird_font_os2_table_real_parse (BirdFontOtfTable* base,
                                     BirdFontFontData* dis,
                                     GError** error);
static void bird_font_os2_table_finalize (GObject * obj);
static GType bird_font_os2_table_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_os2_table_get_instance_private (BirdFontOs2Table* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontOs2Table_private_offset);
}

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

BirdFontOs2Table*
bird_font_os2_table_construct (GType object_type,
                               BirdFontGlyfTable* gt,
                               BirdFontHmtxTable* hmtx,
                               BirdFontHheaTable* hhea)
{
	BirdFontOs2Table * self = NULL;
	gchar* _tmp0_;
	BirdFontGlyfTable* _tmp1_;
	BirdFontHmtxTable* _tmp2_;
	BirdFontHheaTable* _tmp3_;
	g_return_val_if_fail (gt != NULL, NULL);
	g_return_val_if_fail (hmtx != NULL, NULL);
	g_return_val_if_fail (hhea != NULL, NULL);
	self = (BirdFontOs2Table*) bird_font_otf_table_construct (object_type);
	_tmp0_ = g_strdup ("OS/2");
	_g_free0 (((BirdFontOtfTable*) self)->id);
	((BirdFontOtfTable*) self)->id = _tmp0_;
	_tmp1_ = _g_object_ref0 (gt);
	_g_object_unref0 (self->priv->glyf_table);
	self->priv->glyf_table = _tmp1_;
	_tmp2_ = _g_object_ref0 (hmtx);
	_g_object_unref0 (self->priv->hmtx_table);
	self->priv->hmtx_table = _tmp2_;
	_tmp3_ = _g_object_ref0 (hhea);
	_g_object_unref0 (self->priv->hhea_table);
	self->priv->hhea_table = _tmp3_;
	return self;
}

BirdFontOs2Table*
bird_font_os2_table_new (BirdFontGlyfTable* gt,
                         BirdFontHmtxTable* hmtx,
                         BirdFontHheaTable* hhea)
{
	return bird_font_os2_table_construct (BIRD_FONT_TYPE_OS2_TABLE, gt, hmtx, hhea);
}

static void
bird_font_os2_table_real_parse (BirdFontOtfTable* base,
                                BirdFontFontData* dis,
                                GError** error)
{
	BirdFontOs2Table * self;
	self = (BirdFontOs2Table*) base;
	g_return_if_fail (dis != NULL);
}

void
bird_font_os2_table_process (BirdFontOs2Table* self)
{
	g_return_if_fail (self != NULL);
	bird_font_os2_table_process_table (self, FALSE);
}

void
bird_font_os2_table_process_mac (BirdFontOs2Table* self)
{
	g_return_if_fail (self != NULL);
	bird_font_os2_table_process_table (self, TRUE);
}

void
bird_font_os2_table_process_table (BirdFontOs2Table* self,
                                   gboolean mac)
{
	BirdFontFontData* fd = NULL;
	BirdFontFontData* _tmp0_;
	BirdFontFont* font = NULL;
	BirdFontFont* _tmp1_;
	guint16 style = 0U;
	BirdFontUnicodeRangeBits* ranges = NULL;
	BirdFontUnicodeRangeBits* _tmp2_;
	BirdFontCodePageBits* pages = NULL;
	BirdFontCodePageBits* _tmp3_;
	guint32 unicodeRange1 = 0U;
	guint32 unicodeRange2 = 0U;
	guint32 unicodeRange3 = 0U;
	guint32 unicodeRange4 = 0U;
	guint32 codepage1 = 0U;
	guint32 codepage2 = 0U;
	gint16 win_descent = 0;
	BirdFontFontData* _tmp4_;
	BirdFontFontData* _tmp5_;
	BirdFontHmtxTable* _tmp6_;
	BirdFontFontData* _tmp7_;
	BirdFontFont* _tmp8_;
	BirdFontFontData* _tmp9_;
	BirdFontFontData* _tmp10_;
	BirdFontFontData* _tmp11_;
	BirdFontFontData* _tmp12_;
	BirdFontFontData* _tmp13_;
	BirdFontFontData* _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_;
	BirdFontFontData* _tmp29_;
	BirdFontFontData* _tmp30_;
	BirdFontFontData* _tmp31_;
	BirdFontUnicodeRangeBits* _tmp32_;
	BirdFontFont* _tmp33_;
	guint32 _tmp34_ = 0U;
	guint32 _tmp35_ = 0U;
	guint32 _tmp36_ = 0U;
	guint32 _tmp37_ = 0U;
	BirdFontFontData* _tmp46_;
	gboolean _tmp47_ = FALSE;
	BirdFontFont* _tmp48_;
	BirdFontFont* _tmp50_;
	BirdFontFont* _tmp51_;
	BirdFontFontData* _tmp52_;
	BirdFontFontData* _tmp53_;
	BirdFontGlyfTable* _tmp54_;
	BirdFontFontData* _tmp55_;
	BirdFontGlyfTable* _tmp56_;
	gint16 ascender = 0;
	BirdFontFont* _tmp57_;
	BirdFontFont* _tmp58_;
	gint16 descender = 0;
	BirdFontFont* _tmp59_;
	BirdFontFont* _tmp60_;
	BirdFontFontData* _tmp61_;
	BirdFontFontData* _tmp62_;
	BirdFontFontData* _tmp63_;
	BirdFontFontData* _tmp64_;
	BirdFontCodePageBits* _tmp71_;
	BirdFontFont* _tmp72_;
	guint32 _tmp73_ = 0U;
	guint32 _tmp74_ = 0U;
	gint16 xheight = 0;
	BirdFontFont* _tmp79_;
	BirdFontFont* _tmp80_;
	gint16 cap_height = 0;
	BirdFontFont* _tmp81_;
	BirdFontFont* _tmp82_;
	BirdFontFontData* _tmp83_;
	BirdFontFontData* _tmp84_;
	BirdFontFontData* _tmp85_;
	BirdFontFontData* _tmp86_;
	gint16 num_glyphs = 0;
	BirdFontFontData* _tmp87_;
	BirdFontFontData* _tmp88_;
	BirdFontFontData* _tmp89_;
	BirdFontFontData* _tmp90_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_font_data_new ((guint32) 1024);
	fd = _tmp0_;
	_tmp1_ = bird_font_open_font_format_writer_get_current_font ();
	font = _tmp1_;
	style = (guint16) 0;
	_tmp2_ = bird_font_unicode_range_bits_new ();
	ranges = _tmp2_;
	_tmp3_ = bird_font_code_page_bits_new ();
	pages = _tmp3_;
	_tmp4_ = fd;
	bird_font_font_data_add_u16 (_tmp4_, (guint16) 0x0002);
	_tmp5_ = fd;
	_tmp6_ = self->priv->hmtx_table;
	bird_font_font_data_add_16 (_tmp5_, bird_font_hmtx_table_get_average_width (_tmp6_));
	_tmp7_ = fd;
	_tmp8_ = font;
	bird_font_font_data_add_u16 (_tmp7_, (guint16) _tmp8_->weight);
	_tmp9_ = fd;
	bird_font_font_data_add_u16 (_tmp9_, (guint16) 5);
	_tmp10_ = fd;
	bird_font_font_data_add_u16 (_tmp10_, (guint16) 0);
	_tmp11_ = fd;
	bird_font_font_data_add_16 (_tmp11_, (gint16) 40);
	_tmp12_ = fd;
	bird_font_font_data_add_16 (_tmp12_, (gint16) 40);
	_tmp13_ = fd;
	bird_font_font_data_add_16 (_tmp13_, (gint16) 40);
	_tmp14_ = fd;
	bird_font_font_data_add_16 (_tmp14_, (gint16) 40);
	_tmp15_ = fd;
	bird_font_font_data_add_16 (_tmp15_, (gint16) 40);
	_tmp16_ = fd;
	bird_font_font_data_add_16 (_tmp16_, (gint16) 40);
	_tmp17_ = fd;
	bird_font_font_data_add_16 (_tmp17_, (gint16) 40);
	_tmp18_ = fd;
	bird_font_font_data_add_16 (_tmp18_, (gint16) 40);
	_tmp19_ = fd;
	bird_font_font_data_add_16 (_tmp19_, (gint16) 40);
	_tmp20_ = fd;
	bird_font_font_data_add_16 (_tmp20_, (gint16) 200);
	_tmp21_ = fd;
	bird_font_font_data_add_16 (_tmp21_, (gint16) 0);
	_tmp22_ = fd;
	bird_font_font_data_add (_tmp22_, (guint8) 0);
	_tmp23_ = fd;
	bird_font_font_data_add (_tmp23_, (guint8) 0);
	_tmp24_ = fd;
	bird_font_font_data_add (_tmp24_, (guint8) 0);
	_tmp25_ = fd;
	bird_font_font_data_add (_tmp25_, (guint8) 0);
	_tmp26_ = fd;
	bird_font_font_data_add (_tmp26_, (guint8) 0);
	_tmp27_ = fd;
	bird_font_font_data_add (_tmp27_, (guint8) 0);
	_tmp28_ = fd;
	bird_font_font_data_add (_tmp28_, (guint8) 0);
	_tmp29_ = fd;
	bird_font_font_data_add (_tmp29_, (guint8) 0);
	_tmp30_ = fd;
	bird_font_font_data_add (_tmp30_, (guint8) 0);
	_tmp31_ = fd;
	bird_font_font_data_add (_tmp31_, (guint8) 0);
	_tmp32_ = ranges;
	_tmp33_ = font;
	bird_font_unicode_range_bits_get_ranges (_tmp32_, _tmp33_, &_tmp34_, &_tmp35_, &_tmp36_, &_tmp37_);
	unicodeRange1 = _tmp34_;
	unicodeRange2 = _tmp35_;
	unicodeRange3 = _tmp36_;
	unicodeRange4 = _tmp37_;
	if (mac) {
		BirdFontFontData* _tmp38_;
		BirdFontFontData* _tmp39_;
		BirdFontFontData* _tmp40_;
		BirdFontFontData* _tmp41_;
		_tmp38_ = fd;
		bird_font_font_data_add_u32 (_tmp38_, unicodeRange1);
		_tmp39_ = fd;
		bird_font_font_data_add_u32 (_tmp39_, (guint32) 0);
		_tmp40_ = fd;
		bird_font_font_data_add_u32 (_tmp40_, (guint32) 0);
		_tmp41_ = fd;
		bird_font_font_data_add_u32 (_tmp41_, (guint32) 0);
	} else {
		BirdFontFontData* _tmp42_;
		BirdFontFontData* _tmp43_;
		BirdFontFontData* _tmp44_;
		BirdFontFontData* _tmp45_;
		_tmp42_ = fd;
		bird_font_font_data_add_u32 (_tmp42_, unicodeRange1);
		_tmp43_ = fd;
		bird_font_font_data_add_u32 (_tmp43_, unicodeRange2);
		_tmp44_ = fd;
		bird_font_font_data_add_u32 (_tmp44_, unicodeRange3);
		_tmp45_ = fd;
		bird_font_font_data_add_u32 (_tmp45_, unicodeRange4);
	}
	_tmp46_ = fd;
	bird_font_font_data_add_tag (_tmp46_, "Bird");
	_tmp48_ = font;
	if (!_tmp48_->bold) {
		BirdFontFont* _tmp49_;
		_tmp49_ = font;
		_tmp47_ = !_tmp49_->italic;
	} else {
		_tmp47_ = FALSE;
	}
	if (_tmp47_) {
		style |= BIRD_FONT_OS2_TABLE_REGULAR;
	}
	_tmp50_ = font;
	if (_tmp50_->bold) {
		style |= BIRD_FONT_OS2_TABLE_BOLD;
	}
	_tmp51_ = font;
	if (_tmp51_->italic) {
		style |= BIRD_FONT_OS2_TABLE_ITALIC;
	}
	_tmp52_ = fd;
	bird_font_font_data_add_u16 (_tmp52_, style);
	_tmp53_ = fd;
	_tmp54_ = self->priv->glyf_table;
	bird_font_font_data_add_u16 (_tmp53_, bird_font_glyf_table_get_first_char (_tmp54_));
	_tmp55_ = fd;
	_tmp56_ = self->priv->glyf_table;
	bird_font_font_data_add_u16 (_tmp55_, bird_font_glyf_table_get_last_char (_tmp56_));
	_tmp57_ = font;
	_tmp58_ = font;
	ascender = (gint16) rint ((_tmp57_->top_limit - _tmp58_->base_line) * bird_font_head_table_UNITS);
	_tmp59_ = font;
	_tmp60_ = font;
	descender = (gint16) rint ((_tmp59_->bottom_limit - _tmp60_->base_line) * bird_font_head_table_UNITS);
	_tmp61_ = fd;
	bird_font_font_data_add_16 (_tmp61_, ascender);
	_tmp62_ = fd;
	bird_font_font_data_add_16 (_tmp62_, descender);
	_tmp63_ = fd;
	bird_font_font_data_add_16 (_tmp63_, (gint16) 100);
	_tmp64_ = fd;
	bird_font_font_data_add_u16 (_tmp64_, (guint16) ascender);
	win_descent = descender;
	if (((gint) win_descent) > 0) {
		gchar* _tmp65_;
		gchar* _tmp66_;
		gchar* _tmp67_;
		gchar* _tmp68_;
		BirdFontFontData* _tmp69_;
		_tmp65_ = g_strdup_printf ("%" G_GINT16_FORMAT, win_descent);
		_tmp66_ = _tmp65_;
		_tmp67_ = g_strconcat ("usWinDescent is unsigned, can not write ", _tmp66_, " to the field.", NULL);
		_tmp68_ = _tmp67_;
		g_warning ("Os2Table.vala:147: %s", _tmp68_);
		_g_free0 (_tmp68_);
		_g_free0 (_tmp66_);
		_tmp69_ = fd;
		bird_font_font_data_add_u16 (_tmp69_, (guint16) 0);
	} else {
		BirdFontFontData* _tmp70_;
		_tmp70_ = fd;
		bird_font_font_data_add_u16 (_tmp70_, (guint16) (-win_descent));
	}
	_tmp71_ = pages;
	_tmp72_ = font;
	bird_font_code_page_bits_get_pages (_tmp71_, _tmp72_, &_tmp73_, &_tmp74_);
	codepage1 = _tmp73_;
	codepage2 = _tmp74_;
	if (mac) {
		BirdFontFontData* _tmp75_;
		BirdFontFontData* _tmp76_;
		_tmp75_ = fd;
		bird_font_font_data_add_u32 (_tmp75_, (guint32) 1);
		_tmp76_ = fd;
		bird_font_font_data_add_u32 (_tmp76_, (guint32) 0);
	} else {
		BirdFontFontData* _tmp77_;
		BirdFontFontData* _tmp78_;
		_tmp77_ = fd;
		bird_font_font_data_add_u32 (_tmp77_, codepage1);
		_tmp78_ = fd;
		bird_font_font_data_add_u32 (_tmp78_, codepage2);
	}
	_tmp79_ = font;
	_tmp80_ = font;
	xheight = (gint16) rint ((_tmp79_->xheight_position - _tmp80_->base_line) * bird_font_head_table_UNITS);
	_tmp81_ = font;
	_tmp82_ = font;
	cap_height = (gint16) rint ((_tmp81_->top_limit - _tmp82_->base_line) * bird_font_head_table_UNITS);
	_tmp83_ = fd;
	bird_font_font_data_add_16 (_tmp83_, xheight);
	_tmp84_ = fd;
	bird_font_font_data_add_16 (_tmp84_, cap_height);
	_tmp85_ = fd;
	bird_font_font_data_add_16 (_tmp85_, (gint16) 0);
	_tmp86_ = fd;
	bird_font_font_data_add_16 (_tmp86_, (gint16) 0x0020);
	num_glyphs = (gint16) 2;
	_tmp87_ = fd;
	bird_font_font_data_add_16 (_tmp87_, num_glyphs);
	_tmp88_ = fd;
	bird_font_font_data_pad (_tmp88_);
	_tmp89_ = fd;
	_tmp90_ = _g_object_ref0 (_tmp89_);
	_g_object_unref0 (((BirdFontOtfTable*) self)->font_data);
	((BirdFontOtfTable*) self)->font_data = _tmp90_;
	_g_object_unref0 (pages);
	_g_object_unref0 (ranges);
	_g_object_unref0 (font);
	_g_object_unref0 (fd);
}

static void
bird_font_os2_table_class_init (BirdFontOs2TableClass * klass,
                                gpointer klass_data)
{
	bird_font_os2_table_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontOs2Table_private_offset);
	((BirdFontOtfTableClass *) klass)->parse = (void (*) (BirdFontOtfTable*, BirdFontFontData*, GError**)) bird_font_os2_table_real_parse;
	G_OBJECT_CLASS (klass)->finalize = bird_font_os2_table_finalize;
}

static void
bird_font_os2_table_instance_init (BirdFontOs2Table * self,
                                   gpointer klass)
{
	self->priv = bird_font_os2_table_get_instance_private (self);
}

static void
bird_font_os2_table_finalize (GObject * obj)
{
	BirdFontOs2Table * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_OS2_TABLE, BirdFontOs2Table);
	_g_object_unref0 (self->priv->glyf_table);
	_g_object_unref0 (self->priv->hmtx_table);
	_g_object_unref0 (self->priv->hhea_table);
	G_OBJECT_CLASS (bird_font_os2_table_parent_class)->finalize (obj);
}

static GType
bird_font_os2_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontOs2TableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_os2_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontOs2Table), 0, (GInstanceInitFunc) bird_font_os2_table_instance_init, NULL };
	GType bird_font_os2_table_type_id;
	bird_font_os2_table_type_id = g_type_register_static (BIRD_FONT_TYPE_OTF_TABLE, "BirdFontOs2Table", &g_define_type_info, 0);
	BirdFontOs2Table_private_offset = g_type_add_instance_private (bird_font_os2_table_type_id, sizeof (BirdFontOs2TablePrivate));
	return bird_font_os2_table_type_id;
}

GType
bird_font_os2_table_get_type (void)
{
	static volatile gsize bird_font_os2_table_type_id__once = 0;
	if (g_once_init_enter (&bird_font_os2_table_type_id__once)) {
		GType bird_font_os2_table_type_id;
		bird_font_os2_table_type_id = bird_font_os2_table_get_type_once ();
		g_once_init_leave (&bird_font_os2_table_type_id__once, bird_font_os2_table_type_id);
	}
	return bird_font_os2_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;
}

