當前位置: 首頁>>代碼示例>>Java>>正文


Java FontFormatException類代碼示例

本文整理匯總了Java中java.awt.FontFormatException的典型用法代碼示例。如果您正苦於以下問題:Java FontFormatException類的具體用法?Java FontFormatException怎麽用?Java FontFormatException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FontFormatException類屬於java.awt包,在下文中一共展示了FontFormatException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: registerFont

import java.awt.FontFormatException; //導入依賴的package包/類
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;
}
 
開發者ID:isu3ru,項目名稱:java-swing-template,代碼行數:12,代碼來源:Utilities.java

示例2: initFonts

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:Ativelox,項目名稱:LeagueStats,代碼行數:20,代碼來源:Assets.java

示例3: TrueTypeFont

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * - 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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:TrueTypeFont.java

示例4: Type1Font

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * - 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.");
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:Type1Font.java

示例5: verify

import java.awt.FontFormatException; //導入依賴的package包/類
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();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:Type1Font.java

示例6: verifyPFB

import java.awt.FontFormatException; //導入依賴的package包/類
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());
            }
        }
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:Type1Font.java

示例7: NativeFont

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:NativeFont.java

示例8: TrueTypeFont

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * - 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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:32,代碼來源:TrueTypeFont.java

示例9: TrueTypeFont

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * - 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:TrueTypeFont.java

示例10: Type1Font

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * - 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.");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Type1Font.java

示例11: NativeFont

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:NativeFont.java

示例12: loadResources

import java.awt.FontFormatException; //導入依賴的package包/類
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);
	}
}
 
開發者ID:ProjectK47,項目名稱:Mafia,代碼行數:18,代碼來源:FontResources.java

示例13: init

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:yugecin,項目名稱:opsu-dance,代碼行數:29,代碼來源:Fonts.java

示例14: isFontRegisteredInOS

import java.awt.FontFormatException; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:31,代碼來源:CodecUtil.java

示例15: loadFont

import java.awt.FontFormatException; //導入依賴的package包/類
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);
//        }
    }
 
開發者ID:leMaik,項目名稱:swing-material,代碼行數:18,代碼來源:MaterialIcons.java


注:本文中的java.awt.FontFormatException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。