Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rune.sanity.client;
- import java.awt.Font;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.zip.GZIPInputStream;
- import java.util.zip.GZIPOutputStream;
- import com.rune.sanity.client.sign.Signlink;
- /**
- * @author Sam
- */
- public class FontArchiver {
- private static CustomFont[] fontArchive;
- public static CustomFont getFont(int index) {
- if (fontArchive == null) {
- return null;
- }
- return fontArchive[index];
- }
- public static void loadArchive() throws FileNotFoundException, IOException {
- DataInputStream in = new DataInputStream(new GZIPInputStream(new FileInputStream(Signlink.findcachedir() + "main_file_cache.idx6")));
- try {
- byte fontCount = in.readByte();
- fontArchive = new CustomFont[fontCount + 4];
- for (int index = 0; index < fontCount; index++) {
- long length = in.readLong();
- byte[] fontData = new byte[(int) length];
- in.readFully(fontData);
- fontArchive[index] = new CustomFont(fontData);
- }
- fontArchive[3] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 15, true);
- fontArchive[4] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 12, true);
- fontArchive[5] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 17, true);
- fontArchive[6] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 10, true);
- } finally {
- in.close();
- }
- }
- public static void writeFontArchive(String destination) {
- try {
- final CustomFont[] FONTS = new CustomFont[] {
- new CustomFont(Client.instance, "trajan pro", Font.BOLD, 20, true),
- new CustomFont(Client.instance, "trajan pro", Font.PLAIN, 80, true),
- };
- DataOutputStream out = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(destination + "main_file_cache.idx5")));
- try {
- out.writeByte(FONTS.length);
- for (int index = 0; index < FONTS.length; index++) {
- out.writeLong(FONTS[index].toByteArray().length);
- out.write(FONTS[index].toByteArray());
- }
- } finally {
- out.flush();
- out.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement