Package de.lessvoid.nifty.renderer.lwjgl.render

Source Code of de.lessvoid.nifty.renderer.lwjgl.render.LwjglRenderFont

package de.lessvoid.nifty.renderer.lwjgl.render;

import de.lessvoid.nifty.renderer.lwjgl.render.font.CharacterInfo;
import de.lessvoid.nifty.renderer.lwjgl.render.font.Font;
import de.lessvoid.nifty.spi.render.RenderDevice;
import de.lessvoid.nifty.spi.render.RenderFont;

public class LwjglRenderFont implements RenderFont {
  private Font font;

  public LwjglRenderFont(final String name, final RenderDevice device) {
    font = new Font(device);
    font.init(name);
  }

  public int getHeight() {
    return font.getHeight();
  }

  public int getWidth(final String text) {
    return font.getStringWidth(text);
  }

  public static int getKerning(final CharacterInfo charInfoC, final char nextc) {
    Integer kern = charInfoC.getKerning().get(Character.valueOf(nextc));
    if (kern != null) {
      return kern.intValue();
    }
    return 0;
  }

  public Integer getCharacterAdvance(final char currentCharacter, final char nextCharacter, final float size) {
    CharacterInfo currentCharacterInfo = font.getChar(currentCharacter);
    if (currentCharacterInfo == null) {
      return null;
    } else {
      return new Integer(
          (int) (currentCharacterInfo.getXadvance() * size + getKerning(currentCharacterInfo, nextCharacter)));
    }
  }

  public Font getFont() {
    return font;
  }

  public void dispose() {
  } 
}
TOP

Related Classes of de.lessvoid.nifty.renderer.lwjgl.render.LwjglRenderFont

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.