Browse Source

- FontCreator creates working AngelFonts now

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7127 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
nor..67 14 years ago
parent
commit
7cffe5cafb

+ 1 - 1
jme3-angelfont/nbproject/project.properties

@@ -1,3 +1,3 @@
 javac.source=1.5
 javac.source=1.5
 javac.compilerargs=-Xlint -Xlint:-serial
 javac.compilerargs=-Xlint -Xlint:-serial
-spec.version.base=0.1.0
+spec.version.base=0.6.0

+ 55 - 0
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFont.java

@@ -0,0 +1,55 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.jme3.gde.angelfont;
+
+import java.awt.image.BufferedImage;
+
+/**
+ *
+ * @author normenhansen
+ */
+public class AngelFont {
+    private BufferedImage image;
+    private String description;
+
+    public AngelFont() {
+    }
+
+    public AngelFont(BufferedImage image, String description) {
+        this.image = image;
+        this.description = description;
+    }
+
+    /**
+     * @return the image
+     */
+    public BufferedImage getImage() {
+        return image;
+    }
+
+    /**
+     * @param image the image to set
+     */
+    public void setImage(BufferedImage image) {
+        this.image = image;
+    }
+
+    /**
+     * @return the description
+     */
+    public String getDescription() {
+        return description;
+    }
+
+    /**
+     * @param description the description to set
+     */
+    public void setDescription(String description) {
+        this.description = description;
+    }
+    
+
+}

+ 1 - 1
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontVisualPanel1.java

@@ -88,7 +88,7 @@ public final class AngelFontVisualPanel1 extends JPanel {
     }// </editor-fold>//GEN-END:initComponents
     }// </editor-fold>//GEN-END:initComponents
 
 
     private void updateFont(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_updateFont
     private void updateFont(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_updateFont
-        jLabel1.setIcon(new ImageIcon(FontCreator.buildFont((String) jList1.getSelectedValue(), 256)));
+        jLabel1.setIcon(new ImageIcon(FontCreator.buildFont((String) jList1.getSelectedValue(), 256).getImage()));
         selectedFont = (String) jList1.getSelectedValue();
         selectedFont = (String) jList1.getSelectedValue();
     }//GEN-LAST:event_updateFont
     }//GEN-LAST:event_updateFont
     // Variables declaration - do not modify//GEN-BEGIN:variables
     // Variables declaration - do not modify//GEN-BEGIN:variables

+ 71 - 2
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontVisualPanel2.form

@@ -16,13 +16,82 @@
   <Layout>
   <Layout>
     <DimensionLayout dim="0">
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <EmptySpace min="0" pref="360" max="32767" attributes="0"/>
+          <Component id="jToolBar1" alignment="1" pref="441" max="32767" attributes="0"/>
+          <Component id="jPanel1" alignment="0" pref="441" max="32767" attributes="0"/>
       </Group>
       </Group>
     </DimensionLayout>
     </DimensionLayout>
     <DimensionLayout dim="1">
     <DimensionLayout dim="1">
       <Group type="103" groupAlignment="0" attributes="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <EmptySpace min="0" pref="256" max="32767" attributes="0"/>
+          <Group type="102" alignment="1" attributes="0">
+              <Component id="jPanel1" pref="307" max="32767" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="jToolBar1" min="-2" pref="25" max="-2" attributes="0"/>
+          </Group>
       </Group>
       </Group>
     </DimensionLayout>
     </DimensionLayout>
   </Layout>
   </Layout>
