<commit_before>package openfl._internal.renderer.cairo;


import lime.graphics.cairo.Cairo;
import lime.graphics.cairo.CairoAntialias;
import lime.graphics.cairo.CairoFontFace;
import lime.graphics.cairo.CairoFontOptions;
import lime.graphics.cairo.CairoFTFontFace;
import lime.graphics.cairo.CairoGlyph;
import lime.graphics.cairo.CairoHintMetrics;
import lime.graphics.cairo.CairoHintStyle;
import lime.graphics.cairo.CairoImageSurface;
import openfl._internal.text.TextEngine;
import openfl.display.BitmapData;
import openfl.display.CairoRenderer;
import openfl.display.Graphics;
import openfl.filters.GlowFilter;
import openfl.geom.Matrix;
import openfl.geom.Rectangle;
import openfl.text.TextField;
import openfl.text.TextFormat;

#if !openfl_debug
@:fileXml('tags="haxe,release"')
@:noDebug
#end

@:access(openfl.display.BitmapData)
@:access(openfl.display.Graphics)
@:access(openfl.geom.Matrix)
@:access(openfl.text.TextField)


class CairoTextField {
	
	
	public static function render (textField:TextField, renderer:CairoRenderer, transform:Matrix) {
		
		#if lime_cairo
		
		var textEngine = textField.__textEngine;
		var bounds = (textEngine.background || textEngine.border) ? textEngine.bounds : textEngine.textBounds;
		var graphics = textField.__graphics;
		var cairo = graphics.__cairo;
		
		if (textField.__dirty) {
			
			textField.__updateLayout ();
			
			if (graphics.__bounds == null) {
				
				graphics.__bounds = new Rectangle ();
				
			}
			
			graphics.__bounds.copyFrom (bounds);
			
			//graphics.__bounds.x += textField.__offsetX;
			//graphics.__bounds.y += textField.__offsetY;
			
		}
		
		graphics.__update (renderer.__worldTransform);
		
		var width = graphics.__width;
		var height = graphics.__height;
		
		var renderable = (textEngine.border || textEngine.background || textEngine.text != null);
		var needsUpscaling = false;
		
		if (cairo != null) {
			
			//var surface:CairoImageSurface = cast cairo.target;
			var surface = graphics.__bitmap.getSurface ();
			
			if (graphics.__dirty && (width > surface.width || height > surface.height)) {
				
				needsUpscaling = true;
				
			}
			
			if (!renderable || needsUpscaling) {
				
				graphics.__cairo = null;
				graphics.__bitmap = null;
				graphics.__visible = false;
				cairo = null;
				
			}
			
		}
		
		if (width <= 0 || height <= 0 || (!textField.__dirty && !graphics.__dirty) || !renderable) {
			
			textField.__dirty = false;
			return;
			
		}
		
		if (cairo == null) {
			
			var bitmap = needsUpscaling ?
					new BitmapData (Std.int (Math.min (width * 1.25, Graphics.maxTextureWidth)), Std.int (Math.min (height * 1.25, Graphics.maxTextureHeight)), true, 0) :
					new BitmapData (width, height, true, 0);
			var surface = bitmap.getSurface ();
			graphics.__cairo = new Cairo (surface);
			graphics.__visible = true;
			graphics.__managed = true;
			
			graphics.__bitmap = bitmap;
			<commit_msg>Software render fix<commit_after>package openfl._internal.renderer.cairo;


import lime.graphics.cairo.Cairo;
import lime.graphics.cairo.CairoAntialias;
import lime.graphics.cairo.CairoFontFace;
import lime.graphics.cairo.CairoFontOptions;
import lime.graphics.cairo.CairoFTFontFace;
import lime.graphics.cairo.CairoGlyph;
import lime.graphics.cairo.CairoHintMetrics;
import lime.graphics.cairo.CairoHintStyle;
import lime.graphics.cairo.CairoImageSurface;
import openfl._internal.text.TextEngine;
import openfl.display.BitmapData;
import openfl.display.CairoRenderer;
import openfl.display.Graphics;
import openfl.filters.GlowFilter;
import openfl.geom.Matrix;
import openfl.geom.Rectangle;
import openfl.text.TextField;
import openfl.text.TextFormat;

#if !openfl_debug
@:fileXml('tags="haxe,release"')
@:noDebug
#end

@:access(openfl.display.BitmapData)
@:access(openfl.display.Graphics)
@:access(openfl.geom.Matrix)
@:access(openfl.text.TextField)


class CairoTextField {
	
	
	public static function render (textField:TextField, renderer:CairoRenderer, transform:Matrix) {
		
		#if lime_cairo
		
		var textEngine = textField.__textEngine;
		var bounds = (textEngine.background || textEngine.border) ? textEngine.bounds : textEngine.textBounds;
		var graphics = textField.__graphics;
		var cairo = graphics.__cairo;
		
		if (textField.__dirty) {
			
			textField.__updateLayout ();
			
			if (graphics.__bounds == null) {
				
				graphics.__bounds = new Rectangle ();
				
			}
			
			graphics.__bounds.copyFrom (bounds);
			
			//graphics.__bounds.x += textField.__offsetX;
			//graphics.__bounds.y += textField.__offsetY;
			
		}
		
		graphics.__update (renderer.__worldTransform);
		
		var width = graphics.__width;
		var height = graphics.__height;
		
		var renderable = (textEngine.border || textEngine.background || textEngine.text != null);
		var needsUpscaling = false;
		
		if (cairo != null) {
			
			//var surface:CairoImageSurface = cast cairo.target;
			var surface = graphics.__bitmap.getSurface ();
			
			if (graphics.__dirty && (width > surface.width || height > surface.height)) {
				
				needsUpscaling = true;
				
			}
			
			if (!renderable || needsUpscaling) {
				
				graphics.__cairo = null;
				graphics.__bitmap = null;
				graphics.__visible = false;
				cairo = null;
				
			}
			
		}
		
		if (width <= 0 || height <= 0 || (!textField.__dirty && !graphics.__dirty) || !renderable) {
			
			textField.__dirty = false;
			return;
			
		}
		
		if (cairo == null) {
			
			var bitmapWidth = needsUpscaling ? Std.int (width * 1.25) : width;
			var bitmapHeight = needsUpscaling ? Std.int (height * 1.25) : height;
			
			if (Graphics.maxTextureWidth != null && bitmapWidth > Graphics.maxTextureWidth) {
				
				bitmapWidth = Graphics.maxTextureWidth;
				
			}
			
			if (Graphics.maxTextureHeight != null && bitmapHeight > Graphics.maxTextureHeight) {
				
				bitmapHeight = Graphics.maxTextureHeight;
				
			}
			
			var bitmap = new BitmapData (bitmapWidth, bitmapHeight, true, 0);
			var surface = bitmap.getSurface ();
			graphics.__cairo = new Cairo (surface);
			graphics.__visible = true;
			graphics.__managed = true;
			
			graphics.__bitmap = bitmap;
			
{'fraction_non_alphanumeric': 0.11665575916230367, 'fraction_numerical': 0.003108638743455497, 'mean_word_length': 3.6451367781155017, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7316408', 'n_tokens_mistral': 2316, 'n_tokens_neox': 1881, 'n_words': 383}