Java Code Examples for java.awt.FontFormatException

The following are top voted examples for showing how to use java.awt.FontFormatException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: LeagueStats   File: Assets.java   Source Code and License 6 votes vote down vote up
/**
 * Initializes the fonts for this application.
 */
private static void initFonts() {
	final String extension = ".ttf";
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

	try {
		ge.registerFont(Font.createFont(Font.TRUETYPE_FONT,
				new File(FONT_FILE_PATH + CAVIAR_FONT_NAME.replace(" ", "") + extension)));

	} catch (FontFormatException | IOException e) {
		logger.logError("An error occured while trying to register the font: " + CAVIAR_FONT_NAME + extension);

	}
	NAME_FONT = new Font(CAVIAR_FONT_NAME, Font.BOLD, 18);
	SMALL_NAME_FONT = new Font(CAVIAR_FONT_NAME, Font.PLAIN, 15);
	STATS_FONT = new Font(CAVIAR_FONT_NAME, Font.PLAIN, 18);
}
 
Example 2
Project: java-swing-template   File: Utilities.java   Source Code and License 6 votes vote down vote up
public static boolean registerFont(File fontFile) {
    boolean b = false;
    try {
        Font f = Font.createFont(Font.TRUETYPE_FONT, fontFile);
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(f);
        b = true;
    } catch (FontFormatException | IOException e) {
        b = false;
    }
    return b;
}
 
Example 3
Project: OpenJSharp   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify();
        init(fIndex);
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 4
Project: OpenJSharp   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 5
Project: OpenJSharp   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 6
Project: OpenJSharp   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 7
Project: OpenJSharp   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 8
Project: jdk8u-jdk   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer, boolean useFilePool)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify(useFilePool);
        init(fIndex);
        if (!useFilePool) {
           close();
        }
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 9
Project: jdk8u-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 10
Project: jdk8u-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 11
Project: jdk8u-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 12
Project: jdk8u-jdk   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 13
Project: openjdk-jdk10   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer, boolean useFilePool)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify(useFilePool);
        init(fIndex);
        if (!useFilePool) {
           close();
        }
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 14
Project: openjdk-jdk10   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 15
Project: openjdk-jdk10   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 16
Project: openjdk-jdk10   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 17
Project: openjdk-jdk10   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 18
Project: Mafia   File: FontResources.java   Source Code and License 6 votes vote down vote up
public static void loadResources() {
	try(InputStream mainFontIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntu.ttf");
			InputStream mainFontBoldIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntuBold.ttf")) {
		
		mainFont = Font.createFont(Font.TRUETYPE_FONT, mainFontIn);
		mainFontBold = Font.createFont(Font.TRUETYPE_FONT, mainFontBoldIn);
		
		
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		
		ge.registerFont(mainFont);
		ge.registerFont(mainFontBold);
	} catch (IOException | FontFormatException e) {
		e.printStackTrace();
		System.exit(-1);
	}
}
 
Example 19
Project: openjdk9   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer, boolean useFilePool)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify(useFilePool);
        init(fIndex);
        if (!useFilePool) {
           close();
        }
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 20
Project: openjdk9   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 21
Project: openjdk9   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 22
Project: openjdk9   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 23
Project: openjdk9   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 24
Project: opsu-dance   File: Fonts.java   Source Code and License 6 votes vote down vote up
/**
 * Initializes all fonts.
 * @throws SlickException if ASCII glyphs could not be loaded
 * @throws FontFormatException if any font stream data does not contain the required font tables
 * @throws IOException if a font stream cannot be completely read
 */
public static void init() throws SlickException, FontFormatException, IOException {
	float fontBase = 12f * GameImage.getUIscale();
	Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME));
	Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	DEFAULT = new UnicodeFont(font);
	BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
	XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
	LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
	MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
	MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2));
	SMALL = new UnicodeFont(font.deriveFont(fontBase));
	SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase));
	ColorEffect colorEffect = new ColorEffect();
	loadFont(DEFAULT, colorEffect);
	loadFont(BOLD, colorEffect);
	loadFont(XLARGE, colorEffect);
	loadFont(LARGE, colorEffect);
	loadFont(MEDIUM, colorEffect);
	loadFont(MEDIUMBOLD, colorEffect);
	loadFont(SMALL, colorEffect);
	loadFont(SMALLBOLD, colorEffect);
}
 
