Skip to content

Instantly share code, notes, and snippets.

@lion328
Created May 1, 2015 13:56
Show Gist options
  • Save lion328/620f9289727119231a56 to your computer and use it in GitHub Desktop.
Save lion328/620f9289727119231a56 to your computer and use it in GitHub Desktop.
ThaiFixes 1.8.4 (Vanilla mod) Source code
diff --git a/original_src/avn.java b/modified_src/avn.java
index 0371507..d8af3ce 100644
--- a/original_src/avn.java
+++ b/modified_src/avn.java
@@ -1,6 +1,7 @@
import com.ibm.icu.text.ArabicShaping;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.Bidi;
+import com.lion328.thaifixes.ThaiFixesUtils;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
@@ -35,6 +36,7 @@ public class avn implements bnj {
private boolean t;
private boolean u;
private boolean v;
+ private char beforeChar = 0;
public avn(avh var, jy var1, bmj var2, boolean var3) {
this.g = var1;
@@ -151,13 +153,19 @@ public class avn implements bnj {
}
private float a(char var, boolean var1) {
- if (var == 32) {
- return 4.0F;
+ float out = 0;
+ if (ThaiFixesUtils.isThaiChar(var)) {
+ out = this.renderThaiChar(var, var1);
+ }
+ else if (var == 32) {
+ out = 4.0F;
} else {
int var2 = "ÀÁÂÈÊËÍÓÔÕÚßãõğİıŒœŞşŴŵžȇ\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø×ƒáíóúñѪº¿®¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αβΓπΣσμτΦΘΩδ∞∅∈∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\u0000".indexOf(var);
- return var2 != -1 && !this.k ? this.a(var2, var1) : this.b(var, var1);
+ out = var2 != -1 && !this.k ? this.a(var2, var1) : this.b(var, var1);
}
+ beforeChar = var;
+ return out;
}
private float a(int var, boolean var1) {
@@ -223,6 +231,49 @@ public class avn implements bnj {
return (var6 - var5) / 2.0F + 1.0F;
}
}
+
+ private float renderThaiChar(char c, boolean italic) {
+ if (!ThaiFixesUtils.isSpecialThaiChar(c)) {
+ return this.b(c, italic);
+ }
+
+ byte size = this.e[c];
+ float charHeightOnTexture = 4.98F;
+ float beginTexcoordY = ThaiFixesUtils.isLowerThaiChar(c) ? 15.98F - charHeightOnTexture : 0F;
+ float quadHeight = charHeightOnTexture / 2; // vertex position, not for texture coordinate.
+
+ // glyphWidth format:
+ // XXXXYYYY, XXXX as start X position on texture coordinate and YYYY as width.
+ float startTexcoordX = (float)(size >>> 4);
+ float charWidth = (float)((size & 0xF) + 1);
+
+ float texcoordX = (float)(c % 16 * 16) + startTexcoordX;
+ float texcoordY = (float)((c & 255) / 16 * 16);
+ float realCharWidth = charWidth - startTexcoordX - 0.02F;
+ float italicSize = italic ? 1.0F : 0.0F;
+
+ float cPosX = i - (realCharWidth - 0.02F) / 2 - 1 + 0.5F; // get current position
+ float cPosY = j;
+
+ if (ThaiFixesUtils.isLowerThaiChar(c)) {
+ cPosY += 0.5F;
+ }
+ if (ThaiFixesUtils.isSpecialThaiChar(c) && ThaiFixesUtils.isSpecialThaiChar(beforeChar) && c != beforeChar) {
+ cPosY -= 0.5F;
+ }
+
+ GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
+ GL11.glTexCoord2f(texcoordX / 256.0F, (texcoordY + beginTexcoordY) / 256.0F);
+ GL11.glVertex2f(cPosX + italicSize, cPosY + (beginTexcoordY / 2));
+ GL11.glTexCoord2f(texcoordX / 256.0F, (texcoordY + beginTexcoordY + charHeightOnTexture) / 256.0F);
+ GL11.glVertex2f(cPosX - italicSize, cPosY + (beginTexcoordY / 2) + quadHeight);
+ GL11.glTexCoord2f((texcoordX + realCharWidth) / 256.0F, (texcoordY + beginTexcoordY) / 256.0F);
+ GL11.glVertex2f(cPosX + realCharWidth / 2.0F + italicSize, cPosY + (beginTexcoordY / 2));
+ GL11.glTexCoord2f((texcoordX + realCharWidth) / 256.0F, (texcoordY + beginTexcoordY + charHeightOnTexture) / 256.0F);
+ GL11.glVertex2f(cPosX + realCharWidth / 2.0F - italicSize, cPosY + (beginTexcoordY / 2) + quadHeight);
+ GL11.glEnd();
+ return 0;//(realCharWidth + 0.02F) / 2.0F + 1.0F;
+ }
public int a(String var, float var1, float var2, int var3) {
return this.a(var, var1, var2, var3, true);
@@ -469,7 +520,9 @@ public class avn implements bnj {
}
public int a(char var) {
- if (var == 167) {
+ if (ThaiFixesUtils.isSpecialThaiChar(var)) {
+ return 0;
+ } else if (var == 167) {
return -1;
} else if (var == 32) {
return 4;
/*
* Copyright (c) 2014-2015 Waritnan Sookbuntherng
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lion328.thaifixes;
public class ThaiFixesUtils {
public static boolean isThaiChar(char c) {
return c >= 3585 && c <= 3675;
}
public static boolean isSpecialThaiChar(char c) {
return isLowerThaiChar(c) || isUpperThaiChar(c);
}
public static boolean isUpperThaiChar(char c) {
return "ัิีึื็่้๊๋์ํ๎".indexOf(c) != -1;
}
public static boolean isLowerThaiChar(char c) {
return "ฺุู".indexOf(c) != -1;
}
public static boolean isSpecialSpecialThaiChar(char c) {
return "่้๊๋".indexOf(c) != -1;
}
public static boolean isVeryLongTailThaiChar(char c) {
return "ฟฝฬ".indexOf(c) != -1;
}
@Deprecated
public static char convertKeycharToUnicode(char c) {
return (char)((int)c + 3424);
}
@Deprecated
public static char convertToThai(char c) {
return isThaiChar(convertKeycharToUnicode(c)) ? convertKeycharToUnicode(c) : c;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment