73 lines
2.1 KiB
Java
73 lines
2.1 KiB
Java
package speiger.src.coreengine.rendering.gui.renderer.provider;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import speiger.src.coreengine.rendering.gui.renderer.IFontRenderer.CharInstance;
|
|
import speiger.src.coreengine.rendering.textures.base.ITexture;
|
|
import speiger.src.coreengine.utils.helpers.JsonUtil;
|
|
|
|
public interface IFontProvider
|
|
{
|
|
public ITexture getTexture();
|
|
public boolean isCharacterValid(int codePoint);
|
|
public CharInstance getCharacter(int codePoint, boolean bold);
|
|
public float height();
|
|
public float baseLine();
|
|
|
|
public float getSpaceWidth();
|
|
public float getTabWidth();
|
|
|
|
public void destroy();
|
|
|
|
public static class FontInfo
|
|
{
|
|
public int textureWidth;
|
|
public int textureHeight;
|
|
public float fontHeight;
|
|
public float fontBase;
|
|
public int tabs;
|
|
|
|
public FontInfo(JsonObject obj)
|
|
{
|
|
this(obj.get("width").getAsInt(), obj.get("height").getAsInt(), obj.get("charHeight").getAsInt(), obj.get("base").getAsInt(), JsonUtil.getOrDefault(obj, "tabs", 4));
|
|
}
|
|
|
|
public FontInfo(int textureWidth, int textureHeight, float fontHeight, float fontBase, int tabs)
|
|
{
|
|
this.textureWidth = textureWidth;
|
|
this.textureHeight = textureHeight;
|
|
this.fontHeight = fontHeight;
|
|
this.fontBase = fontBase;
|
|
this.tabs = tabs;
|
|
}
|
|
|
|
public float setDesiredHeight(float desired)
|
|
{
|
|
float multiplier = desired / fontHeight;
|
|
fontHeight *= multiplier;
|
|
fontBase *= multiplier;
|
|
return multiplier;
|
|
}
|
|
|
|
public CharInstance create(JsonObject obj)
|
|
{
|
|
return create(obj.get("char").getAsInt(), obj.get("minX").getAsInt(), obj.get("minY").getAsInt(), obj.get("maxX").getAsInt(), obj.get("maxY").getAsInt(), JsonUtil.getOrDefault(obj, "bold", false));
|
|
}
|
|
|
|
public CharInstance create(int character, int minX, int minY, int maxX, int maxY, boolean bold)
|
|
{
|
|
return new CharInstance(character, maxX - minX, maxY - minY, getTextureU(minX), getTextureV(minY), getTextureU(maxX), getTextureV(maxY), maxX - minX, bold);
|
|
}
|
|
|
|
public float getTextureU(float value)
|
|
{
|
|
return value / textureWidth;
|
|
}
|
|
|
|
public float getTextureV(float value)
|
|
{
|
|
return value / textureHeight;
|
|
}
|
|
}
|
|
}
|