Example 25
Project: DigitalMediaServer   File: CodecUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Check the font file or font name if registered in the OS
 *
 * @param fontName font represented by font file or by the font name
 *
 * @return the registered font name or null when not found
 */
public static String isFontRegisteredInOS(String fontName) {
	if (isNotBlank(fontName)) {
		File fontFile = new File(fontName);
		if (fontFile.exists()) { // Test if the font is specified by the file.
			try {
				fontName = Font.createFont(Font.TRUETYPE_FONT, fontFile).getFontName();
			} catch (FontFormatException | IOException e) {
				LOGGER.debug("Exception when implementing the custom font: ", e.getMessage());
			}
		}

		// The font is specified by the name. Check if it is registered in the OS.
		String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
		for (String font : fonts) {
			if (font.equals(fontName)) {
				return font;
			}
		}
	}

	LOGGER.debug("Font name not found. Check if it is properly specified or installed in the OS");
	return null;
}
 
Example 26
Project: jdk8u_jdk   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer, boolean useFilePool)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify(useFilePool);
        init(fIndex);
        if (!useFilePool) {
           close();
        }
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 27
Project: jdk8u_jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 28
Project: jdk8u_jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 29
Project: jdk8u_jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 30
Project: jdk8u_jdk   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 31
Project: swing-material   File: MaterialIcons.java   Source Code and License 6 votes vote down vote up
private static Font loadFont(String resourceName) {
        try (InputStream inputStream = MaterialIcons.class.getResourceAsStream("/fonts/" + resourceName)) {
            return Font.createFont(Font.TRUETYPE_FONT, inputStream);
        } catch (IOException | FontFormatException e) {
            throw new RuntimeException("Could not load " + resourceName, e);
        }
        //JDK 6 compatible
//        try {
//            Font font;
//            InputStream inputStream = MaterialIcons.class.getResourceAsStream("/fonts/" + resourceName);
//            font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
//            inputStream.close();
//            return font;
//        } catch (Exception e) {
//            throw new RuntimeException("Could not load " + resourceName, e);
//        }
    }
 
Example 32
Project: lookaside_java-1.8.0-openjdk   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer, boolean useFilePool)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify(useFilePool);
        init(fIndex);
        if (!useFilePool) {
           close();
        }
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 33
Project: lookaside_java-1.8.0-openjdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 34
Project: lookaside_java-1.8.0-openjdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 35
Project: lookaside_java-1.8.0-openjdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 36
Project: lookaside_java-1.8.0-openjdk   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 37
Project: PokeSweeper   File: Helbideak.java   Source Code and License 6 votes vote down vote up
private static void besteakKargatu(){
	try{
		iturria = (Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("skin/font/normala.ttf"))).deriveFont(12F);
		unownIturria = (Font.createFont( Font.TRUETYPE_FONT, new FileInputStream("skin/font/unown.ttf"))).deriveFont(12F);
		ikonoa = ImageIO.read(new File("skin/ikonoa.png"));
	}catch (IOException | FontFormatException e){}
	kursorea = Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().getImage("skin/kursorea.png") , new Point(3, 30), "img");
	voltorb = new ImageIcon("skin/laukiak/voltorb/voltorb.png");
	voltorb_s = new ImageIcon("skin/laukiak/voltorb/voltorb_s.png");
	splashGif = new ImageIcon("skin/splashEnter.gif");
	galdera = new ImageIcon("skin/laukiak/galdera.png");
	lorea = new ImageIcon("skin/kontadorea/lorea.gif");
	win = new ImageIcon("skin/hallDeFama/winTrasparentzia.gif");
	lugia = new ImageIcon("skin/hallDeFama/lugia.png"); 
	hooh = new ImageIcon("skin/hallDeFama/ho-oh.png");
	oak = new ImageIcon("skin/oak.gif");
	sliderIcon = new ImageIcon("skin/sliderIcon.png");
	flute = new ImageIcon("skin/flute.png");
}
 
Example 38
Project: code-similarity   File: TTFontDemo.java   Source Code and License 6 votes vote down vote up
/** Construct a TTFontDemo -- Create a Font from TTF.
 */
