<commit_before>#include <cairo.h>
#include <cairo-ft.h>
#include <math/Matrix3.h>
#include <math/Vector2.h>
#include <hx/CFFIPrime.h>
#include <text/Font.h>


namespace lime {
	
	
	void gc_cairo (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_t* cairo = (cairo_t*)val_data (handle);
			cairo_destroy (cairo);
			
		}
		
	}
	
	
	void gc_cairo_font_face (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_font_face_t* face = (cairo_font_face_t*)val_data (handle);
			cairo_font_face_destroy (face);
			
		}
		
	}
	
	
	void gc_cairo_font_options (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_font_options_t* options = (cairo_font_options_t*)val_data (handle);
			cairo_font_options_destroy (options);
			
		}
		
	}
	
	
	void gc_cairo_pattern (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_pattern_t* pattern = (cairo_pattern_t*)val_data (handle);
			cairo_pattern_destroy (pattern);
			
		}
		
	}
	
	
	void gc_cairo_surface (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_surface_t* surface = (cairo_surface_t*)val_data (handle);
			cairo_surface_destroy (surface);
			
		}
		
	}
	
	
	void lime_cairo_arc (value handle, double xc, double yc, double radius, double angle1, double angle2) {
		
		cairo_arc ((cairo_t*)val_data (handle), xc, yc, radius, angle1, angle2);
		
	}
	
	
	void lime_cairo_arc_negative (value handle, double xc, double yc, double radius, double angle1, double angle2) {
		
		cairo_arc_negative ((cairo_t*)val_data (handle), xc, yc, radius, angle1, angle2);
		
	}
	
	
	void lime_cairo_clip (value handle) {
		
		cairo_clip ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_clip_extents (value handle, double x1, double y1, double x2, double y2) {
		
		cairo_clip_extents ((cairo_t*)val_data (handle), &x1, &y1, &x2, &y2);
		
	}
	
	
	void lime_cairo_clip_preserve (value handle) {
		
		cairo_clip_preserve ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_close_path (value handle) {
		
		cairo_close_path ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_copy_page (value handle) {
		
		cairo_copy_page ((cairo_t*)val_data (handle));
		
	}
	
	
	value lime_cairo_create (value surface) {
		
		cairo_t* cairo = cairo_create ((cairo_surface_t*)val_data (surface));
		value handle = cffi::alloc_pointer (cairo);
		val_gc (handle, gc_cairo);
		return handle;
		
	}
	
	
	void lime_cairo_curve_to (value handle, double x1, double y1, double x2, double y2, double x3, double y3) {
		
		cairo_curve_to ((cairo_t*)val_data (handle), x1, y1, x2, y2, x3, y3);
		
	}
	
	
	void lime_cairo_fill (value handle) {
		
		cairo_fill ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_fill_extents (value handle, double x1, double y1, double x2, double y2) {
		
		cairo_fill_extents ((cairo_t*)val_data (handle), &x1, &y1, &x2, &y2);
		
	}
	
	
	void lime_cairo_fill_preserve (value handle) {
		
		cairo_fill_preserve ((cairo_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_face_status (value handle) {
		
		return cairo_font_face_status ((cairo_font_face_t*)val_data (handle));
		
	}
	
	
	value lime_cairo_font_options_create () {
		
		value handle = cffi::alloc_pointer (cairo_font_options_create ());
		val_gc (handle, gc_cairo_font_options);
		return handle;
		
	}
	
	
	int lime_cairo_font_options_get_antialias (value handle) {
		
		return cairo_font_options_get_antialias ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_options_get_hint_metrics (value handle) {
		
		return cairo_font_options_get_hint_metrics ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_options_get_hint_style (value handle) {
		
		return cairo_font_options_get_hint_style ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_options_get_subpixel_order (value handle) {
		
		return cairo_font_options_get_subpixel_order ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_font_options_set_antialias (value handle, int v) {
		
		cairo_font_options_set_antialias ((cairo_font_options_t*)val_data (handle), (cairo_antialias_t)v);
		
	}
	
	
	void lime_cairo_font_options_set_hint_metrics (value handle, int v) {
		
		cairo_font_options_set_hint_metrics ((cairo_font_options_t*)val_data (handle), (cairo_hint_metrics_t)v);
		
	}
	
	
	void lime_cairo_font_options_set_hint_style (value handle, int v) {
		
		cairo_font_options_set_hint_style ((cairo_font_options_t*)val_data (handle), (cairo_hint_style_t)v);
		
	}
	
	
	void lime_cairo_font_options_set_subpixel_order (value handle, int v) {
		
		cairo_font_options_set_subpixel_order ((cairo_font_options_t*)val_data (handle), (cairo_subpixel_order_t)v);
		
	}
	
	
	value lime_cairo_ft_font_face_create (value face, int flags) {
		
		#ifdef LIME_FREETYPE
		Font *font = (Font*)val_data (face);
		cairo_font_face_t* cairoFont = cairo_ft_font_face_create_for_ft_face ((FT_Face)font->face, flags);
		value handle = cffi::alloc_pointer (cairoFont);
		val_gc (handle, gc_cairo_font_face);
		return handle;
		#else
		return 0;
		#endif
		
	}
	
	
	int lime_cairo_get_antialias (value handle) {
		
		return cairo_get_antialias ((cairo_t*)val_data (handle));
		
	}
	
	
	value lime_cairo_get_current_point (value handle) {
		
		double x, y;
		cairo_get_current_point ((cairo_t*)val_data (handle), &x, &y);
		Vector2 vec2 = Vector2 (x, y);
		return vec2.Value ();
		
	}
	
	
	value lime_cairo_get_dash (value handle) {
		
		int length = cairo_get_dash_count ((cairo_t*)val_data (handle));<commit_msg>Improve Cairo bindings to hold a GC reference to Fonts used<commit_after>#include <cairo.h>
#include <cairo-ft.h>
#include <math/Matrix3.h>
#include <math/Vector2.h>
#include <hx/CFFIPrime.h>
#include <text/Font.h>


namespace lime {
	
	
	cairo_user_data_key_t userData;
	
	
	void gc_cairo (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_t* cairo = (cairo_t*)val_data (handle);
			cairo_destroy (cairo);
			
		}
		
	}
	
	
	void gc_cairo_font_face (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_font_face_t* face = (cairo_font_face_t*)val_data (handle);
			cairo_font_face_destroy (face);
			
		}
		
	}
	
	
	void gc_cairo_font_options (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_font_options_t* options = (cairo_font_options_t*)val_data (handle);
			cairo_font_options_destroy (options);
			
		}
		
	}
	
	
	void gc_cairo_pattern (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_pattern_t* pattern = (cairo_pattern_t*)val_data (handle);
			cairo_pattern_destroy (pattern);
			
		}
		
	}
	
	
	void gc_cairo_surface (value handle) {
		
		if (!val_is_null (handle)) {
			
			cairo_surface_t* surface = (cairo_surface_t*)val_data (handle);
			cairo_surface_destroy (surface);
			
		}
		
	}
	
	
	void gc_user_data (void* data) {
		
		AutoGCRoot* reference = (AutoGCRoot*)data;
		delete reference;
		
	}
	
	
	void lime_cairo_arc (value handle, double xc, double yc, double radius, double angle1, double angle2) {
		
		cairo_arc ((cairo_t*)val_data (handle), xc, yc, radius, angle1, angle2);
		
	}
	
	
	void lime_cairo_arc_negative (value handle, double xc, double yc, double radius, double angle1, double angle2) {
		
		cairo_arc_negative ((cairo_t*)val_data (handle), xc, yc, radius, angle1, angle2);
		
	}
	
	
	void lime_cairo_clip (value handle) {
		
		cairo_clip ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_clip_extents (value handle, double x1, double y1, double x2, double y2) {
		
		cairo_clip_extents ((cairo_t*)val_data (handle), &x1, &y1, &x2, &y2);
		
	}
	
	
	void lime_cairo_clip_preserve (value handle) {
		
		cairo_clip_preserve ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_close_path (value handle) {
		
		cairo_close_path ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_copy_page (value handle) {
		
		cairo_copy_page ((cairo_t*)val_data (handle));
		
	}
	
	
	value lime_cairo_create (value surface) {
		
		cairo_t* cairo = cairo_create ((cairo_surface_t*)val_data (surface));
		value handle = cffi::alloc_pointer (cairo);
		val_gc (handle, gc_cairo);
		return handle;
		
	}
	
	
	void lime_cairo_curve_to (value handle, double x1, double y1, double x2, double y2, double x3, double y3) {
		
		cairo_curve_to ((cairo_t*)val_data (handle), x1, y1, x2, y2, x3, y3);
		
	}
	
	
	void lime_cairo_fill (value handle) {
		
		cairo_fill ((cairo_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_fill_extents (value handle, double x1, double y1, double x2, double y2) {
		
		cairo_fill_extents ((cairo_t*)val_data (handle), &x1, &y1, &x2, &y2);
		
	}
	
	
	void lime_cairo_fill_preserve (value handle) {
		
		cairo_fill_preserve ((cairo_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_face_status (value handle) {
		
		return cairo_font_face_status ((cairo_font_face_t*)val_data (handle));
		
	}
	
	
	value lime_cairo_font_options_create () {
		
		value handle = cffi::alloc_pointer (cairo_font_options_create ());
		val_gc (handle, gc_cairo_font_options);
		return handle;
		
	}
	
	
	int lime_cairo_font_options_get_antialias (value handle) {
		
		return cairo_font_options_get_antialias ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_options_get_hint_metrics (value handle) {
		
		return cairo_font_options_get_hint_metrics ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_options_get_hint_style (value handle) {
		
		return cairo_font_options_get_hint_style ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	int lime_cairo_font_options_get_subpixel_order (value handle) {
		
		return cairo_font_options_get_subpixel_order ((cairo_font_options_t*)val_data (handle));
		
	}
	
	
	void lime_cairo_font_options_set_antialias (value handle, int v) {
		
		cairo_font_options_set_antialias ((cairo_font_options_t*)val_data (handle), (cairo_antialias_t)v);
		
	}
	
	
	void lime_cairo_font_options_set_hint_metrics (value handle, int v) {
		
		cairo_font_options_set_hint_metrics ((cairo_font_options_t*)val_data (handle), (cairo_hint_metrics_t)v);
		
	}
	
	
	void lime_cairo_font_options_set_hint_style (value handle, int v) {
		
		cairo_font_options_set_hint_style ((cairo_font_options_t*)val_data (handle), (cairo_hint_style_t)v);
		
	}
	
	
	void lime_cairo_font_options_set_subpixel_order (value handle, int v) {
		
		cairo_font_options_set_subpixel_order ((cairo_font_options_t*)val_data (handle), (cairo_subpixel_order_t)v);
		
	}
	
	
	value lime_cairo_ft_font_face_create (value face, int flags) {
		
		#ifdef LIME_FREETYPE
		Font* font = (Font*)val_data (face);
		cairo_font_face_t* cairoFont = cairo_ft_font_face_create_for_ft_face ((FT_Face)font->face, flags);
		
		AutoGCRoot* fontReference = new AutoGCRoot (face);
		cairo_font_face_set_user_data (cairoFont, &userData, fontReference, gc_user_data);
		
		value handle = cffi::alloc_pointer (cairoFont);
		val_gc (handle, gc_cairo_font_face);
		return handle;
		#else
		return 0;
		#endif
		
	}
	
	
	int lime_cairo_get_antialias (value handle) {
		
		return cairo_get_antialias ((cairo_t*)val_data (handle));
		
	}
	
	
	value lime_cairo_get_current_point (value handle) {
		
		double x, y;
		cairo_get_current_point ((cairo_t*)val_data (handle), &x, &y);
		Vector2 vec2 = Vector2 (x, y);
		return vec2.Value ();
		
	}
	
	
	value lime_cairo_get_dash (value handle) {
		
		int length = cairo_get_dash_count ((cairo_t*)val_data (handle));
{'fraction_non_alphanumeric': 0.10524927459773147, 'fraction_numerical': 0.007561769102259738, 'mean_word_length': 4.2633040259139285, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4929529', 'n_tokens_mistral': 5140, 'n_tokens_neox': 4349, 'n_words': 836}