public void createFont(final File fntFile, final String name, final int size, final boolean isBold, final boolean isItalic) { final JFrame frame = new JFrame() {{ pack(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // IMPORTANT }}; frame.getContentPane().add(new MyLwjglCanvas(new ApplicationAdapter() { private final UnicodeFont unicodeFont = new UnicodeFont(Font.decode(name), size, isBold, isItalic); @Override public void create() { unicodeFont.setMono(false); unicodeFont.setPaddingTop(PADDING); unicodeFont.setPaddingRight(PADDING); unicodeFont.setPaddingBottom(PADDING); unicodeFont.setPaddingLeft(PADDING); unicodeFont.setPaddingAdvanceX(-2 * PADDING); unicodeFont.setPaddingAdvanceY(-2 * PADDING); unicodeFont.setGlyphPageWidth(1024); unicodeFont.setGlyphPageHeight(512); unicodeFont.setRenderType(UnicodeFont.RenderType.Java); List effects = unicodeFont.getEffects(); effects.add(new ColorEffect(Color.white)); unicodeFont.addGlyphs(CHARACTERS); try { FileUtil.createNewFile(fntFile); new BMFontUtil(unicodeFont).save(fntFile); } catch (Throwable ex) { ex.printStackTrace(); } if ("studio".equals(System.getProperty("featurea.launcher"))) { frame.dispose(); } else { frame.setVisible(false); } } }).getCanvas()); }
/** Loads a single glyph to the backing texture, if it fits. */ private void renderGlyph (Glyph glyph, int width, int height) { // Draw the glyph to the scratch image using Java2D. scratchGraphics.setComposite(AlphaComposite.Clear); scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE); scratchGraphics.setComposite(AlphaComposite.SrcOver); if (unicodeFont.getNativeRendering()) { for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) { Effect effect = (Effect)iter.next(); if (effect instanceof ColorEffect) scratchGraphics.setColor(((ColorEffect)effect).getColor()); } scratchGraphics.setColor(java.awt.Color.white); scratchGraphics.setFont(unicodeFont.getFont()); scratchGraphics.drawString("" + (char)glyph.getCodePoint(), 0, unicodeFont.getAscent()); } else { scratchGraphics.setColor(java.awt.Color.white); for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) ((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph); glyph.setShape(null); // The shape will never be needed again. } width = Math.min(width, texture.getWidth()); height = Math.min(height, texture.getHeight()); WritableRaster raster = scratchImage.getRaster(); int[] row = new int[width]; for (int y = 0; y < height; y++) { raster.getDataElements(0, y, width, 1, row); scratchIntBuffer.put(row); } GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, pageX, pageY, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, scratchByteBuffer); scratchIntBuffer.clear(); float u = pageX / (float)texture.getWidth(); float v = pageY / (float)texture.getHeight(); float u2 = (pageX + width) / (float)texture.getWidth(); float v2 = (pageY + height) / (float)texture.getHeight(); glyph.setTexture(texture, u, v, u2, v2); }
public Hiero(String [] args) { super("Hiero v3.0 - Bitmap Font Tool"); Splash splash = new Splash(this, "/splash.jpg", 2000); initialize(); splash.close(); gamePanel.add(new LwjglCanvas(new Renderer()).getCanvas()); prefs = Preferences.userNodeForPackage(Hiero.class); java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000")); backgroundColorLabel.setIcon(getColorIcon(backgroundColor)); renderingBackgroundColor = new Color(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, 1); fontList.setSelectedValue(prefs.get("system.font", "Arial"), true); fontFileText.setText(prefs.get("font.file", "")); java.awt.Color foregroundColor = EffectUtil.fromString(prefs.get("foreground", "ffffff")); colorEffect = new ColorEffect(); colorEffect.setColor(foregroundColor); effectsListModel.addElement(colorEffect); effectsListModel.addElement(new GradientEffect()); effectsListModel.addElement(new OutlineEffect()); effectsListModel.addElement(new OutlineWobbleEffect()); effectsListModel.addElement(new OutlineZigzagEffect()); effectsListModel.addElement(new ShadowEffect()); effectsListModel.addElement(new DistanceFieldEffect()); new EffectPanel(colorEffect); parseArgs(args); addWindowListener(new WindowAdapter() { public void windowClosed (WindowEvent event) { System.exit(0); // Gdx.app.quit(); } }); updateFontSelector(); setVisible(true); }
public HieroPanel() { super(new BorderLayout()); initialize(); //fontRenderer = new FontRenderer(); //canvas = new LwjglAWTCanvas(fontRenderer, false); //gamePanel.add(canvas.getCanvas()); prefs = Preferences.userNodeForPackage(HieroPanel.class); java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000")); backgroundColorLabel.setIcon(getColorIcon(backgroundColor)); renderingBackgroundColor = new Color(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, 1); fontList.setSelectedValue(prefs.get("system.font", "Arial"), true); fontFileText.setText(prefs.get("font.file", "")); java.awt.Color foregroundColor = EffectUtil.fromString(prefs.get("foreground", "ffffff")); colorEffect = new ColorEffect(); colorEffect.setColor(foregroundColor); effectsListModel.addElement(colorEffect); effectsListModel.addElement(new GradientEffect()); effectsListModel.addElement(new OutlineEffect()); effectsListModel.addElement(new OutlineWobbleEffect()); effectsListModel.addElement(new OutlineZigzagEffect()); effectsListModel.addElement(new ShadowEffect()); effectsListModel.addElement(new DistanceFieldEffect()); new EffectPanel(colorEffect); setVisible(true); }
public Hiero () { super("Hiero v3.0 - Bitmap Font Tool"); Splash splash = new Splash(this, "/splash.jpg", 2000); initialize(); splash.close(); gamePanel.add(new LwjglCanvas(new Renderer(), false).getCanvas()); prefs = Preferences.userNodeForPackage(Hiero.class); java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000")); backgroundColorLabel.setIcon(getColorIcon(backgroundColor)); renderingBackgroundColor = new Color(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, 1); fontList.setSelectedValue(prefs.get("system.font", "Arial"), true); fontFileText.setText(prefs.get("font.file", "")); java.awt.Color foregroundColor = EffectUtil.fromString(prefs.get("foreground", "ffffff")); colorEffect = new ColorEffect(); colorEffect.setColor(foregroundColor); effectsListModel.addElement(colorEffect); effectsListModel.addElement(new GradientEffect()); effectsListModel.addElement(new OutlineEffect()); effectsListModel.addElement(new OutlineWobbleEffect()); effectsListModel.addElement(new OutlineZigzagEffect()); effectsListModel.addElement(new ShadowEffect()); effectsListModel.addElement(new DistanceFieldEffect()); new EffectPanel(colorEffect); setVisible(true); }
public Hiero () { super("Hiero v3.0 - Bitmap Font Tool"); Splash splash = new Splash(this, "/splash.jpg", 2000); initialize(); splash.close(); gamePanel.add(new LwjglCanvas(new Renderer(), false).getCanvas()); prefs = Preferences.userNodeForPackage(Hiero.class); java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000")); backgroundColorLabel.setIcon(getColorIcon(backgroundColor)); renderingBackgroundColor = new Color(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, 1); fontList.setSelectedValue(prefs.get("system.font", "Arial"), true); fontFileText.setText(prefs.get("font.file", "")); java.awt.Color foregroundColor = EffectUtil.fromString(prefs.get("foreground", "ffffff")); colorEffect = new ColorEffect(); colorEffect.setColor(foregroundColor); effectsListModel.addElement(colorEffect); effectsListModel.addElement(new GradientEffect()); effectsListModel.addElement(new OutlineEffect()); effectsListModel.addElement(new OutlineWobbleEffect()); effectsListModel.addElement(new OutlineZigzagEffect()); effectsListModel.addElement(new ShadowEffect()); effectsListModel.addElement(new DistanceFieldEffect()); new EffectPanel(colorEffect); addWindowListener(new WindowAdapter() { public void windowClosed (WindowEvent event) { System.exit(0); // Gdx.app.quit(); } }); setVisible(true); }
@Override public void create () { unicodeFont = new UnicodeFont("c:/windows/fonts/arial.ttf", 48, false, false); unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.white)); }