public TTFontDemo(String fontFileName, String text)
throws IOException, FontFormatException {
    super(text, JLabel.CENTER);

    setBackground(Color.white);

    // First, see if we can load the font file.
    InputStream is = this.getClass().getResourceAsStream(fontFileName);
    if (is == null) {
        throw new IOException("Cannot open " + fontFileName);
    }

    // createFont makes a 1-point font, bit hard to read :-)
    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    // So scale it to 24 pt.
    Font ttfReal = ttfBase.deriveFont(Font.PLAIN, 24);

    setFont(ttfReal);
}
 
Example 39
Project: Java-2D-Game   File: Fonts.java   Source Code and License 6 votes vote down vote up
public Fonts() {
    char tabc[] = {'ą', 'ę', 'ó', 'ć', 'ż', 'ł', 'ś', 'ź', 'ń', 'Ł', 'Ó','Ś','Ę',};
    try {
        //Utworzenie czcionki
        font = Font.createFont(Font.TRUETYPE_FONT, new File("res/fonts/TrajanPro-Regular.otf"));
        //font = font.deriveFont(Font.BOLD, 48f);
    } catch (FontFormatException fe) {
        System.out.println("FONT - FontFormatException");
    } catch (IOException ioe) {
        System.out.println("FILE - IOException");
    }
    
    //stworzenie zmiennej printLabel i printHead, ustalenie parametrów czcionki
    printLabel = new TrueTypeFont(font.deriveFont(Font.BOLD, 18f), true, tabc);
    printHead = new TrueTypeFont(font.deriveFont(Font.BOLD, 28f), true, tabc);
    printBig = new TrueTypeFont(font.deriveFont(Font.BOLD, 25f), true, tabc);
    printMediumLogo = new TrueTypeFont(font.deriveFont(Font.BOLD, 46f), true, tabc);
    printBigLogo = new TrueTypeFont(font.deriveFont(Font.BOLD, 78f), true, tabc);
}
 
Example 40
Project: stendhal   File: Initializer.java   Source Code and License 6 votes vote down vote up
/**
 * Load a custom font.
 * 
 * @param fontName Name of the font
 */
private static void initFont(String fontName) {
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	// Don't needlessly load the font if user already has it installed
	boolean needsLoading = true;
	for (String font : ge.getAvailableFontFamilyNames()) {
		if (fontName.equals(font)) {
			needsLoading = false;
			break;
		}
	}
	if (needsLoading) {
		String resource = "data/gui/" + fontName + ".ttf";
		try {
			ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, DataLoader.getResourceAsStream(resource)));
		} catch (IOException|FontFormatException e) {
			logger.error("Error loading custom font '" + resource + '"', e);
		}
	}
}
 
Example 41
Project: ClearVolume   File: ClearVolumeDefaultFont.java   Source Code and License 6 votes vote down vote up
public static Font getFontPlain(float pSize)
{
	if (sFont != null)
		return sFont;

	try
	{
		sFont = Font.createFont(Font.TRUETYPE_FONT,
								ClearVolumeDefaultFont.class.getResourceAsStream(cFontPath))
					.deriveFont(Font.PLAIN, pSize);
	}
	catch (final FontFormatException | IOException e)
	{
		// use a fallback font in case the original couldn't be found or
		// there has
		// been a problem
		// with the font format
		System.err.println("Could not use \"" + cFontPath
							+ "\" ("
							+ e.toString()
							+ "), falling back to Sans.");
		sFont = new Font("Sans", Font.PLAIN, 12);
	}
	return sFont;
}
 
