Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. package com.rune.sanity.client;
  2.  
  3. import java.awt.Font;
  4. import java.io.DataInputStream;
  5. import java.io.DataOutputStream;
  6. import java.io.FileInputStream;
  7. import java.io.FileNotFoundException;
  8. import java.io.FileOutputStream;
  9. import java.io.IOException;
  10. import java.util.zip.GZIPInputStream;
  11. import java.util.zip.GZIPOutputStream;
  12.  
  13. import com.rune.sanity.client.sign.Signlink;
  14.  
  15.  
  16. /**
  17.  * @author Sam
  18.  */
  19. public class FontArchiver {
  20.    
  21.     private static CustomFont[] fontArchive;
  22.    
  23.     public static CustomFont getFont(int index) {
  24.         if (fontArchive == null) {
  25.             return null;
  26.         }
  27.         return fontArchive[index];
  28.     }
  29.    
  30.     public static void loadArchive() throws FileNotFoundException, IOException {
  31.         DataInputStream in = new DataInputStream(new GZIPInputStream(new FileInputStream(Signlink.findcachedir() + "main_file_cache.idx6")));
  32.         try {
  33.             byte fontCount = in.readByte();
  34.             fontArchive = new CustomFont[fontCount + 4];
  35.             for (int index = 0; index < fontCount; index++) {
  36.                 long length = in.readLong();
  37.                 byte[] fontData = new byte[(int) length];
  38.                 in.readFully(fontData);
  39.                 fontArchive[index]  = new CustomFont(fontData);
  40.             }
  41.             fontArchive[3] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 15, true);
  42.             fontArchive[4] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 12, true);
  43.             fontArchive[5] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 17, true);
  44.             fontArchive[6] = new CustomFont(Client.instance, "Arial", Font.PLAIN, 10, true);
  45.         } finally {
  46.             in.close();
  47.         }
  48.     }
  49.  
  50.     public static void writeFontArchive(String destination) {
  51.         try {
  52.             final CustomFont[] FONTS = new CustomFont[] {
  53.                 new CustomFont(Client.instance, "trajan pro", Font.BOLD, 20, true),
  54.                 new CustomFont(Client.instance, "trajan pro", Font.PLAIN, 80, true),
  55.             };
  56.             DataOutputStream out = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(destination + "main_file_cache.idx5")));
  57.             try {
  58.                 out.writeByte(FONTS.length);
  59.                 for (int index = 0; index < FONTS.length; index++) {
  60.                     out.writeLong(FONTS[index].toByteArray().length);
  61.                     out.write(FONTS[index].toByteArray());
  62.                 }
  63.             } finally {
  64.                 out.flush();
  65.                 out.close();
  66.             }
  67.         } catch (Exception e) {
  68.             e.printStackTrace();
  69.         }
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement