Android Open Source - Airplanes T T F Font Manager






From Project

Back to project page Airplanes.

License

The source code is released under:

GNU General Public License

If you think the Android project Airplanes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.axnsan.airplanes.util;
/*from   ww w .  ja va2  s  .  co  m*/
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;

public class TTFFontManager implements FontManagerInterface {
  private SortedMap<Integer, BitmapFont> fonts = new TreeMap<Integer, BitmapFont>(Collections.reverseOrder());
  private boolean init = false;
  private final Integer sizes[] = { 15, 16, 17, 18, 20, 22, 25, 30, 35, 42, 55 }, defaultSize = 15;
  private BitmapFont defaultFont;
  
  /**Initialize the font manager*/
  private void init() {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/segoeui.ttf"));
    FreeTypeFontParameter par = new FreeTypeFontParameter();
    par.characters = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" +
        "?????? -;'.[]\\(),?!\"/@#$%^&*1234567890<>_:+";
    for (Integer size : sizes) {
      par.size = size;
      BitmapFont font = generator.generateFont(par);
      font.setColor(Color.BLACK);
      fonts.put(size, font);
    }
    par.size = defaultSize;
    defaultFont = generator.generateFont(par);
    generator.dispose();
    init = true;
  }
  
  /**Returns the largest font that is smaller than the given size*/
  @Override
  public BitmapFont getFontForHeight(Integer size) {
    if (!init)
      init();
    
    for(SortedMap.Entry<Integer, BitmapFont> entry : fonts.entrySet()) {
      if (size >= entry.getKey()) {
        BitmapFont ret = entry.getValue();
        ret.setColor(Color.BLACK);
        return ret;
      }
    }
    
    return defaultFont;
  }
  
  @Override
  public BitmapFont getFontForHeight(float size) {
    return getFontForHeight(new Integer((int)size));
  }
  
  /**Dispose of the generated fonts*/
  @Override
  public void dispose() {
    for(SortedMap.Entry<Integer, BitmapFont> entry : fonts.entrySet()) {
      BitmapFont font = entry.getValue();
      if (font != null)
        font.dispose();
    }
    fonts.clear();
    if (defaultFont != null)
      defaultFont.dispose();
    defaultFont = null;
    init = false;
  }
}




Java Source Code List

com.axnsan.airplanes.Airplanes.java
com.axnsan.airplanes.BaseGrid.java
com.axnsan.airplanes.GameConfiguration.java
com.axnsan.airplanes.GameState.java
com.axnsan.airplanes.GridRandomizer.java
com.axnsan.airplanes.Grid.java
com.axnsan.airplanes.GuardedScreen.java
com.axnsan.airplanes.HotseatMatchHandler.java
com.axnsan.airplanes.MainActivity.java
com.axnsan.airplanes.Main.java
com.axnsan.airplanes.MatchHandler.java
com.axnsan.airplanes.PlacementGrid.java
com.axnsan.airplanes.Plane.java
com.axnsan.airplanes.Player.java
com.axnsan.airplanes.PlayingGrid.java
com.axnsan.airplanes.online.ClientSocket.java
com.axnsan.airplanes.online.EventHandler.java
com.axnsan.airplanes.online.Game.java
com.axnsan.airplanes.online.LobbyScreen.java
com.axnsan.airplanes.online.LoginScreen.java
com.axnsan.airplanes.online.Message.java
com.axnsan.airplanes.online.Messages.java
com.axnsan.airplanes.online.OnlineGameScreen.java
com.axnsan.airplanes.online.OnlineMatchHandler.java
com.axnsan.airplanes.online.OnlineMenuScreen.java
com.axnsan.airplanes.online.OnlineSettingsScreen.java
com.axnsan.airplanes.online.SessionData.java
com.axnsan.airplanes.screens.BeginTurnScreen.java
com.axnsan.airplanes.screens.HotseatPlayersScreen.java
com.axnsan.airplanes.screens.HotseatScreen.java
com.axnsan.airplanes.screens.HotseatSettingsScreen.java
com.axnsan.airplanes.screens.HotseatStartScreen.java
com.axnsan.airplanes.screens.MainMenuScreen.java
com.axnsan.airplanes.screens.PlacementScreen.java
com.axnsan.airplanes.screens.PlayMenuScreen.java
com.axnsan.airplanes.screens.PracticeScreen.java
com.axnsan.airplanes.screens.PracticeSettingsScreen.java
com.axnsan.airplanes.screens.PracticeStartScreen.java
com.axnsan.airplanes.util.ActionManager.java
com.axnsan.airplanes.util.ActionResolver.java
com.axnsan.airplanes.util.BasicFontManager.java
com.axnsan.airplanes.util.Detector.java
com.axnsan.airplanes.util.DoubleTapDetector.java
com.axnsan.airplanes.util.DoubleTapListener.java
com.axnsan.airplanes.util.FontManagerInterface.java
com.axnsan.airplanes.util.FontManager.java
com.axnsan.airplanes.util.JavaXmlParser.java
com.axnsan.airplanes.util.Point2D.java
com.axnsan.airplanes.util.RandomizedQueue.java
com.axnsan.airplanes.util.StringManager.java
com.axnsan.airplanes.util.StringXmlParser.java
com.axnsan.airplanes.util.TTFFontManager.java
com.axnsan.airplanes.util.TapDetector.java
com.axnsan.airplanes.util.TapListener.java