package speiger.src.coreengine.rendering.guiOld.renderer;

import speiger.src.coreengine.rendering.guiOld.components.TextComponent;
import speiger.src.coreengine.rendering.texturesOld.base.ITexture;

public interface IFontRenderer
{
	public static final int BOLD = 1;
	public static final int SPECIAL = 2;
	
	public float height();
	public float baseLine();
	public ITexture getTexture();
	public CharInstance getInstance(int codepoint, boolean bold);
	
	public void updateText(TextComponent component);
	
	public default String trimToWidth(String text, float limit){return trimToWidth(text, limit, false);}
	public String trimToWidth(String text, float limit, boolean reverse);
	
	public default float width(int codepoint){return width(codepoint, false);};
	public float width(int codepoint, boolean bold);
	
	public default float width(String text){return width(text, 0);};
	public float width(String text, int flags);
	public float[] widths(String text, int flags);
	
	public default float height(String text){return height(text, 0);};
	public float height(String text, int flags);
	
	public String[] split(String text, float maxWidth, int flags);
	
	public boolean isCharValid(int codepoint);
	public default String clearInvalidLetters(String text) 
	{
		if(text == null || text.isEmpty())
		{
			return "";
		}
		StringBuilder builder = new StringBuilder(text.length());
		for(int i = 0,m=text.length();i<m;)
		{
			int codePoint = text.codePointAt(i);
			if(isCharValid(codePoint)) builder.append(Character.toChars(codePoint));
			i += Character.charCount(codePoint);
		}
		return builder.toString();
	}
	
	
	public static final class CharInstance
	{
		int character;
		float width;
		float height;
		float minU;
		float minV;
		float maxU;
		float maxV;
		float xAdvance;
		boolean bold;
		
		public CharInstance(int character, boolean bold)
		{
			this.character = character;
			this.bold = bold;
		}
		
		public CharInstance(int character, int width, int height, float minU, float minV, float maxU, float maxV, int xAdvance, boolean bold)
		{
			this.character = character;
			this.width = width;
			this.height = height;
			this.minU = minU;
			this.minV = minV;
			this.maxU = maxU;
			this.maxV = maxV;
			this.xAdvance = xAdvance;
			this.bold = bold;
		}
		
		public void scale(float scale)
		{
			width *= scale;
			height *= scale;
			xAdvance *= scale;
		}
		
		public int getCharacter()
		{
			return character;
		}
		
		public float getWidth()
		{
			return width;
		}
		
		public float getHeight()
		{
			return height;
		}
		
		public float getMinU()
		{
			return minU;
		}
		
		public float getMinV()
		{
			return minV;
		}
		
		public float getMaxU()
		{
			return maxU;
		}
		
		public float getMaxV()
		{
			return maxV;
		}
		
		public float getXAdvance()
		{
			return xAdvance;
		}
		
		public boolean isBold()
		{
			return bold;
		}
	}
}
