Updated font creator too:

1. Not create an entry for glyphs that cannot be rendered
2. Look at the pixel bounds of an image when allocating space for it to prevent overlaps and prevent wasted space
3. Allow a character range to be selected (0->256 is default) when creating the font

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10245 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Zer..om 12 years ago
parent 8fa2ac69dd
commit cf66bd4d45
  1. 131
      sdk/jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontVisualPanel2.form
  2. 119
      sdk/jme3-angelfont/src/com/jme3/gde/angelfont/AngelFontVisualPanel2.java
  3. 4
      sdk/jme3-angelfont/src/com/jme3/gde/angelfont/Bundle.properties
  4. 48
      sdk/jme3-angelfont/src/com/jme3/gde/angelfont/FontCreator.java

@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents> <NonVisualComponents>
@ -25,22 +25,23 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" attributes="0">
<Component id="jPanel3" max="32767" attributes="0"/> <Component id="jPanel3" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jPanel2" min="-2" max="-2" attributes="0"/> <Component id="jPanel2" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Component id="jPanel1" alignment="0" pref="531" max="32767" attributes="0"/> <Component id="jPanel1" 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">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Component id="jPanel1" pref="404" max="32767" attributes="0"/> <Component id="jPanel1" pref="432" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel2" max="32767" attributes="1"/> <Component id="jPanel2" min="-2" max="-2" attributes="1"/>
<Component id="jPanel3" alignment="0" max="32767" attributes="1"/> <Component id="jPanel3" min="-2" max="-2" attributes="1"/>
</Group> </Group>
</Group> </Group>
</Group> </Group>
@ -80,7 +81,7 @@
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0"> <Group type="103" groupAlignment="1" attributes="0">
@ -93,16 +94,13 @@
<Component id="jLabel4" alignment="0" min="-2" pref="52" max="-2" attributes="0"/> <Component id="jLabel4" alignment="0" min="-2" pref="52" max="-2" attributes="0"/>
</Group> </Group>
<Group type="103" groupAlignment="1" attributes="0"> <Group type="103" groupAlignment="1" attributes="0">
<Component id="jSpinner3" pref="156" max="32767" attributes="1"/> <Component id="jSpinner3" max="32767" attributes="1"/>
<Group type="103" alignment="1" groupAlignment="0" max="-2" attributes="0"> <Component id="jSpinner4" alignment="1" max="32767" attributes="1"/>
<Component id="jSpinner2" alignment="0" max="32767" attributes="1"/> <Component id="jSpinner2" alignment="1" max="32767" attributes="1"/>
<Component id="jTextField1" alignment="1" pref="156" max="32767" attributes="1"/> <Component id="jTextField1" alignment="1" pref="188" max="32767" attributes="1"/>
</Group>
<Component id="jSpinner4" alignment="1" pref="156" max="32767" attributes="1"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jLabel8" min="-2" max="-2" attributes="0"/> <Component id="jLabel8" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -233,21 +231,41 @@
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="1" max="-2" attributes="0">
<Group type="103" groupAlignment="1" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="jLabel11" alignment="1" min="-2" max="-2" attributes="0"/> <EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
<Component id="jLabel9" alignment="1" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="1" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="jLabel9" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="jLabel6" alignment="1" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jLabel6" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="10" pref="10" max="-2" attributes="0"/>
<Component id="jLabel12" max="32767" attributes="0"/>
</Group>
<Component id="jLabel11" max="32767" attributes="0"/>
</Group>
</Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jSpinner1" alignment="1" pref="78" max="32767" attributes="1"/> <Component id="jSpinner1" alignment="1" max="32767" attributes="1"/>
<Component id="jLabel10" alignment="0" pref="78" max="32767" attributes="0"/> <Component id="jLabel10" alignment="0" max="32767" attributes="0"/>
<Component id="jComboBox1" alignment="1" pref="78" max="32767" attributes="0"/> <Component id="jComboBox1" alignment="1" max="32767" attributes="0"/>
<Component id="jSpinner5" alignment="0" pref="78" max="32767" attributes="1"/> <Component id="jSpinner5" alignment="0" max="32767" attributes="1"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jSpinner6" pref="60" max="32767" attributes="1"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jLabel13" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jSpinner7" pref="58" max="32767" attributes="1"/>
</Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -268,10 +286,17 @@
<Component id="jSpinner1" alignment="3" min="-2" pref="23" max="-2" attributes="0"/> <Component id="jSpinner1" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace pref="7" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jSpinner5" alignment="3" min="-2" pref="23" max="-2" attributes="0"/> <Component id="jSpinner5" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
<Component id="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="8" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel12" alignment="3" min="-2" pref="29" max="-2" attributes="0"/>
<Component id="jSpinner6" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
<Component id="jLabel13" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jSpinner7" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -355,6 +380,46 @@
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="letterSpacingUpdate"/> <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="letterSpacingUpdate"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="jLabel12">
<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.jLabel12.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="jSpinner6">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" maximum="65535" minimum="0" numberType="java.lang.Integer" stepSize="32" type="number"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/angelfont/Bundle.properties" key="AngelFontVisualPanel2.jSpinner6.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="jSpinner6letterSpacingUpdate"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel13">
<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.jLabel13.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="jSpinner7">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="256" maximum="65535" minimum="0" numberType="java.lang.Integer" stepSize="32" type="number"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/angelfont/Bundle.properties" key="AngelFontVisualPanel2.jSpinner7.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="jSpinner7letterSpacingUpdate"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
</SubComponents> </SubComponents>

