Example usage for java.awt FontFormatException FontFormatException

List of usage examples for java.awt FontFormatException FontFormatException

Introduction

In this page you can find the example usage for java.awt FontFormatException FontFormatException.

Prototype

public FontFormatException(String reason) 

Source Link

Document

Report a FontFormatException for the reason specified.

Usage

From source file:PolyGlot.IOHandler.java

/**
 * Gets font from save file if possible, null otherwise
 *
 * @param _path The path of the PGD file
 * @return a Font object if the PGD file is both a zip archive and contains
 * a font/*from  w  ww.j ava 2  s  .  c o m*/
 * @throws java.io.IOException
 * @throws java.awt.FontFormatException
 */
public static Font getFontFrom(String _path) throws IOException, FontFormatException {
    Font ret = null;

    if (isFileZipArchive(_path)) {
        ZipFile zipFile = new ZipFile(_path);

        ZipEntry fontEntry = zipFile.getEntry(PGTUtil.fontFileName);

        if (fontEntry != null) {
            final File tempFile = File.createTempFile("stream2file", ".tmp");
            tempFile.deleteOnExit();

            FileOutputStream out = new FileOutputStream(tempFile);
            IOUtils.copy(zipFile.getInputStream(fontEntry), out);

            try {
                ret = Font.createFont(Font.TRUETYPE_FONT, tempFile);
            } catch (FontFormatException e) {
                throw new FontFormatException(
                        "Could not load language font. Possible incompatible font: " + e.getMessage());
            } catch (IOException e) {
                throw new FontFormatException("Could not load language font. I/O exception: " + e.getMessage());
            }
        }
    }

    return ret;
}