JSpinner padAdvanceYSpinner;\r
JCheckBox italicCheckBox;\r
JCheckBox boldCheckBox;\r
+ JRadioButton javaRadio;\r
+ JRadioButton nativeRadio;\r
JLabel glyphsTotalLabel;\r
JLabel glyphPagesTotalLabel;\r
JComboBox glyphPageHeightCombo;\r
File saveBmFontFile;\r
\r
public Hiero () {\r
- super("Hiero v2.0 - Bitmap Font Tool");\r
+ super("Hiero v3.0 - Bitmap Font Tool");\r
Splash splash = new Splash(this, "/splash.jpg", 2000);\r
initialize();\r
splash.close();\r
unicodeFont.setPaddingAdvanceY(((Integer)padAdvanceYSpinner.getValue()).intValue());\r
unicodeFont.setGlyphPageWidth(((Integer)glyphPageWidthCombo.getSelectedItem()).intValue());\r
unicodeFont.setGlyphPageHeight(((Integer)glyphPageHeightCombo.getSelectedItem()).intValue());\r
+ unicodeFont.setNativeRendering(nativeRadio.isSelected());\r
\r
for (Iterator iter = effectPanels.iterator(); iter.hasNext();) {\r
EffectPanel panel = (EffectPanel)iter.next();\r
boldCheckBox.addActionListener(listener);\r
italicCheckBox.addActionListener(listener);\r
resetCacheButton.addActionListener(listener);\r
+ javaRadio.addActionListener(listener);\r
+ nativeRadio.addActionListener(listener);\r
\r
sampleTextRadio.addActionListener(new ActionListener() {\r
public void actionPerformed (ActionEvent evt) {\r
GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));\r
browseButton.setMargin(new Insets(0, 0, 0, 0));\r
}\r
+ {\r
+ fontPanel.add(new JLabel("Rendering:"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,\r
+ GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));\r
+ }\r
+ {\r
+ javaRadio = new JRadioButton("Java");\r
+ fontPanel.add(javaRadio, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,\r
+ GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));\r
+ javaRadio.setSelected(true);\r
+ }\r
+ {\r
+ nativeRadio = new JRadioButton("Native");\r
+ fontPanel.add(nativeRadio, new GridBagConstraints(2, 4, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,\r
+ GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));\r
+ }\r
ButtonGroup buttonGroup = new ButtonGroup();\r
buttonGroup.add(systemFontRadio);\r
buttonGroup.add(fontFileRadio);\r
+ buttonGroup = new ButtonGroup();\r
+ buttonGroup.add(javaRadio);\r
+ buttonGroup.add(nativeRadio);\r
}\r
{\r
JPanel samplePanel = new JPanel();\r
GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));\r
}\r
{\r
- glyphPageWidthCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] {new Integer(256), new Integer(512),\r
- new Integer(1024), new Integer(2048)}));\r
+ glyphPageWidthCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] {new Integer(32), new Integer(64),\r
+ new Integer(128), new Integer(256), new Integer(512), new Integer(1024), new Integer(2048)}));\r
glyphCachePanel.add(glyphPageWidthCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,\r
GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));\r
- glyphPageWidthCombo.setSelectedIndex(1);\r
+ glyphPageWidthCombo.setSelectedIndex(4);\r
}\r
{\r
- glyphPageHeightCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] {new Integer(256), new Integer(512),\r
- new Integer(1024), new Integer(2048)}));\r
+ glyphPageHeightCombo = new JComboBox(new DefaultComboBoxModel(new Integer[] {new Integer(32), new Integer(64),\r
+ new Integer(128), new Integer(256), new Integer(512), new Integer(1024), new Integer(2048)}));\r
glyphCachePanel.add(glyphPageHeightCombo, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,\r
GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));\r
- glyphPageHeightCombo.setSelectedIndex(1);\r
+ glyphPageHeightCombo.setSelectedIndex(4);\r
}\r
{\r
resetCacheButton = new JButton("Reset Cache");\r
newUnicodeFont = null;\r
}\r
\r
- // BOZO - Fix no effects.\r
- if (unicodeFont.loadGlyphs(25)) {\r
+ if (!unicodeFont.getEffects().isEmpty() && unicodeFont.loadGlyphs(25)) {\r
glyphPageComboModel.removeAllElements();\r
int pageCount = unicodeFont.getGlyphPages().size();\r
int glyphCount = 0;\r
}\r
\r
if (sampleTextRadio.isSelected()) {\r
- GL11.glColor4f(renderingBackgroundColor.r, renderingBackgroundColor.g, renderingBackgroundColor.b,\r
+ GL11.glClearColor(renderingBackgroundColor.r, renderingBackgroundColor.g, renderingBackgroundColor.b,\r
renderingBackgroundColor.a);\r
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);\r
int offset = unicodeFont.getYOffset(sampleText);\r
if (offset > 0) offset = 0;\r
unicodeFont.drawString(0, -offset, sampleText, Color.WHITE, 0, sampleText.length());\r
} else {\r
- GL11.glColor4f(1, 1, 1, 1);\r
+ GL11.glClearColor(1, 1, 1, 1);\r
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);\r
unicodeFont.addGlyphs(sampleText);\r
// GL11.glColor4f(renderingBackgroundColor.r, renderingBackgroundColor.g, renderingBackgroundColor.b,\r
List pages = unicodeFont.getGlyphPages();\r
if (index >= 0 && index < pages.size()) {\r
Texture texture = ((GlyphPage)pages.get(glyphPageCombo.getSelectedIndex())).getTexture();\r
- GL11.glBegin(GL11.GL_QUADS);\r
- GL11.glTexCoord2f(0, 0);\r
- GL11.glVertex3f(0, 0, 0);\r
- GL11.glTexCoord2f(0, 1);\r
- GL11.glVertex3f(0, texture.getHeight(), 0);\r
- GL11.glTexCoord2f(1, 1);\r
- GL11.glVertex3f(texture.getWidth(), texture.getHeight(), 0);\r
- GL11.glTexCoord2f(1, 0);\r
- GL11.glVertex3f(texture.getWidth(), 0, 0);\r
- GL11.glEnd();\r
+\r
+ glDisable(GL_TEXTURE_2D);\r
+ glColor4f(renderingBackgroundColor.r, renderingBackgroundColor.g, renderingBackgroundColor.b,\r
+ renderingBackgroundColor.a);\r
+ glBegin(GL_QUADS);\r
+ glVertex3f(0, 0, 0);\r
+ glVertex3f(0, texture.getHeight(), 0);\r
+ glVertex3f(texture.getWidth(), texture.getHeight(), 0);\r
+ glVertex3f(texture.getWidth(), 0, 0);\r
+ glEnd();\r
+ glEnable(GL_TEXTURE_2D);\r
+\r
+ texture.bind();\r
+ glColor4f(1, 1, 1, 1);\r
+ glBegin(GL_QUADS);\r
+ glTexCoord2f(0, 0);\r
+ glVertex3f(0, 0, 0);\r
+\r
+ glTexCoord2f(0, 1);\r
+ glVertex3f(0, texture.getHeight(), 0);\r
+\r
+ glTexCoord2f(1, 1);\r
+ glVertex3f(texture.getWidth(), texture.getHeight(), 0);\r
+\r
+ glTexCoord2f(1, 0);\r
+ glVertex3f(texture.getWidth(), 0, 0);\r
+ glEnd();\r
}\r
}\r
}\r
package com.badlogic.gdx.hiero.unicodefont;\r
\r
import java.awt.AlphaComposite;\r
+import java.awt.FontMetrics;\r
import java.awt.Graphics2D;\r
import java.awt.RenderingHints;\r
import java.awt.font.FontRenderContext;\r
import com.badlogic.gdx.graphics.Texture;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.hiero.unicodefont.effects.ColorEffect;\r
import com.badlogic.gdx.hiero.unicodefont.effects.Effect;\r
\r
/**\r
scratchGraphics.setComposite(AlphaComposite.Clear);\r
scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE);\r
scratchGraphics.setComposite(AlphaComposite.SrcOver);\r
- scratchGraphics.setColor(java.awt.Color.white);\r
- for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();)\r
- ((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph);\r
- glyph.setShape(null); // The shape will never be needed again.\r
+ if (unicodeFont.getNativeRendering()) {\r
+ for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) {\r
+ Effect effect = (Effect)iter.next();\r
+ if (effect instanceof ColorEffect) scratchGraphics.setColor(((ColorEffect)effect).getColor());\r
+ }\r
+ scratchGraphics.setColor(java.awt.Color.white);\r
+ scratchGraphics.setFont(unicodeFont.getFont());\r
+ scratchGraphics.drawString("" + (char)glyph.getCodePoint(), 0, unicodeFont.getAscent());\r
+ } else {\r
+ scratchGraphics.setColor(java.awt.Color.white);\r
+ for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();)\r
+ ((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph);\r
+ glyph.setShape(null); // The shape will never be needed again.\r
+ }\r
\r
WritableRaster raster = scratchImage.getRaster();\r
int[] row = new int[width];\r
import java.awt.Rectangle;\r
import java.awt.font.GlyphVector;\r
import java.awt.font.TextAttribute;\r
+import java.awt.geom.Rectangle2D;\r
import java.io.IOException;\r
import java.lang.reflect.Field;\r
import java.util.ArrayList;\r
static private final int PAGES = MAX_GLYPH_CODE / PAGE_SIZE;\r
\r
private Font font;\r
+ private FontMetrics metrics;\r
private String ttfFileRef;\r
private int ascent, descent, leading, spaceWidth;\r
private final Glyph[][] glyphs = new Glyph[PAGES][];\r
private Glyph missingGlyph;\r
private int glyphPageWidth = 512, glyphPageHeight = 512;\r
private final DisplayList emptyDisplayList = new DisplayList();\r
+ private boolean nativeRendering;\r
\r
private boolean displayListCaching = true;\r
private int baseDisplayListID = -1;\r
}\r
font = baseFont.deriveFont(attributes);\r
\r
- FontMetrics metrics = GlyphPage.scratchGraphics.getFontMetrics(font);\r
+ metrics = GlyphPage.scratchGraphics.getFontMetrics(font);\r
ascent = metrics.getAscent();\r
descent = metrics.getDescent();\r
leading = metrics.getLeading();\r
int extraX = 0, extraY = ascent;\r
boolean startNewLine = false;\r
Texture lastBind = null;\r
+ int offsetX = 0;\r
for (int glyphIndex = 0, n = vector.getNumGlyphs(); glyphIndex < n; glyphIndex++) {\r
int charIndex = vector.getGlyphCharIndex(glyphIndex);\r
if (charIndex < startIndex) continue;\r
int codePoint = text.codePointAt(charIndex);\r
\r
Rectangle bounds = getGlyphBounds(vector, glyphIndex, codePoint);\r
+ bounds.x += offsetX;\r
Glyph glyph = getGlyph(vector.getGlyphCode(glyphIndex), codePoint, bounds, vector, glyphIndex);\r
\r
if (startNewLine && codePoint != '\n') {\r
extraY += getLineHeight();\r
lines++;\r
totalHeight = 0;\r
- }\r
+ } else if (nativeRendering)\r
+ offsetX += bounds.width;\r
}\r
if (lastBind != null) GL11.glEnd();\r
\r
}\r
\r
private Rectangle getGlyphBounds (GlyphVector vector, int index, int codePoint) {\r
- Rectangle bounds = vector.getGlyphPixelBounds(index, GlyphPage.renderContext, 0, 0);\r
+ Rectangle bounds;\r
+ if (nativeRendering)\r
+ bounds = metrics.getStringBounds("" + (char)codePoint, GlyphPage.scratchGraphics).getBounds();\r
+ else\r
+ bounds = vector.getGlyphPixelBounds(index, GlyphPage.renderContext, 0, 0);\r
if (codePoint == ' ') bounds.width = spaceWidth;\r
return bounds;\r
}\r
this.displayListCaching = displayListCaching;\r
}\r
\r
+ public void setNativeRendering (boolean nativeRendering) {\r
+ this.nativeRendering = nativeRendering;\r
+ }\r
+\r
+ public boolean getNativeRendering () {\r
+ return nativeRendering;\r
+ }\r
+\r
/**\r
* Returns the path to the TTF file for this UnicodeFont, or null. If this UnicodeFont was created without specifying the TTF\r
* file, it will try to determine the path using Sun classes. If this fails, null is returned.\r