|
| 1 | +//Deobfuscated with https://github.com/SimplyProgrammer/Minecraft-Deobfuscator3000 using mappings "C:\Users\u1\Documents\Java Decompiler\1.12 stable mappings"! |
| 2 | + |
| 3 | +//Decompiled by Procyon! |
| 4 | + |
| 5 | +package com.veteran.hack.gui.font; |
| 6 | + |
| 7 | +import net.minecraft.client.renderer.texture.*; |
| 8 | +import java.awt.image.*; |
| 9 | +import java.awt.*; |
| 10 | +import java.awt.geom.*; |
| 11 | +import org.lwjgl.opengl.*; |
| 12 | + |
| 13 | +public class CFont |
| 14 | +{ |
| 15 | + private float imgSize; |
| 16 | + protected CharData[] charData; |
| 17 | + protected Font font; |
| 18 | + protected boolean antiAlias; |
| 19 | + protected boolean fractionalMetrics; |
| 20 | + protected int fontHeight; |
| 21 | + protected int charOffset; |
| 22 | + protected DynamicTexture tex; |
| 23 | + |
| 24 | + public CFont(final Font font, final boolean antiAlias, final boolean fractionalMetrics) { |
| 25 | + this.imgSize = 512.0f; |
| 26 | + this.charData = new CharData[256]; |
| 27 | + this.fontHeight = -1; |
| 28 | + this.charOffset = 0; |
| 29 | + this.font = font; |
| 30 | + this.antiAlias = antiAlias; |
| 31 | + this.fractionalMetrics = fractionalMetrics; |
| 32 | + this.tex = this.setupTexture(font, antiAlias, fractionalMetrics, this.charData); |
| 33 | + } |
| 34 | + |
| 35 | + protected DynamicTexture setupTexture(final Font font, final boolean antiAlias, final boolean fractionalMetrics, final CharData[] chars) { |
| 36 | + final BufferedImage img = this.generateFontImage(font, antiAlias, fractionalMetrics, chars); |
| 37 | + try { |
| 38 | + return new DynamicTexture(img); |
| 39 | + } |
| 40 | + catch (Exception e) { |
| 41 | + e.printStackTrace(); |
| 42 | + return null; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + protected BufferedImage generateFontImage(final Font font, final boolean antiAlias, final boolean fractionalMetrics, final CharData[] chars) { |
| 47 | + final int imgSize = (int)this.imgSize; |
| 48 | + final BufferedImage bufferedImage = new BufferedImage(imgSize, imgSize, 2); |
| 49 | + final Graphics2D g = (Graphics2D)bufferedImage.getGraphics(); |
| 50 | + g.setFont(font); |
| 51 | + g.setColor(new Color(255, 255, 255, 0)); |
| 52 | + g.fillRect(0, 0, imgSize, imgSize); |
| 53 | + g.setColor(Color.WHITE); |
| 54 | + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, fractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF); |
| 55 | + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antiAlias ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); |
| 56 | + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); |
| 57 | + final FontMetrics fontMetrics = g.getFontMetrics(); |
| 58 | + int charHeight = 0; |
| 59 | + int positionX = 0; |
| 60 | + int positionY = 1; |
| 61 | + for (int i = 0; i < chars.length; ++i) { |
| 62 | + final char ch = (char)i; |
| 63 | + final CharData charData = new CharData(); |
| 64 | + final Rectangle2D dimensions = fontMetrics.getStringBounds(String.valueOf(ch), g); |
| 65 | + charData.width = dimensions.getBounds().width + 8; |
| 66 | + charData.height = dimensions.getBounds().height; |
| 67 | + if (positionX + charData.width >= imgSize) { |
| 68 | + positionX = 0; |
| 69 | + positionY += charHeight; |
| 70 | + charHeight = 0; |
| 71 | + } |
| 72 | + if (charData.height > charHeight) { |
| 73 | + charHeight = charData.height; |
| 74 | + } |
| 75 | + charData.storedX = positionX; |
| 76 | + charData.storedY = positionY; |
| 77 | + if (charData.height > this.fontHeight) { |
| 78 | + this.fontHeight = charData.height; |
| 79 | + } |
| 80 | + chars[i] = charData; |
| 81 | + g.drawString(String.valueOf(ch), positionX + 2, positionY + fontMetrics.getAscent()); |
| 82 | + positionX += charData.width; |
| 83 | + } |
| 84 | + return bufferedImage; |
| 85 | + } |
| 86 | + |
| 87 | + public void drawChar(final CharData[] chars, final char c, final float x, final float y) throws ArrayIndexOutOfBoundsException { |
| 88 | + try { |
| 89 | + this.drawQuad(x, y, (float)chars[c].width, (float)chars[c].height, (float)chars[c].storedX, (float)chars[c].storedY, (float)chars[c].width, (float)chars[c].height); |
| 90 | + } |
| 91 | + catch (Exception e) { |
| 92 | + e.printStackTrace(); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + protected void drawQuad(final float x, final float y, final float width, final float height, final float srcX, final float srcY, final float srcWidth, final float srcHeight) { |
| 97 | + final float renderSRCX = srcX / this.imgSize; |
| 98 | + final float renderSRCY = srcY / this.imgSize; |
| 99 | + final float renderSRCWidth = srcWidth / this.imgSize; |
| 100 | + final float renderSRCHeight = srcHeight / this.imgSize; |
| 101 | + GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY); |
| 102 | + GL11.glVertex2d((double)(x + width), (double)y); |
| 103 | + GL11.glTexCoord2f(renderSRCX, renderSRCY); |
| 104 | + GL11.glVertex2d((double)x, (double)y); |
| 105 | + GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight); |
| 106 | + GL11.glVertex2d((double)x, (double)(y + height)); |
| 107 | + GL11.glTexCoord2f(renderSRCX, renderSRCY + renderSRCHeight); |
| 108 | + GL11.glVertex2d((double)x, (double)(y + height)); |
| 109 | + GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY + renderSRCHeight); |
| 110 | + GL11.glVertex2d((double)(x + width), (double)(y + height)); |
| 111 | + GL11.glTexCoord2f(renderSRCX + renderSRCWidth, renderSRCY); |
| 112 | + GL11.glVertex2d((double)(x + width), (double)y); |
| 113 | + } |
| 114 | + |
| 115 | + public int getStringHeight(final String text) { |
| 116 | + return this.getHeight(); |
| 117 | + } |
| 118 | + |
| 119 | + public int getHeight() { |
| 120 | + return (this.fontHeight - 8) / 2; |
| 121 | + } |
| 122 | + |
| 123 | + public int getStringWidth(final String text) { |
| 124 | + int width = 0; |
| 125 | + for (final char c : text.toCharArray()) { |
| 126 | + if (c < this.charData.length && c >= '\0') { |
| 127 | + width += this.charData[c].width - 8 + this.charOffset; |
| 128 | + } |
| 129 | + } |
| 130 | + return width / 2; |
| 131 | + } |
| 132 | + |
| 133 | + public boolean isAntiAlias() { |
| 134 | + return this.antiAlias; |
| 135 | + } |
| 136 | + |
| 137 | + public void setAntiAlias(final boolean antiAlias) { |
| 138 | + if (this.antiAlias != antiAlias) { |
| 139 | + this.antiAlias = antiAlias; |
| 140 | + this.tex = this.setupTexture(this.font, antiAlias, this.fractionalMetrics, this.charData); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + public boolean isFractionalMetrics() { |
| 145 | + return this.fractionalMetrics; |
| 146 | + } |
| 147 | + |
| 148 | + public void setFractionalMetrics(final boolean fractionalMetrics) { |
| 149 | + if (this.fractionalMetrics != fractionalMetrics) { |
| 150 | + this.fractionalMetrics = fractionalMetrics; |
| 151 | + this.tex = this.setupTexture(this.font, this.antiAlias, fractionalMetrics, this.charData); |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + public Font getFont() { |
| 156 | + return this.font; |
| 157 | + } |
| 158 | + |
| 159 | + public void setFont(final Font font) { |
| 160 | + this.font = font; |
| 161 | + this.tex = this.setupTexture(font, this.antiAlias, this.fractionalMetrics, this.charData); |
| 162 | + } |
| 163 | + |
| 164 | + protected class CharData |
| 165 | + { |
| 166 | + public int width; |
| 167 | + public int height; |
| 168 | + public int storedX; |
| 169 | + public int storedY; |
| 170 | + } |
| 171 | +} |
0 commit comments