List of usage examples for java.awt Font createFont
public static Font createFont(int fontFormat, File fontFile) throws java.awt.FontFormatException, java.io.IOException
From source file:sagan.projects.support.VersionBadgeService.java
@PostConstruct public void postConstruct() throws Exception { Font font;/*from w w w . j a v a 2 s . com*/ try (InputStream is = VERDANA_FONT.openStream()) { font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(0, 11); } graphics = DUMMY.getGraphics(); graphics.setFont(font); DefaultXMLFactoriesConfig myConfig = new DefaultXMLFactoriesConfig(); myConfig.setNamespacePhilosophy(NamespacePhilosophy.NIHILISTIC); xbProjector = new XBProjector(myConfig, Flags.TO_STRING_RENDERS_XML); }
From source file:org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font.java
/** * {@inheritDoc}// w w w . j a va 2 s.c o m */ public Font getawtFont() throws IOException { Font awtFont = null; PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) getFontDescriptor(); PDStream ff2Stream = fd.getFontFile2(); if (ff2Stream != null) { try { // create a font with the embedded data awtFont = Font.createFont(Font.TRUETYPE_FONT, ff2Stream.createInputStream()); } catch (FontFormatException f) { LOG.info("Can't read the embedded font " + fd.getFontName()); } if (awtFont == null) { awtFont = FontManager.getAwtFont(fd.getFontName()); if (awtFont != null) { LOG.info("Using font " + awtFont.getName() + " instead"); } setIsFontSubstituted(true); } } // TODO FontFile3 return awtFont; }
From source file:org.rockyroadshub.planner.core.utils.Utilities.java
/** * /*from ww w. j ava2s . c om*/ * @param jarPath * @return * @throws IOException * @throws FontFormatException */ @LogExceptions public static Font getFont(String jarPath) throws IOException, FontFormatException { try (InputStream in = Utilities.class.getResourceAsStream(jarPath)) { return Font.createFont(Font.TRUETYPE_FONT, in); } }
From source file:org.shredzone.commons.captcha.impl.DefaultCaptchaGenerator.java
/** * Sets up the captcha generator.// w w w. ja v a 2 s.c o m */ @PostConstruct public void setup() { if (width <= 0 || height <= 0) { throw new IllegalStateException("Captcha size is not set"); } if (fontPath == null) { throw new IllegalStateException("Font is not set"); } try (InputStream fontStream = DefaultCaptchaGenerator.class.getResourceAsStream(fontPath)) { font = Font.createFont(Font.TRUETYPE_FONT, fontStream); } catch (Exception ex) { LOG.error("Could not open font " + fontPath, ex); throw new IllegalStateException(); } }
From source file:CheckFonts.java
protected static Font getDialogFont(ResourceDialog dialog) throws Exception { Font r = FONTS.get(dialog.typeface); if (r == null) { r = Font.createFont(Font.TRUETYPE_FONT, new File("fonts/" + dialog.typeface.replace(' ', '_') + ".ttf")); FONTS.put(dialog.typeface, r);/*from w ww .j av a2s .c om*/ } return r; }
From source file:net.technicpack.ui.lang.ResourceLoader.java
public Font getFontByName(String fontName) { Font font;//from w ww .j av a 2 s . c om if (fontCache.containsKey(fontName)) return fontCache.get(fontName); if (launcherAssets == null) return fallbackFont; InputStream fontStream = null; try { String fullName = getString(fontName); fontStream = FileUtils.openInputStream(new File(launcherAssets, fullName)); if (fontStream == null) return fallbackFont; font = Font.createFont(Font.TRUETYPE_FONT, fontStream); GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); genv.registerFont(font); } catch (Exception e) { e.printStackTrace(); // Fallback return fallbackFont; } finally { if (fontStream != null) IOUtils.closeQuietly(fontStream); } fontCache.put(fontName, font); if (font == null) return fallbackFont; return font; }
From source file:com.neophob.sematrix.generator.Textwriter.java
/** * Instantiates a new textwriter.//from w w w . j a va2s. c om * * @param controller the controller * @param fontName the font name * @param fontSize the font size * @param text the text */ public Textwriter(PixelControllerGenerator controller, String fontName, int fontSize, String text) { super(controller, GeneratorName.TEXTWRITER, ResizeName.PIXEL_RESIZE); color = new Color(128); xpos = 0; ypos = internalBufferYSize; try { InputStream is = Collector.getInstance().getPapplet().createInput(fontName); tmp = new int[internalBuffer.length]; font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(Font.BOLD, (float) fontSize); LOG.log(Level.INFO, "Loaded font " + fontName + ", size: " + fontSize); } catch (Exception e) { LOG.log(Level.WARNING, "Failed to load font " + fontName + ":", e); } createTextImage(text); }
From source file:es.emergya.cliente.constants.LogicConstantsUI.java
private static Font getFont(Integer type, String font) { Font f;/* w w w . j av a 2s .c o m*/ try { f = Font.createFont(Font.TRUETYPE_FONT, LogicConstantsUI.class.getResourceAsStream(font)); } catch (Exception e) { LogicConstantsUI.LOG.error("No se pudo cargar el font bold", e); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = ge.getAvailableFontFamilyNames(); if (fontNames.length > 0) { f = Font.decode(fontNames[0]); if (type != null) { f = f.deriveFont(type); } } else { throw new NullPointerException("There is no font available: " + font); } } return f; }
From source file:com.neophob.sematrix.core.generator.Textwriter.java
/** * Instantiates a new textwriter.// ww w. j a va 2 s .com * * @param controller the controller * @param fontName the font name * @param fontSize the font size * @param text the text */ public Textwriter(MatrixData matrix, String fontName, int fontSize, FileUtils fu) { super(matrix, GeneratorName.TEXTWRITER, ResizeName.PIXEL_RESIZE); String filename = fu.getDataDir() + File.separator + fontName; InputStream is = null; try { is = new FileInputStream(filename); textAsImage = new int[internalBuffer.length]; font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(Font.BOLD, (float) fontSize); LOG.log(Level.INFO, "Loaded font " + fontName + ", size: " + fontSize); } catch (Exception e) { LOG.log(Level.WARNING, "Failed to load font " + filename + ":", e); throw new IllegalArgumentException( "Failed to load font " + filename + ". Check your config.properties file."); } finally { if (is != null) { try { is.close(); } catch (IOException e) { LOG.log(Level.WARNING, "Failed to close InputStream.", e); } } } createTextImage(INITIAL_STRING); scroller = new PingPongScroller(); }
From source file:es.emergya.cliente.constants.LogicConstants.java
private static Font getFont(Integer type, String font) { Font f;/*from ww w . j ava2 s . c om*/ try { f = Font.createFont(Font.TRUETYPE_FONT, LogicConstants.class.getResourceAsStream(font)); } catch (Exception e) { LogicConstants.LOG.error("No se pudo cargar el font bold", e); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = ge.getAvailableFontFamilyNames(); if (fontNames.length > 0) { f = Font.decode(fontNames[0]); if (type != null) { f = f.deriveFont(type); } } else { throw new NullPointerException("There is no font available: " + font); } } return f; }