java.awt.FontFormatException Java Examples
The following examples show how to use
java.awt.FontFormatException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Type1Font.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * - 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 #2
Source File: Initializer.java From stendhal with GNU General Public License v2.0 | 6 votes |
/** * 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 #3
Source File: Type1Font.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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 #4
Source File: NativeFont.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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 #5
Source File: Type1Font.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * - 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 #6
Source File: TrueTypeFont.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * - 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 #7
Source File: Type1Font.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: NativeFont.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 #9
Source File: HyperiumFontRenderer.java From Hyperium with GNU Lesser General Public License v3.0 | 6 votes |
private Font getFontByName(String name) throws IOException, FontFormatException { if (name.equalsIgnoreCase("roboto condensed")) { return getFontFromInput("/assets/hyperium/fonts/RobotoCondensed-Regular.ttf"); } else if (name.equalsIgnoreCase("roboto")) { return getFontFromInput("/assets/hyperium/fonts/Roboto-Regular.ttf"); } else if (name.equalsIgnoreCase("roboto medium")) { return getFontFromInput("/assets/hyperium/fonts/Roboto-Medium.ttf"); } else if (name.equalsIgnoreCase("montserrat")) { return getFontFromInput("/assets/hyperium/fonts/Montserrat-Regular.ttf"); } else if (name.equalsIgnoreCase("segoeui") || name.equalsIgnoreCase("segoeui light")) { return getFontFromInput("/assets/hyperium/fonts/SegoeUI-Light.ttf"); } else if (name.equalsIgnoreCase("raleway")) { return getFontFromInput("/assets/hyperium/fonts/Raleway-SemiBold.ttf"); } else { // Need to return the default font. return getFontFromInput("/assets/hyperium/fonts/SegoeUI-Light.ttf"); } }
Example #10
Source File: Type1Font.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: TrueTypeFont.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * - 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 #12
Source File: TrueTypeFont.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * - 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 #13
Source File: NativeFont.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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 #14
Source File: PhysicalFont.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Opens the file (temporarily) and does basic verification. * Initializes the CMAP * @throws FontFormatException - if the font can't be opened * or fails verification, or there's no usable cmap */ PhysicalFont(String platname, Object nativeNames) throws FontFormatException { handle = new Font2DHandle(this); this.platName = platname; this.nativeNames = nativeNames; }
Example #15
Source File: PFontHandler.java From PolyGlot with MIT License | 5 votes |
/** * Fetches and returns a font from a given location * * @param filePath * @return collected font * @throws java.awt.FontFormatException * @throws java.io.IOException */ public static Font getFontFromFile(String filePath) throws FontFormatException, IOException { File fontFile = new File(filePath); Font ret = Font.createFont(Font.TRUETYPE_FONT, fontFile); Map attributes = ret.getAttributes(); attributes.put(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON); ret = ret.deriveFont(attributes); return ret; }
Example #16
Source File: Type1Font.java From hottub with GNU General Public License v2.0 | 5 votes |
public int getFileSize() { if (fileSize == 0) { try { getBuffer(); } catch (FontFormatException e) { } } return fileSize; }
Example #17
Source File: Type1Font.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public synchronized ByteBuffer readBlock(int offset, int length) { ByteBuffer mappedBuf = null; try { mappedBuf = getBuffer(); if (offset > fileSize) { offset = fileSize; } mappedBuf.position(offset); return mappedBuf.slice(); } catch (FontFormatException e) { return null; } }
Example #18
Source File: HyperiumFontRenderer.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
public HyperiumFontRenderer(String fontName, float fontSize) { name = fontName; size = fontSize; ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); try { prevScaleFactor = resolution.getScaleFactor(); unicodeFont = new UnicodeFont(getFontByName(fontName).deriveFont(fontSize * prevScaleFactor / 2)); unicodeFont.addAsciiGlyphs(); unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE)); unicodeFont.loadGlyphs(); } catch (FontFormatException | IOException | SlickException e) { e.printStackTrace(); } this.antiAliasingFactor = resolution.getScaleFactor(); }
Example #19
Source File: Type1Font.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public synchronized ByteBuffer readBlock(int offset, int length) { ByteBuffer mappedBuf = null; try { mappedBuf = getBuffer(); if (offset > fileSize) { offset = fileSize; } mappedBuf.position(offset); return mappedBuf.slice(); } catch (FontFormatException e) { return null; } }
Example #20
Source File: PhysicalFont.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Opens the file (temporarily) and does basic verification. * Initializes the CMAP * @throws FontFormatException - if the font can't be opened * or fails verification, or there's no usable cmap */ PhysicalFont(String platname, Object nativeNames) throws FontFormatException { handle = new Font2DHandle(this); this.platName = platname; this.nativeNames = nativeNames; }
Example #21
Source File: OpenHtmlToPdfConverter.java From yarg with Apache License 2.0 | 5 votes |
@Override public void addFont(File file) throws IOException { try { builder.useFont(file, Font.createFont(Font.TRUETYPE_FONT, file).getFamily()); } catch (FontFormatException e) { throw new IOException(e); } }
Example #22
Source File: Win32FontManager.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public Object run() { String eudcFile = getEUDCFontFile(); if (eudcFile != null) { try { /* Must use Java rasteriser since GDI doesn't * enumerate (allow direct use) of EUDC fonts. */ eudcFont = new TrueTypeFont(eudcFile, null, 0, true); } catch (FontFormatException e) { } } return null; }
Example #23
Source File: Win32FontManager.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public Object run() { String eudcFile = getEUDCFontFile(); if (eudcFile != null) { try { /* Must use Java rasteriser since GDI doesn't * enumerate (allow direct use) of EUDC fonts. */ eudcFont = new TrueTypeFont(eudcFile, null, 0, true, false); } catch (FontFormatException e) { } } return null; }
Example #24
Source File: Type1Font.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public synchronized ByteBuffer readBlock(int offset, int length) { ByteBuffer mappedBuf = null; try { mappedBuf = getBuffer(); if (offset > fileSize) { offset = fileSize; } mappedBuf.position(offset); return mappedBuf.slice(); } catch (FontFormatException e) { return null; } }
Example #25
Source File: CreateAlbumToolPanel.java From java-photoslibrary with Apache License 2.0 | 5 votes |
private JPanel getCreatePanel(BiConsumer<AbstractCustomView, String> onCreateClicked) throws IOException, FontFormatException { JPanel panel = new JPanel(); panel.setLayout(new FlowLayout(FlowLayout.LEFT)); panel.add(getCreateButton(onCreateClicked)); return panel; }
Example #26
Source File: PhysicalFont.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Opens the file (temporarily) and does basic verification. * Initializes the CMAP * @throws FontFormatException - if the font can't be opened * or fails verification, or there's no usable cmap */ PhysicalFont(String platname, Object nativeNames) throws FontFormatException { handle = new Font2DHandle(this); this.platName = platname; this.nativeNames = nativeNames; }
Example #27
Source File: FontHelper.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
public List<KerningPair> loadFromTTF(File file, int size) throws IOException, FontFormatException { font = Font.createFont(Font.TRUETYPE_FONT, file); charmap = getFontGlyphToCharMap(font); InputStream input = new FileInputStream(file); List<KerningPair> ret = new ArrayList<>(); this.size = size; if (input == null) { throw new IllegalArgumentException("input cannot be null."); } readTableDirectory(input); if (headOffset == -1) { throw new IOException("HEAD table not found."); } if (kernOffset == -1) { return ret; } if (headOffset < kernOffset) { readHEAD(input); readKERN(input, ret); } else { readKERN(input, ret); readHEAD(input); } input.close(); for (KerningPair kp : ret) { kp.kerning *= scale; } return ret; }
Example #28
Source File: Type1Font.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public int getFileSize() { if (fileSize == 0) { try { getBuffer(); } catch (FontFormatException e) { } } return fileSize; }
Example #29
Source File: Type1Font.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public int getFileSize() { if (fileSize == 0) { try { getBuffer(); } catch (FontFormatException e) { } } return fileSize; }
Example #30
Source File: FontUtils.java From scrimage with Apache License 2.0 | 5 votes |
public static Font createTrueType(InputStream in, int size) throws IOException, FontFormatException { assert (in != null); Font font = Font.createFont(Font.TRUETYPE_FONT, in); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); return font.deriveFont(Font.PLAIN, size); }