@ -18,6 +18,8 @@ public final class AngelFontVisualPanel2 extends JPanel {
int letterSpacing = 0; int letterSpacing = 0;
String fileName = ""; String fileName = "";
int style = Font.PLAIN; int style = Font.PLAIN;
int charRangeStart = 0;
int charRangeEnd = 256;
/** Creates new form AngelFontVisualPanel2 */ /** Creates new form AngelFontVisualPanel2 */
public AngelFontVisualPanel2() { public AngelFontVisualPanel2() {
@ -26,7 +28,6 @@ public final class AngelFontVisualPanel2 extends JPanel {
jComboBox1.addItem("PLAIN"); jComboBox1.addItem("PLAIN");
jComboBox1.addItem("ITALIC"); jComboBox1.addItem("ITALIC");
jComboBox1.addItem("BOLD"); jComboBox1.addItem("BOLD");
} }
@Override @Override
@ -46,7 +47,7 @@ public final class AngelFontVisualPanel2 extends JPanel {
} }
private void updateFont() { private void updateFont() {
jLabel3.setIcon(new ImageIcon(FontCreator.buildFont(fontName, getFileName(), imageSize, fontSize, style, paddingX, paddingY, letterSpacing, true).getImage())); jLabel3.setIcon(new ImageIcon(FontCreator.buildFont(fontName, getFileName(), imageSize, fontSize, style, paddingX, paddingY, letterSpacing, charRangeStart, charRangeEnd, true).getImage()));
jLabel3.repaint(); jLabel3.repaint();
jPanel1.repaint(); jPanel1.repaint();
} }
@ -81,6 +82,10 @@ public final class AngelFontVisualPanel2 extends JPanel {
jLabel10 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel();
jSpinner5 = new javax.swing.JSpinner(); jSpinner5 = new javax.swing.JSpinner();
jLabel12 = new javax.swing.JLabel();
jSpinner6 = new javax.swing.JSpinner();
jLabel13 = new javax.swing.JLabel();
jSpinner7 = new javax.swing.JSpinner();
org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jButton1.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jButton1.text")); // NOI18N
@ -147,14 +152,12 @@ public final class AngelFontVisualPanel2 extends JPanel {
.addComponent(jLabel5) .addComponent(jLabel5)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSpinner3, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE) .addComponent(jSpinner3)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jSpinner4)
.addComponent(jSpinner2) .addComponent(jSpinner2)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))
.addComponent(jSpinner4, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel8) .addComponent(jLabel8))
.addGap(45, 45, 45))
); );
jPanel2Layout.setVerticalGroup( jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -213,23 +216,57 @@ public final class AngelFontVisualPanel2 extends JPanel {
} }
}); });
org.openide.awt.Mnemonics.setLocalizedText(jLabel12, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jLabel12.text")); // NOI18N
jSpinner6.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 32));
jSpinner6.setToolTipText(org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jSpinner6.toolTipText")); // NOI18N
jSpinner6.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
jSpinner6letterSpacingUpdate(evt);
}
});
org.openide.awt.Mnemonics.setLocalizedText(jLabel13, org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jLabel13.text")); // NOI18N
jSpinner7.setModel(new javax.swing.SpinnerNumberModel(256, 0, 65535, 32));
jSpinner7.setToolTipText(org.openide.util.NbBundle.getMessage(AngelFontVisualPanel2.class, "AngelFontVisualPanel2.jSpinner7.toolTipText")); // NOI18N
jSpinner7.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
jSpinner7letterSpacingUpdate(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout); jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup( jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
.addComponent(jLabel11) .addGap(27, 27, 27)
.addComponent(jLabel9) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1) .addComponent(jLabel9)
.addComponent(jLabel6)) .addComponent(jLabel1)
.addComponent(jLabel6)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSpinner1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE) .addComponent(jSpinner1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE) .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 78, Short.MAX_VALUE) .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSpinner5, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)) .addComponent(jSpinner5)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jSpinner6, javax.swing.GroupLayout.PREFERRED_SIZE, 60, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSpinner7, javax.swing.GroupLayout.PREFERRED_SIZE, 58, Short.MAX_VALUE)))
.addContainerGap()) .addContainerGap())
); );
jPanel3Layout.setVerticalGroup( jPanel3Layout.setVerticalGroup(
@ -246,10 +283,16 @@ public final class AngelFontVisualPanel2 extends JPanel {
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)) .addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jSpinner5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11) .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinner5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jSpinner6, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel13)
.addComponent(jSpinner7, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap()) .addContainerGap())
); );
@ -257,20 +300,21 @@ public final class AngelFontVisualPanel2 extends JPanel {
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE) .addContainerGap())
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
); );
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
@ -312,12 +356,25 @@ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
private void letterSpacingUpdate(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_letterSpacingUpdate private void letterSpacingUpdate(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_letterSpacingUpdate
letterSpacing = (Integer) jSpinner5.getValue(); letterSpacing = (Integer) jSpinner5.getValue();
}//GEN-LAST:event_letterSpacingUpdate }//GEN-LAST:event_letterSpacingUpdate
private void jSpinner6letterSpacingUpdate(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner6letterSpacingUpdate
charRangeStart = (Integer)jSpinner6.getValue();
updateFont();
}//GEN-LAST:event_jSpinner6letterSpacingUpdate
private void jSpinner7letterSpacingUpdate(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner7letterSpacingUpdate
charRangeEnd = (Integer)jSpinner7.getValue();
updateFont();
}//GEN-LAST:event_jSpinner7letterSpacingUpdate
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1; private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel4;
@ -334,6 +391,8 @@ private void letterSpacingUpdate(javax.swing.event.ChangeEvent evt) {//GEN-FIRST
private javax.swing.JSpinner jSpinner3; private javax.swing.JSpinner jSpinner3;
private javax.swing.JSpinner jSpinner4; private javax.swing.JSpinner jSpinner4;
private javax.swing.JSpinner jSpinner5; private javax.swing.JSpinner jSpinner5;
private javax.swing.JSpinner jSpinner6;
private javax.swing.JSpinner jSpinner7;
private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

@ -28,3 +28,7 @@ AngelFontVisualPanel2.jComboBox1.toolTipText=The style of the font
AngelFontVisualPanel2.jTextField1.toolTipText=The name of the generated files AngelFontVisualPanel2.jTextField1.toolTipText=The name of the generated files
AngelFontVisualPanel2.jSpinner2.toolTipText=The resulting png image size will be Image Size x Image Size AngelFontVisualPanel2.jSpinner2.toolTipText=The resulting png image size will be Image Size x Image Size
AngelFontVisualPanel2.jSpinner5.toolTipText=Defines the vertical padding used for each letter cell AngelFontVisualPanel2.jSpinner5.toolTipText=Defines the vertical padding used for each letter cell
AngelFontVisualPanel2.jLabel12.text=Char Range:
AngelFontVisualPanel2.jSpinner6.toolTipText=Defines the vertical padding used for each letter cell
AngelFontVisualPanel2.jLabel13.text=to
AngelFontVisualPanel2.jSpinner7.toolTipText=Defines the vertical padding used for each letter cell

@ -9,6 +9,8 @@ import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -45,6 +47,10 @@ public abstract class FontCreator {
} }
public static AngelFont buildFont(String fontName, String fileName, int bitmapSize, int fontSize, int style, int paddingX, int paddingY, int letterSpacing, boolean debug) { public static AngelFont buildFont(String fontName, String fileName, int bitmapSize, int fontSize, int style, int paddingX, int paddingY, int letterSpacing, boolean debug) {
return buildFont(fontName, fileName, bitmapSize, fontSize, style, paddingX, paddingY, letterSpacing, 0, 256, debug);
}
public static AngelFont buildFont(String fontName, String fileName, int bitmapSize, int fontSize, int style, int paddingX, int paddingY, int letterSpacing, int firstChar, int lastChar, boolean debug) {
BufferedImage fontImage; BufferedImage fontImage;
Font font; Font font;
@ -62,6 +68,7 @@ public abstract class FontCreator {
} }
g.setColor(OPAQUE_WHITE); g.setColor(OPAQUE_WHITE);
g.setBackground(TRANSPARENT_BLACK); g.setBackground(TRANSPARENT_BLACK);
FontRenderContext frc = g.getFontRenderContext();
FontMetrics fm = g.getFontMetrics(); FontMetrics fm = g.getFontMetrics();
@ -70,38 +77,49 @@ public abstract class FontCreator {
g.drawRect(0, 0, bitmapSize - 1, bitmapSize - 1); g.drawRect(0, 0, bitmapSize - 1, bitmapSize - 1);
} }
int xPos = 0; int xPos = 0;
int yPos = 0; int height = fm.getDescent() + fm.getAscent();
int height = 0; int yPos = height + (paddingY * 2);
for (int i = 0; i < 256; i++) {
for (int i = firstChar; i <= lastChar; i++) {
char ch[] = {(char) i}; char ch[] = {(char) i};
String temp = new String(ch); String temp = new String(ch);
Rectangle2D bounds = fm.getStringBounds(temp, g);
height = fm.getDescent() + fm.getAscent(); if (!font.canDisplay((char)i)) {
if (yPos == 0) { continue;
yPos = height + (paddingY * 2);
} }
if (xPos + bounds.getWidth() + (paddingX * 2) > bitmapSize) {
TextLayout tl = new TextLayout(temp, font, frc);
Rectangle2D pixelBounds = tl.getPixelBounds(frc, xPos, yPos);
int width = (int)Math.ceil(pixelBounds.getWidth());
int advance = (int)Math.ceil(tl.getAdvance());
int xOffset = (int)Math.round(pixelBounds.getX()) - xPos;
if (xPos + width + (paddingX * 2) > bitmapSize) {
xPos = 0; xPos = 0;
yPos += height + (paddingY * 2); yPos += height + (paddingY * 2);
} }
g.drawString(temp, xPos + paddingX, yPos + paddingY);
g.drawString(temp, xPos + paddingX - xOffset, yPos + paddingY);
if (debug) { if (debug) {
g.setColor(Color.BLUE); g.setColor(Color.BLUE);
g.drawRect(xPos, yPos - fm.getAscent(), (int) bounds.getWidth() + (paddingX * 2), height + (paddingY * 2)); g.drawRect(xPos, yPos - fm.getAscent(), width + (paddingX * 2), height + (paddingY * 2));
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
} }
charLocs = charLocs charLocs = charLocs
+ "char id=" + i + "char id=" + i
+ " x=" + xPos + " x=" + xPos
+ " y=" + (yPos - fm.getAscent()) + " y=" + (yPos - fm.getAscent())
+ " width=" + ((int) bounds.getWidth() + (paddingX * 2)) + " width=" + (width + (paddingX * 2))
+ " height=" + ((int) bounds.getHeight() + (paddingY * 2)) + " height=" + (fm.getHeight() + (paddingY * 2))
+ " xoffset=0" + " xoffset=" + (xOffset)
+ " yoffset=0" + " yoffset=0"
+ " xadvance=" + (((int) bounds.getWidth() + letterSpacing) - 1) + " " + " xadvance=" + ((advance + letterSpacing) - 1) + " "
+ " page=0" + " page=0"
+ " chnl=0\n"; + " chnl=0\n";
xPos += bounds.getWidth() + (paddingX * 2); xPos += width + (paddingX * 2);
} }
charLocs = "info face=null " charLocs = "info face=null "
+ "size=" + fontSize + " " + "size=" + fontSize + " "

Loading…
Cancel
Save