Java Code Examples for java.awt.GraphicsEnvironment#registerFont()
The following examples show how to use
java.awt.GraphicsEnvironment#registerFont() .
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: PFontHandler.java From PolyGlot with MIT License | 6 votes |
/** * Fetches and returns default button font nonstatic * * @return Font to default buttons to * @throws java.io.IOException if unable to load font */ private Font getMenuFontInternal() throws IOException { Font ret; try (InputStream tmp = this.getClass().getResourceAsStream(PGTUtil.BUTTON_FONT_LOCATION)) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ret = Font.createFont(Font.TRUETYPE_FONT, tmp); ret = ret.deriveFont((float) 12); // default to size 12 font if (ret != null) { ge.registerFont(ret); } } catch (Exception e) { throw new IOException("Unable to load button font.", e); } return ret; }
Example 2
Source File: Font467.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String fontFileName = Font467.class.getResource("fonts/DejaVuSans.ttf").getFile(); if (args.length > 0) SCREENSHOT_FILE_NAME1 = args[0]; if (args.length > 1) SCREENSHOT_FILE_NAME2 = args[1]; try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontFileName))); } catch (IOException | FontFormatException e) { e.printStackTrace(); } FONT = new Font("DejaVu Sans", Font.PLAIN, 12); BufferedImage bufferedImage1 = drawImage("a"); BufferedImage bufferedImage2 = drawImage("a\ufe00"); if (!imagesAreEqual(bufferedImage1, bufferedImage2)) { try { ImageIO.write(bufferedImage1, "png", new File(System.getProperty("test.classes") + File.separator + SCREENSHOT_FILE_NAME1)); ImageIO.write(bufferedImage2, "png", new File(System.getProperty("test.classes") + File.separator + SCREENSHOT_FILE_NAME2)); } catch (IOException | NullPointerException ex) { ex.printStackTrace(); } throw new RuntimeException("Expected: screenshots must be equal"); } }
Example 3
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 4
Source File: Main.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private static void initPrintPreviewFonts() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontDir = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fonts" + File.separator + "NotoSans" + File.separator; try { ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Regular.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Bold.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Italic.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-BoldItalic.ttf"))); } catch (IOException | FontFormatException ex) { Logging.errorPrint("Unexpected exception loading fonts fo print p", ex); } }
Example 5
Source File: PFontHandler.java From PolyGlot with MIT License | 6 votes |
/** * Fetches and returns unicode compatible font NOTE 1: this is a non-static * method due to an input stream restriction NOTE 2: this is the default * conlang font in PolyGlot * * @return Charis unicode compatible font */ private Font getCharisUnicodeFontInternal(String location) throws IOException { Font ret; try (InputStream tmp = this.getClass().getResourceAsStream(location)) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ret = Font.createFont(Font.TRUETYPE_FONT, tmp); if (ret != null) { ge.registerFont(ret); } } catch (IOException | FontFormatException e) { throw new IOException("Unable to load Charis (" + location + "): " + e.getLocalizedMessage(), e); } return ret; }
Example 6
Source File: Main.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private static void initPrintPreviewFonts() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontDir = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fonts" + File.separator + "NotoSans" + File.separator; try { ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Regular.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Bold.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Italic.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-BoldItalic.ttf"))); } catch (IOException | FontFormatException ex) { Logging.errorPrint("Unexpected exception loading fonts fo print p", ex); } }
Example 7
Source File: Fonts.java From WorldGrower with GNU General Public License v3.0 | 5 votes |
private static Font createFont() { try { Font font = Font.createFont(Font.TRUETYPE_FONT, ImageInfoReader.class.getResourceAsStream("/ufonts.com_tw-cen-mt.ttf")); Font derivedFont = font.deriveFont((float)FONT_SIZE); GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); genv.registerFont(derivedFont); return derivedFont; } catch (FontFormatException | IOException e) { throw new IllegalStateException(e); } }
Example 8
Source File: CollectEarthUtils.java From collect-earth with MIT License | 5 votes |
public static void setUiFont(String ttfFileName) { try { //create the font to use. Specify the size! InputStream fontStream = CollectEarthUtils.class.getResourceAsStream(ttfFileName); Font laoFont = Font.createFont(Font.TRUETYPE_FONT, fontStream).deriveFont(12f); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); //register the font ge.registerFont(laoFont); CollectEarthUtils.setUIFont( new javax.swing.plaf.FontUIResource( laoFont.getFontName(),Font.PLAIN,12) ); } catch (IOException | FontFormatException e) { logger.error("error setting the font " + ttfFileName , e ); } }
Example 9
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); }
Example 10
Source File: FontCheck.java From jclic with GNU General Public License v2.0 | 5 votes |
public static Font buildNewFont(String fileName, StreamIO.InputStreamProvider isp, String resourceName) throws Exception { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = Font.createFont(Font.TRUETYPE_FONT, isp.getInputStream(resourceName)); if (ge != null && font != null) { ge.registerFont(font); font = getValidFont(font.getName(), Font.PLAIN, 1); } return font; }
Example 11
Source File: PFontHandler.java From PolyGlot with MIT License | 5 votes |
/** * Fetches and returns LCD style font NOTE 1: the font returned is very * small, use deriveFont() to make it a usable size NOTE 2: this is a * non-static method due to an input stream restriction * * @return LCD display font * @throws java.awt.FontFormatException if font corrupted * @throws java.io.IOException if unable to load font */ private Font getLcdFontInternal() throws FontFormatException, IOException { try (InputStream tmp = this.getClass().getResourceAsStream(PGTUtil.LCD_FONT_LOCATION)) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font ret = Font.createFont(Font.TRUETYPE_FONT, tmp); if (ret != null) { ge.registerFont(ret); } return ret; } }
Example 12
Source File: UIRes.java From RipplePower with Apache License 2.0 | 5 votes |
public static Font getFont(String fontName, int type, int style, int size) { try { Font font = Font.createFont(type, UIRes.getStream(fontName)); font = font.deriveFont(style, size); final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); return font; } catch (Exception e) { e.printStackTrace(); } return new Font(Font.DIALOG, style, size); }
Example 13
Source File: Utils.java From Game with GNU General Public License v3.0 | 5 votes |
public static Font getFont(final String fontName, final int type, final float size) { try { Font font = Font.createFont(0, Utils.class.getResource("/res/" + fontName).openStream()); final GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); genv.registerFont(font); font = font.deriveFont(type, size); return font; } catch (FontFormatException | IOException ex2) { ((Exception) null).printStackTrace(); return null; } }
Example 14
Source File: LukeMain.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { String lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName(); if (!lookAndFeelClassName.contains("AquaLookAndFeel") && !lookAndFeelClassName.contains("PlasticXPLookAndFeel")) { // may be running on linux platform lookAndFeelClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; } UIManager.setLookAndFeel(lookAndFeelClassName); GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); genv.registerFont(FontUtils.createElegantIconFont()); javax.swing.SwingUtilities.invokeLater(LukeMain::createAndShowGUI); }
Example 15
Source File: OCR.java From ExoVisix with MIT License | 5 votes |
public String init() throws FontFormatException { try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("f2.ttf"))); } catch (IOException e) { //Handle exception } BytePointer outText; TessBaseAPI api=new TessBaseAPI(); //to use tesseract api,at first you have to install tesseract with desired language training data on your system.After That you have to mention //the installation folder. if(api.Init("C:/tessdata", "eng") != 0) { System.out.println("could not initialize tesseract"); System.exit(1); } // //For Bengali Language /* if(api.Init("C:/tesseract-ocr/tessdata", "ben") != 0) { System.out.println("could not initialize tesseract"); System.exit(1); }*/ //read an image from default location for ocr output PIX image=pixRead("ocr_test.png"); if(image==null) { System.err.println("Could not opened the image or Image not found "); } api.SetImage(image); outText=api.GetUTF8Text(); String output= outText.getString(); api.End(); outText.deallocate(); pixDestroy(image); return output; }
Example 16
Source File: Fontf.java From yt-java-game with MIT License | 5 votes |
public void loadFont(String path, String name) { try { System.out.println("Loading: " + path + "..."); Font customFont = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream(path)); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(customFont); Font font = new Font(name, Font.PLAIN, 32); fonts.put(name, font); } catch (Exception e) { System.out.println("ERROR: ttfFont - can't load font " + path + "..."); e.printStackTrace(); } }
Example 17
Source File: MiscTools.java From megabasterd with GNU General Public License v3.0 | 4 votes |
public static Font createAndRegisterFont(String name) { Font font = null; try { font = Font.createFont(Font.TRUETYPE_FONT, MiscTools.class.getResourceAsStream(name)); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); ge.registerFont(font); } catch (FontFormatException | IOException ex) { Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, ex.getMessage()); } return font; }