package org.xith3d.shapegeom;

import com.xith3d.scenegraph.Shape3D;

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

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

  private Font font;
  private String text;
  private ShapeTriangulator st;
  private FontRenderContext rc;


  /**
   * Extends Shape3D to display text in three dimensions. The text is drawn in the
   * xy plane with the bottom left corner at the origin. It is then extruded in the -z
   * direction.
   *
   * @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)
   * @param depth the depth to extrude in the - z direction
   */
  public Text3D(Font font, String text, double flatness, int vertexFormat, float depth) {
    this.font = font;
    this.text = text;
    rc = new FontRenderContext(null, false, false);
    GlyphVector glv = font.createGlyphVector(rc,text);
    Shape s = glv.getOutline(0,0);

    st = new ShapeTriangulator(s,flatness);
    this.setGeometry(st.getExtrudedGeometry(vertexFormat, depth));
  }

  public ShapeTriangulator getSt() {
    return st;
  }

  public String getText() {
    return text;
  }

  public Font getFont() {
    return font;
  }


}
