Java 类java.awt.FontFormatException 实例源码

项目:LeagueStats    文件:Assets.java   
/**
 * 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);
}
项目:OpenJSharp    文件:TrueTypeFont.java   
/**
 * - 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);
}
项目:OpenJSharp    文件:Type1Font.java   
/**
 * - 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.");
        }
    }
}
项目:OpenJSharp    文件:Type1Font.java   
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();
}
项目:OpenJSharp    文件:Type1Font.java   
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());
            }
        }
    }
项目:OpenJSharp    文件:NativeFont.java   
/**
 * 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);
    }
}
项目:jdk8u-jdk    文件:TrueTypeFont.java   
/**
 * - 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);
}
项目:jdk8u-jdk    文件:Type1Font.java   
/**
 * - 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.");
        }
    }
}
项目:jdk8u-jdk    文件:Type1Font.java   
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();
}
项目:jdk8u-jdk    文件:Type1Font.java   
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());
            }
        }
    }
项目:jdk8u-jdk    文件:NativeFont.java   
/**
 * 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);
    }
}
项目:openjdk-jdk10    文件:TrueTypeFont.java   
/**
 * - 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);
}
项目:openjdk-jdk10    文件:Type1Font.java   
/**
 * - 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.");
        }
    }
}
项目:openjdk-jdk10    文件:Type1Font.java   
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();
}
项目:openjdk-jdk10    文件:Type1Font.java   
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());
            }
        }
    }
项目:openjdk-jdk10    文件:NativeFont.java   
/**
 * 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);
    }
}
项目:Mafia    文件:FontResources.java   
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);
    }
}
项目:openjdk9    文件:TrueTypeFont.java   
/**
 * - 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);
}
项目:openjdk9    文件:Type1Font.java   
/**
 * - 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.");
        }
    }
}
项目:openjdk9    文件:Type1Font.java   
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();
}
项目:openjdk9    文件:Type1Font.java   
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());
            }
        }
    }
项目:openjdk9    文件:NativeFont.java   
/**
 * 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);
    }
}
项目:opsu-dance    文件:Fonts.java   
/**
 * 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);
}
项目:DigitalMediaServer    文件:CodecUtil.java   
/**
 * 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;
}
项目:jdk8u_jdk    文件:TrueTypeFont.java   
/**
 * - 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);
}
项目:jdk8u_jdk    文件:Type1Font.java   
/**
 * - 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.");
        }
    }
}
项目:jdk8u_jdk    文件:Type1Font.java   
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();
}
项目:jdk8u_jdk    文件:Type1Font.java   
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());
            }
        }
    }
项目:jdk8u_jdk    文件:NativeFont.java   
/**
 * 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);
    }
}
项目:swing-material    文件:MaterialIcons.java   
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);
//        }
    }
项目:lookaside_java-1.8.0-openjdk    文件:TrueTypeFont.java   
/**
 * - 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);
}
项目:lookaside_java-1.8.0-openjdk    文件:Type1Font.java   
/**
 * - 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.");
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:Type1Font.java   
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();
}
项目:lookaside_java-1.8.0-openjdk    文件:Type1Font.java   
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());
            }
        }
    }
项目:lookaside_java-1.8.0-openjdk    文件:NativeFont.java   
/**
 * 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);
    }
}
项目:PokeSweeper    文件:Helbideak.java   
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");
}
项目:code-similarity    文件:TTFontDemo.java   
/** 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);
}
项目:Java-2D-Game    文件:Fonts.java   
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);
}
项目:stendhal    文件:Initializer.java   
/**
 * 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);
        }
    }
}
项目:ClearVolume    文件:ClearVolumeDefaultFont.java   
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;
}