Example 42
Project: MinecraftAutoInstaller   File: MultiMainFrame.java   Source Code and License 6 votes vote down vote up
public MultiMainFrame() throws UnsupportedEncodingException, FontFormatException, IOException {
    MultiMainFrame.font = Font.createFont(Font.TRUETYPE_FONT, this.getClass().getResourceAsStream("/fonts/NanumBarunGothic.ttf")).deriveFont(Font.PLAIN, 0);
    SettingHandling sh = new SettingHandling();
    settings = sh.getSettingFile();
    unzipsettings = sh.getUnzipProperties();
    installarray = getInstallHashMap();
    model = getCustomModel();
    Enumeration<?> pn = unzipsettings.propertyNames();
    unzipprofile = sh.getUnzipProfileProperties((String) pn.nextElement());
    path = new String(System.getenv("APPDATA").getBytes("ISO-8859-1"), "UTF-8");
    title = new String(settings.getProperty("title").getBytes("ISO-8859-1"), "UTF-8");
    description = new String(settings.getProperty("description").getBytes("ISO-8859-1"), "UTF-8");
    unzippath = new String(unzipprofile.getProperty("unzippath").getBytes("ISO-8859-1"), "UTF-8");
    unzipfile = new String(unzipprofile.getProperty("zippath").getBytes("ISO-8859-1"), "UTF-8");
    initComponents();
}
 
Example 43
Project: infobip-open-jdk-8   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify();
        init(fIndex);
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 44
Project: infobip-open-jdk-8   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 45
Project: infobip-open-jdk-8   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 46
Project: infobip-open-jdk-8   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 47
Project: infobip-open-jdk-8   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 48
Project: onegui   File: FontResourceFactory.java   Source Code and License 6 votes vote down vote up
/**
 * Get a specific font
 * 
 * @param resource
 *            the resource name. Must be a TrueType font.
 * @param size
 *            the size in pixels
 * @param style
 *            the font style
 * @return the font reference
 */
public Font getFont(final String resource, final int size, final FontStyle style) {

    final FontResourceKey key = new FontResourceKey(resource, size, style);
    final Font cached = this.fonts.get(key);

    if (cached != null) {
        return cached;
    }

    Font baseFont = this.baseFonts.get(resource);

    if (baseFont == null) {
        try {
            baseFont = this.createFont(resource);
        } catch (IOException | FontFormatException e) {
            throw new RuntimeException("Failed to load font: " + resource, e);
        }
    }

    final Font derivedFont = baseFont.deriveFont(style.getStyle(), size);

    this.fonts.put(key, derivedFont);

    return derivedFont;
}
 
Example 49
Project: jdk8u-dev-jdk   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify();
        init(fIndex);
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 50
Project: jdk8u-dev-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 51
Project: jdk8u-dev-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 52
Project: jdk8u-dev-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example 53
Project: jdk8u-dev-jdk   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}
 
Example 54
Project: esp8266-oled-ssd1306-font-converter   File: TimeResource.java   Source Code and License 6 votes vote down vote up
@Post(value = "json")
public TimeOutDto execute(TimeInDto inDto) throws FontFormatException, IOException {
    TimeOutDto outDto = new TimeOutDto();
    DateTime dateTime = new DateTime(DateTimeZone.UTC);

    Locale locale = new Locale(inDto.getLanguage(), inDto.getCountry());
    outDto.setMillisOfDayUtc(dateTime.getMillisOfDay());

    List<TimeZoneDto> timeZones = new ArrayList<>();
    outDto.setTimeZoneDto(timeZones);

    for (String timeZoneId : inDto.getTimeZoneIds()) {
        DateTimeZone zone = DateTimeZone.forID(timeZoneId);
        DateTime localDateTime = new DateTime(zone);
        TimeZoneDto zoneDto = new TimeZoneDto();
        zoneDto.setIndex(timeZones.size());
        zoneDto.setTimeZoneId(timeZoneId);
        zoneDto.setTimeZoneOffsetToUtcMillis(zone.getOffset(dateTime.getMillis()));
        zoneDto.setFormattedDate(localDateTime.toString(inDto.getDateFormat(), locale));
        timeZones.add(zoneDto);

    }
    return outDto;
}
 
Example 55
Project: esp8266-oled-ssd1306-font-converter   File: FontResource.java   Source Code and License 6 votes vote down vote up
@Get(value = "json")
public List<FontDto> execute() throws FontFormatException, IOException {
    String fontFamily = (String) this.getRequestAttributes().get("fontFamily");
    List<FontDto> fonts = new ArrayList<>();
    GraphicsEnvironment graphicEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (Font font : graphicEnvironment.getAllFonts()) {
        if (fontFamily == null || fontFamily.equals(font.getFamily())) {
            FontDto dto = new FontDto();
            dto.setName(font.getFontName());
            dto.setFontFamily(font.getFamily());
            dto.setPlain(font.isPlain());
            dto.setItalic(font.isItalic());
            dto.setBold(font.isBold());
            fonts.add(dto);
        }
    }
    return fonts;
}
 