+  <SubComponents>
+    <Container class="javax.swing.JPanel" name="jPanel1">
+      <Properties>
+        <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
+          <Color blue="0" green="0" red="0" type="rgb"/>
+        </Property>
+      </Properties>
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
+      <SubComponents>
+        <Component class="javax.swing.JLabel" name="jLabel3">
+          <Properties>
+            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+              <ResourceString bundle="com/jme3/gde/angelfont/Bundle.properties" key="AngelFontVisualPanel2.jLabel3.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+            </Property>
+          </Properties>
+        </Component>
+      </SubComponents>
+    </Container>
+    <Container class="javax.swing.JToolBar" name="jToolBar1">
+      <Properties>
+        <Property name="floatable" type="boolean" value="false"/>
+        <Property name="rollover" type="boolean" value="true"/>
+      </Properties>
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
+      <SubComponents>
+        <Component class="javax.swing.JLabel" name="jLabel1">
+          <Properties>
+            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+              <ResourceString bundle="com/jme3/gde/angelfont/Bundle.properties" key="AngelFontVisualPanel2.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+            </Property>
+          </Properties>
+        </Component>
+        <Component class="javax.swing.JSpinner" name="jSpinner1">
+          <Properties>
+            <Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
+              <SpinnerModel initial="16" minimum="1" numberType="java.lang.Integer" stepSize="1" type="number"/>
+            </Property>
+          </Properties>
+          <Events>
+            <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="updateFontSize"/>
+          </Events>
+        </Component>
+        <Component class="javax.swing.JLabel" name="jLabel2">
+          <Properties>
+            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+              <ResourceString bundle="com/jme3/gde/angelfont/Bundle.properties" key="AngelFontVisualPanel2.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+            </Property>
+          </Properties>
+        </Component>
+        <Component class="javax.swing.JSpinner" name="jSpinner2">
+          <Properties>
+            <Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
+              <SpinnerModel initial="256" minimum="64" numberType="java.lang.Integer" stepSize="1" type="number"/>
+            </Property>
+          </Properties>
+          <Events>
+            <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="updateImageSize"/>
+          </Events>
+        </Component>
+      </SubComponents>
+    </Container>
+  </SubComponents>
 </Form>
 </Form>

+ 79 - 3
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontVisualPanel2.java

@@ -4,10 +4,15 @@
  */
  */
 package com.jme3.gde.angelfont;
 package com.jme3.gde.angelfont;
 
 
