/* * UFO Saved Game Editor * Copyright (C) 2010 Christopher Davoren * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.rubikscomplex.ufosge.resources; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import net.rubikscomplex.ufosge.util.Util; /** * * @author Chris Davoren */ public class BigLetter { public static final int NUM_LETTERS = 128; public static final int ASCII_OFFSET = 33; public static final int HEIGHT = 16; public static final int WIDTH = 16; public static final int SPACE_WIDTH = WIDTH / 2; protected static BigLetter[] yellowCache = null; public BufferedImage image; public int visibleWidth; protected BigLetter() { } public static int[] VISIBLE_WIDTHS = { 5, 8, 13, 11, 11, 11, 4, 6, 6, 9, 8, 4, 8, 4, 8, 10, 6, 10, 10, 10, 10, 10, 10, 10, 10, 4, 4, 7, 8, 7, 11, 12, 10, 10, 10, 10, 10, 10, 10, 10, 4, 10, 10, 10, 13, 11, 10, 10, 10, 10, 10, 10, 10, 10, 13, 10, 10, 10, 5, 8, 5, 7, 9, 10, 9, 9, 9, 9, 9, 9, 9, 9, 4, 9, 9, 4, 12, 9, 9, 9, 9, 9, 9, 9, 9, 9, 12, 10, 9, 10, 6, 3, 6, 9, 13, 10, 9, 9, 9, 9, 9, 3, 9, 9, 9, 9, 9, 7, 3, 10, 3, 10, 3, 3, 9, 9, 3, 9, 3, 3, 10, 10, 3, 3, 3, 10, 0, 9 }; public static BigLetter[] loadBigLetters() throws IOException { yellowCache = new BigLetter[NUM_LETTERS]; for(int i = 0; i < NUM_LETTERS; i++) { BigLetter yellowLetter = new BigLetter(); // yellowLetter.image = ImageIO.read(new File(directory + File.separator + "letters-big-yellow-" + i + ".png")); yellowLetter.image = ImageIO.read(ResourceManager.getImageResource("letters-big-yellow-" + i + ".png")); yellowLetter.visibleWidth = VISIBLE_WIDTHS[i]; yellowCache[i] = yellowLetter; } return yellowCache; } public static BigLetter makeSpaceLetter() { BufferedImage spaceImage = new BufferedImage(SPACE_WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); Util.clearImage(spaceImage); BigLetter spaceLetter = new BigLetter(); spaceLetter.image = spaceImage; spaceLetter.visibleWidth = SPACE_WIDTH; return spaceLetter; } public static BigLetter getYellowLetterForChar(char ch) { int chValue = (int)ch; if (chValue < ASCII_OFFSET || chValue >= ASCII_OFFSET + NUM_LETTERS) { return makeSpaceLetter(); } else { return yellowCache[chValue - ASCII_OFFSET]; } } public static int getCharWidth(char ch) { int chValue = (int)ch; if (chValue < ASCII_OFFSET || chValue >= ASCII_OFFSET + NUM_LETTERS) { return SPACE_WIDTH; } else { return yellowCache[chValue - ASCII_OFFSET].visibleWidth; } } public static BufferedImage makeYellowWordImage(String str) { int iwidth = 0; for(int i = 0; i < str.length(); i++) { iwidth += getCharWidth(str.charAt(i)); } BufferedImage wordImage = new BufferedImage(iwidth, HEIGHT, BufferedImage.TYPE_INT_ARGB); Util.clearImage(wordImage); Graphics2D iwg = wordImage.createGraphics(); int xpos = 0; for(int i = 0; i < str.length(); i++) { iwg.drawImage(getYellowLetterForChar(str.charAt(i)).image, xpos, 0, null); xpos += getCharWidth(str.charAt(i)); } return wordImage; } }