Example 56
Project: jdk7-jdk   File: TrueTypeFont.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the header table for this font (within a collection)
 * - reads the names (full, family).
 * - determines the style of the font.
 * - initializes the CMAP
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public TrueTypeFont(String platname, Object nativeNames, int fIndex,
             boolean javaRasterizer)
    throws FontFormatException {
    super(platname, nativeNames);
    useJavaRasterizer = javaRasterizer;
    fontRank = Font2D.TTF_RANK;
    try {
        verify();
        init(fIndex);
    } catch (Throwable t) {
        close();
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
    Disposer.addObjectRecord(this, disposerRecord);
}
 
Example 57
Project: jdk7-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
/**
 * - does basic verification of the file
 * - reads the names (full, family).
 * - determines the style of the font.
 * @throws FontFormatException - if the font can't be opened
 * or fails verification,  or there's no usable cmap
 */
public Type1Font(String platname, Object nativeNames, boolean createdCopy)
    throws FontFormatException {
    super(platname, nativeNames);
    fontRank = Font2D.TYPE1_RANK;
    checkedNatives = true;
    try {
        verify();
    } catch (Throwable t) {
        if (createdCopy) {
            T1DisposerRecord ref = new T1DisposerRecord(platname);
            Disposer.addObjectRecord(bufferRef, ref);
            bufferRef = null;
        }
        if (t instanceof FontFormatException) {
            throw (FontFormatException)t;
        } else {
            throw new FontFormatException("Unexpected runtime exception.");
        }
    }
}
 
Example 58
Project: jdk7-jdk   File: Type1Font.java   Source Code and License 6 votes vote down vote up
private void verify() throws FontFormatException {
    /* Normal usage should not call getBuffer(), as its state
     * ie endianness, position etc, are shared. verify() can do
     * this as its called only from within the constructor before
     * there are other users of this object.
     */
    ByteBuffer bb = getBuffer();
    if (bb.capacity() < 6) {
        throw new FontFormatException("short file");
    }
    int val = bb.get(0) & 0xff;
    if ((bb.get(0) & 0xff) == 0x80) {
        verifyPFB(bb);
        bb.position(6);
    } else {
        verifyPFA(bb);
        bb.position(0);
    }
    initNames(bb);
    if (familyName == null || fullName == null) {
        throw new FontFormatException("Font name not found");
    }
    setStyle();
}
 
Example 59
Project: LWJGFont   File: TestLWJGFontFactory_packageDuplicateFonts.java   Source Code and License 6 votes vote down vote up
@Test
public void loadLWJGFontClass() throws ClassNotFoundException, IOException, FontFormatException {
	URLClassLoader	classLoader = null;
	
	try {
		classLoader = new URLClassLoader(new URL[] {new File(TEST_JAR_PATH).toURI().toURL()});

		assertNotNull(classLoader.loadClass(CLASS_MOSAMOSAFONT_8));
	} finally {
		if (classLoader != null) {
			try {
				classLoader.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
 
Example 60
Project: jdk7-jdk   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies native font is accessible.
 * @throws FontFormatException - if the font can't be located.
 */
public NativeFont(String platName, boolean bitmapDelegate)
    throws FontFormatException {
    super(platName, null);

    /* This is set true if this is an instance of a NativeFont
     * created by some other font, to get native bitmaps.
     * The delegating font will call this font only for "basic"
     * cases - ie non-rotated, uniform scale, monochrome bitmaps.
     * If this is false, then this instance may need to itself
     * delegate to another font for non-basic cases. Since
     * NativeFonts are used in that way only for symbol and dingbats
     * we know its safe to delegate these to the JRE's default
     * physical font (Lucida Sans Regular).
     */
    isBitmapDelegate = bitmapDelegate;

    if (GraphicsEnvironment.isHeadless()) {
        throw new FontFormatException("Native font in headless toolkit");
    }
    fontRank = Font2D.NATIVE_RANK;
    initNames();
    if (getNumGlyphs() == 0) {
      throw new FontFormatException("Couldn't locate font" + platName);
    }
}