+import javax.swing.ImageIcon;
 import javax.swing.JPanel;
 import javax.swing.JPanel;
 
 
 public final class AngelFontVisualPanel2 extends JPanel {
 public final class AngelFontVisualPanel2 extends JPanel {
 
 
+    String fontName = "";
+    int fontSize = 16;
+    int imageSize = 256;
+
     /** Creates new form AngelFontVisualPanel2 */
     /** Creates new form AngelFontVisualPanel2 */
     public AngelFontVisualPanel2() {
     public AngelFontVisualPanel2() {
         initComponents();
         initComponents();
@@ -15,7 +20,18 @@ public final class AngelFontVisualPanel2 extends JPanel {
 
 
     @Override
     @Override
     public String getName() {
     public String getName() {
-        return "Step #2";
+        return "Configure Font";
+    }
+
+    public void setFont(String name) {
+        this.fontName = name;
+        updateFont();
+    }
+
+    private void updateFont() {
+        jLabel3.setIcon(new ImageIcon(FontCreator.buildFont(fontName, imageSize, fontSize, true).getImage()));
+        jLabel3.repaint();
+        jPanel1.repaint();
     }
     }
 
 
     /** This method is called from within the constructor to
     /** This method is called from within the constructor to
@@ -26,17 +42,77 @@ public final class AngelFontVisualPanel2 extends JPanel {
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private void initComponents() {
     private void initComponents() {
 
 
+        jPanel1 = new javax.swing.JPanel();
+        jLabel3 = new javax.swing.JLabel();
+        jToolBar1 = new javax.swing.JToolBar();
+        jLabel1 = new javax.swing.JLabel();
+        jSpinner1 = new javax.swing.JSpinner();
+        jLabel2 = new javax.swing.JLabel();
+        jSpinner2 = new javax.swing.JSpinner();
+
+        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
+        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));
+
+        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jLabel3.text")); // NOI18N
+        jPanel1.add(jLabel3);
+
+        jToolBar1.setFloatable(false);
+        jToolBar1.setRollover(true);
+
+        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jLabel1.text")); // NOI18N
+        jToolBar1.add(jLabel1);
+
+        jSpinner1.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(16), Integer.valueOf(1), null, Integer.valueOf(1)));
+        jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
+            public void stateChanged(javax.swing.event.ChangeEvent evt) {
+                updateFontSize(evt);
+            }
+        });
+        jToolBar1.add(jSpinner1);
+
+        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jLabel2.text")); // NOI18N
+        jToolBar1.add(jLabel2);
+
+        jSpinner2.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(256), Integer.valueOf(64), null, Integer.valueOf(1)));
+        jSpinner2.addChangeListener(new javax.swing.event.ChangeListener() {
+            public void stateChanged(javax.swing.event.ChangeEvent evt) {
+                updateImageSize(evt);
+            }
+        });
+        jToolBar1.add(jSpinner2);
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         this.setLayout(layout);
         layout.setHorizontalGroup(
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGap(0, 360, Short.MAX_VALUE)
+            .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
+            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
         );
         );
         layout.setVerticalGroup(
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGap(0, 256, Short.MAX_VALUE)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
         );
         );
     }// </editor-fold>//GEN-END:initComponents
     }// </editor-fold>//GEN-END:initComponents
+
+    private void updateFontSize(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_updateFontSize
+        fontSize = (Integer) jSpinner1.getValue();
+        updateFont();
+    }//GEN-LAST:event_updateFontSize
+
+    private void updateImageSize(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_updateImageSize
+        imageSize = (Integer) jSpinner2.getValue();
+        updateFont();
+    }//GEN-LAST:event_updateImageSize
     // Variables declaration - do not modify//GEN-BEGIN:variables
     // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JLabel jLabel1;
+    private javax.swing.JLabel jLabel2;
+    private javax.swing.JLabel jLabel3;
+    private javax.swing.JPanel jPanel1;
+    private javax.swing.JSpinner jSpinner1;
+    private javax.swing.JSpinner jSpinner2;
+    private javax.swing.JToolBar jToolBar1;
     // End of variables declaration//GEN-END:variables
     // End of variables declaration//GEN-END:variables
 }
 }

+ 15 - 7
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontWizardIterator.java

@@ -9,6 +9,7 @@ import java.awt.Component;
 import java.awt.image.BufferedImage;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.nio.ByteBuffer;
 import java.nio.ByteBuffer;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Iterator;
@@ -72,19 +73,23 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
 
 
     public Set<FileObject> instantiate() throws IOException {
     public Set<FileObject> instantiate() throws IOException {
         String name = (String) wizard.getProperty("font_name");
         String name = (String) wizard.getProperty("font_name");
+        int fontSize = (Integer) wizard.getProperty("font_size");
+        int imageSize = (Integer) wizard.getProperty("image_size");
         Project project = (Project) wizard.getProperty("project");
         Project project = (Project) wizard.getProperty("project");
         ProjectAssetManager pm = project.getLookup().lookup(ProjectAssetManager.class);
         ProjectAssetManager pm = project.getLookup().lookup(ProjectAssetManager.class);
         if (pm == null) {
         if (pm == null) {
             Logger.getLogger(AngelFontWizardIterator.class.getName()).log(Level.WARNING, "No ProjectAssetManager found!");
             Logger.getLogger(AngelFontWizardIterator.class.getName()).log(Level.WARNING, "No ProjectAssetManager found!");
             return Collections.EMPTY_SET;
             return Collections.EMPTY_SET;
         }
         }
-        BufferedImage fontImage = FontCreator.buildFont(name);
+        AngelFont font = FontCreator.buildFont(name, imageSize, fontSize);
+        BufferedImage fontImage = font.getImage();
         ByteBuffer scratch = ByteBuffer.allocateDirect(4 * fontImage.getWidth() * fontImage.getHeight());
         ByteBuffer scratch = ByteBuffer.allocateDirect(4 * fontImage.getWidth() * fontImage.getHeight());
         byte[] data = (byte[]) fontImage.getRaster().getDataElements(0, 0,
         byte[] data = (byte[]) fontImage.getRaster().getDataElements(0, 0,
                 fontImage.getWidth(), fontImage.getHeight(), null);
                 fontImage.getWidth(), fontImage.getHeight(), null);
         scratch.clear();
         scratch.clear();
         scratch.put(data);
         scratch.put(data);
         scratch.rewind();
         scratch.rewind();
+        name = name.replaceAll(" ", "");
         File outputFile;
         File outputFile;
         try {
         try {
             if (pm.getAssetFolder().getFileObject("Interface") == null) {
             if (pm.getAssetFolder().getFileObject("Interface") == null) {
@@ -95,10 +100,18 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
             }
             }
             outputFile = FileUtil.toFile(pm.getAssetFolder().getFileObject("Interface/Fonts"));
             outputFile = FileUtil.toFile(pm.getAssetFolder().getFileObject("Interface/Fonts"));
             if (!outputFile.getName().endsWith(".png")) {
             if (!outputFile.getName().endsWith(".png")) {
-                outputFile = new File(outputFile.getAbsoluteFile() + File.separator + name.replaceAll(" ", "") + ".png");
+                outputFile = new File(outputFile.getAbsoluteFile() + File.separator + name + ".png");
             }
             }
             // write png file
             // write png file
             ImageIO.write(fontImage, "PNG", outputFile);
             ImageIO.write(fontImage, "PNG", outputFile);
+
+            FileObject object = pm.getAssetFolder().getFileObject("Interface/Fonts/" + name, "fnt");
+            if (object == null) {
+                object = pm.getAssetFolder().getFileObject("Interface/Fonts").createData(name, "fnt");
+            }
+            OutputStreamWriter out = new OutputStreamWriter(object.getOutputStream());
+            out.write(font.getDescription());
+            out.close();
         } catch (Exception e) {
         } catch (Exception e) {
             Exceptions.printStackTrace(e);
             Exceptions.printStackTrace(e);
             return Collections.EMPTY_SET;
             return Collections.EMPTY_SET;
@@ -108,11 +121,6 @@ public final class AngelFontWizardIterator implements WizardDescriptor.Instantia
 
 
     public void initialize(WizardDescriptor wizard) {
     public void initialize(WizardDescriptor wizard) {
         this.wizard = wizard;
         this.wizard = wizard;
-        System.out.println("FOLDERRRR:" + wizard.getProperty("folder"));
-        for (Iterator<Entry<String, Object>> it = wizard.getProperties().entrySet().iterator(); it.hasNext();) {
-            Entry<String, Object> entry = it.next();
-            System.out.println(entry.getKey() + ": " + wizard.getProperty(entry.getKey()));
-        }
     }
     }
 
 
     public void uninitialize(WizardDescriptor wizard) {
     public void uninitialize(WizardDescriptor wizard) {

+ 4 - 1
jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontWizardPanel2.java

@@ -15,7 +15,7 @@ public class AngelFontWizardPanel2 implements WizardDescriptor.Panel {
      * The visual component that displays this panel. If you need to access the
      * The visual component that displays this panel. If you need to access the
      * component from this class, just use getComponent().
      * component from this class, just use getComponent().
      */
      */
-    private Component component;
+    private AngelFontVisualPanel2 component;
 
 
     // Get the visual component for the panel. In this template, the component
     // Get the visual component for the panel. In this template, the component
     // is kept separate. This can be more efficient: if the wizard is created
     // is kept separate. This can be more efficient: if the wizard is created
@@ -79,8 +79,11 @@ public class AngelFontWizardPanel2 implements WizardDescriptor.Panel {
     // WizardDescriptor.getProperty & putProperty to store information entered
     // WizardDescriptor.getProperty & putProperty to store information entered
     // by the user.
     // by the user.
     public void readSettings(Object settings) {
     public void readSettings(Object settings) {
+        component.setFont((String)((WizardDescriptor)settings).getProperty("font_name"));
     }
     }
 
 
     public void storeSettings(Object settings) {
     public void storeSettings(Object settings) {
+        ((WizardDescriptor)settings).putProperty("font_size", component.fontSize);
+        ((WizardDescriptor)settings).putProperty("image_size", component.imageSize);
     }
     }
 }
 }

+ 4 - 1
jme3-angelfont/src/com/jme3/gde/angelfont/Bundle.properties

@@ -1,7 +1,10 @@
 OpenIDE-Module-Display-Category=jMonkeyPlatform
 OpenIDE-Module-Display-Category=jMonkeyPlatform
 OpenIDE-Module-Long-Description=\
 OpenIDE-Module-Long-Description=\
     Font Support for jMonkeyPlatform, create AngelFont files from system fonts
     Font Support for jMonkeyPlatform, create AngelFont files from system fonts
-OpenIDE-Module-Name=jME3 Font Creator
+OpenIDE-Module-Name=Font Creator
 OpenIDE-Module-Short-Description=Create AngelFont files from system fonts
 OpenIDE-Module-Short-Description=Create AngelFont files from system fonts
 Templates/GUI/angelFont=Font
 Templates/GUI/angelFont=Font
 AngelFontVisualPanel1.jLabel1.text=
 AngelFontVisualPanel1.jLabel1.text=
+AngelFontVisualPanel2.jLabel1.text=Font Size:
+AngelFontVisualPanel2.jLabel2.text=Image Size:
+AngelFontVisualPanel2.jLabel3.text=jLabel3

+ 67 - 85
jme3-angelfont/src/com/jme3/gde/angelfont/FontCreator.java

@@ -24,117 +24,99 @@ public abstract class FontCreator {
     public FontCreator() {
     public FontCreator() {
     }
     }
 
 
-    public static BufferedImage buildFont(String fontName) {
+    public static AngelFont buildFont(String fontName) {
         return buildFont(fontName, 512);
         return buildFont(fontName, 512);
     }
     }
 
 
-    public static BufferedImage buildFont(String fontName, int bitmapSize) {
-        return buildFont(fontName, bitmapSize, 63);
+    public static AngelFont buildFont(String fontName, int bitmapSize) {
+        return buildFont(fontName, bitmapSize, 16, false);
     }
     }
 
 
-    public static BufferedImage buildFont(String fontName, int bitmapSize, int offset) {
+    public static AngelFont buildFont(String fontName, int bitmapSize, int fontSize) {
+        return buildFont(fontName, bitmapSize, fontSize, false);
+    }
+
+    public static AngelFont buildFont(String fontName, int bitmapSize, int fontSize, boolean debug) {
         BufferedImage fontImage;
         BufferedImage fontImage;
         Font font;
         Font font;
 
 
-        boolean sizeFound = false;
-        boolean directionSet = false;
-        int delta = 0;
-        int fontSize = 24;
-
         String charLocs = "";
         String charLocs = "";
 
 
-        /*
-         * To find out how much space a Font takes, you need to use a the
-         * FontMetrics class. To get the FontMetrics, you need to get it from a
-         * Graphics context. A Graphics context is only available from a
-         * displayable surface, ie any class that subclasses Component or any
-         * Image. First the font is set on a Graphics object. Then get the
-         * FontMetrics and find out the width and height of the widest character
-         * (W). Then take the largest of the 2 values and find the maximum size
-         * font that will fit in the size allocated.
-         */
-        while (!sizeFound) {
-            font = new Font(fontName, Font.PLAIN, fontSize); // Font Name
-            // use BufferedImage.TYPE_4BYTE_ABGR to allow alpha blending
-            fontImage = new BufferedImage(bitmapSize, bitmapSize,
-                    BufferedImage.TYPE_4BYTE_ABGR);
-            Graphics2D g = (Graphics2D) fontImage.getGraphics();
-            g.setFont(font);
-            FontMetrics fm = g.getFontMetrics();
-            int width = fm.stringWidth("W");
-            int height = fm.getHeight();
-            int lineWidth = (width > height) ? width * 16 : height * 16;
-            if (!directionSet) {
-                if (lineWidth > bitmapSize) {
-                    delta = -2;
-                } else {
-                    delta = 2;
-                }
-                directionSet = true;
-            }
-            if (delta > 0) {
-                if (lineWidth < bitmapSize) {
-                    fontSize += delta;
-                } else {
-                    sizeFound = true;
-                    fontSize -= delta;
-                }
-            } else if (delta < 0) {
-                if (lineWidth > bitmapSize) {
-                    fontSize += delta;
-                } else {
-                    sizeFound = true;
-                    fontSize -= delta;
-                }
-            }
-        }
-
-        /*
-         * Now that a font size has been determined, create the final image, set
-         * the font and draw the standard/extended ASCII character set for that
-         * font.
-         */
         font = new Font(fontName, Font.BOLD, fontSize); // Font Name
         font = new Font(fontName, Font.BOLD, fontSize); // Font Name
         // use BufferedImage.TYPE_4BYTE_ABGR to allow alpha blending
         // use BufferedImage.TYPE_4BYTE_ABGR to allow alpha blending
         fontImage = new BufferedImage(bitmapSize, bitmapSize,
         fontImage = new BufferedImage(bitmapSize, bitmapSize,
                 BufferedImage.TYPE_4BYTE_ABGR);
                 BufferedImage.TYPE_4BYTE_ABGR);
         Graphics2D g = (Graphics2D) fontImage.getGraphics();
         Graphics2D g = (Graphics2D) fontImage.getGraphics();
         g.setFont(font);
         g.setFont(font);
-        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-                RenderingHints.VALUE_ANTIALIAS_ON);
+        if (!debug) {
+            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                    RenderingHints.VALUE_ANTIALIAS_ON);
+        }
         g.setColor(OPAQUE_WHITE);
         g.setColor(OPAQUE_WHITE);
         g.setBackground(TRANSPARENT_BLACK);
         g.setBackground(TRANSPARENT_BLACK);
 
 
         FontMetrics fm = g.getFontMetrics();
         FontMetrics fm = g.getFontMetrics();
 
 
+        if (debug) {
+            g.setColor(Color.WHITE);
+            g.drawRect(0, 0, bitmapSize - 1, bitmapSize - 1);
+        }
+        int xPos = 0;
+        int yPos = 0;
+        int height = 0;
         for (int i = 0; i < 256; i++) {
         for (int i = 0; i < 256; i++) {
-            int x = i % 16;
-            int y = i / 16;
             char ch[] = {(char) i};
             char ch[] = {(char) i};
             String temp = new String(ch);
             String temp = new String(ch);
             Rectangle2D bounds = fm.getStringBounds(temp, g);
             Rectangle2D bounds = fm.getStringBounds(temp, g);
-
-            int xPos = (int) ((x * 32) + (16 - (bounds.getWidth() / 2)));
-            int yPos = (y * 32) + fm.getAscent() - offset;
+            height = fm.getDescent() + fm.getAscent();
+            if (yPos == 0) {
+                yPos = height;
+            }
+            if (xPos + bounds.getWidth() > bitmapSize) {
+                xPos = 0;
+                yPos += height;
+            }
             g.drawString(temp, xPos, yPos);
             g.drawString(temp, xPos, yPos);
-            //TODO: AngelFont support!
-//            g.setColor(Color.BLUE);
-//            g.drawRect(xPos, yPos-(int)bounds.getHeight(), (int)bounds.getWidth(), (int)bounds.getHeight()+fm.getDescent());
-//            g.setColor(Color.WHITE);
-//
-//            charLocs=charLocs+
-//                    "char id="+i+
-//                    "    x="+xPos +
-//                    "    y="+(yPos-(int)bounds.getHeight()-fm.getAscent())+
-//                    "    width="+(int)bounds.getWidth()+
-//                    "    height="+(int)bounds.getHeight()+
-//                    "    xoffset=0" +
-//                    "    yoffset=0" +
-//                    "    xadvance=0" +
-//                    "    page=0" +
-//                    "    chnl=15\n";
+            if (debug) {
+                g.setColor(Color.BLUE);
+                g.drawRect(xPos, yPos - fm.getAscent(), (int) bounds.getWidth(), height);
+                g.setColor(Color.WHITE);
+            }
+            charLocs = charLocs
+                    + "char id=" + i
+                    + "    x=" + xPos
+                    + "    y=" + (yPos - fm.getAscent())
+                    + "    width=" + (int) bounds.getWidth()
+                    + "    height=" + (int) bounds.getHeight()
+                    + "    xoffset=0"
+                    + "    yoffset=0"
+                    + "    xadvance=" + ((int) bounds.getWidth() - 1) + " "
+                    + "    page=0"
+                    + "    chnl=0\n";
+            xPos += bounds.getWidth();
         }
         }
-//        System.out.println(charLocs);
-        return fontImage;
+        charLocs = "info face=null "
+                + "size=" + fontSize + " "
+                + "bold=0 "
+                + "italic=0 "
+                + "charset=ASCII "
+                + "unicode=0 "
+                + "stretchH=100 "
+                + "smooth=1 "
+                + "aa=1 "
+                + "paiing=0,0,0,0 "
+                + "spacing=1,1 "
+                + "\n"
+                + "common lineHeight=" + height + " "
+                + "base=26 "
+                + "scaleW=" + bitmapSize + " "
+                + "scaleH=" + bitmapSize + " "
+                + "pages=1 "
+                + "packed=0 "
+                + "\n"
+                + "page id=0 file=\"" + fontName.replaceAll(" ", "") + ".png\"\n"
+                + "chars count=255\n"
+                + charLocs;
+        return new AngelFont(fontImage, charLocs);
     }
     }
 }
 }