package org.xith3d.shapegeom;

import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.Geometry;

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

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

  private Font font;
  private char c;
  private ShapeTriangulator st;
  private FontRenderContext rc;
  private float width;
  private float height;


  /**
   * Extends Shape3D to display a character 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 c the character 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 Char3D(Font font, char c, double flatness, int vertexFormat, float depth) {
    this.font = font;
    this.c = c;
    rc = new FontRenderContext(null, false, false);
    GlyphVector glv = font.createGlyphVector(rc, new char[]{c});
    Shape s = glv.getOutline(0,0);

    Rectangle2D rect = font.getStringBounds(new char[]{c},0,1,rc);
    this.width = (float)rect.getWidth();
    this.height = (float)rect.getHeight();
    st = new ShapeTriangulator(s,flatness);
    this.setGeometry(st.getExtrudedGeometry(vertexFormat, depth));
  }

  public Char3D(Char3D old){
    this.setGeometry((Geometry)old.getGeometry().cloneNodeComponent(true));
  }

  public ShapeTriangulator getSt() {
    return st;
  }

  public char getChar() {
    return c;
  }

  public Font getFont() {
    return font;
  }

  public float getWidth() {
    return width;
  }

  public void setWidth(float width) {
    this.width = width;
  }

  public float getHeight() {
    return height;
  }

  public void setHeight(float height) {
    this.height = height;
  }


}
