public ColorMenu(JFrame frame, int players) { this.frame = frame; numPlayers = players; try { kenVector25 = Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf")) .deriveFont(25f); kenVector16 = Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf")) .deriveFont(16f); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // register the font ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf"))); ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("fonts/kenvector_future.ttf"))); } catch (IOException e) { e.printStackTrace(); } catch (FontFormatException e) { e.printStackTrace(); } initializeComponents(); createGUI(); addEvents(); }
public static void reloadFonts() { String font1Path = Config.getString("font1_file"); String font2Path = Config.getString("font2_file"); int font1Type = font1Path.endsWith(".ttf") ? Font.TRUETYPE_FONT : Font.TYPE1_FONT; int font2Type = font2Path.endsWith(".ttf") ? Font.TRUETYPE_FONT : Font.TYPE1_FONT; File font1 = new File(font1Path); File font2 = new File(font2Path); try { fonts = new Font[] { Font.createFont(font1Type, font1) .deriveFont(Font.BOLD, Integer.parseInt(Config.getString("font1_size"))), Font.createFont(font2Type, font2) .deriveFont(Font.BOLD, Integer.parseInt(Config.getString("font2_size"))), }; } catch (IOException | FontFormatException e) { JOptionPane.showMessageDialog( instance, "Font failed to load: " + e, Constants.SOFTWARE_NAME, JOptionPane.WARNING_MESSAGE); e.printStackTrace(); } }
/** * Extracts the default fonts if the folder doesn't exist Zip extraction code taken from * http://www.codejava.net/java-se/file-io/programmatically-extract-a-zip-file-using-java Loads * all the Fonts into an ArrayList and the String containing the Font directory into a HashMap */ public void setUp() { File folder = new File( System.getProperty("user.home") + File.separator + "vamix" + File.separator + "fonts" + File.separator); // If the fonts folder doesn't exist, the fonts would be extracted if (!folder.exists()) { ZipInputStream zipIn = new ZipInputStream(getClass().getResourceAsStream(File.separator + "fonts.zip")); ZipEntry entry; try { entry = zipIn.getNextEntry(); // iterates over entries in the zip file while (entry != null) { String filePath = System.getProperty("user.home") + File.separator + "vamix" + File.separator + entry.getName(); if (!entry.isDirectory()) { // if the entry is a file, extracts it extractFile(zipIn, filePath); } else { // if the entry is a directory, make the directory File dir = new File(filePath); dir.mkdir(); } zipIn.closeEntry(); entry = zipIn.getNextEntry(); } zipIn.close(); } catch (IOException e1) { e1.printStackTrace(); } } // Loads all the fonts in the folder File[] listofFiles = folder.listFiles(); for (int i = 0; i < listofFiles.length; i++) { if (listofFiles[i].isFile()) { try { Font newFont = Font.createFont(Font.TRUETYPE_FONT, listofFiles[i]); _fontList.add(Font.createFont(Font.TRUETYPE_FONT, listofFiles[i])); _fontDirectory.put(newFont.getName(), listofFiles[i].toString()); } catch (FontFormatException | IOException e) { e.printStackTrace(); } } } }
/** * Loads a font based on file path * * @param String filePath * @param float fontSize * @param FontStyle fontStyle * @throws FontFormatException * @throws IOException */ public INFont(String filePath, float fontSize, FontStyle fontStyle) throws FontFormatException, IOException { File fontFile = new File(filePath); this.loadedFont = Font.createFont(Font.TRUETYPE_FONT, fontFile); this.loadedFont = this.loadedFont.deriveFont(fontSize); this.style = fontStyle; this.size = fontSize; switch (fontStyle) { case BOLD: this.loadedFont = this.loadedFont.deriveFont(Font.BOLD); break; case ITALIC: this.loadedFont = this.loadedFont.deriveFont(Font.ITALIC); break; case PLAIN: this.loadedFont = this.loadedFont.deriveFont(Font.PLAIN); break; case BOLDANDITALIC: this.loadedFont = this.loadedFont.deriveFont(Font.BOLD + Font.ITALIC); break; } }
@Override public void init(GameContainer gc, StateBasedGame st) throws SlickException { // Lade Pixel Font try { font = Font.createFont(Font.TRUETYPE_FONT, new File("./resources/pixel.ttf")); } catch (FontFormatException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Große Pixel Font uniTitle = new UnicodeFont(font, 100, true, false); uniTitle.getEffects().add(new ColorEffect(java.awt.Color.orange)); uniTitle.addAsciiGlyphs(); uniTitle.loadGlyphs(); // Kleine Pixel Font uniNormal = new UnicodeFont(font, 30, true, false); uniNormal.getEffects().add(new ColorEffect(java.awt.Color.white)); uniNormal.addAsciiGlyphs(); uniNormal.loadGlyphs(); levelNames = new ArrayList<>(); playerNames = new ArrayList<>(); times = new ArrayList<>(); selection = new Rectangle(0, 0, 0, 40); }
public static void main(String[] args) throws Exception { int size = Util.getPropertyInt("size", 100); double min = Util.getPropertyDouble("min", 0.01); double max = Util.getPropertyDouble("max", 0.9); Font font = new Font("serif", Font.PLAIN, size); String fpath = Util.getProperty("font", null); if (fpath != null) { font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(fpath)); } for (char c = Character.MIN_VALUE + 1; c < Character.MAX_VALUE; ++c) { int type = Character.getType(c); if (type != Character.CONTROL && type != Character.FORMAT && type != Character.PRIVATE_USE && type != Character.SURROGATE && type != Character.UNASSIGNED && !Character.isMirrored(c) && !Character.isSpaceChar(c)) { String s = "" + c; if (Normalizer.normalize(s, NFKC).contains("\u0308")) continue; // TODO: adhoc UnigramMetrics m = new UnigramMetrics(s, size, false, true, font); if (min < m.getBlackness() && m.getBlackness() < max) { System.out.println("" + c + " " + (int) c); } } } }
TilePanel(Tile tile) { mTile = tile; setOpaque(false); // Used to keep track what component should be displayed components = new Stack<Component>(); if (mTile != null) { if (mTile.isHome()) { try { JLabel j = new JLabel("Home"); Font f = Font.createFont( Font.TRUETYPE_FONT, new FileInputStream("src/fonts/kenvector_future.ttf")); f = f.deriveFont(7f); j.setFont(f); components.push(j); } catch (FontFormatException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (mTile.isStart()) { try { JLabel j = new JLabel("Start"); Font f = Font.createFont( Font.TRUETYPE_FONT, new FileInputStream("src/fonts/kenvector_future.ttf")); f = f.deriveFont(7f); j.setFont(f); components.push(j); } catch (FontFormatException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // If the tile is clicked by the user... addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { // Update this in the action manager mGameManager.tileClicked(mTile, mGameManager.getMainPlayer()); } }); }
static { try { InputStream is = FontAwesome.class.getResourceAsStream(TTF_PATH); fontAwesome = Font.createFont(Font.TRUETYPE_FONT, is); } catch (IOException | FontFormatException e) { System.out.println("Error loading Font Awesome : " + e); } }
/** * Returns the SourceSansPro regular font. * * @param size the size of font * @return the font SourceSansPro-Regualar * @throws FontFormatException the font format exception * @throws IOException Signals that an I/O exception has occurred. * @throws Exception the exception */ private static Font getSourceSansPro(float size) throws FontFormatException, IOException, Exception { Font font = Font.createFont( Font.TRUETYPE_FONT, Fonts.class.getResourceAsStream("/information/fonts/SourceSansPro-Regular.otf")); return font.deriveFont(size); }
// renders font characters to be used for text painting in tests (to make font rendering // platform-independent) public static void main(String[] args) throws Exception { Font font = Font.createFont( Font.TRUETYPE_FONT, EditorPaintingTest.class.getResourceAsStream("/fonts/Inconsolata.ttf")); BitmapFont bitmapFont = BitmapFont.createFromFont(font); bitmapFont.saveToFile(getFontFile()); }
/** * Loads the Bootstrap font containing the glyphs * * @param size Desired font size * @return Font object for Bootstrap Glyph Font * @throws FontFormatException * @throws IOException */ private Font loadGlyphFont(float size) throws FontFormatException, IOException { Font fontRaw = Font.createFont( Font.TRUETYPE_FONT, this.getClass() .getResourceAsStream("/resource/image/glyphicons-halflings-regular.ttf")); Font fontBase = fontRaw.deriveFont(16f); return fontBase.deriveFont(Font.PLAIN, size); }
public void initializeComponents() { Font font; try { font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("images/Riffic.ttf")); Font styledAndSized = font.deriveFont(42F); hostLabel = new JLabel("Host"); hostLabel.setFont(styledAndSized); portLabel = new JLabel("Port:"); styledAndSized = font.deriveFont(28F); portLabel.setFont(styledAndSized); portTF = new JTextField(5); portTF.setFont(styledAndSized); portTF .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { changed(); } public void removeUpdate(DocumentEvent e) { changed(); } public void insertUpdate(DocumentEvent e) { changed(); } public void changed() { if (portTF.getText().equals("")) { submitButton.setEnabled(false); } else { submitButton.setEnabled(true); } } }); submitButton = new JButton("Submit"); styledAndSized = font.deriveFont(20F); submitButton.setFont(styledAndSized); submitButton.setPreferredSize(new Dimension(200, 50)); buttonPanel = new JPanel(); hostPanel = new JPanel(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FontFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public GameFont(String fontName, float size) { Font font; try { InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fontName); font = Font.createFont(TRUETYPE_FONT, inputStream).deriveFont(size); } catch (IOException | FontFormatException e) { throw new IllegalStateException("Font is not loaded.", e); } generateFontTexture(font); }
public static Font getFont(String path, float size) { Font f = null; try { try { f = Font.createFont( Font.TRUETYPE_FONT, Emoticon.class.getClassLoader().getResourceAsStream(path)); } catch (Exception e) { if (f == null) { f = Font.createFont( Font.TRUETYPE_FONT, Emoticon.class.getClassLoader().getResourceAsStream("font.ttf")); } } return f.deriveFont(size); } catch (Exception e) { } return null; }
public static Font createFont() { Font font2 = null; // The font we are going to returnb InputStream is = game.getClass().getResourceAsStream("/fonts/BOOTERZO.ttf"); // Load the font from the file try { // Attempt to... font2 = Font.createFont(Font.TRUETYPE_FONT, is); // set the font to the one from the file } catch (FontFormatException e) { // If there is an error, do nothing } catch (IOException e) { // If there is an error, do nothing } return font2.deriveFont(30f); // return the new font with size 30 }
public static Font createFont(String f, int s) { try { myStream = new BufferedInputStream(new FileInputStream("src/" + f)); ttfBase = Font.createFont(Font.TRUETYPE_FONT, myStream); telefraficoFont = ttfBase.deriveFont(Font.PLAIN, 50); } catch (Exception e) { e.printStackTrace(); System.err.println("Font not loaded."); } return telefraficoFont; }
private void importTTFButtonActionPerformed(ActionEvent evt) { TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); if (item instanceof FontTag) { FontTag ft = (FontTag) item; JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(Configuration.lastOpenDir.get())); FileFilter ttfFilter = new FileFilter() { @Override public boolean accept(File f) { return (f.getName().toLowerCase().endsWith(".ttf")) || (f.isDirectory()); } @Override public String getDescription() { return "TTF files"; } }; fc.setFileFilter(ttfFilter); fc.setAcceptAllFileFilterUsed(false); JFrame fr = new JFrame(); View.setWindowIcon(fr); int returnVal = fc.showOpenDialog(fr); if (returnVal == JFileChooser.APPROVE_OPTION) { Configuration.lastOpenDir.set( Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath()); File selfile = Helper.fixDialogFile(fc.getSelectedFile()); Set<Integer> selChars = new HashSet<>(); try { Font f = Font.createFont(Font.TRUETYPE_FONT, selfile); int required[] = new int[] {0x0001, 0x0000, 0x000D, 0x0020}; loopi: for (char i = 0; i < Character.MAX_VALUE; i++) { for (int r : required) { if (r == i) { continue loopi; } } if (f.canDisplay((int) i)) { selChars.add((int) i); } } fontAddChars(ft, selChars, f); mainPanel.reload(true); } catch (FontFormatException ex) { JOptionPane.showMessageDialog(mainPanel, "Invalid TTF font"); } catch (IOException ex) { Logger.getLogger(FontPanel.class.getName()).log(Level.SEVERE, null, ex); } } } }
/** * Updates the cached font object. * * @throws IOException if the font can't be loaded * @throws FontFormatException if font is not a valid TTF */ private void updateFace() throws IOException, FontFormatException { Font createdFont = null; // Attempt to load font from /fonts under classloader String fontpath = "fonts/" + this.fontname + ".ttf"; InputStream fontStream = this.getClass().getClassLoader().getResourceAsStream(fontpath); if (fontStream != null) { createdFont = Font.createFont(Font.TRUETYPE_FONT, fontStream); fontStream.close(); } // Next try to get it from fontpath if (createdFont == null) { Font tempFont = new Font(this.fontname, Font.PLAIN, 1); // Check we got correct font, not a fallback if (tempFont.getFamily().equals(this.fontname)) { // It's the correct font, set it createdFont = tempFont; } } // Last resort, treat as a path to font if (createdFont == null) { fontStream = new FileInputStream(this.fontname); if (fontStream != null) { createdFont = Font.createFont(Font.TRUETYPE_FONT, fontStream); fontStream.close(); } } // If we still don't have a font, throw exception if (createdFont == null) { throw new IOException("Can't locate font: " + this.fontname); } // Derive font of correct fontsize this.cachedFont = createdFont.deriveFont((float) this.fontsize); // Set on prototype image this.g2.setFont(this.cachedFont); }
/** * Creates a font from its correponding true type file * * @param fontResource ttf file * @return new Font */ public Font createFont(String fontResource) { try { InputStream is = this.referenceClass.getResourceAsStream(bundle.getString(fontResource)); Font ttfBase; ttfBase = Font.createFont(Font.TRUETYPE_FONT, is); return ttfBase; } catch (FontFormatException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public boolean retrieveJAR() { try (InputStream stream = getClass().getResourceAsStream("/resources/font.ttf"); ) { setItem(Font.createFont(Font.TRUETYPE_FONT, stream)); setBroken(false); } catch (Exception e) { setBroken(true); e.printStackTrace(); } return false; }
/** * Creates a new TrueType font addressed by Unicode characters. The font will always be embedded. * * @param ttFile the location of the font on file. The file must end in '.ttf'. The modifiers * after the name are ignored. * @param enc the encoding to be applied to this font * @param emb true if the font is to be embedded in the PDF * @param ttfAfm the font as a <CODE>byte</CODE> array * @throws DocumentException the font is invalid * @throws IOException the font file could not be read */ TrueTypeFontUnicode(String ttFile, String enc, boolean emb, byte ttfAfm[], boolean forceRead) throws DocumentException, IOException { // String nameBase = getBaseName(ttFile); InputStream is = new FileInputStream(ttFile); try { javaFont = Font.createFont(Font.TRUETYPE_FONT, is); } catch (FontFormatException e) { e.printStackTrace(); throw new IOException(e); } finally { is.close(); } javaFontContext = new FontRenderContext(null, false, false); String nameBase = getBaseName(ttFile); String ttcName = getTTCName(nameBase); if (nameBase.length() < ttFile.length()) { style = ttFile.substring(nameBase.length()); } encoding = enc; embedded = emb; fileName = ttcName; ttcIndex = ""; if (ttcName.length() < nameBase.length()) ttcIndex = nameBase.substring(ttcName.length() + 1); fontType = FONT_TYPE_TTUNI; if ((fileName.toLowerCase().endsWith(".ttf") || fileName.toLowerCase().endsWith(".otf") || fileName.toLowerCase().endsWith(".ttc")) && (enc.equals(IDENTITY_H) || enc.equals(IDENTITY_V)) && emb) { process(ttfAfm, forceRead); if (os_2.fsType == 2) throw new DocumentException( MessageLocalization.getComposedMessage( "1.cannot.be.embedded.due.to.licensing.restrictions", fileName + style)); // Sivan if (cmap31 == null && !fontSpecific || cmap10 == null && fontSpecific) directTextToByte = true; // throw new // DocumentException(MessageLocalization.getComposedMessage("1.2.does.not.contain.an.usable.cmap", fileName, style)); if (fontSpecific) { fontSpecific = false; String tempEncoding = encoding; encoding = ""; createEncoding(); encoding = tempEncoding; fontSpecific = true; } } else throw new DocumentException( MessageLocalization.getComposedMessage("1.2.is.not.a.ttf.font.file", fileName, style)); vertical = enc.endsWith("V"); }
public static Font loadTTFFontFromFile(String fileName, float size) { Font font = null; try { File f = new File(fileName); System.out.println(f.getAbsolutePath()); FileInputStream in = new FileInputStream(f); Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in); return dynamicFont.deriveFont(size); } catch (Exception ex) { font = new Font("serif", Font.PLAIN, 24); } return font; }
@Override public boolean retrieveIDE() { try { File file = new File("resources/font.ttf"); setItem(Font.createFont(Font.TRUETYPE_FONT, file)); setBroken(false); } catch (Exception e) { setBroken(true); e.printStackTrace(); } return false; }
static { try { labelFont = Font.createFont( Font.TYPE1_FONT, ClassLoader.getSystemResourceAsStream("fonts/default.pfb")) .deriveFont(0.5f); } catch (FontFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Create a new font data element * * @param ttf The TTF file to read * @param size The size of the new font * @throws java.io.IOException Indicates a failure to */ private FontData(InputStream ttf, float size) throws IOException { if (ttf.available() > MAX_FILE_SIZE) { throw new IOException("Can't load font - too big"); } byte[] data = IOUtils.toByteArray(ttf); if (data.length > MAX_FILE_SIZE) { throw new IOException("Can't load font - too big"); } this.size = size; try { javaFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(data)); TTFFile rawFont = new TTFFile(); if (!rawFont.readFont(new FontFileReader(data))) { throw new IOException("Invalid font file"); } upem = rawFont.getUPEM(); ansiKerning = rawFont.getAnsiKerning(); charWidth = rawFont.getAnsiWidth(); fontName = rawFont.getPostScriptName(); familyName = rawFont.getFamilyName(); String name = getName(); System.err.println("Loaded: " + name + " (" + data.length + ")"); boolean bo = false; boolean it = false; if (name.indexOf(',') >= 0) { name = name.substring(name.indexOf(',')); if (name.indexOf("Bold") >= 0) { bo = true; } if (name.indexOf("Italic") >= 0) { it = true; } } if ((bo & it)) { javaFont = javaFont.deriveFont(Font.BOLD | Font.ITALIC); } else if (bo) { javaFont = javaFont.deriveFont(Font.BOLD); } else if (it) { javaFont = javaFont.deriveFont(Font.ITALIC); } } catch (FontFormatException e) { IOException x = new IOException("Failed to read font"); x.initCause(e); throw x; } }
/*Load font for use with labels*/ private void loadFont() { // load font try { // create the font to use GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // register the font ge.registerFont( Font.createFont(Font.TRUETYPE_FONT, new File("assets\\fonts\\Sen-Regular.ttf"))); } catch (IOException ex) { Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex); } catch (FontFormatException ex) { Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex); } }
private void addFont(String fontKey, String fontName, float scale) { try { fontName = fontName.toLowerCase(); FileInputStream stream = new FileInputStream("data/fonts/ttf/" + fontName + ".ttf"); Font f = Font.createFont(Font.TRUETYPE_FONT, stream); f = f.deriveFont(scale); fonts.put(fontKey, f); stream.close(); } catch (Exception e) { e.printStackTrace(); } }
private void init() { running = true; bufferedImage = new BufferedImage(PANEL_WIDTH, PANEL_HEIGHT, BufferedImage.TYPE_INT_ARGB); Font font = null; try { font = Font.createFont(Font.TRUETYPE_FONT, ClassLoader.getSystemResourceAsStream("font.ttf")) .deriveFont(64f); } catch (FontFormatException | IOException e) { e.printStackTrace(); } graphics2D = (Graphics2D) bufferedImage.getGraphics(); graphics2D.setFont(font); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gameStateManager = new GameStateManager(this); }
public void init(GameContainer container, StateBasedGame sbg) throws SlickException { hintergrund = new Image("res/pictures/background.png"); this.game = sbg; // eigenes Font laden try { InputStream inputStream = ResourceLoader.getResourceAsStream("res/fonts/Volter__28Goldfish_29.ttf"); Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream); // Font Groesse awtFont = awtFont.deriveFont(24f); font = new TrueTypeFont(awtFont, false); } catch (Exception e) { e.printStackTrace(); } }
public static Font getFont(String name) { Font font = null; if (cache != null) { if ((font = (Font) cache.get(name)) != null) { return font; } } String fName = "/fonts/" + name; try { InputStream is = DemoFonts.class.getResourceAsStream(fName); font = Font.createFont(Font.TRUETYPE_FONT, is); } catch (Exception ex) { ex.printStackTrace(); System.err.println(fName + " not loaded. Using serif font."); font = new Font("serif", Font.PLAIN, 24); } return font; }