package org.xith3d.shapegeom;

import com.xith3d.scenegraph.Shape3D;

import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;

/**
 * <p>
 * Uses the ShapeTriangulator to draw a flat representation of text
 * </p>
 *
 *
 *
 * Date: 8/04/2005
 * @author Alistair Dickie
 */
public class Text2D extends Shape3D{

  private Font font;
  private String text;
  private ShapeTriangulator shapeTriangulator;
  /**
   * Extends Shape3D to display text in two dimensions. The text is drawn in the
   * xy plane with the bottom left corner at the origin.
   *
   *
   * @param font a java.awt.Font object 
   * @param text the text to display
   * @param flatness the flatness to used to smooth out the curves. 1% of the font size usually is about righ
   * @param vertexFormat OR's properties of the verticies (e.g. GeometryArray.COORDINATES|GeometryArray.NORMALS)
   */
  public Text2D(java.awt.Font font, String text, double flatness, int vertexFormat) {
    this.font = font;
    this.text = text;
    FontRenderContext rc = new FontRenderContext(null, false, false);
    GlyphVector glv = font.createGlyphVector(rc,text);
    Shape s = glv.getOutline(0,0);

    shapeTriangulator = new ShapeTriangulator(s,flatness);
    this.setGeometry(shapeTriangulator.getFaceGeometry(vertexFormat));
  }

  public Font getFont() {
    return font;
  }

  public String getText() {
    return text;
  }

  public ShapeTriangulator getSt() {
    return shapeTriangulator;
  }
}
